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

Reviewed-by: kvn
This commit is contained in:
Ashutosh Mehra 2025-06-04 16:52:38 +00:00
parent 8a79ac8863
commit fd0ab04367
5 changed files with 24 additions and 30 deletions

View File

@ -1099,7 +1099,8 @@ 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!");
}
@ -1107,6 +1108,10 @@ 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);
@ -1151,7 +1156,8 @@ 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!");
}
@ -1159,6 +1165,10 @@ 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);

View File

@ -426,6 +426,8 @@ class AsmRemarks {
AsmRemarks();
~AsmRemarks();
void init();
const char* insert(uint offset, const char* remstr);
bool is_empty() const;
@ -452,6 +454,8 @@ class DbgStrings {
DbgStrings();
~DbgStrings();
void init();
const char* insert(const char* dbgstr);
bool is_empty() const;

View File

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

View File

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

View File

@ -318,12 +318,7 @@ public:
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);
};
//----------------------------------------------------------------------------------------------------