RFR: 8342782: AWTEventMulticaster throws StackOverflowError using AquaButtonUI
Jeremy
duke at openjdk.org
Thu Nov 7 17:54:17 UTC 2024
The AWTEventMulticaster is a tree node with 2 children. This PR proposes rebalancing that tree after 500 additions to avoid potential StackOverflowErrors when trying to interact with a large AWTEventMulticaster.
In the original headful test:
We added 8,000 checkboxes, and when their parent panel was hidden the stack needed to grow to 24,000 lines. It took 8,000 lines to recursively call `java.awt.AWTEventMulticaster.componentHidden`, and then 16,000 additional lines to call two recursive methods to remove a listener:
java.desktop/java.awt.AWTEventMulticaster.removeInternal()
java.desktop/java.awt.AWTEventMulticaster.remove()
With this current PR the max stack size reaches 1,267 instead. (If we rebalanced at EVERY addition, then that same scenario would reach a max stack size of 71.)
JDK-8342782 included a headful test case, but I think the main problem it demonstrated can be represented by the headless test case attached to this PR.
Depending on how this PR is received I may submit a separate ticket & PR to modify AquaButtonUI so it doesn't always attach an AncestorListener. (That is: if my GUI includes 8,000 checkboxes then I don't need 8,000 AncestorListeners.) But JDK-8342782's test case is currently written in a way that should reproduce across all L&F's, so that can be discussed separately.
-------------
Commit messages:
- 8342782: code cleanup for PR
- 8342782: code cleanup for PR
- 8342782: code cleanup for PR
- 8342782: Adding test for 8342782.
- 8342782: sometimes let addInternal call new rebalance method
- 8342782: reverting previous 3 commits
- 8342782: make listener notifications avoid recursion
- 8342782: make getListenerCount & populateListenerArray use less recursion
- 8342782: add removeWithoutRecursion
- Merge pull request #5 from openjdk/master
- ... and 4 more: https://git.openjdk.org/jdk/compare/41ee582d...d3c7d785
Changes: https://git.openjdk.org/jdk/pull/21962/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=21962&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8342782
Stats: 135 lines in 2 files changed: 134 ins; 0 del; 1 mod
Patch: https://git.openjdk.org/jdk/pull/21962.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/21962/head:pull/21962
PR: https://git.openjdk.org/jdk/pull/21962
More information about the client-libs-dev
mailing list