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_offset = 0;
1716 assert(offsets->value(CodeOffsets::Deopt ) != -1, "must be set");
1717
1718 _exception_offset = _stub_offset + offsets->value(CodeOffsets::Exceptions);
1719 _deopt_handler_offset = _stub_offset + offsets->value(CodeOffsets::Deopt);
1720 }
1721 if (offsets->value(CodeOffsets::UnwindHandler) != -1) {
1722 // C1 generates UnwindHandler at the end of instructions section.
1723 // Calculate positive offset as distance between the start of stubs section
1724 // (which is also the end of instructions section) and the start of the handler.
1725 int unwind_handler_offset = code_offset() + offsets->value(CodeOffsets::UnwindHandler);
1726 CHECKED_CAST(_unwind_handler_offset, int16_t, (_stub_offset - unwind_handler_offset));
1727 } else {
1728 _unwind_handler_offset = -1;
1729 }
1730
1731 CHECKED_CAST(_oops_size, uint16_t, align_up(code_buffer->total_oop_size(), oopSize));
1732 uint16_t metadata_size;
1733 CHECKED_CAST(metadata_size, uint16_t, align_up(code_buffer->total_metadata_size(), wordSize));
1734 JVMCI_ONLY( _metadata_size = metadata_size; )
1735 int jvmci_data_size = 0 JVMCI_ONLY( + align_up(compiler->is_jvmci() ? jvmci_data->size() : 0, oopSize));
1736 assert(_mutable_data_size == _relocation_size + metadata_size + jvmci_data_size,
1737 "wrong mutable data size: %d != %d + %d + %d",
1738 _mutable_data_size, _relocation_size, metadata_size, jvmci_data_size);
1739 assert(nmethod_size == data_end() - header_begin(), "wrong nmethod size: %d != %d",
1740 nmethod_size, (int)(code_end() - header_begin()));
1741
1742 _immutable_data_size = immutable_data_size;
1743 if (immutable_data_size > 0) {
1744 assert(immutable_data != nullptr, "required");
1745 _immutable_data = immutable_data;
1746 } else {
1747 // We need unique not null address
1748 _immutable_data = blob_end();
1749 }
1750 CHECKED_CAST(_nul_chk_table_offset, uint16_t, (align_up((int)dependencies->size_in_bytes(), oopSize)));
1751 CHECKED_CAST(_handler_table_offset, uint16_t, (_nul_chk_table_offset + align_up(nul_chk_table->size_in_bytes(), oopSize)));
1752 _scopes_pcs_offset = _handler_table_offset + align_up(handler_table->size_in_bytes(), oopSize);
1753 _scopes_data_offset = _scopes_pcs_offset + adjust_pcs_size(debug_info->pcs_size());
1754
1755 #if INCLUDE_JVMCI
3166 }
3167
3168 bool nmethod::check_dependency_on(DepChange& changes) {
3169 // What has happened:
3170 // 1) a new class dependee has been added
3171 // 2) dependee and all its super classes have been marked
3172 bool found_check = false; // set true if we are upset
3173 for (Dependencies::DepStream deps(this); deps.next(); ) {
3174 // Evaluate only relevant dependencies.
3175 if (deps.spot_check_dependency_at(changes) != nullptr) {
3176 found_check = true;
3177 NOT_DEBUG(break);
3178 }
3179 }
3180 return found_check;
3181 }
3182
3183 // Called from mark_for_deoptimization, when dependee is invalidated.
3184 bool nmethod::is_dependent_on_method(Method* dependee) {
3185 for (Dependencies::DepStream deps(this); deps.next(); ) {
3186 if (deps.type() != Dependencies::evol_method)
3187 continue;
3188 Method* method = deps.method_argument(0);
3189 if (method == dependee) return true;
3190 }
3191 return false;
3192 }
3193
3194 void nmethod_init() {
3195 // make sure you didn't forget to adjust the filler fields
3196 assert(sizeof(nmethod) % oopSize == 0, "nmethod size must be multiple of a word");
3197 }
3198
3199 // -----------------------------------------------------------------------------
3200 // Verification
3201
3202 class VerifyOopsClosure: public OopClosure {
3203 nmethod* _nm;
3204 bool _ok;
3205 public:
3206 VerifyOopsClosure(nmethod* nm) : _nm(nm), _ok(true) { }
3207 bool ok() { return _ok; }
3208 virtual void do_oop(oop* p) {
3209 if (oopDesc::is_oop_or_null(*p)) return;
4007 return st.as_string();
4008 }
4009 }
4010 }
4011 return have_one ? "other" : nullptr;
4012 }
4013
4014 // Return the last scope in (begin..end]
4015 ScopeDesc* nmethod::scope_desc_in(address begin, address end) {
4016 PcDesc* p = pc_desc_near(begin+1);
4017 if (p != nullptr && p->real_pc(this) <= end) {
4018 return new ScopeDesc(this, p);
4019 }
4020 return nullptr;
4021 }
4022
4023 const char* nmethod::nmethod_section_label(address pos) const {
4024 const char* label = nullptr;
4025 if (pos == code_begin()) label = "[Instructions begin]";
4026 if (pos == entry_point()) label = "[Entry Point]";
4027 if (pos == verified_entry_point()) label = "[Verified Entry Point]";
4028 if (pos == consts_begin() && pos != insts_begin()) label = "[Constants]";
4029 // Check stub_code before checking exception_handler or deopt_handler.
4030 if (pos == this->stub_begin()) label = "[Stub Code]";
4031 if (JVMCI_ONLY(_exception_offset >= 0 &&) pos == exception_begin()) label = "[Exception Handler]";
4032 if (JVMCI_ONLY(_deopt_handler_offset != -1 &&) pos == deopt_handler_begin()) label = "[Deopt Handler Code]";
4033 return label;
4034 }
4035
4036 void nmethod::print_nmethod_labels(outputStream* stream, address block_begin, bool print_section_labels) const {
4037 if (print_section_labels) {
4038 const char* label = nmethod_section_label(block_begin);
4039 if (label != nullptr) {
4040 stream->bol();
4041 stream->print_cr("%s", label);
4042 }
4043 }
4044
4045 if (block_begin == entry_point()) {
4046 Method* m = method();
4047 if (m != nullptr) {
4048 stream->print(" # ");
4049 m->print_value_on(stream);
4050 stream->cr();
4051 }
4052 if (m != nullptr && !is_osr_method()) {
4053 ResourceMark rm;
4054 int sizeargs = m->size_of_parameters();
4055 BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sizeargs);
4056 VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, sizeargs);
4057 {
4058 int sig_index = 0;
4059 if (!m->is_static())
4060 sig_bt[sig_index++] = T_OBJECT; // 'this'
4061 for (SignatureStream ss(m->signature()); !ss.at_return_type(); ss.next()) {
4062 BasicType t = ss.type();
4063 sig_bt[sig_index++] = t;
4064 if (type2size[t] == 2) {
4065 sig_bt[sig_index++] = T_VOID;
4066 } else {
4067 assert(type2size[t] == 1, "size is 1 or 2");
4068 }
4069 }
4070 assert(sig_index == sizeargs, "");
4071 }
4072 const char* spname = "sp"; // make arch-specific?
4073 SharedRuntime::java_calling_convention(sig_bt, regs, sizeargs);
4074 int stack_slot_offset = this->frame_size() * wordSize;
4075 int tab1 = 14, tab2 = 24;
4076 int sig_index = 0;
4077 int arg_index = (m->is_static() ? 0 : -1);
4078 bool did_old_sp = false;
4079 for (SignatureStream ss(m->signature()); !ss.at_return_type(); ) {
4080 bool at_this = (arg_index == -1);
4081 bool at_old_sp = false;
4082 BasicType t = (at_this ? T_OBJECT : ss.type());
4083 assert(t == sig_bt[sig_index], "sigs in sync");
4084 if (at_this)
4085 stream->print(" # this: ");
4086 else
4087 stream->print(" # parm%d: ", arg_index);
4088 stream->move_to(tab1);
4089 VMReg fst = regs[sig_index].first();
4090 VMReg snd = regs[sig_index].second();
4091 if (fst->is_reg()) {
4092 stream->print("%s", fst->name());
4093 if (snd->is_valid()) {
4094 stream->print(":%s", snd->name());
4095 }
4096 } else if (fst->is_stack()) {
4097 int offset = fst->reg2stack() * VMRegImpl::stack_slot_size + stack_slot_offset;
4098 if (offset == stack_slot_offset) at_old_sp = true;
4099 stream->print("[%s+0x%x]", spname, offset);
4100 } else {
4101 stream->print("reg%d:%d??", (int)(intptr_t)fst, (int)(intptr_t)snd);
4102 }
4103 stream->print(" ");
4104 stream->move_to(tab2);
4105 stream->print("= ");
4106 if (at_this) {
4107 m->method_holder()->print_value_on(stream);
4108 } else {
4109 bool did_name = false;
4110 if (!at_this && ss.is_reference()) {
4111 Symbol* name = ss.as_symbol();
4112 name->print_value_on(stream);
4113 did_name = true;
4114 }
4115 if (!did_name)
4116 stream->print("%s", type2name(t));
4117 }
4118 if (at_old_sp) {
4119 stream->print(" (%s of caller)", spname);
4120 did_old_sp = true;
4121 }
4122 stream->cr();
4123 sig_index += type2size[t];
4124 arg_index += 1;
4125 if (!at_this) ss.next();
4126 }
4127 if (!did_old_sp) {
4128 stream->print(" # ");
4129 stream->move_to(tab1);
4130 stream->print("[%s+0x%x]", spname, stack_slot_offset);
4131 stream->print(" (%s of caller)", spname);
4132 stream->cr();
4133 }
4134 }
4135 }
4136 }
4137
4138 // Returns whether this nmethod has code comments.
4139 bool nmethod::has_code_comment(address begin, address end) {
4140 // scopes?
4141 ScopeDesc* sd = scope_desc_in(begin, end);
4142 if (sd != nullptr) return true;
4143
4144 // relocations?
4145 const char* str = reloc_string_for(begin, end);
4146 if (str != nullptr) return true;
4147
4148 // implicit exceptions?
4149 int cont_offset = ImplicitExceptionTable(this).continuation_offset((uint)(begin - code_begin()));
4150 if (cont_offset != 0) return true;
4151
4152 return false;
4153 }
4154
4238 else
4239 st->print("<UNKNOWN>");
4240 break;
4241 }
4242 case Bytecodes::_getfield:
4243 case Bytecodes::_putfield:
4244 case Bytecodes::_getstatic:
4245 case Bytecodes::_putstatic:
4246 {
4247 Bytecode_field field(methodHandle(thread, sd->method()), sd->bci());
4248 st->print(" ");
4249 if (field.name() != nullptr)
4250 field.name()->print_symbol_on(st);
4251 else
4252 st->print("<UNKNOWN>");
4253 }
4254 default:
4255 break;
4256 }
4257 }
4258 st->print(" {reexecute=%d rethrow=%d return_oop=%d}", sd->should_reexecute(), sd->rethrow_exception(), sd->return_oop());
4259 }
4260
4261 // Print all scopes
4262 for (;sd != nullptr; sd = sd->sender()) {
4263 st->move_to(column, 6, 0);
4264 st->print("; -");
4265 if (sd->should_reexecute()) {
4266 st->print(" (reexecute)");
4267 }
4268 if (sd->method() == nullptr) {
4269 st->print("method is nullptr");
4270 } else {
4271 sd->method()->print_short_name(st);
4272 }
4273 int lineno = sd->method()->line_number_from_bci(sd->bci());
4274 if (lineno != -1) {
4275 st->print("@%d (line %d)", sd->bci(), lineno);
4276 } else {
4277 st->print("@%d", sd->bci());
4278 }
|
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_offset = 0;
1731 assert(offsets->value(CodeOffsets::Deopt ) != -1, "must be set");
1732
1733 _exception_offset = _stub_offset + offsets->value(CodeOffsets::Exceptions);
1734 _deopt_handler_offset = _stub_offset + offsets->value(CodeOffsets::Deopt);
1735 }
1736 if (offsets->value(CodeOffsets::UnwindHandler) != -1) {
1737 // C1 generates UnwindHandler at the end of instructions section.
1738 // Calculate positive offset as distance between the start of stubs section
1739 // (which is also the end of instructions section) and the start of the handler.
1740 int unwind_handler_offset = code_offset() + offsets->value(CodeOffsets::UnwindHandler);
1741 CHECKED_CAST(_unwind_handler_offset, int16_t, (_stub_offset - unwind_handler_offset));
1742 } else {
1743 _unwind_handler_offset = -1;
1744 }
1745
1746 CHECKED_CAST(_oops_size, uint16_t, align_up(code_buffer->total_oop_size(), oopSize));
1747 uint16_t metadata_size;
1748 CHECKED_CAST(metadata_size, uint16_t, align_up(code_buffer->total_metadata_size(), wordSize));
1749 JVMCI_ONLY( _metadata_size = metadata_size; )
1750 int jvmci_data_size = 0 JVMCI_ONLY( + align_up(compiler->is_jvmci() ? jvmci_data->size() : 0, oopSize));
1751 _inline_entry_point = code_begin() + offsets->value(CodeOffsets::Inline_Entry);
1752 _verified_inline_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Inline_Entry);
1753 _verified_inline_ro_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Inline_Entry_RO);
1754
1755 assert(_mutable_data_size == _relocation_size + metadata_size + jvmci_data_size,
1756 "wrong mutable data size: %d != %d + %d + %d",
1757 _mutable_data_size, _relocation_size, metadata_size, jvmci_data_size);
1758 assert(nmethod_size == data_end() - header_begin(), "wrong nmethod size: %d != %d",
1759 nmethod_size, (int)(code_end() - header_begin()));
1760
1761 _immutable_data_size = immutable_data_size;
1762 if (immutable_data_size > 0) {
1763 assert(immutable_data != nullptr, "required");
1764 _immutable_data = immutable_data;
1765 } else {
1766 // We need unique not null address
1767 _immutable_data = blob_end();
1768 }
1769 CHECKED_CAST(_nul_chk_table_offset, uint16_t, (align_up((int)dependencies->size_in_bytes(), oopSize)));
1770 CHECKED_CAST(_handler_table_offset, uint16_t, (_nul_chk_table_offset + align_up(nul_chk_table->size_in_bytes(), oopSize)));
1771 _scopes_pcs_offset = _handler_table_offset + align_up(handler_table->size_in_bytes(), oopSize);
1772 _scopes_data_offset = _scopes_pcs_offset + adjust_pcs_size(debug_info->pcs_size());
1773
1774 #if INCLUDE_JVMCI
3185 }
3186
3187 bool nmethod::check_dependency_on(DepChange& changes) {
3188 // What has happened:
3189 // 1) a new class dependee has been added
3190 // 2) dependee and all its super classes have been marked
3191 bool found_check = false; // set true if we are upset
3192 for (Dependencies::DepStream deps(this); deps.next(); ) {
3193 // Evaluate only relevant dependencies.
3194 if (deps.spot_check_dependency_at(changes) != nullptr) {
3195 found_check = true;
3196 NOT_DEBUG(break);
3197 }
3198 }
3199 return found_check;
3200 }
3201
3202 // Called from mark_for_deoptimization, when dependee is invalidated.
3203 bool nmethod::is_dependent_on_method(Method* dependee) {
3204 for (Dependencies::DepStream deps(this); deps.next(); ) {
3205 if (Dependencies::has_method_dep(deps.type())) {
3206 Method* method = deps.method_argument(0);
3207 if (method == dependee) return true;
3208 }
3209 }
3210 return false;
3211 }
3212
3213 void nmethod_init() {
3214 // make sure you didn't forget to adjust the filler fields
3215 assert(sizeof(nmethod) % oopSize == 0, "nmethod size must be multiple of a word");
3216 }
3217
3218 // -----------------------------------------------------------------------------
3219 // Verification
3220
3221 class VerifyOopsClosure: public OopClosure {
3222 nmethod* _nm;
3223 bool _ok;
3224 public:
3225 VerifyOopsClosure(nmethod* nm) : _nm(nm), _ok(true) { }
3226 bool ok() { return _ok; }
3227 virtual void do_oop(oop* p) {
3228 if (oopDesc::is_oop_or_null(*p)) return;
4026 return st.as_string();
4027 }
4028 }
4029 }
4030 return have_one ? "other" : nullptr;
4031 }
4032
4033 // Return the last scope in (begin..end]
4034 ScopeDesc* nmethod::scope_desc_in(address begin, address end) {
4035 PcDesc* p = pc_desc_near(begin+1);
4036 if (p != nullptr && p->real_pc(this) <= end) {
4037 return new ScopeDesc(this, p);
4038 }
4039 return nullptr;
4040 }
4041
4042 const char* nmethod::nmethod_section_label(address pos) const {
4043 const char* label = nullptr;
4044 if (pos == code_begin()) label = "[Instructions begin]";
4045 if (pos == entry_point()) label = "[Entry Point]";
4046 if (pos == inline_entry_point()) label = "[Inline Entry Point]";
4047 if (pos == verified_entry_point()) label = "[Verified Entry Point]";
4048 if (pos == verified_inline_entry_point()) label = "[Verified Inline Entry Point]";
4049 if (pos == verified_inline_ro_entry_point()) label = "[Verified Inline Entry Point (RO)]";
4050 if (pos == consts_begin() && pos != insts_begin()) label = "[Constants]";
4051 // Check stub_code before checking exception_handler or deopt_handler.
4052 if (pos == this->stub_begin()) label = "[Stub Code]";
4053 if (JVMCI_ONLY(_exception_offset >= 0 &&) pos == exception_begin()) label = "[Exception Handler]";
4054 if (JVMCI_ONLY(_deopt_handler_offset != -1 &&) pos == deopt_handler_begin()) label = "[Deopt Handler Code]";
4055 return label;
4056 }
4057
4058 static int maybe_print_entry_label(outputStream* stream, address pos, address entry, const char* label) {
4059 if (pos == entry) {
4060 stream->bol();
4061 stream->print_cr("%s", label);
4062 return 1;
4063 } else {
4064 return 0;
4065 }
4066 }
4067
4068 void nmethod::print_nmethod_labels(outputStream* stream, address block_begin, bool print_section_labels) const {
4069 if (print_section_labels) {
4070 int n = 0;
4071 // Multiple entry points may be at the same position. Print them all.
4072 n += maybe_print_entry_label(stream, block_begin, entry_point(), "[Entry Point]");
4073 n += maybe_print_entry_label(stream, block_begin, inline_entry_point(), "[Inline Entry Point]");
4074 n += maybe_print_entry_label(stream, block_begin, verified_entry_point(), "[Verified Entry Point]");
4075 n += maybe_print_entry_label(stream, block_begin, verified_inline_entry_point(), "[Verified Inline Entry Point]");
4076 n += maybe_print_entry_label(stream, block_begin, verified_inline_ro_entry_point(), "[Verified Inline Entry Point (RO)]");
4077 if (n == 0) {
4078 const char* label = nmethod_section_label(block_begin);
4079 if (label != nullptr) {
4080 stream->bol();
4081 stream->print_cr("%s", label);
4082 }
4083 }
4084 }
4085
4086 Method* m = method();
4087 if (m == nullptr || is_osr_method()) {
4088 return;
4089 }
4090
4091 // Print the name of the method (only once)
4092 address low = MIN3(entry_point(),
4093 verified_entry_point(),
4094 inline_entry_point());
4095 // The verified inline entry point and verified inline RO entry point are not always
4096 // used. When they are unused. CodeOffsets::Verified_Inline_Entry(_RO) is -1. Hence,
4097 // the calculated entry point is smaller than the block they are offsetting into.
4098 if (verified_inline_entry_point() >= block_begin) {
4099 low = MIN2(low, verified_inline_entry_point());
4100 }
4101 if (verified_inline_ro_entry_point() >= block_begin) {
4102 low = MIN2(low, verified_inline_ro_entry_point());
4103 }
4104 assert(low != 0, "sanity");
4105 if (block_begin == low) {
4106 stream->print(" # ");
4107 m->print_value_on(stream);
4108 stream->cr();
4109 }
4110
4111 // Print the arguments for the 3 types of verified entry points
4112 CompiledEntrySignature ces(m);
4113 ces.compute_calling_conventions(false);
4114 const GrowableArray<SigEntry>* sig_cc;
4115 const VMRegPair* regs;
4116 if (block_begin == verified_entry_point()) {
4117 sig_cc = ces.sig_cc();
4118 regs = ces.regs_cc();
4119 } else if (block_begin == verified_inline_entry_point()) {
4120 sig_cc = ces.sig();
4121 regs = ces.regs();
4122 } else if (block_begin == verified_inline_ro_entry_point()) {
4123 sig_cc = ces.sig_cc_ro();
4124 regs = ces.regs_cc_ro();
4125 } else {
4126 return;
4127 }
4128
4129 bool has_this = !m->is_static();
4130 if (ces.has_inline_recv() && block_begin == verified_entry_point()) {
4131 // <this> argument is scalarized for verified_entry_point()
4132 has_this = false;
4133 }
4134 const char* spname = "sp"; // make arch-specific?
4135 int stack_slot_offset = this->frame_size() * wordSize;
4136 int tab1 = 14, tab2 = 24;
4137 int sig_index = 0;
4138 int arg_index = has_this ? -1 : 0;
4139 bool did_old_sp = false;
4140 for (ExtendedSignature sig = ExtendedSignature(sig_cc, SigEntryFilter()); !sig.at_end(); ++sig) {
4141 bool at_this = (arg_index == -1);
4142 bool at_old_sp = false;
4143 BasicType t = (*sig)._bt;
4144 if (at_this) {
4145 stream->print(" # this: ");
4146 } else {
4147 stream->print(" # parm%d: ", arg_index);
4148 }
4149 stream->move_to(tab1);
4150 VMReg fst = regs[sig_index].first();
4151 VMReg snd = regs[sig_index].second();
4152 if (fst->is_reg()) {
4153 stream->print("%s", fst->name());
4154 if (snd->is_valid()) {
4155 stream->print(":%s", snd->name());
4156 }
4157 } else if (fst->is_stack()) {
4158 int offset = fst->reg2stack() * VMRegImpl::stack_slot_size + stack_slot_offset;
4159 if (offset == stack_slot_offset) at_old_sp = true;
4160 stream->print("[%s+0x%x]", spname, offset);
4161 } else {
4162 stream->print("reg%d:%d??", (int)(intptr_t)fst, (int)(intptr_t)snd);
4163 }
4164 stream->print(" ");
4165 stream->move_to(tab2);
4166 stream->print("= ");
4167 if (at_this) {
4168 m->method_holder()->print_value_on(stream);
4169 } else {
4170 bool did_name = false;
4171 if (is_reference_type(t)) {
4172 Symbol* name = (*sig)._name;
4173 name->print_value_on(stream);
4174 did_name = true;
4175 }
4176 if (!did_name)
4177 stream->print("%s", type2name(t));
4178 if ((*sig)._null_marker) {
4179 stream->print(" (null marker)");
4180 }
4181 }
4182 if (at_old_sp) {
4183 stream->print(" (%s of caller)", spname);
4184 did_old_sp = true;
4185 }
4186 stream->cr();
4187 sig_index += type2size[t];
4188 arg_index += 1;
4189 }
4190 if (!did_old_sp) {
4191 stream->print(" # ");
4192 stream->move_to(tab1);
4193 stream->print("[%s+0x%x]", spname, stack_slot_offset);
4194 stream->print(" (%s of caller)", spname);
4195 stream->cr();
4196 }
4197 }
4198
4199 // Returns whether this nmethod has code comments.
4200 bool nmethod::has_code_comment(address begin, address end) {
4201 // scopes?
4202 ScopeDesc* sd = scope_desc_in(begin, end);
4203 if (sd != nullptr) return true;
4204
4205 // relocations?
4206 const char* str = reloc_string_for(begin, end);
4207 if (str != nullptr) return true;
4208
4209 // implicit exceptions?
4210 int cont_offset = ImplicitExceptionTable(this).continuation_offset((uint)(begin - code_begin()));
4211 if (cont_offset != 0) return true;
4212
4213 return false;
4214 }
4215
4299 else
4300 st->print("<UNKNOWN>");
4301 break;
4302 }
4303 case Bytecodes::_getfield:
4304 case Bytecodes::_putfield:
4305 case Bytecodes::_getstatic:
4306 case Bytecodes::_putstatic:
4307 {
4308 Bytecode_field field(methodHandle(thread, sd->method()), sd->bci());
4309 st->print(" ");
4310 if (field.name() != nullptr)
4311 field.name()->print_symbol_on(st);
4312 else
4313 st->print("<UNKNOWN>");
4314 }
4315 default:
4316 break;
4317 }
4318 }
4319 st->print(" {reexecute=%d rethrow=%d return_oop=%d return_scalarized=%d}", sd->should_reexecute(), sd->rethrow_exception(), sd->return_oop(), sd->return_scalarized());
4320 }
4321
4322 // Print all scopes
4323 for (;sd != nullptr; sd = sd->sender()) {
4324 st->move_to(column, 6, 0);
4325 st->print("; -");
4326 if (sd->should_reexecute()) {
4327 st->print(" (reexecute)");
4328 }
4329 if (sd->method() == nullptr) {
4330 st->print("method is nullptr");
4331 } else {
4332 sd->method()->print_short_name(st);
4333 }
4334 int lineno = sd->method()->line_number_from_bci(sd->bci());
4335 if (lineno != -1) {
4336 st->print("@%d (line %d)", sd->bci(), lineno);
4337 } else {
4338 st->print("@%d", sd->bci());
4339 }
|