Profile Image

What is Java Native Interface Checks: -Xcheck:jni?

What is Java Native Interface Checks: -Xcheck:jni? Have you used this JVM argument before? What are the pros & cons of using this Java argument? Can you share your perspective/experience in using this JVM argument?

  • jvm-argument

  • xcheck-jni

  • check-jni

  • Java Native Interface Checks

Please Sign In or to post your comment or answer

Profile Image

Pavel Khodakovsky


• -Xcheck:jni


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.

Default Value:

-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)
ad org.example.MyApp.main(
Then the JVM will terminate with an error exit code.

Arguments Related to -Xcheck:jni


Related Posts:

• 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.


Got something else on mind? Post Your Question

Not the answer you're looking for? Browse other questions tagged
  • jvm-argument

  • xcheck-jni

  • check-jni

  • Java Native Interface Checks