Skip to content

Commit

Permalink
8304138: [JVMCI] Test FailedSpeculation existence before appending.
Browse files Browse the repository at this point in the history
Reviewed-by: kvn, dnsimon
  • Loading branch information
Yudi Zheng authored and Doug Simon committed Mar 18, 2023
1 parent f8482c2 commit 7503ecc
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/hotspot/share/oops/methodData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -837,27 +837,37 @@ static void guarantee_failed_speculations_alive(nmethod* nm, FailedSpeculation**
bool FailedSpeculation::add_failed_speculation(nmethod* nm, FailedSpeculation** failed_speculations_address, address speculation, int speculation_len) {
assert(failed_speculations_address != nullptr, "must be");
size_t fs_size = sizeof(FailedSpeculation) + speculation_len;
FailedSpeculation* fs = new (fs_size) FailedSpeculation(speculation, speculation_len);
if (fs == nullptr) {
// no memory -> ignore failed speculation
return false;
}

guarantee(is_aligned(fs, sizeof(FailedSpeculation*)), "FailedSpeculation objects must be pointer aligned");
guarantee_failed_speculations_alive(nm, failed_speculations_address);

FailedSpeculation** cursor = failed_speculations_address;
FailedSpeculation* fs = nullptr;
do {
if (*cursor == nullptr) {
if (fs == nullptr) {
// lazily allocate FailedSpeculation
fs = new (fs_size) FailedSpeculation(speculation, speculation_len);
if (fs == nullptr) {
// no memory -> ignore failed speculation
return false;
}
guarantee(is_aligned(fs, sizeof(FailedSpeculation*)), "FailedSpeculation objects must be pointer aligned");
}
FailedSpeculation* old_fs = Atomic::cmpxchg(cursor, (FailedSpeculation*) nullptr, fs);
if (old_fs == nullptr) {
// Successfully appended fs to end of the list
return true;
}
cursor = old_fs->next_adr();
} else {
cursor = (*cursor)->next_adr();
}
guarantee(*cursor != nullptr, "cursor must point to non-null FailedSpeculation");
// check if the current entry matches this thread's failed speculation
if ((*cursor)->data_len() == speculation_len && memcmp(speculation, (*cursor)->data(), speculation_len) == 0) {
if (fs != nullptr) {
delete fs;
}
return false;
}
cursor = (*cursor)->next_adr();
} while (true);
}

Expand Down

1 comment on commit 7503ecc

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.