-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8259869: [macOS] Remove desktop module dependencies on JNF Reference APIs #2133
Conversation
👋 Welcome back prr! A progress list of the required criteria for merging this PR into |
Webrevs
|
@@ -53,7 +52,7 @@ | |||
// An instance of either AWTWindow_Normal or AWTWindow_Panel | |||
@property (nonatomic, retain) NSWindow *nsWindow; | |||
|
|||
@property (nonatomic, retain) JNFWeakJObjectWrapper *javaPlatformWindow; | |||
@property (nonatomic) jobject javaPlatformWindow; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose I can add a comment ... but it is already done in the couple of dozen usages so any one adding a new usage who misses that will likely miss the comment too.
@@ -1544,7 +1544,7 @@ + (AWTWindow *) lastKeyWindow { | |||
[ThreadUtilities performOnMainThreadWaiting:YES block:^{ | |||
AWTWindow *awtWindow = [AWTWindow getTopmostWindowUnderMouse]; | |||
if (awtWindow != nil) { | |||
topmostWindowUnderMouse = [awtWindow.javaPlatformWindow jObject]; | |||
topmostWindowUnderMouse = awtWindow.javaPlatformWindow; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder what type of "reference" we should return here, I do not remember how the "NewWeakGlobalRef" behave when returned to java.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is no different than other cases. Java will get a new strong ref to the object
and expect it to be of the return type of this native method.
jobject gTransferable = (*env)->NewGlobalRef(env, jtransferable); | ||
jobject gTriggerEvent = (*env)->NewGlobalRef(env, jtrigger); | ||
jlongArray gFormats = (*env)->NewGlobalRef(env, jformats); | ||
jobject gFormatMap = (*env)->NewGlobalRef(env, jformatmap); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is the case that per even the latest spec. none of these throw any exception.
https://docs.oracle.com/en/java/javase/15/docs/specs/jni/functions.html#newglobalref
So I think the existing code doesn't do anything in the event of a NULL return.
And if you want to check for NULL here and return NULL from the native method there's semantic implications that require the caller never pass NULL for any of these.
It is not illegal to pass NULL to NewGlobalRef.
Investigating and confirming that is beyond the scope of this change.
Or we make the code a bit more complex here and check that we get back non-null for a non-null arg. But once again nothing new here.
/label add 2d swing |
@prrace The |
@prrace This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 74 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
/integrate |
@prrace Since your change was applied there have been 74 commits pushed to the
Your commit was automatically rebased without conflicts. Pushed as commit 92c2f08. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
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.
Progress
Issue
Reviewers
Download
$ git fetch https://git.openjdk.java.net/jdk pull/2133/head:pull/2133
$ git checkout pull/2133