CratonVM

CratonVM

CratonVM

CI License Rust

A Java Virtual Machine written in Rust, with a custom x86-64 JIT and an opt-in automatic GPU fast path for a documented subset of Java kernels.

CratonVM boots against a real JDK when one is present (JAVA_HOME, CRATONVM_JAVA_HOME, or java on PATH) and runs fully standalone when it isn't — its own Rust implementations of the Java standard library mean no JDK install, no rt.jar, one self-contained binary.

Highlights

  • Custom x86-64 JIT — tiered compilation (interpreter → C1 → C2), OSR, LICM, bounds-check elimination, AVX2 SIMD, precise stack maps. Experimental AArch64 backend.
  • Automatic GPU fast path — supported pure static array kernels can run on NVIDIA GPUs without API changes. Eligibility is intentionally narrow and unsupported shapes fall back to CPU (see below).
  • Generational GC — young/old generations, card table, selective promotion. The moving/compacting (Cheney) young gen is the default, with CRATONVM_NO_MOVING_YOUNG as the compatibility opt-out; a cycle that cannot prove complete root coverage diverts to the non-moving sweep rather than relocating (see ARCHITECTURE.md). Opt-in region-based G1 (-XX:+UseG1GC).
  • Real frameworks run — Spring, Spring Boot, Tomcat, Netty, Hibernate, Hibernate Reactive, Quarkus, H2 Database boot and pass large test suites.
  • Rust implementation — Rust removes many ambient memory hazards, but the VM, JIT, GC, FFI, I/O, AWT, CUDA, and JFR contain reviewed and still-being- audited unsafe regions. See SECURITY.md.
  • JNI & embedding — JNI Invocation API, a stable C-ABI library (libcratonvm), and a Rust facade (cratonvm-embed).
  • Observability & hardening — Java Flight Recorder, bytecode verification, opt-in I/O confinement and network egress policy (docs/SECURITY_HARDENING.md).
  • Provenance instrumentation (--jdk-only) — an internal diagnostic that makes every compatibility substitution a counted, attributed event, so the gap between "runs on CratonVM" and "runs on the real class bytes" is measurable rather than assumed. Not a supported runtime mode; --real-jdk stays the default (see below).

Performance

CPU, vs HotSpot JDK 25 C2 — same flags both sides, checksum-verified against HotSpot on every run (zero mismatches):

BenchmarkJDK 25 C2CratonVMRatioCV (CratonVM)
Arithmetic (2B ops)1,852 ms3,601 ms1.94x0.6%
Fibonacci(44)1,449 ms5,059 ms3.49x0.6%
Sieve (100K × 20K)2,333 ms2,360 ms1.01x2.0%
Matrix 1280×12802,106 ms2,094 ms0.99x0.2%
HashMap (10M put/get)983 ms2,049 ms2.08x0.6%
String/Regex (100K)50 ms200 ms4.00x0.9%
Binary Trees (depth 18)176 ms1,700 ms9.66x1.1%

