695
696 // handle the case of an anchor explicitly set in continuation code that doesn't have a callee
697 JavaThread* thread = reg_map->thread();
698 if ((thread->has_last_Java_frame() && fr.sp() == thread->last_Java_sp())
699 JVMTI_ONLY(|| (method()->is_continuation_enter_intrinsic() && thread->on_monitor_waited_event()))) {
700 return;
701 }
702
703 if (!method()->is_native()) {
704 address pc = fr.pc();
705 bool has_receiver, has_appendix;
706 Symbol* signature;
707
708 // The method attached by JIT-compilers should be used, if present.
709 // Bytecode can be inaccurate in such case.
710 Method* callee = attached_method_before_pc(pc);
711 if (callee != nullptr) {
712 has_receiver = !(callee->access_flags().is_static());
713 has_appendix = false;
714 signature = callee->signature();
715 } else {
716 SimpleScopeDesc ssd(this, pc);
717
718 Bytecode_invoke call(methodHandle(Thread::current(), ssd.method()), ssd.bci());
719 has_receiver = call.has_receiver();
720 has_appendix = call.has_appendix();
721 signature = call.signature();
722 }
723
724 fr.oops_compiled_arguments_do(signature, has_receiver, has_appendix, reg_map, f);
725 } else if (method()->is_continuation_enter_intrinsic()) {
726 // This method only calls Continuation.enter()
727 Symbol* signature = vmSymbols::continuationEnter_signature();
728 fr.oops_compiled_arguments_do(signature, false, false, reg_map, f);
729 }
730 }
731
732 Method* nmethod::attached_method(address call_instr) {
733 assert(code_contains(call_instr), "not part of the nmethod");
734 RelocIterator iter(this, call_instr, call_instr + 1);
1225
1226 _has_unsafe_access = 0;
1227 _has_wide_vectors = 0;
1228 _has_monitors = 0;
1229 _has_scoped_access = 0;
1230 _has_flushed_dependencies = 0;
1231 _is_unlinked = 0;
1232 _load_reported = 0; // jvmti state
1233
1234 _deoptimization_status = not_marked;
1235
1236 // SECT_CONSTS is first in code buffer so the offset should be 0.
1237 int consts_offset = code_buffer->total_offset_of(code_buffer->consts());
1238 assert(consts_offset == 0, "const_offset: %d", consts_offset);
1239
1240 _stub_offset = content_offset() + code_buffer->total_offset_of(code_buffer->stubs());
1241
1242 CHECKED_CAST(_entry_offset, uint16_t, (offsets->value(CodeOffsets::Entry)));
1243 CHECKED_CAST(_verified_entry_offset, uint16_t, (offsets->value(CodeOffsets::Verified_Entry)));
1244
1245 _skipped_instructions_size = code_buffer->total_skipped_instructions_size();
1246 }
1247
1248 // Post initialization
1249 void nmethod::post_init() {
1250 clear_unloading_state();
1251
1252 finalize_relocations();
1253
1254 Universe::heap()->register_nmethod(this);
1255 DEBUG_ONLY(Universe::heap()->verify_nmethod(this));
1256
1257 CodeCache::commit(this);
1258 }
1259
1260 // For native wrappers
1261 nmethod::nmethod(
1262 Method* method,
1263 CompilerType type,
1264 int nmethod_size,
1265 int compile_id,
1266 CodeOffsets* offsets,
1267 CodeBuffer* code_buffer,
1268 int frame_size,
1269 ByteSize basic_lock_owner_sp_offset,
1270 ByteSize basic_lock_sp_offset,
1271 OopMapSet* oop_maps,
1272 int mutable_data_size)
1273 : CodeBlob("native nmethod", CodeBlobKind::Nmethod, code_buffer, nmethod_size, sizeof(nmethod),
1274 offsets->value(CodeOffsets::Frame_Complete), frame_size, oop_maps, false, mutable_data_size),
1275 _deoptimization_generation(0),
1276 _gc_epoch(CodeCache::gc_epoch()),
1277 _method(method),
1278 _native_receiver_sp_offset(basic_lock_owner_sp_offset),
1279 _native_basic_lock_sp_offset(basic_lock_sp_offset)
1280 {
1281 {
1282 DEBUG_ONLY(NoSafepointVerifier nsv;)
1283 assert_locked_or_safepoint(CodeCache_lock);
1284
1285 init_defaults(code_buffer, offsets);
1286
1287 _osr_entry_point = nullptr;
1288 _pc_desc_container = nullptr;
1289 _entry_bci = InvocationEntryBci;
1290 _compile_id = compile_id;
1291 _comp_level = CompLevel_none;
1292 _compiler_type = type;
1293 _orig_pc_offset = 0;
1294 _num_stack_arg_slots = 0;
1295
1296 if (offsets->value(CodeOffsets::Exceptions) != -1) {
1297 // Continuation enter intrinsic
1298 _exception_offset = code_offset() + offsets->value(CodeOffsets::Exceptions);
1299 } else {
1300 _exception_offset = 0;
1301 }
1302 // Native wrappers do not have deopt handlers. Make the values
1303 // something that will never match a pc like the nmethod vtable entry
1304 _deopt_handler_offset = 0;
1713 assert(offsets->value(CodeOffsets::Deopt ) != -1, "must be set");
1714
1715 _exception_offset = _stub_offset + offsets->value(CodeOffsets::Exceptions);
1716 _deopt_handler_offset = _stub_offset + offsets->value(CodeOffsets::Deopt);
1717 }
1718 if (offsets->value(CodeOffsets::UnwindHandler) != -1) {
1719 // C1 generates UnwindHandler at the end of instructions section.
1720 // Calculate positive offset as distance between the start of stubs section
1721 // (which is also the end of instructions section) and the start of the handler.
1722 int unwind_handler_offset = code_offset() + offsets->value(CodeOffsets::UnwindHandler);
1723 CHECKED_CAST(_unwind_handler_offset, int16_t, (_stub_offset - unwind_handler_offset));
1724 } else {
1725 _unwind_handler_offset = -1;
1726 }
1727
1728 CHECKED_CAST(_oops_size, uint16_t, align_up(code_buffer->total_oop_size(), oopSize));
1729 uint16_t metadata_size;
1730 CHECKED_CAST(metadata_size, uint16_t, align_up(code_buffer->total_metadata_size(), wordSize));
1731 JVMCI_ONLY( _metadata_size = metadata_size; )
1732 int jvmci_data_size = 0 JVMCI_ONLY( + align_up(compiler->is_jvmci() ? jvmci_data->size() : 0, oopSize));
1733 assert(_mutable_data_size == _relocation_size + metadata_size + jvmci_data_size,
1734 "wrong mutable data size: %d != %d + %d + %d",
1735 _mutable_data_size, _relocation_size, metadata_size, jvmci_data_size);
1736 assert(nmethod_size == data_end() - header_begin(), "wrong nmethod size: %d != %d",
1737 nmethod_size, (int)(code_end() - header_begin()));
1738
1739 _immutable_data_size = immutable_data_size;
1740 if (immutable_data_size > 0) {
1741 assert(immutable_data != nullptr, "required");
1742 _immutable_data = immutable_data;
1743 } else {
1744 // We need unique not null address
1745 _immutable_data = blob_end();
1746 }
1747 CHECKED_CAST(_nul_chk_table_offset, uint16_t, (align_up((int)dependencies->size_in_bytes(), oopSize)));
1748 CHECKED_CAST(_handler_table_offset, uint16_t, (_nul_chk_table_offset + align_up(nul_chk_table->size_in_bytes(), oopSize)));
1749 _scopes_pcs_offset = _handler_table_offset + align_up(handler_table->size_in_bytes(), oopSize);
1750 _scopes_data_offset = _scopes_pcs_offset + adjust_pcs_size(debug_info->pcs_size());
1751
1752 #if INCLUDE_JVMCI
3124 }
3125
3126 bool nmethod::check_dependency_on(DepChange& changes) {
3127 // What has happened:
3128 // 1) a new class dependee has been added
3129 // 2) dependee and all its super classes have been marked
3130 bool found_check = false; // set true if we are upset
3131 for (Dependencies::DepStream deps(this); deps.next(); ) {
3132 // Evaluate only relevant dependencies.
3133 if (deps.spot_check_dependency_at(changes) != nullptr) {
3134 found_check = true;
3135 NOT_DEBUG(break);
3136 }
3137 }
3138 return found_check;
3139 }
3140
3141 // Called from mark_for_deoptimization, when dependee is invalidated.
3142 bool nmethod::is_dependent_on_method(Method* dependee) {
3143 for (Dependencies::DepStream deps(this); deps.next(); ) {
3144 if (deps.type() != Dependencies::evol_method)
3145 continue;
3146 Method* method = deps.method_argument(0);
3147 if (method == dependee) return true;
3148 }
3149 return false;
3150 }
3151
3152 void nmethod_init() {
3153 // make sure you didn't forget to adjust the filler fields
3154 assert(sizeof(nmethod) % oopSize == 0, "nmethod size must be multiple of a word");
3155 }
3156
3157 // -----------------------------------------------------------------------------
3158 // Verification
3159
3160 class VerifyOopsClosure: public OopClosure {
3161 nmethod* _nm;
3162 bool _ok;
3163 public:
3164 VerifyOopsClosure(nmethod* nm) : _nm(nm), _ok(true) { }
3165 bool ok() { return _ok; }
3166 virtual void do_oop(oop* p) {
3167 if (oopDesc::is_oop_or_null(*p)) return;
3965 return st.as_string();
3966 }
3967 }
3968 }
3969 return have_one ? "other" : nullptr;
3970 }
3971
3972 // Return the last scope in (begin..end]
3973 ScopeDesc* nmethod::scope_desc_in(address begin, address end) {
3974 PcDesc* p = pc_desc_near(begin+1);
3975 if (p != nullptr && p->real_pc(this) <= end) {
3976 return new ScopeDesc(this, p);
3977 }
3978 return nullptr;
3979 }
3980
3981 const char* nmethod::nmethod_section_label(address pos) const {
3982 const char* label = nullptr;
3983 if (pos == code_begin()) label = "[Instructions begin]";
3984 if (pos == entry_point()) label = "[Entry Point]";
3985 if (pos == verified_entry_point()) label = "[Verified Entry Point]";
3986 if (pos == consts_begin() && pos != insts_begin()) label = "[Constants]";
3987 // Check stub_code before checking exception_handler or deopt_handler.
3988 if (pos == this->stub_begin()) label = "[Stub Code]";
3989 if (JVMCI_ONLY(_exception_offset >= 0 &&) pos == exception_begin()) label = "[Exception Handler]";
3990 if (JVMCI_ONLY(_deopt_handler_offset != -1 &&) pos == deopt_handler_begin()) label = "[Deopt Handler Code]";
3991 return label;
3992 }
3993
3994 void nmethod::print_nmethod_labels(outputStream* stream, address block_begin, bool print_section_labels) const {
3995 if (print_section_labels) {
3996 const char* label = nmethod_section_label(block_begin);
3997 if (label != nullptr) {
3998 stream->bol();
3999 stream->print_cr("%s", label);
4000 }
4001 }
4002
4003 if (block_begin == entry_point()) {
4004 Method* m = method();
4005 if (m != nullptr) {
4006 stream->print(" # ");
4007 m->print_value_on(stream);
4008 stream->cr();
4009 }
4010 if (m != nullptr && !is_osr_method()) {
4011 ResourceMark rm;
4012 int sizeargs = m->size_of_parameters();
4013 BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sizeargs);
4014 VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, sizeargs);
4015 {
4016 int sig_index = 0;
4017 if (!m->is_static())
4018 sig_bt[sig_index++] = T_OBJECT; // 'this'
4019 for (SignatureStream ss(m->signature()); !ss.at_return_type(); ss.next()) {
4020 BasicType t = ss.type();
4021 sig_bt[sig_index++] = t;
4022 if (type2size[t] == 2) {
4023 sig_bt[sig_index++] = T_VOID;
4024 } else {
4025 assert(type2size[t] == 1, "size is 1 or 2");
4026 }
4027 }
4028 assert(sig_index == sizeargs, "");
4029 }
4030 const char* spname = "sp"; // make arch-specific?
4031 SharedRuntime::java_calling_convention(sig_bt, regs, sizeargs);
4032 int stack_slot_offset = this->frame_size() * wordSize;
4033 int tab1 = 14, tab2 = 24;
4034 int sig_index = 0;
4035 int arg_index = (m->is_static() ? 0 : -1);
4036 bool did_old_sp = false;
4037 for (SignatureStream ss(m->signature()); !ss.at_return_type(); ) {
4038 bool at_this = (arg_index == -1);
4039 bool at_old_sp = false;
4040 BasicType t = (at_this ? T_OBJECT : ss.type());
4041 assert(t == sig_bt[sig_index], "sigs in sync");
4042 if (at_this)
4043 stream->print(" # this: ");
4044 else
4045 stream->print(" # parm%d: ", arg_index);
4046 stream->move_to(tab1);
4047 VMReg fst = regs[sig_index].first();
4048 VMReg snd = regs[sig_index].second();
4049 if (fst->is_reg()) {
4050 stream->print("%s", fst->name());
4051 if (snd->is_valid()) {
4052 stream->print(":%s", snd->name());
4053 }
4054 } else if (fst->is_stack()) {
4055 int offset = fst->reg2stack() * VMRegImpl::stack_slot_size + stack_slot_offset;
4056 if (offset == stack_slot_offset) at_old_sp = true;
4057 stream->print("[%s+0x%x]", spname, offset);
4058 } else {
4059 stream->print("reg%d:%d??", (int)(intptr_t)fst, (int)(intptr_t)snd);
4060 }
4061 stream->print(" ");
4062 stream->move_to(tab2);
4063 stream->print("= ");
4064 if (at_this) {
4065 m->method_holder()->print_value_on(stream);
4066 } else {
4067 bool did_name = false;
4068 if (!at_this && ss.is_reference()) {
4069 Symbol* name = ss.as_symbol();
4070 name->print_value_on(stream);
4071 did_name = true;
4072 }
4073 if (!did_name)
4074 stream->print("%s", type2name(t));
4075 }
4076 if (at_old_sp) {
4077 stream->print(" (%s of caller)", spname);
4078 did_old_sp = true;
4079 }
4080 stream->cr();
4081 sig_index += type2size[t];
4082 arg_index += 1;
4083 if (!at_this) ss.next();
4084 }
4085 if (!did_old_sp) {
4086 stream->print(" # ");
4087 stream->move_to(tab1);
4088 stream->print("[%s+0x%x]", spname, stack_slot_offset);
4089 stream->print(" (%s of caller)", spname);
4090 stream->cr();
4091 }
4092 }
4093 }
4094 }
4095
4096 // Returns whether this nmethod has code comments.
4097 bool nmethod::has_code_comment(address begin, address end) {
4098 // scopes?
4099 ScopeDesc* sd = scope_desc_in(begin, end);
4100 if (sd != nullptr) return true;
4101
4102 // relocations?
4103 const char* str = reloc_string_for(begin, end);
4104 if (str != nullptr) return true;
4105
4106 // implicit exceptions?
4107 int cont_offset = ImplicitExceptionTable(this).continuation_offset((uint)(begin - code_begin()));
4108 if (cont_offset != 0) return true;
4109
4110 return false;
4111 }
4112
4196 else
4197 st->print("<UNKNOWN>");
4198 break;
4199 }
4200 case Bytecodes::_getfield:
4201 case Bytecodes::_putfield:
4202 case Bytecodes::_getstatic:
4203 case Bytecodes::_putstatic:
4204 {
4205 Bytecode_field field(methodHandle(thread, sd->method()), sd->bci());
4206 st->print(" ");
4207 if (field.name() != nullptr)
4208 field.name()->print_symbol_on(st);
4209 else
4210 st->print("<UNKNOWN>");
4211 }
4212 default:
4213 break;
4214 }
4215 }
4216 st->print(" {reexecute=%d rethrow=%d return_oop=%d}", sd->should_reexecute(), sd->rethrow_exception(), sd->return_oop());
4217 }
4218
4219 // Print all scopes
4220 for (;sd != nullptr; sd = sd->sender()) {
4221 st->move_to(column, 6, 0);
4222 st->print("; -");
4223 if (sd->should_reexecute()) {
4224 st->print(" (reexecute)");
4225 }
4226 if (sd->method() == nullptr) {
4227 st->print("method is nullptr");
4228 } else {
4229 sd->method()->print_short_name(st);
4230 }
4231 int lineno = sd->method()->line_number_from_bci(sd->bci());
4232 if (lineno != -1) {
4233 st->print("@%d (line %d)", sd->bci(), lineno);
4234 } else {
4235 st->print("@%d", sd->bci());
4236 }
|
695
696 // handle the case of an anchor explicitly set in continuation code that doesn't have a callee
697 JavaThread* thread = reg_map->thread();
698 if ((thread->has_last_Java_frame() && fr.sp() == thread->last_Java_sp())
699 JVMTI_ONLY(|| (method()->is_continuation_enter_intrinsic() && thread->on_monitor_waited_event()))) {
700 return;
701 }
702
703 if (!method()->is_native()) {
704 address pc = fr.pc();
705 bool has_receiver, has_appendix;
706 Symbol* signature;
707
708 // The method attached by JIT-compilers should be used, if present.
709 // Bytecode can be inaccurate in such case.
710 Method* callee = attached_method_before_pc(pc);
711 if (callee != nullptr) {
712 has_receiver = !(callee->access_flags().is_static());
713 has_appendix = false;
714 signature = callee->signature();
715
716 // If inline types are passed as fields, use the extended signature
717 // which contains the types of all (oop) fields of the inline type.
718 if (is_compiled_by_c2() && callee->has_scalarized_args()) {
719 const GrowableArray<SigEntry>* sig = callee->adapter()->get_sig_cc();
720 assert(sig != nullptr, "sig should never be null");
721 TempNewSymbol tmp_sig = SigEntry::create_symbol(sig);
722 has_receiver = false; // The extended signature contains the receiver type
723 fr.oops_compiled_arguments_do(tmp_sig, has_receiver, has_appendix, reg_map, f);
724 return;
725 }
726 } else {
727 SimpleScopeDesc ssd(this, pc);
728
729 Bytecode_invoke call(methodHandle(Thread::current(), ssd.method()), ssd.bci());
730 has_receiver = call.has_receiver();
731 has_appendix = call.has_appendix();
732 signature = call.signature();
733 }
734
735 fr.oops_compiled_arguments_do(signature, has_receiver, has_appendix, reg_map, f);
736 } else if (method()->is_continuation_enter_intrinsic()) {
737 // This method only calls Continuation.enter()
738 Symbol* signature = vmSymbols::continuationEnter_signature();
739 fr.oops_compiled_arguments_do(signature, false, false, reg_map, f);
740 }
741 }
742
743 Method* nmethod::attached_method(address call_instr) {
744 assert(code_contains(call_instr), "not part of the nmethod");
745 RelocIterator iter(this, call_instr, call_instr + 1);
1236
1237 _has_unsafe_access = 0;
1238 _has_wide_vectors = 0;
1239 _has_monitors = 0;
1240 _has_scoped_access = 0;
1241 _has_flushed_dependencies = 0;
1242 _is_unlinked = 0;
1243 _load_reported = 0; // jvmti state
1244
1245 _deoptimization_status = not_marked;
1246
1247 // SECT_CONSTS is first in code buffer so the offset should be 0.
1248 int consts_offset = code_buffer->total_offset_of(code_buffer->consts());
1249 assert(consts_offset == 0, "const_offset: %d", consts_offset);
1250
1251 _stub_offset = content_offset() + code_buffer->total_offset_of(code_buffer->stubs());
1252
1253 CHECKED_CAST(_entry_offset, uint16_t, (offsets->value(CodeOffsets::Entry)));
1254 CHECKED_CAST(_verified_entry_offset, uint16_t, (offsets->value(CodeOffsets::Verified_Entry)));
1255
1256 _inline_entry_point = entry_point();
1257 _verified_inline_entry_point = verified_entry_point();
1258 _verified_inline_ro_entry_point = verified_entry_point();
1259
1260 _skipped_instructions_size = code_buffer->total_skipped_instructions_size();
1261 }
1262
1263 // Post initialization
1264 void nmethod::post_init() {
1265 clear_unloading_state();
1266
1267 finalize_relocations();
1268
1269 Universe::heap()->register_nmethod(this);
1270 DEBUG_ONLY(Universe::heap()->verify_nmethod(this));
1271
1272 CodeCache::commit(this);
1273 }
1274
1275 // For native wrappers
1276 nmethod::nmethod(
1277 Method* method,
1278 CompilerType type,
1279 int nmethod_size,
1280 int compile_id,
1281 CodeOffsets* offsets,
1282 CodeBuffer* code_buffer,
1283 int frame_size,
1284 ByteSize basic_lock_owner_sp_offset,
1285 ByteSize basic_lock_sp_offset,
1286 OopMapSet* oop_maps,
1287 int mutable_data_size)
1288 : CodeBlob("native nmethod", CodeBlobKind::Nmethod, code_buffer, nmethod_size, sizeof(nmethod),
1289 offsets->value(CodeOffsets::Frame_Complete), frame_size, oop_maps, false, mutable_data_size),
1290 _deoptimization_generation(0),
1291 _gc_epoch(CodeCache::gc_epoch()),
1292 _method(method),
1293 _native_receiver_sp_offset(basic_lock_owner_sp_offset),
1294 _native_basic_lock_sp_offset(basic_lock_sp_offset)
1295 {
1296 {
1297 DEBUG_ONLY(NoSafepointVerifier nsv;)
1298 assert_locked_or_safepoint(CodeCache_lock);
1299 assert(!method->has_scalarized_args(), "scalarized native wrappers not supported yet");
1300 init_defaults(code_buffer, offsets);
1301
1302 _osr_entry_point = nullptr;
1303 _pc_desc_container = nullptr;
1304 _entry_bci = InvocationEntryBci;
1305 _compile_id = compile_id;
1306 _comp_level = CompLevel_none;
1307 _compiler_type = type;
1308 _orig_pc_offset = 0;
1309 _num_stack_arg_slots = 0;
1310
1311 if (offsets->value(CodeOffsets::Exceptions) != -1) {
1312 // Continuation enter intrinsic
1313 _exception_offset = code_offset() + offsets->value(CodeOffsets::Exceptions);
1314 } else {
1315 _exception_offset = 0;
1316 }
1317 // Native wrappers do not have deopt handlers. Make the values
1318 // something that will never match a pc like the nmethod vtable entry
1319 _deopt_handler_offset = 0;
1728 assert(offsets->value(CodeOffsets::Deopt ) != -1, "must be set");
1729
1730 _exception_offset = _stub_offset + offsets->value(CodeOffsets::Exceptions);
1731 _deopt_handler_offset = _stub_offset + offsets->value(CodeOffsets::Deopt);
1732 }
1733 if (offsets->value(CodeOffsets::UnwindHandler) != -1) {
1734 // C1 generates UnwindHandler at the end of instructions section.
1735 // Calculate positive offset as distance between the start of stubs section
1736 // (which is also the end of instructions section) and the start of the handler.
1737 int unwind_handler_offset = code_offset() + offsets->value(CodeOffsets::UnwindHandler);
1738 CHECKED_CAST(_unwind_handler_offset, int16_t, (_stub_offset - unwind_handler_offset));
1739 } else {
1740 _unwind_handler_offset = -1;
1741 }
1742
1743 CHECKED_CAST(_oops_size, uint16_t, align_up(code_buffer->total_oop_size(), oopSize));
1744 uint16_t metadata_size;
1745 CHECKED_CAST(metadata_size, uint16_t, align_up(code_buffer->total_metadata_size(), wordSize));
1746 JVMCI_ONLY( _metadata_size = metadata_size; )
1747 int jvmci_data_size = 0 JVMCI_ONLY( + align_up(compiler->is_jvmci() ? jvmci_data->size() : 0, oopSize));
1748 _inline_entry_point = code_begin() + offsets->value(CodeOffsets::Inline_Entry);
1749 _verified_inline_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Inline_Entry);
1750 _verified_inline_ro_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Inline_Entry_RO);
1751
1752 assert(_mutable_data_size == _relocation_size + metadata_size + jvmci_data_size,
1753 "wrong mutable data size: %d != %d + %d + %d",
1754 _mutable_data_size, _relocation_size, metadata_size, jvmci_data_size);
1755 assert(nmethod_size == data_end() - header_begin(), "wrong nmethod size: %d != %d",
1756 nmethod_size, (int)(code_end() - header_begin()));
1757
1758 _immutable_data_size = immutable_data_size;
1759 if (immutable_data_size > 0) {
1760 assert(immutable_data != nullptr, "required");
1761 _immutable_data = immutable_data;
1762 } else {
1763 // We need unique not null address
1764 _immutable_data = blob_end();
1765 }
1766 CHECKED_CAST(_nul_chk_table_offset, uint16_t, (align_up((int)dependencies->size_in_bytes(), oopSize)));
1767 CHECKED_CAST(_handler_table_offset, uint16_t, (_nul_chk_table_offset + align_up(nul_chk_table->size_in_bytes(), oopSize)));
1768 _scopes_pcs_offset = _handler_table_offset + align_up(handler_table->size_in_bytes(), oopSize);
1769 _scopes_data_offset = _scopes_pcs_offset + adjust_pcs_size(debug_info->pcs_size());
1770
1771 #if INCLUDE_JVMCI
3143 }
3144
3145 bool nmethod::check_dependency_on(DepChange& changes) {
3146 // What has happened:
3147 // 1) a new class dependee has been added
3148 // 2) dependee and all its super classes have been marked
3149 bool found_check = false; // set true if we are upset
3150 for (Dependencies::DepStream deps(this); deps.next(); ) {
3151 // Evaluate only relevant dependencies.
3152 if (deps.spot_check_dependency_at(changes) != nullptr) {
3153 found_check = true;
3154 NOT_DEBUG(break);
3155 }
3156 }
3157 return found_check;
3158 }
3159
3160 // Called from mark_for_deoptimization, when dependee is invalidated.
3161 bool nmethod::is_dependent_on_method(Method* dependee) {
3162 for (Dependencies::DepStream deps(this); deps.next(); ) {
3163 if (Dependencies::has_method_dep(deps.type())) {
3164 Method* method = deps.method_argument(0);
3165 if (method == dependee) return true;
3166 }
3167 }
3168 return false;
3169 }
3170
3171 void nmethod_init() {
3172 // make sure you didn't forget to adjust the filler fields
3173 assert(sizeof(nmethod) % oopSize == 0, "nmethod size must be multiple of a word");
3174 }
3175
3176 // -----------------------------------------------------------------------------
3177 // Verification
3178
3179 class VerifyOopsClosure: public OopClosure {
3180 nmethod* _nm;
3181 bool _ok;
3182 public:
3183 VerifyOopsClosure(nmethod* nm) : _nm(nm), _ok(true) { }
3184 bool ok() { return _ok; }
3185 virtual void do_oop(oop* p) {
3186 if (oopDesc::is_oop_or_null(*p)) return;
3984 return st.as_string();
3985 }
3986 }
3987 }
3988 return have_one ? "other" : nullptr;
3989 }
3990
3991 // Return the last scope in (begin..end]
3992 ScopeDesc* nmethod::scope_desc_in(address begin, address end) {
3993 PcDesc* p = pc_desc_near(begin+1);
3994 if (p != nullptr && p->real_pc(this) <= end) {
3995 return new ScopeDesc(this, p);
3996 }
3997 return nullptr;
3998 }
3999
4000 const char* nmethod::nmethod_section_label(address pos) const {
4001 const char* label = nullptr;
4002 if (pos == code_begin()) label = "[Instructions begin]";
4003 if (pos == entry_point()) label = "[Entry Point]";
4004 if (pos == inline_entry_point()) label = "[Inline Entry Point]";
4005 if (pos == verified_entry_point()) label = "[Verified Entry Point]";
4006 if (pos == verified_inline_entry_point()) label = "[Verified Inline Entry Point]";
4007 if (pos == verified_inline_ro_entry_point()) label = "[Verified Inline Entry Point (RO)]";
4008 if (pos == consts_begin() && pos != insts_begin()) label = "[Constants]";
4009 // Check stub_code before checking exception_handler or deopt_handler.
4010 if (pos == this->stub_begin()) label = "[Stub Code]";
4011 if (JVMCI_ONLY(_exception_offset >= 0 &&) pos == exception_begin()) label = "[Exception Handler]";
4012 if (JVMCI_ONLY(_deopt_handler_offset != -1 &&) pos == deopt_handler_begin()) label = "[Deopt Handler Code]";
4013 return label;
4014 }
4015
4016 static int maybe_print_entry_label(outputStream* stream, address pos, address entry, const char* label) {
4017 if (pos == entry) {
4018 stream->bol();
4019 stream->print_cr("%s", label);
4020 return 1;
4021 } else {
4022 return 0;
4023 }
4024 }
4025
4026 void nmethod::print_nmethod_labels(outputStream* stream, address block_begin, bool print_section_labels) const {
4027 if (print_section_labels) {
4028 int n = 0;
4029 // Multiple entry points may be at the same position. Print them all.
4030 n += maybe_print_entry_label(stream, block_begin, entry_point(), "[Entry Point]");
4031 n += maybe_print_entry_label(stream, block_begin, inline_entry_point(), "[Inline Entry Point]");
4032 n += maybe_print_entry_label(stream, block_begin, verified_entry_point(), "[Verified Entry Point]");
4033 n += maybe_print_entry_label(stream, block_begin, verified_inline_entry_point(), "[Verified Inline Entry Point]");
4034 n += maybe_print_entry_label(stream, block_begin, verified_inline_ro_entry_point(), "[Verified Inline Entry Point (RO)]");
4035 if (n == 0) {
4036 const char* label = nmethod_section_label(block_begin);
4037 if (label != nullptr) {
4038 stream->bol();
4039 stream->print_cr("%s", label);
4040 }
4041 }
4042 }
4043
4044 Method* m = method();
4045 if (m == nullptr || is_osr_method()) {
4046 return;
4047 }
4048
4049 // Print the name of the method (only once)
4050 address low = MIN3(entry_point(),
4051 verified_entry_point(),
4052 inline_entry_point());
4053 // The verified inline entry point and verified inline RO entry point are not always
4054 // used. When they are unused. CodeOffsets::Verified_Inline_Entry(_RO) is -1. Hence,
4055 // the calculated entry point is smaller than the block they are offsetting into.
4056 if (verified_inline_entry_point() >= block_begin) {
4057 low = MIN2(low, verified_inline_entry_point());
4058 }
4059 if (verified_inline_ro_entry_point() >= block_begin) {
4060 low = MIN2(low, verified_inline_ro_entry_point());
4061 }
4062 assert(low != 0, "sanity");
4063 if (block_begin == low) {
4064 stream->print(" # ");
4065 m->print_value_on(stream);
4066 stream->cr();
4067 }
4068
4069 // Print the arguments for the 3 types of verified entry points
4070 CompiledEntrySignature ces(m);
4071 ces.compute_calling_conventions(false);
4072 const GrowableArray<SigEntry>* sig_cc;
4073 const VMRegPair* regs;
4074 if (block_begin == verified_entry_point()) {
4075 sig_cc = ces.sig_cc();
4076 regs = ces.regs_cc();
4077 } else if (block_begin == verified_inline_entry_point()) {
4078 sig_cc = ces.sig();
4079 regs = ces.regs();
4080 } else if (block_begin == verified_inline_ro_entry_point()) {
4081 sig_cc = ces.sig_cc_ro();
4082 regs = ces.regs_cc_ro();
4083 } else {
4084 return;
4085 }
4086
4087 bool has_this = !m->is_static();
4088 if (ces.has_inline_recv() && block_begin == verified_entry_point()) {
4089 // <this> argument is scalarized for verified_entry_point()
4090 has_this = false;
4091 }
4092 const char* spname = "sp"; // make arch-specific?
4093 int stack_slot_offset = this->frame_size() * wordSize;
4094 int tab1 = 14, tab2 = 24;
4095 int sig_index = 0;
4096 int arg_index = has_this ? -1 : 0;
4097 bool did_old_sp = false;
4098 for (ExtendedSignature sig = ExtendedSignature(sig_cc, SigEntryFilter()); !sig.at_end(); ++sig) {
4099 bool at_this = (arg_index == -1);
4100 bool at_old_sp = false;
4101 BasicType t = (*sig)._bt;
4102 if (at_this) {
4103 stream->print(" # this: ");
4104 } else {
4105 stream->print(" # parm%d: ", arg_index);
4106 }
4107 stream->move_to(tab1);
4108 VMReg fst = regs[sig_index].first();
4109 VMReg snd = regs[sig_index].second();
4110 if (fst->is_reg()) {
4111 stream->print("%s", fst->name());
4112 if (snd->is_valid()) {
4113 stream->print(":%s", snd->name());
4114 }
4115 } else if (fst->is_stack()) {
4116 int offset = fst->reg2stack() * VMRegImpl::stack_slot_size + stack_slot_offset;
4117 if (offset == stack_slot_offset) at_old_sp = true;
4118 stream->print("[%s+0x%x]", spname, offset);
4119 } else {
4120 stream->print("reg%d:%d??", (int)(intptr_t)fst, (int)(intptr_t)snd);
4121 }
4122 stream->print(" ");
4123 stream->move_to(tab2);
4124 stream->print("= ");
4125 if (at_this) {
4126 m->method_holder()->print_value_on(stream);
4127 } else {
4128 bool did_name = false;
4129 if (is_reference_type(t)) {
4130 Symbol* name = (*sig)._name;
4131 name->print_value_on(stream);
4132 did_name = true;
4133 }
4134 if (!did_name)
4135 stream->print("%s", type2name(t));
4136 if ((*sig)._null_marker) {
4137 stream->print(" (null marker)");
4138 }
4139 }
4140 if (at_old_sp) {
4141 stream->print(" (%s of caller)", spname);
4142 did_old_sp = true;
4143 }
4144 stream->cr();
4145 sig_index += type2size[t];
4146 arg_index += 1;
4147 }
4148 if (!did_old_sp) {
4149 stream->print(" # ");
4150 stream->move_to(tab1);
4151 stream->print("[%s+0x%x]", spname, stack_slot_offset);
4152 stream->print(" (%s of caller)", spname);
4153 stream->cr();
4154 }
4155 }
4156
4157 // Returns whether this nmethod has code comments.
4158 bool nmethod::has_code_comment(address begin, address end) {
4159 // scopes?
4160 ScopeDesc* sd = scope_desc_in(begin, end);
4161 if (sd != nullptr) return true;
4162
4163 // relocations?
4164 const char* str = reloc_string_for(begin, end);
4165 if (str != nullptr) return true;
4166
4167 // implicit exceptions?
4168 int cont_offset = ImplicitExceptionTable(this).continuation_offset((uint)(begin - code_begin()));
4169 if (cont_offset != 0) return true;
4170
4171 return false;
4172 }
4173
4257 else
4258 st->print("<UNKNOWN>");
4259 break;
4260 }
4261 case Bytecodes::_getfield:
4262 case Bytecodes::_putfield:
4263 case Bytecodes::_getstatic:
4264 case Bytecodes::_putstatic:
4265 {
4266 Bytecode_field field(methodHandle(thread, sd->method()), sd->bci());
4267 st->print(" ");
4268 if (field.name() != nullptr)
4269 field.name()->print_symbol_on(st);
4270 else
4271 st->print("<UNKNOWN>");
4272 }
4273 default:
4274 break;
4275 }
4276 }
4277 st->print(" {reexecute=%d rethrow=%d return_oop=%d return_scalarized=%d}", sd->should_reexecute(), sd->rethrow_exception(), sd->return_oop(), sd->return_scalarized());
4278 }
4279
4280 // Print all scopes
4281 for (;sd != nullptr; sd = sd->sender()) {
4282 st->move_to(column, 6, 0);
4283 st->print("; -");
4284 if (sd->should_reexecute()) {
4285 st->print(" (reexecute)");
4286 }
4287 if (sd->method() == nullptr) {
4288 st->print("method is nullptr");
4289 } else {
4290 sd->method()->print_short_name(st);
4291 }
4292 int lineno = sd->method()->line_number_from_bci(sd->bci());
4293 if (lineno != -1) {
4294 st->print("@%d (line %d)", sd->bci(), lineno);
4295 } else {
4296 st->print("@%d", sd->bci());
4297 }
|