< prev index next >

src/hotspot/share/code/nmethod.cpp

Print this page

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











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

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




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

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




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

3699           return st.as_string();
3700         }
3701     }
3702   }
3703   return have_one ? "other" : nullptr;
3704 }
3705 
3706 // Return the last scope in (begin..end]
3707 ScopeDesc* nmethod::scope_desc_in(address begin, address end) {
3708   PcDesc* p = pc_desc_near(begin+1);
3709   if (p != nullptr && p->real_pc(this) <= end) {
3710     return new ScopeDesc(this, p);
3711   }
3712   return nullptr;
3713 }
3714 
3715 const char* nmethod::nmethod_section_label(address pos) const {
3716   const char* label = nullptr;
3717   if (pos == code_begin())                                              label = "[Instructions begin]";
3718   if (pos == entry_point())                                             label = "[Entry Point]";

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


3720   if (has_method_handle_invokes() && (pos == deopt_mh_handler_begin())) label = "[Deopt MH Handler Code]";
3721   if (pos == consts_begin() && pos != insts_begin())                    label = "[Constants]";
3722   // Check stub_code before checking exception_handler or deopt_handler.
3723   if (pos == this->stub_begin())                                        label = "[Stub Code]";
3724   if (JVMCI_ONLY(_exception_offset >= 0 &&) pos == exception_begin())          label = "[Exception Handler]";
3725   if (JVMCI_ONLY(_deopt_handler_offset != -1 &&) pos == deopt_handler_begin()) label = "[Deopt Handler Code]";
3726   return label;
3727 }
3728 










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



















3819       }
3820       if (!did_old_sp) {
3821         stream->print("  # ");
3822         stream->move_to(tab1);
3823         stream->print("[%s+0x%x]", spname, stack_slot_offset);
3824         stream->print("  (%s of caller)", spname);
3825         stream->cr();

















3826       }
3827     }














3828   }
3829 }
3830 
3831 // Returns whether this nmethod has code comments.
3832 bool nmethod::has_code_comment(address begin, address end) {
3833   // scopes?
3834   ScopeDesc* sd  = scope_desc_in(begin, end);
3835   if (sd != nullptr) return true;
3836 
3837   // relocations?
3838   const char* str = reloc_string_for(begin, end);
3839   if (str != nullptr) return true;
3840 
3841   // implicit exceptions?
3842   int cont_offset = ImplicitExceptionTable(this).continuation_offset((uint)(begin - code_begin()));
3843   if (cont_offset != 0) return true;
3844 
3845   return false;
3846 }
3847 

3931             else
3932               st->print("<UNKNOWN>");
3933             break;
3934           }
3935         case Bytecodes::_getfield:
3936         case Bytecodes::_putfield:
3937         case Bytecodes::_getstatic:
3938         case Bytecodes::_putstatic:
3939           {
3940             Bytecode_field field(methodHandle(thread, sd->method()), sd->bci());
3941             st->print(" ");
3942             if (field.name() != nullptr)
3943               field.name()->print_symbol_on(st);
3944             else
3945               st->print("<UNKNOWN>");
3946           }
3947         default:
3948           break;
3949         }
3950       }
3951       st->print(" {reexecute=%d rethrow=%d return_oop=%d}", sd->should_reexecute(), sd->rethrow_exception(), sd->return_oop());
3952     }
3953 
3954     // Print all scopes
3955     for (;sd != nullptr; sd = sd->sender()) {
3956       st->move_to(column, 6, 0);
3957       st->print("; -");
3958       if (sd->should_reexecute()) {
3959         st->print(" (reexecute)");
3960       }
3961       if (sd->method() == nullptr) {
3962         st->print("method is nullptr");
3963       } else {
3964         sd->method()->print_short_name(st);
3965       }
3966       int lineno = sd->method()->line_number_from_bci(sd->bci());
3967       if (lineno != -1) {
3968         st->print("@%d (line %d)", sd->bci(), lineno);
3969       } else {
3970         st->print("@%d", sd->bci());
3971       }

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

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

1497         _deopt_mh_handler_offset = _stub_offset + offsets->value(CodeOffsets::DeoptMH);
1498       } else {
1499         _deopt_mh_handler_offset = -1;
1500       }
1501     }
1502     if (offsets->value(CodeOffsets::UnwindHandler) != -1) {
1503       // C1 generates UnwindHandler at the end of instructions section.
1504       // Calculate positive offset as distance between the start of stubs section
1505       // (which is also the end of instructions section) and the start of the handler.
1506       int unwind_handler_offset = code_offset() + offsets->value(CodeOffsets::UnwindHandler);
1507       CHECKED_CAST(_unwind_handler_offset, int16_t, (_stub_offset - unwind_handler_offset));
1508     } else {
1509       _unwind_handler_offset = -1;
1510     }
1511 
1512     CHECKED_CAST(_oops_size, uint16_t, align_up(code_buffer->total_oop_size(), oopSize));
1513     uint16_t metadata_size;
1514     CHECKED_CAST(metadata_size, uint16_t, align_up(code_buffer->total_metadata_size(), wordSize));
1515     JVMCI_ONLY( _metadata_size = metadata_size; )
1516     int jvmci_data_size = 0 JVMCI_ONLY( + align_up(compiler->is_jvmci() ? jvmci_data->size() : 0, oopSize));
1517     _inline_entry_point             = code_begin() + offsets->value(CodeOffsets::Inline_Entry);
1518     _verified_inline_entry_point    = code_begin() + offsets->value(CodeOffsets::Verified_Inline_Entry);
1519     _verified_inline_ro_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Inline_Entry_RO);
1520 
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

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





















