< prev index next >

src/hotspot/share/asm/codeBuffer.cpp

Print this page

  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  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,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "asm/codeBuffer.hpp"
  27 #include "code/compiledIC.hpp"
  28 #include "code/oopRecorder.inline.hpp"
  29 #include "compiler/disassembler.hpp"
  30 #include "logging/log.hpp"
  31 #include "oops/klass.inline.hpp"

  32 #include "oops/methodData.hpp"
  33 #include "oops/oop.inline.hpp"
  34 #include "runtime/icache.hpp"
  35 #include "runtime/safepointVerifiers.hpp"
  36 #include "utilities/align.hpp"
  37 #include "utilities/copy.hpp"
  38 #include "utilities/powerOfTwo.hpp"
  39 #include "utilities/xmlstream.hpp"
  40 
  41 // The structure of a CodeSection:
  42 //
  43 //    _start ->           +----------------+
  44 //                        | machine code...|
  45 //    _end ->             |----------------|
  46 //                        |                |
  47 //                        |    (empty)     |
  48 //                        |                |
  49 //                        |                |
  50 //                        +----------------+
  51 //    _limit ->           |                |

 519 void CodeBuffer::finalize_oop_references(const methodHandle& mh) {
 520   NoSafepointVerifier nsv;
 521 
 522   GrowableArray<oop> oops;
 523 
 524   // Make sure that immediate metadata records something in the OopRecorder
 525   for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) {
 526     // pull code out of each section
 527     CodeSection* cs = code_section(n);
 528     if (cs->is_empty() || !cs->has_locs()) continue;  // skip trivial section
 529     RelocIterator iter(cs);
 530     while (iter.next()) {
 531       if (iter.type() == relocInfo::metadata_type) {
 532         metadata_Relocation* md = iter.metadata_reloc();
 533         if (md->metadata_is_immediate()) {
 534           Metadata* m = md->metadata_value();
 535           if (oop_recorder()->is_real(m)) {
 536             if (m->is_methodData()) {
 537               m = ((MethodData*)m)->method();
 538             }



 539             if (m->is_method()) {
 540               m = ((Method*)m)->method_holder();
 541             }
 542             if (m->is_klass()) {
 543               append_oop_references(&oops, (Klass*)m);
 544             } else {
 545               // XXX This will currently occur for MDO which don't
 546               // have a backpointer.  This has to be fixed later.
 547               m->print();
 548               ShouldNotReachHere();
 549             }
 550           }
 551         }
 552       }
 553     }
 554   }
 555 
 556   if (!oop_recorder()->is_unused()) {
 557     for (int i = 0; i < oop_recorder()->metadata_count(); i++) {
 558       Metadata* m = oop_recorder()->metadata_at(i);
 559       if (oop_recorder()->is_real(m)) {
 560         if (m->is_methodData()) {
 561           m = ((MethodData*)m)->method();
 562         }



 563         if (m->is_method()) {
 564           m = ((Method*)m)->method_holder();
 565         }
 566         if (m->is_klass()) {
 567           append_oop_references(&oops, (Klass*)m);
 568         } else {
 569           m->print();
 570           ShouldNotReachHere();
 571         }
 572       }
 573     }
 574 
 575   }
 576 
 577   // Add the class loader of Method* for the nmethod itself
 578   append_oop_references(&oops, mh->method_holder());
 579 
 580   // Add any oops that we've found
 581   Thread* thread = Thread::current();
 582   for (int i = 0; i < oops.length(); i++) {

 705 csize_t CodeBuffer::copy_relocations_to(CodeBlob* dest) const {
 706   address buf = nullptr;
 707   csize_t buf_offset = 0;
 708   csize_t buf_limit = 0;
 709 
 710   if (dest != nullptr) {
 711     buf = (address)dest->relocation_begin();
 712     buf_limit = (address)dest->relocation_end() - buf;
 713   }
 714   // if dest is null, this is just the sizing pass
 715   //
 716   buf_offset = copy_relocations_to(buf, buf_limit, false);
 717 
 718   return buf_offset;
 719 }
 720 
 721 void CodeBuffer::copy_code_to(CodeBlob* dest_blob) {
 722 #ifndef PRODUCT
 723   if (PrintNMethods && (WizardMode || Verbose)) {
 724     tty->print("done with CodeBuffer:");
 725     ((CodeBuffer*)this)->print();
 726   }
 727 #endif //PRODUCT
 728 
 729   CodeBuffer dest(dest_blob);
 730   assert(dest_blob->content_size() >= total_content_size(), "good sizing");
 731   this->compute_final_layout(&dest);
 732 
 733   // Set beginning of constant table before relocating.
 734   dest_blob->set_ctable_begin(dest.consts()->start());
 735 
 736   relocate_code_to(&dest);
 737 
 738   // Share assembly remarks and debug strings with the blob.
 739   NOT_PRODUCT(dest_blob->use_remarks(_asm_remarks));
 740   NOT_PRODUCT(dest_blob->use_strings(_dbg_strings));
 741 
 742   // Done moving code bytes; were they the right size?
 743   assert((int)align_up(dest.total_content_size(), oopSize) == dest_blob->content_size(), "sanity");
 744 
 745   // Flush generated code

 846       exp = 0;
 847     }
 848     // Allow for inter-section slop:
 849     exp += CodeSection::end_slop();
 850     csize_t new_cap = sect->size() + exp;
 851     if (new_cap < sect->capacity()) {
 852       // No need to expand after all.
 853       new_cap = sect->capacity();
 854     }
 855     new_capacity[n] = new_cap;
 856     new_total_cap += new_cap;
 857   }
 858 
 859   return new_total_cap;
 860 }
 861 
 862 void CodeBuffer::expand(CodeSection* which_cs, csize_t amount) {
 863 #ifndef PRODUCT
 864   if (PrintNMethods && (WizardMode || Verbose)) {
 865     tty->print("expanding CodeBuffer:");
 866     this->print();
 867   }
 868 
 869   if (StressCodeBuffers && blob() != nullptr) {
 870     static int expand_count = 0;
 871     if (expand_count >= 0)  expand_count += 1;
 872     if (expand_count > 100 && is_power_of_2(expand_count)) {
 873       tty->print_cr("StressCodeBuffers: have expanded %d times", expand_count);
 874       // simulate an occasional allocation failure:
 875       free_blob();
 876     }
 877   }
 878 #endif //PRODUCT
 879 
 880   // Resizing must be allowed
 881   {
 882     if (blob() == nullptr)  return;  // caller must check if blob is null
 883   }
 884 
 885   // Figure new capacity for each section.
 886   csize_t new_capacity[SECT_LIMIT];

 929 
 930   // Move all the code and relocations to the new blob:
 931   relocate_code_to(&cb);
 932 
 933   // Copy the temporary code buffer into the current code buffer.
 934   // Basically, do {*this = cb}, except for some control information.
 935   this->take_over_code_from(&cb);
 936   cb.set_blob(nullptr);
 937 
 938   // Zap the old code buffer contents, to avoid mistakenly using them.
 939   debug_only(Copy::fill_to_bytes(bxp->_total_start, bxp->_total_size,
 940                                  badCodeHeapFreeVal);)
 941 
 942   // Make certain that the new sections are all snugly inside the new blob.
 943   debug_only(verify_section_allocation();)
 944 
 945 #ifndef PRODUCT
 946   _decode_begin = nullptr;  // sanity
 947   if (PrintNMethods && (WizardMode || Verbose)) {
 948     tty->print("expanded CodeBuffer:");
 949     this->print();
 950   }
 951 #endif //PRODUCT
 952 }
 953 
 954 void CodeBuffer::take_over_code_from(CodeBuffer* cb) {
 955   // Must already have disposed of the old blob somehow.
 956   assert(blob() == nullptr, "must be empty");
 957   // Take the new blob away from cb.
 958   set_blob(cb->blob());
 959   // Take over all the section pointers.
 960   for (int n = 0; n < (int)SECT_LIMIT; n++) {
 961     CodeSection* cb_sect   = cb->code_section(n);
 962     CodeSection* this_sect = code_section(n);
 963     this_sect->take_over_code_from(cb_sect);
 964   }
 965   _overflow_arena = cb->_overflow_arena;
 966   cb->_overflow_arena = nullptr;
 967   // Make sure the old cb won't try to use it or free it.
 968   DEBUG_ONLY(cb->_blob = (BufferBlob*)badAddress);
 969 }

 974   address tend   = tstart + _total_size;
 975   if (_blob != nullptr) {
 976     guarantee(tstart >= _blob->content_begin(), "sanity");
 977     guarantee(tend   <= _blob->content_end(),   "sanity");
 978   }
 979   // Verify disjointness.
 980   for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) {
 981     CodeSection* sect = code_section(n);
 982     if (!sect->is_allocated() || sect->is_empty()) {
 983       continue;
 984     }
 985     guarantee(_blob == nullptr || is_aligned(sect->start(), sect->alignment()),
 986            "start is aligned");
 987     for (int m = n + 1; m < (int) SECT_LIMIT; m++) {
 988       CodeSection* other = code_section(m);
 989       if (!other->is_allocated() || other == sect) {
 990         continue;
 991       }
 992       guarantee(other->disjoint(sect), "sanity");
 993     }
 994     guarantee(sect->end() <= tend, "sanity");
 995     guarantee(sect->end() <= sect->limit(), "sanity");
 996   }
 997 }
 998 
 999 void CodeBuffer::log_section_sizes(const char* name) {
1000   if (xtty != nullptr) {
1001     ttyLocker ttyl;
1002     // log info about buffer usage
1003     xtty->print_cr("<blob name='%s' total_size='%d'>", name, _total_size);
1004     for (int n = (int) CodeBuffer::SECT_FIRST; n < (int) CodeBuffer::SECT_LIMIT; n++) {
1005       CodeSection* sect = code_section(n);
1006       if (!sect->is_allocated() || sect->is_empty())  continue;
1007       xtty->print_cr("<sect index='%d' capacity='%d' size='%d' remaining='%d'/>",
1008                      n, sect->capacity(), sect->size(), sect->remaining());
1009     }
1010     xtty->print_cr("</blob>");
1011   }
1012 }
1013 
1014 bool CodeBuffer::finalize_stubs() {
1015   // Record size of code before we generate stubs in instructions section
1016   _main_code_size = _insts.size();
1017   if (_finalize_stubs && !pd_finalize_stubs()) {
1018     // stub allocation failure
1019     return false;
1020   }
1021   _finalize_stubs = false;
1022   return true;
1023 }
1024 
1025 void CodeBuffer::shared_stub_to_interp_for(ciMethod* callee, csize_t call_offset) {
1026   if (_shared_stub_to_interp_requests == nullptr) {
1027     _shared_stub_to_interp_requests = new SharedStubToInterpRequests(8);
1028   }
1029   SharedStubToInterpRequest request(callee, call_offset);
1030   _shared_stub_to_interp_requests->push(request);

1034 #ifndef PRODUCT
1035 void CodeBuffer::block_comment(ptrdiff_t offset, const char* comment) {
1036   if (_collect_comments) {
1037     const char* str = _asm_remarks.insert(offset, comment);
1038     postcond(str != comment);
1039   }
1040 }
1041 
1042 const char* CodeBuffer::code_string(const char* str) {
1043   const char* tmp = _dbg_strings.insert(str);
1044   postcond(tmp != str);
1045   return tmp;
1046 }
1047 
1048 void CodeBuffer::decode() {
1049   ttyLocker ttyl;
1050   Disassembler::decode(decode_begin(), insts_end(), tty NOT_PRODUCT(COMMA &asm_remarks()));
1051   _decode_begin = insts_end();
1052 }
1053 
1054 void CodeSection::print(const char* name) {
1055   csize_t locs_size = locs_end() - locs_start();
1056   tty->print_cr(" %7s.code = " PTR_FORMAT " : " PTR_FORMAT " : " PTR_FORMAT " (%d of %d)",
1057                 name, p2i(start()), p2i(end()), p2i(limit()), size(), capacity());
1058   tty->print_cr(" %7s.locs = " PTR_FORMAT " : " PTR_FORMAT " : " PTR_FORMAT " (%d of %d) point=%d",
1059                 name, p2i(locs_start()), p2i(locs_end()), p2i(locs_limit()), locs_size, locs_capacity(), locs_point_off());
1060   if (PrintRelocations) {
1061     RelocIterator iter(this);
1062     iter.print();
1063   }
1064 }
1065 
1066 void CodeBuffer::print() {
1067   tty->print_cr("CodeBuffer:");







1068   for (int n = 0; n < (int)SECT_LIMIT; n++) {
1069     // print each section
1070     CodeSection* cs = code_section(n);
1071     cs->print(code_section_name(n));
1072   }
1073 }
1074 
1075 // ----- CHeapString -----------------------------------------------------------
1076 
1077 class CHeapString : public CHeapObj<mtCode> {
1078  public:
1079   CHeapString(const char* str) : _string(os::strdup(str)) {}
1080  ~CHeapString() {
1081     os::free((void*)_string);
1082     _string = nullptr;
1083   }
1084   const char* string() const { return _string; }
1085 
1086  private:
1087   const char* _string;
1088 };
1089 
1090 // ----- AsmRemarkCollection ---------------------------------------------------
1091 

  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  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,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "asm/codeBuffer.hpp"
  27 #include "code/compiledIC.hpp"
  28 #include "code/oopRecorder.inline.hpp"
  29 #include "compiler/disassembler.hpp"
  30 #include "logging/log.hpp"
  31 #include "oops/klass.inline.hpp"
  32 #include "oops/methodCounters.hpp"
  33 #include "oops/methodData.hpp"
  34 #include "oops/oop.inline.hpp"
  35 #include "runtime/icache.hpp"
  36 #include "runtime/safepointVerifiers.hpp"
  37 #include "utilities/align.hpp"
  38 #include "utilities/copy.hpp"
  39 #include "utilities/powerOfTwo.hpp"
  40 #include "utilities/xmlstream.hpp"
  41 
  42 // The structure of a CodeSection:
  43 //
  44 //    _start ->           +----------------+
  45 //                        | machine code...|
  46 //    _end ->             |----------------|
  47 //                        |                |
  48 //                        |    (empty)     |
  49 //                        |                |
  50 //                        |                |
  51 //                        +----------------+
  52 //    _limit ->           |                |

 520 void CodeBuffer::finalize_oop_references(const methodHandle& mh) {
 521   NoSafepointVerifier nsv;
 522 
 523   GrowableArray<oop> oops;
 524 
 525   // Make sure that immediate metadata records something in the OopRecorder
 526   for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) {
 527     // pull code out of each section
 528     CodeSection* cs = code_section(n);
 529     if (cs->is_empty() || !cs->has_locs()) continue;  // skip trivial section
 530     RelocIterator iter(cs);
 531     while (iter.next()) {
 532       if (iter.type() == relocInfo::metadata_type) {
 533         metadata_Relocation* md = iter.metadata_reloc();
 534         if (md->metadata_is_immediate()) {
 535           Metadata* m = md->metadata_value();
 536           if (oop_recorder()->is_real(m)) {
 537             if (m->is_methodData()) {
 538               m = ((MethodData*)m)->method();
 539             }
 540             if (m->is_methodCounters()) {
 541               m = ((MethodCounters*)m)->method();
 542             }
 543             if (m->is_method()) {
 544               m = ((Method*)m)->method_holder();
 545             }
 546             if (m->is_klass()) {
 547               append_oop_references(&oops, (Klass*)m);
 548             } else {
 549               // XXX This will currently occur for MDO which don't
 550               // have a backpointer.  This has to be fixed later.
 551               m->print();
 552               ShouldNotReachHere();
 553             }
 554           }
 555         }
 556       }
 557     }
 558   }
 559 
 560   if (!oop_recorder()->is_unused()) {
 561     for (int i = 0; i < oop_recorder()->metadata_count(); i++) {
 562       Metadata* m = oop_recorder()->metadata_at(i);
 563       if (oop_recorder()->is_real(m)) {
 564         if (m->is_methodData()) {
 565           m = ((MethodData*)m)->method();
 566         }
 567         if (m->is_methodCounters()) {
 568           m = ((MethodCounters*)m)->method();
 569         }
 570         if (m->is_method()) {
 571           m = ((Method*)m)->method_holder();
 572         }
 573         if (m->is_klass()) {
 574           append_oop_references(&oops, (Klass*)m);
 575         } else {
 576           m->print();
 577           ShouldNotReachHere();
 578         }
 579       }
 580     }
 581 
 582   }
 583 
 584   // Add the class loader of Method* for the nmethod itself
 585   append_oop_references(&oops, mh->method_holder());
 586 
 587   // Add any oops that we've found
 588   Thread* thread = Thread::current();
 589   for (int i = 0; i < oops.length(); i++) {

 712 csize_t CodeBuffer::copy_relocations_to(CodeBlob* dest) const {
 713   address buf = nullptr;
 714   csize_t buf_offset = 0;
 715   csize_t buf_limit = 0;
 716 
 717   if (dest != nullptr) {
 718     buf = (address)dest->relocation_begin();
 719     buf_limit = (address)dest->relocation_end() - buf;
 720   }
 721   // if dest is null, this is just the sizing pass
 722   //
 723   buf_offset = copy_relocations_to(buf, buf_limit, false);
 724 
 725   return buf_offset;
 726 }
 727 
 728 void CodeBuffer::copy_code_to(CodeBlob* dest_blob) {
 729 #ifndef PRODUCT
 730   if (PrintNMethods && (WizardMode || Verbose)) {
 731     tty->print("done with CodeBuffer:");
 732     ((CodeBuffer*)this)->print_on(tty);
 733   }
 734 #endif //PRODUCT
 735 
 736   CodeBuffer dest(dest_blob);
 737   assert(dest_blob->content_size() >= total_content_size(), "good sizing");
 738   this->compute_final_layout(&dest);
 739 
 740   // Set beginning of constant table before relocating.
 741   dest_blob->set_ctable_begin(dest.consts()->start());
 742 
 743   relocate_code_to(&dest);
 744 
 745   // Share assembly remarks and debug strings with the blob.
 746   NOT_PRODUCT(dest_blob->use_remarks(_asm_remarks));
 747   NOT_PRODUCT(dest_blob->use_strings(_dbg_strings));
 748 
 749   // Done moving code bytes; were they the right size?
 750   assert((int)align_up(dest.total_content_size(), oopSize) == dest_blob->content_size(), "sanity");
 751 
 752   // Flush generated code

 853       exp = 0;
 854     }
 855     // Allow for inter-section slop:
 856     exp += CodeSection::end_slop();
 857     csize_t new_cap = sect->size() + exp;
 858     if (new_cap < sect->capacity()) {
 859       // No need to expand after all.
 860       new_cap = sect->capacity();
 861     }
 862     new_capacity[n] = new_cap;
 863     new_total_cap += new_cap;
 864   }
 865 
 866   return new_total_cap;
 867 }
 868 
 869 void CodeBuffer::expand(CodeSection* which_cs, csize_t amount) {
 870 #ifndef PRODUCT
 871   if (PrintNMethods && (WizardMode || Verbose)) {
 872     tty->print("expanding CodeBuffer:");
 873     this->print_on(tty);
 874   }
 875 
 876   if (StressCodeBuffers && blob() != nullptr) {
 877     static int expand_count = 0;
 878     if (expand_count >= 0)  expand_count += 1;
 879     if (expand_count > 100 && is_power_of_2(expand_count)) {
 880       tty->print_cr("StressCodeBuffers: have expanded %d times", expand_count);
 881       // simulate an occasional allocation failure:
 882       free_blob();
 883     }
 884   }
 885 #endif //PRODUCT
 886 
 887   // Resizing must be allowed
 888   {
 889     if (blob() == nullptr)  return;  // caller must check if blob is null
 890   }
 891 
 892   // Figure new capacity for each section.
 893   csize_t new_capacity[SECT_LIMIT];

 936 
 937   // Move all the code and relocations to the new blob:
 938   relocate_code_to(&cb);
 939 
 940   // Copy the temporary code buffer into the current code buffer.
 941   // Basically, do {*this = cb}, except for some control information.
 942   this->take_over_code_from(&cb);
 943   cb.set_blob(nullptr);
 944 
 945   // Zap the old code buffer contents, to avoid mistakenly using them.
 946   debug_only(Copy::fill_to_bytes(bxp->_total_start, bxp->_total_size,
 947                                  badCodeHeapFreeVal);)
 948 
 949   // Make certain that the new sections are all snugly inside the new blob.
 950   debug_only(verify_section_allocation();)
 951 
 952 #ifndef PRODUCT
 953   _decode_begin = nullptr;  // sanity
 954   if (PrintNMethods && (WizardMode || Verbose)) {
 955     tty->print("expanded CodeBuffer:");
 956     this->print_on(tty);
 957   }
 958 #endif //PRODUCT
 959 }
 960 
 961 void CodeBuffer::take_over_code_from(CodeBuffer* cb) {
 962   // Must already have disposed of the old blob somehow.
 963   assert(blob() == nullptr, "must be empty");
 964   // Take the new blob away from cb.
 965   set_blob(cb->blob());
 966   // Take over all the section pointers.
 967   for (int n = 0; n < (int)SECT_LIMIT; n++) {
 968     CodeSection* cb_sect   = cb->code_section(n);
 969     CodeSection* this_sect = code_section(n);
 970     this_sect->take_over_code_from(cb_sect);
 971   }
 972   _overflow_arena = cb->_overflow_arena;
 973   cb->_overflow_arena = nullptr;
 974   // Make sure the old cb won't try to use it or free it.
 975   DEBUG_ONLY(cb->_blob = (BufferBlob*)badAddress);
 976 }

 981   address tend   = tstart + _total_size;
 982   if (_blob != nullptr) {
 983     guarantee(tstart >= _blob->content_begin(), "sanity");
 984     guarantee(tend   <= _blob->content_end(),   "sanity");
 985   }
 986   // Verify disjointness.
 987   for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) {
 988     CodeSection* sect = code_section(n);
 989     if (!sect->is_allocated() || sect->is_empty()) {
 990       continue;
 991     }
 992     guarantee(_blob == nullptr || is_aligned(sect->start(), sect->alignment()),
 993            "start is aligned");
 994     for (int m = n + 1; m < (int) SECT_LIMIT; m++) {
 995       CodeSection* other = code_section(m);
 996       if (!other->is_allocated() || other == sect) {
 997         continue;
 998       }
 999       guarantee(other->disjoint(sect), "sanity");
1000     }
1001     guarantee(sect->end() <= tend, "sanity, sect_end: " PTR_FORMAT " tend: " PTR_FORMAT " size: %d", p2i(sect->end()), p2i(tend), (int)_total_size);
1002     guarantee(sect->end() <= sect->limit(), "sanity, sect_end: " PTR_FORMAT " sect_limit: " PTR_FORMAT, p2i(sect->end()), p2i(sect->limit()));
1003   }
1004 }
1005 
1006 void CodeBuffer::log_section_sizes(const char* name) {
1007   if (xtty != nullptr) {
1008     ttyLocker ttyl;
1009     // log info about buffer usage
1010     xtty->head("blob name='%s' total_size='%d'", name, _total_size);
1011     for (int n = (int) CodeBuffer::SECT_FIRST; n < (int) CodeBuffer::SECT_LIMIT; n++) {
1012       CodeSection* sect = code_section(n);
1013       if (!sect->is_allocated() || sect->is_empty())  continue;
1014       xtty->elem("sect index='%d' capacity='%d' size='%d' remaining='%d'",
1015                  n, sect->capacity(), sect->size(), sect->remaining());
1016     }
1017     xtty->tail("blob");
1018   }
1019 }
1020 
1021 bool CodeBuffer::finalize_stubs() {
1022   // Record size of code before we generate stubs in instructions section
1023   _main_code_size = _insts.size();
1024   if (_finalize_stubs && !pd_finalize_stubs()) {
1025     // stub allocation failure
1026     return false;
1027   }
1028   _finalize_stubs = false;
1029   return true;
1030 }
1031 
1032 void CodeBuffer::shared_stub_to_interp_for(ciMethod* callee, csize_t call_offset) {
1033   if (_shared_stub_to_interp_requests == nullptr) {
1034     _shared_stub_to_interp_requests = new SharedStubToInterpRequests(8);
1035   }
1036   SharedStubToInterpRequest request(callee, call_offset);
1037   _shared_stub_to_interp_requests->push(request);

1041 #ifndef PRODUCT
1042 void CodeBuffer::block_comment(ptrdiff_t offset, const char* comment) {
1043   if (_collect_comments) {
1044     const char* str = _asm_remarks.insert(offset, comment);
1045     postcond(str != comment);
1046   }
1047 }
1048 
1049 const char* CodeBuffer::code_string(const char* str) {
1050   const char* tmp = _dbg_strings.insert(str);
1051   postcond(tmp != str);
1052   return tmp;
1053 }
1054 
1055 void CodeBuffer::decode() {
1056   ttyLocker ttyl;
1057   Disassembler::decode(decode_begin(), insts_end(), tty NOT_PRODUCT(COMMA &asm_remarks()));
1058   _decode_begin = insts_end();
1059 }
1060 
1061 void CodeSection::print_on(outputStream* st, const char* name) {
1062   csize_t locs_size = locs_end() - locs_start();
1063   st->print_cr(" %7s.code = " PTR_FORMAT " : " PTR_FORMAT " : " PTR_FORMAT " (%d of %d)",
1064                name, p2i(start()), p2i(end()), p2i(limit()), size(), capacity());
1065   st->print_cr(" %7s.locs = " PTR_FORMAT " : " PTR_FORMAT " : " PTR_FORMAT " (%d of %d) point=%d",
1066                name, p2i(locs_start()), p2i(locs_end()), p2i(locs_limit()), locs_size, locs_capacity(), locs_point_off());
1067   if (PrintRelocations) {
1068     RelocIterator iter(this);
1069     iter.print_on(st);
1070   }
1071 }
1072 
1073 void CodeBuffer::print_on(outputStream* st) {
1074 #if 0
1075   if (this == nullptr) { // gcc complains 'nonnull' argument 'this' compared to NULL 
1076     st->print_cr("null CodeBuffer pointer");
1077     return;
1078   }
1079 #endif
1080 
1081   st->print_cr("CodeBuffer:%s", name());
1082   for (int n = 0; n < (int)SECT_LIMIT; n++) {
1083     // print each section
1084     CodeSection* cs = code_section(n);
1085     cs->print_on(st, code_section_name(n));
1086   }
1087 }
1088 
1089 // ----- CHeapString -----------------------------------------------------------
1090 
1091 class CHeapString : public CHeapObj<mtCode> {
1092  public:
1093   CHeapString(const char* str) : _string(os::strdup(str)) {}
1094  ~CHeapString() {
1095     os::free((void*)_string);
1096     _string = nullptr;
1097   }
1098   const char* string() const { return _string; }
1099 
1100  private:
1101   const char* _string;
1102 };
1103 
1104 // ----- AsmRemarkCollection ---------------------------------------------------
1105 
< prev index next >