Skip to content

Commit 2be60e3

Browse files
committed
8257988: Remove JNF dependency from libsaproc/MacosxDebuggerLocal.m
Reviewed-by: ihse, cjplummer
1 parent f025bc1 commit 2be60e3

File tree

2 files changed

+43
-10
lines changed

2 files changed

+43
-10
lines changed

make/modules/jdk.hotspot.agent/Lib.gmk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBSA, \
6969
LIBS := $(LIBCXX), \
7070
LIBS_unix := -ljava, \
7171
LIBS_linux := $(LIBDL), \
72-
LIBS_macosx := -framework Foundation -framework JavaNativeFoundation \
72+
LIBS_macosx := -framework Foundation \
7373
-framework JavaRuntimeSupport -framework Security -framework CoreFoundation, \
7474
LIBS_windows := dbgeng.lib $(WIN_JAVA_LIB), \
7575
))

src/jdk.hotspot.agent/macosx/native/libsaproc/MacosxDebuggerLocal.m

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424

2525
#include <objc/objc-runtime.h>
2626
#import <Foundation/Foundation.h>
27-
#import <JavaNativeFoundation/JavaNativeFoundation.h>
28-
#import <JavaRuntimeSupport/JavaRuntimeSupport.h>
2927

3028
#include <jni.h>
3129

@@ -260,6 +258,39 @@ jlong lookupByNameIncore(
260258
return addr;
261259
}
262260

261+
/* Create a pool and initiate a try block to catch any exception */
262+
#define JNI_COCOA_ENTER(env) \
263+
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; \
264+
@try {
265+
266+
/* Don't allow NSExceptions to escape to Java.
267+
* If there is a Java exception that has been thrown that should escape.
268+
* And ensure we drain the auto-release pool.
269+
*/
270+
#define JNI_COCOA_EXIT(env) \
271+
} \
272+
@catch (NSException *e) { \
273+
NSLog(@"%@", [e callStackSymbols]); \
274+
} \
275+
@finally { \
276+
[pool drain]; \
277+
};
278+
279+
static NSString* JavaStringToNSString(JNIEnv *env, jstring jstr) {
280+
281+
if (jstr == NULL) {
282+
return NULL;
283+
}
284+
jsize len = (*env)->GetStringLength(env, jstr);
285+
const jchar *chars = (*env)->GetStringChars(env, jstr, NULL);
286+
if (chars == NULL) {
287+
return NULL;
288+
}
289+
NSString *result = [NSString stringWithCharacters:(UniChar *)chars length:len];
290+
(*env)->ReleaseStringChars(env, jstr, chars);
291+
return result;
292+
}
293+
263294
/*
264295
* Class: sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
265296
* Method: lookupByName0
@@ -277,8 +308,9 @@ jlong lookupByNameIncore(
277308

278309
jlong address = 0;
279310

280-
JNF_COCOA_ENTER(env);
281-
NSString *symbolNameString = JNFJavaToNSString(env, symbolName);
311+
JNI_COCOA_ENTER(env);
312+
313+
NSString *symbolNameString = JavaStringToNSString(env, symbolName);
282314

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

@@ -289,7 +321,7 @@ jlong lookupByNameIncore(
289321
}
290322

291323
print_debug("address of symbol %s = %llx\n", [symbolNameString UTF8String], address);
292-
JNF_COCOA_EXIT(env);
324+
JNI_COCOA_EXIT(env);
293325

294326
return address;
295327
}
@@ -812,7 +844,7 @@ static bool wait_for_exception() {
812844
{
813845
print_debug("attach0 called for jpid=%d\n", (int)jpid);
814846

815-
JNF_COCOA_ENTER(env);
847+
JNI_COCOA_ENTER(env);
816848

817849
kern_return_t result;
818850
task_t gTask = 0;
@@ -926,7 +958,7 @@ static bool wait_for_exception() {
926958
THROW_NEW_DEBUGGER_EXCEPTION("Can't attach symbolicator to the process");
927959
}
928960

929-
JNF_COCOA_EXIT(env);
961+
JNI_COCOA_EXIT(env);
930962
}
931963

932964
/** For core file,
@@ -1020,7 +1052,8 @@ static void detach_cleanup(task_t gTask, JNIEnv *env, jobject this_obj, bool thr
10201052
Prelease(ph);
10211053
return;
10221054
}
1023-
JNF_COCOA_ENTER(env);
1055+
1056+
JNI_COCOA_ENTER(env);
10241057

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

10721105
detach_cleanup(gTask, env, this_obj, false);
10731106

1074-
JNF_COCOA_EXIT(env);
1107+
JNI_COCOA_EXIT(env);
10751108
}

0 commit comments

Comments
 (0)