Re: OS/X Java native bug
Re: OS/X Java native bug
- Subject: Re: OS/X Java native bug
- From: Michael Hall via Cocoa-dev <email@hidden>
- Date: Sat, 18 Mar 2023 04:46:56 -0500
> On Mar 17, 2023, at 7:49 AM, Alan Snyder <email@hidden> wrote:
>
> block() means invoke the block
Not exactly and it still seems unnecessary here.
It appears to convert the block to a selector and then to invoke it.
Eliminate the comments and NSLog’s and I think the following is equivalent and
a bit more concise. Note that performOnMainThread also includes a main thread
check with the same wait=YES.
Unfortunately this still doesn’t eliminate the -XstartOnFirstThread hang. Still
looking at that. The hang doesn’t ever get into the block. The paths to get
here are slightly different but I haven’t figured out where the difference
amounts to a bug.
+ (void)performOnMainThreadWaiting:(BOOL)wait block:(void (^)())block {
// if ([NSThread isMainThread] && wait == YES) {
/*
if ([NSThread isMainThread]) {
NSLog(@"ThreadUtilities perform main and wait");
//block();
[self performOnMainThread: on:self withObject:block waitUntilDone:wait];
} else {
*/
if (wait == YES) {
NSLog(@"ThreadUtilities not main and wait");
[self performOnMainThread:@selector(invokeBlock:) on:self
withObject:block waitUntilDone:YES];
} else {
void (^blockCopy)(void) = Block_copy(block);
[self performOnMainThread:@selector(invokeBlockCopy:) on:self
withObject:blockCopy waitUntilDone:NO];
}
// }
}
+ (void)performOnMainThread:(SEL)aSelector on:(id)target withObject:(id)arg
waitUntilDone:(BOOL)wait {
NSLog(@"ThreadUtilities performOnMainThread target %@ with %@ on main %d
name %@ wait %d", target, arg, [NSThread isMainThread],[[NSThread
currentThread] name], wait);
NSLog(@"%@", NSThread.callStackSymbols);
NSLog(@"*********************************");
if ([NSThread isMainThread] && wait == YES) {
[target performSelector:aSelector withObject:arg];
} else {
[target performSelectorOnMainThread:aSelector withObject:arg
waitUntilDone:wait modes:javaModes];
}
}
invokeBlock is simply block()
+ (void)invokeBlock:(void (^)())block {
block();
}
If really of interest the difference I’m seeing so far is this
for -XstartOnFirstThread which works
2023-03-17 21:40:34.426 java[25865:2604833] java_md_macosx.m
CreateExecutionEnvironment
2023-03-17 21:40:34.427 java[25865:2604833] java_md_macosx.m
CreateExecutionEnvironment before MacOSXStartup
2023-03-17 21:40:34.427 java[25865:2604833] java_md_macosx MacOSXStartup
2023-03-17 21:40:34.427 java[25865:2604833] java_md_macosx ParkEventLoop
2023-03-17 21:40:34.427 java[25865:2604834] java_md_macosx.m
CreateExecutionEnvironment
2023-03-17 21:40:34.427 java[25865:2604834] java_md_macosx.m
CreateExecutionEnvironment before MacOSXStartup
2023-03-17 21:40:34.427 java[25865:2604834] java_md_macosx.m
CreateExecutionEnvironment after MacOSXStartup
2023-03-17 21:40:35.342 java[25865:2604835] ThreadUtilities performOnMainThread
target ThreadUtilities with <__NSMallocBlock__: 0x600001d0b630> on main 0 name
wait 0
2023-03-17 21:40:35.343 java[25865:2604835] (
0 libosxapp.dylib 0x000000010b9b3f43
+[ThreadUtilities performOnMainThread:on:withObject:waitUntilDone:] + 131
1 libawt_lwawt.dylib 0x000000010bded11a +[AWTStarter
start:] + 346
2 libawt_lwawt.dylib 0x000000010bdeedb1
Java_sun_lwawt_macosx_LWCToolkit_initAppkit + 273
3 ??? 0x000000011ccfdde0 0x0 +
4778352096
)
2023-03-17 21:40:35.343 java[25865:2604835] *********************************
2023-03-17 21:40:35.343 java[25865:2604833] ThreadUtilities invokeBlockCopy
2023-03-17 21:40:35.343 java[25865:2604833] (
0 libosxapp.dylib 0x000000010b9b3dcb
+[ThreadUtilities invokeBlockCopy:] + 43
1 Foundation 0x00007ff8039c9190
__NSThreadPerformPerform + 177
2 CoreFoundation 0x00007ff802b4eb78
__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
3 CoreFoundation 0x00007ff802b4eb27
__CFRunLoopDoSource0 + 157
4 CoreFoundation 0x00007ff802b4e901
__CFRunLoopDoSources0 + 212
5 CoreFoundation 0x00007ff802b4d57b
__CFRunLoopRun + 929
6 CoreFoundation 0x00007ff802b4cb60
CFRunLoopRunSpecific + 560
7 libjli.dylib 0x000000010ae4dd42
CreateExecutionEnvironment + 450
8 libjli.dylib 0x000000010ae49a13 JLI_Launch +
1411
9 java 0x000000010ada1c05 main + 389
10 dyld 0x00007ff802740310 start + 2432
)
2023-03-17 21:40:35.343 java[25865:2604833] *********************************
2023-03-17 21:40:35.586 java[25865:2604835] ThreadUtilities not main and wait
2023-03-17 21:40:35.586 java[25865:2604835] ThreadUtilities performOnMainThread
target ThreadUtilities with <__NSGlobalBlock__: 0x10be3f758> on main 0 name
wait 1
2023-03-17 21:40:35.586 java[25865:2604835] (
0 libosxapp.dylib 0x000000010b9b3f43
+[ThreadUtilities performOnMainThread:on:withObject:waitUntilDone:] + 131
1 libawt_lwawt.dylib 0x000000010bded1f8 +[AWTStarter
start:] + 568
2 libawt_lwawt.dylib 0x000000010bdeedb1
Java_sun_lwawt_macosx_LWCToolkit_initAppkit + 273
3 ??? 0x000000011ccfdde0 0x0 +
4778352096
)
2023-03-17 21:40:35.586 java[25865:2604835] *********************************
2023-03-17 21:40:35.636 java[25865:2604899] MTLGraphicsConfig
tryLoadMetalLibrary on main 0 name Java: AWT-EventQueue-0
2023-03-17 21:40:35.636 java[25865:2604899] ThreadUtilities not main and wait
2023-03-17 21:40:35.636 java[25865:2604899] ThreadUtilities performOnMainThread
target ThreadUtilities with <__NSStackBlock__: 0x7000039ca628> on main 0 name
Java: AWT-EventQueue-0 wait 1
2023-03-17 21:40:35.636 java[25865:2604899] (
0 libosxapp.dylib 0x000000010b9b3f43
+[ThreadUtilities performOnMainThread:on:withObject:waitUntilDone:] + 131
1 libawt_lwawt.dylib 0x000000010bdf41cb
Java_sun_java2d_metal_MTLGraphicsConfig_tryLoadMetalLibrary + 347
2 ??? 0x000000011ccfdde0 0x0 +
4778352096
3 ??? 0x000000011ccf96ba 0x0 +
4778333882
)
2023-03-17 21:40:35.636 java[25865:2604899] *********************************
2023-03-17 21:40:35.636 java[25865:2604833] MTLGraphicsConfig
tryLoadMetalLibrary in block on main 1 name
_____________________________________________________
Where you can see it ends up in and running the block. The main differences
seeming to be that it takes a pass through the CFRunLoop doing an
invokeBlockCopy resulting in a <__NSGlobalBlock__: 0x10be3f758> instead of a
plain old <__NSStackBlock__: 0x7000039ca628> This appears to come from
7 libjli.dylib 0x000000010ae4dd42
CreateExecutionEnvironment + 450
But I haven’t figured out exactly where in CreateExecutionEnvironment this is
and why the -XstartOnFirstThread doesn’t do the same thing. Or if that actually
amounts to the bug.
With -XstartOnFirstThread the trace is less verbose…
2023-03-18 04:43:12.889 java[50119:516520] java_md_macosx.m
CreateExecutionEnvironment
2023-03-18 04:43:12.890 java[50119:516520] java_md_macosx.m
CreateExecutionEnvironment before MacOSXStartup
2023-03-18 04:43:12.890 java[50119:516520] java_md_macosx MacOSXStartup
2023-03-18 04:43:12.890 java[50119:516520] java_md_macosx ParkEventLoop
2023-03-18 04:43:12.890 java[50119:516521] java_md_macosx.m
CreateExecutionEnvironment
2023-03-18 04:43:12.891 java[50119:516521] java_md_macosx.m
CreateExecutionEnvironment before MacOSXStartup
2023-03-18 04:43:12.891 java[50119:516520] java_md_macosx ParkEventLoop parking
2023-03-18 04:43:12.891 java[50119:516521] java_md_macosx.m
CreateExecutionEnvironment after MacOSXStartup
2023-03-18 04:43:12.896 java[50119:516521] ProcessPlatformOption
-XstartOnFirstThread
2023-03-18 04:43:12.896 java[50119:516521] java_md_macosx
SetXStartOnFirstThreadArg before
2023-03-18 04:43:12.896 java[50119:516521] java_md_macosx
SetXStartOnFirstThreadArg after
2023-03-18 04:43:13.447 java[50119:516520] ThreadUtilities performOnMainThread
target ThreadUtilities with <__NSMallocBlock__: 0x600001f605a0> on main 1 name
wait 0
2023-03-18 04:43:13.447 java[50119:516520] (
0 libosxapp.dylib 0x000000010738ef63
+[ThreadUtilities performOnMainThread:on:withObject:waitUntilDone:] + 131
1 libawt_lwawt.dylib 0x00000001077c811a +[AWTStarter
start:] + 346
2 libawt_lwawt.dylib 0x00000001077c9db1
Java_sun_lwawt_macosx_LWCToolkit_initAppkit + 273
3 ??? 0x000000011028fde0 0x0 +
4566089184
4 ??? 0x000000011028b7e2 0x0 +
4566071266
)
2023-03-18 04:43:13.447 java[50119:516520] *********************************
2023-03-18 04:43:13.447 java[50119:516520] ThreadUtilities not main and wait
2023-03-18 04:43:13.447 java[50119:516520] ThreadUtilities performOnMainThread
target ThreadUtilities with <__NSGlobalBlock__: 0x10781a758> on main 1 name
wait 1
2023-03-18 04:43:13.447 java[50119:516520] (
0 libosxapp.dylib 0x000000010738ef63
+[ThreadUtilities performOnMainThread:on:withObject:waitUntilDone:] + 131
1 libawt_lwawt.dylib 0x00000001077c81f8 +[AWTStarter
start:] + 568
2 libawt_lwawt.dylib 0x00000001077c9db1
Java_sun_lwawt_macosx_LWCToolkit_initAppkit + 273
3 ??? 0x000000011028fde0 0x0 +
4566089184
4 ??? 0x000000011028b7e2 0x0 +
4566071266
)
2023-03-18 04:43:13.447 java[50119:516520] *********************************
2023-03-18 04:43:13.529 java[50119:516547] MTLGraphicsConfig
tryLoadMetalLibrary on main 0 name Java: AWT-EventQueue-0
2023-03-18 04:43:13.529 java[50119:516547] ThreadUtilities not main and wait
2023-03-18 04:43:13.529 java[50119:516547] ThreadUtilities performOnMainThread
target ThreadUtilities with <__NSStackBlock__: 0x700004c06628> on main 0 name
Java: AWT-EventQueue-0 wait 1
2023-03-18 04:43:13.530 java[50119:516547] (
0 libosxapp.dylib 0x000000010738ef63
+[ThreadUtilities performOnMainThread:on:withObject:waitUntilDone:] + 131
1 libawt_lwawt.dylib 0x00000001077cf1cb
Java_sun_java2d_metal_MTLGraphicsConfig_tryLoadMetalLibrary + 347
2 ??? 0x000000011028fde0 0x0 +
4566089184
3 ??? 0x000000011028b6ba 0x0 +
4566070970
)
2023-03-18 04:43:13.530 java[50119:516547] *********************************
And it is hung here without getting into the block.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden