2323 }
2324
2325 return true;
2326 }
2327
2328 void CMSCollector::verify_after_remark_work_1() {
2329 ResourceMark rm;
2330 HandleMark hm;
2331 GenCollectedHeap* gch = GenCollectedHeap::heap();
2332
2333 // Get a clear set of claim bits for the roots processing to work with.
2334 ClassLoaderDataGraph::clear_claimed_marks();
2335
2336 // Mark from roots one level into CMS
2337 MarkRefsIntoClosure notOlder(_span, verification_mark_bm());
2338 gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel.
2339
2340 {
2341 StrongRootsScope srs(1);
2342
2343 gch->gen_process_roots(&srs,
2344 GenCollectedHeap::OldGen,
2345 true, // young gen as roots
2346 GenCollectedHeap::ScanningOption(roots_scanning_options()),
2347 should_unload_classes(),
2348 ¬Older,
2349 NULL,
2350 NULL);
2351 }
2352
2353 // Now mark from the roots
2354 MarkFromRootsClosure markFromRootsClosure(this, _span,
2355 verification_mark_bm(), verification_mark_stack(),
2356 false /* don't yield */, true /* verifying */);
2357 assert(_restart_addr == NULL, "Expected pre-condition");
2358 verification_mark_bm()->iterate(&markFromRootsClosure);
2359 while (_restart_addr != NULL) {
2360 // Deal with stack overflow: by restarting at the indicated
2361 // address.
2362 HeapWord* ra = _restart_addr;
2363 markFromRootsClosure.reset(ra);
2364 _restart_addr = NULL;
2365 verification_mark_bm()->iterate(&markFromRootsClosure, ra, _span.end());
2366 }
2367 assert(verification_mark_stack()->isEmpty(), "Should have been drained");
2368 verify_work_stacks_empty();
2369
2397 };
2398
2399 void CMSCollector::verify_after_remark_work_2() {
2400 ResourceMark rm;
2401 HandleMark hm;
2402 GenCollectedHeap* gch = GenCollectedHeap::heap();
2403
2404 // Get a clear set of claim bits for the roots processing to work with.
2405 ClassLoaderDataGraph::clear_claimed_marks();
2406
2407 // Mark from roots one level into CMS
2408 MarkRefsIntoVerifyClosure notOlder(_span, verification_mark_bm(),
2409 markBitMap());
2410 CLDToOopClosure cld_closure(¬Older, true);
2411
2412 gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel.
2413
2414 {
2415 StrongRootsScope srs(1);
2416
2417 gch->gen_process_roots(&srs,
2418 GenCollectedHeap::OldGen,
2419 true, // young gen as roots
2420 GenCollectedHeap::ScanningOption(roots_scanning_options()),
2421 should_unload_classes(),
2422 ¬Older,
2423 NULL,
2424 &cld_closure);
2425 }
2426
2427 // Now mark from the roots
2428 MarkFromRootsVerifyClosure markFromRootsClosure(this, _span,
2429 verification_mark_bm(), markBitMap(), verification_mark_stack());
2430 assert(_restart_addr == NULL, "Expected pre-condition");
2431 verification_mark_bm()->iterate(&markFromRootsClosure);
2432 while (_restart_addr != NULL) {
2433 // Deal with stack overflow: by restarting at the indicated
2434 // address.
2435 HeapWord* ra = _restart_addr;
2436 markFromRootsClosure.reset(ra);
2437 _restart_addr = NULL;
2438 verification_mark_bm()->iterate(&markFromRootsClosure, ra, _span.end());
2439 }
2440 assert(verification_mark_stack()->isEmpty(), "Should have been drained");
2441 verify_work_stacks_empty();
2442
2443 VerifyKlassOopsKlassClosure verify_klass_oops(verification_mark_bm());
2886
2887 StrongRootsScope srs(n_workers);
2888
2889 CMSParInitialMarkTask tsk(this, &srs, n_workers);
2890 initialize_sequential_subtasks_for_young_gen_rescan(n_workers);
2891 // If the total workers is greater than 1, then multiple workers
2892 // may be used at some time and the initialization has been set
2893 // such that the single threaded path cannot be used.
2894 if (workers->total_workers() > 1) {
2895 workers->run_task(&tsk);
2896 } else {
2897 tsk.work(0);
2898 }
2899 } else {
2900 // The serial version.
2901 CLDToOopClosure cld_closure(¬Older, true);
2902 gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel.
2903
2904 StrongRootsScope srs(1);
2905
2906 gch->gen_process_roots(&srs,
2907 GenCollectedHeap::OldGen,
2908 true, // young gen as roots
2909 GenCollectedHeap::ScanningOption(roots_scanning_options()),
2910 should_unload_classes(),
2911 ¬Older,
2912 NULL,
2913 &cld_closure);
2914 }
2915 }
2916
2917 // Clear mod-union table; it will be dirtied in the prologue of
2918 // CMS generation per each young generation collection.
2919
2920 assert(_modUnionTable.isAllClear(),
2921 "Was cleared in most recent final checkpoint phase"
2922 " or no bits are set in the gc_prologue before the start of the next "
2923 "subsequent marking phase.");
2924
2925 assert(_ct->klass_rem_set()->mod_union_is_clear(), "Must be");
2926
2927 // Save the end of the used_region of the constituent generations
2928 // to be used to limit the extent of sweep in each generation.
2929 save_sweep_limits();
2930 verify_overflow_empty();
2931 }
2932
4273 HandleMark hm;
4274
4275 // ---------- scan from roots --------------
4276 _timer.start();
4277 GenCollectedHeap* gch = GenCollectedHeap::heap();
4278 ParMarkRefsIntoClosure par_mri_cl(_collector->_span, &(_collector->_markBitMap));
4279
4280 // ---------- young gen roots --------------
4281 {
4282 work_on_young_gen_roots(&par_mri_cl);
4283 _timer.stop();
4284 log_trace(gc, task)("Finished young gen initial mark scan work in %dth thread: %3.3f sec", worker_id, _timer.seconds());
4285 }
4286
4287 // ---------- remaining roots --------------
4288 _timer.reset();
4289 _timer.start();
4290
4291 CLDToOopClosure cld_closure(&par_mri_cl, true);
4292
4293 gch->gen_process_roots(_strong_roots_scope,
4294 GenCollectedHeap::OldGen,
4295 false, // yg was scanned above
4296 GenCollectedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()),
4297 _collector->should_unload_classes(),
4298 &par_mri_cl,
4299 NULL,
4300 &cld_closure);
4301 assert(_collector->should_unload_classes()
4302 || (_collector->CMSCollector::roots_scanning_options() & GenCollectedHeap::SO_AllCodeCache),
4303 "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops");
4304 _timer.stop();
4305 log_trace(gc, task)("Finished remaining root initial mark scan work in %dth thread: %3.3f sec", worker_id, _timer.seconds());
4306 }
4307
4308 // Parallel remark task
4309 class CMSParRemarkTask: public CMSParMarkTask {
4310 CompactibleFreeListSpace* _cms_space;
4311
4312 // The per-thread work queues, available here for stealing.
4313 OopTaskQueueSet* _task_queues;
4314 ParallelTaskTerminator _term;
4315 StrongRootsScope* _strong_roots_scope;
4316
4317 public:
4318 // A value of 0 passed to n_workers will cause the number of
4319 // workers to be taken from the active workers in the work gang.
4404 GenCollectedHeap* gch = GenCollectedHeap::heap();
4405 ParMarkRefsIntoAndScanClosure par_mrias_cl(_collector,
4406 _collector->_span, _collector->ref_processor(),
4407 &(_collector->_markBitMap),
4408 work_queue(worker_id));
4409
4410 // Rescan young gen roots first since these are likely
4411 // coarsely partitioned and may, on that account, constitute
4412 // the critical path; thus, it's best to start off that
4413 // work first.
4414 // ---------- young gen roots --------------
4415 {
4416 work_on_young_gen_roots(&par_mrias_cl);
4417 _timer.stop();
4418 log_trace(gc, task)("Finished young gen rescan work in %dth thread: %3.3f sec", worker_id, _timer.seconds());
4419 }
4420
4421 // ---------- remaining roots --------------
4422 _timer.reset();
4423 _timer.start();
4424 gch->gen_process_roots(_strong_roots_scope,
4425 GenCollectedHeap::OldGen,
4426 false, // yg was scanned above
4427 GenCollectedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()),
4428 _collector->should_unload_classes(),
4429 &par_mrias_cl,
4430 NULL,
4431 NULL); // The dirty klasses will be handled below
4432
4433 assert(_collector->should_unload_classes()
4434 || (_collector->CMSCollector::roots_scanning_options() & GenCollectedHeap::SO_AllCodeCache),
4435 "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops");
4436 _timer.stop();
4437 log_trace(gc, task)("Finished remaining root rescan work in %dth thread: %3.3f sec", worker_id, _timer.seconds());
4438
4439 // ---------- unhandled CLD scanning ----------
4440 if (worker_id == 0) { // Single threaded at the moment.
4441 _timer.reset();
4442 _timer.start();
4443
4444 // Scan all new class loader data objects and new dependencies that were
4445 // introduced during concurrent marking.
4446 ResourceMark rm;
4447 GrowableArray<ClassLoaderData*>* array = ClassLoaderDataGraph::new_clds();
4448 for (int i = 0; i < array->length(); i++) {
4449 par_mrias_cl.do_cld_nv(array->at(i));
4450 }
4953 MemRegion cms_span(lb, ub);
4954 _modUnionTable.dirty_range_iterate_clear(cms_span,
4955 &markFromDirtyCardsClosure);
4956 verify_work_stacks_empty();
4957 log_trace(gc)(" (re-scanned " SIZE_FORMAT " dirty cards in cms gen) ", markFromDirtyCardsClosure.num_dirty_cards());
4958 }
4959 }
4960 if (VerifyDuringGC &&
4961 GenCollectedHeap::heap()->total_collections() >= VerifyGCStartAt) {
4962 HandleMark hm; // Discard invalid handles created during verification
4963 Universe::verify();
4964 }
4965 {
4966 GCTraceTime(Trace, gc, phases) t("Root Rescan", _gc_timer_cm);
4967
4968 verify_work_stacks_empty();
4969
4970 gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel.
4971 StrongRootsScope srs(1);
4972
4973 gch->gen_process_roots(&srs,
4974 GenCollectedHeap::OldGen,
4975 true, // young gen as roots
4976 GenCollectedHeap::ScanningOption(roots_scanning_options()),
4977 should_unload_classes(),
4978 &mrias_cl,
4979 NULL,
4980 NULL); // The dirty klasses will be handled below
4981
4982 assert(should_unload_classes()
4983 || (roots_scanning_options() & GenCollectedHeap::SO_AllCodeCache),
4984 "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops");
4985 }
4986
4987 {
4988 GCTraceTime(Trace, gc, phases) t("Visit Unhandled CLDs", _gc_timer_cm);
4989
4990 verify_work_stacks_empty();
4991
4992 // Scan all class loader data objects that might have been introduced
4993 // during concurrent marking.
4994 ResourceMark rm;
4995 GrowableArray<ClassLoaderData*>* array = ClassLoaderDataGraph::new_clds();
4996 for (int i = 0; i < array->length(); i++) {
4997 mrias_cl.do_cld_nv(array->at(i));
4998 }
4999
|
2323 }
2324
2325 return true;
2326 }
2327
2328 void CMSCollector::verify_after_remark_work_1() {
2329 ResourceMark rm;
2330 HandleMark hm;
2331 GenCollectedHeap* gch = GenCollectedHeap::heap();
2332
2333 // Get a clear set of claim bits for the roots processing to work with.
2334 ClassLoaderDataGraph::clear_claimed_marks();
2335
2336 // Mark from roots one level into CMS
2337 MarkRefsIntoClosure notOlder(_span, verification_mark_bm());
2338 gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel.
2339
2340 {
2341 StrongRootsScope srs(1);
2342
2343 gch->old_process_roots(&srs,
2344 true, // young gen as roots
2345 GenCollectedHeap::ScanningOption(roots_scanning_options()),
2346 should_unload_classes(),
2347 ¬Older,
2348 NULL);
2349 }
2350
2351 // Now mark from the roots
2352 MarkFromRootsClosure markFromRootsClosure(this, _span,
2353 verification_mark_bm(), verification_mark_stack(),
2354 false /* don't yield */, true /* verifying */);
2355 assert(_restart_addr == NULL, "Expected pre-condition");
2356 verification_mark_bm()->iterate(&markFromRootsClosure);
2357 while (_restart_addr != NULL) {
2358 // Deal with stack overflow: by restarting at the indicated
2359 // address.
2360 HeapWord* ra = _restart_addr;
2361 markFromRootsClosure.reset(ra);
2362 _restart_addr = NULL;
2363 verification_mark_bm()->iterate(&markFromRootsClosure, ra, _span.end());
2364 }
2365 assert(verification_mark_stack()->isEmpty(), "Should have been drained");
2366 verify_work_stacks_empty();
2367
2395 };
2396
2397 void CMSCollector::verify_after_remark_work_2() {
2398 ResourceMark rm;
2399 HandleMark hm;
2400 GenCollectedHeap* gch = GenCollectedHeap::heap();
2401
2402 // Get a clear set of claim bits for the roots processing to work with.
2403 ClassLoaderDataGraph::clear_claimed_marks();
2404
2405 // Mark from roots one level into CMS
2406 MarkRefsIntoVerifyClosure notOlder(_span, verification_mark_bm(),
2407 markBitMap());
2408 CLDToOopClosure cld_closure(¬Older, true);
2409
2410 gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel.
2411
2412 {
2413 StrongRootsScope srs(1);
2414
2415 gch->old_process_roots(&srs,
2416 true, // young gen as roots
2417 GenCollectedHeap::ScanningOption(roots_scanning_options()),
2418 should_unload_classes(),
2419 ¬Older,
2420 &cld_closure);
2421 }
2422
2423 // Now mark from the roots
2424 MarkFromRootsVerifyClosure markFromRootsClosure(this, _span,
2425 verification_mark_bm(), markBitMap(), verification_mark_stack());
2426 assert(_restart_addr == NULL, "Expected pre-condition");
2427 verification_mark_bm()->iterate(&markFromRootsClosure);
2428 while (_restart_addr != NULL) {
2429 // Deal with stack overflow: by restarting at the indicated
2430 // address.
2431 HeapWord* ra = _restart_addr;
2432 markFromRootsClosure.reset(ra);
2433 _restart_addr = NULL;
2434 verification_mark_bm()->iterate(&markFromRootsClosure, ra, _span.end());
2435 }
2436 assert(verification_mark_stack()->isEmpty(), "Should have been drained");
2437 verify_work_stacks_empty();
2438
2439 VerifyKlassOopsKlassClosure verify_klass_oops(verification_mark_bm());
2882
2883 StrongRootsScope srs(n_workers);
2884
2885 CMSParInitialMarkTask tsk(this, &srs, n_workers);
2886 initialize_sequential_subtasks_for_young_gen_rescan(n_workers);
2887 // If the total workers is greater than 1, then multiple workers
2888 // may be used at some time and the initialization has been set
2889 // such that the single threaded path cannot be used.
2890 if (workers->total_workers() > 1) {
2891 workers->run_task(&tsk);
2892 } else {
2893 tsk.work(0);
2894 }
2895 } else {
2896 // The serial version.
2897 CLDToOopClosure cld_closure(¬Older, true);
2898 gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel.
2899
2900 StrongRootsScope srs(1);
2901
2902 gch->old_process_roots(&srs,
2903 true, // young gen as roots
2904 GenCollectedHeap::ScanningOption(roots_scanning_options()),
2905 should_unload_classes(),
2906 ¬Older,
2907 &cld_closure);
2908 }
2909 }
2910
2911 // Clear mod-union table; it will be dirtied in the prologue of
2912 // CMS generation per each young generation collection.
2913
2914 assert(_modUnionTable.isAllClear(),
2915 "Was cleared in most recent final checkpoint phase"
2916 " or no bits are set in the gc_prologue before the start of the next "
2917 "subsequent marking phase.");
2918
2919 assert(_ct->klass_rem_set()->mod_union_is_clear(), "Must be");
2920
2921 // Save the end of the used_region of the constituent generations
2922 // to be used to limit the extent of sweep in each generation.
2923 save_sweep_limits();
2924 verify_overflow_empty();
2925 }
2926
4267 HandleMark hm;
4268
4269 // ---------- scan from roots --------------
4270 _timer.start();
4271 GenCollectedHeap* gch = GenCollectedHeap::heap();
4272 ParMarkRefsIntoClosure par_mri_cl(_collector->_span, &(_collector->_markBitMap));
4273
4274 // ---------- young gen roots --------------
4275 {
4276 work_on_young_gen_roots(&par_mri_cl);
4277 _timer.stop();
4278 log_trace(gc, task)("Finished young gen initial mark scan work in %dth thread: %3.3f sec", worker_id, _timer.seconds());
4279 }
4280
4281 // ---------- remaining roots --------------
4282 _timer.reset();
4283 _timer.start();
4284
4285 CLDToOopClosure cld_closure(&par_mri_cl, true);
4286
4287 gch->old_process_roots(_strong_roots_scope,
4288 false, // yg was scanned above
4289 GenCollectedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()),
4290 _collector->should_unload_classes(),
4291 &par_mri_cl,
4292 &cld_closure);
4293 assert(_collector->should_unload_classes()
4294 || (_collector->CMSCollector::roots_scanning_options() & GenCollectedHeap::SO_AllCodeCache),
4295 "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops");
4296 _timer.stop();
4297 log_trace(gc, task)("Finished remaining root initial mark scan work in %dth thread: %3.3f sec", worker_id, _timer.seconds());
4298 }
4299
4300 // Parallel remark task
4301 class CMSParRemarkTask: public CMSParMarkTask {
4302 CompactibleFreeListSpace* _cms_space;
4303
4304 // The per-thread work queues, available here for stealing.
4305 OopTaskQueueSet* _task_queues;
4306 ParallelTaskTerminator _term;
4307 StrongRootsScope* _strong_roots_scope;
4308
4309 public:
4310 // A value of 0 passed to n_workers will cause the number of
4311 // workers to be taken from the active workers in the work gang.
4396 GenCollectedHeap* gch = GenCollectedHeap::heap();
4397 ParMarkRefsIntoAndScanClosure par_mrias_cl(_collector,
4398 _collector->_span, _collector->ref_processor(),
4399 &(_collector->_markBitMap),
4400 work_queue(worker_id));
4401
4402 // Rescan young gen roots first since these are likely
4403 // coarsely partitioned and may, on that account, constitute
4404 // the critical path; thus, it's best to start off that
4405 // work first.
4406 // ---------- young gen roots --------------
4407 {
4408 work_on_young_gen_roots(&par_mrias_cl);
4409 _timer.stop();
4410 log_trace(gc, task)("Finished young gen rescan work in %dth thread: %3.3f sec", worker_id, _timer.seconds());
4411 }
4412
4413 // ---------- remaining roots --------------
4414 _timer.reset();
4415 _timer.start();
4416 gch->old_process_roots(_strong_roots_scope,
4417 false, // yg was scanned above
4418 GenCollectedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()),
4419 _collector->should_unload_classes(),
4420 &par_mrias_cl,
4421 NULL); // The dirty klasses will be handled below
4422
4423 assert(_collector->should_unload_classes()
4424 || (_collector->CMSCollector::roots_scanning_options() & GenCollectedHeap::SO_AllCodeCache),
4425 "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops");
4426 _timer.stop();
4427 log_trace(gc, task)("Finished remaining root rescan work in %dth thread: %3.3f sec", worker_id, _timer.seconds());
4428
4429 // ---------- unhandled CLD scanning ----------
4430 if (worker_id == 0) { // Single threaded at the moment.
4431 _timer.reset();
4432 _timer.start();
4433
4434 // Scan all new class loader data objects and new dependencies that were
4435 // introduced during concurrent marking.
4436 ResourceMark rm;
4437 GrowableArray<ClassLoaderData*>* array = ClassLoaderDataGraph::new_clds();
4438 for (int i = 0; i < array->length(); i++) {
4439 par_mrias_cl.do_cld_nv(array->at(i));
4440 }
4943 MemRegion cms_span(lb, ub);
4944 _modUnionTable.dirty_range_iterate_clear(cms_span,
4945 &markFromDirtyCardsClosure);
4946 verify_work_stacks_empty();
4947 log_trace(gc)(" (re-scanned " SIZE_FORMAT " dirty cards in cms gen) ", markFromDirtyCardsClosure.num_dirty_cards());
4948 }
4949 }
4950 if (VerifyDuringGC &&
4951 GenCollectedHeap::heap()->total_collections() >= VerifyGCStartAt) {
4952 HandleMark hm; // Discard invalid handles created during verification
4953 Universe::verify();
4954 }
4955 {
4956 GCTraceTime(Trace, gc, phases) t("Root Rescan", _gc_timer_cm);
4957
4958 verify_work_stacks_empty();
4959
4960 gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel.
4961 StrongRootsScope srs(1);
4962
4963 gch->old_process_roots(&srs,
4964 true, // young gen as roots
4965 GenCollectedHeap::ScanningOption(roots_scanning_options()),
4966 should_unload_classes(),
4967 &mrias_cl,
4968 NULL); // The dirty klasses will be handled below
4969
4970 assert(should_unload_classes()
4971 || (roots_scanning_options() & GenCollectedHeap::SO_AllCodeCache),
4972 "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops");
4973 }
4974
4975 {
4976 GCTraceTime(Trace, gc, phases) t("Visit Unhandled CLDs", _gc_timer_cm);
4977
4978 verify_work_stacks_empty();
4979
4980 // Scan all class loader data objects that might have been introduced
4981 // during concurrent marking.
4982 ResourceMark rm;
4983 GrowableArray<ClassLoaderData*>* array = ClassLoaderDataGraph::new_clds();
4984 for (int i = 0; i < array->length(); i++) {
4985 mrias_cl.do_cld_nv(array->at(i));
4986 }
4987
|