JLang icon indicating copy to clipboard operation
JLang copied to clipboard

faster interaction with C code?

Open Mis012 opened this issue 4 years ago • 1 comments

Hi, does this eliminate the performance penalty for JNI calls? (since you're not jumping into / out of a VM) if not, does this enable a different option for implementing Java APIs in C?

Mis012 avatar Jan 22 '21 13:01 Mis012

Hi, great question!

We haven't evaluated native method call performance specifically compared to standard JVM implementations, although I think we likely do better there.

At the moment there is some overhead because we execute a dynamic native method call lookup, which I'm not sure that we can eliminate. The Java native API allows you to dynamically register native methods signatures to native implementations at runtime (and change these bindings), so our implementation stores signature to native function bindings. Invoking a native method involves a lookup in this map and then jumping to the linked native code. If it's not found in the map then we attempt to invoke the method as a system DLL.

There may be optimizations that allow us to remove this dynamic lookup for certain invocations and statically link the native code, but I am not certain and haven't looked into it in any detail.

dz333 avatar Jan 22 '21 15:01 dz333