< prev index next >

src/hotspot/share/code/nmethod.cpp

Print this page

 708 
 709   // handle the case of an anchor explicitly set in continuation code that doesn't have a callee
 710   JavaThread* thread = reg_map->thread();
 711   if ((thread->has_last_Java_frame() && fr.sp() == thread->last_Java_sp())
 712       JVMTI_ONLY(|| (method()->is_continuation_enter_intrinsic() && thread->on_monitor_waited_event()))) {
 713     return;
 714   }
 715 
 716   if (!method()->is_native()) {
 717     address pc = fr.pc();
 718     bool has_receiver, has_appendix;
 719     Symbol* signature;
 720 
 721     // The method attached by JIT-compilers should be used, if present.
 722     // Bytecode can be inaccurate in such case.
 723     Method* callee = attached_method_before_pc(pc);
 724     if (callee != nullptr) {
 725       has_receiver = !(callee->access_flags().is_static());
 726       has_appendix = false;
 727       signature    = callee->signature();











 728     } else {
 729       SimpleScopeDesc ssd(this, pc);
 730 
 731       Bytecode_invoke call(methodHandle(Thread::current(), ssd.method()), ssd.bci());
 732       has_receiver = call.has_receiver();
 733       has_appendix = call.has_appendix();
 734       signature    = call.signature();
 735     }
 736 
 737     fr.oops_compiled_arguments_do(signature, has_receiver, has_appendix, reg_map, f);
 738   } else if (method()->is_continuation_enter_intrinsic()) {
 739     // This method only calls Continuation.enter()
 740     Symbol* signature = vmSymbols::continuationEnter_signature();
 741     fr.oops_compiled_arguments_do(signature, false, false, reg_map, f);
 742   }
 743 }
 744 
 745 Method* nmethod::attached_method(address call_instr) {
 746   assert(code_contains(call_instr), "not part of the nmethod");
 747   RelocIterator iter(this, call_instr, call_instr + 1);

1242   _has_unsafe_access          = 0;
1243   _has_method_handle_invokes  = 0;
1244   _has_wide_vectors           = 0;
1245   _has_monitors               = 0;
1246   _has_scoped_access          = 0;
1247   _has_flushed_dependencies   = 0;
1248   _is_unlinked                = 0;
1249   _load_reported              = 0; // jvmti state
1250 
1251   _deoptimization_status      = not_marked;
1252 
1253   // SECT_CONSTS is first in code buffer so the offset should be 0.
1254   int consts_offset = code_buffer->total_offset_of(code_buffer->consts());
1255   assert(consts_offset == 0, "const_offset: %d", consts_offset);
1256 
1257   _stub_offset = content_offset() + code_buffer->total_offset_of(code_buffer->stubs());
1258 
1259   CHECKED_CAST(_entry_offset,              uint16_t, (offsets->value(CodeOffsets::Entry)));
1260   CHECKED_CAST(_verified_entry_offset,     uint16_t, (offsets->value(CodeOffsets::Verified_Entry)));
1261 




1262   _skipped_instructions_size = code_buffer->total_skipped_instructions_size();
1263 }
1264 
1265 // Post initialization
1266 void nmethod::post_init() {
1267   clear_unloading_state();
1268 
1269   finalize_relocations();
1270 
1271   Universe::heap()->register_nmethod(this);
1272   debug_only(Universe::heap()->verify_nmethod(this));
1273 
1274   CodeCache::commit(this);
1275 }
1276 
1277 // For native wrappers
1278 nmethod::nmethod(
1279   Method* method,
1280   CompilerType type,
1281   int nmethod_size,
1282   int compile_id,
1283   CodeOffsets* offsets,
1284   CodeBuffer* code_buffer,
1285   int frame_size,
1286   ByteSize basic_lock_owner_sp_offset,
1287   ByteSize basic_lock_sp_offset,
1288   OopMapSet* oop_maps,
1289   int mutable_data_size)
1290   : CodeBlob("native nmethod", CodeBlobKind::Nmethod, code_buffer, nmethod_size, sizeof(nmethod),
1291              offsets->value(CodeOffsets::Frame_Complete), frame_size, oop_maps, false, mutable_data_size),
1292   _deoptimization_generation(0),
1293   _gc_epoch(CodeCache::gc_epoch()),
1294   _method(method),
1295   _native_receiver_sp_offset(basic_lock_owner_sp_offset),
1296   _native_basic_lock_sp_offset(basic_lock_sp_offset)
1297 {
1298   {
1299     debug_only(NoSafepointVerifier nsv;)
1300     assert_locked_or_safepoint(CodeCache_lock);
1301 
1302     init_defaults(code_buffer, offsets);
1303 
1304     _osr_entry_point         = nullptr;
1305     _pc_desc_container       = nullptr;
1306     _entry_bci               = InvocationEntryBci;
1307     _compile_id              = compile_id;
1308     _comp_level              = CompLevel_none;
1309     _compiler_type           = type;
1310     _orig_pc_offset          = 0;
1311     _num_stack_arg_slots     = 0;
1312 
1313     if (offsets->value(CodeOffsets::Exceptions) != -1) {
1314       // Continuation enter intrinsic
1315       _exception_offset      = code_offset() + offsets->value(CodeOffsets::Exceptions);
1316     } else {
1317       _exception_offset      = 0;
1318     }
1319     // Native wrappers do not have deopt handlers. Make the values
1320     // something that will never match a pc like the nmethod vtable entry
1321     _deopt_handler_offset    = 0;

1483       if (offsets->value(CodeOffsets::DeoptMH) != -1) {
1484         _deopt_mh_handler_offset = _stub_offset + offsets->value(CodeOffsets::DeoptMH);
1485       } else {
1486         _deopt_mh_handler_offset = -1;
1487       }
1488     }
1489     if (offsets->value(CodeOffsets::UnwindHandler) != -1) {
1490       // C1 generates UnwindHandler at the end of instructions section.
1491       // Calculate positive offset as distance between the start of stubs section
1492       // (which is also the end of instructions section) and the start of the handler.
1493       int unwind_handler_offset = code_offset() + offsets->value(CodeOffsets::UnwindHandler);
1494       CHECKED_CAST(_unwind_handler_offset, int16_t, (_stub_offset - unwind_handler_offset));
1495     } else {
1496       _unwind_handler_offset = -1;
1497     }
1498 
1499     CHECKED_CAST(_oops_size, uint16_t, align_up(code_buffer->total_oop_size(), oopSize));
1500     uint16_t metadata_size = (uint16_t)align_up(code_buffer->total_metadata_size(), wordSize);
1501     JVMCI_ONLY(CHECKED_CAST(_jvmci_data_size, uint16_t, align_up(compiler->is_jvmci() ? jvmci_data->size() : 0, oopSize)));
1502     int jvmci_data_size = 0 JVMCI_ONLY(+ _jvmci_data_size);



1503     assert(_mutable_data_size == _relocation_size + metadata_size + jvmci_data_size,
1504            "wrong mutable data size: %d != %d + %d + %d",
1505            _mutable_data_size, _relocation_size, metadata_size, jvmci_data_size);
1506     assert(nmethod_size == data_end() - header_begin(), "wrong nmethod size: %d != %d",
1507            nmethod_size, (int)(code_end() - header_begin()));
1508 
1509     _immutable_data_size  = immutable_data_size;
1510     if (immutable_data_size > 0) {
1511       assert(immutable_data != nullptr, "required");
1512       _immutable_data     = immutable_data;
1513     } else {
1514       // We need unique not null address
1515       _immutable_data     = blob_end();
1516     }
1517     CHECKED_CAST(_nul_chk_table_offset, uint16_t, (align_up((int)dependencies->size_in_bytes(), oopSize)));
1518     CHECKED_CAST(_handler_table_offset, uint16_t, (_nul_chk_table_offset + align_up(nul_chk_table->size_in_bytes(), oopSize)));
1519     _scopes_pcs_offset    = _handler_table_offset + align_up(handler_table->size_in_bytes(), oopSize);
1520     _scopes_data_offset   = _scopes_pcs_offset    + adjust_pcs_size(debug_info->pcs_size());
1521 
1522 #if INCLUDE_JVMCI

3685           return st.as_string();
3686         }
3687     }
3688   }
3689   return have_one ? "other" : nullptr;
3690 }
3691 
3692 // Return the last scope in (begin..end]
3693 ScopeDesc* nmethod::scope_desc_in(address begin, address end) {
3694   PcDesc* p = pc_desc_near(begin+1);
3695   if (p != nullptr && p->real_pc(this) <= end) {
3696     return new ScopeDesc(this, p);
3697   }
3698   return nullptr;
3699 }
3700 
3701 const char* nmethod::nmethod_section_label(address pos) const {
3702   const char* label = nullptr;
3703   if (pos == code_begin())                                              label = "[Instructions begin]";
3704   if (pos == entry_point())                                             label = "[Entry Point]";

3705   if (pos == verified_entry_point())                                    label = "[Verified Entry Point]";


3706   if (has_method_handle_invokes() && (pos == deopt_mh_handler_begin())) label = "[Deopt MH Handler Code]";
3707   if (pos == consts_begin() && pos != insts_begin())                    label = "[Constants]";
3708   // Check stub_code before checking exception_handler or deopt_handler.
3709   if (pos == this->stub_begin())                                        label = "[Stub Code]";
3710   if (JVMCI_ONLY(_exception_offset >= 0 &&) pos == exception_begin())          label = "[Exception Handler]";
3711   if (JVMCI_ONLY(_deopt_handler_offset != -1 &&) pos == deopt_handler_begin()) label = "[Deopt Handler Code]";
3712   return label;
3713 }
3714 










