< prev index next >

src/hotspot/share/code/nmethod.cpp

Print this page

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











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

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




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

1412     _mutable_data = (address)os::malloc(_mutable_data_size, mtCode);
1413     if (_mutable_data == nullptr) {
1414       vm_exit_out_of_memory(_mutable_data_size, OOM_MALLOC_ERROR, "nmethod: no space for mutable data");
1415     }
1416     memcpy(mutable_data_begin(), nm.mutable_data_begin(), nm.mutable_data_size());
1417   } else {
1418     _mutable_data               = nullptr;
1419   }
1420 
1421   _deoptimization_generation    = 0;
1422   _gc_epoch                     = CodeCache::gc_epoch();
1423   _method                       = nm._method;
1424   _osr_link                     = nullptr;
1425 
1426   _exception_cache              = nullptr;
1427   _gc_data                      = nullptr;
1428   _oops_do_mark_nmethods        = nullptr;
1429   _oops_do_mark_link            = nullptr;
1430   _compiled_ic_data             = nullptr;
1431 
1432   if (nm._osr_entry_point != nullptr) {
1433     _osr_entry_point            = (nm._osr_entry_point - (address) &nm) + (address) this;

1434   } else {
1435     _osr_entry_point            = nullptr;



1436   }
1437 
1438   _entry_offset                 = nm._entry_offset;
1439   _verified_entry_offset        = nm._verified_entry_offset;




1440   _entry_bci                    = nm._entry_bci;
1441   _immutable_data_size          = nm._immutable_data_size;
1442 
1443   _skipped_instructions_size    = nm._skipped_instructions_size;
1444   _stub_offset                  = nm._stub_offset;
1445   _exception_offset             = nm._exception_offset;
1446   _deopt_handler_entry_offset   = nm._deopt_handler_entry_offset;
1447   _unwind_handler_offset        = nm._unwind_handler_offset;
1448   _num_stack_arg_slots          = nm._num_stack_arg_slots;
1449   _oops_size                    = nm._oops_size;
1450 #if INCLUDE_JVMCI
1451   _metadata_size                = nm._metadata_size;
1452 #endif
1453   _nul_chk_table_offset         = nm._nul_chk_table_offset;
1454   _handler_table_offset         = nm._handler_table_offset;
1455   _scopes_pcs_offset            = nm._scopes_pcs_offset;
1456   _scopes_data_offset           = nm._scopes_data_offset;
1457 #if INCLUDE_JVMCI
1458   _speculations_offset          = nm._speculations_offset;
1459 #endif

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










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

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

4031           return st.as_string();
4032         }
4033     }
4034   }
4035   return have_one ? "other" : nullptr;
4036 }
4037 
4038 // Return the last scope in (begin..end]
4039 ScopeDesc* nmethod::scope_desc_in(address begin, address end) {
4040   PcDesc* p = pc_desc_near(begin+1);
4041   if (p != nullptr && p->real_pc(this) <= end) {
4042     return new ScopeDesc(this, p);
4043   }
4044   return nullptr;
4045 }
4046 
4047 const char* nmethod::nmethod_section_label(address pos) const {
4048   const char* label = nullptr;
4049   if (pos == code_begin())                                              label = "[Instructions begin]";
4050   if (pos == entry_point())                                             label = "[Entry Point]";

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


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 void nmethod::print_nmethod_labels(outputStream* stream, address block_begin, bool print_section_labels) const {
4061   if (print_section_labels) {
4062     const char* label = nmethod_section_label(block_begin);
4063     if (label != nullptr) {
4064       stream->bol();
4065       stream->print_cr("%s", label);









4066     }
4067   }
4068 
4069   if (block_begin == entry_point()) {
4070     Method* m = method();
4071     if (m != nullptr) {
4072       stream->print("  # ");
4073       m->print_value_on(stream);
4074       stream->cr();
























































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














4159   }
4160 }
4161 
4162 // Returns whether this nmethod has code comments.
4163 bool nmethod::has_code_comment(address begin, address end) {
4164   // scopes?
4165   ScopeDesc* sd  = scope_desc_in(begin, end);
4166   if (sd != nullptr) return true;
4167 
4168   // relocations?
4169   const char* str = reloc_string_for(begin, end);
4170   if (str != nullptr) return true;
4171 
4172   // implicit exceptions?
4173   int cont_offset = ImplicitExceptionTable(this).continuation_offset((uint)(begin - code_begin()));
4174   if (cont_offset != 0) return true;
4175 
4176   return false;
4177 }
4178 

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

 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);

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

1427     _mutable_data = (address)os::malloc(_mutable_data_size, mtCode);
1428     if (_mutable_data == nullptr) {
1429       vm_exit_out_of_memory(_mutable_data_size, OOM_MALLOC_ERROR, "nmethod: no space for mutable data");
1430     }
1431     memcpy(mutable_data_begin(), nm.mutable_data_begin(), nm.mutable_data_size());
1432   } else {
1433     _mutable_data               = nullptr;
1434   }
1435 
1436   _deoptimization_generation    = 0;
1437   _gc_epoch                     = CodeCache::gc_epoch();
1438   _method                       = nm._method;
1439   _osr_link                     = nullptr;
1440 
1441   _exception_cache              = nullptr;
1442   _gc_data                      = nullptr;
1443   _oops_do_mark_nmethods        = nullptr;
1444   _oops_do_mark_link            = nullptr;
1445   _compiled_ic_data             = nullptr;
1446 
1447   // Relocate the OSR entry point from nm to the new nmethod.
1448   if (nm._osr_entry_point == nullptr) {
1449     _osr_entry_point = nullptr;
1450   } else {
1451     address new_addr = nm._osr_entry_point - (address) &nm + (address) this;
1452     assert(new_addr >= code_begin() && new_addr < code_end(),
1453            "relocated address must be within code bounds");
1454     _osr_entry_point = new_addr;
1455   }

