When -Xcheck:jni is used, the JVM performs additional checks when invoking
Java Native Interface (JNI) functions. These checks are intended to find bugs in
the native code that could cause the JVM to crash or behave incorrectly. When
the -Xcheck:jni argument is enabled, the JVM performs additional validation
on the arguments passed to JNI functions. by validating parameters passed to
the JNI function before processing a JNI request.
The implementation of -Xcheck:jni works by wrapping each JNI function to
perform the checks before delegating to the real function. As such it adds a
performance penalty, which can affect any Java application, not only applications
that are implemented with large amounts of native code, because parts of the JDK
library also use JNI. When the wrapper function detects an invalid arguments,
a message is printed to the console along with a stack trace, and the JVM exits
with an error code.
-Xcheck:jni can be used in development and testing in order to find and
eliminate bugs at an early stage, but should not be used in production due to
its performance impact.
-Xcheck:jni is off by default.
When -Xcheck:jni is enabled and invalid data is encountered, a message is
printed on the standard error stream, for example:
FATAL ERROR in native method: Null object passed to JNI
at org.example.NativeMethods.native1(Native method)
Then the JVM will terminate with an error exit code.
Arguments Related to -Xcheck:jni
• Oracle JDK 8 Documentation for -Xcheck:jni.
If you have additional comments, interesting experiences or even point of disagreement with this JVM argument description, please leave a comment. Your
insights will help the entire 10+ million java developer community to develop
one standard source of documentation for all the JVM arguments.
Edit your Comment