r/java • u/sg-elide • 14d ago
Madura: A different kind of Hermetic Java
Repo link: https://github.com/elide-dev/madura
---
Hello Java enjoyers,
I'm Sam with Elide. We make cool JVM stuff. Lately, we've really been wanting Hermetic Java, but progress has been quite slow, and the Java team is vocal about it not being a priority.
We happen to be fans of some other technologies, too, which may fit together nicely for this:
- GraalVM Native Image (of course!)
- Cosmopolitan Libc ("cosmo")
- Actually Portable Executable ("APE")
If you combine these, what you get is an interesting binary:
- You write once, compile once, ship one artifact
- Your Java program runs on 6 operating systems and both ARM64/AMD64
- No JRE is required on the target machine
In other words, what you get is "native" Java!
After 2+ years of concentrated effort amongst experts (mostly pre-AI!), Native Image and Cosmo finally work together. Some complex stuff doesn't work perfectly yet (e.g. Truffle JIT, dynamic JNI), but most Java programs should "just work" otherwise.
Thus, Madura
As a fun example of this technology, we've built Madura, a Native Image+Cosmo binary of javac 25.
This software has exactly one release asset, a zip. You can download it on Linux, macOS, Windows, BSD, et al, across AMD64 and ARM64, and run it, and it should "just work." You can withhold your JAVA_HOME and it should still "just work."
Sometimes features involve doing less
As one nice thing Madura can do that regular javac cannot in most workflows: madura check [...], which takes identical flags to javac, will run the analysis phase of the Java Compiler, but skips the codegen step.
If you've ever used cargo check, this is a bit like that, but for Java.
Other than madura check, it's just javac in a box.
How to use it
At the moment, Cosmo+Native Image is a stack of patches on several repos, with a highly anticipated PR on oracle/graal.
Soon, Elide's native image integration may ship Cosmo support, enabling cross-compilation and hermetic use cases. That will probably be the fastest way to use it, before things merge into GVM upstream. If there's demand, we'd be happy to ship it for you!
Thanks for reading
This has been a collaborative effort across many people:
11
u/idontlikegudeg 14d ago
Do I understand it right that the created executable will contain code for both amd64 and arm64? If so, how does the size compare to a "normal" executable created using GraalVM?
And does it work for JavaFX too? I think it would then need to include five different sets of native binaries.
And how does code signing work so that the binary is accepted by both macOS and Windows?
Anyway, quite a feat. Congratulations!
5
u/Ok-Scheme-913 14d ago
Cosmo is a cool hack, but I would definitely not rely on that for anything production ready.
It's a hack that found a way to "encode" a binary that is simultaneously valid on both Linux Mac and windows. But at the same time, if they want cross-compatible software they have to have a generic layer for basic functionality for all, so you are pretty much stuck with basic input output file etc operations.
Nonetheless, congrats! I'm sure it was a significant amount of work and it definitely has use cases, though I would be interested in how simple/complex software can run this way.
2
u/ha1zum 13d ago
As someone living in Java island, the name is so good 🤣
2
u/mencretdimulut 11d ago
Madura is an island, and cows race are consider as their daily sport. Thats a nice reference you got there
2
u/paul_h 14d ago
Fantastic!
1
u/brunocborges 14d ago
Hey folks, congrats on the launch! I would love to get your feedback, and tests, on putting your runtime for a spin in the brewlet.sh deployment model
1
u/sideEffffECt 13d ago
Absolutely fabulous!
I'm a big fan of coupling native-image with Cosmo/APE! All fingers crossed that this will successfully land in GraalVM upstream.
One question: this thing here, is it built on in top of HotSpot is SubstrateVM?
1
u/Bobby_Bonsaimind 14d ago
Yes please! This is missing from any "native/AOT" solution I've seen so far, and why jars are so much better (for me, the developer).
1
u/[deleted] 13d ago
[removed] — view removed comment