3715 void nmethod::print_nmethod_labels(outputStream* stream, address block_begin, bool print_section_labels) const {
3716   if (print_section_labels) {
3717     const char* label = nmethod_section_label(block_begin);
3718     if (label != nullptr) {
3719       stream->bol();
3720       stream->print_cr("%s", label);
3721     }
3722   }
3723 
3724   if (block_begin == entry_point()) {
3725     Method* m = method();
3726     if (m != nullptr) {
3727       stream->print("  # ");
3728       m->print_value_on(stream);
3729       stream->cr();
3730     }
3731     if (m != nullptr && !is_osr_method()) {
3732       ResourceMark rm;
3733       int sizeargs = m->size_of_parameters();
3734       BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sizeargs);
3735       VMRegPair* regs   = NEW_RESOURCE_ARRAY(VMRegPair, sizeargs);
3736       {
3737         int sig_index = 0;
3738         if (!m->is_static())
3739           sig_bt[sig_index++] = T_OBJECT; // 'this'
3740         for (SignatureStream ss(m->signature()); !ss.at_return_type(); ss.next()) {
3741           BasicType t = ss.type();
3742           sig_bt[sig_index++] = t;
3743           if (type2size[t] == 2) {
3744             sig_bt[sig_index++] = T_VOID;
3745           } else {
3746             assert(type2size[t] == 1, "size is 1 or 2");
3747           }
3748         }
3749         assert(sig_index == sizeargs, "");
3750       }
3751       const char* spname = "sp"; // make arch-specific?
3752       SharedRuntime::java_calling_convention(sig_bt, regs, sizeargs);
3753       int stack_slot_offset = this->frame_size() * wordSize;
3754       int tab1 = 14, tab2 = 24;
3755       int sig_index = 0;
3756       int arg_index = (m->is_static() ? 0 : -1);
3757       bool did_old_sp = false;
3758       for (SignatureStream ss(m->signature()); !ss.at_return_type(); ) {
3759         bool at_this = (arg_index == -1);
3760         bool at_old_sp = false;
3761         BasicType t = (at_this ? T_OBJECT : ss.type());
3762         assert(t == sig_bt[sig_index], "sigs in sync");
3763         if (at_this)
3764           stream->print("  # this: ");
3765         else
3766           stream->print("  # parm%d: ", arg_index);
3767         stream->move_to(tab1);
3768         VMReg fst = regs[sig_index].first();
3769         VMReg snd = regs[sig_index].second();
3770         if (fst->is_reg()) {
3771           stream->print("%s", fst->name());
3772           if (snd->is_valid())  {
3773             stream->print(":%s", snd->name());
3774           }
3775         } else if (fst->is_stack()) {
3776           int offset = fst->reg2stack() * VMRegImpl::stack_slot_size + stack_slot_offset;
3777           if (offset == stack_slot_offset)  at_old_sp = true;
3778           stream->print("[%s+0x%x]", spname, offset);
3779         } else {
3780           stream->print("reg%d:%d??", (int)(intptr_t)fst, (int)(intptr_t)snd);
3781         }
3782         stream->print(" ");
3783         stream->move_to(tab2);
3784         stream->print("= ");
3785         if (at_this) {
3786           m->method_holder()->print_value_on(stream);
3787         } else {
3788           bool did_name = false;
3789           if (!at_this && ss.is_reference()) {
3790             Symbol* name = ss.as_symbol();
3791             name->print_value_on(stream);
3792             did_name = true;
3793           }
3794           if (!did_name)
3795             stream->print("%s", type2name(t));
3796         }
3797         if (at_old_sp) {
3798           stream->print("  (%s of caller)", spname);
3799           did_old_sp = true;
3800         }
3801         stream->cr();
3802         sig_index += type2size[t];
3803         arg_index += 1;
3804         if (!at_this)  ss.next();









3805       }
3806       if (!did_old_sp) {
3807         stream->print("  # ");
3808         stream->move_to(tab1);
3809         stream->print("[%s+0x%x]", spname, stack_slot_offset);
3810         stream->print("  (%s of caller)", spname);
3811         stream->cr();


















3812       }
3813     }














3814   }
3815 }
3816 
3817 // Returns whether this nmethod has code comments.
3818 bool nmethod::has_code_comment(address begin, address end) {
3819   // scopes?
3820   ScopeDesc* sd  = scope_desc_in(begin, end);
3821   if (sd != nullptr) return true;
3822 
3823   // relocations?
3824   const char* str = reloc_string_for(begin, end);
3825   if (str != nullptr) return true;
3826 
3827   // implicit exceptions?
3828   int cont_offset = ImplicitExceptionTable(this).continuation_offset((uint)(begin - code_begin()));
3829   if (cont_offset != 0) return true;
3830 
3831   return false;
3832 }
3833 

