Mercurial > hg > truffle
comparison src/share/vm/asm/codeBuffer.cpp @ 1930:2d26b0046e0d
Merge.
author | Thomas Wuerthinger <wuerthinger@ssw.jku.at> |
---|---|
date | Tue, 30 Nov 2010 14:53:30 +0100 |
parents | e1a275dbc8cd 0878d7bae69f |
children | 06f017f7daa7 |
comparison
equal
deleted
inserted
replaced
1484:6b7001391c97 | 1930:2d26b0046e0d |
---|---|
1 /* | 1 /* |
2 * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved. | 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
14 * | 14 * |
15 * You should have received a copy of the GNU General Public License version | 15 * You should have received a copy of the GNU General Public License version |
16 * 2 along with this work; if not, write to the Free Software Foundation, | 16 * 2 along with this work; if not, write to the Free Software Foundation, |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
18 * | 18 * |
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | 20 * or visit www.oracle.com if you need additional information or have any |
21 * have any questions. | 21 * questions. |
22 * | 22 * |
23 */ | 23 */ |
24 | 24 |
25 # include "incls/_precompiled.incl" | 25 # include "incls/_precompiled.incl" |
26 # include "incls/_codeBuffer.cpp.incl" | 26 # include "incls/_codeBuffer.cpp.incl" |
72 // the empty parts of each section are removed, and everything | 72 // the empty parts of each section are removed, and everything |
73 // is copied into contiguous locations. | 73 // is copied into contiguous locations. |
74 | 74 |
75 typedef CodeBuffer::csize_t csize_t; // file-local definition | 75 typedef CodeBuffer::csize_t csize_t; // file-local definition |
76 | 76 |
77 // external buffer, in a predefined CodeBlob or other buffer area | 77 // External buffer, in a predefined CodeBlob. |
78 // Important: The code_start must be taken exactly, and not realigned. | 78 // Important: The code_start must be taken exactly, and not realigned. |
79 CodeBuffer::CodeBuffer(address code_start, csize_t code_size) { | 79 CodeBuffer::CodeBuffer(CodeBlob* blob) { |
80 assert(code_start != NULL, "sanity"); | |
81 initialize_misc("static buffer"); | 80 initialize_misc("static buffer"); |
82 initialize(code_start, code_size); | 81 initialize(blob->content_begin(), blob->content_size()); |
83 assert(verify_section_allocation(), "initial use of buffer OK"); | 82 assert(verify_section_allocation(), "initial use of buffer OK"); |
84 } | 83 } |
85 | 84 |
86 void CodeBuffer::initialize(csize_t code_size, csize_t locs_size) { | 85 void CodeBuffer::initialize(csize_t code_size, csize_t locs_size) { |
87 // Compute maximal alignment. | 86 // Compute maximal alignment. |
97 } | 96 } |
98 | 97 |
99 // Set up various pointers into the blob. | 98 // Set up various pointers into the blob. |
100 initialize(_total_start, _total_size); | 99 initialize(_total_start, _total_size); |
101 | 100 |
102 assert((uintptr_t)code_begin() % CodeEntryAlignment == 0, "instruction start not code entry aligned"); | 101 assert((uintptr_t)insts_begin() % CodeEntryAlignment == 0, "instruction start not code entry aligned"); |
103 | 102 |
104 pd_initialize(); | 103 pd_initialize(); |
105 | 104 |
106 if (locs_size != 0) { | 105 if (locs_size != 0) { |
107 _insts.initialize_locs(locs_size / sizeof(relocInfo)); | 106 _insts.initialize_locs(locs_size / sizeof(relocInfo)); |
126 | 125 |
127 // free any overflow storage | 126 // free any overflow storage |
128 delete _overflow_arena; | 127 delete _overflow_arena; |
129 | 128 |
130 #ifdef ASSERT | 129 #ifdef ASSERT |
130 // Save allocation type to execute assert in ~ResourceObj() | |
131 // which is called after this destructor. | |
132 ResourceObj::allocation_type at = _default_oop_recorder.get_allocation_type(); | |
131 Copy::fill_to_bytes(this, sizeof(*this), badResourceValue); | 133 Copy::fill_to_bytes(this, sizeof(*this), badResourceValue); |
134 ResourceObj::set_allocation_type((address)(&_default_oop_recorder), at); | |
132 #endif | 135 #endif |
133 } | 136 } |
134 | 137 |
135 void CodeBuffer::initialize_oop_recorder(OopRecorder* r) { | 138 void CodeBuffer::initialize_oop_recorder(OopRecorder* r) { |
136 assert(_oop_recorder == &_default_oop_recorder && _default_oop_recorder.is_unused(), "do this once"); | 139 assert(_oop_recorder == &_default_oop_recorder && _default_oop_recorder.is_unused(), "do this once"); |
138 _oop_recorder = r; | 141 _oop_recorder = r; |
139 } | 142 } |
140 | 143 |
141 void CodeBuffer::initialize_section_size(CodeSection* cs, csize_t size) { | 144 void CodeBuffer::initialize_section_size(CodeSection* cs, csize_t size) { |
142 assert(cs != &_insts, "insts is the memory provider, not the consumer"); | 145 assert(cs != &_insts, "insts is the memory provider, not the consumer"); |
143 #ifdef ASSERT | |
144 for (int n = (int)SECT_INSTS+1; n < (int)SECT_LIMIT; n++) { | |
145 CodeSection* prevCS = code_section(n); | |
146 if (prevCS == cs) break; | |
147 assert(!prevCS->is_allocated(), "section allocation must be in reverse order"); | |
148 } | |
149 #endif | |
150 csize_t slop = CodeSection::end_slop(); // margin between sections | 146 csize_t slop = CodeSection::end_slop(); // margin between sections |
151 int align = cs->alignment(); | 147 int align = cs->alignment(); |
152 assert(is_power_of_2(align), "sanity"); | 148 assert(is_power_of_2(align), "sanity"); |
153 address start = _insts._start; | 149 address start = _insts._start; |
154 address limit = _insts._limit; | 150 address limit = _insts._limit; |
186 } | 182 } |
187 | 183 |
188 void CodeBuffer::set_blob(BufferBlob* blob) { | 184 void CodeBuffer::set_blob(BufferBlob* blob) { |
189 _blob = blob; | 185 _blob = blob; |
190 if (blob != NULL) { | 186 if (blob != NULL) { |
191 address start = blob->instructions_begin(); | 187 address start = blob->content_begin(); |
192 address end = blob->instructions_end(); | 188 address end = blob->content_end(); |
193 // Round up the starting address. | 189 // Round up the starting address. |
194 int align = _insts.alignment(); | 190 int align = _insts.alignment(); |
195 start += (-(intptr_t)start) & (align-1); | 191 start += (-(intptr_t)start) & (align-1); |
196 _total_start = start; | 192 _total_start = start; |
197 _total_size = end - start; | 193 _total_size = end - start; |
198 } else { | 194 } else { |
199 #ifdef ASSERT | 195 #ifdef ASSERT |
200 // Clean out dangling pointers. | 196 // Clean out dangling pointers. |
201 _total_start = badAddress; | 197 _total_start = badAddress; |
198 _consts._start = _consts._end = badAddress; | |
202 _insts._start = _insts._end = badAddress; | 199 _insts._start = _insts._end = badAddress; |
203 _stubs._start = _stubs._end = badAddress; | 200 _stubs._start = _stubs._end = badAddress; |
204 _consts._start = _consts._end = badAddress; | 201 #endif //ASSERT |
205 #endif //ASSERT | |
206 } | 202 } |
207 } | 203 } |
208 | 204 |
209 void CodeBuffer::free_blob() { | 205 void CodeBuffer::free_blob() { |
210 if (_blob != NULL) { | 206 if (_blob != NULL) { |
216 const char* CodeBuffer::code_section_name(int n) { | 212 const char* CodeBuffer::code_section_name(int n) { |
217 #ifdef PRODUCT | 213 #ifdef PRODUCT |
218 return NULL; | 214 return NULL; |
219 #else //PRODUCT | 215 #else //PRODUCT |
220 switch (n) { | 216 switch (n) { |
217 case SECT_CONSTS: return "consts"; | |
221 case SECT_INSTS: return "insts"; | 218 case SECT_INSTS: return "insts"; |
222 case SECT_STUBS: return "stubs"; | 219 case SECT_STUBS: return "stubs"; |
223 case SECT_CONSTS: return "consts"; | |
224 default: return NULL; | 220 default: return NULL; |
225 } | 221 } |
226 #endif //PRODUCT | 222 #endif //PRODUCT |
227 } | 223 } |
228 | 224 |
402 relocInfo* locs_start; | 398 relocInfo* locs_start; |
403 if (_locs_own) { | 399 if (_locs_own) { |
404 locs_start = REALLOC_RESOURCE_ARRAY(relocInfo, _locs_start, old_capacity, new_capacity); | 400 locs_start = REALLOC_RESOURCE_ARRAY(relocInfo, _locs_start, old_capacity, new_capacity); |
405 } else { | 401 } else { |
406 locs_start = NEW_RESOURCE_ARRAY(relocInfo, new_capacity); | 402 locs_start = NEW_RESOURCE_ARRAY(relocInfo, new_capacity); |
407 Copy::conjoint_bytes(_locs_start, locs_start, old_capacity * sizeof(relocInfo)); | 403 Copy::conjoint_jbytes(_locs_start, locs_start, old_capacity * sizeof(relocInfo)); |
408 _locs_own = true; | 404 _locs_own = true; |
409 } | 405 } |
410 _locs_start = locs_start; | 406 _locs_start = locs_start; |
411 _locs_end = locs_start + old_count; | 407 _locs_end = locs_start + old_count; |
412 _locs_limit = locs_start + new_capacity; | 408 _locs_limit = locs_start + new_capacity; |
416 | 412 |
417 /// Support for emitting the code to its final location. | 413 /// Support for emitting the code to its final location. |
418 /// The pattern is the same for all functions. | 414 /// The pattern is the same for all functions. |
419 /// We iterate over all the sections, padding each to alignment. | 415 /// We iterate over all the sections, padding each to alignment. |
420 | 416 |
421 csize_t CodeBuffer::total_code_size() const { | 417 csize_t CodeBuffer::total_content_size() const { |
422 csize_t code_size_so_far = 0; | 418 csize_t size_so_far = 0; |
423 for (int n = 0; n < (int)SECT_LIMIT; n++) { | 419 for (int n = 0; n < (int)SECT_LIMIT; n++) { |
424 const CodeSection* cs = code_section(n); | 420 const CodeSection* cs = code_section(n); |
425 if (cs->is_empty()) continue; // skip trivial section | 421 if (cs->is_empty()) continue; // skip trivial section |
426 code_size_so_far = cs->align_at_start(code_size_so_far); | 422 size_so_far = cs->align_at_start(size_so_far); |
427 code_size_so_far += cs->size(); | 423 size_so_far += cs->size(); |
428 } | 424 } |
429 return code_size_so_far; | 425 return size_so_far; |
430 } | 426 } |
431 | 427 |
432 void CodeBuffer::compute_final_layout(CodeBuffer* dest) const { | 428 void CodeBuffer::compute_final_layout(CodeBuffer* dest) const { |
433 address buf = dest->_total_start; | 429 address buf = dest->_total_start; |
434 csize_t buf_offset = 0; | 430 csize_t buf_offset = 0; |
435 assert(dest->_total_size >= total_code_size(), "must be big enough"); | 431 assert(dest->_total_size >= total_content_size(), "must be big enough"); |
436 | 432 |
437 { | 433 { |
438 // not sure why this is here, but why not... | 434 // not sure why this is here, but why not... |
439 // (tw) disabled assert | 435 // (tw) disabled assert |
440 // int alignSize = MAX2((intx) sizeof(jdouble), CodeEntryAlignment); | 436 // int alignSize = MAX2((intx) sizeof(jdouble), CodeEntryAlignment); |
441 // assert( (dest->_total_start - _insts.start()) % alignSize == 0, "copy must preserve alignment"); | 437 // assert( (dest->_total_start - _insts.start()) % alignSize == 0, "copy must preserve alignment"); |
442 } | 438 } |
443 | 439 |
444 const CodeSection* prev_cs = NULL; | 440 const CodeSection* prev_cs = NULL; |
445 CodeSection* prev_dest_cs = NULL; | 441 CodeSection* prev_dest_cs = NULL; |
446 for (int n = 0; n < (int)SECT_LIMIT; n++) { | 442 |
443 for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) { | |
447 // figure compact layout of each section | 444 // figure compact layout of each section |
448 const CodeSection* cs = code_section(n); | 445 const CodeSection* cs = code_section(n); |
449 address cstart = cs->start(); | 446 csize_t csize = cs->size(); |
450 address cend = cs->end(); | |
451 csize_t csize = cend - cstart; | |
452 | 447 |
453 CodeSection* dest_cs = dest->code_section(n); | 448 CodeSection* dest_cs = dest->code_section(n); |
454 if (!cs->is_empty()) { | 449 if (!cs->is_empty()) { |
455 // Compute initial padding; assign it to the previous non-empty guy. | 450 // Compute initial padding; assign it to the previous non-empty guy. |
456 // Cf. figure_expanded_capacities. | 451 // Cf. figure_expanded_capacities. |
459 buf_offset += padding; | 454 buf_offset += padding; |
460 assert(prev_dest_cs != NULL, "sanity"); | 455 assert(prev_dest_cs != NULL, "sanity"); |
461 prev_dest_cs->_limit += padding; | 456 prev_dest_cs->_limit += padding; |
462 } | 457 } |
463 #ifdef ASSERT | 458 #ifdef ASSERT |
464 if (prev_cs != NULL && prev_cs->is_frozen() && n < SECT_CONSTS) { | 459 if (prev_cs != NULL && prev_cs->is_frozen() && n < (SECT_LIMIT - 1)) { |
465 // Make sure the ends still match up. | 460 // Make sure the ends still match up. |
466 // This is important because a branch in a frozen section | 461 // This is important because a branch in a frozen section |
467 // might target code in a following section, via a Label, | 462 // might target code in a following section, via a Label, |
468 // and without a relocation record. See Label::patch_instructions. | 463 // and without a relocation record. See Label::patch_instructions. |
469 address dest_start = buf+buf_offset; | 464 address dest_start = buf+buf_offset; |
484 | 479 |
485 buf_offset += csize; | 480 buf_offset += csize; |
486 } | 481 } |
487 | 482 |
488 // Done calculating sections; did it come out to the right end? | 483 // Done calculating sections; did it come out to the right end? |
489 assert(buf_offset == total_code_size(), "sanity"); | 484 assert(buf_offset == total_content_size(), "sanity"); |
490 assert(dest->verify_section_allocation(), "final configuration works"); | 485 assert(dest->verify_section_allocation(), "final configuration works"); |
491 } | 486 } |
492 | 487 |
493 csize_t CodeBuffer::total_offset_of(address addr) const { | 488 csize_t CodeBuffer::total_offset_of(CodeSection* cs) const { |
494 csize_t code_size_so_far = 0; | 489 csize_t size_so_far = 0; |
495 for (int n = 0; n < (int)SECT_LIMIT; n++) { | 490 for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) { |
496 const CodeSection* cs = code_section(n); | 491 const CodeSection* cur_cs = code_section(n); |
497 if (!cs->is_empty()) { | 492 if (!cur_cs->is_empty()) { |
498 code_size_so_far = cs->align_at_start(code_size_so_far); | 493 size_so_far = cur_cs->align_at_start(size_so_far); |
499 } | 494 } |
500 if (cs->contains2(addr)) { | 495 if (cur_cs->index() == cs->index()) { |
501 return code_size_so_far + (addr - cs->start()); | 496 return size_so_far; |
502 } | 497 } |
503 code_size_so_far += cs->size(); | 498 size_so_far += cur_cs->size(); |
504 } | 499 } |
505 #ifndef PRODUCT | |
506 tty->print_cr("Dangling address " PTR_FORMAT " in:", addr); | |
507 ((CodeBuffer*)this)->print(); | |
508 #endif | |
509 ShouldNotReachHere(); | 500 ShouldNotReachHere(); |
510 return -1; | 501 return -1; |
511 } | 502 } |
512 | 503 |
513 csize_t CodeBuffer::total_relocation_size() const { | 504 csize_t CodeBuffer::total_relocation_size() const { |
514 csize_t lsize = copy_relocations_to(NULL); // dry run only | 505 csize_t lsize = copy_relocations_to(NULL); // dry run only |
515 csize_t csize = total_code_size(); | 506 csize_t csize = total_content_size(); |
516 csize_t total = RelocIterator::locs_and_index_size(csize, lsize); | 507 csize_t total = RelocIterator::locs_and_index_size(csize, lsize); |
517 return (csize_t) align_size_up(total, HeapWordSize); | 508 return (csize_t) align_size_up(total, HeapWordSize); |
518 } | 509 } |
519 | 510 |
520 csize_t CodeBuffer::copy_relocations_to(CodeBlob* dest) const { | 511 csize_t CodeBuffer::copy_relocations_to(CodeBlob* dest) const { |
529 } | 520 } |
530 // if dest == NULL, this is just the sizing pass | 521 // if dest == NULL, this is just the sizing pass |
531 | 522 |
532 csize_t code_end_so_far = 0; | 523 csize_t code_end_so_far = 0; |
533 csize_t code_point_so_far = 0; | 524 csize_t code_point_so_far = 0; |
534 for (int n = 0; n < (int)SECT_LIMIT; n++) { | 525 for (int n = (int) SECT_FIRST; n < (int)SECT_LIMIT; n++) { |
535 // pull relocs out of each section | 526 // pull relocs out of each section |
536 const CodeSection* cs = code_section(n); | 527 const CodeSection* cs = code_section(n); |
537 assert(!(cs->is_empty() && cs->locs_count() > 0), "sanity"); | 528 assert(!(cs->is_empty() && cs->locs_count() > 0), "sanity"); |
538 if (cs->is_empty()) continue; // skip trivial section | 529 if (cs->is_empty()) continue; // skip trivial section |
539 relocInfo* lstart = cs->locs_start(); | 530 relocInfo* lstart = cs->locs_start(); |
580 // Use wordwise copies if possible: | 571 // Use wordwise copies if possible: |
581 Copy::disjoint_words((HeapWord*)lstart, | 572 Copy::disjoint_words((HeapWord*)lstart, |
582 (HeapWord*)(buf+buf_offset), | 573 (HeapWord*)(buf+buf_offset), |
583 (lsize + HeapWordSize-1) / HeapWordSize); | 574 (lsize + HeapWordSize-1) / HeapWordSize); |
584 } else { | 575 } else { |
585 Copy::conjoint_bytes(lstart, buf+buf_offset, lsize); | 576 Copy::conjoint_jbytes(lstart, buf+buf_offset, lsize); |
586 } | 577 } |
587 } | 578 } |
588 buf_offset += lsize; | 579 buf_offset += lsize; |
589 } | 580 } |
590 | 581 |
596 *(relocInfo*)(buf+buf_offset) = padding; | 587 *(relocInfo*)(buf+buf_offset) = padding; |
597 } | 588 } |
598 buf_offset += sizeof(relocInfo); | 589 buf_offset += sizeof(relocInfo); |
599 } | 590 } |
600 | 591 |
601 assert(code_end_so_far == total_code_size(), "sanity"); | 592 assert(code_end_so_far == total_content_size(), "sanity"); |
602 | 593 |
603 // Account for index: | 594 // Account for index: |
604 if (buf != NULL) { | 595 if (buf != NULL) { |
605 RelocIterator::create_index(dest->relocation_begin(), | 596 RelocIterator::create_index(dest->relocation_begin(), |
606 buf_offset / sizeof(relocInfo), | 597 buf_offset / sizeof(relocInfo), |
616 tty->print("done with CodeBuffer:"); | 607 tty->print("done with CodeBuffer:"); |
617 ((CodeBuffer*)this)->print(); | 608 ((CodeBuffer*)this)->print(); |
618 } | 609 } |
619 #endif //PRODUCT | 610 #endif //PRODUCT |
620 | 611 |
621 CodeBuffer dest(dest_blob->instructions_begin(), | 612 CodeBuffer dest(dest_blob); |
622 dest_blob->instructions_size()); | 613 assert(dest_blob->content_size() >= total_content_size(), "good sizing"); |
623 assert(dest_blob->instructions_size() >= total_code_size(), "good sizing"); | |
624 this->compute_final_layout(&dest); | 614 this->compute_final_layout(&dest); |
625 relocate_code_to(&dest); | 615 relocate_code_to(&dest); |
626 | 616 |
627 // transfer comments from buffer to blob | 617 // transfer comments from buffer to blob |
628 dest_blob->set_comments(_comments); | 618 dest_blob->set_comments(_comments); |
629 | 619 |
630 // Done moving code bytes; were they the right size? | 620 // Done moving code bytes; were they the right size? |
631 assert(round_to(dest.total_code_size(), oopSize) == dest_blob->instructions_size(), "sanity"); | 621 assert(round_to(dest.total_content_size(), oopSize) == dest_blob->content_size(), "sanity"); |
632 | 622 |
633 // Flush generated code | 623 // Flush generated code |
634 ICache::invalidate_range(dest_blob->instructions_begin(), | 624 ICache::invalidate_range(dest_blob->code_begin(), dest_blob->code_size()); |
635 dest_blob->instructions_size()); | 625 } |
636 } | 626 |
637 | 627 // Move all my code into another code buffer. Consult applicable |
638 // Move all my code into another code buffer. | 628 // relocs to repair embedded addresses. The layout in the destination |
639 // Consult applicable relocs to repair embedded addresses. | 629 // CodeBuffer is different to the source CodeBuffer: the destination |
630 // CodeBuffer gets the final layout (consts, insts, stubs in order of | |
631 // ascending address). | |
640 void CodeBuffer::relocate_code_to(CodeBuffer* dest) const { | 632 void CodeBuffer::relocate_code_to(CodeBuffer* dest) const { |
641 DEBUG_ONLY(address dest_end = dest->_total_start + dest->_total_size); | 633 DEBUG_ONLY(address dest_end = dest->_total_start + dest->_total_size); |
642 for (int n = 0; n < (int)SECT_LIMIT; n++) { | 634 for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) { |
643 // pull code out of each section | 635 // pull code out of each section |
644 const CodeSection* cs = code_section(n); | 636 const CodeSection* cs = code_section(n); |
645 if (cs->is_empty()) continue; // skip trivial section | 637 if (cs->is_empty()) continue; // skip trivial section |
646 CodeSection* dest_cs = dest->code_section(n); | 638 CodeSection* dest_cs = dest->code_section(n); |
647 assert(cs->size() == dest_cs->size(), "sanity"); | 639 assert(cs->size() == dest_cs->size(), "sanity"); |
679 csize_t CodeBuffer::figure_expanded_capacities(CodeSection* which_cs, | 671 csize_t CodeBuffer::figure_expanded_capacities(CodeSection* which_cs, |
680 csize_t amount, | 672 csize_t amount, |
681 csize_t* new_capacity) { | 673 csize_t* new_capacity) { |
682 csize_t new_total_cap = 0; | 674 csize_t new_total_cap = 0; |
683 | 675 |
684 int prev_n = -1; | 676 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); | 677 const CodeSection* sect = code_section(n); |
687 | 678 |
688 if (!sect->is_empty()) { | 679 if (!sect->is_empty()) { |
689 // Compute initial padding; assign it to the previous non-empty guy. | 680 // Compute initial padding; assign it to the previous section, |
690 // Cf. compute_final_layout. | 681 // even if it's empty (e.g. consts section can be empty). |
682 // Cf. compute_final_layout | |
691 csize_t padding = sect->align_at_start(new_total_cap) - new_total_cap; | 683 csize_t padding = sect->align_at_start(new_total_cap) - new_total_cap; |
692 if (padding != 0) { | 684 if (padding != 0) { |
693 new_total_cap += padding; | 685 new_total_cap += padding; |
694 assert(prev_n >= 0, "sanity"); | 686 assert(n - 1 >= SECT_FIRST, "sanity"); |
695 new_capacity[prev_n] += padding; | 687 new_capacity[n - 1] += padding; |
696 } | 688 } |
697 prev_n = n; | |
698 } | 689 } |
699 | 690 |
700 csize_t exp = sect->size(); // 100% increase | 691 csize_t exp = sect->size(); // 100% increase |
701 if ((uint)exp < 4*K) exp = 4*K; // minimum initial increase | 692 if ((uint)exp < 4*K) exp = 4*K; // minimum initial increase |
702 if (sect == which_cs) { | 693 if (sect == which_cs) { |
772 DEBUG_ONLY(this->_blob = NULL); // silence a later assert | 763 DEBUG_ONLY(this->_blob = NULL); // silence a later assert |
773 bxp->_before_expand = this->_before_expand; | 764 bxp->_before_expand = this->_before_expand; |
774 this->_before_expand = bxp; | 765 this->_before_expand = bxp; |
775 | 766 |
776 // Give each section its required (expanded) capacity. | 767 // Give each section its required (expanded) capacity. |
777 for (int n = (int)SECT_LIMIT-1; n >= SECT_INSTS; n--) { | 768 for (int n = (int)SECT_LIMIT-1; n >= SECT_FIRST; n--) { |
778 CodeSection* cb_sect = cb.code_section(n); | 769 CodeSection* cb_sect = cb.code_section(n); |
779 CodeSection* this_sect = code_section(n); | 770 CodeSection* this_sect = code_section(n); |
780 if (new_capacity[n] == 0) continue; // already nulled out | 771 if (new_capacity[n] == 0) continue; // already nulled out |
781 if (n > SECT_INSTS) { | 772 if (n != SECT_INSTS) { |
782 cb.initialize_section_size(cb_sect, new_capacity[n]); | 773 cb.initialize_section_size(cb_sect, new_capacity[n]); |
783 } | 774 } |
784 assert(cb_sect->capacity() >= new_capacity[n], "big enough"); | 775 assert(cb_sect->capacity() >= new_capacity[n], "big enough"); |
785 address cb_start = cb_sect->start(); | 776 address cb_start = cb_sect->start(); |
786 cb_sect->set_end(cb_start + this_sect->size()); | 777 cb_sect->set_end(cb_start + this_sect->size()); |
839 bool CodeBuffer::verify_section_allocation() { | 830 bool CodeBuffer::verify_section_allocation() { |
840 address tstart = _total_start; | 831 address tstart = _total_start; |
841 if (tstart == badAddress) return true; // smashed by set_blob(NULL) | 832 if (tstart == badAddress) return true; // smashed by set_blob(NULL) |
842 address tend = tstart + _total_size; | 833 address tend = tstart + _total_size; |
843 if (_blob != NULL) { | 834 if (_blob != NULL) { |
844 assert(tstart >= _blob->instructions_begin(), "sanity"); | 835 assert(tstart >= _blob->content_begin(), "sanity"); |
845 assert(tend <= _blob->instructions_end(), "sanity"); | 836 assert(tend <= _blob->content_end(), "sanity"); |
846 } | 837 } |
847 address tcheck = tstart; // advancing pointer to verify disjointness | 838 // Verify disjointness. |
848 for (int n = 0; n < (int)SECT_LIMIT; n++) { | 839 for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) { |
849 CodeSection* sect = code_section(n); | 840 CodeSection* sect = code_section(n); |
850 if (!sect->is_allocated()) continue; | 841 if (!sect->is_allocated() || sect->is_empty()) continue; |
851 assert(sect->start() >= tcheck, "sanity"); | 842 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, | 843 || sect->is_empty() || _blob == NULL, |
855 "start is aligned"); | 844 "start is aligned"); |
856 assert(sect->end() >= tcheck, "sanity"); | 845 for (int m = (int) SECT_FIRST; m < (int) SECT_LIMIT; m++) { |
857 assert(sect->end() <= tend, "sanity"); | 846 CodeSection* other = code_section(m); |
847 if (!other->is_allocated() || other == sect) continue; | |
848 assert(!other->contains(sect->start() ), "sanity"); | |
849 // limit is an exclusive address and can be the start of another | |
850 // section. | |
851 assert(!other->contains(sect->limit() - 1), "sanity"); | |
852 } | |
853 assert(sect->end() <= tend, "sanity"); | |
858 } | 854 } |
859 return true; | 855 return true; |
860 } | 856 } |
861 #endif //ASSERT | 857 #endif //ASSERT |
862 | 858 |
976 } | 972 } |
977 | 973 |
978 | 974 |
979 | 975 |
980 void CodeBuffer::decode() { | 976 void CodeBuffer::decode() { |
981 Disassembler::decode(decode_begin(), code_end()); | 977 Disassembler::decode(decode_begin(), insts_end()); |
982 _decode_begin = code_end(); | 978 _decode_begin = insts_end(); |
983 } | 979 } |
984 | 980 |
985 | 981 |
986 void CodeBuffer::skip_decode() { | 982 void CodeBuffer::skip_decode() { |
987 _decode_begin = code_end(); | 983 _decode_begin = insts_end(); |
988 } | 984 } |
989 | 985 |
990 | 986 |
991 void CodeBuffer::decode_all() { | 987 void CodeBuffer::decode_all() { |
992 for (int n = 0; n < (int)SECT_LIMIT; n++) { | 988 for (int n = 0; n < (int)SECT_LIMIT; n++) { |