Skip to content

Latest commit

 

History

1,824 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ristretto

ci Documentation Code Coverage Benchmarks Latest version License Semantic Versioning

Embeddable Java Virtual Machine and Java compiler implementation.

Getting Started

Try the Java playground to compile and run Java entirely in your browser, without installing a JDK. JShell evaluates Java snippets, expressions, and methods in a persistent interactive session.

The Ristretto java runtime can be installed using the following methods:

Linux / MacOS

curl --proto '=https' --tlsv1.2 -LsSf https://github.com/theseus-rs/ristretto/releases/latest/download/ristretto_java-installer.sh | sh

Windows

irm https://github.com/theseus-rs/ristretto/releases/latest/download/ristretto_java-installer.ps1 | iex

For more information, and additional installations instructions (cargo, homebrew, msi), visit the ristretto site.

Run a compiled HelloWorld.class in the current directory using its class name (without .class):

java -cp . HelloWorld

To embed the JVM in a Rust application, add the dependencies:

cargo add ristretto_vm
cargo add tokio

Place HelloWorld.class in the current directory and use this in src/main.rs:

use ristretto_vm::{ClassPath, ConfigurationBuilder, Result, VM};

#[tokio::main]
async fn main() -> Result<()> {
    let configuration = ConfigurationBuilder::new()
        .class_path(ClassPath::from(&["."]))
        .main_class("HelloWorld")
        .build()?;

    let vm = VM::new(configuration).await?;
    vm.invoke_main::<&str>(&[]).await?;
    Ok(())
}

Run the application with cargo run.

The javac compiler is available as a separate Cargo package:

cargo install ristretto_javac
javac -d classes HelloWorld.java

Rust applications can also embed and reuse the compiler:

use ristretto_vm::{Compiler, CompilerError};

#[tokio::main]
async fn main() -> Result<(), CompilerError> {
    let compiler = Compiler::default().await?;
    compiler.compile(&["-d", "classes", "HelloWorld.java"]).await?;
    Ok(())
}

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.
  • A javac-compatible CLI and reusable file or in-memory Rust compiler API.
  • Interpreter support for all Java byte codes including invokedynamic.
  • Fully asynchronous, non-blocking execution using Rust async/await for:
    • java.lang.Process
    • 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.
  • Native Maven POM (Project Object Model) parsing.
  • Asynchronous JVM dependency resolution with graph introspection and extensible artifact storage.

Limitations

Runtime Native Methods

The Java runtime requires hundreds of native methods. This project aims to provide Rust equivalents for these methods. If a native method is called that is not implemented, the program throw a java.lang.UnsatisfiedLinkError. Please submit a pull request, or open an issue if you need a specific native method implemented.

Security Manager

Support for the Security Manager is not implemented and there are no plans to implement it. The security manager has been deprecated; see: JEP 411

System.getSecurityManager() will always return null, and System.setSecurityManager() will throw an exception.

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

Java Virtual Machine

Topics

Resources

Security policy

Stars

66 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages