Mercurial > hg > truffle
comparison src/share/vm/asm/codeBuffer.cpp @ 20804:7848fc12602b
Merge with jdk8u40-b25
author | Gilles Duboscq <gilles.m.duboscq@oracle.com> |
---|---|
date | Tue, 07 Apr 2015 14:58:49 +0200 |
parents | 52b4284cb496 094cbdffa87d |
children |
comparison
equal
deleted
inserted
replaced
20184:84105dcdb05b | 20804:7848fc12602b |
---|---|
131 } | 131 } |
132 | 132 |
133 // free any overflow storage | 133 // free any overflow storage |
134 delete _overflow_arena; | 134 delete _overflow_arena; |
135 | 135 |
136 // Claim is that stack allocation ensures resources are cleaned up. | |
137 // This is resource clean up, let's hope that all were properly copied out. | |
138 free_strings(); | |
139 | |
136 #ifdef ASSERT | 140 #ifdef ASSERT |
137 // Save allocation type to execute assert in ~ResourceObj() | 141 // Save allocation type to execute assert in ~ResourceObj() |
138 // which is called after this destructor. | 142 // which is called after this destructor. |
139 assert(_default_oop_recorder.allocated_on_stack(), "should be embedded object"); | 143 assert(_default_oop_recorder.allocated_on_stack(), "should be embedded object"); |
140 ResourceObj::allocation_type at = _default_oop_recorder.get_allocation_type(); | 144 ResourceObj::allocation_type at = _default_oop_recorder.get_allocation_type(); |
266 } | 270 } |
267 | 271 |
268 | 272 |
269 GrowableArray<int>* CodeBuffer::create_patch_overflow() { | 273 GrowableArray<int>* CodeBuffer::create_patch_overflow() { |
270 if (_overflow_arena == NULL) { | 274 if (_overflow_arena == NULL) { |
271 _overflow_arena = new (mtCode) Arena(); | 275 _overflow_arena = new (mtCode) Arena(mtCode); |
272 } | 276 } |
273 return new (_overflow_arena) GrowableArray<int>(_overflow_arena, 8, 0, 0); | 277 return new (_overflow_arena) GrowableArray<int>(_overflow_arena, 8, 0, 0); |
274 } | 278 } |
275 | 279 |
276 | 280 |
702 assert(dest_blob->content_size() >= total_content_size(), "good sizing"); | 706 assert(dest_blob->content_size() >= total_content_size(), "good sizing"); |
703 this->compute_final_layout(&dest); | 707 this->compute_final_layout(&dest); |
704 relocate_code_to(&dest); | 708 relocate_code_to(&dest); |
705 | 709 |
706 // transfer strings and comments from buffer to blob | 710 // transfer strings and comments from buffer to blob |
707 dest_blob->set_strings(_strings); | 711 dest_blob->set_strings(_code_strings); |
708 | 712 |
709 // Done moving code bytes; were they the right size? | 713 // Done moving code bytes; were they the right size? |
710 assert(round_to(dest.total_content_size(), oopSize) == dest_blob->content_size(), "sanity"); | 714 assert(round_to(dest.total_content_size(), oopSize) == dest_blob->content_size(), "sanity"); |
711 | 715 |
712 // Flush generated code | 716 // Flush generated code |
1001 Disassembler::decode(start(), end()); | 1005 Disassembler::decode(start(), end()); |
1002 } | 1006 } |
1003 | 1007 |
1004 | 1008 |
1005 void CodeBuffer::block_comment(intptr_t offset, const char * comment) { | 1009 void CodeBuffer::block_comment(intptr_t offset, const char * comment) { |
1006 _strings.add_comment(offset, comment); | 1010 _code_strings.add_comment(offset, comment); |
1007 } | 1011 } |
1008 | 1012 |
1009 const char* CodeBuffer::code_string(const char* str) { | 1013 const char* CodeBuffer::code_string(const char* str) { |
1010 return _strings.add_string(str); | 1014 return _code_strings.add_string(str); |
1011 } | 1015 } |
1012 | 1016 |
1013 class CodeString: public CHeapObj<mtCode> { | 1017 class CodeString: public CHeapObj<mtCode> { |
1014 private: | 1018 private: |
1015 friend class CodeStrings; | 1019 friend class CodeStrings; |
1071 } | 1075 } |
1072 return a; | 1076 return a; |
1073 } | 1077 } |
1074 | 1078 |
1075 void CodeStrings::add_comment(intptr_t offset, const char * comment) { | 1079 void CodeStrings::add_comment(intptr_t offset, const char * comment) { |
1080 check_valid(); | |
1076 CodeString* c = new CodeString(comment, offset); | 1081 CodeString* c = new CodeString(comment, offset); |
1077 CodeString* inspos = (_strings == NULL) ? NULL : find_last(offset); | 1082 CodeString* inspos = (_strings == NULL) ? NULL : find_last(offset); |
1078 | 1083 |
1079 if (inspos) { | 1084 if (inspos) { |
1080 // insert after already existing comments with same offset | 1085 // insert after already existing comments with same offset |
1086 _strings = c; | 1091 _strings = c; |
1087 } | 1092 } |
1088 } | 1093 } |
1089 | 1094 |
1090 void CodeStrings::assign(CodeStrings& other) { | 1095 void CodeStrings::assign(CodeStrings& other) { |
1096 other.check_valid(); | |
1097 // Cannot do following because CodeStrings constructor is not alway run! | |
1098 assert(is_null(), "Cannot assign onto non-empty CodeStrings"); | |
1091 _strings = other._strings; | 1099 _strings = other._strings; |
1100 other.set_null_and_invalidate(); | |
1101 } | |
1102 | |
1103 // Deep copy of CodeStrings for consistent memory management. | |
1104 // Only used for actual disassembly so this is cheaper than reference counting | |
1105 // for the "normal" fastdebug case. | |
1106 void CodeStrings::copy(CodeStrings& other) { | |
1107 other.check_valid(); | |
1108 check_valid(); | |
1109 assert(is_null(), "Cannot copy onto non-empty CodeStrings"); | |
1110 CodeString* n = other._strings; | |
1111 CodeString** ps = &_strings; | |
1112 while (n != NULL) { | |
1113 *ps = new CodeString(n->string(),n->offset()); | |
1114 ps = &((*ps)->_next); | |
1115 n = n->next(); | |
1116 } | |
1092 } | 1117 } |
1093 | 1118 |
1094 void CodeStrings::print_block_comment(outputStream* stream, intptr_t offset) const { | 1119 void CodeStrings::print_block_comment(outputStream* stream, intptr_t offset) const { |
1095 if (_strings != NULL) { | 1120 check_valid(); |
1121 if (_strings != NULL) { | |
1096 CodeString* c = find(offset); | 1122 CodeString* c = find(offset); |
1097 while (c && c->offset() == offset) { | 1123 while (c && c->offset() == offset) { |
1098 stream->bol(); | 1124 stream->bol(); |
1099 stream->print_raw(" ;; "); | 1125 stream->print_raw(" ;; "); |
1100 // Don't interpret as format strings since it could contain % | 1126 // Don't interpret as format strings since it could contain % |
1102 c = c->next_comment(); | 1128 c = c->next_comment(); |
1103 } | 1129 } |
1104 } | 1130 } |
1105 } | 1131 } |
1106 | 1132 |
1107 | 1133 // Also sets isNull() |
1108 void CodeStrings::free() { | 1134 void CodeStrings::free() { |
1109 CodeString* n = _strings; | 1135 CodeString* n = _strings; |
1110 while (n) { | 1136 while (n) { |
1111 // unlink the node from the list saving a pointer to the next | 1137 // unlink the node from the list saving a pointer to the next |
1112 CodeString* p = n->next(); | 1138 CodeString* p = n->next(); |
1113 n->set_next(NULL); | 1139 n->set_next(NULL); |
1114 delete n; | 1140 delete n; |
1115 n = p; | 1141 n = p; |
1116 } | 1142 } |
1117 _strings = NULL; | 1143 set_null_and_invalidate(); |
1118 } | 1144 } |
1119 | 1145 |
1120 const char* CodeStrings::add_string(const char * string) { | 1146 const char* CodeStrings::add_string(const char * string) { |
1147 check_valid(); | |
1121 CodeString* s = new CodeString(string); | 1148 CodeString* s = new CodeString(string); |
1122 s->set_next(_strings); | 1149 s->set_next(_strings); |
1123 _strings = s; | 1150 _strings = s; |
1124 assert(s->string() != NULL, "should have a string"); | 1151 assert(s->string() != NULL, "should have a string"); |
1125 return s->string(); | 1152 return s->string(); |