1.1 --- a/src/share/vm/asm/codeBuffer.cpp Wed Sep 03 15:26:06 2014 +0400 1.2 +++ b/src/share/vm/asm/codeBuffer.cpp Fri Aug 29 19:45:49 2014 -0400 1.3 @@ -133,6 +133,10 @@ 1.4 // free any overflow storage 1.5 delete _overflow_arena; 1.6 1.7 + // Claim is that stack allocation ensures resources are cleaned up. 1.8 + // This is resource clean up, let's hope that all were properly copied out. 1.9 + free_strings(); 1.10 + 1.11 #ifdef ASSERT 1.12 // Save allocation type to execute assert in ~ResourceObj() 1.13 // which is called after this destructor. 1.14 @@ -704,7 +708,7 @@ 1.15 relocate_code_to(&dest); 1.16 1.17 // transfer strings and comments from buffer to blob 1.18 - dest_blob->set_strings(_strings); 1.19 + dest_blob->set_strings(_code_strings); 1.20 1.21 // Done moving code bytes; were they the right size? 1.22 assert(round_to(dest.total_content_size(), oopSize) == dest_blob->content_size(), "sanity"); 1.23 @@ -1003,11 +1007,11 @@ 1.24 1.25 1.26 void CodeBuffer::block_comment(intptr_t offset, const char * comment) { 1.27 - _strings.add_comment(offset, comment); 1.28 + _code_strings.add_comment(offset, comment); 1.29 } 1.30 1.31 const char* CodeBuffer::code_string(const char* str) { 1.32 - return _strings.add_string(str); 1.33 + return _code_strings.add_string(str); 1.34 } 1.35 1.36 class CodeString: public CHeapObj<mtCode> { 1.37 @@ -1073,6 +1077,7 @@ 1.38 } 1.39 1.40 void CodeStrings::add_comment(intptr_t offset, const char * comment) { 1.41 + check_valid(); 1.42 CodeString* c = new CodeString(comment, offset); 1.43 CodeString* inspos = (_strings == NULL) ? NULL : find_last(offset); 1.44 1.45 @@ -1088,11 +1093,32 @@ 1.46 } 1.47 1.48 void CodeStrings::assign(CodeStrings& other) { 1.49 + other.check_valid(); 1.50 + // Cannot do following because CodeStrings constructor is not alway run! 1.51 + assert(is_null(), "Cannot assign onto non-empty CodeStrings"); 1.52 _strings = other._strings; 1.53 + other.set_null_and_invalidate(); 1.54 +} 1.55 + 1.56 +// Deep copy of CodeStrings for consistent memory management. 1.57 +// Only used for actual disassembly so this is cheaper than reference counting 1.58 +// for the "normal" fastdebug case. 1.59 +void CodeStrings::copy(CodeStrings& other) { 1.60 + other.check_valid(); 1.61 + check_valid(); 1.62 + assert(is_null(), "Cannot copy onto non-empty CodeStrings"); 1.63 + CodeString* n = other._strings; 1.64 + CodeString** ps = &_strings; 1.65 + while (n != NULL) { 1.66 + *ps = new CodeString(n->string(),n->offset()); 1.67 + ps = &((*ps)->_next); 1.68 + n = n->next(); 1.69 + } 1.70 } 1.71 1.72 void CodeStrings::print_block_comment(outputStream* stream, intptr_t offset) const { 1.73 - if (_strings != NULL) { 1.74 + check_valid(); 1.75 + if (_strings != NULL) { 1.76 CodeString* c = find(offset); 1.77 while (c && c->offset() == offset) { 1.78 stream->bol(); 1.79 @@ -1103,7 +1129,7 @@ 1.80 } 1.81 } 1.82 1.83 - 1.84 +// Also sets isNull() 1.85 void CodeStrings::free() { 1.86 CodeString* n = _strings; 1.87 while (n) { 1.88 @@ -1113,10 +1139,11 @@ 1.89 delete n; 1.90 n = p; 1.91 } 1.92 - _strings = NULL; 1.93 + set_null_and_invalidate(); 1.94 } 1.95 1.96 const char* CodeStrings::add_string(const char * string) { 1.97 + check_valid(); 1.98 CodeString* s = new CodeString(string); 1.99 s->set_next(_strings); 1.100 _strings = s;