8022291: Mac OS: Unexpected JavaLaunchHelper message displaying
authorddehaven
Tue, 21 Jun 2016 15:46:22 -0700
changeset 39534 b12e60ec4e0f
parent 39533 fe4d6551efca
child 39535 440d2d91ed16
8022291: Mac OS: Unexpected JavaLaunchHelper message displaying Reviewed-by: serb, ksrini
jdk/src/java.base/macosx/native/libjli/java_md_macosx.c
--- a/jdk/src/java.base/macosx/native/libjli/java_md_macosx.c	Tue Jun 28 16:17:08 2016 +0530
+++ b/jdk/src/java.base/macosx/native/libjli/java_md_macosx.c	Tue Jun 21 15:46:22 2016 -0700
@@ -1053,32 +1053,6 @@
     setenv(envVar, "1", 1);
 }
 
-/* This class is made for performSelectorOnMainThread when java main
- * should be launched on main thread.
- * We cannot use dispatch_sync here, because it blocks the main dispatch queue
- * which is used inside Cocoa
- */
-@interface JavaLaunchHelper : NSObject {
-    int _returnValue;
-}
-- (void) launchJava:(NSValue*)argsValue;
-- (int) getReturnValue;
-@end
-
-@implementation JavaLaunchHelper
-
-- (void) launchJava:(NSValue*)argsValue
-{
-    _returnValue = JavaMain([argsValue pointerValue]);
-}
-
-- (int) getReturnValue
-{
-    return _returnValue;
-}
-
-@end
-
 // MacOSX we may continue in the same thread
 int
 JVMInit(InvocationFunctions* ifn, jlong threadStackSize,
@@ -1088,20 +1062,26 @@
         JLI_TraceLauncher("In same thread\n");
         // need to block this thread against the main thread
         // so signals get caught correctly
-        JavaMainArgs args;
-        args.argc = argc;
-        args.argv = argv;
-        args.mode = mode;
-        args.what = what;
-        args.ifn  = *ifn;
-        int rslt;
+        __block int rslt = 0;
         NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
         {
-            JavaLaunchHelper* launcher = [[[JavaLaunchHelper alloc] init] autorelease];
-            [launcher performSelectorOnMainThread:@selector(launchJava:)
-                                       withObject:[NSValue valueWithPointer:(void*)&args]
-                                    waitUntilDone:YES];
-            rslt = [launcher getReturnValue];
+            NSBlockOperation *op = [NSBlockOperation blockOperationWithBlock: ^{
+                JavaMainArgs args;
+                args.argc = argc;
+                args.argv = argv;
+                args.mode = mode;
+                args.what = what;
+                args.ifn  = *ifn;
+                rslt = JavaMain(&args);
+            }];
+
+            /*
+             * We cannot use dispatch_sync here, because it blocks the main dispatch queue.
+             * Using the main NSRunLoop allows the dispatch queue to run properly once
+             * SWT (or whatever toolkit this is needed for) kicks off it's own NSRunLoop
+             * and starts running.
+             */
+            [op performSelectorOnMainThread:@selector(start) withObject:nil waitUntilDone:YES];
         }
         [pool drain];
         return rslt;