1456   _entry_offset                 = nm._entry_offset;
1457   _verified_entry_offset        = nm._verified_entry_offset;
1458   _inline_entry_offset             = nm._inline_entry_offset;
1459   _verified_inline_entry_offset    = nm._verified_inline_entry_offset;
1460   _verified_inline_ro_entry_offset = nm._verified_inline_ro_entry_offset;
1461 
1462   _entry_bci                    = nm._entry_bci;
1463   _immutable_data_size          = nm._immutable_data_size;
1464 
1465   _skipped_instructions_size    = nm._skipped_instructions_size;
1466   _stub_offset                  = nm._stub_offset;
1467   _exception_offset             = nm._exception_offset;
1468   _deopt_handler_entry_offset   = nm._deopt_handler_entry_offset;
1469   _unwind_handler_offset        = nm._unwind_handler_offset;
1470   _num_stack_arg_slots          = nm._num_stack_arg_slots;
1471   _oops_size                    = nm._oops_size;
1472 #if INCLUDE_JVMCI
1473   _metadata_size                = nm._metadata_size;
1474 #endif
1475   _nul_chk_table_offset         = nm._nul_chk_table_offset;
1476   _handler_table_offset         = nm._handler_table_offset;
1477   _scopes_pcs_offset            = nm._scopes_pcs_offset;
1478   _scopes_data_offset           = nm._scopes_data_offset;
1479 #if INCLUDE_JVMCI
1480   _speculations_offset          = nm._speculations_offset;
1481 #endif

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

