606
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 lsize = copy_relocations_to(NULL); // dry run only
627 csize_t csize = total_content_size();
628 csize_t total = RelocIterator::locs_and_index_size(csize, lsize);
629 return (csize_t) align_size_up(total, HeapWordSize);
630 }
631
632 csize_t CodeBuffer::copy_relocations_to(address buf, csize_t buf_limit, bool only_inst) const {
633 csize_t buf_offset = 0;
634 csize_t code_end_so_far = 0;
635 csize_t code_point_so_far = 0;
636
637 assert((uintptr_t)buf % HeapWordSize == 0, "buf must be fully aligned");
638 assert(buf_limit % HeapWordSize == 0, "buf must be evenly sized");
639
640 for (int n = (int) SECT_FIRST; n < (int)SECT_LIMIT; n++) {
641 if (only_inst && (n != (int)SECT_INSTS)) {
642 // Need only relocation info for code.
643 continue;
644 }
645 // pull relocs out of each section
646 const CodeSection* cs = code_section(n);
647 assert(!(cs->is_empty() && cs->locs_count() > 0), "sanity");
648 if (cs->is_empty()) continue; // skip trivial section
708 buf_offset += sizeof(relocInfo);
709 }
710
711 assert(only_inst || code_end_so_far == total_content_size(), "sanity");
712
713 return buf_offset;
714 }
715
716 csize_t CodeBuffer::copy_relocations_to(CodeBlob* dest) const {
717 address buf = NULL;
718 csize_t buf_offset = 0;
719 csize_t buf_limit = 0;
720
721 if (dest != NULL) {
722 buf = (address)dest->relocation_begin();
723 buf_limit = (address)dest->relocation_end() - buf;
724 }
725 // if dest == NULL, this is just the sizing pass
726 //
727 buf_offset = copy_relocations_to(buf, buf_limit, false);
728
729 // Account for index:
730 if (buf != NULL) {
731 RelocIterator::create_index(dest->relocation_begin(),
732 buf_offset / sizeof(relocInfo),
733 dest->relocation_end());
734 }
735
736 return buf_offset;
737 }
738
739 void CodeBuffer::copy_code_to(CodeBlob* dest_blob) {
740 #ifndef PRODUCT
741 if (PrintNMethods && (WizardMode || Verbose)) {
742 tty->print("done with CodeBuffer:");
743 ((CodeBuffer*)this)->print();
744 }
745 #endif //PRODUCT
746
747 CodeBuffer dest(dest_blob);
748 assert(dest_blob->content_size() >= total_content_size(), "good sizing");
749 this->compute_final_layout(&dest);
750
751 // Set beginning of constant table before relocating.
752 dest_blob->set_ctable_begin(dest.consts()->start());
753
754 relocate_code_to(&dest);
|
606
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
706 buf_offset += sizeof(relocInfo);
707 }
708
709 assert(only_inst || code_end_so_far == total_content_size(), "sanity");
710
711 return buf_offset;
712 }
713
714 csize_t CodeBuffer::copy_relocations_to(CodeBlob* dest) const {
715 address buf = NULL;
716 csize_t buf_offset = 0;
717 csize_t buf_limit = 0;
718
719 if (dest != NULL) {
720 buf = (address)dest->relocation_begin();
721 buf_limit = (address)dest->relocation_end() - buf;
722 }
723 // if dest == NULL, this is just the sizing pass
724 //
725 buf_offset = copy_relocations_to(buf, buf_limit, false);
726
727 return buf_offset;
728 }
729
730 void CodeBuffer::copy_code_to(CodeBlob* dest_blob) {
731 #ifndef PRODUCT
732 if (PrintNMethods && (WizardMode || Verbose)) {
733 tty->print("done with CodeBuffer:");
734 ((CodeBuffer*)this)->print();
735 }
736 #endif //PRODUCT
737
738 CodeBuffer dest(dest_blob);
739 assert(dest_blob->content_size() >= total_content_size(), "good sizing");
740 this->compute_final_layout(&dest);
741
742 // Set beginning of constant table before relocating.
743 dest_blob->set_ctable_begin(dest.consts()->start());
744
745 relocate_code_to(&dest);
|