< prev index next >

src/share/vm/asm/codeBuffer.cpp

Print this page




 607 
 608 
 609 csize_t CodeBuffer::total_offset_of(const CodeSection* cs) const {
 610   csize_t size_so_far = 0;
 611   for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) {
 612     const CodeSection* cur_cs = code_section(n);
 613     if (!cur_cs->is_empty()) {
 614       size_so_far = cur_cs->align_at_start(size_so_far);
 615     }
 616     if (cur_cs->index() == cs->index()) {
 617       return size_so_far;
 618     }
 619     size_so_far += cur_cs->size();
 620   }
 621   ShouldNotReachHere();
 622   return -1;
 623 }
 624 
 625 csize_t CodeBuffer::total_relocation_size() const {
 626   csize_t total = copy_relocations_to(NULL);  // dry run only
 627   return (csize_t) align_size_up(total, HeapWordSize);
 628 }
 629 
 630 csize_t CodeBuffer::copy_relocations_to(address buf, csize_t buf_limit, bool only_inst) const {
 631   csize_t buf_offset = 0;
 632   csize_t code_end_so_far = 0;
 633   csize_t code_point_so_far = 0;
 634 
 635   assert((uintptr_t)buf % HeapWordSize == 0, "buf must be fully aligned");
 636   assert(buf_limit % HeapWordSize == 0, "buf must be evenly sized");
 637 
 638   for (int n = (int) SECT_FIRST; n < (int)SECT_LIMIT; n++) {
 639     if (only_inst && (n != (int)SECT_INSTS)) {
 640       // Need only relocation info for code.
 641       continue;
 642     }
 643     // pull relocs out of each section
 644     const CodeSection* cs = code_section(n);
 645     assert(!(cs->is_empty() && cs->locs_count() > 0), "sanity");
 646     if (cs->is_empty())  continue;  // skip trivial section
 647     relocInfo* lstart = cs->locs_start();


 752 
 753   // Flush generated code
 754   ICache::invalidate_range(dest_blob->code_begin(), dest_blob->code_size());
 755 }
 756 
 757 // Move all my code into another code buffer.  Consult applicable
 758 // relocs to repair embedded addresses.  The layout in the destination
 759 // CodeBuffer is different to the source CodeBuffer: the destination
 760 // CodeBuffer gets the final layout (consts, insts, stubs in order of
 761 // ascending address).
 762 void CodeBuffer::relocate_code_to(CodeBuffer* dest) const {
 763   address dest_end = dest->_total_start + dest->_total_size;
 764   address dest_filled = NULL;
 765   for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) {
 766     // pull code out of each section
 767     const CodeSection* cs = code_section(n);
 768     if (cs->is_empty())  continue;  // skip trivial section
 769     CodeSection* dest_cs = dest->code_section(n);
 770     assert(cs->size() == dest_cs->size(), "sanity");
 771     csize_t usize = dest_cs->size();
 772     csize_t wsize = align_size_up(usize, HeapWordSize);
 773     assert(dest_cs->start() + wsize <= dest_end, "no overflow");
 774     // Copy the code as aligned machine words.
 775     // This may also include an uninitialized partial word at the end.
 776     Copy::disjoint_words((HeapWord*)cs->start(),
 777                          (HeapWord*)dest_cs->start(),
 778                          wsize / HeapWordSize);
 779 
 780     if (dest->blob() == NULL) {
 781       // Destination is a final resting place, not just another buffer.
 782       // Normalize uninitialized bytes in the final padding.
 783       Copy::fill_to_bytes(dest_cs->end(), dest_cs->remaining(),
 784                           Assembler::code_fill_byte());
 785     }
 786     // Keep track of the highest filled address
 787     dest_filled = MAX2(dest_filled, dest_cs->end() + dest_cs->remaining());
 788 
 789     assert(cs->locs_start() != (relocInfo*)badAddress,
 790            "this section carries no reloc storage, but reloc was attempted");
 791 
 792     // Make the new code copy use the old copy's relocations:




 607 
 608 
 609 csize_t CodeBuffer::total_offset_of(const CodeSection* cs) const {
 610   csize_t size_so_far = 0;
 611   for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) {
 612     const CodeSection* cur_cs = code_section(n);
 613     if (!cur_cs->is_empty()) {
 614       size_so_far = cur_cs->align_at_start(size_so_far);
 615     }
 616     if (cur_cs->index() == cs->index()) {
 617       return size_so_far;
 618     }
 619     size_so_far += cur_cs->size();
 620   }
 621   ShouldNotReachHere();
 622   return -1;
 623 }
 624 
 625 csize_t CodeBuffer::total_relocation_size() const {
 626   csize_t total = copy_relocations_to(NULL);  // dry run only
 627   return (csize_t) align_up(total, HeapWordSize);
 628 }
 629 
 630 csize_t CodeBuffer::copy_relocations_to(address buf, csize_t buf_limit, bool only_inst) const {
 631   csize_t buf_offset = 0;
 632   csize_t code_end_so_far = 0;
 633   csize_t code_point_so_far = 0;
 634 
 635   assert((uintptr_t)buf % HeapWordSize == 0, "buf must be fully aligned");
 636   assert(buf_limit % HeapWordSize == 0, "buf must be evenly sized");
 637 
 638   for (int n = (int) SECT_FIRST; n < (int)SECT_LIMIT; n++) {
 639     if (only_inst && (n != (int)SECT_INSTS)) {
 640       // Need only relocation info for code.
 641       continue;
 642     }
 643     // pull relocs out of each section
 644     const CodeSection* cs = code_section(n);
 645     assert(!(cs->is_empty() && cs->locs_count() > 0), "sanity");
 646     if (cs->is_empty())  continue;  // skip trivial section
 647     relocInfo* lstart = cs->locs_start();


 752 
 753   // Flush generated code
 754   ICache::invalidate_range(dest_blob->code_begin(), dest_blob->code_size());
 755 }
 756 
 757 // Move all my code into another code buffer.  Consult applicable
 758 // relocs to repair embedded addresses.  The layout in the destination
 759 // CodeBuffer is different to the source CodeBuffer: the destination
 760 // CodeBuffer gets the final layout (consts, insts, stubs in order of
 761 // ascending address).
 762 void CodeBuffer::relocate_code_to(CodeBuffer* dest) const {
 763   address dest_end = dest->_total_start + dest->_total_size;
 764   address dest_filled = NULL;
 765   for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) {
 766     // pull code out of each section
 767     const CodeSection* cs = code_section(n);
 768     if (cs->is_empty())  continue;  // skip trivial section
 769     CodeSection* dest_cs = dest->code_section(n);
 770     assert(cs->size() == dest_cs->size(), "sanity");
 771     csize_t usize = dest_cs->size();
 772     csize_t wsize = align_up(usize, HeapWordSize);
 773     assert(dest_cs->start() + wsize <= dest_end, "no overflow");
 774     // Copy the code as aligned machine words.
 775     // This may also include an uninitialized partial word at the end.
 776     Copy::disjoint_words((HeapWord*)cs->start(),
 777                          (HeapWord*)dest_cs->start(),
 778                          wsize / HeapWordSize);
 779 
 780     if (dest->blob() == NULL) {
 781       // Destination is a final resting place, not just another buffer.
 782       // Normalize uninitialized bytes in the final padding.
 783       Copy::fill_to_bytes(dest_cs->end(), dest_cs->remaining(),
 784                           Assembler::code_fill_byte());
 785     }
 786     // Keep track of the highest filled address
 787     dest_filled = MAX2(dest_filled, dest_cs->end() + dest_cs->remaining());
 788 
 789     assert(cs->locs_start() != (relocInfo*)badAddress,
 790            "this section carries no reloc storage, but reloc was attempted");
 791 
 792     // Make the new code copy use the old copy's relocations:


< prev index next >