68 #include "memory/allocation.hpp" 69 #include "memory/binaryTreeDictionary.inline.hpp" 70 #include "memory/iterator.inline.hpp" 71 #include "memory/padded.hpp" 72 #include "memory/resourceArea.hpp" 73 #include "oops/access.inline.hpp" 74 #include "oops/oop.inline.hpp" 75 #include "prims/jvmtiExport.hpp" 76 #include "runtime/atomic.hpp" 77 #include "runtime/flags/flagSetting.hpp" 78 #include "runtime/globals_extension.hpp" 79 #include "runtime/handles.inline.hpp" 80 #include "runtime/java.hpp" 81 #include "runtime/orderAccess.hpp" 82 #include "runtime/timer.hpp" 83 #include "runtime/vmThread.hpp" 84 #include "services/memoryService.hpp" 85 #include "services/runtimeService.hpp" 86 #include "utilities/align.hpp" 87 #include "utilities/stack.inline.hpp" 88 89 // statics 90 CMSCollector* ConcurrentMarkSweepGeneration::_collector = NULL; 91 bool CMSCollector::_full_gc_requested = false; 92 GCCause::Cause CMSCollector::_full_gc_cause = GCCause::_no_gc; 93 94 ////////////////////////////////////////////////////////////////// 95 // In support of CMS/VM thread synchronization 96 ////////////////////////////////////////////////////////////////// 97 // We split use of the CGC_lock into 2 "levels". 98 // The low-level locking is of the usual CGC_lock monitor. We introduce 99 // a higher level "token" (hereafter "CMS token") built on top of the 100 // low level monitor (hereafter "CGC lock"). 101 // The token-passing protocol gives priority to the VM thread. The 102 // CMS-lock doesn't provide any fairness guarantees, but clients 103 // should ensure that it is only held for very short, bounded 104 // durations. 105 // 106 // When either of the CMS thread or the VM thread is involved in 107 // collection operations during which it does not want the other 5247 // This is the point where the entire marking should have completed. 5248 verify_work_stacks_empty(); 5249 5250 { 5251 GCTraceTime(Debug, gc, phases) t("Weak Processing", _gc_timer_cm); 5252 WeakProcessor::weak_oops_do(&_is_alive_closure, &do_nothing_cl); 5253 } 5254 5255 if (should_unload_classes()) { 5256 { 5257 GCTraceTime(Debug, gc, phases) t("Class Unloading", _gc_timer_cm); 5258 5259 // Unload classes and purge the SystemDictionary. 5260 bool purged_class = SystemDictionary::do_unloading(_gc_timer_cm); 5261 5262 // Unload nmethods. 5263 CodeCache::do_unloading(&_is_alive_closure, purged_class); 5264 5265 // Prune dead klasses from subklass/sibling/implementor lists. 5266 Klass::clean_weak_klass_links(purged_class); 5267 } 5268 } 5269 5270 // Restore any preserved marks as a result of mark stack or 5271 // work queue overflow 5272 restore_preserved_marks_if_any(); // done single-threaded for now 5273 5274 rp->set_enqueuing_is_done(true); 5275 rp->verify_no_references_recorded(); 5276 } 5277 5278 #ifndef PRODUCT 5279 void CMSCollector::check_correct_thread_executing() { 5280 Thread* t = Thread::current(); 5281 // Only the VM thread or the CMS thread should be here. 5282 assert(t->is_ConcurrentGC_thread() || t->is_VM_thread(), 5283 "Unexpected thread type"); 5284 // If this is the vm thread, the foreground process 5285 // should not be waiting. Note that _foregroundGCIsActive is 5286 // true while the foreground collector is waiting. | 68 #include "memory/allocation.hpp" 69 #include "memory/binaryTreeDictionary.inline.hpp" 70 #include "memory/iterator.inline.hpp" 71 #include "memory/padded.hpp" 72 #include "memory/resourceArea.hpp" 73 #include "oops/access.inline.hpp" 74 #include "oops/oop.inline.hpp" 75 #include "prims/jvmtiExport.hpp" 76 #include "runtime/atomic.hpp" 77 #include "runtime/flags/flagSetting.hpp" 78 #include "runtime/globals_extension.hpp" 79 #include "runtime/handles.inline.hpp" 80 #include "runtime/java.hpp" 81 #include "runtime/orderAccess.hpp" 82 #include "runtime/timer.hpp" 83 #include "runtime/vmThread.hpp" 84 #include "services/memoryService.hpp" 85 #include "services/runtimeService.hpp" 86 #include "utilities/align.hpp" 87 #include "utilities/stack.inline.hpp" 88 #if INCLUDE_JVMCI 89 #include "jvmci/jvmci.hpp" 90 #endif 91 92 // statics 93 CMSCollector* ConcurrentMarkSweepGeneration::_collector = NULL; 94 bool CMSCollector::_full_gc_requested = false; 95 GCCause::Cause CMSCollector::_full_gc_cause = GCCause::_no_gc; 96 97 ////////////////////////////////////////////////////////////////// 98 // In support of CMS/VM thread synchronization 99 ////////////////////////////////////////////////////////////////// 100 // We split use of the CGC_lock into 2 "levels". 101 // The low-level locking is of the usual CGC_lock monitor. We introduce 102 // a higher level "token" (hereafter "CMS token") built on top of the 103 // low level monitor (hereafter "CGC lock"). 104 // The token-passing protocol gives priority to the VM thread. The 105 // CMS-lock doesn't provide any fairness guarantees, but clients 106 // should ensure that it is only held for very short, bounded 107 // durations. 108 // 109 // When either of the CMS thread or the VM thread is involved in 110 // collection operations during which it does not want the other 5250 // This is the point where the entire marking should have completed. 5251 verify_work_stacks_empty(); 5252 5253 { 5254 GCTraceTime(Debug, gc, phases) t("Weak Processing", _gc_timer_cm); 5255 WeakProcessor::weak_oops_do(&_is_alive_closure, &do_nothing_cl); 5256 } 5257 5258 if (should_unload_classes()) { 5259 { 5260 GCTraceTime(Debug, gc, phases) t("Class Unloading", _gc_timer_cm); 5261 5262 // Unload classes and purge the SystemDictionary. 5263 bool purged_class = SystemDictionary::do_unloading(_gc_timer_cm); 5264 5265 // Unload nmethods. 5266 CodeCache::do_unloading(&_is_alive_closure, purged_class); 5267 5268 // Prune dead klasses from subklass/sibling/implementor lists. 5269 Klass::clean_weak_klass_links(purged_class); 5270 5271 #if INCLUDE_JVMCI 5272 // Clean JVMCI metadata handles. 5273 JVMCI::do_unloading(&_is_alive_closure, purged_class); 5274 #endif 5275 } 5276 } 5277 5278 // Restore any preserved marks as a result of mark stack or 5279 // work queue overflow 5280 restore_preserved_marks_if_any(); // done single-threaded for now 5281 5282 rp->set_enqueuing_is_done(true); 5283 rp->verify_no_references_recorded(); 5284 } 5285 5286 #ifndef PRODUCT 5287 void CMSCollector::check_correct_thread_executing() { 5288 Thread* t = Thread::current(); 5289 // Only the VM thread or the CMS thread should be here. 5290 assert(t->is_ConcurrentGC_thread() || t->is_VM_thread(), 5291 "Unexpected thread type"); 5292 // If this is the vm thread, the foreground process 5293 // should not be waiting. Note that _foregroundGCIsActive is 5294 // true while the foreground collector is waiting. |