Skip to content
Open
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) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2026, 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 @@ -39,6 +39,7 @@ static jvmtiEventCallbacks callbacks;
static jint result = PASSED;
static jboolean printdump = JNI_FALSE;
static jmethodID mid;
static jclass testThreadClass = nullptr;

void JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *env,
jthread thread, jmethodID method, jlocation location) {
Expand Down Expand Up @@ -166,6 +167,8 @@ Java_nsk_jvmti_PopFrame_popframe007_getReady(JNIEnv *env,
return;
}

testThreadClass = (jclass)env->NewGlobalRef(clazz);

err = jvmti->SetBreakpoint(mid, 0);
if (err != JVMTI_ERROR_NONE) {
printf("(SetBreakpoint) unexpected error: %s (%d)\n",
Expand All @@ -191,7 +194,7 @@ Java_nsk_jvmti_PopFrame_popframe007_getRes(JNIEnv *env, jclass cls) {
JNIEXPORT void JNICALL
Java_nsk_jvmti_PopFrame_popframe007_B(JNIEnv *env, jclass cls) {
if (mid != nullptr) {
env->CallStaticVoidMethod(cls, mid);
env->CallStaticVoidMethod(testThreadClass, mid);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this just end up getting an exception that we never handle anywhere?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On debug builds with -Xcheck:jni, it catches the class/method ID mismatch and aborts with a fatal error before the call even executes. Without -Xcheck:jni, the behavior is undefined per the JNI spec. It could silently leave a pending exception or produce incorrect results.

}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2026, 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 @@ -113,14 +113,21 @@ ClassFileLoadHook (
loader, method_id, class_name_string)) != nullptr))
return;

if (jni->ExceptionCheck()) {
jni->ExceptionDescribe();
jni->ExceptionClear();
return;
}

if (!NSK_VERIFY((method_id = jni->GetStaticMethodID(
callback_class, "callback", "(Ljava/lang/String;I)V")) != nullptr))
return;

if (!NSK_VERIFY((class_name_string = jni->NewStringUTF(name)) != nullptr))
return;

jni->CallStaticObjectMethod(callback_class, method_id, class_name_string, agent_id);
if (!NSK_JNI_VERIFY_VOID(jni, jni->CallStaticVoidMethod(callback_class, method_id, class_name_string, agent_id)))
return;
}


Expand Down
24 changes: 23 additions & 1 deletion test/hotspot/jtreg/vmTestbase/nsk/share/aod/aod.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2026, 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 @@ -31,6 +31,20 @@ extern "C" {

static volatile int internalError = 0;

/*
* Check for pending JNI exceptions after a JNI call.
* If an exception is found, describe it, clear it, and return failure.
*/
static int nsk_aod_checkJNIException(JNIEnv* jni) {
if (jni->ExceptionCheck()) {
jni->ExceptionDescribe();
jni->ExceptionClear();
NSK_COMPLAIN0("Unexpected exception after JNI call\n");
return NSK_FALSE;
}
return NSK_TRUE;
}

/*
* This function can be used to inform AOD framework that some non critical for test logic
* error happened inside shared function (e.g. JVMTI Deallocate failed).
Expand Down Expand Up @@ -227,6 +241,10 @@ int nsk_aod_agentLoaded(JNIEnv* jni, const char* agentName) {

jni->CallStaticVoidMethod(targetAppClass, agentLoadedMethod, agentNameString);

if (!nsk_aod_checkJNIException(jni)) {
return NSK_FALSE;
}

return NSK_TRUE;
}

Expand Down Expand Up @@ -263,6 +281,10 @@ int nsk_aod_agentFinished(JNIEnv* jni, const char* agentName, int success) {

jni->CallStaticVoidMethod(targetAppClass, agentFinishedMethod, agentNameString, success ? JNI_TRUE : JNI_FALSE);

if (!nsk_aod_checkJNIException(jni)) {
return NSK_FALSE;
}

return NSK_TRUE;
}

Expand Down