3917             else
3918               st->print("<UNKNOWN>");
3919             break;
3920           }
3921         case Bytecodes::_getfield:
3922         case Bytecodes::_putfield:
3923         case Bytecodes::_getstatic:
3924         case Bytecodes::_putstatic:
3925           {
3926             Bytecode_field field(methodHandle(thread, sd->method()), sd->bci());
3927             st->print(" ");
3928             if (field.name() != nullptr)
3929               field.name()->print_symbol_on(st);
3930             else
3931               st->print("<UNKNOWN>");
3932           }
3933         default:
3934           break;
3935         }
3936       }
3937       st->print(" {reexecute=%d rethrow=%d return_oop=%d}", sd->should_reexecute(), sd->rethrow_exception(), sd->return_oop());
3938     }
3939 
3940     // Print all scopes
3941     for (;sd != nullptr; sd = sd->sender()) {
3942       st->move_to(column, 6, 0);
3943       st->print("; -");
3944       if (sd->should_reexecute()) {
3945         st->print(" (reexecute)");
3946       }
3947       if (sd->method() == nullptr) {
3948         st->print("method is nullptr");
3949       } else {
3950         sd->method()->print_short_name(st);
3951       }
3952       int lineno = sd->method()->line_number_from_bci(sd->bci());
3953       if (lineno != -1) {
3954         st->print("@%d (line %d)", sd->bci(), lineno);
3955       } else {
3956         st->print("@%d", sd->bci());
3957       }

 708 
 709   // handle the case of an anchor explicitly set in continuation code that doesn't have a callee
 710   JavaThread* thread = reg_map->thread();
 711   if ((thread->has_last_Java_frame() && fr.sp() == thread->last_Java_sp())
 712       JVMTI_ONLY(|| (method()->is_continuation_enter_intrinsic() && thread->on_monitor_waited_event()))) {
 713     return;
 714   }
 715 
 716   if (!method()->is_native()) {
 717     address pc = fr.pc();
 718     bool has_receiver, has_appendix;
 719     Symbol* signature;
 720 
 721     // The method attached by JIT-compilers should be used, if present.
 722     // Bytecode can be inaccurate in such case.
 723     Method* callee = attached_method_before_pc(pc);
 724     if (callee != nullptr) {
 725       has_receiver = !(callee->access_flags().is_static());
 726       has_appendix = false;
 727       signature    = callee->signature();
 728 
 729       // If inline types are passed as fields, use the extended signature
 730       // which contains the types of all (oop) fields of the inline type.
 731       if (is_compiled_by_c2() && callee->has_scalarized_args()) {
 732         const GrowableArray<SigEntry>* sig = callee->adapter()->get_sig_cc();
 733         assert(sig != nullptr, "sig should never be null");
 734         TempNewSymbol tmp_sig = SigEntry::create_symbol(sig);
 735         has_receiver = false; // The extended signature contains the receiver type
 736         fr.oops_compiled_arguments_do(tmp_sig, has_receiver, has_appendix, reg_map, f);
 737         return;
 738       }
 739     } else {
 740       SimpleScopeDesc ssd(this, pc);
 741 
 742       Bytecode_invoke call(methodHandle(Thread::current(), ssd.method()), ssd.bci());
 743       has_receiver = call.has_receiver();
 744       has_appendix = call.has_appendix();
 745       signature    = call.signature();
 746     }
 747 
 748     fr.oops_compiled_arguments_do(signature, has_receiver, has_appendix, reg_map, f);
 749   } else if (method()->is_continuation_enter_intrinsic()) {
 750     // This method only calls Continuation.enter()
 751     Symbol* signature = vmSymbols::continuationEnter_signature();
 752     fr.oops_compiled_arguments_do(signature, false, false, reg_map, f);
 753   }
 754 }
 755 
 756 Method* nmethod::attached_method(address call_instr) {
 757   assert(code_contains(call_instr), "not part of the nmethod");
 758   RelocIterator iter(this, call_instr, call_instr + 1);

1253   _has_unsafe_access          = 0;
1254   _has_method_handle_invokes  = 0;
1255   _has_wide_vectors           = 0;
1256   _has_monitors               = 0;
1257   _has_scoped_access          = 0;
1258   _has_flushed_dependencies   = 0;
1259   _is_unlinked                = 0;
1260   _load_reported              = 0; // jvmti state
1261 
1262   _deoptimization_status      = not_marked;
1263 
1264   // SECT_CONSTS is first in code buffer so the offset should be 0.
1265   int consts_offset = code_buffer->total_offset_of(code_buffer->consts());
1266   assert(consts_offset == 0, "const_offset: %d", consts_offset);
1267 
1268   _stub_offset = content_offset() + code_buffer->total_offset_of(code_buffer->stubs());
1269 
1270   CHECKED_CAST(_entry_offset,              uint16_t, (offsets->value(CodeOffsets::Entry)));
1271   CHECKED_CAST(_verified_entry_offset,     uint16_t, (offsets->value(CodeOffsets::Verified_Entry)));
1272 
1273   _inline_entry_point             = entry_point();
1274   _verified_inline_entry_point    = verified_entry_point();
1275   _verified_inline_ro_entry_point = verified_entry_point();
1276 
1277   _skipped_instructions_size = code_buffer->total_skipped_instructions_size();
1278 }
1279 
1280 // Post initialization
1281 void nmethod::post_init() {
1282   clear_unloading_state();
1283 
1284   finalize_relocations();
1285 
1286   Universe::heap()->register_nmethod(this);
1287   debug_only(Universe::heap()->verify_nmethod(this));
1288 
1289   CodeCache::commit(this);
1290 }
1291 
1292 // For native wrappers
1293 nmethod::nmethod(
1294   Method* method,
1295   CompilerType type,
1296   int nmethod_size,
1297   int compile_id,
1298   CodeOffsets* offsets,
1299   CodeBuffer* code_buffer,
1300   int frame_size,
1301   ByteSize basic_lock_owner_sp_offset,
1302   ByteSize basic_lock_sp_offset,
1303   OopMapSet* oop_maps,
1304   int mutable_data_size)
1305   : CodeBlob("native nmethod", CodeBlobKind::Nmethod, code_buffer, nmethod_size, sizeof(nmethod),
1306              offsets->value(CodeOffsets::Frame_Complete), frame_size, oop_maps, false, mutable_data_size),
1307   _deoptimization_generation(0),
1308   _gc_epoch(CodeCache::gc_epoch()),
1309   _method(method),
1310   _native_receiver_sp_offset(basic_lock_owner_sp_offset),
1311   _native_basic_lock_sp_offset(basic_lock_sp_offset)
1312 {
1313   {
1314     debug_only(NoSafepointVerifier nsv;)
1315     assert_locked_or_safepoint(CodeCache_lock);
1316     assert(!method->has_scalarized_args(), "scalarized native wrappers not supported yet");
1317     init_defaults(code_buffer, offsets);
1318 
1319     _osr_entry_point         = nullptr;
1320     _pc_desc_container       = nullptr;
1321     _entry_bci               = InvocationEntryBci;
1322     _compile_id              = compile_id;
1323     _comp_level              = CompLevel_none;
1324     _compiler_type           = type;
1325     _orig_pc_offset          = 0;
1326     _num_stack_arg_slots     = 0;
1327 
1328     if (offsets->value(CodeOffsets::Exceptions) != -1) {
1329       // Continuation enter intrinsic
1330       _exception_offset      = code_offset() + offsets->value(CodeOffsets::Exceptions);
1331     } else {
1332       _exception_offset      = 0;
1333     }
1334     // Native wrappers do not have deopt handlers. Make the values
1335     // something that will never match a pc like the nmethod vtable entry
1336     _deopt_handler_offset    = 0;

1498       if (offsets->value(CodeOffsets::DeoptMH) != -1) {
1499         _deopt_mh_handler_offset = _stub_offset + offsets->value(CodeOffsets::DeoptMH);
1500       } else {
1501         _deopt_mh_handler_offset = -1;
1502       }
1503     }
1504     if (offsets->value(CodeOffsets::UnwindHandler) != -1) {
1505       // C1 generates UnwindHandler at the end of instructions section.
1506       // Calculate positive offset as distance between the start of stubs section
1507       // (which is also the end of instructions section) and the start of the handler.
1508       int unwind_handler_offset = code_offset() + offsets->value(CodeOffsets::UnwindHandler);
1509       CHECKED_CAST(_unwind_handler_offset, int16_t, (_stub_offset - unwind_handler_offset));
1510     } else {
1511       _unwind_handler_offset = -1;
1512     }
1513 
1514     CHECKED_CAST(_oops_size, uint16_t, align_up(code_buffer->total_oop_size(), oopSize));
1515     uint16_t metadata_size = (uint16_t)align_up(code_buffer->total_metadata_size(), wordSize);
1516     JVMCI_ONLY(CHECKED_CAST(_jvmci_data_size, uint16_t, align_up(compiler->is_jvmci() ? jvmci_data->size() : 0, oopSize)));
1517     int jvmci_data_size = 0 JVMCI_ONLY(+ _jvmci_data_size);
1518     _inline_entry_point             = code_begin() + offsets->value(CodeOffsets::Inline_Entry);
1519     _verified_inline_entry_point    = code_begin() + offsets->value(CodeOffsets::Verified_Inline_Entry);
1520     _verified_inline_ro_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Inline_Entry_RO);
1521     assert(_mutable_data_size == _relocation_size + metadata_size + jvmci_data_size,
1522            "wrong mutable data size: %d != %d + %d + %d",
1523            _mutable_data_size, _relocation_size, metadata_size, jvmci_data_size);
1524     assert(nmethod_size == data_end() - header_begin(), "wrong nmethod size: %d != %d",
1525            nmethod_size, (int)(code_end() - header_begin()));
1526 
1527     _immutable_data_size  = immutable_data_size;
1528     if (immutable_data_size > 0) {
1529       assert(immutable_data != nullptr, "required");
1530       _immutable_data     = immutable_data;
1531     } else {
1532       // We need unique not null address
1533       _immutable_data     = blob_end();
1534     }
1535     CHECKED_CAST(_nul_chk_table_offset, uint16_t, (align_up((int)dependencies->size_in_bytes(), oopSize)));
1536     CHECKED_CAST(_handler_table_offset, uint16_t, (_nul_chk_table_offset + align_up(nul_chk_table->size_in_bytes(), oopSize)));
1537     _scopes_pcs_offset    = _handler_table_offset + align_up(handler_table->size_in_bytes(), oopSize);
1538     _scopes_data_offset   = _scopes_pcs_offset    + adjust_pcs_size(debug_info->pcs_size());
1539 
1540 #if INCLUDE_JVMCI

