597 _deopt_handler_begin = (address) this + deoptimize_offset; |
596 _deopt_handler_begin = (address) this + deoptimize_offset; |
598 _deopt_mh_handler_begin = (address) this + deoptimize_mh_offset; |
597 _deopt_mh_handler_begin = (address) this + deoptimize_mh_offset; |
599 |
598 |
600 code_buffer->copy_code_and_locs_to(this); |
599 code_buffer->copy_code_and_locs_to(this); |
601 code_buffer->copy_values_to(this); |
600 code_buffer->copy_values_to(this); |
|
601 |
602 if (ScavengeRootsInCode) { |
602 if (ScavengeRootsInCode) { |
603 Universe::heap()->register_nmethod(this); |
603 Universe::heap()->register_nmethod(this); |
604 } |
604 } |
605 debug_only(Universe::heap()->verify_nmethod(this)); |
605 debug_only(Universe::heap()->verify_nmethod(this)); |
606 CodeCache::commit(this); |
606 CodeCache::commit(this); |
755 code_buffer->copy_code_and_locs_to(this); |
755 code_buffer->copy_code_and_locs_to(this); |
756 // Copy contents of ScopeDescRecorder to nmethod |
756 // Copy contents of ScopeDescRecorder to nmethod |
757 code_buffer->copy_values_to(this); |
757 code_buffer->copy_values_to(this); |
758 debug_info->copy_to(this); |
758 debug_info->copy_to(this); |
759 dependencies->copy_to(this); |
759 dependencies->copy_to(this); |
|
760 clear_unloading_state(); |
760 if (ScavengeRootsInCode) { |
761 if (ScavengeRootsInCode) { |
761 Universe::heap()->register_nmethod(this); |
762 Universe::heap()->register_nmethod(this); |
762 } |
763 } |
763 debug_only(Universe::heap()->verify_nmethod(this)); |
764 debug_only(Universe::heap()->verify_nmethod(this)); |
764 |
765 |
1023 if (mdo == NULL) return; |
1024 if (mdo == NULL) return; |
1024 // There is a benign race here. See comments in methodData.hpp. |
1025 // There is a benign race here. See comments in methodData.hpp. |
1025 mdo->inc_decompile_count(); |
1026 mdo->inc_decompile_count(); |
1026 } |
1027 } |
1027 |
1028 |
1028 void nmethod::make_unloaded(oop cause) { |
1029 void nmethod::make_unloaded() { |
1029 |
|
1030 post_compiled_method_unload(); |
1030 post_compiled_method_unload(); |
1031 |
1031 |
1032 // This nmethod is being unloaded, make sure that dependencies |
1032 // This nmethod is being unloaded, make sure that dependencies |
1033 // recorded in instanceKlasses get flushed. |
1033 // recorded in instanceKlasses get flushed. |
1034 // Since this work is being done during a GC, defer deleting dependencies from the |
1034 // Since this work is being done during a GC, defer deleting dependencies from the |
1040 LogTarget(Trace, class, unload, nmethod) lt; |
1040 LogTarget(Trace, class, unload, nmethod) lt; |
1041 if (lt.is_enabled()) { |
1041 if (lt.is_enabled()) { |
1042 LogStream ls(lt); |
1042 LogStream ls(lt); |
1043 ls.print("making nmethod " INTPTR_FORMAT |
1043 ls.print("making nmethod " INTPTR_FORMAT |
1044 " unloadable, Method*(" INTPTR_FORMAT |
1044 " unloadable, Method*(" INTPTR_FORMAT |
1045 "), cause(" INTPTR_FORMAT ") ", |
1045 ") ", |
1046 p2i(this), p2i(_method), p2i(cause)); |
1046 p2i(this), p2i(_method)); |
1047 if (cause != NULL) { |
|
1048 cause->print_value_on(&ls); |
|
1049 } |
|
1050 ls.cr(); |
1047 ls.cr(); |
1051 } |
1048 } |
1052 // Unlink the osr method, so we do not look this up again |
1049 // Unlink the osr method, so we do not look this up again |
1053 if (is_osr_method()) { |
1050 if (is_osr_method()) { |
1054 // Invalidate the osr nmethod only once |
1051 // Invalidate the osr nmethod only once |
1077 _method = NULL; // Clear the method of this dead nmethod |
1074 _method = NULL; // Clear the method of this dead nmethod |
1078 } |
1075 } |
1079 |
1076 |
1080 // Make the class unloaded - i.e., change state and notify sweeper |
1077 // Make the class unloaded - i.e., change state and notify sweeper |
1081 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); |
1078 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); |
1082 if (is_in_use()) { |
|
1083 // Transitioning directly from live to unloaded -- so |
|
1084 // we need to force a cache clean-up; remember this |
|
1085 // for later on. |
|
1086 CodeCache::set_needs_cache_clean(true); |
|
1087 } |
|
1088 |
1079 |
1089 // Unregister must be done before the state change |
1080 // Unregister must be done before the state change |
1090 Universe::heap()->unregister_nmethod(this); |
1081 Universe::heap()->unregister_nmethod(this); |
1091 |
1082 |
1092 _state = unloaded; |
1083 _state = unloaded; |
1093 |
1084 |
1094 // Log the unloading. |
1085 // Log the unloading. |
1095 log_state_change(cause); |
1086 log_state_change(); |
1096 |
1087 |
1097 #if INCLUDE_JVMCI |
1088 #if INCLUDE_JVMCI |
1098 // The method can only be unloaded after the pointer to the installed code |
1089 // The method can only be unloaded after the pointer to the installed code |
1099 // Java wrapper is no longer alive. Here we need to clear out this weak |
1090 // Java wrapper is no longer alive. Here we need to clear out this weak |
1100 // reference to the dead object. |
1091 // reference to the dead object. |
1114 if (method() != NULL) { |
1105 if (method() != NULL) { |
1115 method()->method_holder()->remove_osr_nmethod(this); |
1106 method()->method_holder()->remove_osr_nmethod(this); |
1116 } |
1107 } |
1117 } |
1108 } |
1118 |
1109 |
1119 void nmethod::log_state_change(oop cause) const { |
1110 void nmethod::log_state_change() const { |
1120 if (LogCompilation) { |
1111 if (LogCompilation) { |
1121 if (xtty != NULL) { |
1112 if (xtty != NULL) { |
1122 ttyLocker ttyl; // keep the following output all in one block |
1113 ttyLocker ttyl; // keep the following output all in one block |
1123 if (_state == unloaded) { |
1114 if (_state == unloaded) { |
1124 xtty->begin_elem("make_unloaded thread='" UINTX_FORMAT "'", |
1115 xtty->begin_elem("make_unloaded thread='" UINTX_FORMAT "'", |
1378 } |
1366 } |
1379 } |
1367 } |
1380 } |
1368 } |
1381 } |
1369 } |
1382 |
1370 |
1383 |
|
1384 // If this oop is not live, the nmethod can be unloaded. |
|
1385 bool nmethod::can_unload(BoolObjectClosure* is_alive, oop* root) { |
|
1386 assert(root != NULL, "just checking"); |
|
1387 oop obj = *root; |
|
1388 if (obj == NULL || is_alive->do_object_b(obj)) { |
|
1389 return false; |
|
1390 } |
|
1391 |
|
1392 // An nmethod might be unloaded simply because one of its constant oops has gone dead. |
|
1393 // No actual classes need to be unloaded in order for this to occur. |
|
1394 make_unloaded(obj); |
|
1395 return true; |
|
1396 } |
|
1397 |
|
1398 // ------------------------------------------------------------------ |
1371 // ------------------------------------------------------------------ |
1399 // post_compiled_method_load_event |
1372 // post_compiled_method_load_event |
1400 // new method for install_code() path |
1373 // new method for install_code() path |
1401 // Transfer information from compilation to jvmti |
1374 // Transfer information from compilation to jvmti |
1402 void nmethod::post_compiled_method_load_event() { |
1375 void nmethod::post_compiled_method_load_event() { |
1465 // having the unload event reported - this will ensure that we don't |
1438 // having the unload event reported - this will ensure that we don't |
1466 // attempt to report the event in the unlikely scenario where the |
1439 // attempt to report the event in the unlikely scenario where the |
1467 // event is enabled at the time the nmethod is made a zombie. |
1440 // event is enabled at the time the nmethod is made a zombie. |
1468 set_unload_reported(); |
1441 set_unload_reported(); |
1469 } |
1442 } |
1470 |
|
1471 bool nmethod::unload_if_dead_at(RelocIterator* iter_at_oop, BoolObjectClosure *is_alive) { |
|
1472 assert(iter_at_oop->type() == relocInfo::oop_type, "Wrong relocation type"); |
|
1473 |
|
1474 oop_Relocation* r = iter_at_oop->oop_reloc(); |
|
1475 // Traverse those oops directly embedded in the code. |
|
1476 // Other oops (oop_index>0) are seen as part of scopes_oops. |
|
1477 assert(1 == (r->oop_is_immediate()) + |
|
1478 (r->oop_addr() >= oops_begin() && r->oop_addr() < oops_end()), |
|
1479 "oop must be found in exactly one place"); |
|
1480 if (r->oop_is_immediate() && r->oop_value() != NULL) { |
|
1481 // Unload this nmethod if the oop is dead. |
|
1482 if (can_unload(is_alive, r->oop_addr())) { |
|
1483 return true;; |
|
1484 } |
|
1485 } |
|
1486 |
|
1487 return false; |
|
1488 } |
|
1489 |
|
1490 bool nmethod::do_unloading_scopes(BoolObjectClosure* is_alive) { |
|
1491 // Scopes |
|
1492 for (oop* p = oops_begin(); p < oops_end(); p++) { |
|
1493 if (*p == Universe::non_oop_word()) continue; // skip non-oops |
|
1494 if (can_unload(is_alive, p)) { |
|
1495 return true; |
|
1496 } |
|
1497 } |
|
1498 return false; |
|
1499 } |
|
1500 |
|
1501 bool nmethod::do_unloading_oops(address low_boundary, BoolObjectClosure* is_alive) { |
|
1502 // Compiled code |
|
1503 |
|
1504 // Prevent extra code cache walk for platforms that don't have immediate oops. |
|
1505 if (relocInfo::mustIterateImmediateOopsInCode()) { |
|
1506 RelocIterator iter(this, low_boundary); |
|
1507 while (iter.next()) { |
|
1508 if (iter.type() == relocInfo::oop_type) { |
|
1509 if (unload_if_dead_at(&iter, is_alive)) { |
|
1510 return true; |
|
1511 } |
|
1512 } |
|
1513 } |
|
1514 } |
|
1515 |
|
1516 return do_unloading_scopes(is_alive); |
|
1517 } |
|
1518 |
|
1519 #if INCLUDE_JVMCI |
|
1520 bool nmethod::do_unloading_jvmci() { |
|
1521 if (_jvmci_installed_code != NULL) { |
|
1522 if (JNIHandles::is_global_weak_cleared(_jvmci_installed_code)) { |
|
1523 if (_jvmci_installed_code_triggers_invalidation) { |
|
1524 // The reference to the installed code has been dropped so invalidate |
|
1525 // this nmethod and allow the sweeper to reclaim it. |
|
1526 make_not_entrant(); |
|
1527 } |
|
1528 clear_jvmci_installed_code(); |
|
1529 } |
|
1530 } |
|
1531 return false; |
|
1532 } |
|
1533 #endif |
|
1534 |
1443 |
1535 // Iterate over metadata calling this function. Used by RedefineClasses |
1444 // Iterate over metadata calling this function. Used by RedefineClasses |
1536 void nmethod::metadata_do(void f(Metadata*)) { |
1445 void nmethod::metadata_do(void f(Metadata*)) { |
1537 { |
1446 { |
1538 // Visit all immediate references that are embedded in the instruction stream. |
1447 // Visit all immediate references that are embedded in the instruction stream. |
1575 f(md); |
1484 f(md); |
1576 } |
1485 } |
1577 |
1486 |
1578 // Visit metadata not embedded in the other places. |
1487 // Visit metadata not embedded in the other places. |
1579 if (_method != NULL) f(_method); |
1488 if (_method != NULL) f(_method); |
|
1489 } |
|
1490 |
|
1491 |
|
1492 // This is called at the end of the strong tracing/marking phase of a |
|
1493 // GC to unload an nmethod if it contains otherwise unreachable |
|
1494 // oops. |
|
1495 |
|
1496 void nmethod::do_unloading(bool unloading_occurred) { |
|
1497 // Make sure the oop's ready to receive visitors |
|
1498 assert(!is_zombie() && !is_unloaded(), |
|
1499 "should not call follow on zombie or unloaded nmethod"); |
|
1500 |
|
1501 if (is_unloading()) { |
|
1502 make_unloaded(); |
|
1503 } else { |
|
1504 #if INCLUDE_JVMCI |
|
1505 if (_jvmci_installed_code != NULL) { |
|
1506 if (JNIHandles::is_global_weak_cleared(_jvmci_installed_code)) { |
|
1507 if (_jvmci_installed_code_triggers_invalidation) { |
|
1508 make_not_entrant(); |
|
1509 } |
|
1510 clear_jvmci_installed_code(); |
|
1511 } |
|
1512 } |
|
1513 #endif |
|
1514 |
|
1515 unload_nmethod_caches(unloading_occurred); |
|
1516 } |
1580 } |
1517 } |
1581 |
1518 |
1582 void nmethod::oops_do(OopClosure* f, bool allow_zombie) { |
1519 void nmethod::oops_do(OopClosure* f, bool allow_zombie) { |
1583 // make sure the oops ready to receive visitors |
1520 // make sure the oops ready to receive visitors |
1584 assert(allow_zombie || !is_zombie(), "should not call follow on zombie nmethod"); |
1521 assert(allow_zombie || !is_zombie(), "should not call follow on zombie nmethod"); |