4 releases (2 breaking)

0.3.0 Jun 28, 2025
0.2.1 Jun 4, 2025
0.2.0 Jun 2, 2025
0.1.0 May 26, 2025

#21 in Emulators

Download history 90/week @ 2025-05-21 132/week @ 2025-05-28 176/week @ 2025-06-04 9/week @ 2025-06-11 8/week @ 2025-06-18 120/week @ 2025-06-25 30/week @ 2025-07-02

170 downloads per month

MIT license

525KB
12K SLoC

rusty-jvm

Platform Crate Docs Build Status License codecov dependency status

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

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.

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Demo {
    public static void main(String[] args) {
        ControlGroup controlGroup = new ControlGroup();
        controlGroup.addUnits(new Zealot(), new DarkTemplar(), new Unit() {
            @Override
            public int damage() {
                return 4;
            }
        });

        int groupAttackPower = controlGroup.damage();
        System.out.print("Group attack power is ");
        System.out.println(groupAttackPower);
    }
}

interface Unit {
    int damage();
}

abstract class AbstractUnit implements Unit {
    public AbstractUnit() {
        System.out.println(say());
    }
    protected abstract String say();
}

class Zealot extends AbstractUnit {
    @Override
    public int damage() {
        return 8;
    }
    @Override
    public String say() {
        return "We embrace the glory of battle!";
    }
}

class DarkTemplar extends AbstractUnit {
    @Override
    public int damage() {
        return 45;
    }
    @Override
    public String say() {
        return "Battle is upon us!";
    }
}

class ControlGroup implements Unit {
    private final List<Unit> units = new ArrayList<>();
    public void addUnits(Unit... units) {
        this.units.addAll(Arrays.asList(units));
    }
    @Override
    public int damage() {
        int totalAttackPower = 0;
        for (Unit unit : units) {
            totalAttackPower += unit.damage();
        }
        return totalAttackPower;
    }
}

Steps to Run

  1. Compile the program using the Java compiler:

    javac -d . Demo.java
    
  2. Run it using rusty-jvm:

    cargo run -- Demo
    

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.

Dependencies

~9–24MB
~269K SLoC