< 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 "asm/codeBuffer.hpp"
  26 #include "code/aotCodeCache.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++) {

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

1087     cs->print_on(st, code_section_name(n));
1088   }
1089 }
1090 
1091 CHeapString::~CHeapString() {
1092   os::free((void*)_string);
1093   _string = nullptr;
1094 }
1095 
1096 // ----- AsmRemarks ------------------------------------------------------------
1097 //
1098 // Acting as interface to reference counted mapping [offset -> remark], where
1099 // offset is a byte offset into an instruction stream (CodeBuffer, CodeBlob or
1100 // other memory buffer) and remark is a string (comment).
1101 //
1102 AsmRemarks::AsmRemarks() : _remarks(new AsmRemarkCollection()) {
1103   assert(_remarks != nullptr, "Allocation failure!");
1104 }
1105 
1106 AsmRemarks::~AsmRemarks() {



1107   assert(_remarks == nullptr, "Must 'clear()' before deleting!");
1108 }
1109 




1110 const char* AsmRemarks::insert(uint offset, const char* remstr) {
1111   precond(remstr != nullptr);
1112   return _remarks->insert(offset, remstr);
1113 }
1114 
1115 bool AsmRemarks::is_empty() const {
1116   return _remarks->is_empty();
1117 }
1118 
1119 void AsmRemarks::share(const AsmRemarks &src) {
1120   precond(_remarks == nullptr || is_empty());
1121   clear();
1122   _remarks = src._remarks->reuse();
1123 }
1124 
1125 void AsmRemarks::clear() {
1126   if (_remarks != nullptr && _remarks->clear() == 0) {
1127     delete _remarks;
1128   }
1129   _remarks = nullptr;

1139     // Don't interpret as format strings since it could contain '%'.
1140     strm->print_raw(remstr);
1141     // Advance to next line iff string didn't contain a cr() at the end.
1142     strm->bol();
1143     remstr = _remarks->next(offset);
1144     count++;
1145   }
1146   return count;
1147 }
1148 
1149 // ----- DbgStrings ------------------------------------------------------------
1150 //
1151 // Acting as interface to reference counted collection of (debug) strings used
1152 // in the code generated, and thus requiring a fixed address.
1153 //
1154 DbgStrings::DbgStrings() : _strings(new DbgStringCollection()) {
1155   assert(_strings != nullptr, "Allocation failure!");
1156 }
1157 
1158 DbgStrings::~DbgStrings() {



1159   assert(_strings == nullptr, "Must 'clear()' before deleting!");
1160 }
1161 




1162 const char* DbgStrings::insert(const char* dbgstr) {
1163   const char* str = _strings->lookup(dbgstr);
1164   return str != nullptr ? str : _strings->insert(dbgstr);
1165 }
1166 
1167 bool DbgStrings::is_empty() const {
1168   return _strings->is_empty();
1169 }
1170 
1171 void DbgStrings::share(const DbgStrings &src) {
1172   precond(_strings == nullptr || is_empty());
1173   clear();
1174   _strings = src._strings->reuse();
1175 }
1176 
1177 void DbgStrings::clear() {
1178   if (_strings != nullptr && _strings->clear() == 0) {
1179     delete _strings;
1180   }
1181   _strings = nullptr;

  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/aotCodeCache.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++) {

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

1094     cs->print_on(st, code_section_name(n));
1095   }
1096 }
1097 
1098 CHeapString::~CHeapString() {
1099   os::free((void*)_string);
1100   _string = nullptr;
1101 }
1102 
1103 // ----- AsmRemarks ------------------------------------------------------------
1104 //
1105 // Acting as interface to reference counted mapping [offset -> remark], where
1106 // offset is a byte offset into an instruction stream (CodeBuffer, CodeBlob or
1107 // other memory buffer) and remark is a string (comment).
1108 //
1109 AsmRemarks::AsmRemarks() : _remarks(new AsmRemarkCollection()) {
1110   assert(_remarks != nullptr, "Allocation failure!");
1111 }
1112 
1113 AsmRemarks::~AsmRemarks() {
1114   if (_remarks != nullptr) {
1115     clear();
1116   }
1117   assert(_remarks == nullptr, "Must 'clear()' before deleting!");
1118 }
1119 
1120 void AsmRemarks::init(AsmRemarks& asm_remarks) {
1121   asm_remarks._remarks = new AsmRemarkCollection();
1122 }
1123 
1124 const char* AsmRemarks::insert(uint offset, const char* remstr) {
1125   precond(remstr != nullptr);
1126   return _remarks->insert(offset, remstr);
1127 }
1128 
1129 bool AsmRemarks::is_empty() const {
1130   return _remarks->is_empty();
1131 }
1132 
1133 void AsmRemarks::share(const AsmRemarks &src) {
1134   precond(_remarks == nullptr || is_empty());
1135   clear();
1136   _remarks = src._remarks->reuse();
1137 }
1138 
1139 void AsmRemarks::clear() {
1140   if (_remarks != nullptr && _remarks->clear() == 0) {
1141     delete _remarks;
1142   }
1143   _remarks = nullptr;

1153     // Don't interpret as format strings since it could contain '%'.
1154     strm->print_raw(remstr);
1155     // Advance to next line iff string didn't contain a cr() at the end.
1156     strm->bol();
1157     remstr = _remarks->next(offset);
1158     count++;
1159   }
1160   return count;
1161 }
1162 
1163 // ----- DbgStrings ------------------------------------------------------------
1164 //
1165 // Acting as interface to reference counted collection of (debug) strings used
1166 // in the code generated, and thus requiring a fixed address.
1167 //
1168 DbgStrings::DbgStrings() : _strings(new DbgStringCollection()) {
1169   assert(_strings != nullptr, "Allocation failure!");
1170 }
1171 
1172 DbgStrings::~DbgStrings() {
1173   if (_strings != nullptr) {
1174     clear();
1175   }
1176   assert(_strings == nullptr, "Must 'clear()' before deleting!");
1177 }
1178 
1179 void DbgStrings::init(DbgStrings& dbg_strings) {
1180   dbg_strings._strings = new DbgStringCollection();
1181 }
1182 
1183 const char* DbgStrings::insert(const char* dbgstr) {
1184   const char* str = _strings->lookup(dbgstr);
1185   return str != nullptr ? str : _strings->insert(dbgstr);
1186 }
1187 
1188 bool DbgStrings::is_empty() const {
1189   return _strings->is_empty();
1190 }
1191 
1192 void DbgStrings::share(const DbgStrings &src) {
1193   precond(_strings == nullptr || is_empty());
1194   clear();
1195   _strings = src._strings->reuse();
1196 }
1197 
1198 void DbgStrings::clear() {
1199   if (_strings != nullptr && _strings->clear() == 0) {
1200     delete _strings;
1201   }
1202   _strings = nullptr;
< prev index next >