I want to create a very minimalistic virtual machine with limited set of instructions in java. I know how to do it in c/c++ with combination of LLVM but I want to try it in java as well how can I do it in java since I don't have access to LLVM how can I simulate the situation?
Asked
Active
Viewed 625 times
-1
-
This is a duplicate of http://stackoverflow.com/questions/2598675/how-to-write-a-virtual-machine, only with an "in Java" added. Both are of a very wide scope, and - in my opinion - not appropriate here. Maybe you can try to narrow down the question to something more concrete by providing details regarding the instruction set you want to support, whether you want to perform JIT to native or not and if so in what way, etc. – Oak Dec 02 '12 at 10:38
2 Answers
1
If you want to compile down to Java bytecode then you probably want to use a library like ASM: it is designed for generating and manipulating bytecode:
A lot of JVM languages (e.g. Clojure, Groovy) use ASM or something similar as an underlying bytecode generator.

mikera
- 105,238
- 25
- 256
- 415
-
1My purpose is to learn how to create a simple VM , ASM is far big for my purpose, but thanks for brought it up – Vahid Hashemi Dec 01 '12 at 21:00
1
To use the JVM you have to work within the constraints of how the JVM works which is to run byte code. This means you either have to generate byte code or Java source which you compile. If you use the Java source option, you can generate "instructions" which are implemented using method calls as a very light weight (for the developer) way of implementing it.

Peter Lawrey
- 525,659
- 79
- 751
- 1,130