1333 // OSR methods point to the Method*, but the Method* does not 1334 // point back! 1335 if (_method->code() == this) { 1336 _method->clear_code(); // Break a cycle 1337 } 1338 _method = NULL; // Clear the method of this dead nmethod 1339 } 1340 1341 // Make the class unloaded - i.e., change state and notify sweeper 1342 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); 1343 if (is_in_use()) { 1344 // Transitioning directly from live to unloaded -- so 1345 // we need to force a cache clean-up; remember this 1346 // for later on. 1347 CodeCache::set_needs_cache_clean(true); 1348 } 1349 1350 // Unregister must be done before the state change 1351 Universe::heap()->unregister_nmethod(this); 1352 1353 #if INCLUDE_JVMCI 1354 // The method can only be unloaded after the pointer to the installed code 1355 // Java wrapper is no longer alive. Here we need to clear out this weak 1356 // reference to the dead object. Nulling out the reference has to happen 1357 // after the method is unregistered since the original value may be still 1358 // tracked by the rset. 1359 if (_jvmci_installed_code != NULL) { 1360 InstalledCode::set_address(_jvmci_installed_code, 0); 1361 _jvmci_installed_code = NULL; 1362 } 1363 #endif 1364 1365 _state = unloaded; 1366 1367 // Log the unloading. 1368 log_state_change(); 1369 1370 // The Method* is gone at this point 1371 assert(_method == NULL, "Tautology"); 1372 1373 set_osr_link(NULL); 1374 //set_scavenge_root_link(NULL); // done by prune_scavenge_root_nmethods 1375 NMethodSweeper::report_state_change(this); 1376 } 1377 1378 void nmethod::invalidate_osr_method() { 1379 assert(_entry_bci != InvocationEntryBci, "wrong kind of nmethod"); 1380 // Remove from list of active nmethods 1381 if (method() != NULL) 1382 method()->method_holder()->remove_osr_nmethod(this); 1383 } 1384 1385 void nmethod::log_state_change() const { 1386 if (LogCompilation) { 1508 } 1509 1510 // zombie only - if a JVMTI agent has enabled the CompiledMethodUnload 1511 // event and it hasn't already been reported for this nmethod then 1512 // report it now. The event may have been reported earilier if the GC 1513 // marked it for unloading). JvmtiDeferredEventQueue support means 1514 // we no longer go to a safepoint here. 1515 post_compiled_method_unload(); 1516 1517 #ifdef ASSERT 1518 // It's no longer safe to access the oops section since zombie 1519 // nmethods aren't scanned for GC. 1520 _oops_are_stale = true; 1521 #endif 1522 // the Method may be reclaimed by class unloading now that the 1523 // nmethod is in zombie state 1524 set_method(NULL); 1525 } else { 1526 assert(state == not_entrant, "other cases may need to be handled differently"); 1527 } 1528 #if INCLUDE_JVMCI 1529 if (_jvmci_installed_code != NULL) { 1530 // Break the link between nmethod and InstalledCode such that the nmethod can subsequently be flushed safely. 1531 InstalledCode::set_address(_jvmci_installed_code, 0); 1532 } 1533 #endif 1534 1535 if (TraceCreateZombies) { 1536 ResourceMark m; 1537 tty->print_cr("nmethod <" INTPTR_FORMAT "> %s code made %s", p2i(this), this->method() ? this->method()->name_and_sig_as_C_string() : "null", (state == not_entrant) ? "not entrant" : "zombie"); 1538 } 1539 1540 NMethodSweeper::report_state_change(this); 1541 return true; 1542 } 1543 1544 void nmethod::flush() { 1545 // Note that there are no valid oops in the nmethod anymore. 1546 assert(is_zombie() || (is_osr_method() && is_unloaded()), "must be a zombie method"); 1547 assert(is_marked_for_reclamation() || (is_osr_method() && is_unloaded()), "must be marked for reclamation"); 1548 1549 assert (!is_locked_by_vm(), "locked methods shouldn't be flushed"); 1550 assert_locked_or_safepoint(CodeCache_lock); 1551 1552 // completely deallocate this method 1553 Events::log(JavaThread::current(), "flushing nmethod " INTPTR_FORMAT, p2i(this)); 3367 c2_java_nmethod_stats.print_nmethod_stats("C2"); 3368 #endif 3369 #if INCLUDE_JVMCI 3370 jvmci_java_nmethod_stats.print_nmethod_stats("JVMCI"); 3371 #endif 3372 #ifdef SHARK 3373 shark_java_nmethod_stats.print_nmethod_stats("Shark"); 3374 #endif 3375 unknown_java_nmethod_stats.print_nmethod_stats("Unknown"); 3376 DebugInformationRecorder::print_statistics(); 3377 #ifndef PRODUCT 3378 pc_nmethod_stats.print_pc_stats(); 3379 #endif 3380 Dependencies::print_statistics(); 3381 if (xtty != NULL) xtty->tail("statistics"); 3382 } 3383 3384 #endif // !PRODUCT 3385 3386 #if INCLUDE_JVMCI 3387 char* nmethod::jvmci_installed_code_name(char* buf, size_t buflen) { 3388 if (!this->is_compiled_by_jvmci()) { 3389 return NULL; 3390 } 3391 oop installedCode = this->jvmci_installed_code(); 3392 if (installedCode != NULL) { 3393 oop installedCodeName = NULL; 3394 if (installedCode->is_a(InstalledCode::klass())) { 3395 installedCodeName = InstalledCode::name(installedCode); 3396 } 3397 if (installedCodeName != NULL) { 3398 return java_lang_String::as_utf8_string(installedCodeName, buf, (int)buflen); 3399 } else { 3400 jio_snprintf(buf, buflen, "null"); 3401 return buf; 3402 } 3403 } 3404 jio_snprintf(buf, buflen, "noInstalledCode"); 3405 return buf; 3406 } | 1333 // OSR methods point to the Method*, but the Method* does not 1334 // point back! 1335 if (_method->code() == this) { 1336 _method->clear_code(); // Break a cycle 1337 } 1338 _method = NULL; // Clear the method of this dead nmethod 1339 } 1340 1341 // Make the class unloaded - i.e., change state and notify sweeper 1342 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); 1343 if (is_in_use()) { 1344 // Transitioning directly from live to unloaded -- so 1345 // we need to force a cache clean-up; remember this 1346 // for later on. 1347 CodeCache::set_needs_cache_clean(true); 1348 } 1349 1350 // Unregister must be done before the state change 1351 Universe::heap()->unregister_nmethod(this); 1352 1353 _state = unloaded; 1354 1355 #if INCLUDE_JVMCI 1356 // The method can only be unloaded after the pointer to the installed code 1357 // Java wrapper is no longer alive. Here we need to clear out this weak 1358 // reference to the dead object. Nulling out the reference has to happen 1359 // after the method is unregistered since the original value may be still 1360 // tracked by the rset. 1361 maybe_invalidate_installed_code(); 1362 #endif 1363 1364 // Log the unloading. 1365 log_state_change(); 1366 1367 // The Method* is gone at this point 1368 assert(_method == NULL, "Tautology"); 1369 1370 set_osr_link(NULL); 1371 //set_scavenge_root_link(NULL); // done by prune_scavenge_root_nmethods 1372 NMethodSweeper::report_state_change(this); 1373 } 1374 1375 void nmethod::invalidate_osr_method() { 1376 assert(_entry_bci != InvocationEntryBci, "wrong kind of nmethod"); 1377 // Remove from list of active nmethods 1378 if (method() != NULL) 1379 method()->method_holder()->remove_osr_nmethod(this); 1380 } 1381 1382 void nmethod::log_state_change() const { 1383 if (LogCompilation) { 1505 } 1506 1507 // zombie only - if a JVMTI agent has enabled the CompiledMethodUnload 1508 // event and it hasn't already been reported for this nmethod then 1509 // report it now. The event may have been reported earilier if the GC 1510 // marked it for unloading). JvmtiDeferredEventQueue support means 1511 // we no longer go to a safepoint here. 1512 post_compiled_method_unload(); 1513 1514 #ifdef ASSERT 1515 // It's no longer safe to access the oops section since zombie 1516 // nmethods aren't scanned for GC. 1517 _oops_are_stale = true; 1518 #endif 1519 // the Method may be reclaimed by class unloading now that the 1520 // nmethod is in zombie state 1521 set_method(NULL); 1522 } else { 1523 assert(state == not_entrant, "other cases may need to be handled differently"); 1524 } 1525 1526 JVMCI_ONLY(maybe_invalidate_installed_code()); 1527 1528 if (TraceCreateZombies) { 1529 ResourceMark m; 1530 tty->print_cr("nmethod <" INTPTR_FORMAT "> %s code made %s", p2i(this), this->method() ? this->method()->name_and_sig_as_C_string() : "null", (state == not_entrant) ? "not entrant" : "zombie"); 1531 } 1532 1533 NMethodSweeper::report_state_change(this); 1534 return true; 1535 } 1536 1537 void nmethod::flush() { 1538 // Note that there are no valid oops in the nmethod anymore. 1539 assert(is_zombie() || (is_osr_method() && is_unloaded()), "must be a zombie method"); 1540 assert(is_marked_for_reclamation() || (is_osr_method() && is_unloaded()), "must be marked for reclamation"); 1541 1542 assert (!is_locked_by_vm(), "locked methods shouldn't be flushed"); 1543 assert_locked_or_safepoint(CodeCache_lock); 1544 1545 // completely deallocate this method 1546 Events::log(JavaThread::current(), "flushing nmethod " INTPTR_FORMAT, p2i(this)); 3360 c2_java_nmethod_stats.print_nmethod_stats("C2"); 3361 #endif 3362 #if INCLUDE_JVMCI 3363 jvmci_java_nmethod_stats.print_nmethod_stats("JVMCI"); 3364 #endif 3365 #ifdef SHARK 3366 shark_java_nmethod_stats.print_nmethod_stats("Shark"); 3367 #endif 3368 unknown_java_nmethod_stats.print_nmethod_stats("Unknown"); 3369 DebugInformationRecorder::print_statistics(); 3370 #ifndef PRODUCT 3371 pc_nmethod_stats.print_pc_stats(); 3372 #endif 3373 Dependencies::print_statistics(); 3374 if (xtty != NULL) xtty->tail("statistics"); 3375 } 3376 3377 #endif // !PRODUCT 3378 3379 #if INCLUDE_JVMCI 3380 void nmethod::maybe_invalidate_installed_code() { 3381 if (_jvmci_installed_code != NULL) { 3382 if (!is_alive()) { 3383 // Break the link between nmethod and InstalledCode such that the nmethod 3384 // can subsequently be flushed safely. The link must be maintained while 3385 // the method could have live activations since invalidateInstalledCode 3386 // might want to invalidate all existing activations. 3387 InstalledCode::set_address(_jvmci_installed_code, 0); 3388 InstalledCode::set_entryPoint(_jvmci_installed_code, 0); 3389 _jvmci_installed_code = NULL; 3390 } else if (is_not_entrant()) { 3391 InstalledCode::set_entryPoint(_jvmci_installed_code, 0); 3392 } 3393 } 3394 } 3395 3396 char* nmethod::jvmci_installed_code_name(char* buf, size_t buflen) { 3397 if (!this->is_compiled_by_jvmci()) { 3398 return NULL; 3399 } 3400 oop installedCode = this->jvmci_installed_code(); 3401 if (installedCode != NULL) { 3402 oop installedCodeName = NULL; 3403 if (installedCode->is_a(InstalledCode::klass())) { 3404 installedCodeName = InstalledCode::name(installedCode); 3405 } 3406 if (installedCodeName != NULL) { 3407 return java_lang_String::as_utf8_string(installedCodeName, buf, (int)buflen); 3408 } else { 3409 jio_snprintf(buf, buflen, "null"); 3410 return buf; 3411 } 3412 } 3413 jio_snprintf(buf, buflen, "noInstalledCode"); 3414 return buf; 3415 } |