3026 void CMSCollector::verify_after_remark_work_1() { |
3026 void CMSCollector::verify_after_remark_work_1() { |
3027 ResourceMark rm; |
3027 ResourceMark rm; |
3028 HandleMark hm; |
3028 HandleMark hm; |
3029 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
3029 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
3030 |
3030 |
3031 // Get a clear set of claim bits for the strong roots processing to work with. |
3031 // Get a clear set of claim bits for the roots processing to work with. |
3032 ClassLoaderDataGraph::clear_claimed_marks(); |
3032 ClassLoaderDataGraph::clear_claimed_marks(); |
3033 |
3033 |
3034 // Mark from roots one level into CMS |
3034 // Mark from roots one level into CMS |
3035 MarkRefsIntoClosure notOlder(_span, verification_mark_bm()); |
3035 MarkRefsIntoClosure notOlder(_span, verification_mark_bm()); |
3036 gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel. |
3036 gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel. |
3037 |
3037 |
3038 gch->gen_process_strong_roots(_cmsGen->level(), |
3038 gch->gen_process_roots(_cmsGen->level(), |
3039 true, // younger gens are roots |
3039 true, // younger gens are roots |
3040 true, // activate StrongRootsScope |
3040 true, // activate StrongRootsScope |
3041 SharedHeap::ScanningOption(roots_scanning_options()), |
3041 SharedHeap::ScanningOption(roots_scanning_options()), |
3042 ¬Older, |
3042 should_unload_classes(), |
3043 NULL, |
3043 ¬Older, |
3044 NULL); // SSS: Provide correct closure |
3044 NULL, |
|
3045 NULL); // SSS: Provide correct closure |
3045 |
3046 |
3046 // Now mark from the roots |
3047 // Now mark from the roots |
3047 MarkFromRootsClosure markFromRootsClosure(this, _span, |
3048 MarkFromRootsClosure markFromRootsClosure(this, _span, |
3048 verification_mark_bm(), verification_mark_stack(), |
3049 verification_mark_bm(), verification_mark_stack(), |
3049 false /* don't yield */, true /* verifying */); |
3050 false /* don't yield */, true /* verifying */); |
3090 void CMSCollector::verify_after_remark_work_2() { |
3091 void CMSCollector::verify_after_remark_work_2() { |
3091 ResourceMark rm; |
3092 ResourceMark rm; |
3092 HandleMark hm; |
3093 HandleMark hm; |
3093 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
3094 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
3094 |
3095 |
3095 // Get a clear set of claim bits for the strong roots processing to work with. |
3096 // Get a clear set of claim bits for the roots processing to work with. |
3096 ClassLoaderDataGraph::clear_claimed_marks(); |
3097 ClassLoaderDataGraph::clear_claimed_marks(); |
3097 |
3098 |
3098 // Mark from roots one level into CMS |
3099 // Mark from roots one level into CMS |
3099 MarkRefsIntoVerifyClosure notOlder(_span, verification_mark_bm(), |
3100 MarkRefsIntoVerifyClosure notOlder(_span, verification_mark_bm(), |
3100 markBitMap()); |
3101 markBitMap()); |
3101 KlassToOopClosure klass_closure(¬Older); |
3102 CLDToOopClosure cld_closure(¬Older, true); |
3102 |
3103 |
3103 gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel. |
3104 gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel. |
3104 gch->gen_process_strong_roots(_cmsGen->level(), |
3105 |
3105 true, // younger gens are roots |
3106 gch->gen_process_roots(_cmsGen->level(), |
3106 true, // activate StrongRootsScope |
3107 true, // younger gens are roots |
3107 SharedHeap::ScanningOption(roots_scanning_options()), |
3108 true, // activate StrongRootsScope |
3108 ¬Older, |
3109 SharedHeap::ScanningOption(roots_scanning_options()), |
3109 NULL, |
3110 should_unload_classes(), |
3110 &klass_closure); |
3111 ¬Older, |
|
3112 NULL, |
|
3113 &cld_closure); |
3111 |
3114 |
3112 // Now mark from the roots |
3115 // Now mark from the roots |
3113 MarkFromRootsVerifyClosure markFromRootsClosure(this, _span, |
3116 MarkFromRootsVerifyClosure markFromRootsClosure(this, _span, |
3114 verification_mark_bm(), markBitMap(), verification_mark_stack()); |
3117 verification_mark_bm(), markBitMap(), verification_mark_stack()); |
3115 assert(_restart_addr == NULL, "Expected pre-condition"); |
3118 assert(_restart_addr == NULL, "Expected pre-condition"); |
3292 } |
3295 } |
3293 |
3296 |
3294 void CMSCollector::setup_cms_unloading_and_verification_state() { |
3297 void CMSCollector::setup_cms_unloading_and_verification_state() { |
3295 const bool should_verify = VerifyBeforeGC || VerifyAfterGC || VerifyDuringGC |
3298 const bool should_verify = VerifyBeforeGC || VerifyAfterGC || VerifyDuringGC |
3296 || VerifyBeforeExit; |
3299 || VerifyBeforeExit; |
3297 const int rso = SharedHeap::SO_Strings | SharedHeap::SO_AllCodeCache; |
3300 const int rso = SharedHeap::SO_AllCodeCache; |
3298 |
3301 |
3299 // We set the proper root for this CMS cycle here. |
3302 // We set the proper root for this CMS cycle here. |
3300 if (should_unload_classes()) { // Should unload classes this cycle |
3303 if (should_unload_classes()) { // Should unload classes this cycle |
3301 remove_root_scanning_option(SharedHeap::SO_AllClasses); |
|
3302 add_root_scanning_option(SharedHeap::SO_SystemClasses); |
|
3303 remove_root_scanning_option(rso); // Shrink the root set appropriately |
3304 remove_root_scanning_option(rso); // Shrink the root set appropriately |
3304 set_verifying(should_verify); // Set verification state for this cycle |
3305 set_verifying(should_verify); // Set verification state for this cycle |
3305 return; // Nothing else needs to be done at this time |
3306 return; // Nothing else needs to be done at this time |
3306 } |
3307 } |
3307 |
3308 |
3308 // Not unloading classes this cycle |
3309 // Not unloading classes this cycle |
3309 assert(!should_unload_classes(), "Inconsitency!"); |
3310 assert(!should_unload_classes(), "Inconsitency!"); |
3310 remove_root_scanning_option(SharedHeap::SO_SystemClasses); |
|
3311 add_root_scanning_option(SharedHeap::SO_AllClasses); |
|
3312 |
3311 |
3313 if ((!verifying() || unloaded_classes_last_cycle()) && should_verify) { |
3312 if ((!verifying() || unloaded_classes_last_cycle()) && should_verify) { |
3314 // Include symbols, strings and code cache elements to prevent their resurrection. |
3313 // Include symbols, strings and code cache elements to prevent their resurrection. |
3315 add_root_scanning_option(rso); |
3314 add_root_scanning_option(rso); |
3316 set_verifying(true); |
3315 set_verifying(true); |
3717 tsk.work(0); |
3716 tsk.work(0); |
3718 } |
3717 } |
3719 gch->set_par_threads(0); |
3718 gch->set_par_threads(0); |
3720 } else { |
3719 } else { |
3721 // The serial version. |
3720 // The serial version. |
3722 KlassToOopClosure klass_closure(¬Older); |
3721 CLDToOopClosure cld_closure(¬Older, true); |
3723 gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel. |
3722 gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel. |
3724 gch->gen_process_strong_roots(_cmsGen->level(), |
3723 gch->gen_process_roots(_cmsGen->level(), |
3725 true, // younger gens are roots |
3724 true, // younger gens are roots |
3726 true, // activate StrongRootsScope |
3725 true, // activate StrongRootsScope |
3727 SharedHeap::ScanningOption(roots_scanning_options()), |
3726 SharedHeap::ScanningOption(roots_scanning_options()), |
3728 ¬Older, |
3727 should_unload_classes(), |
3729 NULL, |
3728 ¬Older, |
3730 &klass_closure); |
3729 NULL, |
|
3730 &cld_closure); |
3731 } |
3731 } |
3732 } |
3732 } |
3733 |
3733 |
3734 // Clear mod-union table; it will be dirtied in the prologue of |
3734 // Clear mod-union table; it will be dirtied in the prologue of |
3735 // CMS generation per each younger generation collection. |
3735 // CMS generation per each younger generation collection. |
5201 |
5201 |
5202 // ---------- scan from roots -------------- |
5202 // ---------- scan from roots -------------- |
5203 _timer.start(); |
5203 _timer.start(); |
5204 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
5204 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
5205 Par_MarkRefsIntoClosure par_mri_cl(_collector->_span, &(_collector->_markBitMap)); |
5205 Par_MarkRefsIntoClosure par_mri_cl(_collector->_span, &(_collector->_markBitMap)); |
5206 KlassToOopClosure klass_closure(&par_mri_cl); |
|
5207 |
5206 |
5208 // ---------- young gen roots -------------- |
5207 // ---------- young gen roots -------------- |
5209 { |
5208 { |
5210 work_on_young_gen_roots(worker_id, &par_mri_cl); |
5209 work_on_young_gen_roots(worker_id, &par_mri_cl); |
5211 _timer.stop(); |
5210 _timer.stop(); |
5217 } |
5216 } |
5218 |
5217 |
5219 // ---------- remaining roots -------------- |
5218 // ---------- remaining roots -------------- |
5220 _timer.reset(); |
5219 _timer.reset(); |
5221 _timer.start(); |
5220 _timer.start(); |
5222 gch->gen_process_strong_roots(_collector->_cmsGen->level(), |
5221 |
5223 false, // yg was scanned above |
5222 CLDToOopClosure cld_closure(&par_mri_cl, true); |
5224 false, // this is parallel code |
5223 |
5225 SharedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()), |
5224 gch->gen_process_roots(_collector->_cmsGen->level(), |
5226 &par_mri_cl, |
5225 false, // yg was scanned above |
5227 NULL, |
5226 false, // this is parallel code |
5228 &klass_closure); |
5227 SharedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()), |
|
5228 _collector->should_unload_classes(), |
|
5229 &par_mri_cl, |
|
5230 NULL, |
|
5231 &cld_closure); |
5229 assert(_collector->should_unload_classes() |
5232 assert(_collector->should_unload_classes() |
5230 || (_collector->CMSCollector::roots_scanning_options() & SharedHeap::SO_AllCodeCache), |
5233 || (_collector->CMSCollector::roots_scanning_options() & SharedHeap::SO_AllCodeCache), |
5231 "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops"); |
5234 "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops"); |
5232 _timer.stop(); |
5235 _timer.stop(); |
5233 if (PrintCMSStatistics != 0) { |
5236 if (PrintCMSStatistics != 0) { |
5352 } |
5355 } |
5353 |
5356 |
5354 // ---------- remaining roots -------------- |
5357 // ---------- remaining roots -------------- |
5355 _timer.reset(); |
5358 _timer.reset(); |
5356 _timer.start(); |
5359 _timer.start(); |
5357 gch->gen_process_strong_roots(_collector->_cmsGen->level(), |
5360 gch->gen_process_roots(_collector->_cmsGen->level(), |
5358 false, // yg was scanned above |
5361 false, // yg was scanned above |
5359 false, // this is parallel code |
5362 false, // this is parallel code |
5360 SharedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()), |
5363 SharedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()), |
5361 &par_mrias_cl, |
5364 _collector->should_unload_classes(), |
5362 NULL, |
5365 &par_mrias_cl, |
5363 NULL); // The dirty klasses will be handled below |
5366 NULL, |
|
5367 NULL); // The dirty klasses will be handled below |
|
5368 |
5364 assert(_collector->should_unload_classes() |
5369 assert(_collector->should_unload_classes() |
5365 || (_collector->CMSCollector::roots_scanning_options() & SharedHeap::SO_AllCodeCache), |
5370 || (_collector->CMSCollector::roots_scanning_options() & SharedHeap::SO_AllCodeCache), |
5366 "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops"); |
5371 "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops"); |
5367 _timer.stop(); |
5372 _timer.stop(); |
5368 if (PrintCMSStatistics != 0) { |
5373 if (PrintCMSStatistics != 0) { |
5413 } |
5418 } |
5414 |
5419 |
5415 // We might have added oops to ClassLoaderData::_handles during the |
5420 // We might have added oops to ClassLoaderData::_handles during the |
5416 // concurrent marking phase. These oops point to newly allocated objects |
5421 // concurrent marking phase. These oops point to newly allocated objects |
5417 // that are guaranteed to be kept alive. Either by the direct allocation |
5422 // that are guaranteed to be kept alive. Either by the direct allocation |
5418 // code, or when the young collector processes the strong roots. Hence, |
5423 // code, or when the young collector processes the roots. Hence, |
5419 // we don't have to revisit the _handles block during the remark phase. |
5424 // we don't have to revisit the _handles block during the remark phase. |
5420 |
5425 |
5421 // ---------- rescan dirty cards ------------ |
5426 // ---------- rescan dirty cards ------------ |
5422 _timer.reset(); |
5427 _timer.reset(); |
5423 _timer.start(); |
5428 _timer.start(); |
5835 |
5840 |
5836 CMSParRemarkTask tsk(this, |
5841 CMSParRemarkTask tsk(this, |
5837 cms_space, |
5842 cms_space, |
5838 n_workers, workers, task_queues()); |
5843 n_workers, workers, task_queues()); |
5839 |
5844 |
5840 // Set up for parallel process_strong_roots work. |
5845 // Set up for parallel process_roots work. |
5841 gch->set_par_threads(n_workers); |
5846 gch->set_par_threads(n_workers); |
5842 // We won't be iterating over the cards in the card table updating |
5847 // We won't be iterating over the cards in the card table updating |
5843 // the younger_gen cards, so we shouldn't call the following else |
5848 // the younger_gen cards, so we shouldn't call the following else |
5844 // the verification code as well as subsequent younger_refs_iterate |
5849 // the verification code as well as subsequent younger_refs_iterate |
5845 // code would get confused. XXX |
5850 // code would get confused. XXX |
5846 // gch->rem_set()->prepare_for_younger_refs_iterate(true); // parallel |
5851 // gch->rem_set()->prepare_for_younger_refs_iterate(true); // parallel |
5847 |
5852 |
5848 // The young gen rescan work will not be done as part of |
5853 // The young gen rescan work will not be done as part of |
5849 // process_strong_roots (which currently doesn't knw how to |
5854 // process_roots (which currently doesn't know how to |
5850 // parallelize such a scan), but rather will be broken up into |
5855 // parallelize such a scan), but rather will be broken up into |
5851 // a set of parallel tasks (via the sampling that the [abortable] |
5856 // a set of parallel tasks (via the sampling that the [abortable] |
5852 // preclean phase did of EdenSpace, plus the [two] tasks of |
5857 // preclean phase did of EdenSpace, plus the [two] tasks of |
5853 // scanning the [two] survivor spaces. Further fine-grain |
5858 // scanning the [two] survivor spaces. Further fine-grain |
5854 // parallelization of the scanning of the survivor spaces |
5859 // parallelization of the scanning of the survivor spaces |
5941 |
5946 |
5942 verify_work_stacks_empty(); |
5947 verify_work_stacks_empty(); |
5943 |
5948 |
5944 gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel. |
5949 gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel. |
5945 GenCollectedHeap::StrongRootsScope srs(gch); |
5950 GenCollectedHeap::StrongRootsScope srs(gch); |
5946 gch->gen_process_strong_roots(_cmsGen->level(), |
5951 |
5947 true, // younger gens as roots |
5952 gch->gen_process_roots(_cmsGen->level(), |
5948 false, // use the local StrongRootsScope |
5953 true, // younger gens as roots |
5949 SharedHeap::ScanningOption(roots_scanning_options()), |
5954 false, // use the local StrongRootsScope |
5950 &mrias_cl, |
5955 SharedHeap::ScanningOption(roots_scanning_options()), |
5951 NULL, |
5956 should_unload_classes(), |
5952 NULL); // The dirty klasses will be handled below |
5957 &mrias_cl, |
|
5958 NULL, |
|
5959 NULL); // The dirty klasses will be handled below |
5953 |
5960 |
5954 assert(should_unload_classes() |
5961 assert(should_unload_classes() |
5955 || (roots_scanning_options() & SharedHeap::SO_AllCodeCache), |
5962 || (roots_scanning_options() & SharedHeap::SO_AllCodeCache), |
5956 "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops"); |
5963 "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops"); |
5957 } |
5964 } |
5987 } |
5994 } |
5988 |
5995 |
5989 // We might have added oops to ClassLoaderData::_handles during the |
5996 // We might have added oops to ClassLoaderData::_handles during the |
5990 // concurrent marking phase. These oops point to newly allocated objects |
5997 // concurrent marking phase. These oops point to newly allocated objects |
5991 // that are guaranteed to be kept alive. Either by the direct allocation |
5998 // that are guaranteed to be kept alive. Either by the direct allocation |
5992 // code, or when the young collector processes the strong roots. Hence, |
5999 // code, or when the young collector processes the roots. Hence, |
5993 // we don't have to revisit the _handles block during the remark phase. |
6000 // we don't have to revisit the _handles block during the remark phase. |
5994 |
6001 |
5995 verify_work_stacks_empty(); |
6002 verify_work_stacks_empty(); |
5996 // Restore evacuated mark words, if any, used for overflow list links |
6003 // Restore evacuated mark words, if any, used for overflow list links |
5997 if (!CMSOverflowEarlyRestoration) { |
6004 if (!CMSOverflowEarlyRestoration) { |
6237 { |
6244 { |
6238 GCTraceTime t("scrub symbol table", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id()); |
6245 GCTraceTime t("scrub symbol table", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id()); |
6239 // Clean up unreferenced symbols in symbol table. |
6246 // Clean up unreferenced symbols in symbol table. |
6240 SymbolTable::unlink(); |
6247 SymbolTable::unlink(); |
6241 } |
6248 } |
6242 } |
6249 |
6243 |
6250 { |
6244 // CMS doesn't use the StringTable as hard roots when class unloading is turned off. |
6251 GCTraceTime t("scrub string table", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id()); |
6245 // Need to check if we really scanned the StringTable. |
6252 // Delete entries for dead interned strings. |
6246 if ((roots_scanning_options() & SharedHeap::SO_Strings) == 0) { |
6253 StringTable::unlink(&_is_alive_closure); |
6247 GCTraceTime t("scrub string table", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id()); |
6254 } |
6248 // Delete entries for dead interned strings. |
6255 } |
6249 StringTable::unlink(&_is_alive_closure); |
6256 |
6250 } |
|
6251 |
6257 |
6252 // Restore any preserved marks as a result of mark stack or |
6258 // Restore any preserved marks as a result of mark stack or |
6253 // work queue overflow |
6259 // work queue overflow |
6254 restore_preserved_marks_if_any(); // done single-threaded for now |
6260 restore_preserved_marks_if_any(); // done single-threaded for now |
6255 |
6261 |