On Wed, 28 Aug 2024 02:19:08 GMT, Prasanta Sadhukhan <psadhuk...@openjdk.org> 
wrote:

>> The testcase calls Platform.exit before the dialog is made visible but
>> on macOS, JavaFX takes over the AppKit thread and uses that as the FX 
>> application thread. As part of the FX platform shutdown process, it detaches 
>> that thread from the JVM. This means that the AppKit thread is no longer 
>> available to Java processes
>> so AWT crashes when it ties to access appkit thread.
>> Fix is made to check if the thread has been detached for move-resize 
>> notification event before proceeding..
>
> Prasanta Sadhukhan has updated the pull request incrementally with one 
> additional commit since the last revision:
> 
>   Reattach thread if AWT is the owner of NSApplication

I tested it with the existing JavaFX release and there is no more crash. I also 
instrumented the code and it does the right thing in both the case of AWT as 
owner and FX as owner, although in the latter case, it assumes it can cache the 
env for the first call to JNI that happens before the `ApplicationDelegate` is 
initialized. You might consider flipping the default and don't start caching it 
until the ApplicationDelegate says that AWT is the owner.

src/java.desktop/macosx/native/libawt_lwawt/awt/ApplicationDelegate.m line 128:

> 126:         [ThreadUtilities setApplicationOwner:NO];
> 127:         return nil;
> 128:     }

If you flip the default, then you need to set it to YES here:


    [ThreadUtilities setApplicationOwner:YES];


(this might be best anyway, since then you will always set the flag)

src/java.desktop/macosx/native/libosxapp/ThreadUtilities.m line 34:

> 32: // The following must be named "jvm", as there are extern references to 
> it in AWT
> 33: JavaVM *jvm = NULL;
> 34: static BOOL isNSApplicationOwner = YES;

One possible suggestion would be to flip the default to `NO`, so as not to 
cache the env until we know we are the owner.

-------------

Marked as reviewed by kcr (Author).

PR Review: https://git.openjdk.org/jdk/pull/20688#pullrequestreview-2266788505
PR Review Comment: https://git.openjdk.org/jdk/pull/20688#discussion_r1734999212
PR Review Comment: https://git.openjdk.org/jdk/pull/20688#discussion_r1734998040

Reply via email to