Skip to content

8303068: Memory leak in DwarfFile::LineNumberProgram::run_line_number_program#12738

Closed
dholmes-ora wants to merge 3 commits intoopenjdk:masterfrom
dholmes-ora:8303068-leak
Closed

8303068: Memory leak in DwarfFile::LineNumberProgram::run_line_number_program#12738
dholmes-ora wants to merge 3 commits intoopenjdk:masterfrom
dholmes-ora:8303068-leak

Conversation

@dholmes-ora
Copy link
Member

@dholmes-ora dholmes-ora commented Feb 24, 2023

After allocating:

_state = new (std::nothrow) LineNumberProgramState(_header);

we need to delete _state before returning.

Testing: tiers 1-3

Thanks.


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-8303068: Memory leak in DwarfFile::LineNumberProgram::run_line_number_program

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 12738

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 24, 2023

👋 Welcome back dholmes! 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 Feb 24, 2023
@openjdk
Copy link

openjdk bot commented Feb 24, 2023

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

  • hotspot

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 hotspot hotspot-dev@openjdk.org label Feb 24, 2023
@mlbridge
Copy link

mlbridge bot commented Feb 24, 2023

Webrevs

@jdksjolen
Copy link
Contributor

Hi David,

LineNumberProgram is used in elFile.cpp:704, is stack allocated and has exactly one entry point: find_filename_and_line_number. LineNumberProgramState is used only internally by LineNumberProgramState.

LineNumberProgram's current size is 120 bytes. The size of LineNumberProgramState is 48 bytes.

Can't we change the type of _state to LineNumberProgramState? This bloats the size up to 168 bytes, but we no longer have to care about tracking the resource or have another heap allocation call. Yes, we have to change -> to ., so the change is larger, but it's conceptually simpler.

FWIW, _state is also always re-allocated, so I don't see why we even need the reset() method on it, but that's a future RFE.

@dholmes-ora
Copy link
Member Author

Can't we change the type of _state to LineNumberProgramState?

I think you meant change to LineNumberProgram ?

I'm not really familiar with this code and just want to fix the memory leak that was detected. Any redesign of the code really needs to be a separate RFE.

@jcking
Copy link
Contributor

jcking commented Feb 25, 2023

Can't we change the type of _state to LineNumberProgramState?

I think you meant change to LineNumberProgram ?

I'm not really familiar with this code and just want to fix the memory leak that was detected. Any redesign of the code really needs to be a separate RFE.

I agree. Let's take the path of least resistance to removing the leak and follow up with simplification in another PR.

Copy link
Contributor

@jdksjolen jdksjolen left a comment

Choose a reason for hiding this comment

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

OK, that's fair to me, thanks for the changes.

@jdksjolen
Copy link
Contributor

 #else
   DWARF_LOG_DEBUG("Address:              Line:    Column:   File:");
 #endif
-  _state = new (std::nothrow) LineNumberProgramState(_header);
+  LineNumberProgramState state{_header};
+  _state = &state;
   if (_state == nullptr) {
     DWARF_LOG_ERROR("Failed to create new LineNumberProgramState object");
     return false;

Isn't this equivalent?

@jcking
Copy link
Contributor

jcking commented Feb 26, 2023

 #else
   DWARF_LOG_DEBUG("Address:              Line:    Column:   File:");
 #endif
-  _state = new (std::nothrow) LineNumberProgramState(_header);
+  LineNumberProgramState state{_header};
+  _state = &state;
   if (_state == nullptr) {
     DWARF_LOG_ERROR("Failed to create new LineNumberProgramState object");
     return false;

Isn't this equivalent?

You'd have to clear _state before returning from the function for safety.

@dholmes-ora
Copy link
Member Author

I'm going to have to look at this in much more detail. I thought _state was just locally used but it isn't. So I can't just delete it in the non-error cases, and probably need to reset to nullptr as well. That also prevents using the trick @jdksjolen suggested with the stack allocated instance.

@dholmes-ora
Copy link
Member Author

Okay I just pushed a much simpler, cleaner and more robust fix, by adding a destructor for LineNumberProgram.

Copy link
Contributor

@jdksjolen jdksjolen left a comment

Choose a reason for hiding this comment

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

Re-approving

@openjdk
Copy link

openjdk bot commented Feb 27, 2023

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

8303068: Memory leak in DwarfFile::LineNumberProgram::run_line_number_program

Reviewed-by: jsjolen, tschatzl, chagedorn

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

  • f2b03f9: 8303051: Stop saving 5 chunks in each ChunkPool
  • fbc036e: 8303135: JFR: Log periodic events using periodic tag
  • dbb5581: 8081474: SwingWorker calls 'done' before the 'doInBackground' is finished
  • 306134d: 8300792: Refactor examples in java.net.http to use @snippet
  • a2c5a4a: 8302732: sun/net/www/http/HttpClient/MultiThreadTest.java still failing intermittently
  • db217c9: 8292583: Comment for ciArrayKlass::make is wrong
  • 2613b94: 8302149: Speed up compiler/jsr292/methodHandleExceptions/TestAMEnotNPE.java
  • d2660a6: 8303045: Remove RegionNode::LoopStatus::NeverIrreducibleEntry assert with wrong assumption
  • 1794f49: 8302681: [IR Framework] Only allow cpuFeatures from a verified list
  • a43931b: 8303102: jcmd: ManagementAgent.status truncates the text longer than O_BUFLEN
  • ... and 25 more: https://git.openjdk.org/jdk/compare/fcaf871408321ed523cf1c6dd3adf9914f2bf9aa...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 Feb 27, 2023
Copy link
Member

@chhagedorn chhagedorn 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, thanks for fixing this!

@dholmes-ora
Copy link
Member Author

Thanks for the reviews @jdksjolen , @tschatzl and @chhagedorn !

/integrate

@openjdk
Copy link

openjdk bot commented Feb 27, 2023

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

  • 784f7b1: 8293667: Align jlink's --compress option with jmod's --compress option
  • 54603aa: 8303208: JFR: 'jfr print' displays incorrect timestamps
  • 4c169d2: 8303253: Remove unnecessary calls to super() in java.time value based classes
  • b527edd: 8292914: Lambda proxies have unstable names
  • 42330d2: 8029370: (fc) FileChannel javadoc not clear for cases where position == size
  • a253b46: 8301119: Support for GB18030-2022
  • 55e6bb6: 8302685: Some javac unit tests aren't reliably closing open files
  • f5a1276: 8262895: [macos_aarch64] runtime/CompressedOops/CompressedClassPointers.java fails with 'Narrow klass base: 0x0000000000000000' missing from stdout/stderr
  • 2fe4e5f: 8303169: Remove Windows specific workaround from libdt
  • f2b03f9: 8303051: Stop saving 5 chunks in each ChunkPool
  • ... and 34 more: https://git.openjdk.org/jdk/compare/fcaf871408321ed523cf1c6dd3adf9914f2bf9aa...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Feb 27, 2023

@dholmes-ora Pushed as commit f7f1036.

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

@dholmes-ora dholmes-ora deleted the 8303068-leak branch February 27, 2023 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotspot hotspot-dev@openjdk.org integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

5 participants