jdk icon indicating copy to clipboard operation
jdk copied to clipboard

8332154: Memory leak in SynchronousQueue

Open viktorklang-ora opened this issue 1 year ago • 11 comments

Local testing seems to indicate that this fix (which mirrors what's done in the FIFO mode) addresses the problem. Regression test added for JDK20+


Progress

  • [ ] Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • [x] Change must not contain extraneous whitespace
  • [x] Commit message must refer to an issue

Issue

  • JDK-8332154: Memory leak in SynchronousQueue (Bug - P3)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/19271/head:pull/19271
$ git checkout pull/19271

Update a local copy of the PR:
$ git checkout pull/19271
$ git pull https://git.openjdk.org/jdk.git pull/19271/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 19271

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/19271.diff

Webrev

Link to Webrev Comment

viktorklang-ora avatar May 16 '24 14:05 viktorklang-ora

:wave: Welcome back vklang! 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.

bridgekeeper[bot] avatar May 16 '24 14:05 bridgekeeper[bot]

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

8332154: Memory leak in SynchronousQueue

Reviewed-by: alanb

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

  • d6b7f9b170b6ce4f7275cc7595b71b9a3e93c133: 8331851: Add specific regression leap year tests for Calendar.roll()
  • b92bd671835c37cff58e2cdcecd0fe4277557d7f: 8332403: Anachronistic reference to Netscape Communicator in Swing API docs
  • 8acdd2d7c8de17515b87815d54ce556237039406: 8330565: C2: Multiple crashes with CTW after JDK-8316991
  • 0a58cffe88ba823e71fcdcca64b784ed04ca5398: 8298405: Implement JEP 467: Markdown Documentation Comments
  • 39a55e97799b5328da85aaa66c8d23175b305691: 8324809: compiler can crash with SOE while proving if two recursive types are disjoint
  • b7ae0ae1d7481e66a07f40bf01c5614fdf44c2ed: 8328572: JFR: Use Class.forPrimitiveName(String)
  • e611151796d71c40a9395cb6fbe734f36d4c1b55: 8331281: RISC-V: C2: Support vector-scalar and vector-immediate bitwise logic instructions
  • 44bdf9964eb2dd0eb4034576e1f903a27c410286: 8332239: Improve CSS for block tags
  • 9bb6169a1cba900fa79d63119696efe265762083: 8317621: --add-script should support JavaScript modules
  • 4eb1eaf04477b9a8947a57655cf36380b5b88b5c: 8329617: Update stylesheet for specs and tool documentation
  • ... and 67 more: https://git.openjdk.org/jdk/compare/5053b70a7fc67ce9b73dbeecbdd88fbc34d45e04...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[bot] avatar May 16 '24 14:05 openjdk[bot]

@viktorklang-ora The following label will be automatically applied to this pull request:

  • core-libs

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[bot] avatar May 16 '24 14:05 openjdk[bot]

@AlanBateman @DougLea Reviews are most welcome :)

viktorklang-ora avatar May 16 '24 15:05 viktorklang-ora

@viktorklang-ora We managed to reproduce it quite reliably by running the test from the bug report multiple times (in our case, it was 100). I understand this does not make a 100% stable regression reproducer, but in case of multiple runs the probability of false positive in quite low.

knisht avatar May 16 '24 21:05 knisht

Hi @viktorklang-ora The changes was verified as follows

  1. Create the script launching the test (from bug description) in a loop and calculating the number of failures.
cat <<EOF >runme.sh
#!/bin/bash -x

__test_jdk=\$1
__test=\$2
__count=\${3:-20}

i=0
failures=0
while true; do

  ((i=i+1))
  echo i: \$i

  \$__test_jdk/bin/java \
      --add-opens=java.base/java.util.concurrent=ALL-UNNAMED \
      --add-opens=java.base/java.lang=ALL-UNNAMED \
      \$__test || break

  if [ "\$i" -ge "\$__count" ]; then
    break
  fi
done
EOF
  1. Launch the test as follows
