< prev index next >

src/hotspot/share/code/nmethod.cpp

Print this page

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











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

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




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

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



1499     assert((data_offset() + data_end_offset) <= nmethod_size, "wrong nmethod's size: %d > %d",
1500            (data_offset() + data_end_offset), nmethod_size);
1501 
1502     _immutable_data_size  = immutable_data_size;
1503     if (immutable_data_size > 0) {
1504       assert(immutable_data != nullptr, "required");
1505       _immutable_data     = immutable_data;
1506     } else {
1507       // We need unique not null address
1508       _immutable_data     = data_end();
1509     }
1510     CHECKED_CAST(_nul_chk_table_offset, uint16_t, (align_up((int)dependencies->size_in_bytes(), oopSize)));
1511     CHECKED_CAST(_handler_table_offset, uint16_t, (_nul_chk_table_offset + align_up(nul_chk_table->size_in_bytes(), oopSize)));
1512     _scopes_pcs_offset    = _handler_table_offset + align_up(handler_table->size_in_bytes(), oopSize);
1513     _scopes_data_offset   = _scopes_pcs_offset    + adjust_pcs_size(debug_info->pcs_size());
1514 
1515 #if INCLUDE_JVMCI
1516     _speculations_offset  = _scopes_data_offset   + align_up(debug_info->data_size(), oopSize);
1517     DEBUG_ONLY( int immutable_data_end_offset = _speculations_offset  + align_up(speculations_len, oopSize); )
1518 #else

3653           return st.as_string();
3654         }
3655     }
3656   }
3657   return have_one ? "other" : nullptr;
3658 }
3659 
3660 // Return the last scope in (begin..end]
3661 ScopeDesc* nmethod::scope_desc_in(address begin, address end) {
3662   PcDesc* p = pc_desc_near(begin+1);
3663   if (p != nullptr && p->real_pc(this) <= end) {
3664     return new ScopeDesc(this, p);
3665   }
3666   return nullptr;
3667 }
3668 
3669 const char* nmethod::nmethod_section_label(address pos) const {
3670   const char* label = nullptr;
3671   if (pos == code_begin())                                              label = "[Instructions begin]";
3672   if (pos == entry_point())                                             label = "[Entry Point]";

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


3674   if (has_method_handle_invokes() && (pos == deopt_mh_handler_begin())) label = "[Deopt MH Handler Code]";
3675   if (pos == consts_begin() && pos != insts_begin())                    label = "[Constants]";
3676   // Check stub_code before checking exception_handler or deopt_handler.
3677   if (pos == this->stub_begin())                                        label = "[Stub Code]";
3678   if (JVMCI_ONLY(_exception_offset >= 0 &&) pos == exception_begin())          label = "[Exception Handler]";
3679   if (JVMCI_ONLY(_deopt_handler_offset != -1 &&) pos == deopt_handler_begin()) label = "[Deopt Handler Code]";
3680   return label;
3681 }
3682 










