< prev index next >

src/hotspot/share/runtime/safepoint.cpp

Print this page
rev 50896 : 8206003: SafepointSynchronize with TLH: StoreStore barriers should be moved out of the loop
Reviewed-by: eosterlund, rehn, dholmes


 226   //  3. Running compiled Code
 227   //     Compiled code reads a global (Safepoint Polling) page that
 228   //     is set to fault if we are trying to get to a safepoint.
 229   //  4. Blocked
 230   //     A thread which is blocked will not be allowed to return from the
 231   //     block condition until the safepoint operation is complete.
 232   //  5. In VM or Transitioning between states
 233   //     If a Java thread is currently running in the VM or transitioning
 234   //     between states, the safepointing code will wait for the thread to
 235   //     block itself when it attempts transitions to a new state.
 236   //
 237   {
 238     EventSafepointStateSynchronization sync_event;
 239     int initial_running = 0;
 240 
 241     _state            = _synchronizing;
 242 
 243     if (SafepointMechanism::uses_thread_local_poll()) {
 244       // Arming the per thread poll while having _state != _not_synchronized means safepointing
 245       log_trace(safepoint)("Setting thread local yield flag for threads");

 246       for (JavaThreadIteratorWithHandle jtiwh; JavaThread *cur = jtiwh.next(); ) {
 247         // Make sure the threads start polling, it is time to yield.
 248         SafepointMechanism::arm_local_poll(cur); // release store, global state -> local state
 249       }
 250     }
 251     OrderAccess::fence(); // storestore|storeload, global state -> local state
 252 
 253     // Flush all thread states to memory
 254     if (!UseMembar) {
 255       os::serialize_thread_states();
 256     }
 257 
 258     if (SafepointMechanism::uses_global_page_poll()) {
 259       // Make interpreter safepoint aware
 260       Interpreter::notice_safepoints();
 261 
 262       // Make polling safepoint aware
 263       guarantee (PageArmed == 0, "invariant") ;
 264       PageArmed = 1 ;
 265       os::make_polling_page_unreadable();
 266     }
 267 
 268     // Consider using active_processor_count() ... but that call is expensive.


 529       PageArmed = 0 ;
 530     }
 531 
 532     if (SafepointMechanism::uses_global_page_poll()) {
 533       // Remove safepoint check from interpreter
 534       Interpreter::ignore_safepoints();
 535     }
 536 
 537     {
 538       MutexLocker mu(Safepoint_lock);
 539 
 540       assert(_state == _synchronized, "must be synchronized before ending safepoint synchronization");
 541 
 542       if (SafepointMechanism::uses_thread_local_poll()) {
 543         _state = _not_synchronized;
 544         OrderAccess::storestore(); // global state -> local state
 545         jtiwh.rewind();
 546         for (; JavaThread *current = jtiwh.next(); ) {
 547           ThreadSafepointState* cur_state = current->safepoint_state();
 548           cur_state->restart(); // TSS _running
 549           SafepointMechanism::disarm_local_poll(current); // release store, local state -> polling page
 550         }
 551         log_info(safepoint)("Leaving safepoint region");
 552       } else {
 553         // Set to not synchronized, so the threads will not go into the signal_thread_blocked method
 554         // when they get restarted.
 555         _state = _not_synchronized;
 556         OrderAccess::fence();
 557 
 558         log_info(safepoint)("Leaving safepoint region");
 559 
 560         // Start suspended threads
 561         jtiwh.rewind();
 562         for (; JavaThread *current = jtiwh.next(); ) {
 563           // A problem occurring on Solaris is when attempting to restart threads
 564           // the first #cpus - 1 go well, but then the VMThread is preempted when we get
 565           // to the next one (since it has been running the longest).  We then have
 566           // to wait for a cpu to become available before we can continue restarting
 567           // threads.
 568           // FIXME: This causes the performance of the VM to degrade when active and with
 569           // large numbers of threads.  Apparently this is due to the synchronous nature




 226   //  3. Running compiled Code
 227   //     Compiled code reads a global (Safepoint Polling) page that
 228   //     is set to fault if we are trying to get to a safepoint.
 229   //  4. Blocked
 230   //     A thread which is blocked will not be allowed to return from the
 231   //     block condition until the safepoint operation is complete.
 232   //  5. In VM or Transitioning between states
 233   //     If a Java thread is currently running in the VM or transitioning
 234   //     between states, the safepointing code will wait for the thread to
 235   //     block itself when it attempts transitions to a new state.
 236   //
 237   {
 238     EventSafepointStateSynchronization sync_event;
 239     int initial_running = 0;
 240 
 241     _state            = _synchronizing;
 242 
 243     if (SafepointMechanism::uses_thread_local_poll()) {
 244       // Arming the per thread poll while having _state != _not_synchronized means safepointing
 245       log_trace(safepoint)("Setting thread local yield flag for threads");
 246       OrderAccess::storestore(); // storestore, global state -> local state
 247       for (JavaThreadIteratorWithHandle jtiwh; JavaThread *cur = jtiwh.next(); ) {
 248         // Make sure the threads start polling, it is time to yield.
 249         SafepointMechanism::arm_local_poll(cur);
 250       }
 251     }
 252     OrderAccess::fence(); // storestore|storeload, global state -> local state
 253 
 254     // Flush all thread states to memory
 255     if (!UseMembar) {
 256       os::serialize_thread_states();
 257     }
 258 
 259     if (SafepointMechanism::uses_global_page_poll()) {
 260       // Make interpreter safepoint aware
 261       Interpreter::notice_safepoints();
 262 
 263       // Make polling safepoint aware
 264       guarantee (PageArmed == 0, "invariant") ;
 265       PageArmed = 1 ;
 266       os::make_polling_page_unreadable();
 267     }
 268 
 269     // Consider using active_processor_count() ... but that call is expensive.


 530       PageArmed = 0 ;
 531     }
 532 
 533     if (SafepointMechanism::uses_global_page_poll()) {
 534       // Remove safepoint check from interpreter
 535       Interpreter::ignore_safepoints();
 536     }
 537 
 538     {
 539       MutexLocker mu(Safepoint_lock);
 540 
 541       assert(_state == _synchronized, "must be synchronized before ending safepoint synchronization");
 542 
 543       if (SafepointMechanism::uses_thread_local_poll()) {
 544         _state = _not_synchronized;
 545         OrderAccess::storestore(); // global state -> local state
 546         jtiwh.rewind();
 547         for (; JavaThread *current = jtiwh.next(); ) {
 548           ThreadSafepointState* cur_state = current->safepoint_state();
 549           cur_state->restart(); // TSS _running
 550           SafepointMechanism::disarm_local_poll(current);
 551         }
 552         log_info(safepoint)("Leaving safepoint region");
 553       } else {
 554         // Set to not synchronized, so the threads will not go into the signal_thread_blocked method
 555         // when they get restarted.
 556         _state = _not_synchronized;
 557         OrderAccess::fence();
 558 
 559         log_info(safepoint)("Leaving safepoint region");
 560 
 561         // Start suspended threads
 562         jtiwh.rewind();
 563         for (; JavaThread *current = jtiwh.next(); ) {
 564           // A problem occurring on Solaris is when attempting to restart threads
 565           // the first #cpus - 1 go well, but then the VMThread is preempted when we get
 566           // to the next one (since it has been running the longest).  We then have
 567           // to wait for a cpu to become available before we can continue restarting
 568           // threads.
 569           // FIXME: This causes the performance of the VM to degrade when active and with
 570           // large numbers of threads.  Apparently this is due to the synchronous nature


< prev index next >