3775       }
3776     }
3777   }
3778 
3779   Method* m = method();
3780   if (m == nullptr || is_osr_method()) {
3781     return;
3782   }
3783 
3784   // Print the name of the method (only once)
3785   address low = MIN3(entry_point(),
3786                      verified_entry_point(),
3787                      inline_entry_point());
3788   // The verified inline entry point and verified inline RO entry point are not always
3789   // used. When they are unused. CodeOffsets::Verified_Inline_Entry(_RO) is -1. Hence,
3790   // the calculated entry point is smaller than the block they are offsetting into.
3791   if (verified_inline_entry_point() >= block_begin) {
3792     low = MIN2(low, verified_inline_entry_point());
3793   }
3794   if (verified_inline_ro_entry_point() >= block_begin) {
3795     low = MIN2(low, verified_inline_ro_entry_point());
3796   }
3797   assert(low != 0, "sanity");
3798   if (block_begin == low) {
3799     stream->print("  # ");
3800     m->print_value_on(stream);
3801     stream->cr();
3802   }
3803 
3804   // Print the arguments for the 3 types of verified entry points
3805   CompiledEntrySignature ces(m);
3806   ces.compute_calling_conventions(false);
3807   const GrowableArray<SigEntry>* sig_cc;
3808   const VMRegPair* regs;
3809   if (block_begin == verified_entry_point()) {
3810     sig_cc = ces.sig_cc();
3811     regs = ces.regs_cc();
3812   } else if (block_begin == verified_inline_entry_point()) {
3813     sig_cc = ces.sig();
3814     regs = ces.regs();
3815   } else if (block_begin == verified_inline_ro_entry_point()) {
3816     sig_cc = ces.sig_cc_ro();
3817     regs = ces.regs_cc_ro();
3818   } else {
3819     return;
3820   }
3821 
3822   bool has_this = !m->is_static();
3823   if (ces.has_inline_recv() && block_begin == verified_entry_point()) {
3824     // <this> argument is scalarized for verified_entry_point()
3825     has_this = false;
3826   }
3827   const char* spname = "sp"; // make arch-specific?
3828   int stack_slot_offset = this->frame_size() * wordSize;
3829   int tab1 = 14, tab2 = 24;
3830   int sig_index = 0;
3831   int arg_index = has_this ? -1 : 0;
3832   bool did_old_sp = false;
3833   for (ExtendedSignature sig = ExtendedSignature(sig_cc, SigEntryFilter()); !sig.at_end(); ++sig) {
3834     bool at_this = (arg_index == -1);
3835     bool at_old_sp = false;
3836     BasicType t = (*sig)._bt;
3837     if (at_this) {
3838       stream->print("  # this: ");
3839     } else {
3840       stream->print("  # parm%d: ", arg_index);
3841     }
3842     stream->move_to(tab1);
3843     VMReg fst = regs[sig_index].first();
3844     VMReg snd = regs[sig_index].second();
3845     if (fst->is_reg()) {
3846       stream->print("%s", fst->name());
3847       if (snd->is_valid())  {
3848         stream->print(":%s", snd->name());
3849       }
3850     } else if (fst->is_stack()) {
3851       int offset = fst->reg2stack() * VMRegImpl::stack_slot_size + stack_slot_offset;
3852       if (offset == stack_slot_offset)  at_old_sp = true;
3853       stream->print("[%s+0x%x]", spname, offset);
3854     } else {
3855       stream->print("reg%d:%d??", (int)(intptr_t)fst, (int)(intptr_t)snd);
3856     }
3857     stream->print(" ");
3858     stream->move_to(tab2);
3859     stream->print("= ");
3860     if (at_this) {
3861       m->method_holder()->print_value_on(stream);
3862     } else {
3863       bool did_name = false;
3864       if (is_reference_type(t)) {
3865         Symbol* name = (*sig)._name;
3866         name->print_value_on(stream);
3867         did_name = true;
3868       }
3869       if (!did_name)
3870         stream->print("%s", type2name(t));
3871       if ((*sig)._null_marker) {
3872         stream->print(" (null marker)");
3873       }
3874     }
3875     if (at_old_sp) {
3876       stream->print("  (%s of caller)", spname);
3877       did_old_sp = true;
3878     }
3879     stream->cr();
3880     sig_index += type2size[t];
3881     arg_index += 1;
3882   }
3883   if (!did_old_sp) {
3884     stream->print("  # ");
3885     stream->move_to(tab1);
3886     stream->print("[%s+0x%x]", spname, stack_slot_offset);
3887     stream->print("  (%s of caller)", spname);
3888     stream->cr();
3889   }
3890 }
3891 
3892 // Returns whether this nmethod has code comments.
3893 bool nmethod::has_code_comment(address begin, address end) {
3894   // scopes?
3895   ScopeDesc* sd  = scope_desc_in(begin, end);
3896   if (sd != nullptr) return true;
3897 
3898   // relocations?
3899   const char* str = reloc_string_for(begin, end);
3900   if (str != nullptr) return true;
3901 
3902   // implicit exceptions?
3903   int cont_offset = ImplicitExceptionTable(this).continuation_offset((uint)(begin - code_begin()));
3904   if (cont_offset != 0) return true;
3905 
3906   return false;
3907 }
3908 

