RFR: 8275723: Crash on macOS 12 in GlassRunnable::dealloc
Andrew Brygin
bae at openjdk.java.net
Tue Nov 2 18:21:38 UTC 2021
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.
-------------
Commit messages:
- 8275723: Crash on macOS 12 in GlassRunnable::dealloc
Changes: https://git.openjdk.java.net/jfx/pull/661/files
Webrev: https://webrevs.openjdk.java.net/?repo=jfx&pr=661&range=00
Issue: https://bugs.openjdk.java.net/browse/JDK-8275723
Stats: 18 lines in 1 file changed: 4 ins; 13 del; 1 mod
Patch: https://git.openjdk.java.net/jfx/pull/661.diff
Fetch: git fetch https://git.openjdk.java.net/jfx pull/661/head:pull/661
PR: https://git.openjdk.java.net/jfx/pull/661
More information about the openjfx-dev
mailing list