< prev index next >

src/hotspot/share/code/nmethod.cpp

Print this page

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











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

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




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

1736         _exception_offset = -1;
1737       }
1738 
1739       _deopt_handler_entry_offset = _stub_offset + offsets->value(CodeOffsets::Deopt);
1740     }
1741     if (offsets->value(CodeOffsets::UnwindHandler) != -1) {
1742       // C1 generates UnwindHandler at the end of instructions section.
1743       // Calculate positive offset as distance between the start of stubs section
1744       // (which is also the end of instructions section) and the start of the handler.
1745       int unwind_handler_offset = code_offset() + offsets->value(CodeOffsets::UnwindHandler);
1746       CHECKED_CAST(_unwind_handler_offset, int16_t, (_stub_offset - unwind_handler_offset));
1747     } else {
1748       _unwind_handler_offset = -1;
1749     }
1750 
1751     CHECKED_CAST(_oops_size, uint16_t, align_up(code_buffer->total_oop_size(), oopSize));
1752     uint16_t metadata_size;
1753     CHECKED_CAST(metadata_size, uint16_t, align_up(code_buffer->total_metadata_size(), wordSize));
1754     JVMCI_ONLY( _metadata_size = metadata_size; )
1755     int jvmci_data_size = 0 JVMCI_ONLY( + align_up(compiler->is_jvmci() ? jvmci_data->size() : 0, oopSize));




1756     assert(_mutable_data_size == _relocation_size + metadata_size + jvmci_data_size,
1757            "wrong mutable data size: %d != %d + %d + %d",
1758            _mutable_data_size, _relocation_size, metadata_size, jvmci_data_size);
1759     assert(nmethod_size == data_end() - header_begin(), "wrong nmethod size: %d != %d",
1760            nmethod_size, (int)(code_end() - header_begin()));
1761 
1762     _immutable_data_size  = immutable_data_size;
1763     if (immutable_data_size > 0) {
1764       assert(immutable_data != nullptr, "required");
1765       _immutable_data     = immutable_data;
1766     } else {
1767       // We need unique not null address
1768       _immutable_data     = blob_end();
1769     }
1770     CHECKED_CAST(_nul_chk_table_offset, uint16_t, (align_up((int)dependencies->size_in_bytes(), oopSize)));
1771     CHECKED_CAST(_handler_table_offset, uint16_t, (_nul_chk_table_offset + align_up(nul_chk_table->size_in_bytes(), oopSize)));
1772     _scopes_pcs_offset    = _handler_table_offset + align_up(handler_table->size_in_bytes(), oopSize);
1773     _scopes_data_offset   = _scopes_pcs_offset    + adjust_pcs_size(debug_info->pcs_size());
1774 
1775 #if INCLUDE_JVMCI

