406 if (method() != NULL && is_native_method()) return "c2n"; 407 return NULL; 408 } 409 410 // Fill in default values for various flag fields 411 void nmethod::init_defaults() { 412 _state = not_installed; 413 _has_flushed_dependencies = 0; 414 _lock_count = 0; 415 _stack_traversal_mark = 0; 416 _unload_reported = false; // jvmti state 417 _is_far_code = false; // nmethods are located in CodeCache 418 419 #ifdef ASSERT 420 _oops_are_stale = false; 421 #endif 422 423 _oops_do_mark_link = NULL; 424 _jmethod_id = NULL; 425 _osr_link = NULL; 426 _scavenge_root_link = NULL; 427 _scavenge_root_state = 0; 428 #if INCLUDE_RTM_OPT 429 _rtm_state = NoRTM; 430 #endif 431 #if INCLUDE_JVMCI 432 _jvmci_installed_code = NULL; 433 _speculation_log = NULL; 434 _jvmci_installed_code_triggers_invalidation = false; 435 #endif 436 } 437 438 nmethod* nmethod::new_native_nmethod(const methodHandle& method, 439 int compile_id, 440 CodeBuffer *code_buffer, 441 int vep_offset, 442 int frame_complete, 443 int frame_size, 444 ByteSize basic_lock_owner_sp_offset, 445 ByteSize basic_lock_sp_offset, 446 OopMapSet* oop_maps) { 447 code_buffer->finalize_oop_references(method); 1343 // completely deallocate this method 1344 Events::log(JavaThread::current(), "flushing nmethod " INTPTR_FORMAT, p2i(this)); 1345 if (PrintMethodFlushing) { 1346 tty->print_cr("*flushing %s nmethod %3d/" INTPTR_FORMAT ". Live blobs:" UINT32_FORMAT 1347 "/Free CodeCache:" SIZE_FORMAT "Kb", 1348 is_osr_method() ? "osr" : "",_compile_id, p2i(this), CodeCache::blob_count(), 1349 CodeCache::unallocated_capacity(CodeCache::get_code_blob_type(this))/1024); 1350 } 1351 1352 // We need to deallocate any ExceptionCache data. 1353 // Note that we do not need to grab the nmethod lock for this, it 1354 // better be thread safe if we're disposing of it! 1355 ExceptionCache* ec = exception_cache(); 1356 set_exception_cache(NULL); 1357 while(ec != NULL) { 1358 ExceptionCache* next = ec->next(); 1359 delete ec; 1360 ec = next; 1361 } 1362 1363 if (on_scavenge_root_list()) { 1364 CodeCache::drop_scavenge_root_nmethod(this); 1365 } 1366 1367 #if INCLUDE_JVMCI 1368 assert(_jvmci_installed_code == NULL, "should have been nulled out when transitioned to zombie"); 1369 assert(_speculation_log == NULL, "should have been nulled out when transitioned to zombie"); 1370 #endif 1371 1372 Universe::heap()->flush_nmethod(this); 1373 1374 CodeBlob::flush(); 1375 CodeCache::free(this); 1376 } 1377 1378 oop nmethod::oop_at(int index) const { 1379 if (index == 0) { 1380 return NULL; 1381 } 1382 return NativeAccess<AS_NO_KEEPALIVE>::oop_load(oop_addr_at(index)); 1383 } 1384 1385 // 1386 // Notify all classes this nmethod is dependent on that it is no 1760 nmethod* cur = _oops_do_mark_nmethods; 1761 while (cur != NMETHOD_SENTINEL) { 1762 assert(cur != NULL, "not NULL-terminated"); 1763 nmethod* next = cur->_oops_do_mark_link; 1764 cur->_oops_do_mark_link = NULL; 1765 DEBUG_ONLY(cur->verify_oop_relocations()); 1766 1767 LogTarget(Trace, gc, nmethod) lt; 1768 if (lt.is_enabled()) { 1769 LogStream ls(lt); 1770 CompileTask::print(&ls, cur, "oops_do, unmark", /*short_form:*/ true); 1771 } 1772 cur = next; 1773 } 1774 nmethod* required = _oops_do_mark_nmethods; 1775 nmethod* observed = Atomic::cmpxchg((nmethod*)NULL, &_oops_do_mark_nmethods, required); 1776 guarantee(observed == required, "no races in this sequential code"); 1777 log_trace(gc, nmethod)("oops_do_marking_epilogue"); 1778 } 1779 1780 class DetectScavengeRoot: public OopClosure { 1781 bool _detected_scavenge_root; 1782 nmethod* _print_nm; 1783 public: 1784 DetectScavengeRoot(nmethod* nm) : _detected_scavenge_root(false), _print_nm(nm) {} 1785 1786 bool detected_scavenge_root() { return _detected_scavenge_root; } 1787 virtual void do_oop(oop* p) { 1788 if ((*p) != NULL && Universe::heap()->is_scavengable(*p)) { 1789 NOT_PRODUCT(maybe_print(p)); 1790 _detected_scavenge_root = true; 1791 } 1792 } 1793 virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); } 1794 1795 #ifndef PRODUCT 1796 void maybe_print(oop* p) { 1797 LogTarget(Trace, gc, nmethod) lt; 1798 if (lt.is_enabled()) { 1799 LogStream ls(lt); 1800 if (!_detected_scavenge_root) { 1801 CompileTask::print(&ls, _print_nm, "new scavenge root", /*short_form:*/ true); 1802 } 1803 ls.print("" PTR_FORMAT "[offset=%d] detected scavengable oop " PTR_FORMAT " (found at " PTR_FORMAT ") ", 1804 p2i(_print_nm), (int)((intptr_t)p - (intptr_t)_print_nm), 1805 p2i(*p), p2i(p)); 1806 ls.cr(); 1807 } 1808 } 1809 #endif //PRODUCT 1810 }; 1811 1812 bool nmethod::detect_scavenge_root_oops() { 1813 DetectScavengeRoot detect_scavenge_root(this); 1814 oops_do(&detect_scavenge_root); 1815 return detect_scavenge_root.detected_scavenge_root(); 1816 } 1817 1818 inline bool includes(void* p, void* from, void* to) { 1819 return from <= p && p < to; 1820 } 1821 1822 1823 void nmethod::copy_scopes_pcs(PcDesc* pcs, int count) { 1824 assert(count >= 2, "must be sentinel values, at least"); 1825 1826 #ifdef ASSERT 1827 // must be sorted and unique; we do a binary search in find_pc_desc() 1828 int prev_offset = pcs[0].pc_offset(); 1829 assert(prev_offset == PcDesc::lower_offset_limit, 1830 "must start with a sentinel"); 1831 for (int i = 1; i < count; i++) { 1832 int this_offset = pcs[i].pc_offset(); 1833 assert(this_offset > prev_offset, "offsets must be sorted"); 1834 prev_offset = this_offset; 1835 } 1836 assert(prev_offset == PcDesc::upper_offset_limit, 1837 "must end with a sentinel"); 2249 stub = iter.static_call_reloc()->static_stub(false); 2250 //verify_interrupt_point(iter.addr()); 2251 break; 2252 case relocInfo::runtime_call_type: 2253 case relocInfo::runtime_call_w_cp_type: { 2254 address destination = iter.reloc()->value(); 2255 // Right now there is no way to find out which entries support 2256 // an interrupt point. It would be nice if we had this 2257 // information in a table. 2258 break; 2259 } 2260 default: 2261 break; 2262 } 2263 assert(stub == NULL || stub_contains(stub), "static call stub outside stub section"); 2264 } 2265 } 2266 2267 2268 // ----------------------------------------------------------------------------- 2269 // Non-product code 2270 #ifndef PRODUCT 2271 2272 class DebugScavengeRoot: public OopClosure { 2273 nmethod* _nm; 2274 bool _ok; 2275 public: 2276 DebugScavengeRoot(nmethod* nm) : _nm(nm), _ok(true) { } 2277 bool ok() { return _ok; } 2278 virtual void do_oop(oop* p) { 2279 if ((*p) == NULL || !Universe::heap()->is_scavengable(*p)) return; 2280 if (_ok) { 2281 _nm->print_nmethod(true); 2282 _ok = false; 2283 } 2284 tty->print_cr("*** scavengable oop " PTR_FORMAT " found at " PTR_FORMAT " (offset %d)", 2285 p2i(*p), p2i(p), (int)((intptr_t)p - (intptr_t)_nm)); 2286 (*p)->print(); 2287 } 2288 virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); } 2289 }; 2290 2291 void nmethod::verify_scavenge_root_oops() { 2292 if (!on_scavenge_root_list()) { 2293 // Actually look inside, to verify the claim that it's clean. 2294 DebugScavengeRoot debug_scavenge_root(this); 2295 oops_do(&debug_scavenge_root); 2296 if (!debug_scavenge_root.ok()) 2297 fatal("found an unadvertised bad scavengable oop in the code cache"); 2298 } 2299 assert(scavenge_root_not_marked(), ""); 2300 } 2301 2302 #endif // PRODUCT 2303 2304 // Printing operations 2305 2306 void nmethod::print() const { 2307 ResourceMark rm; 2308 ttyLocker ttyl; // keep the following output all in one block 2309 2310 tty->print("Compiled method "); 2311 2312 if (is_compiled_by_c1()) { 2313 tty->print("(c1) "); 2314 } else if (is_compiled_by_c2()) { 2315 tty->print("(c2) "); 2316 } else if (is_compiled_by_jvmci()) { 2317 tty->print("(JVMCI) "); 2318 } else { 2319 tty->print("(nm) "); 2320 } 2321 2322 print_on(tty, NULL); 2323 2324 if (WizardMode) { 2325 tty->print("((nmethod*) " INTPTR_FORMAT ") ", p2i(this)); 2326 tty->print(" for method " INTPTR_FORMAT , p2i(method())); 2327 tty->print(" { "); 2328 tty->print_cr("%s ", state()); 2329 if (on_scavenge_root_list()) tty->print("scavenge_root "); 2330 tty->print_cr("}:"); 2331 } 2332 if (size () > 0) tty->print_cr(" total in heap [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", 2333 p2i(this), 2334 p2i(this) + size(), 2335 size()); 2336 if (relocation_size () > 0) tty->print_cr(" relocation [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", 2337 p2i(relocation_begin()), 2338 p2i(relocation_end()), 2339 relocation_size()); 2340 if (consts_size () > 0) tty->print_cr(" constants [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", 2341 p2i(consts_begin()), 2342 p2i(consts_end()), 2343 consts_size()); 2344 if (insts_size () > 0) tty->print_cr(" main code [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", 2345 p2i(insts_begin()), 2346 p2i(insts_end()), 2347 insts_size()); 2348 if (stub_size () > 0) tty->print_cr(" stub code [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", 2349 p2i(stub_begin()), | 406 if (method() != NULL && is_native_method()) return "c2n"; 407 return NULL; 408 } 409 410 // Fill in default values for various flag fields 411 void nmethod::init_defaults() { 412 _state = not_installed; 413 _has_flushed_dependencies = 0; 414 _lock_count = 0; 415 _stack_traversal_mark = 0; 416 _unload_reported = false; // jvmti state 417 _is_far_code = false; // nmethods are located in CodeCache 418 419 #ifdef ASSERT 420 _oops_are_stale = false; 421 #endif 422 423 _oops_do_mark_link = NULL; 424 _jmethod_id = NULL; 425 _osr_link = NULL; 426 #if INCLUDE_RTM_OPT 427 _rtm_state = NoRTM; 428 #endif 429 #if INCLUDE_JVMCI 430 _jvmci_installed_code = NULL; 431 _speculation_log = NULL; 432 _jvmci_installed_code_triggers_invalidation = false; 433 #endif 434 } 435 436 nmethod* nmethod::new_native_nmethod(const methodHandle& method, 437 int compile_id, 438 CodeBuffer *code_buffer, 439 int vep_offset, 440 int frame_complete, 441 int frame_size, 442 ByteSize basic_lock_owner_sp_offset, 443 ByteSize basic_lock_sp_offset, 444 OopMapSet* oop_maps) { 445 code_buffer->finalize_oop_references(method); 1341 // completely deallocate this method 1342 Events::log(JavaThread::current(), "flushing nmethod " INTPTR_FORMAT, p2i(this)); 1343 if (PrintMethodFlushing) { 1344 tty->print_cr("*flushing %s nmethod %3d/" INTPTR_FORMAT ". Live blobs:" UINT32_FORMAT 1345 "/Free CodeCache:" SIZE_FORMAT "Kb", 1346 is_osr_method() ? "osr" : "",_compile_id, p2i(this), CodeCache::blob_count(), 1347 CodeCache::unallocated_capacity(CodeCache::get_code_blob_type(this))/1024); 1348 } 1349 1350 // We need to deallocate any ExceptionCache data. 1351 // Note that we do not need to grab the nmethod lock for this, it 1352 // better be thread safe if we're disposing of it! 1353 ExceptionCache* ec = exception_cache(); 1354 set_exception_cache(NULL); 1355 while(ec != NULL) { 1356 ExceptionCache* next = ec->next(); 1357 delete ec; 1358 ec = next; 1359 } 1360 1361 #if INCLUDE_JVMCI 1362 assert(_jvmci_installed_code == NULL, "should have been nulled out when transitioned to zombie"); 1363 assert(_speculation_log == NULL, "should have been nulled out when transitioned to zombie"); 1364 #endif 1365 1366 Universe::heap()->flush_nmethod(this); 1367 1368 CodeBlob::flush(); 1369 CodeCache::free(this); 1370 } 1371 1372 oop nmethod::oop_at(int index) const { 1373 if (index == 0) { 1374 return NULL; 1375 } 1376 return NativeAccess<AS_NO_KEEPALIVE>::oop_load(oop_addr_at(index)); 1377 } 1378 1379 // 1380 // Notify all classes this nmethod is dependent on that it is no 1754 nmethod* cur = _oops_do_mark_nmethods; 1755 while (cur != NMETHOD_SENTINEL) { 1756 assert(cur != NULL, "not NULL-terminated"); 1757 nmethod* next = cur->_oops_do_mark_link; 1758 cur->_oops_do_mark_link = NULL; 1759 DEBUG_ONLY(cur->verify_oop_relocations()); 1760 1761 LogTarget(Trace, gc, nmethod) lt; 1762 if (lt.is_enabled()) { 1763 LogStream ls(lt); 1764 CompileTask::print(&ls, cur, "oops_do, unmark", /*short_form:*/ true); 1765 } 1766 cur = next; 1767 } 1768 nmethod* required = _oops_do_mark_nmethods; 1769 nmethod* observed = Atomic::cmpxchg((nmethod*)NULL, &_oops_do_mark_nmethods, required); 1770 guarantee(observed == required, "no races in this sequential code"); 1771 log_trace(gc, nmethod)("oops_do_marking_epilogue"); 1772 } 1773 1774 inline bool includes(void* p, void* from, void* to) { 1775 return from <= p && p < to; 1776 } 1777 1778 1779 void nmethod::copy_scopes_pcs(PcDesc* pcs, int count) { 1780 assert(count >= 2, "must be sentinel values, at least"); 1781 1782 #ifdef ASSERT 1783 // must be sorted and unique; we do a binary search in find_pc_desc() 1784 int prev_offset = pcs[0].pc_offset(); 1785 assert(prev_offset == PcDesc::lower_offset_limit, 1786 "must start with a sentinel"); 1787 for (int i = 1; i < count; i++) { 1788 int this_offset = pcs[i].pc_offset(); 1789 assert(this_offset > prev_offset, "offsets must be sorted"); 1790 prev_offset = this_offset; 1791 } 1792 assert(prev_offset == PcDesc::upper_offset_limit, 1793 "must end with a sentinel"); 2205 stub = iter.static_call_reloc()->static_stub(false); 2206 //verify_interrupt_point(iter.addr()); 2207 break; 2208 case relocInfo::runtime_call_type: 2209 case relocInfo::runtime_call_w_cp_type: { 2210 address destination = iter.reloc()->value(); 2211 // Right now there is no way to find out which entries support 2212 // an interrupt point. It would be nice if we had this 2213 // information in a table. 2214 break; 2215 } 2216 default: 2217 break; 2218 } 2219 assert(stub == NULL || stub_contains(stub), "static call stub outside stub section"); 2220 } 2221 } 2222 2223 2224 // ----------------------------------------------------------------------------- 2225 // Printing operations 2226 2227 void nmethod::print() const { 2228 ResourceMark rm; 2229 ttyLocker ttyl; // keep the following output all in one block 2230 2231 tty->print("Compiled method "); 2232 2233 if (is_compiled_by_c1()) { 2234 tty->print("(c1) "); 2235 } else if (is_compiled_by_c2()) { 2236 tty->print("(c2) "); 2237 } else if (is_compiled_by_jvmci()) { 2238 tty->print("(JVMCI) "); 2239 } else { 2240 tty->print("(nm) "); 2241 } 2242 2243 print_on(tty, NULL); 2244 2245 if (WizardMode) { 2246 tty->print("((nmethod*) " INTPTR_FORMAT ") ", p2i(this)); 2247 tty->print(" for method " INTPTR_FORMAT , p2i(method())); 2248 tty->print(" { "); 2249 tty->print_cr("%s ", state()); 2250 tty->print_cr("}:"); 2251 } 2252 if (size () > 0) tty->print_cr(" total in heap [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", 2253 p2i(this), 2254 p2i(this) + size(), 2255 size()); 2256 if (relocation_size () > 0) tty->print_cr(" relocation [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", 2257 p2i(relocation_begin()), 2258 p2i(relocation_end()), 2259 relocation_size()); 2260 if (consts_size () > 0) tty->print_cr(" constants [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", 2261 p2i(consts_begin()), 2262 p2i(consts_end()), 2263 consts_size()); 2264 if (insts_size () > 0) tty->print_cr(" main code [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", 2265 p2i(insts_begin()), 2266 p2i(insts_end()), 2267 insts_size()); 2268 if (stub_size () > 0) tty->print_cr(" stub code [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", 2269 p2i(stub_begin()), |