--- old/src/share/vm/gc/cms/concurrentMarkSweepGeneration.cpp 2015-10-16 17:28:08.000000000 +0200 +++ new/src/share/vm/gc/cms/concurrentMarkSweepGeneration.cpp 2015-10-16 17:28:08.000000000 +0200 @@ -2414,13 +2414,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); } @@ -2486,13 +2484,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); } @@ -2539,9 +2535,8 @@ \ void ConcurrentMarkSweepGeneration:: \ oop_since_save_marks_iterate##nv_suffix(OopClosureType* cl) { \ - cl->set_generation(this); \ + cl->assert_generation(this); \ cmsSpace()->oop_since_save_marks_iterate##nv_suffix(cl); \ - cl->reset_generation(); \ save_marks(); \ } @@ -3007,13 +3002,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); } } @@ -4436,13 +4429,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), @@ -4575,13 +4566,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() @@ -5156,13 +5145,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 2015-10-16 17:28:09.000000000 +0200 +++ new/src/share/vm/gc/cms/parNewGeneration.cpp 2015-10-16 17:28:09.000000000 +0200 @@ -582,14 +582,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 2015-10-16 17:28:09.000000000 +0200 +++ new/src/share/vm/gc/serial/defNewGeneration.cpp 2015-10-16 17:28:09.000000000 +0200 @@ -627,15 +627,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". @@ -851,11 +846,10 @@ \ void DefNewGeneration:: \ oop_since_save_marks_iterate##nv_suffix(OopClosureType* cl) { \ - cl->set_generation(this); \ + cl->assert_generation(this); \ eden()->oop_since_save_marks_iterate##nv_suffix(cl); \ to()->oop_since_save_marks_iterate##nv_suffix(cl); \ from()->oop_since_save_marks_iterate##nv_suffix(cl); \ - cl->reset_generation(); \ save_marks(); \ } --- old/src/share/vm/gc/serial/genMarkSweep.cpp 2015-10-16 17:28:10.000000000 +0200 +++ new/src/share/vm/gc/serial/genMarkSweep.cpp 2015-10-16 17:28:10.000000000 +0200 @@ -194,7 +194,7 @@ // use OopsInGenClosure constructor which takes a generation, // as the Universe has not been created when the static constructors // are run. - follow_root_closure.set_orig_generation(gch->old_gen()); + follow_root_closure.set_generation(gch->old_gen()); // Need new claim bits before marking starts. ClassLoaderDataGraph::clear_claimed_marks(); @@ -202,13 +202,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); } @@ -284,17 +282,15 @@ // use OopsInGenClosure constructor which takes a generation, // as the Universe has not been created when the static constructors // are run. - adjust_pointer_closure.set_orig_generation(gch->old_gen()); + adjust_pointer_closure.set_generation(gch->old_gen()); { 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, // Strong and weak roots. &adjust_pointer_closure, &adjust_cld_closure); } --- old/src/share/vm/gc/serial/tenuredGeneration.cpp 2015-10-16 17:28:10.000000000 +0200 +++ new/src/share/vm/gc/serial/tenuredGeneration.cpp 2015-10-16 17:28:10.000000000 +0200 @@ -270,9 +270,8 @@ \ void TenuredGeneration:: \ oop_since_save_marks_iterate##nv_suffix(OopClosureType* blk) { \ - blk->set_generation(this); \ + blk->assert_generation(this); \ _the_space->oop_since_save_marks_iterate##nv_suffix(blk); \ - blk->reset_generation(); \ save_marks(); \ } --- old/src/share/vm/gc/shared/cardGeneration.cpp 2015-10-16 17:28:11.000000000 +0200 +++ new/src/share/vm/gc/shared/cardGeneration.cpp 2015-10-16 17:28:10.000000000 +0200 @@ -352,7 +352,6 @@ } void CardGeneration::younger_refs_iterate(OopsInGenClosure* blk, uint n_threads) { - blk->set_generation(this); + blk->assert_generation(this); younger_refs_in_space_iterate(space(), blk, n_threads); - blk->reset_generation(); } --- old/src/share/vm/gc/shared/genCollectedHeap.cpp 2015-10-16 17:28:11.000000000 +0200 +++ new/src/share/vm/gc/shared/genCollectedHeap.cpp 2015-10-16 17:28:11.000000000 +0200 @@ -663,52 +663,49 @@ } } -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)) { + } + + // When collection is parallel, all threads get to cooperate to do + // old generation scanning. + old_gen_closure->assert_generation(_old_gen); + rem_set()->younger_refs_iterate(_old_gen, old_gen_closure, scope->n_threads()); + + _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->assert_generation(_young_gen); + _young_gen->oop_iterate(root_closure); } _process_strong_tasks->all_tasks_completed(scope->n_threads()); } - class AlwaysTrueClosure: public BoolObjectClosure { public: bool do_object_b(oop p) { return true; } --- old/src/share/vm/gc/shared/genCollectedHeap.hpp 2015-10-16 17:28:11.000000000 +0200 +++ new/src/share/vm/gc/shared/genCollectedHeap.hpp 2015-10-16 17:28:11.000000000 +0200 @@ -380,9 +380,9 @@ // the closure is applied to: // "SO_None" does none; enum ScanningOption { - SO_None = 0x0, - SO_AllCodeCache = 0x8, - SO_ScavengeCodeCache = 0x10 + SO_None = 0x00, + SO_AllCodeCache = 0x08, + SO_ScavengeCodeCache = 0x10 }; private: @@ -395,16 +395,16 @@ CodeBlobClosure* code_roots); public: - static const bool StrongAndWeakRoots = false; - static const bool StrongRootsOnly = true; + void young_process_roots(StrongRootsScope* scope, + OopsInGenClosure* not_older_gens, + OopsInGenClosure* older_gens, + 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, CLDClosure* cld_closure); // Apply "root_closure" to all the weak roots of the system. --- old/src/share/vm/gc/shared/genOopClosures.hpp 2015-10-16 17:28:12.000000000 +0200 +++ new/src/share/vm/gc/shared/genOopClosures.hpp 2015-10-16 17:28:12.000000000 +0200 @@ -42,7 +42,6 @@ class OopsInGenClosure : public ExtendedOopClosure { private: - Generation* _orig_gen; // generation originally set in ctor Generation* _gen; // generation being scanned protected: @@ -63,22 +62,16 @@ public: OopsInGenClosure() : ExtendedOopClosure(NULL), - _orig_gen(NULL), _gen(NULL), _gen_boundary(NULL), _rs(NULL) {}; + _gen(NULL), _gen_boundary(NULL), _rs(NULL) {}; OopsInGenClosure(Generation* gen); - void set_generation(Generation* gen); - - void reset_generation() { _gen = _orig_gen; } // Problem with static closures: must have _gen_boundary set at some point, // but cannot do this until after the heap is initialized. - void set_orig_generation(Generation* gen) { - _orig_gen = gen; - set_generation(gen); - } + void set_generation(Generation* gen); + void assert_generation(Generation* gen); HeapWord* gen_boundary() { return _gen_boundary; } - }; // Super class for scan closures. It contains code to dirty scanned Klasses. --- old/src/share/vm/gc/shared/genOopClosures.inline.hpp 2015-10-16 17:28:12.000000000 +0200 +++ new/src/share/vm/gc/shared/genOopClosures.inline.hpp 2015-10-16 17:28:12.000000000 +0200 @@ -34,11 +34,12 @@ #include "gc/shared/space.hpp" inline OopsInGenClosure::OopsInGenClosure(Generation* gen) : - ExtendedOopClosure(gen->ref_processor()), _orig_gen(gen), _rs(NULL) { + ExtendedOopClosure(gen->ref_processor()), _gen(NULL), _rs(NULL) { set_generation(gen); } inline void OopsInGenClosure::set_generation(Generation* gen) { + assert(_gen == NULL, "Generation already initialized"); _gen = gen; _gen_boundary = _gen->reserved().start(); // Barrier set for the heap, must be set after heap is initialized @@ -48,6 +49,10 @@ } } +inline void OopsInGenClosure::assert_generation(Generation* gen) { + assert(_gen == gen, "Generations mismatch. Fix it now!!"); +} + template inline void OopsInGenClosure::do_barrier(T* p) { assert(generation()->is_in_reserved(p), "expected ref in generation"); T heap_oop = oopDesc::load_heap_oop(p);