3181 }
3182 
3183 bool nmethod::check_dependency_on(DepChange& changes) {
3184   // What has happened:
3185   // 1) a new class dependee has been added
3186   // 2) dependee and all its super classes have been marked
3187   bool found_check = false;  // set true if we are upset
3188   for (Dependencies::DepStream deps(this); deps.next(); ) {
3189     // Evaluate only relevant dependencies.
3190     if (deps.spot_check_dependency_at(changes) != nullptr) {
3191       found_check = true;
3192       NOT_DEBUG(break);
3193     }
3194   }
3195   return found_check;
3196 }
3197 
3198 // Called from mark_for_deoptimization, when dependee is invalidated.
3199 bool nmethod::is_dependent_on_method(Method* dependee) {
3200   for (Dependencies::DepStream deps(this); deps.next(); ) {
3201     if (deps.type() != Dependencies::evol_method)
3202       continue;
3203     Method* method = deps.method_argument(0);
3204     if (method == dependee) return true;
3205   }
3206   return false;
3207 }
3208 
3209 void nmethod_init() {
3210   // make sure you didn't forget to adjust the filler fields
3211   assert(sizeof(nmethod) % oopSize == 0, "nmethod size must be multiple of a word");
3212 }
3213 
3214 // -----------------------------------------------------------------------------
3215 // Verification
3216 
3217 class VerifyOopsClosure: public OopClosure {
3218   nmethod* _nm;
3219   bool     _ok;
3220 public:
3221   VerifyOopsClosure(nmethod* nm) : _nm(nm), _ok(true) { }
3222   bool ok() { return _ok; }
3223   virtual void do_oop(oop* p) {
3224     if (oopDesc::is_oop_or_null(*p)) return;

4022           return st.as_string();
4023         }
4024     }
4025   }
4026   return have_one ? "other" : nullptr;
4027 }
4028 
4029 // Return the last scope in (begin..end]
4030 ScopeDesc* nmethod::scope_desc_in(address begin, address end) {
4031   PcDesc* p = pc_desc_near(begin+1);
4032   if (p != nullptr && p->real_pc(this) <= end) {
4033     return new ScopeDesc(this, p);
4034   }
4035   return nullptr;
4036 }
4037 
4038 const char* nmethod::nmethod_section_label(address pos) const {
4039   const char* label = nullptr;
4040   if (pos == code_begin())                                              label = "[Instructions begin]";
4041   if (pos == entry_point())                                             label = "[Entry Point]";

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


4043   if (pos == consts_begin() && pos != insts_begin())                    label = "[Constants]";
4044   // Check stub_code before checking exception_handler or deopt_handler.
4045   if (pos == this->stub_begin())                                        label = "[Stub Code]";
4046   if (JVMCI_ONLY(_exception_offset >= 0 &&) pos == exception_begin())          label = "[Exception Handler]";
4047   if (JVMCI_ONLY(_deopt_handler_entry_offset != -1 &&) pos == deopt_handler_entry()) label = "[Deopt Handler Entry Point]";
4048   return label;
4049 }
4050 










