< prev index next >

src/share/vm/asm/codeBuffer.cpp

Print this page




 585     const CodeSection* cur_cs = code_section(n);
 586     if (!cur_cs->is_empty()) {
 587       size_so_far = cur_cs->align_at_start(size_so_far);
 588     }
 589     if (cur_cs->index() == cs->index()) {
 590       return size_so_far;
 591     }
 592     size_so_far += cur_cs->size();
 593   }
 594   ShouldNotReachHere();
 595   return -1;
 596 }
 597 
 598 csize_t CodeBuffer::total_relocation_size() const {
 599   csize_t lsize = copy_relocations_to(NULL);  // dry run only
 600   csize_t csize = total_content_size();
 601   csize_t total = RelocIterator::locs_and_index_size(csize, lsize);
 602   return (csize_t) align_size_up(total, HeapWordSize);
 603 }
 604 
 605 csize_t CodeBuffer::copy_relocations_to(CodeBlob* dest) const {
 606   address buf = NULL;
 607   csize_t buf_offset = 0;
 608   csize_t buf_limit = 0;
 609   if (dest != NULL) {
 610     buf = (address)dest->relocation_begin();
 611     buf_limit = (address)dest->relocation_end() - buf;
 612     assert((uintptr_t)buf % HeapWordSize == 0, "buf must be fully aligned");
 613     assert(buf_limit % HeapWordSize == 0, "buf must be evenly sized");
 614   }
 615   // if dest == NULL, this is just the sizing pass
 616 
 617   csize_t code_end_so_far = 0;
 618   csize_t code_point_so_far = 0;
 619   for (int n = (int) SECT_FIRST; n < (int)SECT_LIMIT; n++) {




 620     // pull relocs out of each section
 621     const CodeSection* cs = code_section(n);
 622     assert(!(cs->is_empty() && cs->locs_count() > 0), "sanity");
 623     if (cs->is_empty())  continue;  // skip trivial section
 624     relocInfo* lstart = cs->locs_start();
 625     relocInfo* lend   = cs->locs_end();
 626     csize_t    lsize  = (csize_t)( (address)lend - (address)lstart );
 627     csize_t    csize  = cs->size();
 628     code_end_so_far = cs->align_at_start(code_end_so_far);
 629 
 630     if (lsize > 0) {
 631       // Figure out how to advance the combined relocation point
 632       // first to the beginning of this section.
 633       // We'll insert one or more filler relocs to span that gap.
 634       // (Don't bother to improve this by editing the first reloc's offset.)
 635       csize_t new_code_point = code_end_so_far;
 636       for (csize_t jump;
 637            code_point_so_far < new_code_point;
 638            code_point_so_far += jump) {
 639         jump = new_code_point - code_point_so_far;


 666         Copy::disjoint_words((HeapWord*)lstart,
 667                              (HeapWord*)(buf+buf_offset),
 668                              (lsize + HeapWordSize-1) / HeapWordSize);
 669       } else {
 670         Copy::conjoint_jbytes(lstart, buf+buf_offset, lsize);
 671       }
 672     }
 673     buf_offset += lsize;
 674   }
 675 
 676   // Align end of relocation info in target.
 677   while (buf_offset % HeapWordSize != 0) {
 678     if (buf != NULL) {
 679       relocInfo padding = relocInfo(relocInfo::none, 0);
 680       assert(buf_offset + (csize_t)sizeof(padding) <= buf_limit, "padding in bounds");
 681       *(relocInfo*)(buf+buf_offset) = padding;
 682     }
 683     buf_offset += sizeof(relocInfo);
 684   }
 685 
 686   assert(code_end_so_far == total_content_size(), "sanity");
















 687 
 688   // Account for index:
 689   if (buf != NULL) {
 690     RelocIterator::create_index(dest->relocation_begin(),
 691                                 buf_offset / sizeof(relocInfo),
 692                                 dest->relocation_end());
 693   }
 694 
 695   return buf_offset;
 696 }
 697 
 698 void CodeBuffer::copy_code_to(CodeBlob* dest_blob) {
 699 #ifndef PRODUCT
 700   if (PrintNMethods && (WizardMode || Verbose)) {
 701     tty->print("done with CodeBuffer:");
 702     ((CodeBuffer*)this)->print();
 703   }
 704 #endif //PRODUCT
 705 
 706   CodeBuffer dest(dest_blob);


1109   check_valid();
1110   assert(is_null(), "Cannot copy onto non-empty CodeStrings");
1111   CodeString* n = other._strings;
1112   CodeString** ps = &_strings;
1113   while (n != NULL) {
1114     *ps = new CodeString(n->string(),n->offset());
1115     ps = &((*ps)->_next);
1116     n = n->next();
1117   }
1118 }
1119 
1120 const char* CodeStrings::_prefix = " ;; ";  // default: can be changed via set_prefix
1121 
1122 void CodeStrings::print_block_comment(outputStream* stream, intptr_t offset) const {
1123     check_valid();
1124     if (_strings != NULL) {
1125     CodeString* c = find(offset);
1126     while (c && c->offset() == offset) {
1127       stream->bol();
1128       stream->print("%s", _prefix);
1129       stream->print_cr("%s", c->string());

1130       c = c->next_comment();
1131     }
1132   }
1133 }
1134 
1135 // Also sets isNull()
1136 void CodeStrings::free() {
1137   CodeString* n = _strings;
1138   while (n) {
1139     // unlink the node from the list saving a pointer to the next
1140     CodeString* p = n->next();
1141     n->set_next(NULL);
1142     delete n;
1143     n = p;
1144   }
1145   set_null_and_invalidate();
1146 }
1147 
1148 const char* CodeStrings::add_string(const char * string) {
1149   check_valid();




 585     const CodeSection* cur_cs = code_section(n);
 586     if (!cur_cs->is_empty()) {
 587       size_so_far = cur_cs->align_at_start(size_so_far);
 588     }
 589     if (cur_cs->index() == cs->index()) {
 590       return size_so_far;
 591     }
 592     size_so_far += cur_cs->size();
 593   }
 594   ShouldNotReachHere();
 595   return -1;
 596 }
 597 
 598 csize_t CodeBuffer::total_relocation_size() const {
 599   csize_t lsize = copy_relocations_to(NULL);  // dry run only
 600   csize_t csize = total_content_size();
 601   csize_t total = RelocIterator::locs_and_index_size(csize, lsize);
 602   return (csize_t) align_size_up(total, HeapWordSize);
 603 }
 604 
 605 csize_t CodeBuffer::copy_relocations_to(address buf, csize_t buf_limit, bool only_inst) const {

 606   csize_t buf_offset = 0;
 607   csize_t code_end_so_far = 0;
 608   csize_t code_point_so_far = 0;
 609 

 610   assert((uintptr_t)buf % HeapWordSize == 0, "buf must be fully aligned");
 611   assert(buf_limit % HeapWordSize == 0, "buf must be evenly sized");


 612 


 613   for (int n = (int) SECT_FIRST; n < (int)SECT_LIMIT; n++) {
 614     if (only_inst && (n != (int)SECT_INSTS)) {
 615       // Need only relocation info for code.
 616       continue;
 617     }
 618     // pull relocs out of each section
 619     const CodeSection* cs = code_section(n);
 620     assert(!(cs->is_empty() && cs->locs_count() > 0), "sanity");
 621     if (cs->is_empty())  continue;  // skip trivial section
 622     relocInfo* lstart = cs->locs_start();
 623     relocInfo* lend   = cs->locs_end();
 624     csize_t    lsize  = (csize_t)( (address)lend - (address)lstart );
 625     csize_t    csize  = cs->size();
 626     code_end_so_far = cs->align_at_start(code_end_so_far);
 627 
 628     if (lsize > 0) {
 629       // Figure out how to advance the combined relocation point
 630       // first to the beginning of this section.
 631       // We'll insert one or more filler relocs to span that gap.
 632       // (Don't bother to improve this by editing the first reloc's offset.)
 633       csize_t new_code_point = code_end_so_far;
 634       for (csize_t jump;
 635            code_point_so_far < new_code_point;
 636            code_point_so_far += jump) {
 637         jump = new_code_point - code_point_so_far;


 664         Copy::disjoint_words((HeapWord*)lstart,
 665                              (HeapWord*)(buf+buf_offset),
 666                              (lsize + HeapWordSize-1) / HeapWordSize);
 667       } else {
 668         Copy::conjoint_jbytes(lstart, buf+buf_offset, lsize);
 669       }
 670     }
 671     buf_offset += lsize;
 672   }
 673 
 674   // Align end of relocation info in target.
 675   while (buf_offset % HeapWordSize != 0) {
 676     if (buf != NULL) {
 677       relocInfo padding = relocInfo(relocInfo::none, 0);
 678       assert(buf_offset + (csize_t)sizeof(padding) <= buf_limit, "padding in bounds");
 679       *(relocInfo*)(buf+buf_offset) = padding;
 680     }
 681     buf_offset += sizeof(relocInfo);
 682   }
 683 
 684   assert(only_inst || code_end_so_far == total_content_size(), "sanity");
 685 
 686   return buf_offset;
 687 }
 688 
 689 csize_t CodeBuffer::copy_relocations_to(CodeBlob* dest) const {
 690   address buf = NULL;
 691   csize_t buf_offset = 0;
 692   csize_t buf_limit = 0;
 693 
 694   if (dest != NULL) {
 695     buf = (address)dest->relocation_begin();
 696     buf_limit = (address)dest->relocation_end() - buf;
 697   }
 698   // if dest == NULL, this is just the sizing pass
 699   //
 700   buf_offset = copy_relocations_to(buf, buf_limit, false);
 701 
 702   // Account for index:
 703   if (buf != NULL) {
 704     RelocIterator::create_index(dest->relocation_begin(),
 705                                 buf_offset / sizeof(relocInfo),
 706                                 dest->relocation_end());
 707   }
 708 
 709   return buf_offset;
 710 }
 711 
 712 void CodeBuffer::copy_code_to(CodeBlob* dest_blob) {
 713 #ifndef PRODUCT
 714   if (PrintNMethods && (WizardMode || Verbose)) {
 715     tty->print("done with CodeBuffer:");
 716     ((CodeBuffer*)this)->print();
 717   }
 718 #endif //PRODUCT
 719 
 720   CodeBuffer dest(dest_blob);


1123   check_valid();
1124   assert(is_null(), "Cannot copy onto non-empty CodeStrings");
1125   CodeString* n = other._strings;
1126   CodeString** ps = &_strings;
1127   while (n != NULL) {
1128     *ps = new CodeString(n->string(),n->offset());
1129     ps = &((*ps)->_next);
1130     n = n->next();
1131   }
1132 }
1133 
1134 const char* CodeStrings::_prefix = " ;; ";  // default: can be changed via set_prefix
1135 
1136 void CodeStrings::print_block_comment(outputStream* stream, intptr_t offset) const {
1137     check_valid();
1138     if (_strings != NULL) {
1139     CodeString* c = find(offset);
1140     while (c && c->offset() == offset) {
1141       stream->bol();
1142       stream->print("%s", _prefix);
1143       // Don't interpret as format strings since it could contain %
1144       stream->print_raw_cr(c->string());
1145       c = c->next_comment();
1146     }
1147   }
1148 }
1149 
1150 // Also sets isNull()
1151 void CodeStrings::free() {
1152   CodeString* n = _strings;
1153   while (n) {
1154     // unlink the node from the list saving a pointer to the next
1155     CodeString* p = n->next();
1156     n->set_next(NULL);
1157     delete n;
1158     n = p;
1159   }
1160   set_null_and_invalidate();
1161 }
1162 
1163 const char* CodeStrings::add_string(const char * string) {
1164   check_valid();


< prev index next >