Live data from Hacker News

I have written a JVM in Rust

andreabergia.com

11–20 of 185 posts

Re: I have written a JVM in Rust

#11
post #3

Great project, congrats! Mad respect. Started working on something very similar a few years back and gave up pretty soon for some stupid reason. Maybe I should try again, am getting better at getting stuff done.

Please do

Re: I have written a JVM in Rust

#12
post #4
post #2

Nice project, congrats! One thing struck me as a bit odd: > In particular, it does not support: generics What kind of support is there for generics in the JVM? Maybe I'm too naive to assume that due to type erasure on bytecode level everything is just an Object, ie. a reference type? Or do you mean the class definition parser - but then, you don't really have any checks in place to see if the class file is valid (oth…

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.

Java strings are compared by reference, if they do not match, they're compared by value. There's no guarantee every single string has a single instance. That would hurt performance.

Re: I have written a JVM in Rust

#13
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.

Re: I have written a JVM in Rust

#14
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.

Java strings are compared by reference, if they do not match, they're compared by value. There's no guarantee every single string has a single instance. That would hurt performance.

I think op meant "String literals". For those the spec seems to require interning:

> Moreover, a string literal always refers to the same instance of class String. This is because string literals - or, more generally, strings that are the values of constant expressions (§15.28) - are "interned" so as to share unique instances, using the method String.intern.

And later:

> Literal strings within different classes in different packages likewise represent references to the same String object.

Source: https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html...

But that does - as far as I can see - say nothing for non-literal strings.

[edit]: formatting

Re: I have written a JVM in Rust

#15
post #4
post #2

Nice project, congrats! One thing struck me as a bit odd: > In particular, it does not support: generics What kind of support is there for generics in the JVM? Maybe I'm too naive to assume that due to type erasure on bytecode level everything is just an Object, ie. a reference type? Or do you mean the class definition parser - but then, you don't really have any checks in place to see if the class file is valid (oth…

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.

Not entirely correct, last I checked string interning was ONLY guaranteed for those strings defined in source and read in during class loading, strings created via the String constructor (f.ex. via StringBuilder) CAN duplicate those strings that you hardcoded in your sources, to get the "canonical" string in those cases you have to invoke String.intern() if memory serves me correct.

https://docs.oracle.com/en/java/javase/11/docs/api/java.base...()

Also interning strings to optimize equality checks to be able to use pointer comparison is dangerous for external inputs since iirc at some point interned strings could permanently be stored (unless implemented by a WeakSet) and attackers could fill up your heap (or cause other GC issues since the entire interning functionality is a cache) by filling up your interning lists with crap.

Re: I have written a JVM in Rust

#18
post #14

Earlier quoted context omitted.

Java strings are compared by reference, if they do not match, they're compared by value. There's no guarantee every single string has a single instance. That would hurt performance.

I think op meant "String literals". For those the spec seems to require interning: > Moreover, a string literal always refers to the same instance of class String. This is because string literals - or, more generally, strings that are the values of constant expressions (§15.28) - are "interned" so as to share unique instances, using the method String.intern. And later: > Literal strings within different classes in di…

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.

Re: I have written a JVM in Rust

#20
post #16

How often will this post be reposted on HN ? Recent posts: https://news.ycombinator.com/item?id=36735344 - 6 days ago https://news.ycombinator.com/item?id=36717967 - 7 days ago https://news.ycombinator.com/item?id=36710803 - 7 days ago (OP) Btw. nice project!

Doesn't really count as a repost if none of the previous submissions didn't get any traction.
Post reply on HN