ristretto_vm 0.32.0

Java Virtual Machine
Documentation

Ristretto VM

Documentation Code Coverage Benchmarks Latest version License Semantic Versioning

Ristretto VM is a Java Virtual Machine implementation written in pure Rust. It executes Java bytecode by interpreting class files loaded through the Ristretto classloader.

Features

  • Standard runtime classes backed by LTS versions of AWS Corretto.
  • Flexible class loading from directories, JARs, JMODs, JImage files, and URLs.
  • Built-in support for reading, writing, and strictly verifying Java bytecode.
  • Interpreter support for all Java byte codes including invokedynamic.
  • Fully asynchronous, non-blocking execution using Rust async/await for:
    • java.lang.Thread
    • java.io & java.nio
    • java.net
  • A low-pause, concurrent, and parallel mark-and-sweep garbage collector.
  • Parallel Just-In-Time (JIT) compilation for x86-64, aarch64, s390x, and riscv64 architectures.
  • WebAssembly (WASM) compilation support for single-threaded edge and browser deployments.

Examples

use ristretto_vm::{VM, Configuration, ConfigurationBuilder};
use ristretto_classloader::ClassPath;

#[tokio::main]
async fn main() -> ristretto_vm::Result<()> {
    // Create a VM configuration
    let configuration = ConfigurationBuilder::new()
        .class_path(ClassPath::from(&["/path/to/classes"]))
        .build()?;

    // Create the VM instance
    let mut vm = VM::new(configuration).await?;

    // Execute main method of a class
    let _ = vm.invoke_main(&[] as &[&str]).await?;
    Ok(())
}

Feature flags

ristretto_vm uses feature flags to address compile time and binary size uses.

The following features are available:

Name Description Default?
audio Enables javax.sound support Yes
startup-trace Enables startup tracing No
tls-native-tls Enables Native TLS support No
tls-rustls-aws-lc-rs Enables Rustls with the AWS-LC crypto provider No
tls-rustls-ring Enables Rustls with the Ring crypto provider Yes
url Enables URL class path entries No

The TLS backend features are alternatives. To select a non-default backend without compiling Ring, disable default features and enable tls-native-tls or tls-rustls-aws-lc-rs, together with any other required features such as audio.