comparison src/share/vm/asm/codeBuffer.cpp @ 1762:0878d7bae69f

6961697: move nmethod constants section before instruction section Summary: This is a preparation for 6961690. Reviewed-by: kvn, never
author twisti
date Fri, 27 Aug 2010 01:51:27 -0700
parents 3e8fbc61cee8
children 2d26b0046e0d f95d63e2154a
comparison
equal deleted inserted replaced
1761:14b92b91f460 1762:0878d7bae69f
141 _oop_recorder = r; 141 _oop_recorder = r;
142 } 142 }
143 143
144 void CodeBuffer::initialize_section_size(CodeSection* cs, csize_t size) { 144 void CodeBuffer::initialize_section_size(CodeSection* cs, csize_t size) {
145 assert(cs != &_insts, "insts is the memory provider, not the consumer"); 145 assert(cs != &_insts, "insts is the memory provider, not the consumer");
146 #ifdef ASSERT
147 for (int n = (int)SECT_INSTS+1; n < (int)SECT_LIMIT; n++) {
148 CodeSection* prevCS = code_section(n);
149 if (prevCS == cs) break;
150 assert(!prevCS->is_allocated(), "section allocation must be in reverse order");
151 }
152 #endif
153 csize_t slop = CodeSection::end_slop(); // margin between sections 146 csize_t slop = CodeSection::end_slop(); // margin between sections
154 int align = cs->alignment(); 147 int align = cs->alignment();
155 assert(is_power_of_2(align), "sanity"); 148 assert(is_power_of_2(align), "sanity");
156 address start = _insts._start; 149 address start = _insts._start;
157 address limit = _insts._limit; 150 address limit = _insts._limit;
197 int align = _insts.alignment(); 190 int align = _insts.alignment();
198 start += (-(intptr_t)start) & (align-1); 191 start += (-(intptr_t)start) & (align-1);
199 _total_start = start; 192 _total_start = start;
200 _total_size = end - start; 193 _total_size = end - start;
201 } else { 194 } else {
202 #ifdef ASSERT 195 #ifdef ASSERT
203 // Clean out dangling pointers. 196 // Clean out dangling pointers.
204 _total_start = badAddress; 197 _total_start = badAddress;
198 _consts._start = _consts._end = badAddress;
205 _insts._start = _insts._end = badAddress; 199 _insts._start = _insts._end = badAddress;
206 _stubs._start = _stubs._end = badAddress; 200 _stubs._start = _stubs._end = badAddress;
207 _consts._start = _consts._end = badAddress; 201 #endif //ASSERT
208 #endif //ASSERT
209 } 202 }
210 } 203 }
211 204
212 void CodeBuffer::free_blob() { 205 void CodeBuffer::free_blob() {
213 if (_blob != NULL) { 206 if (_blob != NULL) {
219 const char* CodeBuffer::code_section_name(int n) { 212 const char* CodeBuffer::code_section_name(int n) {
220 #ifdef PRODUCT 213 #ifdef PRODUCT
221 return NULL; 214 return NULL;
222 #else //PRODUCT 215 #else //PRODUCT
223 switch (n) { 216 switch (n) {
217 case SECT_CONSTS: return "consts";
224 case SECT_INSTS: return "insts"; 218 case SECT_INSTS: return "insts";
225 case SECT_STUBS: return "stubs"; 219 case SECT_STUBS: return "stubs";
226 case SECT_CONSTS: return "consts";
227 default: return NULL; 220 default: return NULL;
228 } 221 }
229 #endif //PRODUCT 222 #endif //PRODUCT
230 } 223 }
231 224
443 assert( (dest->_total_start - _insts.start()) % alignSize == 0, "copy must preserve alignment"); 436 assert( (dest->_total_start - _insts.start()) % alignSize == 0, "copy must preserve alignment");
444 } 437 }
445 438
446 const CodeSection* prev_cs = NULL; 439 const CodeSection* prev_cs = NULL;
447 CodeSection* prev_dest_cs = NULL; 440 CodeSection* prev_dest_cs = NULL;
448 for (int n = 0; n < (int)SECT_LIMIT; n++) { 441
442 for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) {
449 // figure compact layout of each section 443 // figure compact layout of each section
450 const CodeSection* cs = code_section(n); 444 const CodeSection* cs = code_section(n);
451 address cstart = cs->start(); 445 csize_t csize = cs->size();
452 address cend = cs->end();
453 csize_t csize = cend - cstart;
454 446
455 CodeSection* dest_cs = dest->code_section(n); 447 CodeSection* dest_cs = dest->code_section(n);
456 if (!cs->is_empty()) { 448 if (!cs->is_empty()) {
457 // Compute initial padding; assign it to the previous non-empty guy. 449 // Compute initial padding; assign it to the previous non-empty guy.
458 // Cf. figure_expanded_capacities. 450 // Cf. figure_expanded_capacities.
461 buf_offset += padding; 453 buf_offset += padding;
462 assert(prev_dest_cs != NULL, "sanity"); 454 assert(prev_dest_cs != NULL, "sanity");
463 prev_dest_cs->_limit += padding; 455 prev_dest_cs->_limit += padding;
464 } 456 }
465 #ifdef ASSERT 457 #ifdef ASSERT
466 if (prev_cs != NULL && prev_cs->is_frozen() && n < SECT_CONSTS) { 458 if (prev_cs != NULL && prev_cs->is_frozen() && n < (SECT_LIMIT - 1)) {
467 // Make sure the ends still match up. 459 // Make sure the ends still match up.
468 // This is important because a branch in a frozen section 460 // This is important because a branch in a frozen section
469 // might target code in a following section, via a Label, 461 // might target code in a following section, via a Label,
470 // and without a relocation record. See Label::patch_instructions. 462 // and without a relocation record. See Label::patch_instructions.
471 address dest_start = buf+buf_offset; 463 address dest_start = buf+buf_offset;
490 // Done calculating sections; did it come out to the right end? 482 // Done calculating sections; did it come out to the right end?
491 assert(buf_offset == total_content_size(), "sanity"); 483 assert(buf_offset == total_content_size(), "sanity");
492 assert(dest->verify_section_allocation(), "final configuration works"); 484 assert(dest->verify_section_allocation(), "final configuration works");
493 } 485 }
494 486
495 csize_t CodeBuffer::total_offset_of(address addr) const { 487 csize_t CodeBuffer::total_offset_of(CodeSection* cs) const {
496 csize_t code_size_so_far = 0; 488 csize_t size_so_far = 0;
497 for (int n = 0; n < (int)SECT_LIMIT; n++) { 489 for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) {
498 const CodeSection* cs = code_section(n); 490 const CodeSection* cur_cs = code_section(n);
499 if (!cs->is_empty()) { 491 if (!cur_cs->is_empty()) {
500 code_size_so_far = cs->align_at_start(code_size_so_far); 492 size_so_far = cur_cs->align_at_start(size_so_far);
501 } 493 }
502 if (cs->contains2(addr)) { 494 if (cur_cs->index() == cs->index()) {
503 return code_size_so_far + (addr - cs->start()); 495 return size_so_far;
504 } 496 }
505 code_size_so_far += cs->size(); 497 size_so_far += cur_cs->size();
506 } 498 }
507 #ifndef PRODUCT
508 tty->print_cr("Dangling address " PTR_FORMAT " in:", addr);
509 ((CodeBuffer*)this)->print();
510 #endif
511 ShouldNotReachHere(); 499 ShouldNotReachHere();
512 return -1; 500 return -1;
513 } 501 }
514 502
515 csize_t CodeBuffer::total_relocation_size() const { 503 csize_t CodeBuffer::total_relocation_size() const {
531 } 519 }
532 // if dest == NULL, this is just the sizing pass 520 // if dest == NULL, this is just the sizing pass
533 521
534 csize_t code_end_so_far = 0; 522 csize_t code_end_so_far = 0;
535 csize_t code_point_so_far = 0; 523 csize_t code_point_so_far = 0;
536 for (int n = 0; n < (int)SECT_LIMIT; n++) { 524 for (int n = (int) SECT_FIRST; n < (int)SECT_LIMIT; n++) {
537 // pull relocs out of each section 525 // pull relocs out of each section
538 const CodeSection* cs = code_section(n); 526 const CodeSection* cs = code_section(n);
539 assert(!(cs->is_empty() && cs->locs_count() > 0), "sanity"); 527 assert(!(cs->is_empty() && cs->locs_count() > 0), "sanity");
540 if (cs->is_empty()) continue; // skip trivial section 528 if (cs->is_empty()) continue; // skip trivial section
541 relocInfo* lstart = cs->locs_start(); 529 relocInfo* lstart = cs->locs_start();
633 621
634 // Flush generated code 622 // Flush generated code
635 ICache::invalidate_range(dest_blob->code_begin(), dest_blob->code_size()); 623 ICache::invalidate_range(dest_blob->code_begin(), dest_blob->code_size());
636 } 624 }
637 625
638 // Move all my code into another code buffer. 626 // Move all my code into another code buffer. Consult applicable
639 // Consult applicable relocs to repair embedded addresses. 627 // relocs to repair embedded addresses. The layout in the destination
628 // CodeBuffer is different to the source CodeBuffer: the destination
629 // CodeBuffer gets the final layout (consts, insts, stubs in order of
630 // ascending address).
640 void CodeBuffer::relocate_code_to(CodeBuffer* dest) const { 631 void CodeBuffer::relocate_code_to(CodeBuffer* dest) const {
641 DEBUG_ONLY(address dest_end = dest->_total_start + dest->_total_size); 632 DEBUG_ONLY(address dest_end = dest->_total_start + dest->_total_size);
642 for (int n = 0; n < (int)SECT_LIMIT; n++) { 633 for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) {
643 // pull code out of each section 634 // pull code out of each section
644 const CodeSection* cs = code_section(n); 635 const CodeSection* cs = code_section(n);
645 if (cs->is_empty()) continue; // skip trivial section 636 if (cs->is_empty()) continue; // skip trivial section
646 CodeSection* dest_cs = dest->code_section(n); 637 CodeSection* dest_cs = dest->code_section(n);
647 assert(cs->size() == dest_cs->size(), "sanity"); 638 assert(cs->size() == dest_cs->size(), "sanity");
679 csize_t CodeBuffer::figure_expanded_capacities(CodeSection* which_cs, 670 csize_t CodeBuffer::figure_expanded_capacities(CodeSection* which_cs,
680 csize_t amount, 671 csize_t amount,
681 csize_t* new_capacity) { 672 csize_t* new_capacity) {
682 csize_t new_total_cap = 0; 673 csize_t new_total_cap = 0;
683 674
684 int prev_n = -1; 675 for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) {
685 for (int n = 0; n < (int)SECT_LIMIT; n++) {
686 const CodeSection* sect = code_section(n); 676 const CodeSection* sect = code_section(n);
687 677
688 if (!sect->is_empty()) { 678 if (!sect->is_empty()) {
689 // Compute initial padding; assign it to the previous non-empty guy. 679 // Compute initial padding; assign it to the previous section,
690 // Cf. compute_final_layout. 680 // even if it's empty (e.g. consts section can be empty).
681 // Cf. compute_final_layout
691 csize_t padding = sect->align_at_start(new_total_cap) - new_total_cap; 682 csize_t padding = sect->align_at_start(new_total_cap) - new_total_cap;
692 if (padding != 0) { 683 if (padding != 0) {
693 new_total_cap += padding; 684 new_total_cap += padding;
694 assert(prev_n >= 0, "sanity"); 685 assert(n - 1 >= SECT_FIRST, "sanity");
695 new_capacity[prev_n] += padding; 686 new_capacity[n - 1] += padding;
696 } 687 }
697 prev_n = n;
698 } 688 }
699 689
700 csize_t exp = sect->size(); // 100% increase 690 csize_t exp = sect->size(); // 100% increase
701 if ((uint)exp < 4*K) exp = 4*K; // minimum initial increase 691 if ((uint)exp < 4*K) exp = 4*K; // minimum initial increase
702 if (sect == which_cs) { 692 if (sect == which_cs) {
772 DEBUG_ONLY(this->_blob = NULL); // silence a later assert 762 DEBUG_ONLY(this->_blob = NULL); // silence a later assert
773 bxp->_before_expand = this->_before_expand; 763 bxp->_before_expand = this->_before_expand;
774 this->_before_expand = bxp; 764 this->_before_expand = bxp;
775 765
776 // Give each section its required (expanded) capacity. 766 // Give each section its required (expanded) capacity.
777 for (int n = (int)SECT_LIMIT-1; n >= SECT_INSTS; n--) { 767 for (int n = (int)SECT_LIMIT-1; n >= SECT_FIRST; n--) {
778 CodeSection* cb_sect = cb.code_section(n); 768 CodeSection* cb_sect = cb.code_section(n);
779 CodeSection* this_sect = code_section(n); 769 CodeSection* this_sect = code_section(n);
780 if (new_capacity[n] == 0) continue; // already nulled out 770 if (new_capacity[n] == 0) continue; // already nulled out
781 if (n > SECT_INSTS) { 771 if (n != SECT_INSTS) {
782 cb.initialize_section_size(cb_sect, new_capacity[n]); 772 cb.initialize_section_size(cb_sect, new_capacity[n]);
783 } 773 }
784 assert(cb_sect->capacity() >= new_capacity[n], "big enough"); 774 assert(cb_sect->capacity() >= new_capacity[n], "big enough");
785 address cb_start = cb_sect->start(); 775 address cb_start = cb_sect->start();
786 cb_sect->set_end(cb_start + this_sect->size()); 776 cb_sect->set_end(cb_start + this_sect->size());
842 address tend = tstart + _total_size; 832 address tend = tstart + _total_size;
843 if (_blob != NULL) { 833 if (_blob != NULL) {
844 assert(tstart >= _blob->content_begin(), "sanity"); 834 assert(tstart >= _blob->content_begin(), "sanity");
845 assert(tend <= _blob->content_end(), "sanity"); 835 assert(tend <= _blob->content_end(), "sanity");
846 } 836 }
847 address tcheck = tstart; // advancing pointer to verify disjointness 837 // Verify disjointness.
848 for (int n = 0; n < (int)SECT_LIMIT; n++) { 838 for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) {
849 CodeSection* sect = code_section(n); 839 CodeSection* sect = code_section(n);
850 if (!sect->is_allocated()) continue; 840 if (!sect->is_allocated() || sect->is_empty()) continue;
851 assert(sect->start() >= tcheck, "sanity"); 841 assert((intptr_t)sect->start() % sect->alignment() == 0
852 tcheck = sect->start();
853 assert((intptr_t)tcheck % sect->alignment() == 0
854 || sect->is_empty() || _blob == NULL, 842 || sect->is_empty() || _blob == NULL,
855 "start is aligned"); 843 "start is aligned");
856 assert(sect->end() >= tcheck, "sanity"); 844 for (int m = (int) SECT_FIRST; m < (int) SECT_LIMIT; m++) {
857 assert(sect->end() <= tend, "sanity"); 845 CodeSection* other = code_section(m);
846 if (!other->is_allocated() || other == sect) continue;
847 assert(!other->contains(sect->start() ), "sanity");
848 // limit is an exclusive address and can be the start of another
849 // section.
850 assert(!other->contains(sect->limit() - 1), "sanity");
851 }
852 assert(sect->end() <= tend, "sanity");
858 } 853 }
859 return true; 854 return true;
860 } 855 }
861 #endif //ASSERT 856 #endif //ASSERT
862 857