Skip to content

8358330: AsmRemarks and DbgStrings clear() method may not get called before their destructor #25598

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/hotspot/share/asm/codeBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1099,14 +1099,19 @@ CHeapString::~CHeapString() {
// offset is a byte offset into an instruction stream (CodeBuffer, CodeBlob or
// other memory buffer) and remark is a string (comment).
//
AsmRemarks::AsmRemarks() : _remarks(new AsmRemarkCollection()) {
AsmRemarks::AsmRemarks() {
init();
assert(_remarks != nullptr, "Allocation failure!");
}

AsmRemarks::~AsmRemarks() {
assert(_remarks == nullptr, "Must 'clear()' before deleting!");
}

void AsmRemarks::init() {
_remarks = new AsmRemarkCollection();
}

const char* AsmRemarks::insert(uint offset, const char* remstr) {
precond(remstr != nullptr);
return _remarks->insert(offset, remstr);
Expand Down Expand Up @@ -1151,14 +1156,19 @@ uint AsmRemarks::print(uint offset, outputStream* strm) const {
// Acting as interface to reference counted collection of (debug) strings used
// in the code generated, and thus requiring a fixed address.
//
DbgStrings::DbgStrings() : _strings(new DbgStringCollection()) {
DbgStrings::DbgStrings() {
init();
assert(_strings != nullptr, "Allocation failure!");
}

DbgStrings::~DbgStrings() {
assert(_strings == nullptr, "Must 'clear()' before deleting!");
}

void DbgStrings::init() {
_strings = new DbgStringCollection();
}

const char* DbgStrings::insert(const char* dbgstr) {
const char* str = _strings->lookup(dbgstr);
return str != nullptr ? str : _strings->insert(dbgstr);
Expand Down
4 changes: 4 additions & 0 deletions src/hotspot/share/asm/codeBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ class AsmRemarks {
AsmRemarks();
~AsmRemarks();

void init();

const char* insert(uint offset, const char* remstr);

bool is_empty() const;
Expand All @@ -452,6 +454,8 @@ class DbgStrings {
DbgStrings();
~DbgStrings();

void init();

const char* insert(const char* dbgstr);

bool is_empty() const;
Expand Down
18 changes: 7 additions & 11 deletions src/hotspot/share/code/aotCodeCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -915,26 +915,22 @@ CodeBlob* AOTCodeReader::compile_code_blob(const char* name, int entry_offset_co
oop_maps = read_oop_map_set();
}

#ifndef PRODUCT
AsmRemarks asm_remarks;
read_asm_remarks(asm_remarks);
DbgStrings dbg_strings;
read_dbg_strings(dbg_strings);
#endif // PRODUCT

CodeBlob* code_blob = CodeBlob::create(archived_blob,
stored_name,
reloc_data,
oop_maps
#ifndef PRODUCT
, asm_remarks
, dbg_strings
#endif
);
if (code_blob == nullptr) { // no space left in CodeCache
return nullptr;
}

#ifndef PRODUCT
code_blob->asm_remarks().init();
read_asm_remarks(code_blob->asm_remarks());
code_blob->dbg_strings().init();
read_dbg_strings(code_blob->dbg_strings());
#endif // PRODUCT

fix_relocations(code_blob);

// Read entries offsets
Expand Down
11 changes: 0 additions & 11 deletions src/hotspot/share/code/codeBlob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,6 @@ CodeBlob* CodeBlob::create(CodeBlob* archived_blob,
const char* name,
address archived_reloc_data,
ImmutableOopMapSet* archived_oop_maps
#ifndef PRODUCT
, AsmRemarks& archived_asm_remarks
, DbgStrings& archived_dbg_strings
#endif // PRODUCT
)
{
ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
Expand All @@ -303,13 +299,6 @@ CodeBlob* CodeBlob::create(CodeBlob* archived_blob,
archived_oop_maps);
assert(blob != nullptr, "sanity check");

#ifndef PRODUCT
blob->use_remarks(archived_asm_remarks);
archived_asm_remarks.clear();
blob->use_strings(archived_dbg_strings);
archived_dbg_strings.clear();
#endif // PRODUCT

// Flush the code block
ICache::invalidate_range(blob->code_begin(), blob->code_size());
CodeCache::commit(blob); // Count adapters
Expand Down
7 changes: 1 addition & 6 deletions src/hotspot/share/code/codeBlob.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,7 @@ class CodeBlob {
static CodeBlob* create(CodeBlob* archived_blob,
const char* name,
address archived_reloc_data,
ImmutableOopMapSet* archived_oop_maps
#ifndef PRODUCT
, AsmRemarks& archived_asm_remarks
, DbgStrings& archived_dbg_strings
#endif // PRODUCT
);
ImmutableOopMapSet* archived_oop_maps);
};

//----------------------------------------------------------------------------------------------------
Expand Down