diff --git a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp index 5b88491..b24f8c3 100644 --- a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp +++ b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp @@ -1045,13 +1045,12 @@ CMSCollector::CMSCollector(ConcurrentMarkSweepGeneration* cmsGen, && _survivor_chunk_index == 0), "Error"); - // Choose what strong roots should be scanned depending on verification options - // and perm gen collection mode. + // Choose what strong roots should be scanned. + // If CMSClassUnloadingEnabled is on, roots are set during + // setup_cms_unloading_and_verification_state() on each CMS cycle. if (!CMSClassUnloadingEnabled) { // If class unloading is disabled we want to include all classes into the root set. add_root_scanning_option(SharedHeap::SO_AllClasses); - } else { - add_root_scanning_option(SharedHeap::SO_SystemClasses); } NOT_PRODUCT(_overflow_counter = CMSMarkStackOverflowInterval;) @@ -4393,6 +4392,19 @@ void CMSCollector::setup_cms_unloading_and_verification_state() { || VerifyBeforeExit; const int rso = SharedHeap::SO_Strings | SharedHeap::SO_CodeCache; + // We set the proper root for this CMS cycle here. + // When class unloading is disabled, we set the default root scanning option + // once in the CMSCollector constructor. + if (CMSClassUnloadingEnabled) { + if (should_unload_classes()) { + remove_root_scanning_option(SharedHeap::SO_AllClasses); + add_root_scanning_option(SharedHeap::SO_SystemClasses); + } else { + remove_root_scanning_option(SharedHeap::SO_SystemClasses); + add_root_scanning_option(SharedHeap::SO_AllClasses); + } + } + if (should_unload_classes()) { // Should unload classes this cycle remove_root_scanning_option(rso); // Shrink the root set appropriately set_verifying(should_verify); // Set verification state for this cycle