4051 void nmethod::print_nmethod_labels(outputStream* stream, address block_begin, bool print_section_labels) const {
4052   if (print_section_labels) {
4053     const char* label = nmethod_section_label(block_begin);
4054     if (label != nullptr) {
4055       stream->bol();
4056       stream->print_cr("%s", label);









4057     }
4058   }
4059 
4060   if (block_begin == entry_point()) {
4061     Method* m = method();
4062     if (m != nullptr) {
4063       stream->print("  # ");
4064       m->print_value_on(stream);
4065       stream->cr();
























































4066     }
4067     if (m != nullptr && !is_osr_method()) {
4068       ResourceMark rm;
4069       int sizeargs = m->size_of_parameters();
4070       BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sizeargs);
4071       VMRegPair* regs   = NEW_RESOURCE_ARRAY(VMRegPair, sizeargs);
4072       {
4073         int sig_index = 0;
4074         if (!m->is_static())
4075           sig_bt[sig_index++] = T_OBJECT; // 'this'
4076         for (SignatureStream ss(m->signature()); !ss.at_return_type(); ss.next()) {
4077           BasicType t = ss.type();
4078           sig_bt[sig_index++] = t;
4079           if (type2size[t] == 2) {
4080             sig_bt[sig_index++] = T_VOID;
4081           } else {
4082             assert(type2size[t] == 1, "size is 1 or 2");
4083           }
4084         }
4085         assert(sig_index == sizeargs, "");
4086       }
4087       const char* spname = "sp"; // make arch-specific?
4088       SharedRuntime::java_calling_convention(sig_bt, regs, sizeargs);
4089       int stack_slot_offset = this->frame_size() * wordSize;
4090       int tab1 = 14, tab2 = 24;
4091       int sig_index = 0;
4092       int arg_index = (m->is_static() ? 0 : -1);
4093       bool did_old_sp = false;
4094       for (SignatureStream ss(m->signature()); !ss.at_return_type(); ) {
4095         bool at_this = (arg_index == -1);
4096         bool at_old_sp = false;
4097         BasicType t = (at_this ? T_OBJECT : ss.type());
4098         assert(t == sig_bt[sig_index], "sigs in sync");
4099         if (at_this)
4100           stream->print("  # this: ");
4101         else
4102           stream->print("  # parm%d: ", arg_index);
4103         stream->move_to(tab1);
4104         VMReg fst = regs[sig_index].first();
4105         VMReg snd = regs[sig_index].second();
4106         if (fst->is_reg()) {
4107           stream->print("%s", fst->name());
4108           if (snd->is_valid())  {
4109             stream->print(":%s", snd->name());
4110           }
4111         } else if (fst->is_stack()) {
4112           int offset = fst->reg2stack() * VMRegImpl::stack_slot_size + stack_slot_offset;
4113           if (offset == stack_slot_offset)  at_old_sp = true;
4114           stream->print("[%s+0x%x]", spname, offset);
4115         } else {
4116           stream->print("reg%d:%d??", (int)(intptr_t)fst, (int)(intptr_t)snd);
4117         }
4118         stream->print(" ");
4119         stream->move_to(tab2);
4120         stream->print("= ");
4121         if (at_this) {
4122           m->method_holder()->print_value_on(stream);
4123         } else {
4124           bool did_name = false;
4125           if (!at_this && ss.is_reference()) {
4126             Symbol* name = ss.as_symbol();
4127             name->print_value_on(stream);
4128             did_name = true;
4129           }
4130           if (!did_name)
4131             stream->print("%s", type2name(t));
4132         }
4133         if (at_old_sp) {
4134           stream->print("  (%s of caller)", spname);
4135           did_old_sp = true;
4136         }
4137         stream->cr();
4138         sig_index += type2size[t];
4139         arg_index += 1;
4140         if (!at_this)  ss.next();
4141       }
4142       if (!did_old_sp) {
4143         stream->print("  # ");
4144         stream->move_to(tab1);
4145         stream->print("[%s+0x%x]", spname, stack_slot_offset);
4146         stream->print("  (%s of caller)", spname);
4147         stream->cr();
4148       }
4149     }














4150   }
4151 }
4152 
4153 // Returns whether this nmethod has code comments.
4154 bool nmethod::has_code_comment(address begin, address end) {
4155   // scopes?
4156   ScopeDesc* sd  = scope_desc_in(begin, end);
4157   if (sd != nullptr) return true;
4158 
4159   // relocations?
4160   const char* str = reloc_string_for(begin, end);
4161   if (str != nullptr) return true;
4162 
4163   // implicit exceptions?
4164   int cont_offset = ImplicitExceptionTable(this).continuation_offset((uint)(begin - code_begin()));
4165   if (cont_offset != 0) return true;
4166 
4167   return false;
4168 }
4169 

