Let’s build a (toy) JVM in JavaScript
Although I’ve written a significant amount of Java in my professional career, some of the underlying details of the platform are still a bit of a black box to me. What better way to solidify my understanding and explore new concepts than to implement a JVM? Just for fun, I’m writing it in JavaScript to try out some of the modern APIs, idioms, and toolchains that have emerged in the past few years.
A previous incarnation of this blog was named “(over)undertaking”; that would certainly describe jvm.js. Writing a virtual machine is a massive undertaking, but I’m going to approach it in thin slices, layering on additional functionality as time/curiosity permits. The combination of JVM and JavaScript provides fertile ground for learning and experimentation, including:
- Bytecode & disassembly
- Low-level memory management
- Garbage collectors
- Threading
- Exceptions
- Binary storage/transport formats
- JNI for JavaScript
- JIT & AOT compilation
- High-performance JavaScript & asm.js
- Classloading over a network
- JavaScript API design
- Web Workers and paralel-processing
- Java standard libraries
- Grunt & Karma TDD workflow
This should be a very interesting sandbox to play in, indeed. The code lives at github.com/greghaskins/jvm.js if you’d like to contribute or follow along.