<AWT Dev> RFR: 8259869: [macOS] Remove desktop module dependencies on JNF Reference APIs

Sergey Bylokhov serb at openjdk.java.net
Wed Jan 20 06:13:49 UTC 2021


On Mon, 18 Jan 2021 16:08:37 GMT, Phil Race <prr at openjdk.org> wrote:

> This removes desktop module usage of the JNF JNI reference convenience APIs
> These are simply a direct conversion
> JNFNewGlobalRef 
> JNFDeleteGlobalRef 
> JNFNewWeakGlobalRef 
> JNFDeleteWeakGlobalRef 
> 
> These two
> JNFJObjectWrapper 
> JNFWeakJObjectWrapper 
> exist to allow clean up of the refs when a Cocoa wrapper object is released.
> However in all cases there are more direct ways to clean it up and in at least one usage
> the existing code directly releases it with the comment that this is more efficient.
> 
> All our automated regression and JCK tests pass with this change.

src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.h line 55:

> 53: @property (nonatomic, retain) NSWindow *nsWindow;
> 54: 
> 55: @property (nonatomic) jobject javaPlatformWindow;

I think it will be useful to have a comment here that this value is a weak reference and should be copied to the local ref before usage.

src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m line 1547:

> 1545:         AWTWindow *awtWindow = [AWTWindow getTopmostWindowUnderMouse];
> 1546:         if (awtWindow != nil) {
> 1547:             topmostWindowUnderMouse = awtWindow.javaPlatformWindow;

I wonder what type of "reference" we should return here, I do not remember how the "NewWeakGlobalRef" behave when returned to java.

src/java.desktop/macosx/native/libawt_lwawt/awt/CDragSourceContextPeer.m line 58:

> 56:     jobject gTriggerEvent = (*env)->NewGlobalRef(env, jtrigger);
> 57:     jlongArray gFormats = (*env)->NewGlobalRef(env, jformats);
> 58:     jobject gFormatMap = (*env)->NewGlobalRef(env, jformatmap);

All above should be checked for NULL since OOM may occur, but it looks like it does not throw OOM?
https://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/functions.html#NewGlobalRef

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

PR: https://git.openjdk.java.net/jdk/pull/2133


More information about the awt-dev mailing list