src/share/vm/memory/sharedHeap.cpp

Print this page




 142 SharedHeap::StrongRootsScope::StrongRootsScope(SharedHeap* heap, bool activate)
 143   : MarkScope(activate), _sh(heap), _n_workers_done_with_threads(0)
 144 {
 145   if (_active) {
 146     _sh->register_strong_roots_scope(this);
 147     _sh->change_strong_roots_parity();
 148     // Zero the claimed high water mark in the StringTable
 149     StringTable::clear_parallel_claimed_index();
 150   }
 151 }
 152 
 153 SharedHeap::StrongRootsScope::~StrongRootsScope() {
 154   if (_active) {
 155     _sh->unregister_strong_roots_scope(this);
 156   }
 157 }
 158 
 159 Monitor* SharedHeap::StrongRootsScope::_lock = new Monitor(Mutex::leaf, "StrongRootsScope lock", false);
 160 
 161 void SharedHeap::StrongRootsScope::mark_worker_done_with_threads(uint n_workers) {
 162   // The Thread work barrier is only needed by G1.

 163   // No need to use the barrier if this is single-threaded code.
 164   if (UseG1GC && n_workers > 0) {
 165     uint new_value = (uint)Atomic::add(1, &_n_workers_done_with_threads);
 166     if (new_value == n_workers) {
 167       // This thread is last. Notify the others.
 168       MonitorLockerEx ml(_lock, Mutex::_no_safepoint_check_flag);
 169       _lock->notify_all();
 170     }
 171   }

 172 }
 173 
 174 void SharedHeap::StrongRootsScope::wait_until_all_workers_done_with_threads(uint n_workers) {




 175   // No need to use the barrier if this is single-threaded code.
 176   if (n_workers > 0 && (uint)_n_workers_done_with_threads != n_workers) {
 177     MonitorLockerEx ml(_lock, Mutex::_no_safepoint_check_flag);
 178     while ((uint)_n_workers_done_with_threads != n_workers) {
 179       _lock->wait(Mutex::_no_safepoint_check_flag, 0, false);
 180     }
 181   }

 182 }
 183 
 184 void SharedHeap::process_roots(bool activate_scope,
 185                                ScanningOption so,
 186                                OopClosure* strong_roots,
 187                                OopClosure* weak_roots,
 188                                CLDClosure* strong_cld_closure,
 189                                CLDClosure* weak_cld_closure,
 190                                CodeBlobClosure* code_roots) {
 191   StrongRootsScope srs(this, activate_scope);
 192 
 193   // General roots.
 194   assert(_strong_roots_parity != 0, "must have called prologue code");
 195   assert(code_roots != NULL, "code root closure should always be set");
 196   // _n_termination for _process_strong_tasks should be set up stream
 197   // in a method not running in a GC worker.  Otherwise the GC worker
 198   // could be trying to change the termination condition while the task
 199   // is executing in another GC worker.
 200 
 201   // Iterating over the CLDG and the Threads are done early to allow G1 to




 142 SharedHeap::StrongRootsScope::StrongRootsScope(SharedHeap* heap, bool activate)
 143   : MarkScope(activate), _sh(heap), _n_workers_done_with_threads(0)
 144 {
 145   if (_active) {
 146     _sh->register_strong_roots_scope(this);
 147     _sh->change_strong_roots_parity();
 148     // Zero the claimed high water mark in the StringTable
 149     StringTable::clear_parallel_claimed_index();
 150   }
 151 }
 152 
 153 SharedHeap::StrongRootsScope::~StrongRootsScope() {
 154   if (_active) {
 155     _sh->unregister_strong_roots_scope(this);
 156   }
 157 }
 158 
 159 Monitor* SharedHeap::StrongRootsScope::_lock = new Monitor(Mutex::leaf, "StrongRootsScope lock", false);
 160 
 161 void SharedHeap::StrongRootsScope::mark_worker_done_with_threads(uint n_workers) {
 162 #if INCLUDE_ALL_GCS
 163   // The Thread work barrier is only needed by G1 Class Unloading.
 164   // No need to use the barrier if this is single-threaded code.
 165   if (UseG1GC && G1ClassUnloadingEnabled && n_workers > 0) {
 166     uint new_value = (uint)Atomic::add(1, &_n_workers_done_with_threads);
 167     if (new_value == n_workers) {
 168       // This thread is last. Notify the others.
 169       MonitorLockerEx ml(_lock, Mutex::_no_safepoint_check_flag);
 170       _lock->notify_all();
 171     }
 172   }
 173 #endif
 174 }
 175 
 176 void SharedHeap::StrongRootsScope::wait_until_all_workers_done_with_threads(uint n_workers) {
 177 #if INCLUDE_ALL_GCS
 178   assert(UseG1GC,                 "Currently only used by G1");
 179   assert(G1ClassUnloadingEnabled, "Currently only needed when doing G1 Class Unloading");
 180 
 181   // No need to use the barrier if this is single-threaded code.
 182   if (n_workers > 0 && (uint)_n_workers_done_with_threads != n_workers) {
 183     MonitorLockerEx ml(_lock, Mutex::_no_safepoint_check_flag);
 184     while ((uint)_n_workers_done_with_threads != n_workers) {
 185       _lock->wait(Mutex::_no_safepoint_check_flag, 0, false);
 186     }
 187   }
 188 #endif
 189 }
 190 
 191 void SharedHeap::process_roots(bool activate_scope,
 192                                ScanningOption so,
 193                                OopClosure* strong_roots,
 194                                OopClosure* weak_roots,
 195                                CLDClosure* strong_cld_closure,
 196                                CLDClosure* weak_cld_closure,
 197                                CodeBlobClosure* code_roots) {
 198   StrongRootsScope srs(this, activate_scope);
 199 
 200   // General roots.
 201   assert(_strong_roots_parity != 0, "must have called prologue code");
 202   assert(code_roots != NULL, "code root closure should always be set");
 203   // _n_termination for _process_strong_tasks should be set up stream
 204   // in a method not running in a GC worker.  Otherwise the GC worker
 205   // could be trying to change the termination condition while the task
 206   // is executing in another GC worker.
 207 
 208   // Iterating over the CLDG and the Threads are done early to allow G1 to