From 825ceb16b2e2347a4d9c1977d9a3a2da1296d5fe Mon Sep 17 00:00:00 2001 From: Justin Lu Date: Mon, 4 Nov 2024 20:55:17 +0000 Subject: [PATCH] 8341796: Fix ExceptionOccurred in jdk.hotspot.agent Reviewed-by: dholmes, cjplummer --- .../linux/native/libsaproc/DwarfParser.cpp | 8 +++---- .../native/libsaproc/LinuxDebuggerLocal.cpp | 6 ++--- .../native/libsaproc/MacosxDebuggerLocal.m | 14 ++++++------ .../share/native/libsaproc/sadis.c | 22 +++++++++---------- .../windows/native/libsaproc/sawindbg.cpp | 8 +++---- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/jdk.hotspot.agent/linux/native/libsaproc/DwarfParser.cpp b/src/jdk.hotspot.agent/linux/native/libsaproc/DwarfParser.cpp index 4eb9587a8df..8df08c49e09 100644 --- a/src/jdk.hotspot.agent/linux/native/libsaproc/DwarfParser.cpp +++ b/src/jdk.hotspot.agent/linux/native/libsaproc/DwarfParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2020, 2021, NTT DATA. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -28,7 +28,7 @@ #include "dwarf.hpp" #include "libproc.h" -#define CHECK_EXCEPTION if (env->ExceptionOccurred()) { return; } +#define CHECK_EXCEPTION if (env->ExceptionCheck()) { return; } static jfieldID p_dwarf_context_ID = 0; static jint sa_RAX = -1; @@ -102,7 +102,7 @@ JNIEXPORT jlong JNICALL Java_sun_jvm_hotspot_debugger_linux_amd64_DwarfParser_cr DwarfParser *parser = new DwarfParser(reinterpret_cast(lib)); if (!parser->is_parseable()) { jclass ex_cls = env->FindClass("sun/jvm/hotspot/debugger/DebuggerException"); - if (!env->ExceptionOccurred()) { + if (!env->ExceptionCheck()) { env->ThrowNew(ex_cls, "DWARF not found"); } delete parser; @@ -147,7 +147,7 @@ JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_amd64_DwarfParser_pro DwarfParser *parser = reinterpret_cast(get_dwarf_context(env, this_obj)); if (!parser->process_dwarf(pc)) { jclass ex_cls = env->FindClass("sun/jvm/hotspot/debugger/DebuggerException"); - if (!env->ExceptionOccurred()) { + if (!env->ExceptionCheck()) { env->ThrowNew(ex_cls, "Could not find PC in DWARF"); } return; diff --git a/src/jdk.hotspot.agent/linux/native/libsaproc/LinuxDebuggerLocal.cpp b/src/jdk.hotspot.agent/linux/native/libsaproc/LinuxDebuggerLocal.cpp index 0ad95d0eac7..bd696fd2a25 100644 --- a/src/jdk.hotspot.agent/linux/native/libsaproc/LinuxDebuggerLocal.cpp +++ b/src/jdk.hotspot.agent/linux/native/libsaproc/LinuxDebuggerLocal.cpp @@ -70,7 +70,7 @@ class AutoJavaString { const char* m_buf; public: - // check env->ExceptionOccurred() after ctor + // check env->ExceptionCheck() after ctor AutoJavaString(JNIEnv* env, jstring str) : m_env(env), m_str(str), m_buf(str == NULL ? NULL : env->GetStringUTFChars(str, NULL)) { } @@ -101,8 +101,8 @@ static jmethodID listAdd_ID = 0; */ static char *saaltroot = NULL; -#define CHECK_EXCEPTION_(value) if (env->ExceptionOccurred()) { return value; } -#define CHECK_EXCEPTION if (env->ExceptionOccurred()) { return;} +#define CHECK_EXCEPTION_(value) if (env->ExceptionCheck()) { return value; } +#define CHECK_EXCEPTION if (env->ExceptionCheck()) { return;} #define THROW_NEW_DEBUGGER_EXCEPTION_(str, value) { throw_new_debugger_exception(env, str); return value; } #define THROW_NEW_DEBUGGER_EXCEPTION(str) { throw_new_debugger_exception(env, str); return;} diff --git a/src/jdk.hotspot.agent/macosx/native/libsaproc/MacosxDebuggerLocal.m b/src/jdk.hotspot.agent/macosx/native/libsaproc/MacosxDebuggerLocal.m index 79912a9b4db..a2f59a7ed3e 100644 --- a/src/jdk.hotspot.agent/macosx/native/libsaproc/MacosxDebuggerLocal.m +++ b/src/jdk.hotspot.agent/macosx/native/libsaproc/MacosxDebuggerLocal.m @@ -140,13 +140,13 @@ static task_t getTask(JNIEnv *env, jobject this_obj) { return (task_t)ptr; } -#define CHECK_EXCEPTION_(value) if ((*env)->ExceptionOccurred(env)) { return value; } -#define CHECK_EXCEPTION if ((*env)->ExceptionOccurred(env)) { return;} +#define CHECK_EXCEPTION_(value) if ((*env)->ExceptionCheck(env)) { return value; } +#define CHECK_EXCEPTION if ((*env)->ExceptionCheck(env)) { return;} #define THROW_NEW_DEBUGGER_EXCEPTION_(str, value) { throw_new_debugger_exception(env, str); return value; } #define THROW_NEW_DEBUGGER_EXCEPTION(str) { throw_new_debugger_exception(env, str); return;} -#define CHECK_EXCEPTION_CLEAR if ((*env)->ExceptionOccurred(env)) { (*env)->ExceptionClear(env); } -#define CHECK_EXCEPTION_CLEAR_VOID if ((*env)->ExceptionOccurred(env)) { (*env)->ExceptionClear(env); return; } -#define CHECK_EXCEPTION_CLEAR_(value) if ((*env)->ExceptionOccurred(env)) { (*env)->ExceptionClear(env); return value; } +#define CHECK_EXCEPTION_CLEAR if ((*env)->ExceptionCheck(env)) { (*env)->ExceptionClear(env); } +#define CHECK_EXCEPTION_CLEAR_VOID if ((*env)->ExceptionCheck(env)) { (*env)->ExceptionClear(env); return; } +#define CHECK_EXCEPTION_CLEAR_(value) if ((*env)->ExceptionCheck(env)) { (*env)->ExceptionClear(env); return value; } static void throw_new_debugger_exception(JNIEnv* env, const char* errMsg) { jclass exceptionClass = (*env)->FindClass(env, "sun/jvm/hotspot/debugger/DebuggerException"); @@ -238,7 +238,7 @@ jlong lookupByNameIncore( CHECK_EXCEPTION_(0); } symbolName_cstr = (*env)->GetStringUTFChars(env, symbolName, &isCopy); - if ((*env)->ExceptionOccurred(env)) { + if ((*env)->ExceptionCheck(env)) { if (objectName_cstr != NULL) { (*env)->ReleaseStringUTFChars(env, objectName, objectName_cstr); } @@ -1136,7 +1136,7 @@ Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_attach0__Ljava_lang_String_2L execName_cstr = (*env)->GetStringUTFChars(env, execName, &isCopy); CHECK_EXCEPTION; coreName_cstr = (*env)->GetStringUTFChars(env, coreName, &isCopy); - if ((*env)->ExceptionOccurred(env)) { + if ((*env)->ExceptionCheck(env)) { (*env)->ReleaseStringUTFChars(env, execName, execName_cstr); return; } diff --git a/src/jdk.hotspot.agent/share/native/libsaproc/sadis.c b/src/jdk.hotspot.agent/share/native/libsaproc/sadis.c index 0e1ef479222..7fef530ffe0 100644 --- a/src/jdk.hotspot.agent/share/native/libsaproc/sadis.c +++ b/src/jdk.hotspot.agent/share/native/libsaproc/sadis.c @@ -86,7 +86,7 @@ JNIEXPORT jlong JNICALL Java_sun_jvm_hotspot_asm_Disassembler_load_1library(JNIE #endif libname = (*env)->GetStringUTFChars(env, libname_s, NULL); - if (libname == NULL || (*env)->ExceptionOccurred(env)) { + if (libname == NULL || (*env)->ExceptionCheck(env)) { return 0; } @@ -140,13 +140,13 @@ static void* event_to_env(void* env_pv, const char* event, void* arg) { decode_env* denv = (decode_env*)env_pv; JNIEnv* env = denv->env; jstring event_string = (*env)->NewStringUTF(env, event); - if ((*env)->ExceptionOccurred(env)) { + if ((*env)->ExceptionCheck(env)) { return NULL; } result = (*env)->CallLongMethod(env, denv->dis, denv->handle_event, denv->visitor, event_string, (jlong) (uintptr_t)arg); - if ((*env)->ExceptionOccurred(env)) { + if ((*env)->ExceptionCheck(env)) { /* ignore exceptions for now */ (*env)->ExceptionClear(env); return NULL; @@ -177,11 +177,11 @@ static int printf_to_env(void* env_pv, const char* format, ...) { } if (raw != NULL) { jstring output = (*env)->NewStringUTF(env, raw); - if (!(*env)->ExceptionOccurred(env)) { + if (!(*env)->ExceptionCheck(env)) { /* make sure that UTF allocation doesn't cause OOM */ (*env)->CallVoidMethod(env, denv->dis, denv->raw_print, denv->visitor, output); } - if ((*env)->ExceptionOccurred(env)) { + if ((*env)->ExceptionCheck(env)) { /* ignore exceptions for now */ (*env)->ExceptionClear(env); } @@ -192,12 +192,12 @@ static int printf_to_env(void* env_pv, const char* format, ...) { va_end(ap); output = (*env)->NewStringUTF(env, denv->buffer); - if (!(*env)->ExceptionOccurred(env)) { + if (!(*env)->ExceptionCheck(env)) { /* make sure that UTF allocation doesn't cause OOM */ (*env)->CallVoidMethod(env, denv->dis, denv->raw_print, denv->visitor, output); } - if ((*env)->ExceptionOccurred(env)) { + if ((*env)->ExceptionCheck(env)) { /* ignore exceptions for now */ (*env)->ExceptionClear(env); } @@ -224,12 +224,12 @@ JNIEXPORT void JNICALL Java_sun_jvm_hotspot_asm_Disassembler_decode(JNIEnv * env decode_env denv; start = (*env)->GetByteArrayElements(env, code, NULL); - if ((*env)->ExceptionOccurred(env)) { + if ((*env)->ExceptionCheck(env)) { return; } end = start + (*env)->GetArrayLength(env, code); options = (*env)->GetStringUTFChars(env, options_s, NULL); - if ((*env)->ExceptionOccurred(env)) { + if ((*env)->ExceptionCheck(env)) { (*env)->ReleaseByteArrayElements(env, code, start, JNI_ABORT); return; } @@ -242,7 +242,7 @@ JNIEXPORT void JNICALL Java_sun_jvm_hotspot_asm_Disassembler_decode(JNIEnv * env /* find Disassembler.handleEvent callback */ denv.handle_event = (*env)->GetMethodID(env, disclass, "handleEvent", "(Lsun/jvm/hotspot/asm/InstructionVisitor;Ljava/lang/String;J)J"); - if ((*env)->ExceptionOccurred(env)) { + if ((*env)->ExceptionCheck(env)) { (*env)->ReleaseByteArrayElements(env, code, start, JNI_ABORT); (*env)->ReleaseStringUTFChars(env, options_s, options); return; @@ -251,7 +251,7 @@ JNIEXPORT void JNICALL Java_sun_jvm_hotspot_asm_Disassembler_decode(JNIEnv * env /* find Disassembler.rawPrint callback */ denv.raw_print = (*env)->GetMethodID(env, disclass, "rawPrint", "(Lsun/jvm/hotspot/asm/InstructionVisitor;Ljava/lang/String;)V"); - if ((*env)->ExceptionOccurred(env)) { + if ((*env)->ExceptionCheck(env)) { (*env)->ReleaseByteArrayElements(env, code, start, JNI_ABORT); (*env)->ReleaseStringUTFChars(env, options_s, options); return; diff --git a/src/jdk.hotspot.agent/windows/native/libsaproc/sawindbg.cpp b/src/jdk.hotspot.agent/windows/native/libsaproc/sawindbg.cpp index 5c7773809da..de3c45d00d2 100644 --- a/src/jdk.hotspot.agent/windows/native/libsaproc/sawindbg.cpp +++ b/src/jdk.hotspot.agent/windows/native/libsaproc/sawindbg.cpp @@ -99,7 +99,7 @@ class AutoJavaString { const char* m_buf; public: - // check env->ExceptionOccurred() after ctor + // check env->ExceptionCheck() after ctor AutoJavaString(JNIEnv* env, jstring str) : m_env(env), m_str(str), m_buf(str == nullptr ? nullptr : env->GetStringUTFChars(str, nullptr)) { } @@ -122,7 +122,7 @@ class AutoJavaByteArray { jint releaseMode; public: - // check env->ExceptionOccurred() after ctor + // check env->ExceptionCheck() after ctor AutoJavaByteArray(JNIEnv* env, jbyteArray byteArray, jint releaseMode = JNI_ABORT) : env(env), byteArray(byteArray), bytePtr(env->GetByteArrayElements(byteArray, nullptr)), @@ -164,8 +164,8 @@ static jmethodID addThread_ID = 0; static jmethodID createClosestSymbol_ID = 0; static jmethodID setThreadIntegerRegisterSet_ID = 0; -#define CHECK_EXCEPTION_(value) if (env->ExceptionOccurred()) { return value; } -#define CHECK_EXCEPTION if (env->ExceptionOccurred()) { return; } +#define CHECK_EXCEPTION_(value) if (env->ExceptionCheck()) { return value; } +#define CHECK_EXCEPTION if (env->ExceptionCheck()) { return; } #define THROW_NEW_DEBUGGER_EXCEPTION_(str, value) { \ throwNewDebuggerException(env, str); return value; }