src/share/vm/asm/codeBuffer.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/asm

src/share/vm/asm/codeBuffer.cpp

Print this page




 117 }
 118 
 119 
 120 CodeBuffer::~CodeBuffer() {
 121   verify_section_allocation();
 122 
 123   // If we allocate our code buffer from the CodeCache
 124   // via a BufferBlob, and it's not permanent, then
 125   // free the BufferBlob.
 126   // The rest of the memory will be freed when the ResourceObj
 127   // is released.
 128   for (CodeBuffer* cb = this; cb != NULL; cb = cb->before_expand()) {
 129     // Previous incarnations of this buffer are held live, so that internal
 130     // addresses constructed before expansions will not be confused.
 131     cb->free_blob();
 132   }
 133 
 134   // free any overflow storage
 135   delete _overflow_arena;
 136 




 137 #ifdef ASSERT
 138   // Save allocation type to execute assert in ~ResourceObj()
 139   // which is called after this destructor.
 140   assert(_default_oop_recorder.allocated_on_stack(), "should be embedded object");
 141   ResourceObj::allocation_type at = _default_oop_recorder.get_allocation_type();
 142   Copy::fill_to_bytes(this, sizeof(*this), badResourceValue);
 143   ResourceObj::set_allocation_type((address)(&_default_oop_recorder), at);
 144 #endif
 145 }
 146 
 147 void CodeBuffer::initialize_oop_recorder(OopRecorder* r) {
 148   assert(_oop_recorder == &_default_oop_recorder && _default_oop_recorder.is_unused(), "do this once");
 149   DEBUG_ONLY(_default_oop_recorder.freeze());  // force unused OR to be frozen
 150   _oop_recorder = r;
 151 }
 152 
 153 void CodeBuffer::initialize_section_size(CodeSection* cs, csize_t size) {
 154   assert(cs != &_insts, "insts is the memory provider, not the consumer");
 155   csize_t slop = CodeSection::end_slop();  // margin between sections
 156   int align = cs->alignment();


1058   CodeString* a = _strings->first_comment();
1059   while (a != NULL && a->offset() != offset) {
1060     a = a->next_comment();
1061   }
1062   return a;
1063 }
1064 
1065 // Convenience for add_comment.
1066 CodeString* CodeStrings::find_last(intptr_t offset) const {
1067   CodeString* a = find(offset);
1068   if (a != NULL) {
1069     CodeString* c = NULL;
1070     while (((c = a->next_comment()) != NULL) && (c->offset() == offset)) {
1071       a = c;
1072     }
1073   }
1074   return a;
1075 }
1076 
1077 void CodeStrings::add_comment(intptr_t offset, const char * comment) {

1078   CodeString* c      = new CodeString(comment, offset);
1079   CodeString* inspos = (_strings == NULL) ? NULL : find_last(offset);
1080 
1081   if (inspos) {
1082     // insert after already existing comments with same offset
1083     c->set_next(inspos->next());
1084     inspos->set_next(c);
1085   } else {
1086     // no comments with such offset, yet. Insert before anything else.
1087     c->set_next(_strings);
1088     _strings = c;
1089   }
1090 }
1091 
1092 void CodeStrings::assign(CodeStrings& other) {



1093   _strings = other._strings;

















1094 }
1095 
1096 void CodeStrings::print_block_comment(outputStream* stream, intptr_t offset) const {

1097   if (_strings != NULL) {
1098     CodeString* c = find(offset);
1099     while (c && c->offset() == offset) {
1100       stream->bol();
1101       stream->print("  ;; ");
1102       stream->print_cr("%s", c->string());
1103       c = c->next_comment();
1104     }
1105   }
1106 }
1107 
1108 
1109 void CodeStrings::free() {
1110   CodeString* n = _strings;
1111   while (n) {
1112     // unlink the node from the list saving a pointer to the next
1113     CodeString* p = n->next();
1114     n->set_next(NULL);
1115     delete n;
1116     n = p;
1117   }
1118   _strings = NULL;
1119 }
1120 
1121 const char* CodeStrings::add_string(const char * string) {

1122   CodeString* s = new CodeString(string);
1123   s->set_next(_strings);
1124   _strings = s;
1125   assert(s->string() != NULL, "should have a string");
1126   return s->string();
1127 }
1128 
1129 void CodeBuffer::decode() {
1130   ttyLocker ttyl;
1131   Disassembler::decode(decode_begin(), insts_end());
1132   _decode_begin = insts_end();
1133 }
1134 
1135 
1136 void CodeBuffer::skip_decode() {
1137   _decode_begin = insts_end();
1138 }
1139 
1140 
1141 void CodeBuffer::decode_all() {




 117 }
 118 
 119 
 120 CodeBuffer::~CodeBuffer() {
 121   verify_section_allocation();
 122 
 123   // If we allocate our code buffer from the CodeCache
 124   // via a BufferBlob, and it's not permanent, then
 125   // free the BufferBlob.
 126   // The rest of the memory will be freed when the ResourceObj
 127   // is released.
 128   for (CodeBuffer* cb = this; cb != NULL; cb = cb->before_expand()) {
 129     // Previous incarnations of this buffer are held live, so that internal
 130     // addresses constructed before expansions will not be confused.
 131     cb->free_blob();
 132   }
 133 
 134   // free any overflow storage
 135   delete _overflow_arena;
 136 
 137   // Claim is that stack allocation ensures resources are cleaned up.
 138   // This is resource clean up, let's hope that all were properly copied out.
 139   free_strings();
 140 
 141 #ifdef ASSERT
 142   // Save allocation type to execute assert in ~ResourceObj()
 143   // which is called after this destructor.
 144   assert(_default_oop_recorder.allocated_on_stack(), "should be embedded object");
 145   ResourceObj::allocation_type at = _default_oop_recorder.get_allocation_type();
 146   Copy::fill_to_bytes(this, sizeof(*this), badResourceValue);
 147   ResourceObj::set_allocation_type((address)(&_default_oop_recorder), at);
 148 #endif
 149 }
 150 
 151 void CodeBuffer::initialize_oop_recorder(OopRecorder* r) {
 152   assert(_oop_recorder == &_default_oop_recorder && _default_oop_recorder.is_unused(), "do this once");
 153   DEBUG_ONLY(_default_oop_recorder.freeze());  // force unused OR to be frozen
 154   _oop_recorder = r;
 155 }
 156 
 157 void CodeBuffer::initialize_section_size(CodeSection* cs, csize_t size) {
 158   assert(cs != &_insts, "insts is the memory provider, not the consumer");
 159   csize_t slop = CodeSection::end_slop();  // margin between sections
 160   int align = cs->alignment();


1062   CodeString* a = _strings->first_comment();
1063   while (a != NULL && a->offset() != offset) {
1064     a = a->next_comment();
1065   }
1066   return a;
1067 }
1068 
1069 // Convenience for add_comment.
1070 CodeString* CodeStrings::find_last(intptr_t offset) const {
1071   CodeString* a = find(offset);
1072   if (a != NULL) {
1073     CodeString* c = NULL;
1074     while (((c = a->next_comment()) != NULL) && (c->offset() == offset)) {
1075       a = c;
1076     }
1077   }
1078   return a;
1079 }
1080 
1081 void CodeStrings::add_comment(intptr_t offset, const char * comment) {
1082   check_valid();
1083   CodeString* c      = new CodeString(comment, offset);
1084   CodeString* inspos = (_strings == NULL) ? NULL : find_last(offset);
1085 
1086   if (inspos) {
1087     // insert after already existing comments with same offset
1088     c->set_next(inspos->next());
1089     inspos->set_next(c);
1090   } else {
1091     // no comments with such offset, yet. Insert before anything else.
1092     c->set_next(_strings);
1093     _strings = c;
1094   }
1095 }
1096 
1097 void CodeStrings::assign(CodeStrings& other) {
1098   other.check_valid();
1099   // Cannot do following because CodeStrings constructor is not alway run!
1100   // assert(isNull(), "Cannot assign onto non-empty CodeStrings");
1101   _strings = other._strings;
1102   other.set_null_and_invalidate();
1103 }
1104 
1105 // Deep copy of CodeStrings for consistent memory management.
1106 // Only used for actual disassembly so this is cheaper than reference counting
1107 // for the "normal" fastdebug case.
1108 void CodeStrings::copy(CodeStrings& other) {
1109   other.check_valid();
1110   check_valid();
1111   assert(isNull(), "Cannot copy onto non-empty CodeStrings");
1112   CodeString* n = other._strings;
1113   CodeString** ps = &_strings;
1114   while (n != NULL) {
1115       *ps = new CodeString(n->string(),n->offset());
1116       ps = &((*ps)->_next);
1117       n = n->next();
1118   }
1119 }
1120 
1121 void CodeStrings::print_block_comment(outputStream* stream, intptr_t offset) const {
1122     check_valid();
1123     if (_strings != NULL) {
1124     CodeString* c = find(offset);
1125     while (c && c->offset() == offset) {
1126       stream->bol();
1127       stream->print("  ;; ");
1128       stream->print_cr("%s", c->string());
1129       c = c->next_comment();
1130     }
1131   }
1132 }
1133 
1134 // Also sets isNull()
1135 void CodeStrings::free() {
1136   CodeString* n = _strings;
1137   while (n) {
1138     // unlink the node from the list saving a pointer to the next
1139     CodeString* p = n->next();
1140     n->set_next(NULL);
1141     delete n;
1142     n = p;
1143   }
1144   set_null_and_invalidate();
1145 }
1146 
1147 const char* CodeStrings::add_string(const char * string) {
1148   check_valid();
1149   CodeString* s = new CodeString(string);
1150   s->set_next(_strings);
1151   _strings = s;
1152   assert(s->string() != NULL, "should have a string");
1153   return s->string();
1154 }
1155 
1156 void CodeBuffer::decode() {
1157   ttyLocker ttyl;
1158   Disassembler::decode(decode_begin(), insts_end());
1159   _decode_begin = insts_end();
1160 }
1161 
1162 
1163 void CodeBuffer::skip_decode() {
1164   _decode_begin = insts_end();
1165 }
1166 
1167 
1168 void CodeBuffer::decode_all() {


src/share/vm/asm/codeBuffer.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File