RFR: 8275723: Crash on macOS 12 in GlassRunnable::dealloc

Kevin Rushforth kcr at openjdk.java.net
Wed Nov 3 14:24:22 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.

Testing completed. I ran tests on three different macOS systems:

M1 running macOS 12.0.1 beta
Intel x64 system running macOS 12.0.1 beta
Intel x64 system (MacBook Pro) running 10.15.7

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

Marked as reviewed by kcr (Lead).

PR: https://git.openjdk.java.net/jfx/pull/661


More information about the openjfx-dev mailing list