2380 Log(gc, verify) log;
2381 log.error("Failed marking verification after remark");
2382 ResourceMark rm;
2383 LogStream ls(log.error());
2384 heap->print_on(&ls);
2385 fatal("CMS: failed marking verification after remark");
2386 }
2387 }
2388
2389 class VerifyCLDOopsCLDClosure : public CLDClosure {
2390 class VerifyCLDOopsClosure : public OopClosure {
2391 CMSBitMap* _bitmap;
2392 public:
2393 VerifyCLDOopsClosure(CMSBitMap* bitmap) : _bitmap(bitmap) { }
2394 void do_oop(oop* p) { guarantee(*p == NULL || _bitmap->isMarked((HeapWord*) *p), "Should be marked"); }
2395 void do_oop(narrowOop* p) { ShouldNotReachHere(); }
2396 } _oop_closure;
2397 public:
2398 VerifyCLDOopsCLDClosure(CMSBitMap* bitmap) : _oop_closure(bitmap) {}
2399 void do_cld(ClassLoaderData* cld) {
2400 cld->oops_do(&_oop_closure, ClassLoaderData::_claim_value_none, false);
2401 }
2402 };
2403
2404 void CMSCollector::verify_after_remark_work_2() {
2405 ResourceMark rm;
2406 HandleMark hm;
2407 CMSHeap* heap = CMSHeap::heap();
2408
2409 // Get a clear set of claim bits for the roots processing to work with.
2410 ClassLoaderDataGraph::clear_claimed_marks();
2411
2412 // Mark from roots one level into CMS
2413 MarkRefsIntoVerifyClosure notOlder(_span, verification_mark_bm(),
2414 markBitMap());
2415 CLDToOopClosure cld_closure(¬Older, ClassLoaderData::_claim_value_strong);
2416
2417 heap->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel.
2418
2419 {
2420 StrongRootsScope srs(1);
2421
2422 heap->cms_process_roots(&srs,
2423 true, // young gen as roots
2424 GenCollectedHeap::ScanningOption(roots_scanning_options()),
2425 should_unload_classes(),
2426 ¬Older,
2427 &cld_closure);
2428 }
2429
2430 // Now mark from the roots
2431 MarkFromRootsVerifyClosure markFromRootsClosure(this, _span,
2432 verification_mark_bm(), markBitMap(), verification_mark_stack());
2433 assert(_restart_addr == NULL, "Expected pre-condition");
2434 verification_mark_bm()->iterate(&markFromRootsClosure);
|
2380 Log(gc, verify) log;
2381 log.error("Failed marking verification after remark");
2382 ResourceMark rm;
2383 LogStream ls(log.error());
2384 heap->print_on(&ls);
2385 fatal("CMS: failed marking verification after remark");
2386 }
2387 }
2388
2389 class VerifyCLDOopsCLDClosure : public CLDClosure {
2390 class VerifyCLDOopsClosure : public OopClosure {
2391 CMSBitMap* _bitmap;
2392 public:
2393 VerifyCLDOopsClosure(CMSBitMap* bitmap) : _bitmap(bitmap) { }
2394 void do_oop(oop* p) { guarantee(*p == NULL || _bitmap->isMarked((HeapWord*) *p), "Should be marked"); }
2395 void do_oop(narrowOop* p) { ShouldNotReachHere(); }
2396 } _oop_closure;
2397 public:
2398 VerifyCLDOopsCLDClosure(CMSBitMap* bitmap) : _oop_closure(bitmap) {}
2399 void do_cld(ClassLoaderData* cld) {
2400 cld->oops_do(&_oop_closure, ClassLoaderData::_claim_none, false);
2401 }
2402 };
2403
2404 void CMSCollector::verify_after_remark_work_2() {
2405 ResourceMark rm;
2406 HandleMark hm;
2407 CMSHeap* heap = CMSHeap::heap();
2408
2409 // Get a clear set of claim bits for the roots processing to work with.
2410 ClassLoaderDataGraph::clear_claimed_marks();
2411
2412 // Mark from roots one level into CMS
2413 MarkRefsIntoVerifyClosure notOlder(_span, verification_mark_bm(),
2414 markBitMap());
2415 CLDToOopClosure cld_closure(¬Older, ClassLoaderData::_claim_strong);
2416
2417 heap->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel.
2418
2419 {
2420 StrongRootsScope srs(1);
2421
2422 heap->cms_process_roots(&srs,
2423 true, // young gen as roots
2424 GenCollectedHeap::ScanningOption(roots_scanning_options()),
2425 should_unload_classes(),
2426 ¬Older,
2427 &cld_closure);
2428 }
2429
2430 // Now mark from the roots
2431 MarkFromRootsVerifyClosure markFromRootsClosure(this, _span,
2432 verification_mark_bm(), markBitMap(), verification_mark_stack());
2433 assert(_restart_addr == NULL, "Expected pre-condition");
2434 verification_mark_bm()->iterate(&markFromRootsClosure);
|
2868 if (CMSParallelInitialMarkEnabled) {
2869 // The parallel version.
2870 WorkGang* workers = heap->workers();
2871 assert(workers != NULL, "Need parallel worker threads.");
2872 uint n_workers = workers->active_workers();
2873
2874 StrongRootsScope srs(n_workers);
2875
2876 CMSParInitialMarkTask tsk(this, &srs, n_workers);
2877 initialize_sequential_subtasks_for_young_gen_rescan(n_workers);
2878 // If the total workers is greater than 1, then multiple workers
2879 // may be used at some time and the initialization has been set
2880 // such that the single threaded path cannot be used.
2881 if (workers->total_workers() > 1) {
2882 workers->run_task(&tsk);
2883 } else {
2884 tsk.work(0);
2885 }
2886 } else {
2887 // The serial version.
2888 CLDToOopClosure cld_closure(¬Older, ClassLoaderData::_claim_value_strong);
2889 heap->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel.
2890
2891 StrongRootsScope srs(1);
2892
2893 heap->cms_process_roots(&srs,
2894 true, // young gen as roots
2895 GenCollectedHeap::ScanningOption(roots_scanning_options()),
2896 should_unload_classes(),
2897 ¬Older,
2898 &cld_closure);
2899 }
2900 }
2901
2902 // Clear mod-union table; it will be dirtied in the prologue of
2903 // CMS generation per each young generation collection.
2904
2905 assert(_modUnionTable.isAllClear(),
2906 "Was cleared in most recent final checkpoint phase"
2907 " or no bits are set in the gc_prologue before the start of the next "
|
2868 if (CMSParallelInitialMarkEnabled) {
2869 // The parallel version.
2870 WorkGang* workers = heap->workers();
2871 assert(workers != NULL, "Need parallel worker threads.");
2872 uint n_workers = workers->active_workers();
2873
2874 StrongRootsScope srs(n_workers);
2875
2876 CMSParInitialMarkTask tsk(this, &srs, n_workers);
2877 initialize_sequential_subtasks_for_young_gen_rescan(n_workers);
2878 // If the total workers is greater than 1, then multiple workers
2879 // may be used at some time and the initialization has been set
2880 // such that the single threaded path cannot be used.
2881 if (workers->total_workers() > 1) {
2882 workers->run_task(&tsk);
2883 } else {
2884 tsk.work(0);
2885 }
2886 } else {
2887 // The serial version.
2888 CLDToOopClosure cld_closure(¬Older, ClassLoaderData::_claim_strong);
2889 heap->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel.
2890
2891 StrongRootsScope srs(1);
2892
2893 heap->cms_process_roots(&srs,
2894 true, // young gen as roots
2895 GenCollectedHeap::ScanningOption(roots_scanning_options()),
2896 should_unload_classes(),
2897 ¬Older,
2898 &cld_closure);
2899 }
2900 }
2901
2902 // Clear mod-union table; it will be dirtied in the prologue of
2903 // CMS generation per each young generation collection.
2904
2905 assert(_modUnionTable.isAllClear(),
2906 "Was cleared in most recent final checkpoint phase"
2907 " or no bits are set in the gc_prologue before the start of the next "
|
4251 elapsedTimer _timer;
4252 ResourceMark rm;
4253 HandleMark hm;
4254
4255 // ---------- scan from roots --------------
4256 _timer.start();
4257 CMSHeap* heap = CMSHeap::heap();
4258 ParMarkRefsIntoClosure par_mri_cl(_collector->_span, &(_collector->_markBitMap));
4259
4260 // ---------- young gen roots --------------
4261 {
4262 work_on_young_gen_roots(&par_mri_cl);
4263 _timer.stop();
4264 log_trace(gc, task)("Finished young gen initial mark scan work in %dth thread: %3.3f sec", worker_id, _timer.seconds());
4265 }
4266
4267 // ---------- remaining roots --------------
4268 _timer.reset();
4269 _timer.start();
4270
4271 CLDToOopClosure cld_closure(&par_mri_cl, ClassLoaderData::_claim_value_strong);
4272
4273 heap->cms_process_roots(_strong_roots_scope,
4274 false, // yg was scanned above
4275 GenCollectedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()),
4276 _collector->should_unload_classes(),
4277 &par_mri_cl,
4278 &cld_closure,
4279 &_par_state_string);
4280
4281 assert(_collector->should_unload_classes()
4282 || (_collector->CMSCollector::roots_scanning_options() & GenCollectedHeap::SO_AllCodeCache),
4283 "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops");
4284 _timer.stop();
4285 log_trace(gc, task)("Finished remaining root initial mark scan work in %dth thread: %3.3f sec", worker_id, _timer.seconds());
4286 }
4287
4288 // Parallel remark task
4289 class CMSParRemarkTask: public CMSParMarkTask {
4290 CompactibleFreeListSpace* _cms_space;
|
4251 elapsedTimer _timer;
4252 ResourceMark rm;
4253 HandleMark hm;
4254
4255 // ---------- scan from roots --------------
4256 _timer.start();
4257 CMSHeap* heap = CMSHeap::heap();
4258 ParMarkRefsIntoClosure par_mri_cl(_collector->_span, &(_collector->_markBitMap));
4259
4260 // ---------- young gen roots --------------
4261 {
4262 work_on_young_gen_roots(&par_mri_cl);
4263 _timer.stop();
4264 log_trace(gc, task)("Finished young gen initial mark scan work in %dth thread: %3.3f sec", worker_id, _timer.seconds());
4265 }
4266
4267 // ---------- remaining roots --------------
4268 _timer.reset();
4269 _timer.start();
4270
4271 CLDToOopClosure cld_closure(&par_mri_cl, ClassLoaderData::_claim_strong);
4272
4273 heap->cms_process_roots(_strong_roots_scope,
4274 false, // yg was scanned above
4275 GenCollectedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()),
4276 _collector->should_unload_classes(),
4277 &par_mri_cl,
4278 &cld_closure,
4279 &_par_state_string);
4280
4281 assert(_collector->should_unload_classes()
4282 || (_collector->CMSCollector::roots_scanning_options() & GenCollectedHeap::SO_AllCodeCache),
4283 "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops");
4284 _timer.stop();
4285 log_trace(gc, task)("Finished remaining root initial mark scan work in %dth thread: %3.3f sec", worker_id, _timer.seconds());
4286 }
4287
4288 // Parallel remark task
4289 class CMSParRemarkTask: public CMSParMarkTask {
4290 CompactibleFreeListSpace* _cms_space;
|
4313
4314 OopTaskQueue* work_queue(int i) { return task_queues()->queue(i); }
4315
4316 ParallelTaskTerminator* terminator() { return &_term; }
4317 uint n_workers() { return _n_workers; }
4318
4319 void work(uint worker_id);
4320
4321 private:
4322 // ... of dirty cards in old space
4323 void do_dirty_card_rescan_tasks(CompactibleFreeListSpace* sp, int i,
4324 ParMarkRefsIntoAndScanClosure* cl);
4325
4326 // ... work stealing for the above
4327 void do_work_steal(int i, ParMarkRefsIntoAndScanClosure* cl);
4328 };
4329
4330 class RemarkCLDClosure : public CLDClosure {
4331 CLDToOopClosure _cm_closure;
4332 public:
4333 RemarkCLDClosure(OopClosure* oop_closure) : _cm_closure(oop_closure, ClassLoaderData::_claim_value_strong) {}
4334 void do_cld(ClassLoaderData* cld) {
4335 // Check if we have modified any oops in the CLD during the concurrent marking.
4336 if (cld->has_accumulated_modified_oops()) {
4337 cld->clear_accumulated_modified_oops();
4338
4339 // We could have transfered the current modified marks to the accumulated marks,
4340 // like we do with the Card Table to Mod Union Table. But it's not really necessary.
4341 } else if (cld->has_modified_oops()) {
4342 // Don't clear anything, this info is needed by the next young collection.
4343 } else {
4344 // No modified oops in the ClassLoaderData.
4345 return;
4346 }
4347
4348 // The klass has modified fields, need to scan the klass.
4349 _cm_closure.do_cld(cld);
4350 }
4351 };
4352
|
4313
4314 OopTaskQueue* work_queue(int i) { return task_queues()->queue(i); }
4315
4316 ParallelTaskTerminator* terminator() { return &_term; }
4317 uint n_workers() { return _n_workers; }
4318
4319 void work(uint worker_id);
4320
4321 private:
4322 // ... of dirty cards in old space
4323 void do_dirty_card_rescan_tasks(CompactibleFreeListSpace* sp, int i,
4324 ParMarkRefsIntoAndScanClosure* cl);
4325
4326 // ... work stealing for the above
4327 void do_work_steal(int i, ParMarkRefsIntoAndScanClosure* cl);
4328 };
4329
4330 class RemarkCLDClosure : public CLDClosure {
4331 CLDToOopClosure _cm_closure;
4332 public:
4333 RemarkCLDClosure(OopClosure* oop_closure) : _cm_closure(oop_closure, ClassLoaderData::_claim_strong) {}
4334 void do_cld(ClassLoaderData* cld) {
4335 // Check if we have modified any oops in the CLD during the concurrent marking.
4336 if (cld->has_accumulated_modified_oops()) {
4337 cld->clear_accumulated_modified_oops();
4338
4339 // We could have transfered the current modified marks to the accumulated marks,
4340 // like we do with the Card Table to Mod Union Table. But it's not really necessary.
4341 } else if (cld->has_modified_oops()) {
4342 // Don't clear anything, this info is needed by the next young collection.
4343 } else {
4344 // No modified oops in the ClassLoaderData.
4345 return;
4346 }
4347
4348 // The klass has modified fields, need to scan the klass.
4349 _cm_closure.do_cld(cld);
4350 }
4351 };
4352
|