From 4a92fecc41a971cefe218382d509868d48f34f43 Mon Sep 17 00:00:00 2001 From: pchelko Date: Wed, 19 Feb 2014 22:20:07 +0400 Subject: [PATCH] 8034870: Regression: On Mac, fx app can't be launched if setting a javaagent for it Reviewed-by: serb, art, anthony --- src/macosx/native/sun/awt/LWCToolkit.m | 17 +++++++++-------- src/macosx/native/sun/awt/awt.m | 1 + src/macosx/native/sun/osxapp/ThreadUtilities.h | 2 ++ src/macosx/native/sun/osxapp/ThreadUtilities.m | 9 +++++++++ 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/macosx/native/sun/awt/LWCToolkit.m b/src/macosx/native/sun/awt/LWCToolkit.m index 630c0eed9..d619655e4 100644 --- a/src/macosx/native/sun/awt/LWCToolkit.m +++ b/src/macosx/native/sun/awt/LWCToolkit.m @@ -188,14 +188,15 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_initIDs (JNIEnv *env, jclass klass) { // set thread names - dispatch_async(dispatch_get_main_queue(), ^(void){ - [[NSThread currentThread] setName:@"AppKit Thread"]; - - JNIEnv *env = [ThreadUtilities getJNIEnv]; - static JNF_CLASS_CACHE(jc_LWCToolkit, "sun/lwawt/macosx/LWCToolkit"); - static JNF_STATIC_MEMBER_CACHE(jsm_installToolkitThreadInJava, jc_LWCToolkit, "installToolkitThreadInJava", "()V"); - JNFCallStaticVoidMethod(env, jsm_installToolkitThreadInJava); - }); + if (![ThreadUtilities isAWTEmbedded]) { + dispatch_async(dispatch_get_main_queue(), ^(void){ + [[NSThread currentThread] setName:@"AppKit Thread"]; + JNIEnv *env = [ThreadUtilities getJNIEnv]; + static JNF_CLASS_CACHE(jc_LWCToolkit, "sun/lwawt/macosx/LWCToolkit"); + static JNF_STATIC_MEMBER_CACHE(jsm_installToolkitThreadInJava, jc_LWCToolkit, "installToolkitThreadInJava", "()V"); + JNFCallStaticVoidMethod(env, jsm_installToolkitThreadInJava); + }); + } gNumberOfButtons = sun_lwawt_macosx_LWCToolkit_BUTTONS; diff --git a/src/macosx/native/sun/awt/awt.m b/src/macosx/native/sun/awt/awt.m index 16262af97..293a6c05c 100644 --- a/src/macosx/native/sun/awt/awt.m +++ b/src/macosx/native/sun/awt/awt.m @@ -363,6 +363,7 @@ AWT_ASSERT_APPKIT_THREAD; // AppKit Application. NSApplication *app = [NSApplicationAWT sharedApplication]; isEmbedded = ![NSApp isKindOfClass:[NSApplicationAWT class]]; + [ThreadUtilities setAWTEmbedded:isEmbedded]; if (!isEmbedded) { // Install run loop observers and set the AppKit Java thread name diff --git a/src/macosx/native/sun/osxapp/ThreadUtilities.h b/src/macosx/native/sun/osxapp/ThreadUtilities.h index 2cd41aa0c..6a469cd4c 100644 --- a/src/macosx/native/sun/osxapp/ThreadUtilities.h +++ b/src/macosx/native/sun/osxapp/ThreadUtilities.h @@ -129,6 +129,8 @@ __attribute__((visibility("default"))) + (JNIEnv*)getJNIEnvUncached; + (void)detachCurrentThread; + (void)setAppkitThreadGroup:(jobject)group; ++ (void)setAWTEmbedded:(BOOL)embedded; ++ (BOOL)isAWTEmbedded; //Wrappers for the corresponding JNFRunLoop methods with a check for main thread + (void)performOnMainThreadWaiting:(BOOL)wait block:(void (^)())block; diff --git a/src/macosx/native/sun/osxapp/ThreadUtilities.m b/src/macosx/native/sun/osxapp/ThreadUtilities.m index b7d3b3f55..745843101 100644 --- a/src/macosx/native/sun/osxapp/ThreadUtilities.m +++ b/src/macosx/native/sun/osxapp/ThreadUtilities.m @@ -34,6 +34,7 @@ JavaVM *jvm = NULL; static JNIEnv *appKitEnv = NULL; static jobject appkitThreadGroup = NULL; +static BOOL awtEmbedded = NO; inline void attachCurrentThread(void** env) { if ([NSThread isMainThread]) { @@ -87,6 +88,14 @@ AWT_ASSERT_APPKIT_THREAD; } } ++ (void)setAWTEmbedded:(BOOL)embedded { + awtEmbedded = embedded; +} + ++ (BOOL)isAWTEmbedded { + return awtEmbedded; +} + @end -- GitLab