3222 }
3223 
3224 bool nmethod::check_dependency_on(DepChange& changes) {
3225   // What has happened:
3226   // 1) a new class dependee has been added
3227   // 2) dependee and all its super classes have been marked
3228   bool found_check = false;  // set true if we are upset
3229   for (Dependencies::DepStream deps(this); deps.next(); ) {
3230     // Evaluate only relevant dependencies.
3231     if (deps.spot_check_dependency_at(changes) != nullptr) {
3232       found_check = true;
3233       NOT_DEBUG(break);
3234     }
3235   }
3236   return found_check;
3237 }
3238 
3239 // Called from mark_for_deoptimization, when dependee is invalidated.
3240 bool nmethod::is_dependent_on_method(Method* dependee) {
3241   for (Dependencies::DepStream deps(this); deps.next(); ) {
3242     if (Dependencies::has_method_dep(deps.type())) {
3243       Method* method = deps.method_argument(0);
3244       if (method == dependee) return true;
3245     }
3246   }
3247   return false;
3248 }
3249 
3250 void nmethod_init() {
3251   // make sure you didn't forget to adjust the filler fields
3252   assert(sizeof(nmethod) % oopSize == 0, "nmethod size must be multiple of a word");
3253 }
3254 
3255 // -----------------------------------------------------------------------------
3256 // Verification
3257 
3258 class VerifyOopsClosure: public OopClosure {
3259   nmethod* _nm;
3260   bool     _ok;
3261 public:
3262   VerifyOopsClosure(nmethod* nm) : _nm(nm), _ok(true) { }
3263   bool ok() { return _ok; }
3264   virtual void do_oop(oop* p) {
3265     if (oopDesc::is_oop_or_null(*p)) return;

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












4193       }
4194     } else if (fst->is_stack()) {
4195       int offset = fst->reg2stack() * VMRegImpl::stack_slot_size + stack_slot_offset;
4196       if (offset == stack_slot_offset)  at_old_sp = true;
4197       stream->print("[%s+0x%x]", spname, offset);
4198     } else {
4199       stream->print("reg%d:%d??", (int)(intptr_t)fst, (int)(intptr_t)snd);
4200     }
4201     stream->print(" ");
4202     stream->move_to(tab2);
4203     stream->print("= ");
4204     if (at_this) {
4205       m->method_holder()->print_value_on(stream);
4206     } else {
4207       bool did_name = false;
4208       if (is_reference_type(t)) {
4209         Symbol* name = (*sig)._name;
4210         name->print_value_on(stream);
4211         did_name = true;




































4212       }
4213       if (!did_name)
4214         stream->print("%s", type2name(t));
4215       if ((*sig)._null_marker) {
4216         stream->print(" (null marker)");


4217       }
4218     }
4219     if (at_old_sp) {
4220       stream->print("  (%s of caller)", spname);
4221       did_old_sp = true;
4222     }
4223     stream->cr();
4224     sig_index += type2size[t];
4225     arg_index += 1;
4226   }
4227   if (!did_old_sp) {
4228     stream->print("  # ");
4229     stream->move_to(tab1);
4230     stream->print("[%s+0x%x]", spname, stack_slot_offset);
4231     stream->print("  (%s of caller)", spname);
4232     stream->cr();
4233   }
4234 }
4235 
4236 // Returns whether this nmethod has code comments.
4237 bool nmethod::has_code_comment(address begin, address end) {
4238   // scopes?
4239   ScopeDesc* sd  = scope_desc_in(begin, end);
4240   if (sd != nullptr) return true;
4241 
4242   // relocations?
4243   const char* str = reloc_string_for(begin, end);
4244   if (str != nullptr) return true;
4245 
4246   // implicit exceptions?
4247   int cont_offset = ImplicitExceptionTable(this).continuation_offset((uint)(begin - code_begin()));
4248   if (cont_offset != 0) return true;
4249 
4250   return false;
4251 }
4252 

4336             else
4337               st->print("<UNKNOWN>");
4338             break;
4339           }
4340         case Bytecodes::_getfield:
4341         case Bytecodes::_putfield:
4342         case Bytecodes::_getstatic:
4343         case Bytecodes::_putstatic:
4344           {
4345             Bytecode_field field(methodHandle(thread, sd->method()), sd->bci());
4346             st->print(" ");
4347             if (field.name() != nullptr)
4348               field.name()->print_symbol_on(st);
4349             else
4350               st->print("<UNKNOWN>");
4351           }
4352         default:
4353           break;
4354         }
4355       }
4356       st->print(" {reexecute=%d rethrow=%d return_oop=%d return_scalarized=%d}", sd->should_reexecute(), sd->rethrow_exception(), sd->return_oop(), sd->return_scalarized());
4357     }
4358 
4359     // Print all scopes
4360     for (;sd != nullptr; sd = sd->sender()) {
4361       st->move_to(column, 6, 0);
4362       st->print("; -");
4363       if (sd->should_reexecute()) {
4364         st->print(" (reexecute)");
4365       }
4366       if (sd->method() == nullptr) {
4367         st->print("method is nullptr");
4368       } else {
4369         sd->method()->print_short_name(st);
4370       }
4371       int lineno = sd->method()->line_number_from_bci(sd->bci());
4372       if (lineno != -1) {
4373         st->print("@%d (line %d)", sd->bci(), lineno);
4374       } else {
4375         st->print("@%d", sd->bci());
4376       }
< prev index next >