3683 void nmethod::print_nmethod_labels(outputStream* stream, address block_begin, bool print_section_labels) const {
3684   if (print_section_labels) {
3685     const char* label = nmethod_section_label(block_begin);
3686     if (label != nullptr) {
3687       stream->bol();
3688       stream->print_cr("%s", label);
3689     }
3690   }
3691 
3692   if (block_begin == entry_point()) {
3693     Method* m = method();
3694     if (m != nullptr) {
3695       stream->print("  # ");
3696       m->print_value_on(stream);
3697       stream->cr();
3698     }
3699     if (m != nullptr && !is_osr_method()) {
3700       ResourceMark rm;
3701       int sizeargs = m->size_of_parameters();
3702       BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sizeargs);
3703       VMRegPair* regs   = NEW_RESOURCE_ARRAY(VMRegPair, sizeargs);
3704       {
3705         int sig_index = 0;
3706         if (!m->is_static())
3707           sig_bt[sig_index++] = T_OBJECT; // 'this'
3708         for (SignatureStream ss(m->signature()); !ss.at_return_type(); ss.next()) {
3709           BasicType t = ss.type();
3710           sig_bt[sig_index++] = t;
3711           if (type2size[t] == 2) {
3712             sig_bt[sig_index++] = T_VOID;
3713           } else {
3714             assert(type2size[t] == 1, "size is 1 or 2");
3715           }
3716         }
3717         assert(sig_index == sizeargs, "");
3718       }
3719       const char* spname = "sp"; // make arch-specific?
3720       SharedRuntime::java_calling_convention(sig_bt, regs, sizeargs);
3721       int stack_slot_offset = this->frame_size() * wordSize;
3722       int tab1 = 14, tab2 = 24;
3723       int sig_index = 0;
3724       int arg_index = (m->is_static() ? 0 : -1);
3725       bool did_old_sp = false;
3726       for (SignatureStream ss(m->signature()); !ss.at_return_type(); ) {
3727         bool at_this = (arg_index == -1);
3728         bool at_old_sp = false;
3729         BasicType t = (at_this ? T_OBJECT : ss.type());
3730         assert(t == sig_bt[sig_index], "sigs in sync");
3731         if (at_this)
3732           stream->print("  # this: ");
3733         else
3734           stream->print("  # parm%d: ", arg_index);
3735         stream->move_to(tab1);
3736         VMReg fst = regs[sig_index].first();
3737         VMReg snd = regs[sig_index].second();
3738         if (fst->is_reg()) {
3739           stream->print("%s", fst->name());
3740           if (snd->is_valid())  {
3741             stream->print(":%s", snd->name());
3742           }
3743         } else if (fst->is_stack()) {
3744           int offset = fst->reg2stack() * VMRegImpl::stack_slot_size + stack_slot_offset;
3745           if (offset == stack_slot_offset)  at_old_sp = true;
3746           stream->print("[%s+0x%x]", spname, offset);
3747         } else {
3748           stream->print("reg%d:%d??", (int)(intptr_t)fst, (int)(intptr_t)snd);
3749         }
3750         stream->print(" ");
3751         stream->move_to(tab2);
3752         stream->print("= ");
3753         if (at_this) {
3754           m->method_holder()->print_value_on(stream);
3755         } else {
3756           bool did_name = false;
3757           if (!at_this && ss.is_reference()) {
3758             Symbol* name = ss.as_symbol();
3759             name->print_value_on(stream);
3760             did_name = true;
3761           }
3762           if (!did_name)
3763             stream->print("%s", type2name(t));
3764         }
3765         if (at_old_sp) {
3766           stream->print("  (%s of caller)", spname);
3767           did_old_sp = true;
3768         }
3769         stream->cr();
3770         sig_index += type2size[t];
3771         arg_index += 1;
3772         if (!at_this)  ss.next();









3773       }
3774       if (!did_old_sp) {
3775         stream->print("  # ");
3776         stream->move_to(tab1);
3777         stream->print("[%s+0x%x]", spname, stack_slot_offset);
3778         stream->print("  (%s of caller)", spname);
3779         stream->cr();


















3780       }
3781     }














3782   }
3783 }
3784 
3785 // Returns whether this nmethod has code comments.
3786 bool nmethod::has_code_comment(address begin, address end) {
3787   // scopes?
3788   ScopeDesc* sd  = scope_desc_in(begin, end);
3789   if (sd != nullptr) return true;
3790 
3791   // relocations?
3792   const char* str = reloc_string_for(begin, end);
3793   if (str != nullptr) return true;
3794 
3795   // implicit exceptions?
3796   int cont_offset = ImplicitExceptionTable(this).continuation_offset((uint)(begin - code_begin()));
3797   if (cont_offset != 0) return true;
3798 
3799   return false;
3800 }
3801 

