RFR: 8320189: vmTestbase/nsk/jvmti/scenarios/bcinstr/BI02/bi02t001 memory corruption when using -Xcheck:jni
Leonid Mesnik
lmesnik at openjdk.org
Thu May 29 19:56:52 UTC 2025
On Fri, 23 May 2025 19:37:15 GMT, Serguei Spitsyn <sspitsyn at openjdk.org> wrote:
> This update is fixing a couple of `nsk/jvmti/ scenarios` tests.
> The tests in a JVMTI `ClassFileLoadHook` callback provide new class file bytes with the result returned by JNI `GetByteArrayElements()`. It violates the JVMTI `ClassFileLoadHook` spec saying:
>
> "The agent must allocate the space for the modified class file data buffer using the memory allocation function Allocate because the VM is responsible for freeing the new class file data buffer using Deallocate."
>
> Please, see the JVMTI ClassFileLoadHook spec:
> https://docs.oracle.com/en/java/javase/24/docs/specs/jvmti.html#ClassFileLoadHook
>
> It is the root cause of a memory corruption detected with the VM option `-Xcheck:jni`.
> The fix is to convert a JNI allocated array returned by `GetByteArrayElements()` to a JMVTI allocated array. New conversion function `jni_array_to_jvmti_allocated()` is added to the`jvmti_common.hpp`.
>
> Testing:
> - ran updated tests individually
> - TBD: submit mach5 tiers 1-6
Changes requested by lmesnik (Reviewer).
test/lib/jdk/test/lib/jvmti/jvmti_common.hpp line 458:
> 456: fatal(jni, "JNI GetArrayLength returned a non-positive value");
> 457: }
> 458: jbyte* jni_arr = jni->GetByteArrayElements(arr, nullptr);
I think you need to release array before exit from this function to unpin it.
-------------
PR Review: https://git.openjdk.org/jdk/pull/25422#pullrequestreview-2879448778
PR Review Comment: https://git.openjdk.org/jdk/pull/25422#discussion_r2114651018
More information about the serviceability-dev
mailing list