r/java • • 28d 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:

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:

  • @ahgamut deserves the most credit
  • @jart, the legendary author of Cosmo and APE
  • Many members of the GraalVM team whom helped with review and advice
80 Upvotes

34 comments sorted by

View all comments

Show parent comment

1

u/paul_h 28d ago

I'm involved with a young language where we're embedding others and then sharing variable space and indeed a nascent IPC. That suits Lua and QuickJS better than many others, but in the spirit of #whatTheHeck Java too, maybe :)

1

u/sg-elide 28d ago

That’s awesome! But elide’s polyglot dispatch doesn’t involve IPC, I presume that’s what you’re referring to.

In our case, languages are parsed into their own AST or bytecode (depending on language), then operate on the same heap, sharing a GC, JIT, and threading semantics.

This has drawbacks, and complexities, for sure: for example, if Python calls into JavaScript, it must engage the GIL, so you lose some threading performance without special care.

But it also has benefits: technically you can create a class in TypeScript, and extend it from Python. You can exchange functions and complex types. There’s no serialization in this model, and no IPC.

Hoping I understood your comment’s context correctly

1

u/paul_h 28d ago

Yeah, we made the IPC, we'd be reaching into the guest language (in this case Madura-Java would be the guest) and thunking in hooks. There's a ton of complexity around what-is-a-string types of mismatches that have to get squared between alien language worlds of course.

1

u/sg-elide 28d ago

I should also say: we love Truffle very much as a framework and it might make a good fit for your use case, too. Lua has several implementations. Lua is blessed with many good implementations, though, including LuaJIT, and QuickJS is also very good.

But if you get tired of IPC and want your Java back, Truffle can accomplish this quite well.

Despite being written in Java/Kotlin (and a bit of Rust), Elide ships only as a binary, no JVM or JRE required. So we get all the benefits of build time Java (seamless coverage, null safety, rich Maven ecosystem) without the JRE needed for our users. So choosing Truffle won’t necessarily foist one on your users either.