8257988: Remove JNF dependency from libsaproc/MacosxDebuggerLocal.m
Reviewed-by: ihse, cjplummer
diff --git a/make/lib/Lib-jdk.hotspot.agent.gmk b/make/lib/Lib-jdk.hotspot.agent.gmk
index 1cbae70..2d0c36a 100644
--- a/make/lib/Lib-jdk.hotspot.agent.gmk
+++ b/make/lib/Lib-jdk.hotspot.agent.gmk
@@ -67,7 +67,7 @@
LDFLAGS := $(LDFLAGS_JDKLIB) $(SA_LDFLAGS), \
LIBS_linux := -lthread_db $(LIBDL), \
LIBS_solaris := -ldl -ldemangle -lthread -lproc, \
- LIBS_macosx := -framework Foundation -framework JavaNativeFoundation \
+ LIBS_macosx := -framework Foundation \
-framework JavaRuntimeSupport -framework Security -framework CoreFoundation, \
LIBS_windows := dbgeng.lib, \
))
diff --git a/src/jdk.hotspot.agent/macosx/native/libsaproc/MacosxDebuggerLocal.m b/src/jdk.hotspot.agent/macosx/native/libsaproc/MacosxDebuggerLocal.m
index 3a74238..1188720 100644
--- a/src/jdk.hotspot.agent/macosx/native/libsaproc/MacosxDebuggerLocal.m
+++ b/src/jdk.hotspot.agent/macosx/native/libsaproc/MacosxDebuggerLocal.m
@@ -24,8 +24,6 @@
#include <objc/objc-runtime.h>
#import <Foundation/Foundation.h>
-#import <JavaNativeFoundation/JavaNativeFoundation.h>
-#import <JavaRuntimeSupport/JavaRuntimeSupport.h>
#include <jni.h>
@@ -260,6 +258,39 @@
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
@@ -277,8 +308,9 @@
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]);
@@ -289,7 +321,7 @@
}
print_debug("address of symbol %s = %llx\n", [symbolNameString UTF8String], address);
-JNF_COCOA_EXIT(env);
+ JNI_COCOA_EXIT(env);
return address;
}
@@ -805,7 +837,7 @@
{
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;
@@ -919,7 +951,7 @@
THROW_NEW_DEBUGGER_EXCEPTION("Can't attach symbolicator to the process");
}
-JNF_COCOA_EXIT(env);
+ JNI_COCOA_EXIT(env);
}
/** For core file,
@@ -1013,7 +1045,8 @@
Prelease(ph);
return;
}
-JNF_COCOA_ENTER(env);
+
+ JNI_COCOA_ENTER(env);
task_t gTask = getTask(env, this_obj);
kern_return_t k_res = 0;
@@ -1064,5 +1097,5 @@
detach_cleanup(gTask, env, this_obj, false);
-JNF_COCOA_EXIT(env);
+ JNI_COCOA_EXIT(env);
}