3992             else
3993               st->print("<UNKNOWN>");
3994             break;
3995           }
3996         case Bytecodes::_getfield:
3997         case Bytecodes::_putfield:
3998         case Bytecodes::_getstatic:
3999         case Bytecodes::_putstatic:
4000           {
4001             Bytecode_field field(methodHandle(thread, sd->method()), sd->bci());
4002             st->print(" ");
4003             if (field.name() != nullptr)
4004               field.name()->print_symbol_on(st);
4005             else
4006               st->print("<UNKNOWN>");
4007           }
4008         default:
4009           break;
4010         }
4011       }
4012       st->print(" {reexecute=%d rethrow=%d return_oop=%d return_scalarized=%d}", sd->should_reexecute(), sd->rethrow_exception(), sd->return_oop(), sd->return_scalarized());
4013     }
4014 
4015     // Print all scopes
4016     for (;sd != nullptr; sd = sd->sender()) {
4017       st->move_to(column, 6, 0);
4018       st->print("; -");
4019       if (sd->should_reexecute()) {
4020         st->print(" (reexecute)");
4021       }
4022       if (sd->method() == nullptr) {
4023         st->print("method is nullptr");
4024       } else {
4025         sd->method()->print_short_name(st);
4026       }
4027       int lineno = sd->method()->line_number_from_bci(sd->bci());
4028       if (lineno != -1) {
4029         st->print("@%d (line %d)", sd->bci(), lineno);
4030       } else {
4031         st->print("@%d", sd->bci());
4032       }
< prev index next >