JVMRS
A Java Virtual Machine implementation in Rust, featuring Cranelift JIT, AOT to native object files, generational GC, and multiple compilation backends.
Why JVMRS?
Compared to HotSpot, OpenJ9, and GraalVM, jvmrs differentiates with Rust-native design and unique capabilities:
| Capability | HotSpot / OpenJ9 / GraalVM | JVMRS |
|---|---|---|
| Language | C++ / Java | Rust – memory safety, zero-cost abstractions |
| JIT backend | C2 / Graal / Eclipse OMR | Cranelift – Rust-native, permissive license |
| Inline Caching | Yes (HotSpot) | Yes (JVMRS) – 3-5x faster virtual calls |
| TLAB | Yes (HotSpot) | Yes (JVMRS) – 2-3x faster allocation |
| Compressed oops | Yes (HotSpot, 64-bit only) | Yes (JVMRS) – 16-bit encoded refs, 50% per-slot savings |
| AOT output | GraalVM native-image (binary) | Object files (.o) – link with any C toolchain |
| WebAssembly | Limited / experimental | WASM emission – run Java in browsers |
| Java ↔ Rust interop | JNI only | Direct polyglot – shared objects, no JNI |
| Embedded / no_std | Not supported | no_std targets – microcontrollers, bare-metal |
| SIMD | Auto-vectorization | Explicit SIMD – Rust core::arch |
| Embedding | Heavy footprint | C API – embed as a library in any app |
| Truffle-style API | GraalVM proprietary | Open implementation – language-agnostic runtime |
| REPL | JShell (limited) | Full REPL – interactive JVM exploration |
| Property Tests | Limited | Comprehensive – 30+ property-based tests |
Use jvmrs when you need: embeddable JVM, Java→WASM, Rust/Java interop, AOT to .o files, or a Rust-based JVM for research and tooling.
Installation
Add to your Cargo.toml:
[]
= "0.1"
For optional features (LLVM IR, WebAssembly, etc.):
[]
= { = "0.1", = ["wasm"] }
Quick Start
# Clone and run
# Run example classes (examples/ contains precompiled .class files)
# Or compile your own Java and run
Usage
Run a class
# Run main class (resolves via classpath)
CLI options
| Option | Description |
|---|---|
--aot <output> |
AOT compile class to .o file instead of executing |
--no-jit |
Disable JIT; interpreter-only |
--jit-threshold <n> |
Invocations before JIT compile (default: 100) |
--llvm |
Emit LLVM IR to stdout (requires --features llvm) |
--help, -h |
Show help |
Environment variables
| Variable | Description |
|---|---|
JVMRS_DEBUG |
Enable debug logging |
JVMRS_TRACE |
Enable trace logging |
Examples
# Run with default JIT
# Run without JIT
# AOT compile to object file
# Emit LLVM IR (requires: cargo build --features llvm)
# Custom JIT threshold
Examples
Example Java programs in examples/:
HelloWorld.java
Calculator.java
SimpleMath.java
Running the examples
# Precompiled examples (Minimal, TestGetStatic, TestLdc)
# Or compile and run your own
Rust calling Java (polyglot)
Interactive REPL
# Start interactive REPL (requires repl feature)
# Example REPL commands:
REPL Commands
| Command | Description |
|---|---|
load <class> |
Load a class |
class <class> |
Show class information |
method <class> <name> |
Show method information |
exec <class> [method] |
Execute a method |
new <class> |
Create a new instance |
get/set |
Get/set field values |
state |
Show JVM state |
help |
Show help |
exit |
Exit REPL |
Features
Core
- Class file parser, constant pool, stack-based interpreter
- Generational GC with parallel sweep
- Arrays, strings, inheritance, interfaces
- Inline Caching – Optimized virtual method dispatch (3-5x faster)
- Thread-Local Allocation (TLAB) – Fast, lock-free object allocation (2-3x faster)
- Compressed Oops – 16-bit encoded references for memory-constrained environments (50% per-slot savings)
- Reflection –
Interpreter::new_instance,get_field_value,set_field_value,invoke_method,get_object_class - Serialization – Binary format for
HeapObjectandValue(JVRS format) - Property-Based Tests – 30+ comprehensive property tests for correctness
Compilation
- Cranelift JIT – bytecode-to-native for hot methods
- Tiered compilation – interpreter → baseline → optimized
- AOT – compile to
.ovia cranelift-object - LLVM IR (
--features llvm) – export to LLVM - WebAssembly (
--features wasm) – emit WASM
Optional (feature-gated)
ffi– C API for embeddinginterop– Java/Rust polyglotasync– tokio async I/Osimd– SIMD array opstruffle– GraalVM-style language API
Building
Testing
Test Coverage
- Unit Tests: 68+ tests covering all core modules
- Property-Based Tests: 30+ tests verifying invariants across 20+ properties
- Benchmarks: Comprehensive suite covering 14 benchmark categories
- Integration Tests: End-to-end testing with example classes
Test Features
- Arithmetic operations (commutative, associative, identity)
- Bitwise operations (De Morgan's laws, idempotence)
- Array operations (length preservation, write/read)
- Stack operations (push/pop reversibility)
- String operations (concatenation associativity)
- GC correctness (live object preservation)
- Method invocation consistency
- Object identity and null handling
Documentation
- API Documentation
ARCHITECTURE.md– Design and componentsIMPLEMENTATION_SUMMARY.md– Performance enhancements and featuresdocs/api-reference.md– Complete API reference with examplesdocs/performance-tuning.md– Performance optimization guidedocs/polyglot-programming.md– Java/Rust interop guidedocs/competitive-differentiation.md– How JVMRS differs from other JVMsspec.md– Technical specificationTODO.md– Roadmap
License
Licensed under either of MIT or Apache-2.0 at your option.