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