RFR: 8310628: GcInfoBuilder.c missing JNI Exception checks
Mandy Chung
mchung at openjdk.org
Thu Jun 22 18:18:02 UTC 2023
On Thu, 22 Jun 2023 10:10:07 GMT, Kevin Walls <kevinw at openjdk.org> wrote:
> JNI calls were identified, where we do not check for a pending Exception afterwards.
>
> (JDK-8162530 cleaned up up some of these kind of issues some years back, but more were found.)
>
> I tested a code change to manually create an Exception before some of the new ExceptionCheck calls, and this is correctly recognised, we see an Exception thrown by the native getLastGcInfo0, e.g.
>
> java.lang.NullPointerException: XXX Test Exception
> at jdk.management/com.sun.management.internal.GcInfoBuilder.getLastGcInfo0(Native Method)
> at jdk.management/com.sun.management.internal.GcInfoBuilder.getLastGcInfo(GcInfoBuilder.java:77)
> at jdk.management/com.sun.management.internal.GarbageCollectorExtImpl.getLastGcInfo(GarbageCollectorExtImpl.java:69)
> at LastGCInfo.main(LastGCInfo.java:53)
> at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
> at java.base/java.lang.reflect.Method.invoke(Method.java:580)
> at com.sun.javatest.regtest.agent.MainWrapper$MainTask.run(MainWrapper.java:138)
> at java.base/java.lang.Thread.run(Thread.java:1570)
>
> Tested with all of test/jdk/com/sun/management including test/jdk/com/sun/management/GarbageCollectorMXBean/LastGCInfo.java
Looks fine. It may worth refactoring the code to set an element in an utility method.
jobject obj = JNU_NewObjectByName(env, class_name, signature, value);
if ((*env)->ExceptionCheck(env)) {
return;
}
(*env)->SetObjectArrayElement(env, array, index, obj);
-------------
PR Review: https://git.openjdk.org/jdk/pull/14613#pullrequestreview-1493765649
More information about the serviceability-dev
mailing list