Skip to content
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

Closed
wants to merge 2 commits into from
Closed

Conversation

prrace
Copy link
Contributor

@prrace prrace commented Jan 18, 2021

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

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8259869: [macOS] Remove desktop module dependencies on JNF Reference APIs

Reviewers

Download

$ git fetch https://git.openjdk.java.net/jdk pull/2133/head:pull/2133
$ git checkout pull/2133

@bridgekeeper
Copy link

bridgekeeper bot commented Jan 18, 2021

👋 Welcome back prr! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Jan 18, 2021
@openjdk
Copy link

openjdk bot commented Jan 18, 2021

@prrace The following label will be automatically applied to this pull request:

  • awt

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the awt client-libs-dev@openjdk.org label Jan 18, 2021
@mlbridge
Copy link

mlbridge bot commented Jan 18, 2021

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;
Copy link
Member

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.

Copy link
Contributor Author

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;
Copy link
Member

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.

Copy link
Contributor Author

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);
Copy link
Member

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

Copy link
Contributor Author

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.

@prrace
Copy link
Contributor Author

prrace commented Jan 20, 2021

/label add 2d swing

@openjdk openjdk bot added 2d client-libs-dev@openjdk.org swing client-libs-dev@openjdk.org labels Jan 20, 2021
@openjdk
Copy link

openjdk bot commented Jan 20, 2021

@prrace
The 2d label was successfully added.

The swing label was successfully added.

@openjdk
Copy link

openjdk bot commented Jan 22, 2021

@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:

8259869: [macOS] Remove desktop module dependencies on JNF Reference APIs

Reviewed-by: serb

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 master branch:

  • a7c2ebc: 8239894: Xserver crashes when the wrong high refresh rate is used
  • 2f47c39: 8259943: FileDescriptor.close0 does not handle EINTR
  • a8073ef: 8253478: (se) epoll Selector should use eventfd for wakeup instead of pipe
  • 34eb8b3: 8255765: Shenandoah: Isolate concurrent, degenerated and full GC
  • c3c6662: 8259954: gc/shenandoah/mxbeans tests fail with -Xcomp
  • 6ce0799: 8259851: Use boolean type for tasks in SubTasksDone
  • 4bcffeb: 8260029: aarch64: fix typo in verify_oop_array
  • e1de0bf: 8260043: Reduce allocation in sun.net.www.protocol.jar.Handler.parseURL
  • 4dfd8cc: 8259897: gtest os.dll_address_to_function_and_library_name_vm fails on AIX
  • 7f7166d: 8260035: Deproblemlist few problemlisted test
  • ... and 64 more: https://git.openjdk.java.net/jdk/compare/9aa5672af089a2b017ecf2bd258dadf360139c39...master

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 master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jan 22, 2021
@prrace
Copy link
Contributor Author

prrace commented Jan 22, 2021

/integrate

@openjdk openjdk bot closed this Jan 22, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jan 22, 2021
@openjdk
Copy link

openjdk bot commented Jan 22, 2021

@prrace Since your change was applied there have been 74 commits pushed to the master branch:

  • a7c2ebc: 8239894: Xserver crashes when the wrong high refresh rate is used
  • 2f47c39: 8259943: FileDescriptor.close0 does not handle EINTR
  • a8073ef: 8253478: (se) epoll Selector should use eventfd for wakeup instead of pipe
  • 34eb8b3: 8255765: Shenandoah: Isolate concurrent, degenerated and full GC
  • c3c6662: 8259954: gc/shenandoah/mxbeans tests fail with -Xcomp
  • 6ce0799: 8259851: Use boolean type for tasks in SubTasksDone
  • 4bcffeb: 8260029: aarch64: fix typo in verify_oop_array
  • e1de0bf: 8260043: Reduce allocation in sun.net.www.protocol.jar.Handler.parseURL
  • 4dfd8cc: 8259897: gtest os.dll_address_to_function_and_library_name_vm fails on AIX
  • 7f7166d: 8260035: Deproblemlist few problemlisted test
  • ... and 64 more: https://git.openjdk.java.net/jdk/compare/9aa5672af089a2b017ecf2bd258dadf360139c39...master

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.

@prrace prrace deleted the jnf_refs branch February 10, 2021 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2d client-libs-dev@openjdk.org awt client-libs-dev@openjdk.org integrated Pull request has been integrated swing client-libs-dev@openjdk.org
Development

Successfully merging this pull request may close these issues.

2 participants