Skip to content

Commit

Permalink
8257988: Remove JNF dependency from libsaproc/MacosxDebuggerLocal.m
Browse files Browse the repository at this point in the history
Reviewed-by: ihse, cjplummer
  • Loading branch information
prrace committed Feb 3, 2021
1 parent f025bc1 commit 2be60e3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
2 changes: 1 addition & 1 deletion make/modules/jdk.hotspot.agent/Lib.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBSA, \
LIBS := $(LIBCXX), \
LIBS_unix := -ljava, \
LIBS_linux := $(LIBDL), \
LIBS_macosx := -framework Foundation -framework JavaNativeFoundation \
LIBS_macosx := -framework Foundation \
-framework JavaRuntimeSupport -framework Security -framework CoreFoundation, \
LIBS_windows := dbgeng.lib $(WIN_JAVA_LIB), \
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

#include <objc/objc-runtime.h>
#import <Foundation/Foundation.h>
#import <JavaNativeFoundation/JavaNativeFoundation.h>
#import <JavaRuntimeSupport/JavaRuntimeSupport.h>

#include <jni.h>

Expand Down Expand Up @@ -260,6 +258,39 @@ jlong lookupByNameIncore(
return addr;
}

/* Create a pool and initiate a try block to catch any exception */
#define JNI_COCOA_ENTER(env) \
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; \
@try {

/* Don't allow NSExceptions to escape to Java.
* If there is a Java exception that has been thrown that should escape.
* And ensure we drain the auto-release pool.
*/
#define JNI_COCOA_EXIT(env) \
} \
@catch (NSException *e) { \
NSLog(@"%@", [e callStackSymbols]); \
} \
@finally { \
[pool drain]; \
};

static NSString* JavaStringToNSString(JNIEnv *env, jstring jstr) {

if (jstr == NULL) {
return NULL;
}
jsize len = (*env)->GetStringLength(env, jstr);
const jchar *chars = (*env)->GetStringChars(env, jstr, NULL);
if (chars == NULL) {
return NULL;
}
NSString *result = [NSString stringWithCharacters:(UniChar *)chars length:len];
(*env)->ReleaseStringChars(env, jstr, chars);
return result;
}

/*
* Class: sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
* Method: lookupByName0
Expand All @@ -277,8 +308,9 @@ jlong lookupByNameIncore(

jlong address = 0;

JNF_COCOA_ENTER(env);
NSString *symbolNameString = JNFJavaToNSString(env, symbolName);
JNI_COCOA_ENTER(env);

NSString *symbolNameString = JavaStringToNSString(env, symbolName);

print_debug("lookupInProcess called for %s\n", [symbolNameString UTF8String]);

Expand All @@ -289,7 +321,7 @@ jlong lookupByNameIncore(
}

print_debug("address of symbol %s = %llx\n", [symbolNameString UTF8String], address);
JNF_COCOA_EXIT(env);
JNI_COCOA_EXIT(env);

return address;
}
Expand Down Expand Up @@ -812,7 +844,7 @@ static bool wait_for_exception() {
{
print_debug("attach0 called for jpid=%d\n", (int)jpid);

JNF_COCOA_ENTER(env);
JNI_COCOA_ENTER(env);

kern_return_t result;
task_t gTask = 0;
Expand Down Expand Up @@ -926,7 +958,7 @@ static bool wait_for_exception() {
THROW_NEW_DEBUGGER_EXCEPTION("Can't attach symbolicator to the process");
}

JNF_COCOA_EXIT(env);
JNI_COCOA_EXIT(env);
}

/** For core file,
Expand Down Expand Up @@ -1020,7 +1052,8 @@ static void detach_cleanup(task_t gTask, JNIEnv *env, jobject this_obj, bool thr
Prelease(ph);
return;
}
JNF_COCOA_ENTER(env);

JNI_COCOA_ENTER(env);

task_t gTask = getTask(env, this_obj);
kern_return_t k_res = 0;
Expand Down Expand Up @@ -1071,5 +1104,5 @@ static void detach_cleanup(task_t gTask, JNIEnv *env, jobject this_obj, bool thr

detach_cleanup(gTask, env, this_obj, false);

JNF_COCOA_EXIT(env);
JNI_COCOA_EXIT(env);
}

1 comment on commit 2be60e3

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.