Mercurial > hg > graal-jvmci-8
comparison src/share/vm/asm/codeBuffer.cpp @ 4137:04b9a2566eec
Merge with hsx23/hotspot.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Sat, 17 Dec 2011 21:40:27 +0100 |
parents | e88293edf07c 44ce519bc3d1 |
children | 957c266d8bc5 |
comparison
equal
deleted
inserted
replaced
3737:9dc19b7d89a3 | 4137:04b9a2566eec |
---|---|
24 | 24 |
25 #include "precompiled.hpp" | 25 #include "precompiled.hpp" |
26 #include "asm/codeBuffer.hpp" | 26 #include "asm/codeBuffer.hpp" |
27 #include "compiler/disassembler.hpp" | 27 #include "compiler/disassembler.hpp" |
28 #include "utilities/copy.hpp" | 28 #include "utilities/copy.hpp" |
29 #include "utilities/xmlstream.hpp" | |
29 | 30 |
30 // The structure of a CodeSection: | 31 // The structure of a CodeSection: |
31 // | 32 // |
32 // _start -> +----------------+ | 33 // _start -> +----------------+ |
33 // | machine code...| | 34 // | machine code...| |
79 // External buffer, in a predefined CodeBlob. | 80 // External buffer, in a predefined CodeBlob. |
80 // Important: The code_start must be taken exactly, and not realigned. | 81 // Important: The code_start must be taken exactly, and not realigned. |
81 CodeBuffer::CodeBuffer(CodeBlob* blob) { | 82 CodeBuffer::CodeBuffer(CodeBlob* blob) { |
82 initialize_misc("static buffer"); | 83 initialize_misc("static buffer"); |
83 initialize(blob->content_begin(), blob->content_size()); | 84 initialize(blob->content_begin(), blob->content_size()); |
84 assert(verify_section_allocation(), "initial use of buffer OK"); | 85 verify_section_allocation(); |
85 } | 86 } |
86 | 87 |
87 void CodeBuffer::initialize(csize_t code_size, csize_t locs_size) { | 88 void CodeBuffer::initialize(csize_t code_size, csize_t locs_size) { |
88 // Compute maximal alignment. | 89 // Compute maximal alignment. |
89 int align = _insts.alignment(); | 90 int align = _insts.alignment(); |
106 | 107 |
107 if (locs_size != 0) { | 108 if (locs_size != 0) { |
108 _insts.initialize_locs(locs_size / sizeof(relocInfo)); | 109 _insts.initialize_locs(locs_size / sizeof(relocInfo)); |
109 } | 110 } |
110 | 111 |
111 assert(verify_section_allocation(), "initial use of blob is OK"); | 112 verify_section_allocation(); |
112 } | 113 } |
113 | 114 |
114 | 115 |
115 CodeBuffer::~CodeBuffer() { | 116 CodeBuffer::~CodeBuffer() { |
117 verify_section_allocation(); | |
118 | |
116 // If we allocate our code buffer from the CodeCache | 119 // If we allocate our code buffer from the CodeCache |
117 // via a BufferBlob, and it's not permanent, then | 120 // via a BufferBlob, and it's not permanent, then |
118 // free the BufferBlob. | 121 // free the BufferBlob. |
119 // The rest of the memory will be freed when the ResourceObj | 122 // The rest of the memory will be freed when the ResourceObj |
120 // is released. | 123 // is released. |
121 assert(verify_section_allocation(), "final storage configuration still OK"); | |
122 for (CodeBuffer* cb = this; cb != NULL; cb = cb->before_expand()) { | 124 for (CodeBuffer* cb = this; cb != NULL; cb = cb->before_expand()) { |
123 // Previous incarnations of this buffer are held live, so that internal | 125 // Previous incarnations of this buffer are held live, so that internal |
124 // addresses constructed before expansions will not be confused. | 126 // addresses constructed before expansions will not be confused. |
125 cb->free_blob(); | 127 cb->free_blob(); |
126 } | 128 } |
482 buf_offset += csize; | 484 buf_offset += csize; |
483 } | 485 } |
484 | 486 |
485 // Done calculating sections; did it come out to the right end? | 487 // Done calculating sections; did it come out to the right end? |
486 assert(buf_offset == total_content_size(), "sanity"); | 488 assert(buf_offset == total_content_size(), "sanity"); |
487 assert(dest->verify_section_allocation(), "final configuration works"); | 489 dest->verify_section_allocation(); |
488 } | 490 } |
489 | 491 |
490 csize_t CodeBuffer::total_offset_of(CodeSection* cs) const { | 492 csize_t CodeBuffer::total_offset_of(CodeSection* cs) const { |
491 csize_t size_so_far = 0; | 493 csize_t size_so_far = 0; |
492 for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) { | 494 for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) { |
630 // relocs to repair embedded addresses. The layout in the destination | 632 // relocs to repair embedded addresses. The layout in the destination |
631 // CodeBuffer is different to the source CodeBuffer: the destination | 633 // CodeBuffer is different to the source CodeBuffer: the destination |
632 // CodeBuffer gets the final layout (consts, insts, stubs in order of | 634 // CodeBuffer gets the final layout (consts, insts, stubs in order of |
633 // ascending address). | 635 // ascending address). |
634 void CodeBuffer::relocate_code_to(CodeBuffer* dest) const { | 636 void CodeBuffer::relocate_code_to(CodeBuffer* dest) const { |
635 DEBUG_ONLY(address dest_end = dest->_total_start + dest->_total_size); | 637 address dest_end = dest->_total_start + dest->_total_size; |
638 address dest_filled = NULL; | |
636 for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) { | 639 for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) { |
637 // pull code out of each section | 640 // pull code out of each section |
638 const CodeSection* cs = code_section(n); | 641 const CodeSection* cs = code_section(n); |
639 if (cs->is_empty()) continue; // skip trivial section | 642 if (cs->is_empty()) continue; // skip trivial section |
640 CodeSection* dest_cs = dest->code_section(n); | 643 CodeSection* dest_cs = dest->code_section(n); |
652 // Destination is a final resting place, not just another buffer. | 655 // Destination is a final resting place, not just another buffer. |
653 // Normalize uninitialized bytes in the final padding. | 656 // Normalize uninitialized bytes in the final padding. |
654 Copy::fill_to_bytes(dest_cs->end(), dest_cs->remaining(), | 657 Copy::fill_to_bytes(dest_cs->end(), dest_cs->remaining(), |
655 Assembler::code_fill_byte()); | 658 Assembler::code_fill_byte()); |
656 } | 659 } |
660 // Keep track of the highest filled address | |
661 dest_filled = MAX2(dest_filled, dest_cs->end() + dest_cs->remaining()); | |
657 | 662 |
658 assert(cs->locs_start() != (relocInfo*)badAddress, | 663 assert(cs->locs_start() != (relocInfo*)badAddress, |
659 "this section carries no reloc storage, but reloc was attempted"); | 664 "this section carries no reloc storage, but reloc was attempted"); |
660 | 665 |
661 // Make the new code copy use the old copy's relocations: | 666 // Make the new code copy use the old copy's relocations: |
665 RelocIterator iter(dest_cs); | 670 RelocIterator iter(dest_cs); |
666 while (iter.next()) { | 671 while (iter.next()) { |
667 iter.reloc()->fix_relocation_after_move(this, dest); | 672 iter.reloc()->fix_relocation_after_move(this, dest); |
668 } | 673 } |
669 } | 674 } |
675 } | |
676 | |
677 if (dest->blob() == NULL) { | |
678 // Destination is a final resting place, not just another buffer. | |
679 // Normalize uninitialized bytes in the final padding. | |
680 Copy::fill_to_bytes(dest_filled, dest_end - dest_filled, | |
681 Assembler::code_fill_byte()); | |
682 | |
670 } | 683 } |
671 } | 684 } |
672 | 685 |
673 csize_t CodeBuffer::figure_expanded_capacities(CodeSection* which_cs, | 686 csize_t CodeBuffer::figure_expanded_capacities(CodeSection* which_cs, |
674 csize_t amount, | 687 csize_t amount, |
797 badCodeHeapFreeVal)); | 810 badCodeHeapFreeVal)); |
798 | 811 |
799 _decode_begin = NULL; // sanity | 812 _decode_begin = NULL; // sanity |
800 | 813 |
801 // Make certain that the new sections are all snugly inside the new blob. | 814 // Make certain that the new sections are all snugly inside the new blob. |
802 assert(verify_section_allocation(), "expanded allocation is ship-shape"); | 815 verify_section_allocation(); |
803 | 816 |
804 #ifndef PRODUCT | 817 #ifndef PRODUCT |
805 if (PrintNMethods && (WizardMode || Verbose)) { | 818 if (PrintNMethods && (WizardMode || Verbose)) { |
806 tty->print("expanded CodeBuffer:"); | 819 tty->print("expanded CodeBuffer:"); |
807 this->print(); | 820 this->print(); |
826 _overflow_arena = cb->_overflow_arena; | 839 _overflow_arena = cb->_overflow_arena; |
827 // Make sure the old cb won't try to use it or free it. | 840 // Make sure the old cb won't try to use it or free it. |
828 DEBUG_ONLY(cb->_blob = (BufferBlob*)badAddress); | 841 DEBUG_ONLY(cb->_blob = (BufferBlob*)badAddress); |
829 } | 842 } |
830 | 843 |
831 #ifdef ASSERT | 844 void CodeBuffer::verify_section_allocation() { |
832 bool CodeBuffer::verify_section_allocation() { | |
833 address tstart = _total_start; | 845 address tstart = _total_start; |
834 if (tstart == badAddress) return true; // smashed by set_blob(NULL) | 846 if (tstart == badAddress) return; // smashed by set_blob(NULL) |
835 address tend = tstart + _total_size; | 847 address tend = tstart + _total_size; |
836 if (_blob != NULL) { | 848 if (_blob != NULL) { |
837 assert(tstart >= _blob->content_begin(), "sanity"); | 849 |
838 assert(tend <= _blob->content_end(), "sanity"); | 850 guarantee(tstart >= _blob->content_begin(), "sanity"); |
851 guarantee(tend <= _blob->content_end(), "sanity"); | |
839 } | 852 } |
840 // Verify disjointness. | 853 // Verify disjointness. |
841 for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) { | 854 for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) { |
842 CodeSection* sect = code_section(n); | 855 CodeSection* sect = code_section(n); |
843 if (!sect->is_allocated() || sect->is_empty()) continue; | 856 if (!sect->is_allocated() || sect->is_empty()) continue; |
844 assert((intptr_t)sect->start() % sect->alignment() == 0 | 857 guarantee((intptr_t)sect->start() % sect->alignment() == 0 |
845 || sect->is_empty() || _blob == NULL, | 858 || sect->is_empty() || _blob == NULL, |
846 "start is aligned"); | 859 "start is aligned"); |
847 for (int m = (int) SECT_FIRST; m < (int) SECT_LIMIT; m++) { | 860 for (int m = (int) SECT_FIRST; m < (int) SECT_LIMIT; m++) { |
848 CodeSection* other = code_section(m); | 861 CodeSection* other = code_section(m); |
849 if (!other->is_allocated() || other == sect) continue; | 862 if (!other->is_allocated() || other == sect) continue; |
850 assert(!other->contains(sect->start() ), "sanity"); | 863 guarantee(!other->contains(sect->start() ), "sanity"); |
851 // limit is an exclusive address and can be the start of another | 864 // limit is an exclusive address and can be the start of another |
852 // section. | 865 // section. |
853 assert(!other->contains(sect->limit() - 1), "sanity"); | 866 guarantee(!other->contains(sect->limit() - 1), "sanity"); |
854 } | 867 } |
855 assert(sect->end() <= tend, "sanity"); | 868 guarantee(sect->end() <= tend, "sanity"); |
856 } | 869 guarantee(sect->end() <= sect->limit(), "sanity"); |
857 return true; | 870 } |
858 } | 871 } |
859 #endif //ASSERT | 872 |
873 void CodeBuffer::log_section_sizes(const char* name) { | |
874 if (xtty != NULL) { | |
875 // log info about buffer usage | |
876 xtty->print_cr("<blob name='%s' size='%d'>", name, _total_size); | |
877 for (int n = (int) CodeBuffer::SECT_FIRST; n < (int) CodeBuffer::SECT_LIMIT; n++) { | |
878 CodeSection* sect = code_section(n); | |
879 if (!sect->is_allocated() || sect->is_empty()) continue; | |
880 xtty->print_cr("<sect index='%d' size='" SIZE_FORMAT "' free='" SIZE_FORMAT "'/>", | |
881 n, sect->limit() - sect->start(), sect->limit() - sect->end()); | |
882 } | |
883 xtty->print_cr("</blob>"); | |
884 } | |
885 } | |
860 | 886 |
861 #ifndef PRODUCT | 887 #ifndef PRODUCT |
862 | 888 |
863 void CodeSection::dump() { | 889 void CodeSection::dump() { |
864 address ptr = start(); | 890 address ptr = start(); |
881 | 907 |
882 | 908 |
883 void CodeBuffer::block_comment(intptr_t offset, const char * comment) { | 909 void CodeBuffer::block_comment(intptr_t offset, const char * comment) { |
884 _comments.add_comment(offset, comment); | 910 _comments.add_comment(offset, comment); |
885 } | 911 } |
886 | |
887 | 912 |
888 class CodeComment: public CHeapObj { | 913 class CodeComment: public CHeapObj { |
889 private: | 914 private: |
890 friend class CodeComments; | 915 friend class CodeComments; |
891 intptr_t _offset; | 916 intptr_t _offset; |