548
549 nm = new (nmethod_size, comp_level)
550 nmethod(method(), nmethod_size, compile_id, entry_bci, offsets,
551 orig_pc_offset, debug_info, dependencies, code_buffer, frame_size,
552 oop_maps,
553 handler_table,
554 nul_chk_table,
555 compiler,
556 comp_level);
557
558 if (nm != NULL) {
559 // To make dependency checking during class loading fast, record
560 // the nmethod dependencies in the classes it is dependent on.
561 // This allows the dependency checking code to simply walk the
562 // class hierarchy above the loaded class, checking only nmethods
563 // which are dependent on those classes. The slow way is to
564 // check every nmethod for dependencies which makes it linear in
565 // the number of methods compiled. For applications with a lot
566 // classes the slow way is too slow.
567 for (Dependencies::DepStream deps(nm); deps.next(); ) {
568 Klass* klass = deps.context_type();
569 if (klass == NULL) {
570 continue; // ignore things like evol_method
571 }
572
573 // record this nmethod as dependent on this klass
574 InstanceKlass::cast(klass)->add_dependent_nmethod(nm);
575 }
576 NOT_PRODUCT(nmethod_stats.note_nmethod(nm));
577 if (PrintAssembly || CompilerOracle::has_option_string(method, "PrintAssembly")) {
578 Disassembler::decode(nm);
579 }
580 }
581 }
582 // Do verification and logging outside CodeCache_lock.
583 if (nm != NULL) {
584 // Safepoints in nmethod::verify aren't allowed because nm hasn't been installed yet.
585 DEBUG_ONLY(nm->verify();)
586 nm->log_new_nmethod();
587 }
588 return nm;
589 }
590
591
592 // For native wrappers
593 nmethod::nmethod(
594 Method* method,
1447 // Notify all classes this nmethod is dependent on that it is no
1448 // longer dependent. This should only be called in two situations.
1449 // First, when a nmethod transitions to a zombie all dependents need
1450 // to be clear. Since zombification happens at a safepoint there's no
1451 // synchronization issues. The second place is a little more tricky.
1452 // During phase 1 of mark sweep class unloading may happen and as a
1453 // result some nmethods may get unloaded. In this case the flushing
1454 // of dependencies must happen during phase 1 since after GC any
1455 // dependencies in the unloaded nmethod won't be updated, so
1456 // traversing the dependency information in unsafe. In that case this
1457 // function is called with a non-NULL argument and this function only
1458 // notifies instanceKlasses that are reachable
1459
1460 void nmethod::flush_dependencies(BoolObjectClosure* is_alive) {
1461 assert_locked_or_safepoint(CodeCache_lock);
1462 assert(Universe::heap()->is_gc_active() == (is_alive != NULL),
1463 "is_alive is non-NULL if and only if we are called during GC");
1464 if (!has_flushed_dependencies()) {
1465 set_has_flushed_dependencies();
1466 for (Dependencies::DepStream deps(this); deps.next(); ) {
1467 Klass* klass = deps.context_type();
1468 if (klass == NULL) continue; // ignore things like evol_method
1469
1470 // During GC the is_alive closure is non-NULL, and is used to
1471 // determine liveness of dependees that need to be updated.
1472 if (is_alive == NULL || klass->is_loader_alive(is_alive)) {
1473 InstanceKlass::cast(klass)->remove_dependent_nmethod(this);
1474 }
1475 }
1476 }
1477 }
1478
1479
1480 // If this oop is not live, the nmethod can be unloaded.
1481 bool nmethod::can_unload(BoolObjectClosure* is_alive, oop* root, bool unloading_occurred) {
1482 assert(root != NULL, "just checking");
1483 oop obj = *root;
1484 if (obj == NULL || is_alive->do_object_b(obj)) {
1485 return false;
1486 }
1487
1488 // If ScavengeRootsInCode is true, an nmethod might be unloaded
1489 // simply because one of its constant oops has gone dead.
1490 // No actual classes need to be unloaded in order for this to occur.
1491 assert(unloading_occurred || ScavengeRootsInCode, "Inconsistency in unloading");
1492 make_unloaded(is_alive, obj);
1493 return true;
1494 }
|
548
549 nm = new (nmethod_size, comp_level)
550 nmethod(method(), nmethod_size, compile_id, entry_bci, offsets,
551 orig_pc_offset, debug_info, dependencies, code_buffer, frame_size,
552 oop_maps,
553 handler_table,
554 nul_chk_table,
555 compiler,
556 comp_level);
557
558 if (nm != NULL) {
559 // To make dependency checking during class loading fast, record
560 // the nmethod dependencies in the classes it is dependent on.
561 // This allows the dependency checking code to simply walk the
562 // class hierarchy above the loaded class, checking only nmethods
563 // which are dependent on those classes. The slow way is to
564 // check every nmethod for dependencies which makes it linear in
565 // the number of methods compiled. For applications with a lot
566 // classes the slow way is too slow.
567 for (Dependencies::DepStream deps(nm); deps.next(); ) {
568 if (deps.type() != Dependencies::call_site_target_value) {
569 Klass* klass = deps.context_type();
570 if (klass == NULL) {
571 continue; // ignore things like evol_method
572 }
573 // record this nmethod as dependent on this klass
574 InstanceKlass::cast(klass)->add_dependent_nmethod(nm);
575 } else {
576 // CallSite dependencies are managed on per-CallSite instance basis.
577 oop call_site = deps.argument_oop(0);
578 MethodHandles::add_dependent_nmethod(call_site, nm);
579 }
580 }
581 NOT_PRODUCT(nmethod_stats.note_nmethod(nm));
582 if (PrintAssembly || CompilerOracle::has_option_string(method, "PrintAssembly")) {
583 Disassembler::decode(nm);
584 }
585 }
586 }
587 // Do verification and logging outside CodeCache_lock.
588 if (nm != NULL) {
589 // Safepoints in nmethod::verify aren't allowed because nm hasn't been installed yet.
590 DEBUG_ONLY(nm->verify();)
591 nm->log_new_nmethod();
592 }
593 return nm;
594 }
595
596
597 // For native wrappers
598 nmethod::nmethod(
599 Method* method,
1452 // Notify all classes this nmethod is dependent on that it is no
1453 // longer dependent. This should only be called in two situations.
1454 // First, when a nmethod transitions to a zombie all dependents need
1455 // to be clear. Since zombification happens at a safepoint there's no
1456 // synchronization issues. The second place is a little more tricky.
1457 // During phase 1 of mark sweep class unloading may happen and as a
1458 // result some nmethods may get unloaded. In this case the flushing
1459 // of dependencies must happen during phase 1 since after GC any
1460 // dependencies in the unloaded nmethod won't be updated, so
1461 // traversing the dependency information in unsafe. In that case this
1462 // function is called with a non-NULL argument and this function only
1463 // notifies instanceKlasses that are reachable
1464
1465 void nmethod::flush_dependencies(BoolObjectClosure* is_alive) {
1466 assert_locked_or_safepoint(CodeCache_lock);
1467 assert(Universe::heap()->is_gc_active() == (is_alive != NULL),
1468 "is_alive is non-NULL if and only if we are called during GC");
1469 if (!has_flushed_dependencies()) {
1470 set_has_flushed_dependencies();
1471 for (Dependencies::DepStream deps(this); deps.next(); ) {
1472 if (deps.type() != Dependencies::call_site_target_value) {
1473 Klass* klass = deps.context_type();
1474 if (klass == NULL) {
1475 continue; // ignore things like evol_method
1476 }
1477 // During GC the is_alive closure is non-NULL, and is used to
1478 // determine liveness of dependees that need to be updated.
1479 if (is_alive == NULL || klass->is_loader_alive(is_alive)) {
1480 InstanceKlass::cast(klass)->remove_dependent_nmethod(this);
1481 }
1482 } else {
1483 // CallSite dependencies are managed on per-CallSite instance basis.
1484 oop call_site = deps.argument_oop(0);
1485 MethodHandles::remove_dependent_nmethod(call_site, this);
1486 }
1487 }
1488 }
1489 }
1490
1491
1492 // If this oop is not live, the nmethod can be unloaded.
1493 bool nmethod::can_unload(BoolObjectClosure* is_alive, oop* root, bool unloading_occurred) {
1494 assert(root != NULL, "just checking");
1495 oop obj = *root;
1496 if (obj == NULL || is_alive->do_object_b(obj)) {
1497 return false;
1498 }
1499
1500 // If ScavengeRootsInCode is true, an nmethod might be unloaded
1501 // simply because one of its constant oops has gone dead.
1502 // No actual classes need to be unloaded in order for this to occur.
1503 assert(unloading_occurred || ScavengeRootsInCode, "Inconsistency in unloading");
1504 make_unloaded(is_alive, obj);
1505 return true;
1506 }
|