On Tue, 2 Nov 2021 18:11:38 GMT, Andrew Brygin <b...@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

Reply via email to