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

8088420: JavaFX WebView memory leak via EventListener #799

Closed
wants to merge 10 commits into from

Conversation

jaybhaskar
Copy link
Member

@jaybhaskar jaybhaskar commented May 19, 2022

This PR is new implementation of JavaEvent listener memory management.
Issue JDK-8088420

  1. Calling remove event listener does not free jni global references.
  2. When WebView goes out of scope (disposed from app) , its Event Listeners are not being garbage collected.

Solution:

  1. Detached the jni global reference from JavaEventListener.
  2. Create scoped ref counted wrapper class JavaObjectWrapperHandler for jni global reference.
  3. Create unique JavaObjectWrapperHandler object for each JavaEventListener.
  4. EventListenerManager is a singleton class , which stores the JavaObjectWrapperHandler mapped with JavaEventListener.
  5. EventListenerManager also stores the JavaEventListener mapped with DOMWindow.
  6. When Event listener explicitly removed , JavaEventListener is being forwarded to EventListenerManager to clear the listener.
  7. When WebView goes out of scope, EventListenerManager will de-registered all the event listeners based on the ref counts attached with WebView DOMWindow.

Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (2 reviews required, with at least 1 Reviewer, 1 Author)

Issue

  • JDK-8088420: JavaFX WebView memory leak via EventListener

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jfx pull/799/head:pull/799
$ git checkout pull/799

Update a local copy of the PR:
$ git checkout pull/799
$ git pull https://git.openjdk.java.net/jfx pull/799/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 799

View PR using the GUI difftool:
$ git pr show -t 799

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jfx/pull/799.diff

@bridgekeeper
Copy link

bridgekeeper bot commented May 19, 2022

👋 Welcome back jbhaskar! 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 Ready for review label May 19, 2022
@mlbridge
Copy link

mlbridge bot commented May 19, 2022

@kevinrushforth kevinrushforth self-requested a review May 19, 2022 13:44
@kevinrushforth
Copy link
Member

/reviewers 2

@openjdk
Copy link

openjdk bot commented May 19, 2022

@kevinrushforth
The total number of required reviews for this PR (including the jcheck configuration and the last /reviewers command) is now set to 2 (with 1 of role reviewers, 1 of role authors).

Copy link
Member

@kevinrushforth kevinrushforth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While testing, I noticed one problem in that the new unit tests calls Platform.exit() (this was my fault for adding it when sending you the test case), causing any subsequent web test to fail.

Copy link
Member

@kevinrushforth kevinrushforth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix looks good with a couple questions about removing entries from the map when they are done and some cleanup comments.

In addition to the inline comments I left about the test, I think the following scenarios should be added to the automated test:

  1. Multiple listeners single webiew implicit release (i.e., WebView goes out of scope)
  2. Multiple listeners multiple webiew with explicit release of one webview and implicit release of the other (this one is basically a combination of the others)
  3. Ref count test (single webview is fine) with adding and removing listeners. It should handle the cases of both increasing and decreasing the ref count, and adding the listener to another DOM node after its ref count has gone to zero to make sure that case works.

Copy link
Member

@kevinrushforth kevinrushforth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a couple comments and one question on the changes to the fix.

The new tests look good. I left a few comments and suggestions on the test, but overall they are good additions to verify the fix.

Copy link
Member

@arapte arapte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My review is not complete. I shall continue later. Providing few comments for now.
Please take a look.

Copy link
Member

@kevinrushforth kevinrushforth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a couple comments on one of your test changes.

I think the only remaining question (aside from the few minor comments that Ambarish left) is around the logic in EventListenerManager::resetDOMWindow.

Copy link
Member

@kevinrushforth kevinrushforth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments inline.

Copy link
Member

@kevinrushforth kevinrushforth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good. While doing my final review I noticed one more thing that I think should be changed.

Copy link
Member

@kevinrushforth kevinrushforth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

Copy link
Member

@arapte arapte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@openjdk
Copy link

openjdk bot commented May 28, 2022

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

8088420: JavaFX WebView memory leak via EventListener

Reviewed-by: kcr, arapte

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 3 new commits pushed to the master branch:

  • d677003: 8286256: Update libxml2 to 2.9.14
  • 19a855e: 8286261: Selection of non-expanded non-leaf treeItem grows unexpectedly when adding two-level descendants
  • 18b2366: 8285197: TableColumnHeader: calc of cell width must respect row styling (TreeTableView)

Please see this link for an up-to-date comparison between the source branch of this pull request and the master branch.
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.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@kevinrushforth, @arapte) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Ready to be integrated label May 28, 2022
@jaybhaskar
Copy link
Member Author

/integrate

@openjdk openjdk bot added the sponsor Ready to sponsor label May 29, 2022
@openjdk
Copy link

openjdk bot commented May 29, 2022

@jaybhaskar
Your change (at version c609ad9) is now ready to be sponsored by a Committer.

@kevinrushforth
Copy link
Member

/sponsor

@openjdk
Copy link

openjdk bot commented May 30, 2022

Going to push as commit f534850.
Since your change was applied there have been 3 commits pushed to the master branch:

  • d677003: 8286256: Update libxml2 to 2.9.14
  • 19a855e: 8286261: Selection of non-expanded non-leaf treeItem grows unexpectedly when adding two-level descendants
  • 18b2366: 8285197: TableColumnHeader: calc of cell width must respect row styling (TreeTableView)

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label May 30, 2022
@openjdk openjdk bot closed this May 30, 2022
@openjdk openjdk bot removed ready Ready to be integrated rfr Ready for review sponsor Ready to sponsor labels May 30, 2022
@openjdk
Copy link

openjdk bot commented May 30, 2022

@kevinrushforth @jaybhaskar Pushed as commit f534850.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@jaybhaskar jaybhaskar deleted the JDK-8088420 branch March 4, 2023 04:03
@jaybhaskar jaybhaskar restored the JDK-8088420 branch March 4, 2023 04:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrated Pull request has been integrated
4 participants