Two rows (Matrix, Sieve) are at parity with HotSpot C2. Full methodology, per-row footnotes (HotSpot's Sieve bimodality, the Fibonacci gap), and historical context: BENCHMARK.md.

GPU offload, vs HotSpot C2 and TornadoVM 4.0.1 (RTX 2060, N = 2²⁴, warm, full H2D+kernel+D2H round-trip, checksums bit-identical to HotSpot):

KernelHotSpot C2TornadoVM GPUCratonVM GPUvs HotSpotvs TornadoVM
Integer div-chain (48 divs/elem)2,146 ms26 ms11 ms195x2.4x
Double div-chain (64 divs/elem)1,780 ms128 ms95 ms18.7x1.3x
128 multiply-adds/elem (data-dependent multiplier)1,300 ms27 ms8 ms163x3.4x
Dot-product reduction (int·int → long, x300/elem)1,172 msunimplemented12 ms98xn/a
Ray tracer kernel, 7680×4320 (33.2M px)837.1 ms24.29 ms12.29 ms68x2.0x

Ray tracer rows are 6 interleaved rounds each (arm order alternated per round to cancel drift), full H2D+kernel+D2H, checksums bit-identical to HotSpot; the 3840×2160 row is pooled over two independent 6-round passes (12 rounds total, craton faster in all 12) run 30 minutes apart, which agreed within noise. The kernel is the reduced proxy (bench-gpu/RayTracerKernel.java), documented in gpu/raytracer-vs-tornadovm-RESOLVED-20260821.md in the internal tree, not the full apps/TornadoVM-Ray-Tracer app (whose real kernel — reflections, soft shadows, a skybox — needs dynamic-length scene loops neither engine's analyzer admits yet). The margin over TornadoVM shrinks with resolution (2.5x → 2.2x → 2.0x → 1.85x, the last at 11520×6480 / 74.6M pixels, 6/6 rounds) as CratonVM's fixed per-launch cost advantage amortises away, leaving a smaller but still consistent per-pixel-throughput edge. Every frame from 160×120 to 11520×6480 is bit-identical to HotSpot's.

Unlike TornadoVM, the supported automatic path needs no @Parallel annotations or TaskGraph API — within a deliberately narrow eligibility subset, not a general promise that arbitrary Java runs on the GPU. Full results, extra sizes, and methodology: BENCHMARK.md and docs/gpu/README.md.

What to build on

Boots, runs, and passes large real-world test suites:

  • Spring / Spring Boot
  • Tomcat / Netty
  • Hibernate / Hibernate Reactive
  • H2 DB / PostgreSQL driver
  • Apache Commons Math
  • Bouncy Castle Java

Java Version Support

VersionKey features
Java 8Full language support, lambdas, streams
Java 11Nest-based access control
Java 17Records, sealed classes
Java 21Pattern matching for switch, virtual threads, sequenced collections
Java 25Stream gatherers, scoped values, structured concurrency

Quick Start

Build (Rust 1.80+):

cargo build --release -p cratonvm-cli

Compile and run a class:

javac HelloWorld.java
./target/release/cratonvm -cp . HelloWorld

Run a JAR:

./target/release/cratonvm --jar app.jar

Bigger heap, G1 collector, program arguments:

./target/release/cratonvm -Xmx4g -XX:+UseG1GC -cp "classes:lib/util.jar" com.example.Main arg1 arg2

Command-Line Reference

cratonvm [OPTIONS] <CLASS_NAME> [ARGS]...
cratonvm [OPTIONS] --jar <FILE.jar> [ARGS]...
OptionDescription
-c, -cp, --classpath <PATH>Directories and JARs to search. Separator: : (Unix) / ; (Windows).
--jar <FILE>Execute a JAR (main class from apps/META-INF/MANIFEST.MF; classpath from the JAR and its manifest Class-Path).
-Xmx<SIZE>, --Xmx <SIZE>Maximum heap size (256m, 1g, 8g). Default: 256 MB.
-XX:+UseG1GCUse the region-based G1 collector (experimental; generational is the default).
-D<name>=<value>Set a Java system property.
--verbose:classClass-loading trace to stderr.
--verbose:gcGC activity to stderr.
--nojitInterpreter only (diagnosis / safety fallback).
--noverify, --Xverify <MODE>Bytecode verification policy (none / remote / all).
--java-home <PATH>Boot from a specific JDK's java.base.
--synthetic-jdkForce the built-in Rust standard library even when a JDK is detected.
--jdk-onlyDiagnostic strict mode: real JDK class bytes are authoritative. Implies --real-jdk, conflicts with --synthetic-jdk. May fail where the default passes — see below.
--Xbootclasspath <PATH>Override the bootstrap classpath (advanced).
-V, --version / --helpVersion / full option list.

Every command above is verified against the current binary. --gpu and the other GPU options require a --features gpu-driver build — see docs/gpu/README.md.

JDK-only mode (--jdk-only)

An internal diagnostic, not a supported runtime mode — --real-jdk remains the default. It asks the VM to treat real JDK class bytes as authoritative and report every compatibility substitution it would otherwise make silently, so it is expected to fail on programs that pass under the default. A/B a program to see what it depends on:

./target/release/cratonvm -cp . MyApp                                   # default: --real-jdk
./target/release/cratonvm --jdk-only --jdk-only-report report.json -cp . MyApp

Details: docs/jdk-only-migration.md (operator guide); the rest of the JDK-only docset is indexed from docs/README.md.

Limitations

  • AWT/Swing are headless (no on-screen rendering); JavaFX is out of tree.
  • Reflection and JNI cover the common paths; some edge cases (C-varargs JNI forms, full foreign-thread attach) are partial.
  • Cryptography is best-effort and not constant-time everywhere — see docs/CRYPTO_STATUS.md.

Documentation

Building & Testing

cargo build --release          # full workspace
cargo test --workspace         # unit + integration tests
bash regression-suite/run.sh   # fast HotSpot-differential regression suite

Contributing

See CONTRIBUTING.md. Architectural orientation lives in ARCHITECTURE.md; required merge signals are defined by release readiness and the CI workflows.

License

Apache-2.0 — see LICENSE. CratonVM is an independent implementation and is not derived from OpenJDK sources; see THIRD-PARTY-NOTICES.md and TRADEMARKS.md.