< 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 ->           |                |

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



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

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

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

 933   // some internal addresses, _last_insn _last_label, are used during code emission,
 934   // adjust them in expansion
 935   adjust_internal_address(insts_begin(), cb.insts_begin());
 936 
 937   // Copy the temporary code buffer into the current code buffer.
 938   // Basically, do {*this = cb}, except for some control information.
 939   this->take_over_code_from(&cb);
 940   cb.set_blob(nullptr);
 941 
 942   // Zap the old code buffer contents, to avoid mistakenly using them.
 943   debug_only(Copy::fill_to_bytes(bxp->_total_start, bxp->_total_size,
 944                                  badCodeHeapFreeVal);)
 945 
 946   // Make certain that the new sections are all snugly inside the new blob.
 947   debug_only(verify_section_allocation();)
 948 
 949 #ifndef PRODUCT
 950   _decode_begin = nullptr;  // sanity
 951   if (PrintNMethods && (WizardMode || Verbose)) {
 952     tty->print("expanded CodeBuffer:");
 953     this->print();
 954   }
 955 #endif //PRODUCT
 956 }
 957 
 958 void CodeBuffer::adjust_internal_address(address from, address to) {
 959   if (_last_insn != nullptr) {
 960     _last_insn += to - from;
 961   }
 962   if (_last_label != nullptr) {
 963     _last_label += to - from;
 964   }
 965 }
 966 
 967 void CodeBuffer::take_over_code_from(CodeBuffer* cb) {
 968   // Must already have disposed of the old blob somehow.
 969   assert(blob() == nullptr, "must be empty");
 970   // Take the new blob away from cb.
 971   set_blob(cb->blob());
 972   // Take over all the section pointers.
 973   for (int n = 0; n < (int)SECT_LIMIT; n++) {

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

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







1077   for (int n = 0; n < (int)SECT_LIMIT; n++) {
1078     // print each section
1079     CodeSection* cs = code_section(n);
1080     cs->print(code_section_name(n));
1081   }
1082 }
1083 
1084 // ----- CHeapString -----------------------------------------------------------
1085 
1086 class CHeapString : public CHeapObj<mtCode> {
1087  public:
1088   CHeapString(const char* str) : _string(os::strdup(str)) {}
1089  ~CHeapString() {
1090     os::free((void*)_string);
1091     _string = nullptr;
1092   }
1093   const char* string() const { return _string; }
1094 
1095  private:
1096   const char* _string;
1097 };
1098 
1099 // ----- AsmRemarkCollection ---------------------------------------------------
1100 

  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 ->           |                |

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

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

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

 940   // some internal addresses, _last_insn _last_label, are used during code emission,
 941   // adjust them in expansion
 942   adjust_internal_address(insts_begin(), cb.insts_begin());
 943 
 944   // Copy the temporary code buffer into the current code buffer.
 945   // Basically, do {*this = cb}, except for some control information.
 946   this->take_over_code_from(&cb);
 947   cb.set_blob(nullptr);
 948 
 949   // Zap the old code buffer contents, to avoid mistakenly using them.
 950   debug_only(Copy::fill_to_bytes(bxp->_total_start, bxp->_total_size,
 951                                  badCodeHeapFreeVal);)
 952 
 953   // Make certain that the new sections are all snugly inside the new blob.
 954   debug_only(verify_section_allocation();)
 955 
 956 #ifndef PRODUCT
 957   _decode_begin = nullptr;  // sanity
 958   if (PrintNMethods && (WizardMode || Verbose)) {
 959     tty->print("expanded CodeBuffer:");
 960     this->print_on(tty);
 961   }
 962 #endif //PRODUCT
 963 }
 964 
 965 void CodeBuffer::adjust_internal_address(address from, address to) {
 966   if (_last_insn != nullptr) {
 967     _last_insn += to - from;
 968   }
 969   if (_last_label != nullptr) {
 970     _last_label += to - from;
 971   }
 972 }
 973 
 974 void CodeBuffer::take_over_code_from(CodeBuffer* cb) {
 975   // Must already have disposed of the old blob somehow.
 976   assert(blob() == nullptr, "must be empty");
 977   // Take the new blob away from cb.
 978   set_blob(cb->blob());
 979   // Take over all the section pointers.
 980   for (int n = 0; n < (int)SECT_LIMIT; n++) {

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

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