4253             else
4254               st->print("<UNKNOWN>");
4255             break;
4256           }
4257         case Bytecodes::_getfield:
4258         case Bytecodes::_putfield:
4259         case Bytecodes::_getstatic:
4260         case Bytecodes::_putstatic:
4261           {
4262             Bytecode_field field(methodHandle(thread, sd->method()), sd->bci());
4263             st->print(" ");
4264             if (field.name() != nullptr)
4265               field.name()->print_symbol_on(st);
4266             else
4267               st->print("<UNKNOWN>");
4268           }
4269         default:
4270           break;
4271         }
4272       }
4273       st->print(" {reexecute=%d rethrow=%d return_oop=%d}", sd->should_reexecute(), sd->rethrow_exception(), sd->return_oop());
4274     }
4275 
4276     // Print all scopes
4277     for (;sd != nullptr; sd = sd->sender()) {
4278       st->move_to(column, 6, 0);
4279       st->print("; -");
4280       if (sd->should_reexecute()) {
4281         st->print(" (reexecute)");
4282       }
4283       if (sd->method() == nullptr) {
4284         st->print("method is nullptr");
4285       } else {
4286         sd->method()->print_short_name(st);
4287       }
4288       int lineno = sd->method()->line_number_from_bci(sd->bci());
4289       if (lineno != -1) {
4290         st->print("@%d (line %d)", sd->bci(), lineno);
4291       } else {
4292         st->print("@%d", sd->bci());
4293       }

 696 
 697   // handle the case of an anchor explicitly set in continuation code that doesn't have a callee
 698   JavaThread* thread = reg_map->thread();
 699   if ((thread->has_last_Java_frame() && fr.sp() == thread->last_Java_sp())
 700       JVMTI_ONLY(|| (method()->is_continuation_enter_intrinsic() && thread->on_monitor_waited_event()))) {
 701     return;
 702   }
 703 
 704   if (!method()->is_native()) {
 705     address pc = fr.pc();
 706     bool has_receiver, has_appendix;
 707     Symbol* signature;
 708 
 709     // The method attached by JIT-compilers should be used, if present.
 710     // Bytecode can be inaccurate in such case.
 711     Method* callee = attached_method_before_pc(pc);
 712     if (callee != nullptr) {
 713       has_receiver = !(callee->access_flags().is_static());
 714       has_appendix = false;
 715       signature    = callee->signature();
 716 
 717       // If inline types are passed as fields, use the extended signature
 718       // which contains the types of all (oop) fields of the inline type.
 719       if (is_compiled_by_c2() && callee->has_scalarized_args()) {
 720         const GrowableArray<SigEntry>* sig = callee->adapter()->get_sig_cc();
 721         assert(sig != nullptr, "sig should never be null");
 722         TempNewSymbol tmp_sig = SigEntry::create_symbol(sig);
 723         has_receiver = false; // The extended signature contains the receiver type
 724         fr.oops_compiled_arguments_do(tmp_sig, has_receiver, has_appendix, reg_map, f);
 725         return;
 726       }
 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);

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

1751         _exception_offset = -1;
1752       }
1753 
1754       _deopt_handler_entry_offset = _stub_offset + offsets->value(CodeOffsets::Deopt);
1755     }
1756     if (offsets->value(CodeOffsets::UnwindHandler) != -1) {
1757       // C1 generates UnwindHandler at the end of instructions section.
1758       // Calculate positive offset as distance between the start of stubs section
1759       // (which is also the end of instructions section) and the start of the handler.
1760       int unwind_handler_offset = code_offset() + offsets->value(CodeOffsets::UnwindHandler);
1761       CHECKED_CAST(_unwind_handler_offset, int16_t, (_stub_offset - unwind_handler_offset));
1762     } else {
1763       _unwind_handler_offset = -1;
1764     }
1765 
1766     CHECKED_CAST(_oops_size, uint16_t, align_up(code_buffer->total_oop_size(), oopSize));
1767     uint16_t metadata_size;
1768     CHECKED_CAST(metadata_size, uint16_t, align_up(code_buffer->total_metadata_size(), wordSize));
1769     JVMCI_ONLY( _metadata_size = metadata_size; )
1770     int jvmci_data_size = 0 JVMCI_ONLY( + align_up(compiler->is_jvmci() ? jvmci_data->size() : 0, oopSize));
1771     _inline_entry_point             = code_begin() + offsets->value(CodeOffsets::Inline_Entry);
1772     _verified_inline_entry_point    = code_begin() + offsets->value(CodeOffsets::Verified_Inline_Entry);
1773     _verified_inline_ro_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Inline_Entry_RO);
1774 
1775     assert(_mutable_data_size == _relocation_size + metadata_size + jvmci_data_size,
1776            "wrong mutable data size: %d != %d + %d + %d",
1777            _mutable_data_size, _relocation_size, metadata_size, jvmci_data_size);
1778     assert(nmethod_size == data_end() - header_begin(), "wrong nmethod size: %d != %d",
1779            nmethod_size, (int)(code_end() - header_begin()));
1780 
1781     _immutable_data_size  = immutable_data_size;
1782     if (immutable_data_size > 0) {
1783       assert(immutable_data != nullptr, "required");
1784       _immutable_data     = immutable_data;
1785     } else {
1786       // We need unique not null address
1787       _immutable_data     = blob_end();
1788     }
1789     CHECKED_CAST(_nul_chk_table_offset, uint16_t, (align_up((int)dependencies->size_in_bytes(), oopSize)));
1790     CHECKED_CAST(_handler_table_offset, uint16_t, (_nul_chk_table_offset + align_up(nul_chk_table->size_in_bytes(), oopSize)));
1791     _scopes_pcs_offset    = _handler_table_offset + align_up(handler_table->size_in_bytes(), oopSize);
1792     _scopes_data_offset   = _scopes_pcs_offset    + adjust_pcs_size(debug_info->pcs_size());
1793 
1794 #if INCLUDE_JVMCI

