From 95dff3b913e4377ae30e65c13e13c9436749e68e Mon Sep 17 00:00:00 2001 From: dbuck Date: Sat, 19 Nov 2016 17:38:50 +0000 Subject: [PATCH] 8022291: Mac OS: Unexpected JavaLaunchHelper message displaying Reviewed-by: serb, ksrini --- src/macosx/bin/java_md_macosx.c | 56 +++++++++++---------------------- 1 file changed, 18 insertions(+), 38 deletions(-) diff --git a/src/macosx/bin/java_md_macosx.c b/src/macosx/bin/java_md_macosx.c index 87e632b92..eb20be772 100644 --- a/src/macosx/bin/java_md_macosx.c +++ b/src/macosx/bin/java_md_macosx.c @@ -1004,32 +1004,6 @@ SetXStartOnFirstThreadArg() 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, @@ -1039,20 +1013,26 @@ JVMInit(InvocationFunctions* ifn, jlong threadStackSize, 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; -- GitLab