3703           return st.as_string();
3704         }
3705     }
3706   }
3707   return have_one ? "other" : nullptr;
3708 }
3709 
3710 // Return the last scope in (begin..end]
3711 ScopeDesc* nmethod::scope_desc_in(address begin, address end) {
3712   PcDesc* p = pc_desc_near(begin+1);
3713   if (p != nullptr && p->real_pc(this) <= end) {
3714     return new ScopeDesc(this, p);
3715   }
3716   return nullptr;
3717 }
3718 
3719 const char* nmethod::nmethod_section_label(address pos) const {
3720   const char* label = nullptr;
3721   if (pos == code_begin())                                              label = "[Instructions begin]";
3722   if (pos == entry_point())                                             label = "[Entry Point]";
3723   if (pos == inline_entry_point())                                      label = "[Inline Entry Point]";
3724   if (pos == verified_entry_point())                                    label = "[Verified Entry Point]";
3725   if (pos == verified_inline_entry_point())                             label = "[Verified Inline Entry Point]";
3726   if (pos == verified_inline_ro_entry_point())                          label = "[Verified Inline Entry Point (RO)]";
3727   if (has_method_handle_invokes() && (pos == deopt_mh_handler_begin())) label = "[Deopt MH Handler Code]";
3728   if (pos == consts_begin() && pos != insts_begin())                    label = "[Constants]";
3729   // Check stub_code before checking exception_handler or deopt_handler.
3730   if (pos == this->stub_begin())                                        label = "[Stub Code]";
3731   if (JVMCI_ONLY(_exception_offset >= 0 &&) pos == exception_begin())          label = "[Exception Handler]";
3732   if (JVMCI_ONLY(_deopt_handler_offset != -1 &&) pos == deopt_handler_begin()) label = "[Deopt Handler Code]";
3733   return label;
3734 }
3735 
3736 static int maybe_print_entry_label(outputStream* stream, address pos, address entry, const char* label) {
3737   if (pos == entry) {
3738     stream->bol();
3739     stream->print_cr("%s", label);
3740     return 1;
3741   } else {
3742     return 0;
3743   }
3744 }
3745 
3746 void nmethod::print_nmethod_labels(outputStream* stream, address block_begin, bool print_section_labels) const {
3747   if (print_section_labels) {
3748     int n = 0;
3749     // Multiple entry points may be at the same position. Print them all.
3750     n += maybe_print_entry_label(stream, block_begin, entry_point(),                    "[Entry Point]");
3751     n += maybe_print_entry_label(stream, block_begin, inline_entry_point(),             "[Inline Entry Point]");
3752     n += maybe_print_entry_label(stream, block_begin, verified_entry_point(),           "[Verified Entry Point]");
3753     n += maybe_print_entry_label(stream, block_begin, verified_inline_entry_point(),    "[Verified Inline Entry Point]");
3754     n += maybe_print_entry_label(stream, block_begin, verified_inline_ro_entry_point(), "[Verified Inline Entry Point (RO)]");
3755     if (n == 0) {
3756       const char* label = nmethod_section_label(block_begin);
3757       if (label != nullptr) {
3758         stream->bol();
3759         stream->print_cr("%s", label);





















3760       }
3761     }
3762   }
3763 
3764   Method* m = method();
3765   if (m == nullptr || is_osr_method()) {
3766     return;
3767   }
3768 
3769   // Print the name of the method (only once)
3770   address low = MIN4(entry_point(), verified_entry_point(), verified_inline_entry_point(), verified_inline_ro_entry_point());
3771   low = MIN2(low, inline_entry_point());
3772   assert(low != 0, "sanity");
3773   if (block_begin == low) {
3774     stream->print("  # ");
3775     m->print_value_on(stream);
3776     stream->cr();
3777   }
3778 
3779   // Print the arguments for the 3 types of verified entry points
3780   CompiledEntrySignature ces(m);
3781   ces.compute_calling_conventions(false);
3782   const GrowableArray<SigEntry>* sig_cc;
3783   const VMRegPair* regs;
3784   if (block_begin == verified_entry_point()) {
3785     sig_cc = ces.sig_cc();
3786     regs = ces.regs_cc();
3787   } else if (block_begin == verified_inline_entry_point()) {
3788     sig_cc = ces.sig();
3789     regs = ces.regs();
3790   } else if (block_begin == verified_inline_ro_entry_point()) {
3791     sig_cc = ces.sig_cc_ro();
3792     regs = ces.regs_cc_ro();
3793   } else {
3794     return;
3795   }
3796 
3797   bool has_this = !m->is_static();
3798   if (ces.has_inline_recv() && block_begin == verified_entry_point()) {
3799     // <this> argument is scalarized for verified_entry_point()
3800     has_this = false;
3801   }
3802   const char* spname = "sp"; // make arch-specific?
3803   int stack_slot_offset = this->frame_size() * wordSize;
3804   int tab1 = 14, tab2 = 24;
3805   int sig_index = 0;
3806   int arg_index = has_this ? -1 : 0;
3807   bool did_old_sp = false;
3808   for (ExtendedSignature sig = ExtendedSignature(sig_cc, SigEntryFilter()); !sig.at_end(); ++sig) {
3809     bool at_this = (arg_index == -1);
3810     bool at_old_sp = false;
3811     BasicType t = (*sig)._bt;
3812     if (at_this) {
3813       stream->print("  # this: ");
3814     } else {
3815       stream->print("  # parm%d: ", arg_index);
3816     }
3817     stream->move_to(tab1);
3818     VMReg fst = regs[sig_index].first();
3819     VMReg snd = regs[sig_index].second();
3820     if (fst->is_reg()) {
3821       stream->print("%s", fst->name());
3822       if (snd->is_valid())  {
3823         stream->print(":%s", snd->name());
3824       }
3825     } else if (fst->is_stack()) {
3826       int offset = fst->reg2stack() * VMRegImpl::stack_slot_size + stack_slot_offset;
3827       if (offset == stack_slot_offset)  at_old_sp = true;
3828       stream->print("[%s+0x%x]", spname, offset);
3829     } else {
3830       stream->print("reg%d:%d??", (int)(intptr_t)fst, (int)(intptr_t)snd);
3831     }
3832     stream->print(" ");
3833     stream->move_to(tab2);
3834     stream->print("= ");
3835     if (at_this) {
3836       m->method_holder()->print_value_on(stream);
3837     } else {
3838       bool did_name = false;
3839       if (is_reference_type(t)) {
3840         Symbol* name = (*sig)._symbol;
3841         name->print_value_on(stream);
3842         did_name = true;
3843       }
3844       if (!did_name)
3845         stream->print("%s", type2name(t));
3846       // If the entry has a non-default sort_offset, it must be a null marker
3847       if ((*sig)._sort_offset != (*sig)._offset) {
3848         stream->print(" (null marker)");
3849       }
3850     }
3851     if (at_old_sp) {
3852       stream->print("  (%s of caller)", spname);
3853       did_old_sp = true;
3854     }
3855     stream->cr();
3856     sig_index += type2size[t];
3857     arg_index += 1;
3858   }
3859   if (!did_old_sp) {
3860     stream->print("  # ");
3861     stream->move_to(tab1);
3862     stream->print("[%s+0x%x]", spname, stack_slot_offset);
3863     stream->print("  (%s of caller)", spname);
3864     stream->cr();
3865   }
3866 }
3867 
3868 // Returns whether this nmethod has code comments.
3869 bool nmethod::has_code_comment(address begin, address end) {
3870   // scopes?
3871   ScopeDesc* sd  = scope_desc_in(begin, end);
3872   if (sd != nullptr) return true;
3873 
3874   // relocations?
3875   const char* str = reloc_string_for(begin, end);
3876   if (str != nullptr) return true;
3877 
3878   // implicit exceptions?
3879   int cont_offset = ImplicitExceptionTable(this).continuation_offset((uint)(begin - code_begin()));
3880   if (cont_offset != 0) return true;
3881 
3882   return false;
3883 }
3884 