3200 }
3201 
3202 bool nmethod::check_dependency_on(DepChange& changes) {
3203   // What has happened:
3204   // 1) a new class dependee has been added
3205   // 2) dependee and all its super classes have been marked
3206   bool found_check = false;  // set true if we are upset
3207   for (Dependencies::DepStream deps(this); deps.next(); ) {
3208     // Evaluate only relevant dependencies.
3209     if (deps.spot_check_dependency_at(changes) != nullptr) {
3210       found_check = true;
3211       NOT_DEBUG(break);
3212     }
3213   }
3214   return found_check;
3215 }
3216 
3217 // Called from mark_for_deoptimization, when dependee is invalidated.
3218 bool nmethod::is_dependent_on_method(Method* dependee) {
3219   for (Dependencies::DepStream deps(this); deps.next(); ) {
3220     if (Dependencies::has_method_dep(deps.type())) {
3221       Method* method = deps.method_argument(0);
3222       if (method == dependee) return true;
3223     }
3224   }
3225   return false;
3226 }
3227 
3228 void nmethod_init() {
3229   // make sure you didn't forget to adjust the filler fields
3230   assert(sizeof(nmethod) % oopSize == 0, "nmethod size must be multiple of a word");
3231 }
3232 
3233 // -----------------------------------------------------------------------------
3234 // Verification
3235 
3236 class VerifyOopsClosure: public OopClosure {
3237   nmethod* _nm;
3238   bool     _ok;
3239 public:
3240   VerifyOopsClosure(nmethod* nm) : _nm(nm), _ok(true) { }
3241   bool ok() { return _ok; }
3242   virtual void do_oop(oop* p) {
3243     if (oopDesc::is_oop_or_null(*p)) return;

4041           return st.as_string();
4042         }
4043     }
4044   }
4045   return have_one ? "other" : nullptr;
4046 }
4047 
4048 // Return the last scope in (begin..end]
4049 ScopeDesc* nmethod::scope_desc_in(address begin, address end) {
4050   PcDesc* p = pc_desc_near(begin+1);
4051   if (p != nullptr && p->real_pc(this) <= end) {
4052     return new ScopeDesc(this, p);
4053   }
4054   return nullptr;
4055 }
4056 
4057 const char* nmethod::nmethod_section_label(address pos) const {
4058   const char* label = nullptr;
4059   if (pos == code_begin())                                              label = "[Instructions begin]";
4060   if (pos == entry_point())                                             label = "[Entry Point]";
4061   if (pos == inline_entry_point())                                      label = "[Inline Entry Point]";
4062   if (pos == verified_entry_point())                                    label = "[Verified Entry Point]";
4063   if (pos == verified_inline_entry_point())                             label = "[Verified Inline Entry Point]";
4064   if (pos == verified_inline_ro_entry_point())                          label = "[Verified Inline Entry Point (RO)]";
4065   if (pos == consts_begin() && pos != insts_begin())                    label = "[Constants]";
4066   // Check stub_code before checking exception_handler or deopt_handler.
4067   if (pos == this->stub_begin())                                        label = "[Stub Code]";
4068   if (JVMCI_ONLY(_exception_offset >= 0 &&) pos == exception_begin())          label = "[Exception Handler]";
4069   if (JVMCI_ONLY(_deopt_handler_entry_offset != -1 &&) pos == deopt_handler_entry()) label = "[Deopt Handler Entry Point]";
4070   return label;
4071 }
4072 
4073 static int maybe_print_entry_label(outputStream* stream, address pos, address entry, const char* label) {
4074   if (pos == entry) {
4075     stream->bol();
4076     stream->print_cr("%s", label);
4077     return 1;
4078   } else {
4079     return 0;
4080   }
4081 }
4082 
4083 void nmethod::print_nmethod_labels(outputStream* stream, address block_begin, bool print_section_labels) const {
4084   if (print_section_labels) {
4085     int n = 0;
4086     // Multiple entry points may be at the same position. Print them all.
4087     n += maybe_print_entry_label(stream, block_begin, entry_point(),                    "[Entry Point]");
4088     n += maybe_print_entry_label(stream, block_begin, inline_entry_point(),             "[Inline Entry Point]");
4089     n += maybe_print_entry_label(stream, block_begin, verified_entry_point(),           "[Verified Entry Point]");
4090     n += maybe_print_entry_label(stream, block_begin, verified_inline_entry_point(),    "[Verified Inline Entry Point]");
4091     n += maybe_print_entry_label(stream, block_begin, verified_inline_ro_entry_point(), "[Verified Inline Entry Point (RO)]");
4092     if (n == 0) {
4093       const char* label = nmethod_section_label(block_begin);
4094       if (label != nullptr) {
4095         stream->bol();
4096         stream->print_cr("%s", label);
4097       }
4098     }
4099   }
4100 
4101   Method* m = method();
4102   if (m == nullptr || is_osr_method()) {
4103     return;
4104   }
4105 
4106   // Print the name of the method (only once)
4107   address low = MIN3(entry_point(),
4108                      verified_entry_point(),
4109                      inline_entry_point());
4110   // The verified inline entry point and verified inline RO entry point are not always
4111   // used. When they are unused. CodeOffsets::Verified_Inline_Entry(_RO) is -1. Hence,
4112   // the calculated entry point is smaller than the block they are offsetting into.
4113   if (verified_inline_entry_point() >= block_begin) {
4114     low = MIN2(low, verified_inline_entry_point());
4115   }
4116   if (verified_inline_ro_entry_point() >= block_begin) {
4117     low = MIN2(low, verified_inline_ro_entry_point());
4118   }
4119   assert(low != 0, "sanity");
4120   if (block_begin == low) {
4121     stream->print("  # ");
4122     m->print_value_on(stream);
4123     stream->cr();
4124   }
4125 
4126   // Print the arguments for the 3 types of verified entry points
4127   CompiledEntrySignature ces(m);
4128   ces.compute_calling_conventions(false);
4129   const GrowableArray<SigEntry>* sig_cc;
4130   const VMRegPair* regs;
4131   if (block_begin == verified_entry_point()) {
4132     sig_cc = ces.sig_cc();
4133     regs = ces.regs_cc();
4134   } else if (block_begin == verified_inline_entry_point()) {
4135     sig_cc = ces.sig();
4136     regs = ces.regs();
4137   } else if (block_begin == verified_inline_ro_entry_point()) {
4138     sig_cc = ces.sig_cc_ro();
4139     regs = ces.regs_cc_ro();
4140   } else {
4141     return;
4142   }
4143 
4144   bool has_this = !m->is_static();
4145   if (ces.has_inline_recv() && block_begin == verified_entry_point()) {
4146     // <this> argument is scalarized for verified_entry_point()
4147     has_this = false;
4148   }
4149   const char* spname = "sp"; // make arch-specific?
4150   int stack_slot_offset = this->frame_size() * wordSize;
4151   int tab1 = 14, tab2 = 24;
4152   int sig_index = 0;
4153   int arg_index = has_this ? -1 : 0;
4154   bool did_old_sp = false;
4155   for (ExtendedSignature sig = ExtendedSignature(sig_cc, SigEntryFilter()); !sig.at_end(); ++sig) {
4156     bool at_this = (arg_index == -1);
4157     bool at_old_sp = false;
4158     BasicType t = (*sig)._bt;
4159     if (at_this) {
4160       stream->print("  # this: ");
4161     } else {
4162       stream->print("  # parm%d: ", arg_index);
4163     }
4164     stream->move_to(tab1);
4165     VMReg fst = regs[sig_index].first();
4166     VMReg snd = regs[sig_index].second();
4167     if (fst->is_reg()) {
4168       stream->print("%s", fst->name());
4169       if (snd->is_valid())  {
4170         stream->print(":%s", snd->name());












4171       }
4172     } else if (fst->is_stack()) {
4173       int offset = fst->reg2stack() * VMRegImpl::stack_slot_size + stack_slot_offset;
4174       if (offset == stack_slot_offset)  at_old_sp = true;
4175       stream->print("[%s+0x%x]", spname, offset);
4176     } else {
4177       stream->print("reg%d:%d??", (int)(intptr_t)fst, (int)(intptr_t)snd);
4178     }
4179     stream->print(" ");
4180     stream->move_to(tab2);
4181     stream->print("= ");
4182     if (at_this) {
4183       m->method_holder()->print_value_on(stream);
4184     } else {
4185       bool did_name = false;
4186       if (is_reference_type(t)) {
4187         Symbol* name = (*sig)._name;
4188         name->print_value_on(stream);
4189         did_name = true;




































4190       }
4191       if (!did_name)
4192         stream->print("%s", type2name(t));
4193       if ((*sig)._null_marker) {
4194         stream->print(" (null marker)");


4195       }
4196     }
4197     if (at_old_sp) {
4198       stream->print("  (%s of caller)", spname);
4199       did_old_sp = true;
4200     }
4201     stream->cr();
4202     sig_index += type2size[t];
4203     arg_index += 1;
4204   }
4205   if (!did_old_sp) {
4206     stream->print("  # ");
4207     stream->move_to(tab1);
4208     stream->print("[%s+0x%x]", spname, stack_slot_offset);
4209     stream->print("  (%s of caller)", spname);
4210     stream->cr();
4211   }
4212 }
4213 
4214 // Returns whether this nmethod has code comments.
4215 bool nmethod::has_code_comment(address begin, address end) {
4216   // scopes?
4217   ScopeDesc* sd  = scope_desc_in(begin, end);
4218   if (sd != nullptr) return true;
4219 
4220   // relocations?
4221   const char* str = reloc_string_for(begin, end);
4222   if (str != nullptr) return true;
4223 
4224   // implicit exceptions?
4225   int cont_offset = ImplicitExceptionTable(this).continuation_offset((uint)(begin - code_begin()));
4226   if (cont_offset != 0) return true;
4227 
4228   return false;
4229 }
4230 