3885             else
3886               st->print("<UNKNOWN>");
3887             break;
3888           }
3889         case Bytecodes::_getfield:
3890         case Bytecodes::_putfield:
3891         case Bytecodes::_getstatic:
3892         case Bytecodes::_putstatic:
3893           {
3894             Bytecode_field field(methodHandle(thread, sd->method()), sd->bci());
3895             st->print(" ");
3896             if (field.name() != nullptr)
3897               field.name()->print_symbol_on(st);
3898             else
3899               st->print("<UNKNOWN>");
3900           }
3901         default:
3902           break;
3903         }
3904       }
3905       st->print(" {reexecute=%d rethrow=%d return_oop=%d}", sd->should_reexecute(), sd->rethrow_exception(), sd->return_oop());
3906     }
3907 
3908     // Print all scopes
3909     for (;sd != nullptr; sd = sd->sender()) {
3910       st->move_to(column, 6, 0);
3911       st->print("; -");
3912       if (sd->should_reexecute()) {
3913         st->print(" (reexecute)");
3914       }
3915       if (sd->method() == nullptr) {
3916         st->print("method is nullptr");
3917       } else {
3918         sd->method()->print_short_name(st);
3919       }
3920       int lineno = sd->method()->line_number_from_bci(sd->bci());
3921       if (lineno != -1) {
3922         st->print("@%d (line %d)", sd->bci(), lineno);
3923       } else {
3924         st->print("@%d", sd->bci());
3925       }

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

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

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

3671           return st.as_string();
3672         }
3673     }
3674   }
3675   return have_one ? "other" : nullptr;
3676 }
3677 
3678 // Return the last scope in (begin..end]
3679 ScopeDesc* nmethod::scope_desc_in(address begin, address end) {
3680   PcDesc* p = pc_desc_near(begin+1);
3681   if (p != nullptr && p->real_pc(this) <= end) {
3682     return new ScopeDesc(this, p);
3683   }
3684   return nullptr;
3685 }
3686 
3687 const char* nmethod::nmethod_section_label(address pos) const {
3688   const char* label = nullptr;
3689   if (pos == code_begin())                                              label = "[Instructions begin]";
3690   if (pos == entry_point())                                             label = "[Entry Point]";
3691   if (pos == inline_entry_point())                                      label = "[Inline Entry Point]";
3692   if (pos == verified_entry_point())                                    label = "[Verified Entry Point]";
3693   if (pos == verified_inline_entry_point())                             label = "[Verified Inline Entry Point]";
3694   if (pos == verified_inline_ro_entry_point())                          label = "[Verified Inline Entry Point (RO)]";
3695   if (has_method_handle_invokes() && (pos == deopt_mh_handler_begin())) label = "[Deopt MH Handler Code]";
3696   if (pos == consts_begin() && pos != insts_begin())                    label = "[Constants]";
3697   // Check stub_code before checking exception_handler or deopt_handler.
3698   if (pos == this->stub_begin())                                        label = "[Stub Code]";
3699   if (JVMCI_ONLY(_exception_offset >= 0 &&) pos == exception_begin())          label = "[Exception Handler]";
3700   if (JVMCI_ONLY(_deopt_handler_offset != -1 &&) pos == deopt_handler_begin()) label = "[Deopt Handler Code]";
3701   return label;
3702 }
3703 
3704 static int maybe_print_entry_label(outputStream* stream, address pos, address entry, const char* label) {
3705   if (pos == entry) {
3706     stream->bol();
3707     stream->print_cr("%s", label);
3708     return 1;
3709   } else {
3710     return 0;
3711   }
3712 }
3713 
3714 void nmethod::print_nmethod_labels(outputStream* stream, address block_begin, bool print_section_labels) const {
3715   if (print_section_labels) {
3716     int n = 0;
3717     // Multiple entry points may be at the same position. Print them all.
3718     n += maybe_print_entry_label(stream, block_begin, entry_point(),                    "[Entry Point]");
3719     n += maybe_print_entry_label(stream, block_begin, inline_entry_point(),             "[Inline Entry Point]");
3720     n += maybe_print_entry_label(stream, block_begin, verified_entry_point(),           "[Verified Entry Point]");
3721     n += maybe_print_entry_label(stream, block_begin, verified_inline_entry_point(),    "[Verified Inline Entry Point]");
3722     n += maybe_print_entry_label(stream, block_begin, verified_inline_ro_entry_point(), "[Verified Inline Entry Point (RO)]");
3723     if (n == 0) {
3724       const char* label = nmethod_section_label(block_begin);
3725       if (label != nullptr) {
3726         stream->bol();
3727         stream->print_cr("%s", label);





















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

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