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

JDK-8280002: jmap -histo may leak stream #7078

Closed

Conversation

tstuefe
Copy link
Member

@tstuefe tstuefe commented Jan 14, 2022

Very trivial fix to a handle/memory leak.

JDK-8215624 added parallel heap iteration to both jmap -histo and jcmd GC.class_histogram. When called with an explicit file and an invalid argument for number of threads, it leaks the file (bit of memory and a handle).

Reproduce with:

jmap -histo:parallel=notanumber,file=xx.txt

Can only be reproduced with jmap. jcmd is safe, arguments are handled correctly in shared code.


Progress

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

Issue

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 7078

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Jan 14, 2022

👋 Welcome back stuefe! 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 14, 2022
@openjdk
Copy link

openjdk bot commented Jan 14, 2022

@tstuefe The following labels will be automatically applied to this pull request:

  • hotspot-runtime
  • serviceability

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

@openjdk openjdk bot added serviceability serviceability-dev@openjdk.org hotspot-runtime hotspot-runtime-dev@openjdk.org labels Jan 14, 2022
@mlbridge
Copy link

mlbridge bot commented Jan 14, 2022

Webrevs

@shipilev
Copy link
Member

shipilev commented Jan 14, 2022

This is not as trivial, AFAICS. Note that the existing code delete fs after checking if (os != NULL && os != out). Does it mean this patch can effectively delete out? Or can it call delete nullptr?

@tstuefe
Copy link
Member Author

tstuefe commented Jan 14, 2022

This is not as trivial, AFAICS. Note that the existing code delete fs after checking if (os != NULL && os != out). Does it mean this patch can effectively delete out?

Thanks for looking at this. No, it is safe.

fs is a temporary fileStream which may or may not be NULL. It is safe to delete it. The delete you mention could be moved out of the condition and it would still be fine. The condition is only really needed for the output which should only appear if you don't write to stdout.

Copy link
Member

@shipilev shipilev left a comment

Choose a reason for hiding this comment

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

Okay then!

@openjdk
Copy link

openjdk bot commented Jan 14, 2022

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

8280002: jmap -histo may leak stream

Reviewed-by: shade, sspitsyn

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

  • fb8fdc0: 8279990: (fs) Awkward verbiage in description of Files.createTempFile(Path,String,String,FileAttribute)
  • d9dd485: 8280019: Remove unused code from metaspace
  • cf283e2: 8279570: IGV: Add source/destination property for load and store nodes with an associated field
  • f180530: 8279918: Fix various doc typos
  • ac98b22: 8280028: [BACKOUT] Parallel: More precise boundary in ObjectStartArray::object_starts_in_range
  • 61b8944: 8278851: Correct signer logic for jars signed with multiple digestalgs
  • 35734ad: 8279545: Buffer overrun in reverse_words of sharedRuntime_x86_64.cpp:3517
  • e8f494c: 8279825: JFR: JFCModel shouldn't need FilePermission to read predefined .jfc files
  • 9f30ec1: 8278398: jwebserver: Add test to confirm maximum request time
  • dd76a28: 8280000: Remove unused CardTable::find_covering_region_containing
  • ... and 1 more: https://git.openjdk.java.net/jdk/compare/965c64bca713446e7e513170aa9138a8a5eec5de...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 14, 2022
@tstuefe
Copy link
Member Author

tstuefe commented Jan 14, 2022

Okay then!

Thanks, Alexey!

After your concerns I consider this to be not trivial enough, so I wait for a second reviewer.

Copy link
Contributor

@sspitsyn sspitsyn left a comment

Choose a reason for hiding this comment

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

Hi Thomas,
Nice catch.
Looks good to me.
Thanks,
Serguei

@tstuefe
Copy link
Member Author

tstuefe commented Jan 14, 2022

Thanks, @shipilev and @sspitsyn !

/integrate

@openjdk
Copy link

openjdk bot commented Jan 14, 2022

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

  • fb8fdc0: 8279990: (fs) Awkward verbiage in description of Files.createTempFile(Path,String,String,FileAttribute)
  • d9dd485: 8280019: Remove unused code from metaspace
  • cf283e2: 8279570: IGV: Add source/destination property for load and store nodes with an associated field
  • f180530: 8279918: Fix various doc typos
  • ac98b22: 8280028: [BACKOUT] Parallel: More precise boundary in ObjectStartArray::object_starts_in_range
  • 61b8944: 8278851: Correct signer logic for jars signed with multiple digestalgs
  • 35734ad: 8279545: Buffer overrun in reverse_words of sharedRuntime_x86_64.cpp:3517
  • e8f494c: 8279825: JFR: JFCModel shouldn't need FilePermission to read predefined .jfc files
  • 9f30ec1: 8278398: jwebserver: Add test to confirm maximum request time
  • dd76a28: 8280000: Remove unused CardTable::find_covering_region_containing
  • ... and 1 more: https://git.openjdk.java.net/jdk/compare/965c64bca713446e7e513170aa9138a8a5eec5de...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jan 14, 2022
@openjdk openjdk bot closed this Jan 14, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jan 14, 2022
@openjdk
Copy link

openjdk bot commented Jan 14, 2022

@tstuefe Pushed as commit c359c35.

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

@tstuefe tstuefe deleted the JDK-8280002-memory-leak-jmap-histo branch August 24, 2023 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-runtime hotspot-runtime-dev@openjdk.org integrated Pull request has been integrated serviceability serviceability-dev@openjdk.org
3 participants