< prev index next >

src/hotspot/share/asm/codeBuffer.cpp

Print this page

  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  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 "asm/codeBuffer.hpp"
  26 #include "code/compiledIC.hpp"
  27 #include "code/oopRecorder.inline.hpp"
  28 #include "compiler/disassembler.hpp"
  29 #include "logging/log.hpp"
  30 #include "oops/klass.inline.hpp"

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

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

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

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

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







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

  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  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 "asm/codeBuffer.hpp"
  26 #include "code/compiledIC.hpp"
  27 #include "code/oopRecorder.inline.hpp"
  28 #include "compiler/disassembler.hpp"
  29 #include "logging/log.hpp"
  30 #include "oops/klass.inline.hpp"
  31 #include "oops/methodCounters.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_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

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

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

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

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