3968             else
3969               st->print("<UNKNOWN>");
3970             break;
3971           }
3972         case Bytecodes::_getfield:
3973         case Bytecodes::_putfield:
3974         case Bytecodes::_getstatic:
3975         case Bytecodes::_putstatic:
3976           {
3977             Bytecode_field field(methodHandle(thread, sd->method()), sd->bci());
3978             st->print(" ");
3979             if (field.name() != nullptr)
3980               field.name()->print_symbol_on(st);
3981             else
3982               st->print("<UNKNOWN>");
3983           }
3984         default:
3985           break;
3986         }
3987       }
3988       st->print(" {reexecute=%d rethrow=%d return_oop=%d return_scalarized=%d}", sd->should_reexecute(), sd->rethrow_exception(), sd->return_oop(), sd->return_scalarized());
3989     }
3990 
3991     // Print all scopes
3992     for (;sd != nullptr; sd = sd->sender()) {
3993       st->move_to(column, 6, 0);
3994       st->print("; -");
3995       if (sd->should_reexecute()) {
3996         st->print(" (reexecute)");
3997       }
3998       if (sd->method() == nullptr) {
3999         st->print("method is nullptr");
4000       } else {
4001         sd->method()->print_short_name(st);
4002       }
4003       int lineno = sd->method()->line_number_from_bci(sd->bci());
4004       if (lineno != -1) {
4005         st->print("@%d (line %d)", sd->bci(), lineno);
4006       } else {
4007         st->print("@%d", sd->bci());
4008       }
< prev index next >