rusty-jvm
Introduction
Writing a JVM has long been a dream of mine, so I decided to give it a try combining my curiosity about how suitable Rust is for such a task with my desire to see how far I could push it. I'm not the first to explore this idea this project is a well-known and easily searchable example but unlike that project, I aim to create a JVM capable of running as much Java code as possible. I have to say, I didn’t expect to get this far. Java code is run in interpreted mode, meaning the JVM reads and executes bytecode instructions directly without compiling them to native code, so please don't expect high performance. There is no dependency on any existing JVM implementation. Everything related to Java is implemented from scratch. One major feature that’s still missing is garbage collection. That’s the next big milestone.
Implemented Key Features
- 99% of actual opcodes (JVMS §6)
- Static initialization (JVMS §5.5)
- Polymorphic models (JLS §8.4.8)
- Single- and multi-dimensional arrays (JLS §10)
- Exceptions (JLS §11)
- java.io (partially)
- java.nio (partially)
- Type casting (JLS §5.5)
- Program arguments (JLS §12.1.4)
- java.lang.System (most features)
- Reflection (some features)
- Assertions (JLS §14.10)
See integration tests for broader examples of supported Java features.
Java Standard Library Classes
This project uses Java standard library classes based on OpenJDK JDK 23 General-Availability Release.
The source code and class files are located in the lib directory of this repository.
They are distributed under the GNU GPLv2 with Classpath Exception.
OpenJDK produces OS-specific distributions of these classes.
For simplicity, this project includes modified (under GPLv2+CE) versions usable across Windows, macOS, and Linux.
You can still use original OpenJDK classes, but ensure they're compiled for the OS on which you're running rusty-jvm
.
Getting Started
Prerequisites
Ensure the following are set up:
- A machine running Windows, macOS, or Linux
- Rust installed and configured
- The Java standard library classes, required via one of the following:
- Run the installation command:
rusty-jvm --install
- OR set the
RUSTY_LIB_DIR
environment variable to the path of the standard library
(recommended: the lib directory in this repository)
- Run the installation command:
Example Program
This Java program calculates the total attack power of a group of game units.
It uses abstract classes, interfaces, and polymorphism to showcase rusty-jvm's capabilities.
;
;
;
;
Steps to Run
-
Compile the program using the Java compiler:
-
Run it using rusty-jvm:
Expected Output
If everything is set up correctly, you should see:
We embrace the glory of battle!
Battle is upon us!
Group attack power is 57
License
rusty-jvm
is licensed under the MIT License.
Standard library classes in lib directory are distributed under the GNU GPLv2 with Classpath Exception.