On Tue, 20 Oct 2026 21:45:14 GMT, Phil Race <[email protected]> wrote:

> The native code on macOS which initializes cached JNI refs is not thread safe.
> The fix is to use the macOS dispatch_once mechanism as a lock.
> The fix is essentially all in JNIUtilities.h. There's some refactoring of the 
> macros in there to make things a bit cleaner
> and DECLARE_*_ONLY macros are added which the non-local clients now use to 
> declare variables.
> 
> The problem can be demonstrated with multi-threaded initialisation, and using 
> -Xcheck:jni
> A case which reproduces "fairly often" has been added as a test.
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

src/java.desktop/macosx/native/libawt_lwawt/awt/a11y/ColumnAccessibility.m line 
37:

> 35: #import "sun_lwawt_macosx_CAccessibility.h"
> 36: 
> 37: static jclass sjc_CAccessibility = NULL;

Seems all of this is unused, so it is deleted.

src/java.desktop/macosx/native/libawt_lwawt/awt/a11y/ComboBoxAccessibility.m 
line 34:

> 32: static jclass sjc_CAccessibility = NULL;
> 33: 
> 34: static jmethodID sjm_getAccessibleName = NULL;

Turns out this isn't used. So it is deleted.

src/java.desktop/macosx/native/libosxapp/JNIUtilities.h line 55:

> 53: 
> 54: #define GET_CLASS_ONLY(dst_var, cls) \
> 55:      dispatch_once(&dst_var##_once, ^{ \

This change from a test for NULL to dispatch_once is the fix. The rest is just 
to support it.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/33481#discussion_r4330683156
PR Review Comment: https://git.openjdk.org/jdk/pull/33481#discussion_r4330679410
PR Review Comment: https://git.openjdk.org/jdk/pull/33481#discussion_r4330690966

Reply via email to