< prev index next >

src/share/vm/code/codeCache.cpp

Print this page
rev 10188 : [mq]: scavenge_nmethods_auto_prune


 620   }
 621 }
 622 
 623 void CodeCache::blobs_do(CodeBlobClosure* f) {
 624   assert_locked_or_safepoint(CodeCache_lock);
 625   FOR_ALL_HEAPS(heap) {
 626     FOR_ALL_BLOBS(cb, *heap) {
 627       if (cb->is_alive()) {
 628         f->do_code_blob(cb);
 629 
 630 #ifdef ASSERT
 631         if (cb->is_nmethod())
 632         ((nmethod*)cb)->verify_scavenge_root_oops();
 633 #endif //ASSERT
 634       }
 635     }
 636   }
 637 }
 638 
 639 // Walk the list of methods which might contain non-perm oops.
 640 void CodeCache::scavenge_root_nmethods_do(CodeBlobClosure* f) {
 641   assert_locked_or_safepoint(CodeCache_lock);
 642 
 643   if (UseG1GC) {
 644     return;
 645   }
 646 

 647   debug_only(mark_scavenge_root_nmethods());
 648 
 649   for (nmethod* cur = scavenge_root_nmethods(); cur != NULL; cur = cur->scavenge_root_link()) {


 650     debug_only(cur->clear_scavenge_root_marked());
 651     assert(cur->scavenge_root_not_marked(), "");
 652     assert(cur->on_scavenge_root_list(), "else shouldn't be on this list");
 653 
 654     bool is_live = (!cur->is_zombie() && !cur->is_unloaded());
 655     if (TraceScavenge) {
 656       cur->print_on(tty, is_live ? "scavenge root" : "dead scavenge root"); tty->cr();
 657     }
 658     if (is_live) {
 659       // Perform cur->oops_do(f), maybe just once per nmethod.
 660       f->do_code_blob(cur);
 661     }












 662   }
 663 
 664   // Check for stray marks.
 665   debug_only(verify_perm_nmethods(NULL));
 666 }
 667 
 668 void CodeCache::add_scavenge_root_nmethod(nmethod* nm) {
 669   assert_locked_or_safepoint(CodeCache_lock);
 670 
 671   if (UseG1GC) {
 672     return;
 673   }
 674 
 675   nm->set_on_scavenge_root_list();
 676   nm->set_scavenge_root_link(_scavenge_root_nmethods);
 677   set_scavenge_root_nmethods(nm);
 678   print_trace("add_scavenge_root", nm);
 679 }
 680 


















 681 void CodeCache::drop_scavenge_root_nmethod(nmethod* nm) {
 682   assert_locked_or_safepoint(CodeCache_lock);
 683 
 684   if (UseG1GC) {
 685     return;
 686   }
 687 
 688   print_trace("drop_scavenge_root", nm);
 689   nmethod* last = NULL;
 690   nmethod* cur = scavenge_root_nmethods();
 691   while (cur != NULL) {
 692     nmethod* next = cur->scavenge_root_link();
 693     if (cur == nm) {
 694       if (last != NULL)
 695             last->set_scavenge_root_link(next);
 696       else  set_scavenge_root_nmethods(next);
 697       nm->set_scavenge_root_link(NULL);
 698       nm->clear_on_scavenge_root_list();
 699       return;
 700     }
 701     last = cur;
 702     cur = next;
 703   }
 704   assert(false, "should have been on list");
 705 }
 706 
 707 void CodeCache::prune_scavenge_root_nmethods() {
 708   assert_locked_or_safepoint(CodeCache_lock);
 709 
 710   if (UseG1GC) {
 711     return;
 712   }
 713 
 714   debug_only(mark_scavenge_root_nmethods());
 715 
 716   nmethod* last = NULL;
 717   nmethod* cur = scavenge_root_nmethods();
 718   while (cur != NULL) {
 719     nmethod* next = cur->scavenge_root_link();
 720     debug_only(cur->clear_scavenge_root_marked());
 721     assert(cur->scavenge_root_not_marked(), "");
 722     assert(cur->on_scavenge_root_list(), "else shouldn't be on this list");
 723 
 724     if (!cur->is_zombie() && !cur->is_unloaded()
 725         && cur->detect_scavenge_root_oops()) {
 726       // Keep it.  Advance 'last' to prevent deletion.
 727       last = cur;
 728     } else {
 729       // Prune it from the list, so we don't have to look at it any more.
 730       print_trace("prune_scavenge_root", cur);
 731       cur->set_scavenge_root_link(NULL);
 732       cur->clear_on_scavenge_root_list();
 733       if (last != NULL)
 734             last->set_scavenge_root_link(next);
 735       else  set_scavenge_root_nmethods(next);
 736     }
 737     cur = next;
 738   }
 739 
 740   // Check for stray marks.
 741   debug_only(verify_perm_nmethods(NULL));
 742 }
 743 
 744 #ifndef PRODUCT
 745 void CodeCache::asserted_non_scavengable_nmethods_do(CodeBlobClosure* f) {
 746   if (UseG1GC) {
 747     return;
 748   }
 749 
 750   // While we are here, verify the integrity of the list.
 751   mark_scavenge_root_nmethods();
 752   for (nmethod* cur = scavenge_root_nmethods(); cur != NULL; cur = cur->scavenge_root_link()) {
 753     assert(cur->on_scavenge_root_list(), "else shouldn't be on this list");
 754     cur->clear_scavenge_root_marked();
 755   }




 620   }
 621 }
 622 
 623 void CodeCache::blobs_do(CodeBlobClosure* f) {
 624   assert_locked_or_safepoint(CodeCache_lock);
 625   FOR_ALL_HEAPS(heap) {
 626     FOR_ALL_BLOBS(cb, *heap) {
 627       if (cb->is_alive()) {
 628         f->do_code_blob(cb);
 629 
 630 #ifdef ASSERT
 631         if (cb->is_nmethod())
 632         ((nmethod*)cb)->verify_scavenge_root_oops();
 633 #endif //ASSERT
 634       }
 635     }
 636   }
 637 }
 638 
 639 // Walk the list of methods which might contain non-perm oops.
 640 void CodeCache::scavenge_root_nmethods_do(CodeBlobToOopClosure* f) {
 641   assert_locked_or_safepoint(CodeCache_lock);
 642 
 643   if (UseG1GC) {
 644     return;
 645   }
 646 
 647   const bool fix_relocations = f->fix_relocations();
 648   debug_only(mark_scavenge_root_nmethods());
 649 
 650   nmethod* prev = NULL;
 651   nmethod* cur = scavenge_root_nmethods();
 652   while (cur != NULL) {
 653     debug_only(cur->clear_scavenge_root_marked());
 654     assert(cur->scavenge_root_not_marked(), "");
 655     assert(cur->on_scavenge_root_list(), "else shouldn't be on this list");
 656 
 657     bool is_live = (!cur->is_zombie() && !cur->is_unloaded());
 658     if (TraceScavenge) {
 659       cur->print_on(tty, is_live ? "scavenge root" : "dead scavenge root"); tty->cr();
 660     }
 661     if (is_live) {
 662       // Perform cur->oops_do(f), maybe just once per nmethod.
 663       f->do_code_blob(cur);
 664     }
 665     nmethod* const next = cur->scavenge_root_link();
 666     // The scavengable nmethod list must contain all methods with scavengable
 667     // oops. It is safe to include more nmethod on the list, but we do not
 668     // expect any live non-scavengable nmethods on the list.
 669     if (fix_relocations) {
 670       if (!is_live || !cur->detect_scavenge_root_oops()) {
 671         unlink_scavenge_root_nmethod(cur, prev);
 672       } else {
 673         prev = cur;
 674       }
 675     }
 676     cur = next;
 677   }
 678 
 679   // Check for stray marks.
 680   debug_only(verify_perm_nmethods(NULL));
 681 }
 682 
 683 void CodeCache::add_scavenge_root_nmethod(nmethod* nm) {
 684   assert_locked_or_safepoint(CodeCache_lock);
 685 
 686   if (UseG1GC) {
 687     return;
 688   }
 689 
 690   nm->set_on_scavenge_root_list();
 691   nm->set_scavenge_root_link(_scavenge_root_nmethods);
 692   set_scavenge_root_nmethods(nm);
 693   print_trace("add_scavenge_root", nm);
 694 }
 695 
 696 void CodeCache::unlink_scavenge_root_nmethod(nmethod* nm, nmethod* prev) {
 697   assert_locked_or_safepoint(CodeCache_lock);
 698 
 699   assert((prev == NULL && scavenge_root_nmethods() == nm) ||
 700          (prev != NULL && prev->scavenge_root_link() == nm), "precondition");
 701 
 702   assert(!UseG1GC, "G1 does not use the scavenge_root_nmethods list");
 703 
 704   print_trace("unlink_scavenge_root", nm);
 705   if (prev == NULL) {
 706     set_scavenge_root_nmethods(nm->scavenge_root_link());
 707   } else {
 708     prev->set_scavenge_root_link(nm->scavenge_root_link());
 709   }
 710   nm->set_scavenge_root_link(NULL);
 711   nm->clear_on_scavenge_root_list();
 712 }
 713 
 714 void CodeCache::drop_scavenge_root_nmethod(nmethod* nm) {
 715   assert_locked_or_safepoint(CodeCache_lock);
 716 
 717   if (UseG1GC) {
 718     return;
 719   }
 720 
 721   print_trace("drop_scavenge_root", nm);
 722   nmethod* prev = NULL;
 723   for (nmethod* cur = scavenge_root_nmethods(); cur != NULL; cur = cur->scavenge_root_link()) {


 724     if (cur == nm) {
 725       unlink_scavenge_root_nmethod(cur, prev);




 726       return;
 727     }
 728     prev = cur;

 729   }
 730   assert(false, "should have been on list");
 731 }
 732 
 733 void CodeCache::prune_scavenge_root_nmethods() {
 734   assert_locked_or_safepoint(CodeCache_lock);
 735 
 736   if (UseG1GC) {
 737     return;
 738   }
 739 
 740   debug_only(mark_scavenge_root_nmethods());
 741 
 742   nmethod* last = NULL;
 743   nmethod* cur = scavenge_root_nmethods();
 744   while (cur != NULL) {
 745     nmethod* next = cur->scavenge_root_link();
 746     debug_only(cur->clear_scavenge_root_marked());
 747     assert(cur->scavenge_root_not_marked(), "");
 748     assert(cur->on_scavenge_root_list(), "else shouldn't be on this list");
 749 
 750     if (!cur->is_zombie() && !cur->is_unloaded()
 751         && cur->detect_scavenge_root_oops()) {
 752       // Keep it.  Advance 'last' to prevent deletion.
 753       last = cur;
 754     } else {
 755       // Prune it from the list, so we don't have to look at it any more.
 756       print_trace("prune_scavenge_root", cur);
 757       unlink_scavenge_root_nmethod(cur, last);




 758     }
 759     cur = next;
 760   }
 761 
 762   // Check for stray marks.
 763   debug_only(verify_perm_nmethods(NULL));
 764 }
 765 
 766 #ifndef PRODUCT
 767 void CodeCache::asserted_non_scavengable_nmethods_do(CodeBlobClosure* f) {
 768   if (UseG1GC) {
 769     return;
 770   }
 771 
 772   // While we are here, verify the integrity of the list.
 773   mark_scavenge_root_nmethods();
 774   for (nmethod* cur = scavenge_root_nmethods(); cur != NULL; cur = cur->scavenge_root_link()) {
 775     assert(cur->on_scavenge_root_list(), "else shouldn't be on this list");
 776     cur->clear_scavenge_root_marked();
 777   }


< prev index next >