Live data from Hacker News

I have written a JVM in Rust

andreabergia.com

51–60 of 185 posts

Re: I have written a JVM in Rust

#53
I have a few questions about the garbage collection. One of the hard parts of implementing a garbage collector is making sure everything is properly rooted (especially with a moving collector). you have the `do_garbage_collection` method marked unsafe[1], but don't explain what the calling code needs to do to ensure it is safe to call. How do you ensure all references to the heap are rooted? This is not a trivial problem[2][3][4].

Also note that I cloned the repo and tried to run `cargo test` every test fails with 'should be able to add entries to the classpath: InvalidEntry(".../vm/rt.jar")' vm/tests/integration/real_code_tests.rs:15:10

[1] https://github.com/andreabergia/rjvm/blob/be9c54066c64a82879...

[2] https://manishearth.github.io/blog/2021/04/05/a-tour-of-safe...

[3] https://without.boats/blog/shifgrethor-iii/

[4] https://coredumped.dev/2022/04/11/implementing-a-safe-garbag...

Re: I have written a JVM in Rust

#54
post #23

Earlier quoted context omitted.

Thanks, makes sense yes. Still if the JVM look up in all cases defers to value after ref mismatch, it should work identically, no? Even if interning is mandatory as per spec, I'm not sure how it'd change the outcome of evaluation.

yeah, I'd assume as much. If it indeed falls back to a by-value comparison it would be slower, but should work.

nope - it'd be plain wrong. Literals must be equal by reference, comparing them by value would just break JLS, as they would be equal to any other composed string by reference as well.

Re: I have written a JVM in Rust

#55
post #40
post #4

Earlier quoted context omitted.

pretty much this - generics have (rare) implications to the reflection (but it's unsupported as well) but overall they are replaced with the nearest class/interface when compiled. OTOH lack of string interning is super strange [it's trivial to implement], and w/o it JVM is not a thing. String being equal by reference is important, and part of JLS. Lack of thread makes the entire endeavor a toy project.

> Lack of thread makes the entire endeavor a toy project. yeah, as stated by the author in the line that says "I want to stress that this is a toy JVM, built for learning purposes and not a serious implementation."

Yeah, that's the only part that makes it a toy project - the rest can be added w/o too much of an effort. This is pretty much what makes it a toy project.

Re: I have written a JVM in Rust

#56
post #8
post #6

Earlier quoted context omitted.

“I want to stress that this is a toy JVM, built for learning purposes and not a serious implementation.”

The rest of the stuff, incl. I/O is actually on the trivial side - threads do require planning. This is what I meant by being a 'toy' project, threads (and JMM) would be impossible to bolt in later on.

The reason you're being downvoted is you keep dismissing this as a "toy" project, and pointing out that it would be hard to make a real project.

But, as the previous commenter attempted to point out to you this project is a *self-described* toy project.

On the very page that is linked, the author of the JVM specifically says:

"I want to stress that this is a toy JVM, built for learning purposes and not a serious implementation."

Thus, absolutely no one disagrees that its a toy JVM. They just want you to stop being dismissive of someone's toy project by repeatedly pointing out its a toy project and not a "not a thing"

Re: I have written a JVM in Rust

#57

Earlier quoted context omitted.

Thanks, makes sense yes. Still if the JVM look up in all cases defers to value after ref mismatch, it should work identically, no? Even if interning is mandatory as per spec, I'm not sure how it'd change the outcome of evaluation.

Yes - that is a performance optimisation. I don't think comparing everything by value makes or breaks the implementation.

>I don't think comparing everything by value makes or breaks the implementation.

Nothing much to think -- distinct objects must have distinct references [e.g. new String("a")!=new String("a')], literals must have the same references for the same values [e.g. "a"=="a"].

Re: I have written a JVM in Rust

#58
post #8

Earlier quoted context omitted.

The rest of the stuff, incl. I/O is actually on the trivial side - threads do require planning. This is what I meant by being a 'toy' project, threads (and JMM) would be impossible to bolt in later on.

The reason you're being downvoted is you keep dismissing this as a "toy" project, and pointing out that it would be hard to make a real project. But, as the previous commenter attempted to point out to you this project is a *self-described* toy project. On the very page that is linked, the author of the JVM specifically says: "I want to stress that this is a toy JVM, built for learning purposes and not a serious impl…

Right, just because something is a "toy" doesn't mean it's not still impressive. If someone implemented a "toy" database that could parse and execute SQL queries, distribute data across nodes, etc., you would probably not want to use that in production, but it's still a very impressive project for a single person to pull off, even if it's riddled with bugs. Getting a very complex system to "just barely functional" is still a huge achievement and very cool!

Re: I have written a JVM in Rust

#59
post #8

Earlier quoted context omitted.

The rest of the stuff, incl. I/O is actually on the trivial side - threads do require planning. This is what I meant by being a 'toy' project, threads (and JMM) would be impossible to bolt in later on.

The reason you're being downvoted is you keep dismissing this as a "toy" project, and pointing out that it would be hard to make a real project. But, as the previous commenter attempted to point out to you this project is a *self-described* toy project. On the very page that is linked, the author of the JVM specifically says: "I want to stress that this is a toy JVM, built for learning purposes and not a serious impl…

I've pointed the only part that makes it a toy project is the lack of Threading support, the rest is not hard to add. So the items in list of things missing after 'toy' thing should have totally different weights (with Threads being the added to the last).

Re: I have written a JVM in Rust

#60
post #38

Great learning project, I'm glad the author is having fun. Implementing a VM from scratch is a blast, and I have learned so much in the past doing that kind of thing. If they're interested in bolting on a GC, it couldn't hurt to look at MMtk. ( https://www.mmtk.io/ ) Some high quality collection algorithms, written to be pluggable to various VMs, and written in Rust.

Uh, first time hearing mmtk. Thanks for the link!

I only became aware of it because a former employer (RelationalAI) was heavily interested in replacing Julia's GC with it (for some workloads): https://pretalx.com/juliacon2023/talk/BMBEGY/
Post reply on HN