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. This pull request has now been integrated. Changeset: 4d8e12d2 Author: Andrew Brygin <b...@openjdk.org> Committer: Johan Vos <j...@openjdk.org> URL: https://git.openjdk.java.net/jfx/commit/4d8e12d231476fe72742cf10c223d8baf5028677 Stats: 18 lines in 1 file changed: 4 ins; 13 del; 1 mod 8275723: Crash on macOS 12 in GlassRunnable::dealloc Reviewed-by: kcr, jvos ------------- PR: https://git.openjdk.java.net/jfx/pull/661