Skip to content

8320189: vmTestbase/nsk/jvmti/scenarios/bcinstr/BI02/bi02t001 memory corruption when using -Xcheck:jni #25422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -49,7 +49,7 @@ const char* CLASS_NAME = "nsk/jvmti/scenarios/bcinstr/BI02/bi02t001a";
/** callback functions **/

static void JNICALL
ClassFileLoadHook(jvmtiEnv *jvmti_env, JNIEnv *jni_env,
ClassFileLoadHook(jvmtiEnv *jvmti, JNIEnv *jni,
jclass class_being_redefined, jobject loader,
const char* name, jobject protection_domain,
jint class_data_len, const unsigned char* class_data,
Expand All @@ -61,18 +61,7 @@ ClassFileLoadHook(jvmtiEnv *jvmti_env, JNIEnv *jni_env,

if (class_being_redefined == nullptr) {
/* sent by class load */

if (!NSK_JNI_VERIFY(jni_env, (*new_class_data_len =
jni_env->GetArrayLength(classBytes)) > 0)) {
nsk_jvmti_setFailStatus();
return;
}

if (!NSK_JNI_VERIFY(jni_env, (*new_class_data = (unsigned char*)
jni_env->GetByteArrayElements(classBytes, nullptr)) != nullptr)) {
nsk_jvmti_setFailStatus();
return;
}
*new_class_data = jni_array_to_jvmti_allocated(jvmti, jni, classBytes, new_class_data_len);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -49,7 +49,7 @@ const char* CLASS_NAME = "nsk/jvmti/scenarios/bcinstr/BI03/bi03t001a";
/** callback functions **/

static void JNICALL
ClassFileLoadHook(jvmtiEnv *jvmti_env, JNIEnv *jni_env,
ClassFileLoadHook(jvmtiEnv *jvmti, JNIEnv *jni,
jclass class_being_redefined, jobject loader,
const char* name, jobject protection_domain,
jint class_data_len, const unsigned char* class_data,
Expand All @@ -62,17 +62,7 @@ ClassFileLoadHook(jvmtiEnv *jvmti_env, JNIEnv *jni_env,
if (class_being_redefined == nullptr) {
/* sent by class load */

if (!NSK_JNI_VERIFY(jni_env, (*new_class_data_len =
jni_env->GetArrayLength(classBytes)) > 0)) {
nsk_jvmti_setFailStatus();
return;
}

if (!NSK_JNI_VERIFY(jni_env, (*new_class_data = (unsigned char*)
jni_env->GetByteArrayElements(classBytes, nullptr)) != nullptr)) {
nsk_jvmti_setFailStatus();
return;
}
*new_class_data = jni_array_to_jvmti_allocated(jvmti, jni, classBytes, new_class_data_len);
}
}
}
Expand Down
22 changes: 21 additions & 1 deletion test/lib/jdk/test/lib/jvmti/jvmti_common.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -447,7 +447,27 @@ static jthread get_current_thread(jvmtiEnv *jvmti, JNIEnv* jni) {
return thread;
}

/* Used in a couple of nsk/jvmti/scenarios tests to convert jbyteArray to a JVMTI allocated */
static unsigned char* jni_array_to_jvmti_allocated(jvmtiEnv *jvmti, JNIEnv *jni, jbyteArray arr, jint* len_ptr) {
unsigned char* new_arr = nullptr;

jint len = jni->GetArrayLength(arr);
if (len <= 0) {
fatal(jni, "JNI GetArrayLength returned a non-positive value");
}
jbyte* jni_arr = jni->GetByteArrayElements(arr, nullptr);
if (jni_arr == nullptr) {
fatal(jni, "JNI GetByteArrayElements returned nullptr");
}
jvmtiError err = jvmti->Allocate(len, &new_arr);
check_jvmti_status(jni, err, "JVMTI Allocate returned an error code");

memcpy(new_arr, jni_arr, (size_t)len);
jni->ReleaseByteArrayElements(arr, jni_arr, JNI_ABORT);

*len_ptr = len;
return new_arr;
}

/* Commonly used helper functions */
const char*
Expand Down