4314             else
4315               st->print("<UNKNOWN>");
4316             break;
4317           }
4318         case Bytecodes::_getfield:
4319         case Bytecodes::_putfield:
4320         case Bytecodes::_getstatic:
4321         case Bytecodes::_putstatic:
4322           {
4323             Bytecode_field field(methodHandle(thread, sd->method()), sd->bci());
4324             st->print(" ");
4325             if (field.name() != nullptr)
4326               field.name()->print_symbol_on(st);
4327             else
4328               st->print("<UNKNOWN>");
4329           }
4330         default:
4331           break;
4332         }
4333       }
4334       st->print(" {reexecute=%d rethrow=%d return_oop=%d return_scalarized=%d}", sd->should_reexecute(), sd->rethrow_exception(), sd->return_oop(), sd->return_scalarized());
4335     }
4336 
4337     // Print all scopes
4338     for (;sd != nullptr; sd = sd->sender()) {
4339       st->move_to(column, 6, 0);
4340       st->print("; -");
4341       if (sd->should_reexecute()) {
4342         st->print(" (reexecute)");
4343       }
4344       if (sd->method() == nullptr) {
4345         st->print("method is nullptr");
4346       } else {
4347         sd->method()->print_short_name(st);
4348       }
4349       int lineno = sd->method()->line_number_from_bci(sd->bci());
4350       if (lineno != -1) {
4351         st->print("@%d (line %d)", sd->bci(), lineno);
4352       } else {
4353         st->print("@%d", sd->bci());
4354       }
< prev index next >