src/share/vm/asm/codeBuffer.cpp
Index
Unified diffs
Context diffs
Sdiffs
Patch
New
Old
Previous File
Next File
hotspot Cdiff src/share/vm/asm/codeBuffer.cpp
src/share/vm/asm/codeBuffer.cpp
Print this page
rev 6626 : 8054292: code comments leak in fastdebug builds
Summary: Added deallocation to destructor; hardened interface against misuse
Reviewed-by: kvn
*** 131,140 ****
--- 131,144 ----
}
// free any overflow storage
delete _overflow_arena;
+ // Claim is that stack allocation ensures resources are cleaned up.
+ // This is resource clean up, let's hope that all were properly copied out.
+ free_strings();
+
#ifdef ASSERT
// Save allocation type to execute assert in ~ResourceObj()
// which is called after this destructor.
assert(_default_oop_recorder.allocated_on_stack(), "should be embedded object");
ResourceObj::allocation_type at = _default_oop_recorder.get_allocation_type();
*** 702,712 ****
assert(dest_blob->content_size() >= total_content_size(), "good sizing");
this->compute_final_layout(&dest);
relocate_code_to(&dest);
// transfer strings and comments from buffer to blob
! dest_blob->set_strings(_strings);
// Done moving code bytes; were they the right size?
assert(round_to(dest.total_content_size(), oopSize) == dest_blob->content_size(), "sanity");
// Flush generated code
--- 706,716 ----
assert(dest_blob->content_size() >= total_content_size(), "good sizing");
this->compute_final_layout(&dest);
relocate_code_to(&dest);
// transfer strings and comments from buffer to blob
! dest_blob->set_strings(_code_strings);
// Done moving code bytes; were they the right size?
assert(round_to(dest.total_content_size(), oopSize) == dest_blob->content_size(), "sanity");
// Flush generated code
*** 1001,1015 ****
Disassembler::decode(start(), end());
}
void CodeBuffer::block_comment(intptr_t offset, const char * comment) {
! _strings.add_comment(offset, comment);
}
const char* CodeBuffer::code_string(const char* str) {
! return _strings.add_string(str);
}
class CodeString: public CHeapObj<mtCode> {
private:
friend class CodeStrings;
--- 1005,1019 ----
Disassembler::decode(start(), end());
}
void CodeBuffer::block_comment(intptr_t offset, const char * comment) {
! _code_strings.add_comment(offset, comment);
}
const char* CodeBuffer::code_string(const char* str) {
! return _code_strings.add_string(str);
}
class CodeString: public CHeapObj<mtCode> {
private:
friend class CodeStrings;
*** 1071,1080 ****
--- 1075,1085 ----
}
return a;
}
void CodeStrings::add_comment(intptr_t offset, const char * comment) {
+ check_valid();
CodeString* c = new CodeString(comment, offset);
CodeString* inspos = (_strings == NULL) ? NULL : find_last(offset);
if (inspos) {
// insert after already existing comments with same offset
*** 1086,1099 ****
--- 1091,1125 ----
_strings = c;
}
}
void CodeStrings::assign(CodeStrings& other) {
+ other.check_valid();
+ // Cannot do following because CodeStrings constructor is not alway run!
+ assert(is_null(), "Cannot assign onto non-empty CodeStrings");
_strings = other._strings;
+ other.set_null_and_invalidate();
+ }
+
+ // Deep copy of CodeStrings for consistent memory management.
+ // Only used for actual disassembly so this is cheaper than reference counting
+ // for the "normal" fastdebug case.
+ void CodeStrings::copy(CodeStrings& other) {
+ other.check_valid();
+ check_valid();
+ assert(is_null(), "Cannot copy onto non-empty CodeStrings");
+ CodeString* n = other._strings;
+ CodeString** ps = &_strings;
+ while (n != NULL) {
+ *ps = new CodeString(n->string(),n->offset());
+ ps = &((*ps)->_next);
+ n = n->next();
+ }
}
void CodeStrings::print_block_comment(outputStream* stream, intptr_t offset) const {
+ check_valid();
if (_strings != NULL) {
CodeString* c = find(offset);
while (c && c->offset() == offset) {
stream->bol();
stream->print(" ;; ");
*** 1101,1124 ****
c = c->next_comment();
}
}
}
!
void CodeStrings::free() {
CodeString* n = _strings;
while (n) {
// unlink the node from the list saving a pointer to the next
CodeString* p = n->next();
n->set_next(NULL);
delete n;
n = p;
}
! _strings = NULL;
}
const char* CodeStrings::add_string(const char * string) {
CodeString* s = new CodeString(string);
s->set_next(_strings);
_strings = s;
assert(s->string() != NULL, "should have a string");
return s->string();
--- 1127,1151 ----
c = c->next_comment();
}
}
}
! // Also sets isNull()
void CodeStrings::free() {
CodeString* n = _strings;
while (n) {
// unlink the node from the list saving a pointer to the next
CodeString* p = n->next();
n->set_next(NULL);
delete n;
n = p;
}
! set_null_and_invalidate();
}
const char* CodeStrings::add_string(const char * string) {
+ check_valid();
CodeString* s = new CodeString(string);
s->set_next(_strings);
_strings = s;
assert(s->string() != NULL, "should have a string");
return s->string();
src/share/vm/asm/codeBuffer.cpp
Index
Unified diffs
Context diffs
Sdiffs
Patch
New
Old
Previous File
Next File