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

8318720: G1: Memory leak in G1CodeRootSet after JDK-8315503 #16352

Closed
wants to merge 4 commits into from

Conversation

zhengyu123
Copy link
Contributor

@zhengyu123 zhengyu123 commented Oct 24, 2023

Calling ConcurrentHashTable:table.unsafe_reset() in G1CodeRootSet::clear() does not free the entries that still in the table. This patch empties the table before the unsafe_reset() call to avoid memory leak.

Test:
tier1 and tier2 (fastdebug and release) on Linux x86_64


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-8318720: G1: Memory leak in G1CodeRootSet after JDK-8315503 (Bug - P3)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 16352

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 24, 2023

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

openjdk bot commented Oct 24, 2023

@zhengyu123 The following label will be automatically applied to this pull request:

  • hotspot-gc

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

mlbridge bot commented Oct 24, 2023

Webrevs

Comment on lines 146 to 164
size_t num_entries = Atomic::load(&_num_entries);
if (num_entries != 0) {
auto do_value =
[] (nmethod** value) {
return true;
};

size_t num_deleted = 0;
auto do_delete =
[&] (nmethod** value) {
num_deleted++;
};

bool succeeded = _table.try_bulk_delete(Thread::current(), do_value, do_delete);
guarantee(succeeded, "unable to clean table");
assert(num_entries == num_deleted, "must empty the table");
Atomic::store(&_num_entries, (size_t)0);
}
_table.unsafe_reset();
Copy link
Contributor

@tschatzl tschatzl Oct 25, 2023

Choose a reason for hiding this comment

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

Thanks for catching this!

I believe something like a call to _table.clean([] (nmethod** value) { return true; }); should do roughly the same. (It is fine to name the lambda with something meaningful, like always_true. Or delete_all. do_value is just too unspecific to me).

Copy link
Contributor

Choose a reason for hiding this comment

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

Another option is to provide a reset function in the CHT itself that roughly does what the destructor does right now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's the first place I looked. But free_nodes is not MT-safe, I am not sure it will fit well with other APIs that all seem to be MT-safe.

I also thought about move G1CodeRootSetHashTable::clear() implementation to CHT, but likely I would need another version for safepoint? (e.g. use _table.bulk_delete instead).

Hope to have a chance to return to JVM development fulltime, so I will have time to think about it. For now, I will let you to worry about the refactoring :-)

Copy link
Contributor

@tschatzl tschatzl Oct 25, 2023

Choose a reason for hiding this comment

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

I would strongly prefer something like this after some "worrying about the refactoring" ;)
Passes gc/g1 testing.

Copy link
Contributor

@tschatzl tschatzl Oct 25, 2023

Choose a reason for hiding this comment

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

It's small enough to copy it in here:

  void clear() {
    // Remove all entries.
    auto always_true = [] (nmethod** value) {
                         return true;
                       };

    clean(always_true);
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I was confused by _table.clean() and could not find clean() in CHT. Updated.

@zhengyu123
Copy link
Contributor Author

/add author tschatzl

@openjdk
Copy link

openjdk bot commented Oct 25, 2023

@zhengyu123 Unknown command add - for a list of valid commands use /help.

@zhengyu123
Copy link
Contributor Author

/help

Copy link
Contributor

@tschatzl tschatzl left a comment

Choose a reason for hiding this comment

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

Lgtm :)

@openjdk
Copy link

openjdk bot commented Oct 25, 2023

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

8318720: G1: Memory leak in G1CodeRootSet after JDK-8315503

Reviewed-by: tschatzl

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

  • 43f31d7: 8318607: Enable parallelism in vmTestbase/nsk/stress/jni tests
  • cee44a6: 8318608: Enable parallelism in vmTestbase/nsk/stress/threads tests
  • b026d0b: 8312980: C2: "malformed control flow" created during incremental inlining
  • 3abd772: 8316017: Refactor timeout handler in PassFailJFrame
  • 202c013: 8318669: Target OS detection in 'test-prebuilt' makefile target is incorrect when running on MSYS2
  • c587211: 8316003: Update FileChooserSymLinkTest.java to HTML instructions
  • 42b9ac8: 8294156: Allow PassFailJFrame.Builder to create test UI
  • 14090ef: 8294158: HTML formatting for PassFailJFrame instructions
  • d2d1592: 8318713: G1: Use more accurate age in predict_eden_copy_time_ms
  • c3cdfe2: 8318692: Add instructions for creating Ubuntu-based sysroot for cross compilation
  • ... and 32 more: https://git.openjdk.org/jdk/compare/1b150117fd9ccb7ff8adc012b74d7d95e5219b94...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 Oct 25, 2023
@openjdk
Copy link

openjdk bot commented Oct 25, 2023

@zhengyu123 Available commands:

  • approval - request for maintainer's approval
  • approve - null
  • author - sets an overriding author to be used in the commit when the PR is integrated
  • backport - create a backport
  • cc - add or remove an additional classification label
  • clean - Mark the backport pull request as a clean backport
  • contributor - adds or removes additional contributors for a PR
  • covered - used when employer has signed the OCA
  • csr - require a compatibility and specification request (CSR) for this pull request
  • help - shows this text
  • integrate - performs integration of the changes in the PR
  • issue - edit the list of issues that this PR solves
  • jep - require a JDK Enhancement Proposal (JEP) for this pull request
  • label - add or remove an additional classification label
  • open - Set the pull request state to "open"
  • reviewer - manage additional reviewers for a PR
  • reviewers - set the number of additional required reviewers for this PR
  • signed - used after signing the OCA
  • solves - edit the list of issues that this PR solves
  • sponsor - performs integration of a PR that is authored by a non-committer
  • summary - updates the summary in the commit message
  • test - used to run tests

@zhengyu123
Copy link
Contributor Author

Thanks, @tschatzl

@zhengyu123
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Oct 25, 2023

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

  • a542f73: 8318843: ProblemList java/lang/management/MemoryMXBean/CollectionUsageThreshold.java in Xcomp
  • d96f38b: 8317510: Change Windows debug symbol files naming to avoid losing info when an executable and a library share the same name
  • 10427c0: 8318613: ChoiceFormat patterns are not well tested
  • ca3bdfc: 8318186: ChoiceFormat inconsistency between applyPattern() and setChoices()
  • a520887: 8318487: Specification of the ListFormat.equals() method can be improved
  • cf4ede0: 8317360: Missing null checks in JfrCheckpointManager and JfrStringPool initialization routines
  • 9e98ee6: 8318735: RISC-V: Enable related hotspot tests run on riscv
  • 29d462a: 8318727: Enable parallelism in vmTestbase/vm/gc/concurrent tests
  • 43f31d7: 8318607: Enable parallelism in vmTestbase/nsk/stress/jni tests
  • cee44a6: 8318608: Enable parallelism in vmTestbase/nsk/stress/threads tests
  • ... and 40 more: https://git.openjdk.org/jdk/compare/1b150117fd9ccb7ff8adc012b74d7d95e5219b94...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Oct 25, 2023

@zhengyu123 Pushed as commit 811b436.

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

@zhengyu123 zhengyu123 deleted the JDK-8318720 branch October 26, 2023 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-gc hotspot-gc-dev@openjdk.org integrated Pull request has been integrated
2 participants