Skip to content

Commit

Permalink
8319955: Improve dependencies removal during class unloading
Browse files Browse the repository at this point in the history
Reviewed-by: dholmes, eosterlund
  • Loading branch information
Thomas Schatzl committed Nov 15, 2023
1 parent 4c1540b commit fbe1937
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
43 changes: 39 additions & 4 deletions src/hotspot/share/code/dependencyContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ void DependencyContext::add_dependent_nmethod(nmethod* nm) {
}

void DependencyContext::release(nmethodBucket* b) {
bool expunge = Atomic::load(&_cleaning_epoch) == 0;
if (expunge) {
if (delete_on_release()) {
assert_locked_or_safepoint(CodeCache_lock);
delete b;
if (UsePerfData) {
Expand Down Expand Up @@ -178,9 +177,41 @@ nmethodBucket* DependencyContext::release_and_get_next_not_unloading(nmethodBuck
//
// Invalidate all dependencies in the context
void DependencyContext::remove_all_dependents() {
nmethodBucket* b = dependencies_not_unloading();
// Assume that the dependency is not deleted immediately but moved into the
// purge list when calling this.
assert(!delete_on_release(), "should not delete on release");

nmethodBucket* first = Atomic::load_acquire(_dependency_context_addr);
if (first == nullptr) {
return;
}

nmethodBucket* cur = first;
nmethodBucket* last = cur;
jlong count = 0;
for (; cur != nullptr; cur = cur->next()) {
assert(cur->get_nmethod()->is_unloading(), "must be");
last = cur;
count++;
}

// Add the whole list to the purge list at once.
nmethodBucket* old_purge_list_head = Atomic::load(&_purge_list);
for (;;) {
last->set_purge_list_next(old_purge_list_head);
nmethodBucket* next_purge_list_head = Atomic::cmpxchg(&_purge_list, old_purge_list_head, first);
if (old_purge_list_head == next_purge_list_head) {
break;
}
old_purge_list_head = next_purge_list_head;
}

if (UsePerfData) {
_perf_total_buckets_stale_count->inc(count);
_perf_total_buckets_stale_acc_count->inc(count);
}

set_dependencies(nullptr);
assert(b == nullptr, "All dependents should be unloading");
}

void DependencyContext::remove_and_mark_for_deoptimization_all_dependents(DeoptimizationScope* deopt_scope) {
Expand Down Expand Up @@ -234,6 +265,10 @@ bool DependencyContext::claim_cleanup() {
return Atomic::cmpxchg(_last_cleanup_addr, last_cleanup, cleaning_epoch) == last_cleanup;
}

bool DependencyContext::delete_on_release() {
return Atomic::load(&_cleaning_epoch) == 0;
}

// Retrieve the first nmethodBucket that has a dependent that does not correspond to
// an is_unloading nmethod. Any nmethodBucket entries observed from the original head
// that is_unloading() will be unlinked and placed on the purge list.
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/code/dependencyContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class DependencyContext : public StackObj {
volatile uint64_t* _last_cleanup_addr;

bool claim_cleanup();
static bool delete_on_release();
void set_dependencies(nmethodBucket* b);
nmethodBucket* dependencies();
nmethodBucket* dependencies_not_unloading();
Expand Down

3 comments on commit fbe1937

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@GoeLin
Copy link
Member

@GoeLin GoeLin commented on fbe1937 Apr 5, 2024

Choose a reason for hiding this comment

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

/backport jdk21u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on fbe1937 Apr 5, 2024

Choose a reason for hiding this comment

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

@GoeLin the backport was successfully created on the branch backport-GoeLin-fbe19378 in my personal fork of openjdk/jdk21u-dev. To create a pull request with this backport targeting openjdk/jdk21u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit fbe19378 from the openjdk/jdk repository.

The commit being backported was authored by Thomas Schatzl on 15 Nov 2023 and was reviewed by David Holmes and Erik Österlund.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21u-dev:

$ git fetch https://github.com/openjdk-bots/jdk21u-dev.git backport-GoeLin-fbe19378:backport-GoeLin-fbe19378
$ git checkout backport-GoeLin-fbe19378
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21u-dev.git backport-GoeLin-fbe19378

Please sign in to comment.