cat-jvm
A rust based JVM targeted at embedded environment with a minimum 8MiB of RAM and 16MiB of flash. Supports majority of Java SE standard libararies and features up to Java 25 or class file version 69.
Summary
| Latest Version | Unknown |
|---|---|
| License | Unknown |
| CI Status | Failing |
| Stars | 1 |
| Forks | 0 |
| Open Issues | 0 |
| Last Commit | 2026-11-22 |
| Downloads | 0 |
| Last Indexed | 2026-11-23 09:07 |
Tags
Installation
nimble install cat-jvm
choosenim install cat-jvm
git clone https://gitlab.com/cat-jvm-development-team/cat-jvm
OS Compatibility
| Platform | Linux | macOS | Windows | FreeBSD | OpenBSD | NetBSD | Android | iOS | WASM | Embedded |
|---|---|---|---|---|---|---|---|---|---|---|
| cat-jvm | - | - | - | - | - | - | - | - | - | ✓ |
Source
| Repository | https://gitlab.com/cat-jvm-development-team/cat-jvm |
|---|---|
| Homepage | https://gitlab.com/cat-jvm-development-team/cat-jvm |
| Registry Source | gitlab |
README
CatJvm
CatJvm is an experimental, small Rust JVM aimed at ESP32-class devices running
ESP-IDF/FreeRTOS. The interpreter core is platform-neutral: clocks, sleeping,
randomness, console output, networking, HTTP and filesystem operations are
injected through the Platform trait.
Current milestone
This repository is a working JVM foundation, not a claim of Java SE compatibility. It currently provides:
- strict
.classparsing for class-file versions 45–69 (Java 1.1–25); - lazy
.jar/ZIP loading with Stored and Deflate entries, CRC validation, manifestMain-Class, traversal protection, and a 2 MiB per-entry limit; - a stack bytecode interpreter for constants, locals, integer/long arithmetic, branches/switches, calls, fields, objects, arrays, casts, and returns;
- a bounded mark/sweep Java heap with a default and enforced minimum of 4 MiB;
- a bounded frame stack and loaded-class table;
- host and ESP-IDF platform adapters, with native clock, sleep, random, output, and socket seams;
- initial native methods for
Object,System,Thread,String,Math,PrintStream,Random, and compactSockethooks. - Java 25 JNI for C and C++ libraries, including static firmware linking, Java callbacks, GC-aware references, native-thread attachment, and the Invocation API. Custom class loaders isolate same-name definitions and native bindings. Collecting a loader releases its libraries. See the JNI guide and compatibility limits.
- virtual threads with resumable Java stacks, JNI thread identity and a bounded pool of FreeRTOS carriers (two by default). On multicore targets, carriers can execute arithmetic and other frame-local bytecodes in parallel.
- reflection for application classes, including invocation, fields, constructors, generics, annotations, proxies, and Java 25 record/sealed/nest metadata. Built-in declarations load from a compressed Java 25 metadata catalog on demand. See reflection status for tested behavior and remaining requirements; full Java 25 reflection conformance is not yet achieved.
- Java lambdas, method references, and modern string concatenation through the
bootstrap formats emitted by
javac; executable method/variable handles, handle adapters and loops, hidden classes, StackWalker and proxy default methods. - Array and collection utilities, backed sublists/reversed/sequenced views, checked/synchronized/unmodifiable wrappers, Vector/Stack, HexFormat, StringJoiner/StringTokenizer, functional combinators, custom collectors, spliterators and bounded parallel streams/array operations.
- Common UTF-16 and Unicode 16 text APIs, locale case conversion, normalization, bounded advanced regex, big-number arithmetic/primality, regional date/time, legacy calendars and date/number/message formatting.
- File/buffered/scanner/random-access I/O, NIO buffers, mapped files and file channels, filesystem traversal/attributes/symlinks/watch services, ZIP/GZIP/zlib, manifests, Base64 streams and common Java object serialization.
- Executor pools, scheduling, concurrent collections, locks/conditions, barriers/phasers, CompletableFuture composition/timeouts, process management, shutdown hooks, weak/soft/phantom references and cleaners. Concrete thread pools, ForkJoinPool work stealing, completion services, StampedLock, Flow/SubmissionPublisher, concurrent skip lists/deques/transfer queues and atomic arrays/stamped references are included.
- Resource and service loading, resource bundles and logging; TCP, UDP, multicast and selectors; asynchronous HTTP/2 with streaming response bodies and WebSocket messaging.
- HMAC, AES, RSA/EC/Ed25519 keys and signatures, X.509 certificates, JKS/PKCS12, TLS sockets/contexts and mutual authentication on supported host platforms.
- Application enums/records, interning and throwable stack traces with causes/suppression. These remain tested API subsets; see the coverage and explicit limitations.
- Optional hardware APIs through JNI: GPIO and edge interrupts, UART, I2C, ADC, DAC where available, USB serial device/raw host, and up to 32 PWM outputs sharing one hardware timer. A C function dispatcher selects the platform drivers.
- Optional Bluetooth Low Energy API with
Bluetooth.getBluetooth(), scanning/advertising, GATT client/server objects and notifications through JNI and the same dynamic C dispatcher.
Full coverage of every public class in java.lang, java.net, and java.util
requires additional class-library behavior, verification, reflection, platform
integration and native methods. Those packages contain hundreds of classes. CatJvm is
architected so that library bytecode can live in a boot JAR and platform natives
can be registered without coupling them to the interpreter. See
docs/COMPATIBILITY.md for the exact support contract.
Try it on the host
cargo test
cargo run -- inspect app.class
cargo run -- run app.class one two
cargo run -- run app.jar
cargo run -- run app.jar --heap-mib 16
cargo run -- run app.jar --virtual-thread-carriers 1
cargo run -- run app.jar --add-opens java.base/java.lang.invoke=ALL-UNNAMED
The differential tests for JNI, library APIs, lambdas, and reflection use JDK 25
(javac, jar, and java). Test tooling verifies the reference runtime is
OpenJDK 25; set CATJVM_JAVA_HOME to select its installation explicitly, for
example CATJVM_JAVA_HOME=/usr/lib/jvm/java-25-openjdk-amd64 cargo test.
The Linux JNI tests also use a C/C++ compiler and the JDK headers. Networking
fixtures use local loopback sockets; the HTTPS certificate-rejection fixture
also requires the openssl command.
Compile a small example with Java 25:
javac --release 25 examples/Hello.java
cargo run -- run examples/Hello.class
Embedded memory budget
The hardware target is 16 MiB flash and 8 MiB usable RAM. The default
Java heap remains 4 MiB within that RAM budget. On hardware
with more usable RAM, select a 4–16 MiB managed heap with --heap-mib or
VmConfig::embedded_8mb().with_heap_mib(16)?. A 16 MiB heap requires more
than 16 MiB of total usable RAM.
| Area | Budget |
|---|---|
| Managed Java heap | 4 MiB, including object pages and library payloads |
| Loaded classes, JAR indexes, linked sites, mirrors and scheduler records | 2 MiB on-demand limit, up to 512 loaded classes; separate from the unchanged 4 MiB Java heap |
| Java frames | 512 KiB shared across active and suspended stacks, up to 128 frames per thread |
| ESP-IDF, FreeRTOS, lwIP, native stacks, allocator, and parsing scratch | remaining RAM |
The heap counts reserved slot pages, capacities of object buffers, collection
storage, and charged stream work buffers. The collector traces roots without a
separately allocated mark queue. Load JAR bytes from flash and use
Vm::memory_usage() to check the runtime counters. These counters do not cover
the whole firmware allocation footprint. TLS state, native platform-thread
stacks and arithmetic/regex parsing scratch also consume separate RAM. Use ESP-IDF memory measurements
to validate the 8 MiB board budget with the intended network configuration.
The retained-metadata limit increased from 1 to 2 MiB for the expanded class library. It is allocated on demand: the larger limit does not reserve 2 MiB at startup. The Java heap default remains 4 MiB. Explicit smaller metadata budgets still fail with a controlled allocation error when their limit is reached.
Measured ESP32-S3 footprint
This measurement uses the default API build without the optional hardware
feature. Hardware drivers and application buffers require a separate measurement.
The expanded API build was measured on 22 November 2026 for
xtensa-esp32s3-espidf, with the default
4 MiB Java heap and 2 MiB metadata limit, 8 MiB quad PSRAM and 16 MiB
flash. Both the CatJvm firmware and a matching Rust/ESP-IDF baseline booted
successfully in Espressif QEMU.
The first full-firmware run hit a double exception during carrier startup;
an identical-binary replay completed all scenarios. Both logs are retained.
The cause of that intermittent failure is unresolved.
The fixture did not initialize Wi-Fi or networking. These are emulator
measurements, with physical-board validation still required.
The build used ESP-IDF 5.5.5, Espressif Rust 1.97.0-nightly, QEMU
9.2.2 (esp_develop_9.2.2_20260417), and OpenJDK 25.0.5.1 for the Java
probe. Release settings were opt-level = "s", LTO, one codegen unit and
aborting panics. Both builds used identical SDK configurations: a 64 KiB main
task stack, a 1 KiB PSRAM allocation threshold and a 160 KiB internal-memory
reserve. CatJvm retained its default two virtual-thread carriers, each
requesting a separate 64 KiB native stack.
| Measurement | CatJvm measurement firmware | Increase over baseline |
|---|---|---|
Application flash (app.bin) |
8,239,936 B (7.86 MiB) | 7,867,968 B (7.50 MiB) |
| Static internal RAM, including RAM-resident code | 73,555 B (71.8 KiB) | 4,376 B (4.3 KiB) |
The increase includes CatJvm, its reachable dependencies, a 3,250-byte Java
probe JAR and measurement code. The bootloader occupies another 20,832 bytes;
bootloader and partition-table storage are outside the application figure.
Both builds also allocate 56 bytes of RTC memory. Flash figures use the actual
application image; the padded 16 MiB emulator image represents flash capacity.
Static RAM figures were checked against the final Rust-linked ELF and map.
The factory application partition starts at 0x10000 and spans 16,711,680 B
(0xff0000) in the 16 MiB flash layout. After the measured firmware,
8,471,744 B (8.08 MiB) remain in that partition. This layout uses a single
application slot; OTA or separate JAR/data partitions would share that space.
Runtime figures below are sampled additional allocator usage, combining internal RAM and PSRAM free-byte changes from the same CatJvm firmware's ESP-IDF boot checkpoint. SDK startup allocations, including the main task stack, are already present at that checkpoint.
| Scenario | Additional runtime RAM |
|---|---|
| Empty VM | 4,780 B (4.7 KiB) |
| Small Java workload, before explicit GC | 19,648 B (19.2 KiB) |
| Two active carriers | 165,624 B (161.7 KiB) |
| Near-full Java heap, retained allocation | 4,195,912 B (4.00 MiB) |
The Java heap reached 4,178,045 of 4,194,304 bytes (99.6%). The next
oversized allocation returned OutOfMemory, and clearing the retained array
followed by GC reclaimed its storage. The carrier and heap-pressure scenarios
ran in separate fresh VMs. Their RAM samples are not a combined peak or a
worst-case RAM ceiling; the 4 MiB heap remains an on-demand accounting limit.
The fixture validates these workloads; it does not exercise every compiled
API or measure Wi-Fi, networking or TLS workloads.
Generated artifacts from this run are stored locally under
target/esp32-s3-footprint/, including summary.txt, the measurement fixture,
firmware images, verified linker maps, SDK configurations and UART logs.
ESP32 families
The core does not contain chip-specific code. Build the esp-idf feature from
an ESP-IDF Rust project generated for the selected device. The same source model
supports the ESP32, S2, S3, C2, C3, C6, H2, and P4 targets supported by the
esp-rs ESP-IDF toolchain. Chip target selection is a build concern; a single
firmware binary cannot run on every architecture.
See docs/ESP32.md for integration and target commands.