bash runme.sh ${test_jdk_home} Main 100

When the test is launched 100 times it is guaranteed to fail in at least one iteration. With this fix no failures were detected in 1000 runs.

vprovodin avatar May 17 '24 03:05 vprovodin

Looks good; thanks. I don't know why I left out this check in a case that is otherwise identical to LTQ.

DougLea avatar May 17 '24 11:05 DougLea

@DougLea I decided to move to using VirtualThreads and therefor pulling the memory leak test out into its own class which only runs for JDK20+.

viktorklang-ora avatar May 17 '24 13:05 viktorklang-ora

Sure. Seems reasonable.

DougLea avatar May 17 '24 13:05 DougLea

@DougLea Perfect, thanks for reviewing! :+1:

viktorklang-ora avatar May 17 '24 17:05 viktorklang-ora

Looks okay, I just wonder how reliable assertDoesntLeak with concurrent agents, debug builds, and VM options such as a Xcomp that will challenge the await(10s). Minimally the timed awaits should be untimed. Another idea is try an ES like this:

        try (var executor = Executors.newVirtualThreadPerTaskExecutor()) {
            for (int i = 0; i < NUMBER_OF_ITEMS; i++) {
                executor.submit( .. producer .. );
                executor.submit(.. consumer ..);
            }
        }

No need for the count down latches or the need to retry on InterruptedException. The close method waits for the 400 virtual threads to finish so you can assert that the queue is empty.

The loop that waits for survivors to empty can be unbounded too. If there is a leak then the test will timeout.

AlanBateman avatar May 20 '24 14:05 AlanBateman

@AlanBateman Great suggestions, Alan. I've updated the PR to reflect your improvements.

viktorklang-ora avatar May 20 '24 15:05 viktorklang-ora

/integrate

viktorklang-ora avatar May 20 '24 18:05 viktorklang-ora

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

  • 7652f9811bfddf08650b0c3277012074873deade: 8331885: C2: meet between unloaded and speculative types is not symmetric
  • d6b7f9b170b6ce4f7275cc7595b71b9a3e93c133: 8331851: Add specific regression leap year tests for Calendar.roll()
  • b92bd671835c37cff58e2cdcecd0fe4277557d7f: 8332403: Anachronistic reference to Netscape Communicator in Swing API docs
  • 8acdd2d7c8de17515b87815d54ce556237039406: 8330565: C2: Multiple crashes with CTW after JDK-8316991
  • 0a58cffe88ba823e71fcdcca64b784ed04ca5398: 8298405: Implement JEP 467: Markdown Documentation Comments
  • 39a55e97799b5328da85aaa66c8d23175b305691: 8324809: compiler can crash with SOE while proving if two recursive types are disjoint
  • b7ae0ae1d7481e66a07f40bf01c5614fdf44c2ed: 8328572: JFR: Use Class.forPrimitiveName(String)
  • e611151796d71c40a9395cb6fbe734f36d4c1b55: 8331281: RISC-V: C2: Support vector-scalar and vector-immediate bitwise logic instructions
  • 44bdf9964eb2dd0eb4034576e1f903a27c410286: 8332239: Improve CSS for block tags
  • 9bb6169a1cba900fa79d63119696efe265762083: 8317621: --add-script should support JavaScript modules
  • ... and 68 more: https://git.openjdk.org/jdk/compare/5053b70a7fc67ce9b73dbeecbdd88fbc34d45e04...master

Your commit was automatically rebased without conflicts.

openjdk[bot] avatar May 20 '24 18:05 openjdk[bot]

@viktorklang-ora Pushed as commit b78613b6813a85662fb2af2004d0b68002fe471d.

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

openjdk[bot] avatar May 20 '24 18:05 openjdk[bot]

@knisht @vprovodin Thanks for the thoughts, I decided to go for a blackbox test to make sure that this test does not rely on any internal impl details of SynchronousQueue.

viktorklang-ora avatar May 21 '24 11:05 viktorklang-ora