RFR: 8275723: Crash on macOS 12 in GlassRunnable::dealloc
Kevin Rushforth
kcr at openjdk.java.net
Wed Nov 3 12:16:10 UTC 2021
On Tue, 2 Nov 2021 18:11:38 GMT, Andrew Brygin <bae at openjdk.org> wrote:
> GlassRunnable uses jni environment (jEnv) associated with the main application thread both for run() and dealloc() methods. Both these methods are supposed to be scheduled for execution on the main thread:
>
> if (jEnv != NULL)
> {
> GlassRunnable *runnable = [[GlassRunnable alloc] initWithRunnable:(*env)->NewGlobalRef(env, jRunnable)];
> [runnable performSelectorOnMainThread:@selector(run) withObject:nil waitUntilDone:NO];
> }
>
>
> However, it appears that on macOS 12 only the run() method is executed the main thread, whereas the dealloc() method is executed on the InvokeLaterDispatcher thread, that leads to usage of the main thread jni env in the context of another thread. This problem is more visible on aarch64, where the thread check is triggered by the W^X machinery, but the problem is present on x64 as well.
>
> Proposed fix just encapsulates all jni-related work in the run() method, reducing risks to misuse the jni environment of the main thread.
The fix looks good. All my testing so far looks good. I'll finish my testing today.
-------------
PR: https://git.openjdk.java.net/jfx/pull/661
More information about the openjfx-dev
mailing list