ibm-jdk

Why NewGlobalRef will core dump on JNI on an IBM JDK?


I believe I have hit a bug on the IBM JDK on its JNI implementation.

I'm working on Apache ActiveMQ Artemis and we recently had to make this following fix as we were having issues on the IBM JDK 1.8:

https://github.com/apache/activemq-artemis/commit/18e41963b61a5ef6dbcdb150e27c07c062deaa66

The issue is around acquiring NewGlobalRef on a methodID, which presumably is an object as well. If you acquire a NewGlobalRef(MethodID) through Sun JDK everything is fine, but if you do it on an IBM JDK, then you would get a GPF.

I could fix Artemis Native layer by removing the NewGlobalRef (as I believe I didn't need in the end), but still the JVM shouldn't core dump because of this.

I have put together a project replicating the issue: https://github.com/clebertsuconic/simple-JNI-bug

if you revert the last commit, or comment the code around the NewGlobalRef on the method ID everything will pass.


Solution

  • MethodIds aren't Objects. There is no reason to get a GlobalRef to them. Remove the newGlobalRef call and it will work fine on both vms.

    I don't know why Oracle doesn't crash (maybe checking the value against the heap range?)

    Are you aware of the -Xcheck:jni option? It will help detect and warn about incorrect jni usage.