rusty-jvm
Introduction
This project is a Java Virtual Machine (JVM) implemented in Rust, built to run Java programs independently of existing JVMs. Everything related to Java is implemented from scratch. The current version executes Java bytecode in interpreted mode, with the introduction of a Just-In-Time (JIT) compiler identified as a future milestone. The next major objectives include the integration of garbage collection and support for multithreading.
Implemented Key Features
- 100% of actual opcodes (JVMS §6)
- Lambda Expressions (JLS §15.27)
- Static initialization (JVMS §5.5)
- Polymorphic models (JLS §8.4.8)
- Single- and multi-dimensional arrays (JLS §10)
- Exceptions (JLS §11)
- Record Classes (JVMS §8.10)
- Type casting (JLS §5.5)
- Program arguments (JLS §12.1.4)
- Assertions (JLS §14.10)
- Dynamic Language Support (partially)
- Stream API (partially)
- Reflection (some features)
- java.io (partially)
- java.nio (partially)
- java.util.zip (partially)
- java.lang.System (most features)
See integration tests for broader examples of supported Java features.
Java Standard Library Classes
This project relies on standard library classes from the OpenJDK JDK 23 General Availability Release.
To run the Java code, you must have JDK 23 installed on your machine and ensure the JAVA_HOME
environment variable is properly set.
Getting Started
Prerequisites
Ensure the following are set up:
- A machine running Windows, macOS, or Linux
- JDK installed and configured (OpenJDK 23 is recommended)
- Rust installed and configured
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.
;
;
;
;
record implements TalkingUnit
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:
Assassin(100) says: Target acquired.
Assassin(110) says: Target acquired.
Soldier(2) says: For honor!
Army attack power is 222
License
rusty-jvm
is licensed under the MIT License.