I was reading item #6.10 on http://www.cafeaulait.org/javafaq.html and I began wondering how the big players go about creating their own implementation of a JVM. Would an experimental something or another be possible (and feasible) for one guy?
-
http://www.cafeaulait.org/javafaq.htm: The requested URL /javafaq.htm was not found on this server. It is /javafaq.html, I've corrected it in an edit. – Grant Wagner Apr 08 '09 at 18:19
-
@Grant: So did I, but a little slower. :) – Michael Myers Apr 08 '09 at 18:21
-
"6.10: Does Java have pointers?"? – Tom Hawtin - tackline Apr 08 '09 at 19:44
-
@Tom Hawtin: Indeed, as part of 6.10, the answer says about references: "How exactly the virtual machine implements references at the level of machine code is VM-dependent and completely hidden from the programmer in any case. Most VMs including Sun's use handles, not pointers." – Kai Apr 10 '09 at 15:14
-
That would depend on the guy. – Raedwald Oct 14 '13 at 22:35
4 Answers
technically, all the information people need to create a new JVM is in the public specifications for the language and the targetted platform. A JVM would need to behave differently depending on whether it is meant to run on a desktop computer or a mobile phone, even if the bytecode interpretation would be largely identical.
A few places to start looking for information:
http://en.wikipedia.org/wiki/List_of_Java_virtual_machines
Reading The "Java Virtual Machine Specification" by Tim Lindholm
http://www.jcp.org/en/jsr/detail?id=30
From what I have seen of JVM implementations by Sun, IBM or smaller companies like Esmertec, writing a simple JVM is a several man-months project but adding JSR after JSR to support more functionality can take years afterwards.
Now, if all you need is a simple bytecode interpreter, it's not that bad, but it's still quite a bit of code to write.

- 6,836
- 1
- 16
- 32
A handmade JVM would be a great way to learn about virtual machines in general, the issues of program language design (through the JVM spec), and the nitty gritty of parsing and so forth.
If you choose to take it in that direction, you could also explore optimizations, which is where it can get interesting, and you can take research papers and implement their algorithms.
That being said, if you're less interested in the long and arduous task of creating a VM from scratch, you might want to modify an existing open source VM like Kaffe. It will show you what a virtual machine does, but not necessarily how Java code works in Sun's JVM:
Kaffe is a clean room implementation of the Java virtual machine, plus the associated class libraries needed to provide a Java runtime environment.
This way, you could study the details, but dive in to implementing more interesting features.

- 864
- 8
- 23

- 3,997
- 4
- 30
- 36
I understand that, currently, the big players license the Java library from Sun. They then add their own refinements. The main difference between implementations is the bytecode->machine code compiler.

- 145,806
- 30
- 211
- 305
For one thing, you may want to have a look at Apache Harmony They have come a long way, so their project history may actually give you a good idea on the effort required. I myself would not bet on it being feasible for one guy

- 607
- 3
- 5
-
1"Apache Harmony is retired at the Apache Software Foundation since Nov 16, 2011." – Raedwald Oct 14 '13 at 22:37