--- old/src/share/vm/gc/cms/concurrentMarkSweepGeneration.cpp 2016-09-20 11:01:58.521687061 +0200 +++ new/src/share/vm/gc/cms/concurrentMarkSweepGeneration.cpp 2016-09-20 11:01:58.381681595 +0200 @@ -2340,13 +2340,11 @@ { StrongRootsScope srs(1); - gch->gen_process_roots(&srs, - GenCollectedHeap::OldGen, + gch->old_process_roots(&srs, true, // young gen as roots GenCollectedHeap::ScanningOption(roots_scanning_options()), should_unload_classes(), ¬Older, - NULL, NULL); } @@ -2414,13 +2412,11 @@ { StrongRootsScope srs(1); - gch->gen_process_roots(&srs, - GenCollectedHeap::OldGen, + gch->old_process_roots(&srs, true, // young gen as roots GenCollectedHeap::ScanningOption(roots_scanning_options()), should_unload_classes(), ¬Older, - NULL, &cld_closure); } @@ -2903,13 +2899,11 @@ StrongRootsScope srs(1); - gch->gen_process_roots(&srs, - GenCollectedHeap::OldGen, + gch->old_process_roots(&srs, true, // young gen as roots GenCollectedHeap::ScanningOption(roots_scanning_options()), should_unload_classes(), ¬Older, - NULL, &cld_closure); } } @@ -4290,13 +4284,11 @@ CLDToOopClosure cld_closure(&par_mri_cl, true); - gch->gen_process_roots(_strong_roots_scope, - GenCollectedHeap::OldGen, + gch->old_process_roots(_strong_roots_scope, false, // yg was scanned above GenCollectedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()), _collector->should_unload_classes(), &par_mri_cl, - NULL, &cld_closure); assert(_collector->should_unload_classes() || (_collector->CMSCollector::roots_scanning_options() & GenCollectedHeap::SO_AllCodeCache), @@ -4421,13 +4413,11 @@ // ---------- remaining roots -------------- _timer.reset(); _timer.start(); - gch->gen_process_roots(_strong_roots_scope, - GenCollectedHeap::OldGen, + gch->old_process_roots(_strong_roots_scope, false, // yg was scanned above GenCollectedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()), _collector->should_unload_classes(), &par_mrias_cl, - NULL, NULL); // The dirty klasses will be handled below assert(_collector->should_unload_classes() @@ -4970,13 +4960,11 @@ gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel. StrongRootsScope srs(1); - gch->gen_process_roots(&srs, - GenCollectedHeap::OldGen, + gch->old_process_roots(&srs, true, // young gen as roots GenCollectedHeap::ScanningOption(roots_scanning_options()), should_unload_classes(), &mrias_cl, - NULL, NULL); // The dirty klasses will be handled below assert(should_unload_classes() --- old/src/share/vm/gc/cms/parNewGeneration.cpp 2016-09-20 11:01:59.317718140 +0200 +++ new/src/share/vm/gc/cms/parNewGeneration.cpp 2016-09-20 11:01:59.181712830 +0200 @@ -605,14 +605,10 @@ false); par_scan_state.start_strong_roots(); - gch->gen_process_roots(_strong_roots_scope, - GenCollectedHeap::YoungGen, - true, // Process younger gens, if any, as strong roots. - GenCollectedHeap::SO_ScavengeCodeCache, - GenCollectedHeap::StrongAndWeakRoots, - &par_scan_state.to_space_root_closure(), - &par_scan_state.older_gen_closure(), - &cld_scan_closure); + gch->young_process_roots(_strong_roots_scope, + &par_scan_state.to_space_root_closure(), + &par_scan_state.older_gen_closure(), + &cld_scan_closure); par_scan_state.end_strong_roots(); --- old/src/share/vm/gc/serial/defNewGeneration.cpp 2016-09-20 11:02:00.033746096 +0200 +++ new/src/share/vm/gc/serial/defNewGeneration.cpp 2016-09-20 11:01:59.881740162 +0200 @@ -648,15 +648,10 @@ // See: CardTableModRefBSForCTRS::non_clean_card_iterate_possibly_parallel. StrongRootsScope srs(0); - gch->gen_process_roots(&srs, - GenCollectedHeap::YoungGen, - true, // Process younger gens, if any, - // as strong roots. - GenCollectedHeap::SO_ScavengeCodeCache, - GenCollectedHeap::StrongAndWeakRoots, - &fsc_with_no_gc_barrier, - &fsc_with_gc_barrier, - &cld_scan_closure); + gch->young_process_roots(&srs, + &fsc_with_no_gc_barrier, + &fsc_with_gc_barrier, + &cld_scan_closure); } // "evacuate followers". --- old/src/share/vm/gc/serial/genMarkSweep.cpp 2016-09-20 11:02:00.741773740 +0200 +++ new/src/share/vm/gc/serial/genMarkSweep.cpp 2016-09-20 11:02:00.609768586 +0200 @@ -196,13 +196,11 @@ { StrongRootsScope srs(1); - gch->gen_process_roots(&srs, - GenCollectedHeap::OldGen, + gch->old_process_roots(&srs, false, // Younger gens are not roots. GenCollectedHeap::SO_None, ClassUnloading, &follow_root_closure, - &follow_root_closure, &follow_cld_closure); } @@ -295,12 +293,10 @@ { StrongRootsScope srs(1); - gch->gen_process_roots(&srs, - GenCollectedHeap::OldGen, + gch->old_process_roots(&srs, false, // Younger gens are not roots. GenCollectedHeap::SO_AllCodeCache, - GenCollectedHeap::StrongAndWeakRoots, - &adjust_pointer_closure, + false, &adjust_pointer_closure, &adjust_cld_closure); } --- old/src/share/vm/gc/shared/genCollectedHeap.cpp 2016-09-20 11:02:01.493803102 +0200 +++ new/src/share/vm/gc/shared/genCollectedHeap.cpp 2016-09-20 11:02:01.349797479 +0200 @@ -644,46 +644,47 @@ } } -void GenCollectedHeap::gen_process_roots(StrongRootsScope* scope, - GenerationType type, +void GenCollectedHeap::young_process_roots(StrongRootsScope* scope, + OopsInGenClosure* root_closure, + OopsInGenClosure* old_gen_closure, + CLDClosure* cld_closure) { + MarkingCodeBlobClosure mark_code_closure(root_closure, CodeBlobToOopClosure::FixRelocations); + + process_roots(scope, SO_ScavengeCodeCache, root_closure, root_closure, + cld_closure, cld_closure, &mark_code_closure); + + if (!_process_strong_tasks->is_task_claimed(GCH_PS_younger_gens)) { + root_closure->reset_generation(); + } + + // When collection is parallel, all threads get to cooperate to do + // old generation scanning. + old_gen_closure->set_generation(_old_gen); + rem_set()->younger_refs_iterate(_old_gen, old_gen_closure, scope->n_threads()); + old_gen_closure->reset_generation(); + + _process_strong_tasks->all_tasks_completed(scope->n_threads()); +} + +void GenCollectedHeap::old_process_roots(StrongRootsScope* scope, bool young_gen_as_roots, ScanningOption so, bool only_strong_roots, - OopsInGenClosure* not_older_gens, - OopsInGenClosure* older_gens, + OopsInGenClosure* root_closure, CLDClosure* cld_closure) { - const bool is_adjust_phase = !only_strong_roots && !young_gen_as_roots; - - bool is_moving_collection = false; - if (type == YoungGen || is_adjust_phase) { - // young collections are always moving - is_moving_collection = true; - } + const bool is_moving_collection = !only_strong_roots && !young_gen_as_roots; - MarkingCodeBlobClosure mark_code_closure(not_older_gens, is_moving_collection); - OopsInGenClosure* weak_roots = only_strong_roots ? NULL : not_older_gens; + MarkingCodeBlobClosure mark_code_closure(root_closure, is_moving_collection); + OopsInGenClosure* weak_roots = only_strong_roots ? NULL : root_closure; CLDClosure* weak_cld_closure = only_strong_roots ? NULL : cld_closure; - process_roots(scope, so, - not_older_gens, weak_roots, - cld_closure, weak_cld_closure, - &mark_code_closure); - - if (young_gen_as_roots) { - if (!_process_strong_tasks->is_task_claimed(GCH_PS_younger_gens)) { - if (type == OldGen) { - not_older_gens->set_generation(_young_gen); - _young_gen->oop_iterate(not_older_gens); - } - not_older_gens->reset_generation(); - } - } - // When collection is parallel, all threads get to cooperate to do - // old generation scanning. - if (type == YoungGen) { - older_gens->set_generation(_old_gen); - rem_set()->younger_refs_iterate(_old_gen, older_gens, scope->n_threads()); - older_gens->reset_generation(); + process_roots(scope, so, root_closure, weak_roots, cld_closure, weak_cld_closure, &mark_code_closure); + + if (young_gen_as_roots && + !_process_strong_tasks->is_task_claimed(GCH_PS_younger_gens)) { + root_closure->set_generation(_young_gen); + _young_gen->oop_iterate(root_closure); + root_closure->reset_generation(); } _process_strong_tasks->all_tasks_completed(scope->n_threads()); --- old/src/share/vm/gc/shared/genCollectedHeap.hpp 2016-09-20 11:02:02.297834494 +0200 +++ new/src/share/vm/gc/shared/genCollectedHeap.hpp 2016-09-20 11:02:02.165829340 +0200 @@ -402,16 +402,16 @@ CodeBlobToOopClosure* code_roots); public: - static const bool StrongAndWeakRoots = false; - static const bool StrongRootsOnly = true; + void young_process_roots(StrongRootsScope* scope, + OopsInGenClosure* root_closure, + OopsInGenClosure* old_gen_closure, + CLDClosure* cld_closure); - void gen_process_roots(StrongRootsScope* scope, - GenerationType type, + void old_process_roots(StrongRootsScope* scope, bool young_gen_as_roots, ScanningOption so, bool only_strong_roots, - OopsInGenClosure* not_older_gens, - OopsInGenClosure* older_gens, + OopsInGenClosure* root_closure, CLDClosure* cld_closure); // Apply "root_closure" to all the weak roots of the system.