594 if (PrintMethodFlushing && Verbose) {
595 tty->print_cr("### Nmethod %3d/" PTR_FORMAT " (marked for reclamation) being flushed", nm->compile_id(), nm);
596 }
597 release_nmethod(nm);
598 assert(result == None, "sanity");
599 result = Flushed;
600 } else {
601 if (PrintMethodFlushing && Verbose) {
602 tty->print_cr("### Nmethod %3d/" PTR_FORMAT " (zombie) being marked for reclamation", nm->compile_id(), nm);
603 }
604 nm->mark_for_reclamation();
605 // Keep track of code cache state change
606 _bytes_changed += nm->total_size();
607 SWEEP(nm);
608 assert(result == None, "sanity");
609 result = MarkedForReclamation;
610 }
611 } else if (nm->is_not_entrant()) {
612 // If there are no current activations of this method on the
613 // stack we can safely convert it to a zombie method
614 if (nm->can_not_entrant_be_converted()) {
615 // Clear ICStubs to prevent back patching stubs of zombie or unloaded
616 // nmethods during the next safepoint (see ICStub::finalize).
617 {
618 MutexLocker cl(CompiledIC_lock);
619 nm->clear_ic_stubs();
620 }
621 if (PrintMethodFlushing && Verbose) {
622 tty->print_cr("### Nmethod %3d/" PTR_FORMAT " (not entrant) being made zombie", nm->compile_id(), nm);
623 }
624 // Code cache state change is tracked in make_zombie()
625 nm->make_zombie();
626 SWEEP(nm);
627 assert(result == None, "sanity");
628 result = MadeZombie;
629 assert(nm->is_zombie(), "nmethod must be zombie");
630 } else {
631 // Still alive, clean up its inline caches
632 MutexLocker cl(CompiledIC_lock);
633 nm->cleanup_inline_caches();
634 SWEEP(nm);
635 }
636 } else if (nm->is_unloaded()) {
637 // Unloaded code, just make it a zombie
638 if (PrintMethodFlushing && Verbose) {
639 tty->print_cr("### Nmethod %3d/" PTR_FORMAT " (unloaded) being made zombie", nm->compile_id(), nm);
640 }
641 if (nm->is_osr_method()) {
642 SWEEP(nm);
643 // No inline caches will ever point to osr methods, so we can just remove it
644 release_nmethod(nm);
645 assert(result == None, "sanity");
646 result = Flushed;
647 } else {
648 // Code cache state change is tracked in make_zombie()
649 nm->make_zombie();
650 SWEEP(nm);
651 assert(result == None, "sanity");
652 result = MadeZombie;
653 }
654 } else {
655 possibly_flush(nm);
656 // Clean-up all inline caches that point to zombie/non-reentrant methods
657 MutexLocker cl(CompiledIC_lock);
658 nm->cleanup_inline_caches();
659 SWEEP(nm);
660 }
661 return result;
662 }
663
664
665 void NMethodSweeper::possibly_flush(nmethod* nm) {
666 if (UseCodeCacheFlushing) {
667 if (!nm->is_locked_by_vm() && !nm->is_osr_method() && !nm->is_native_method()) {
|
594 if (PrintMethodFlushing && Verbose) {
595 tty->print_cr("### Nmethod %3d/" PTR_FORMAT " (marked for reclamation) being flushed", nm->compile_id(), nm);
596 }
597 release_nmethod(nm);
598 assert(result == None, "sanity");
599 result = Flushed;
600 } else {
601 if (PrintMethodFlushing && Verbose) {
602 tty->print_cr("### Nmethod %3d/" PTR_FORMAT " (zombie) being marked for reclamation", nm->compile_id(), nm);
603 }
604 nm->mark_for_reclamation();
605 // Keep track of code cache state change
606 _bytes_changed += nm->total_size();
607 SWEEP(nm);
608 assert(result == None, "sanity");
609 result = MarkedForReclamation;
610 }
611 } else if (nm->is_not_entrant()) {
612 // If there are no current activations of this method on the
613 // stack we can safely convert it to a zombie method
614 if (nm->can_convert_to_zombie()) {
615 // Clear ICStubs to prevent back patching stubs of zombie or unloaded
616 // nmethods during the next safepoint (see ICStub::finalize).
617 {
618 MutexLocker cl(CompiledIC_lock);
619 nm->clear_ic_stubs();
620 }
621 if (PrintMethodFlushing && Verbose) {
622 tty->print_cr("### Nmethod %3d/" PTR_FORMAT " (not entrant) being made zombie", nm->compile_id(), nm);
623 }
624 // Code cache state change is tracked in make_zombie()
625 nm->make_zombie();
626 SWEEP(nm);
627 assert(result == None, "sanity");
628 result = MadeZombie;
629 assert(nm->is_zombie(), "nmethod must be zombie");
630 } else {
631 // Still alive, clean up its inline caches
632 MutexLocker cl(CompiledIC_lock);
633 nm->cleanup_inline_caches();
634 SWEEP(nm);
635 }
636 } else if (nm->is_unloaded()) {
637 // Unloaded code, just make it a zombie
638 if (PrintMethodFlushing && Verbose) {
639 tty->print_cr("### Nmethod %3d/" PTR_FORMAT " (unloaded) being made zombie", nm->compile_id(), nm);
640 }
641 if (nm->is_osr_method()) {
642 SWEEP(nm);
643 // No inline caches will ever point to osr methods, so we can just remove it
644 release_nmethod(nm);
645 assert(result == None, "sanity");
646 result = Flushed;
647 } else {
648 {
649 // Clean ICs of unloaded nmethods as well because they may reference other
650 // unloaded nmethods that may be flushed earlier in the sweeper cycle.
651 MutexLocker cl(CompiledIC_lock);
652 nm->cleanup_inline_caches();
653 }
654 // Code cache state change is tracked in make_zombie()
655 nm->make_zombie();
656 SWEEP(nm);
657 assert(result == None, "sanity");
658 result = MadeZombie;
659 }
660 } else {
661 possibly_flush(nm);
662 // Clean-up all inline caches that point to zombie/non-reentrant methods
663 MutexLocker cl(CompiledIC_lock);
664 nm->cleanup_inline_caches();
665 SWEEP(nm);
666 }
667 return result;
668 }
669
670
671 void NMethodSweeper::possibly_flush(nmethod* nm) {
672 if (UseCodeCacheFlushing) {
673 if (!nm->is_locked_by_vm() && !nm->is_osr_method() && !nm->is_native_method()) {
|