Are there any performance implications when calling machine code from Java's bytecode? Since machine code is "unmanaged", and it is not "aware" of Java's internals, maybe this causes JVM's internal schedulers to pause or something like that?
I am new to Java, so maybe this is not even relevant, please help.
I know that in Erlang they have this problem, where the VM basically stops while it is making calls to machine code. I hope this is not the case with Java. Is it?
The Java Native Interface (JNI) establishes a well-defined and platform-independent interface between the two. Native code can be used together with Java in two distinct ways: as "native methods" in a running JVM and as the code that creates a JVM using the "Invocation API".
This chapter introduces the Java Native Interface (JNI). The JNI is a native programming interface. It allows Java code that runs inside a Java Virtual Machine (VM) to interoperate with applications and libraries written in other programming languages, such as C, C++, and assembly.
Threads running native code will not halt JVM.
As soon as JNI method is called, Java thread switches to _thread_in_native
state. Threads in this state are not counted during safepoint operations, i.e. when a stop-the-world event occurs (like garbage collection), JVM does not stop these threads. Conversely, threads in native state cannot stop JVM unless they perform a JNI upcall. When a native method returns, the thread switches back to _thread_in_Java
state.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With