< prev index next >

src/hotspot/share/code/nmethod.cpp

Print this page

 707   }
 708 
 709   // handle the case of an anchor explicitly set in continuation code that doesn't have a callee
 710   JavaThread* thread = reg_map->thread();
 711   if (thread->has_last_Java_frame() && fr.sp() == thread->last_Java_sp()) {
 712     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     = _method->constMethod()->num_stack_arg_slots();
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

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

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


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










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









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












3781       }


3782     }














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

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

 707   }
 708 
 709   // handle the case of an anchor explicitly set in continuation code that doesn't have a callee
 710   JavaThread* thread = reg_map->thread();
 711   if (thread->has_last_Java_frame() && fr.sp() == thread->last_Java_sp()) {
 712     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     = _method->constMethod()->num_stack_arg_slots();
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

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





















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

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