diff --git a/src/hotspot/share/asm/codeBuffer.cpp b/src/hotspot/share/asm/codeBuffer.cpp index f1dbb16760b..ab8aed1cb66 100644 --- a/src/hotspot/share/asm/codeBuffer.cpp +++ b/src/hotspot/share/asm/codeBuffer.cpp @@ -1250,6 +1250,7 @@ bool DbgStrings::is_empty() const { void DbgStrings::share(const DbgStrings &src) { precond(is_empty()); + clear(); _strings = src._strings->reuse(); } diff --git a/src/hotspot/share/interpreter/interpreter.cpp b/src/hotspot/share/interpreter/interpreter.cpp index 6417f9dfd39..3c4ff4c1749 100644 --- a/src/hotspot/share/interpreter/interpreter.cpp +++ b/src/hotspot/share/interpreter/interpreter.cpp @@ -114,6 +114,11 @@ CodeletMark::~CodeletMark() { NOT_PRODUCT(_clet->use_strings((*_masm)->code()->dbg_strings())); AbstractInterpreter::code()->commit(committed_code_size); + } else { + // InterpreterCodelet is not being commited and may be re-used. We need to free the storage for + // remarks and strings. + NOT_PRODUCT(_clet->clear_remarks()); + NOT_PRODUCT(_clet->clear_strings()); } // Make sure nobody can use _masm outside a CodeletMark lifespan. *_masm = nullptr; diff --git a/src/hotspot/share/interpreter/interpreter.hpp b/src/hotspot/share/interpreter/interpreter.hpp index c230b50ee9a..10c5c940a4e 100644 --- a/src/hotspot/share/interpreter/interpreter.hpp +++ b/src/hotspot/share/interpreter/interpreter.hpp @@ -85,6 +85,9 @@ class InterpreterCodelet: public Stub { } void use_remarks(AsmRemarks &remarks) { _asm_remarks.share(remarks); } void use_strings(DbgStrings &strings) { _dbg_strings.share(strings); } + + void clear_remarks() { _asm_remarks.clear(); } + void clear_strings() { _dbg_strings.clear(); } #endif };