--- old/src/share/vm/gc/cms/concurrentMarkSweepGeneration.cpp 2015-05-20 11:05:14.577824092 +0200 +++ new/src/share/vm/gc/cms/concurrentMarkSweepGeneration.cpp 2015-05-20 11:05:14.393817874 +0200 @@ -2427,14 +2427,18 @@ MarkRefsIntoClosure notOlder(_span, verification_mark_bm()); gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel. - gch->gen_process_roots(_cmsGen->level(), - true, // younger gens are roots - true, // activate StrongRootsScope - GenCollectedHeap::ScanningOption(roots_scanning_options()), - should_unload_classes(), - ¬Older, - NULL, - NULL); // SSS: Provide correct closure + { + StrongRootsScope srs(1); + + gch->gen_process_roots(&srs, + _cmsGen->level(), + true, // younger gens are roots + GenCollectedHeap::ScanningOption(roots_scanning_options()), + should_unload_classes(), + ¬Older, + NULL, + NULL); + } // Now mark from the roots MarkFromRootsClosure markFromRootsClosure(this, _span, @@ -2495,14 +2499,18 @@ gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel. - gch->gen_process_roots(_cmsGen->level(), - true, // younger gens are roots - true, // activate StrongRootsScope - GenCollectedHeap::ScanningOption(roots_scanning_options()), - should_unload_classes(), - ¬Older, - NULL, - &cld_closure); + { + StrongRootsScope srs(1); + + gch->gen_process_roots(&srs, + _cmsGen->level(), + true, // younger gens are roots + GenCollectedHeap::ScanningOption(roots_scanning_options()), + should_unload_classes(), + ¬Older, + NULL, + &cld_closure); + } // Now mark from the roots MarkFromRootsVerifyClosure markFromRootsClosure(this, _span, @@ -2912,10 +2920,11 @@ // Parallel initial mark task class CMSParInitialMarkTask: public CMSParMarkTask { + StrongRootsScope* _strong_roots_scope; public: - CMSParInitialMarkTask(CMSCollector* collector, uint n_workers) : - CMSParMarkTask("Scan roots and young gen for initial mark in parallel", - collector, n_workers) {} + CMSParInitialMarkTask(CMSCollector* collector, StrongRootsScope* strong_roots_scope, uint n_workers) : + CMSParMarkTask("Scan roots and young gen for initial mark in parallel", collector, n_workers), + _strong_roots_scope(strong_roots_scope) {} void work(uint worker_id); }; @@ -3003,24 +3012,26 @@ FlexibleWorkGang* workers = gch->workers(); assert(workers != NULL, "Need parallel worker threads."); uint n_workers = workers->active_workers(); - CMSParInitialMarkTask tsk(this, n_workers); - gch->set_par_threads(n_workers); + + StrongRootsScope srs(n_workers); + + CMSParInitialMarkTask tsk(this, &srs, n_workers); initialize_sequential_subtasks_for_young_gen_rescan(n_workers); if (n_workers > 1) { - StrongRootsScope srs; workers->run_task(&tsk); } else { - StrongRootsScope srs; tsk.work(0); } - gch->set_par_threads(0); } else { // The serial version. CLDToOopClosure cld_closure(¬Older, true); gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel. - gch->gen_process_roots(_cmsGen->level(), + + StrongRootsScope srs(1); + + gch->gen_process_roots(&srs, + _cmsGen->level(), true, // younger gens are roots - true, // activate StrongRootsScope GenCollectedHeap::ScanningOption(roots_scanning_options()), should_unload_classes(), ¬Older, @@ -4451,9 +4462,9 @@ CLDToOopClosure cld_closure(&par_mri_cl, true); - gch->gen_process_roots(_collector->_cmsGen->level(), + gch->gen_process_roots(_strong_roots_scope, + _collector->_cmsGen->level(), false, // yg was scanned above - false, // this is parallel code GenCollectedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()), _collector->should_unload_classes(), &par_mri_cl, @@ -4477,6 +4488,7 @@ // The per-thread work queues, available here for stealing. OopTaskQueueSet* _task_queues; ParallelTaskTerminator _term; + StrongRootsScope* _strong_roots_scope; public: // A value of 0 passed to n_workers will cause the number of @@ -4484,12 +4496,14 @@ CMSParRemarkTask(CMSCollector* collector, CompactibleFreeListSpace* cms_space, uint n_workers, FlexibleWorkGang* workers, - OopTaskQueueSet* task_queues): + OopTaskQueueSet* task_queues, + StrongRootsScope* strong_roots_scope): CMSParMarkTask("Rescan roots and grey objects in parallel", collector, n_workers), _cms_space(cms_space), _task_queues(task_queues), - _term(n_workers, task_queues) { } + _term(n_workers, task_queues), + _strong_roots_scope(strong_roots_scope) { } OopTaskQueueSet* task_queues() { return _task_queues; } @@ -4587,9 +4601,9 @@ // ---------- remaining roots -------------- _timer.reset(); _timer.start(); - gch->gen_process_roots(_collector->_cmsGen->level(), + gch->gen_process_roots(_strong_roots_scope, + _collector->_cmsGen->level(), false, // yg was scanned above - false, // this is parallel code GenCollectedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()), _collector->should_unload_classes(), &par_mrias_cl, @@ -5067,12 +5081,10 @@ } CompactibleFreeListSpace* cms_space = _cmsGen->cmsSpace(); - CMSParRemarkTask tsk(this, - cms_space, - n_workers, workers, task_queues()); + StrongRootsScope srs(n_workers); + + CMSParRemarkTask tsk(this, cms_space, n_workers, workers, task_queues(), &srs); - // Set up for parallel process_roots work. - gch->set_par_threads(n_workers); // We won't be iterating over the cards in the card table updating // the younger_gen cards, so we shouldn't call the following else // the verification code as well as subsequent younger_refs_iterate @@ -5104,15 +5116,12 @@ // necessarily be so, since it's possible that we are doing // ST marking. ReferenceProcessorMTDiscoveryMutator mt(ref_processor(), true); - StrongRootsScope srs; workers->run_task(&tsk); } else { ReferenceProcessorMTDiscoveryMutator mt(ref_processor(), false); - StrongRootsScope srs; tsk.work(0); } - gch->set_par_threads(0); // 0 ==> non-parallel. // restore, single-threaded for now, any preserved marks // as a result of work_q overflow restore_preserved_marks_if_any(); @@ -5176,11 +5185,11 @@ verify_work_stacks_empty(); gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel. - StrongRootsScope srs; + StrongRootsScope srs(1); - gch->gen_process_roots(_cmsGen->level(), + gch->gen_process_roots(&srs, + _cmsGen->level(), true, // younger gens as roots - false, // use the local StrongRootsScope GenCollectedHeap::ScanningOption(roots_scanning_options()), should_unload_classes(), &mrias_cl,