1556 } |
1556 } |
1557 return true; |
1557 return true; |
1558 } |
1558 } |
1559 |
1559 |
1560 if (MetaspaceGC::should_concurrent_collect()) { |
1560 if (MetaspaceGC::should_concurrent_collect()) { |
1561 if (Verbose && PrintGCDetails) { |
1561 if (Verbose && PrintGCDetails) { |
1562 gclog_or_tty->print("CMSCollector: collect for metadata allocation "); |
1562 gclog_or_tty->print("CMSCollector: collect for metadata allocation "); |
1563 } |
1563 } |
1564 return true; |
1564 return true; |
1565 } |
1565 } |
1566 |
1566 |
1567 // CMSTriggerInterval starts a CMS cycle if enough time has passed. |
1567 // CMSTriggerInterval starts a CMS cycle if enough time has passed. |
1568 if (CMSTriggerInterval >= 0) { |
1568 if (CMSTriggerInterval >= 0) { |
1569 if (CMSTriggerInterval == 0) { |
1569 if (CMSTriggerInterval == 0) { |
1570 // Trigger always |
1570 // Trigger always |
2995 void CMSCollector::verify_after_remark_work_1() { |
2995 void CMSCollector::verify_after_remark_work_1() { |
2996 ResourceMark rm; |
2996 ResourceMark rm; |
2997 HandleMark hm; |
2997 HandleMark hm; |
2998 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
2998 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
2999 |
2999 |
3000 // Get a clear set of claim bits for the roots processing to work with. |
3000 // Get a clear set of claim bits for the strong roots processing to work with. |
3001 ClassLoaderDataGraph::clear_claimed_marks(); |
3001 ClassLoaderDataGraph::clear_claimed_marks(); |
3002 |
3002 |
3003 // Mark from roots one level into CMS |
3003 // Mark from roots one level into CMS |
3004 MarkRefsIntoClosure notOlder(_span, verification_mark_bm()); |
3004 MarkRefsIntoClosure notOlder(_span, verification_mark_bm()); |
3005 gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel. |
3005 gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel. |
3006 |
3006 |
3007 gch->gen_process_roots(_cmsGen->level(), |
3007 gch->gen_process_strong_roots(_cmsGen->level(), |
3008 true, // younger gens are roots |
3008 true, // younger gens are roots |
3009 true, // activate StrongRootsScope |
3009 true, // activate StrongRootsScope |
3010 SharedHeap::ScanningOption(roots_scanning_options()), |
3010 SharedHeap::ScanningOption(roots_scanning_options()), |
3011 should_unload_classes(), |
3011 ¬Older, |
3012 ¬Older, |
3012 NULL, |
3013 NULL, |
3013 NULL); // SSS: Provide correct closure |
3014 NULL); // SSS: Provide correct closure |
|
3015 |
3014 |
3016 // Now mark from the roots |
3015 // Now mark from the roots |
3017 MarkFromRootsClosure markFromRootsClosure(this, _span, |
3016 MarkFromRootsClosure markFromRootsClosure(this, _span, |
3018 verification_mark_bm(), verification_mark_stack(), |
3017 verification_mark_bm(), verification_mark_stack(), |
3019 false /* don't yield */, true /* verifying */); |
3018 false /* don't yield */, true /* verifying */); |
3060 void CMSCollector::verify_after_remark_work_2() { |
3059 void CMSCollector::verify_after_remark_work_2() { |
3061 ResourceMark rm; |
3060 ResourceMark rm; |
3062 HandleMark hm; |
3061 HandleMark hm; |
3063 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
3062 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
3064 |
3063 |
3065 // Get a clear set of claim bits for the roots processing to work with. |
3064 // Get a clear set of claim bits for the strong roots processing to work with. |
3066 ClassLoaderDataGraph::clear_claimed_marks(); |
3065 ClassLoaderDataGraph::clear_claimed_marks(); |
3067 |
3066 |
3068 // Mark from roots one level into CMS |
3067 // Mark from roots one level into CMS |
3069 MarkRefsIntoVerifyClosure notOlder(_span, verification_mark_bm(), |
3068 MarkRefsIntoVerifyClosure notOlder(_span, verification_mark_bm(), |
3070 markBitMap()); |
3069 markBitMap()); |
3071 CLDToOopClosure cld_closure(¬Older, true); |
3070 KlassToOopClosure klass_closure(¬Older); |
3072 |
3071 |
3073 gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel. |
3072 gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel. |
3074 |
3073 gch->gen_process_strong_roots(_cmsGen->level(), |
3075 gch->gen_process_roots(_cmsGen->level(), |
3074 true, // younger gens are roots |
3076 true, // younger gens are roots |
3075 true, // activate StrongRootsScope |
3077 true, // activate StrongRootsScope |
3076 SharedHeap::ScanningOption(roots_scanning_options()), |
3078 SharedHeap::ScanningOption(roots_scanning_options()), |
3077 ¬Older, |
3079 should_unload_classes(), |
3078 NULL, |
3080 ¬Older, |
3079 &klass_closure); |
3081 NULL, |
|
3082 &cld_closure); |
|
3083 |
3080 |
3084 // Now mark from the roots |
3081 // Now mark from the roots |
3085 MarkFromRootsVerifyClosure markFromRootsClosure(this, _span, |
3082 MarkFromRootsVerifyClosure markFromRootsClosure(this, _span, |
3086 verification_mark_bm(), markBitMap(), verification_mark_stack()); |
3083 verification_mark_bm(), markBitMap(), verification_mark_stack()); |
3087 assert(_restart_addr == NULL, "Expected pre-condition"); |
3084 assert(_restart_addr == NULL, "Expected pre-condition"); |
3264 } |
3261 } |
3265 |
3262 |
3266 void CMSCollector::setup_cms_unloading_and_verification_state() { |
3263 void CMSCollector::setup_cms_unloading_and_verification_state() { |
3267 const bool should_verify = VerifyBeforeGC || VerifyAfterGC || VerifyDuringGC |
3264 const bool should_verify = VerifyBeforeGC || VerifyAfterGC || VerifyDuringGC |
3268 || VerifyBeforeExit; |
3265 || VerifyBeforeExit; |
3269 const int rso = SharedHeap::SO_AllCodeCache; |
3266 const int rso = SharedHeap::SO_Strings | SharedHeap::SO_AllCodeCache; |
3270 |
3267 |
3271 // We set the proper root for this CMS cycle here. |
3268 // We set the proper root for this CMS cycle here. |
3272 if (should_unload_classes()) { // Should unload classes this cycle |
3269 if (should_unload_classes()) { // Should unload classes this cycle |
|
3270 remove_root_scanning_option(SharedHeap::SO_AllClasses); |
|
3271 add_root_scanning_option(SharedHeap::SO_SystemClasses); |
3273 remove_root_scanning_option(rso); // Shrink the root set appropriately |
3272 remove_root_scanning_option(rso); // Shrink the root set appropriately |
3274 set_verifying(should_verify); // Set verification state for this cycle |
3273 set_verifying(should_verify); // Set verification state for this cycle |
3275 return; // Nothing else needs to be done at this time |
3274 return; // Nothing else needs to be done at this time |
3276 } |
3275 } |
3277 |
3276 |
3278 // Not unloading classes this cycle |
3277 // Not unloading classes this cycle |
3279 assert(!should_unload_classes(), "Inconsistency!"); |
3278 assert(!should_unload_classes(), "Inconsistency!"); |
|
3279 remove_root_scanning_option(SharedHeap::SO_SystemClasses); |
|
3280 add_root_scanning_option(SharedHeap::SO_AllClasses); |
3280 |
3281 |
3281 if ((!verifying() || unloaded_classes_last_cycle()) && should_verify) { |
3282 if ((!verifying() || unloaded_classes_last_cycle()) && should_verify) { |
3282 // Include symbols, strings and code cache elements to prevent their resurrection. |
3283 // Include symbols, strings and code cache elements to prevent their resurrection. |
3283 add_root_scanning_option(rso); |
3284 add_root_scanning_option(rso); |
3284 set_verifying(true); |
3285 set_verifying(true); |
3682 tsk.work(0); |
3683 tsk.work(0); |
3683 } |
3684 } |
3684 gch->set_par_threads(0); |
3685 gch->set_par_threads(0); |
3685 } else { |
3686 } else { |
3686 // The serial version. |
3687 // The serial version. |
3687 CLDToOopClosure cld_closure(¬Older, true); |
3688 KlassToOopClosure klass_closure(¬Older); |
3688 gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel. |
3689 gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel. |
3689 gch->gen_process_roots(_cmsGen->level(), |
3690 gch->gen_process_strong_roots(_cmsGen->level(), |
3690 true, // younger gens are roots |
3691 true, // younger gens are roots |
3691 true, // activate StrongRootsScope |
3692 true, // activate StrongRootsScope |
3692 SharedHeap::ScanningOption(roots_scanning_options()), |
3693 SharedHeap::ScanningOption(roots_scanning_options()), |
3693 should_unload_classes(), |
3694 ¬Older, |
3694 ¬Older, |
3695 NULL, |
3695 NULL, |
3696 &klass_closure); |
3696 &cld_closure); |
|
3697 } |
3697 } |
3698 } |
3698 } |
3699 |
3699 |
3700 // Clear mod-union table; it will be dirtied in the prologue of |
3700 // Clear mod-union table; it will be dirtied in the prologue of |
3701 // CMS generation per each younger generation collection. |
3701 // CMS generation per each younger generation collection. |
5137 |
5137 |
5138 // ---------- scan from roots -------------- |
5138 // ---------- scan from roots -------------- |
5139 _timer.start(); |
5139 _timer.start(); |
5140 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
5140 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
5141 Par_MarkRefsIntoClosure par_mri_cl(_collector->_span, &(_collector->_markBitMap)); |
5141 Par_MarkRefsIntoClosure par_mri_cl(_collector->_span, &(_collector->_markBitMap)); |
|
5142 KlassToOopClosure klass_closure(&par_mri_cl); |
5142 |
5143 |
5143 // ---------- young gen roots -------------- |
5144 // ---------- young gen roots -------------- |
5144 { |
5145 { |
5145 work_on_young_gen_roots(worker_id, &par_mri_cl); |
5146 work_on_young_gen_roots(worker_id, &par_mri_cl); |
5146 _timer.stop(); |
5147 _timer.stop(); |
5152 } |
5153 } |
5153 |
5154 |
5154 // ---------- remaining roots -------------- |
5155 // ---------- remaining roots -------------- |
5155 _timer.reset(); |
5156 _timer.reset(); |
5156 _timer.start(); |
5157 _timer.start(); |
5157 |
5158 gch->gen_process_strong_roots(_collector->_cmsGen->level(), |
5158 CLDToOopClosure cld_closure(&par_mri_cl, true); |
5159 false, // yg was scanned above |
5159 |
5160 false, // this is parallel code |
5160 gch->gen_process_roots(_collector->_cmsGen->level(), |
5161 SharedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()), |
5161 false, // yg was scanned above |
5162 &par_mri_cl, |
5162 false, // this is parallel code |
5163 NULL, |
5163 SharedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()), |
5164 &klass_closure); |
5164 _collector->should_unload_classes(), |
|
5165 &par_mri_cl, |
|
5166 NULL, |
|
5167 &cld_closure); |
|
5168 assert(_collector->should_unload_classes() |
5165 assert(_collector->should_unload_classes() |
5169 || (_collector->CMSCollector::roots_scanning_options() & SharedHeap::SO_AllCodeCache), |
5166 || (_collector->CMSCollector::roots_scanning_options() & SharedHeap::SO_AllCodeCache), |
5170 "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops"); |
5167 "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops"); |
5171 _timer.stop(); |
5168 _timer.stop(); |
5172 if (PrintCMSStatistics != 0) { |
5169 if (PrintCMSStatistics != 0) { |
5291 } |
5288 } |
5292 |
5289 |
5293 // ---------- remaining roots -------------- |
5290 // ---------- remaining roots -------------- |
5294 _timer.reset(); |
5291 _timer.reset(); |
5295 _timer.start(); |
5292 _timer.start(); |
5296 gch->gen_process_roots(_collector->_cmsGen->level(), |
5293 gch->gen_process_strong_roots(_collector->_cmsGen->level(), |
5297 false, // yg was scanned above |
5294 false, // yg was scanned above |
5298 false, // this is parallel code |
5295 false, // this is parallel code |
5299 SharedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()), |
5296 SharedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()), |
5300 _collector->should_unload_classes(), |
5297 &par_mrias_cl, |
5301 &par_mrias_cl, |
5298 NULL, |
5302 NULL, |
5299 NULL); // The dirty klasses will be handled below |
5303 NULL); // The dirty klasses will be handled below |
|
5304 |
|
5305 assert(_collector->should_unload_classes() |
5300 assert(_collector->should_unload_classes() |
5306 || (_collector->CMSCollector::roots_scanning_options() & SharedHeap::SO_AllCodeCache), |
5301 || (_collector->CMSCollector::roots_scanning_options() & SharedHeap::SO_AllCodeCache), |
5307 "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops"); |
5302 "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops"); |
5308 _timer.stop(); |
5303 _timer.stop(); |
5309 if (PrintCMSStatistics != 0) { |
5304 if (PrintCMSStatistics != 0) { |
5354 } |
5349 } |
5355 |
5350 |
5356 // We might have added oops to ClassLoaderData::_handles during the |
5351 // We might have added oops to ClassLoaderData::_handles during the |
5357 // concurrent marking phase. These oops point to newly allocated objects |
5352 // concurrent marking phase. These oops point to newly allocated objects |
5358 // that are guaranteed to be kept alive. Either by the direct allocation |
5353 // that are guaranteed to be kept alive. Either by the direct allocation |
5359 // code, or when the young collector processes the roots. Hence, |
5354 // code, or when the young collector processes the strong roots. Hence, |
5360 // we don't have to revisit the _handles block during the remark phase. |
5355 // we don't have to revisit the _handles block during the remark phase. |
5361 |
5356 |
5362 // ---------- rescan dirty cards ------------ |
5357 // ---------- rescan dirty cards ------------ |
5363 _timer.reset(); |
5358 _timer.reset(); |
5364 _timer.start(); |
5359 _timer.start(); |
5776 |
5771 |
5777 CMSParRemarkTask tsk(this, |
5772 CMSParRemarkTask tsk(this, |
5778 cms_space, |
5773 cms_space, |
5779 n_workers, workers, task_queues()); |
5774 n_workers, workers, task_queues()); |
5780 |
5775 |
5781 // Set up for parallel process_roots work. |
5776 // Set up for parallel process_strong_roots work. |
5782 gch->set_par_threads(n_workers); |
5777 gch->set_par_threads(n_workers); |
5783 // We won't be iterating over the cards in the card table updating |
5778 // We won't be iterating over the cards in the card table updating |
5784 // the younger_gen cards, so we shouldn't call the following else |
5779 // the younger_gen cards, so we shouldn't call the following else |
5785 // the verification code as well as subsequent younger_refs_iterate |
5780 // the verification code as well as subsequent younger_refs_iterate |
5786 // code would get confused. XXX |
5781 // code would get confused. XXX |
5787 // gch->rem_set()->prepare_for_younger_refs_iterate(true); // parallel |
5782 // gch->rem_set()->prepare_for_younger_refs_iterate(true); // parallel |
5788 |
5783 |
5789 // The young gen rescan work will not be done as part of |
5784 // The young gen rescan work will not be done as part of |
5790 // process_roots (which currently doesn't know how to |
5785 // process_strong_roots (which currently doesn't knw how to |
5791 // parallelize such a scan), but rather will be broken up into |
5786 // parallelize such a scan), but rather will be broken up into |
5792 // a set of parallel tasks (via the sampling that the [abortable] |
5787 // a set of parallel tasks (via the sampling that the [abortable] |
5793 // preclean phase did of EdenSpace, plus the [two] tasks of |
5788 // preclean phase did of EdenSpace, plus the [two] tasks of |
5794 // scanning the [two] survivor spaces. Further fine-grain |
5789 // scanning the [two] survivor spaces. Further fine-grain |
5795 // parallelization of the scanning of the survivor spaces |
5790 // parallelization of the scanning of the survivor spaces |
5882 |
5877 |
5883 verify_work_stacks_empty(); |
5878 verify_work_stacks_empty(); |
5884 |
5879 |
5885 gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel. |
5880 gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel. |
5886 GenCollectedHeap::StrongRootsScope srs(gch); |
5881 GenCollectedHeap::StrongRootsScope srs(gch); |
5887 |
5882 gch->gen_process_strong_roots(_cmsGen->level(), |
5888 gch->gen_process_roots(_cmsGen->level(), |
5883 true, // younger gens as roots |
5889 true, // younger gens as roots |
5884 false, // use the local StrongRootsScope |
5890 false, // use the local StrongRootsScope |
5885 SharedHeap::ScanningOption(roots_scanning_options()), |
5891 SharedHeap::ScanningOption(roots_scanning_options()), |
5886 &mrias_cl, |
5892 should_unload_classes(), |
5887 NULL, |
5893 &mrias_cl, |
5888 NULL); // The dirty klasses will be handled below |
5894 NULL, |
|
5895 NULL); // The dirty klasses will be handled below |
|
5896 |
5889 |
5897 assert(should_unload_classes() |
5890 assert(should_unload_classes() |
5898 || (roots_scanning_options() & SharedHeap::SO_AllCodeCache), |
5891 || (roots_scanning_options() & SharedHeap::SO_AllCodeCache), |
5899 "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops"); |
5892 "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops"); |
5900 } |
5893 } |
5930 } |
5923 } |
5931 |
5924 |
5932 // We might have added oops to ClassLoaderData::_handles during the |
5925 // We might have added oops to ClassLoaderData::_handles during the |
5933 // concurrent marking phase. These oops point to newly allocated objects |
5926 // concurrent marking phase. These oops point to newly allocated objects |
5934 // that are guaranteed to be kept alive. Either by the direct allocation |
5927 // that are guaranteed to be kept alive. Either by the direct allocation |
5935 // code, or when the young collector processes the roots. Hence, |
5928 // code, or when the young collector processes the strong roots. Hence, |
5936 // we don't have to revisit the _handles block during the remark phase. |
5929 // we don't have to revisit the _handles block during the remark phase. |
5937 |
5930 |
5938 verify_work_stacks_empty(); |
5931 verify_work_stacks_empty(); |
5939 // Restore evacuated mark words, if any, used for overflow list links |
5932 // Restore evacuated mark words, if any, used for overflow list links |
5940 if (!CMSOverflowEarlyRestoration) { |
5933 if (!CMSOverflowEarlyRestoration) { |
6180 { |
6173 { |
6181 GCTraceTime t("scrub symbol table", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id()); |
6174 GCTraceTime t("scrub symbol table", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id()); |
6182 // Clean up unreferenced symbols in symbol table. |
6175 // Clean up unreferenced symbols in symbol table. |
6183 SymbolTable::unlink(); |
6176 SymbolTable::unlink(); |
6184 } |
6177 } |
6185 |
6178 } |
6186 { |
6179 |
6187 GCTraceTime t("scrub string table", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id()); |
6180 // CMS doesn't use the StringTable as hard roots when class unloading is turned off. |
6188 // Delete entries for dead interned strings. |
6181 // Need to check if we really scanned the StringTable. |
6189 StringTable::unlink(&_is_alive_closure); |
6182 if ((roots_scanning_options() & SharedHeap::SO_Strings) == 0) { |
6190 } |
6183 GCTraceTime t("scrub string table", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id()); |
6191 } |
6184 // Delete entries for dead interned strings. |
6192 |
6185 StringTable::unlink(&_is_alive_closure); |
|
6186 } |
6193 |
6187 |
6194 // Restore any preserved marks as a result of mark stack or |
6188 // Restore any preserved marks as a result of mark stack or |
6195 // work queue overflow |
6189 // work queue overflow |
6196 restore_preserved_marks_if_any(); // done single-threaded for now |
6190 restore_preserved_marks_if_any(); // done single-threaded for now |
6197 |
6191 |