polyglot-compiler / JLang

JLang: Ahead-of-time compilation of Java programs to LLVM
http://polyglot-compiler.github.io/JLang/
Other
284 stars 29 forks source link

faster interaction with C code? #74

Open Mis012 opened 3 years ago

Mis012 commented 3 years ago

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?

dz333 commented 3 years ago

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.