4 ms·
Simple Open-Source Java Virtual Machine in C
- peter_d_sherman 3y agoRelated: Java Language and Virtual Machine Specifications https://docs.oracle.com/javase/specs/index.html https://docs.oracle.com/javase/specs/index.html OpenJDK (About + implementation comparison table): https://en.wikipedia.org/wiki/OpenJDK https://en.wikipedia.org/wiki/OpenJDK
- metadat 3y ago(2021)
- cowmix 3y agoI had a buddy that wrote a Java 1.1 JVM from scratch in C back in late '97. He created it completely from the defined specification from Sun and actually found bugs in the spec. IIRC, the found bugs in the thread(s) specification. I believe his JVM was one of the first clean-room JVM implementation outside of Sun's efforts.
- version_five 3y agoI can imagine that the spec would to some extent reflect an attempt to capture the behavior of the jvm they actually wrote, as opposed to being created first and then having Sun implement afterwards? It sounds like an interesting exercise to recreate it based on the spec and see what got missed.
- kevin_thibedeau 3y agoTheir intent was to have hardware implementations. The basic spec is simple enough to make that tractable.
- speps 3y agoA similar effort but in Go from about a month ago: https://jacobin.org/ https://jacobin.org/ [1] [1] https://news.ycombinator.com/item?id=37247394 https://news.ycombinator.com/item?id=37247394
- karmakaze 3y agoIt wasn't actually possible to make a proper implementation from spec before Java 1.5. Quoting Wikipedia > The original Java memory model developed in 1995, was widely perceived as broken, preventing many runtime optimizations and not providing strong enough guarantees for code safety. It was updated through the Java Community Process, as Java Specification Request 133 (JSR-133), which took effect back in 2004, for Tiger (Java 5.0).
- mjan22640 3y ago~90% of the JVM instruction set are simple RISC instructions, the rest is object maintenance. Writting a JVM is like writting an emulator for a simple CPU/platform.
- ahoka 3y agoA simple CPU with a possibly different memory model than the host CPU.
- pjmlp 3y agoTrue until Java 7, not so with all the newer bytecodes.
- teleforce 3y agoIt makes perfect sense at the time Sun is naming it JVM, apparently technically it's a VM. That meant they have had a valid claim to "write once, run anywhere" mantra. It's a shame that in reality it turned out later to be "write once, debug everywhere" kind of nightmare.
- suswagatam_rong 3y agoI so wish I could read that source code. For an amateur like me, it is so phenomenal :)
- alexshendi 3y agoI tried to get it to run Peter Norvig's JScheme [1]. Apparently I also need a class library like GNU classpath? DISCLAIMER: not a Java expert or even practitoner. [1] http://norvig.com/jscheme.html http://norvig.com/jscheme.html