8034870: Regression: On Mac, fx app can't be launched if setting a javaagent for it
authorpchelko
Thu, 20 Feb 2014 09:36:58 +0400
changeset 23921 1cb9d9ff4e61
parent 23920 dc17ca1e4cf9
child 23922 f361e6f7d154
8034870: Regression: On Mac, fx app can't be launched if setting a javaagent for it Reviewed-by: serb, art, anthony
jdk/src/macosx/native/sun/awt/LWCToolkit.m
jdk/src/macosx/native/sun/awt/awt.m
jdk/src/macosx/native/sun/osxapp/ThreadUtilities.h
jdk/src/macosx/native/sun/osxapp/ThreadUtilities.m
--- a/jdk/src/macosx/native/sun/awt/LWCToolkit.m	Fri Feb 07 19:49:58 2014 +0400
+++ b/jdk/src/macosx/native/sun/awt/LWCToolkit.m	Thu Feb 20 09:36:58 2014 +0400
@@ -221,14 +221,15 @@
 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;
 
--- a/jdk/src/macosx/native/sun/awt/awt.m	Fri Feb 07 19:49:58 2014 +0400
+++ b/jdk/src/macosx/native/sun/awt/awt.m	Thu Feb 20 09:36:58 2014 +0400
@@ -363,6 +363,7 @@
     //  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
--- a/jdk/src/macosx/native/sun/osxapp/ThreadUtilities.h	Fri Feb 07 19:49:58 2014 +0400
+++ b/jdk/src/macosx/native/sun/osxapp/ThreadUtilities.h	Thu Feb 20 09:36:58 2014 +0400
@@ -129,6 +129,8 @@
 + (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;
--- a/jdk/src/macosx/native/sun/osxapp/ThreadUtilities.m	Fri Feb 07 19:49:58 2014 +0400
+++ b/jdk/src/macosx/native/sun/osxapp/ThreadUtilities.m	Thu Feb 20 09:36:58 2014 +0400
@@ -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 @@
     }
 }
 
++ (void)setAWTEmbedded:(BOOL)embedded {
+    awtEmbedded = embedded;
+}
+
++ (BOOL)isAWTEmbedded {
+    return awtEmbedded;
+}
+
 @end