< 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

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

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


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










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



















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

















3829       }
3830     }














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

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

 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

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





















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

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