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

8332154: Memory leak in SynchronousQueue #19271

Closed
wants to merge 5 commits into from

Conversation

viktorklang-ora
Copy link
Contributor

@viktorklang-ora viktorklang-ora commented May 16, 2024

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)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

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

Reviewers

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

@bridgekeeper
Copy link

bridgekeeper bot commented May 16, 2024

👋 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.

@openjdk
Copy link

openjdk bot commented May 16, 2024

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

  • d6b7f9b: 8331851: Add specific regression leap year tests for Calendar.roll()
  • b92bd67: 8332403: Anachronistic reference to Netscape Communicator in Swing API docs
  • 8acdd2d: 8330565: C2: Multiple crashes with CTW after JDK-8316991
  • 0a58cff: 8298405: Implement JEP 467: Markdown Documentation Comments
  • 39a55e9: 8324809: compiler can crash with SOE while proving if two recursive types are disjoint
  • b7ae0ae: 8328572: JFR: Use Class.forPrimitiveName(String)
  • e611151: 8331281: RISC-V: C2: Support vector-scalar and vector-immediate bitwise logic instructions
  • 44bdf99: 8332239: Improve CSS for block tags
  • 9bb6169: 8317621: --add-script should support JavaScript modules
  • 4eb1eaf: 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 openjdk bot added the rfr Pull request is ready for review label May 16, 2024
@openjdk
Copy link

openjdk bot commented May 16, 2024

@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 openjdk bot added the core-libs core-libs-dev@openjdk.org label May 16, 2024
@mlbridge
Copy link

mlbridge bot commented May 16, 2024

Webrevs

@viktorklang-ora
Copy link
Contributor Author

@AlanBateman @DougLea Reviews are most welcome :)

@knisht
Copy link

knisht commented May 16, 2024

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

@vprovodin
Copy link

vprovodin commented May 17, 2024

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.

@DougLea
Copy link
Contributor

DougLea commented May 17, 2024

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

…d runs only for JDK20+, using VirtualThreads
@viktorklang-ora
Copy link
Contributor Author

@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+.

@DougLea
Copy link
Contributor

DougLea commented May 17, 2024

Sure. Seems reasonable.

@viktorklang-ora
Copy link
Contributor Author

@DougLea Perfect, thanks for reviewing! 👍

@AlanBateman
Copy link
Contributor

AlanBateman commented May 20, 2024

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.

@viktorklang-ora
Copy link
Contributor Author

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

@openjdk openjdk bot added the ready Pull request is ready to be integrated label May 20, 2024
@viktorklang-ora
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented May 20, 2024

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

  • 7652f98: 8331885: C2: meet between unloaded and speculative types is not symmetric
  • d6b7f9b: 8331851: Add specific regression leap year tests for Calendar.roll()
  • b92bd67: 8332403: Anachronistic reference to Netscape Communicator in Swing API docs
  • 8acdd2d: 8330565: C2: Multiple crashes with CTW after JDK-8316991
  • 0a58cff: 8298405: Implement JEP 467: Markdown Documentation Comments
  • 39a55e9: 8324809: compiler can crash with SOE while proving if two recursive types are disjoint
  • b7ae0ae: 8328572: JFR: Use Class.forPrimitiveName(String)
  • e611151: 8331281: RISC-V: C2: Support vector-scalar and vector-immediate bitwise logic instructions
  • 44bdf99: 8332239: Improve CSS for block tags
  • 9bb6169: 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 openjdk bot added the integrated Pull request has been integrated label May 20, 2024
@openjdk openjdk bot closed this May 20, 2024
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels May 20, 2024
@openjdk
Copy link

openjdk bot commented May 20, 2024

@viktorklang-ora Pushed as commit b78613b.

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

@viktorklang-ora
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated
5 participants