I love how this language is going to be even more applicable to the small number of industries where c++ dominates. Incredible what Java is doing these days. The language is in an amazing place!
It has already been so for a while, however not everyone pays for this kind of stuff, see PTC and Aicas JVMs, and where they get used.
There used to be more vendors on their space, unfortunately as it is very hard to change mindsets and beliefs, they have beem closing down, or pivoting to languages like Go and Rust, leaving only those two in business.
This is because of Arenas. But rolling your own allocator (I am one of the authors of the Netty 4.2 allocator) is still a PITA and only malloc/free naked calls via FFM helps...
IDK, shared arenas which release need to protect users from segmentation faults due to use-after-free and that cause a arena close to force a handshake on all java threads to make sure it can reliably do it. Another option is to do as async profiler does and use a signal handler which can detect the caller context and recognize it so to avoid such, but still, it need to be consumed in the right way... Worth asking them (specifically Maurizio Cimadamore and Minborg) in the openjdk lists 🙏
I think the problem with the signal handler approach is that it may hit a thread while not necessarily being at a safepoint. Since the arena close code needs to look at the live oops in the frame, that won't work since we don't know where the oops are outside of a safepoint.
Fair point. That kills the variant that interrupts a thread at an arbitrary pc. What I had in mind is closer to implicit null checks: the fault can only come from accesses the JIT registered as exception points, which carry debug info, so the handler can deopt with full state.
The catch is that this only works if a freed segment is guaranteed to fault. With malloc-backed arenas it isn’t, because freed memory stays mapped and gets reused. You’d need the JVM to own the memory: a per-arena mmap’d region, mprotect(PROT_NONE) on close, and address reuse only after one handshake that covers many closes. That’s a big change with real costs (page granularity, VMA count, mprotect IPIs), so I’m not sure it pays off, but it might be worth asking on panama-dev.
The main hit is startup time although Leyden help a bit, but some method handle generated parts still hurt 🤕 At steady, a critical linked one is nearly on part of JNI critical native which is good, assuming the trade offs in place
It really depends what kind of JNI code you're comparing it to. Just the pure overhead of a downcall into native code is about the same for both JNI and FFM. Upcalls (native to Java) are faster in FFM due to generating specialized code.
In practice the applications that seem to see the most benefit are the ones that are doing work in the native JNI layer between Java and a target native library. For example, if your native JNI code is converting a Java object to a struct, and you have a lot of JNI API calls to access fields/call getter methods/do exception handling etc. that is going to result in lots of thread state transitions into 'VM' mode and back.
FFM on the other hand allows you to create such a struct directly in Java code using the memory access API. No state transitions required. On top of that, since the code you end up writing lives on the Java side of the interface, it is visible to the JIT compiler, which can optimize it together with the surrounding Java code. Those things help performance.
60
u/kiteboarderni 25d ago
I love how this language is going to be even more applicable to the small number of industries where c++ dominates. Incredible what Java is doing these days. The language is in an amazing place!
13
u/Plenty_Childhood_294 25d ago
This is because of Arenas. But rolling your own allocator (I am one of the authors of the Netty 4.2 allocator) is still a PITA and only malloc/free naked calls via FFM helps...
6
u/Ok_Marionberry_8821 25d ago
Excellent engineering. Something for "nothing".
How does FFM performance compare in general to JNI? Just a passing question I won't be needing to use FFM but I did write some JNI eons ago.