Live data from Hacker News

I have written a JVM in Rust

andreabergia.com

31–40 of 185 posts

Re: I have written a JVM in Rust

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

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/ja…

>String being equal by reference is important, and part of JLS.

I never said String must be equal by reference when their content is. However string literals must be equal by reference. I thought Mentioning the JLS would make it obvious, esp. having 'intern' in the context

Re: I have written a JVM in Rust

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

Thanks!

I know the feeling - this project, like most of my other side projects, got abandoned a couple of times. But I was really curious about implementing a GC and, for once, I managed to finish something. I'm glad I did! :-)

Re: I have written a JVM in Rust

#34
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…

pretty much indeed.

> say nothing for non-literal strings

yes, of course.

Re: I have written a JVM in Rust

#35

Just for kicks, has anybody tried to Rube-Goldberg it, and see how many VM's can stack on top of each other. Like have Java App running on JVM written in RUST, Running on WASM, Running on JVM, etc.. etc...

See also: The Birth & Death of JavaScript, A talk by Gary Bernhardt from PyCon 2014 (https://www.destroyallsoftware.com/talks/the-birth-and-death...)

Re: I have written a JVM in Rust

#36
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…

Thanks!

About the generics - some people have pointed out the same on reddit, and yeah, you are correct. The only thing that should be done is to read the Signature attribute that encodes the generic information about classes, methods, and fields (https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.ht...)

As a matter of fact, I just did a test and the following code works! :-)

    public class Generic {
        public static void main(String[] args) {
            List strings = new ArrayList(10);
            strings.add("hey");
            strings.add("hackernews");

            for (String s : strings) {
                tempPrint(s);
            }
        }

        private static native void tempPrint(String value);
    }

Re: I have written a JVM in Rust

#37

Just for kicks, has anybody tried to Rube-Goldberg it, and see how many VM's can stack on top of each other. Like have Java App running on JVM written in RUST, Running on WASM, Running on JVM, etc.. etc...

This talk isn't about VMs, but it is about an infinite tower of interpreters. You may find it interesting: https://youtu.be/SrKj4hYic5A

Re: I have written a JVM in Rust

#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!

Re: I have written a JVM in Rust

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

> 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."

Post reply on HN