< prev index next >

src/share/vm/runtime/safepoint.cpp

Print this page
rev 12310 : [mq]: gcinterface.patch


  43 #include "runtime/compilationPolicy.hpp"
  44 #include "runtime/deoptimization.hpp"
  45 #include "runtime/frame.inline.hpp"
  46 #include "runtime/interfaceSupport.hpp"
  47 #include "runtime/mutexLocker.hpp"
  48 #include "runtime/orderAccess.inline.hpp"
  49 #include "runtime/osThread.hpp"
  50 #include "runtime/safepoint.hpp"
  51 #include "runtime/signature.hpp"
  52 #include "runtime/stubCodeGenerator.hpp"
  53 #include "runtime/stubRoutines.hpp"
  54 #include "runtime/sweeper.hpp"
  55 #include "runtime/synchronizer.hpp"
  56 #include "runtime/thread.inline.hpp"
  57 #include "runtime/timerTrace.hpp"
  58 #include "services/runtimeService.hpp"
  59 #include "trace/tracing.hpp"
  60 #include "trace/traceMacros.hpp"
  61 #include "utilities/events.hpp"
  62 #include "utilities/macros.hpp"
  63 #if INCLUDE_ALL_GCS
  64 #include "gc/cms/concurrentMarkSweepThread.hpp"
  65 #include "gc/g1/suspendibleThreadSet.hpp"
  66 #endif // INCLUDE_ALL_GCS
  67 #ifdef COMPILER1
  68 #include "c1/c1_globals.hpp"
  69 #endif
  70 
  71 // --------------------------------------------------------------------------------------------------
  72 // Implementation of Safepoint begin/end
  73 
  74 SafepointSynchronize::SynchronizeState volatile SafepointSynchronize::_state = SafepointSynchronize::_not_synchronized;
  75 volatile int  SafepointSynchronize::_waiting_to_block = 0;
  76 volatile int SafepointSynchronize::_safepoint_counter = 0;
  77 int SafepointSynchronize::_current_jni_active_count = 0;
  78 long  SafepointSynchronize::_end_of_last_safepoint = 0;
  79 static volatile int PageArmed = 0 ;        // safepoint polling page is RO|RW vs PROT_NONE
  80 static volatile int TryingToBlock = 0 ;    // proximate value -- for advisory use only
  81 static bool timeout_error_printed = false;
  82 
  83 // Roll all threads forward to a safepoint and suspend them all
  84 void SafepointSynchronize::begin() {
  85   EventSafepointBegin begin_event;
  86   Thread* myThread = Thread::current();
  87   assert(myThread->is_VM_thread(), "Only VM thread may execute a safepoint");
  88 
  89   if (PrintSafepointStatistics || PrintSafepointStatisticsTimeout > 0) {
  90     _safepoint_begin_time = os::javaTimeNanos();
  91     _ts_of_current_safepoint = tty->time_stamp().seconds();
  92   }
  93 
  94 #if INCLUDE_ALL_GCS
  95   if (UseConcMarkSweepGC) {
  96     // In the future we should investigate whether CMS can use the
  97     // more-general mechanism below.  DLD (01/05).
  98     ConcurrentMarkSweepThread::synchronize(false);
  99   } else if (UseG1GC) {
 100     SuspendibleThreadSet::synchronize();
 101   }
 102 #endif // INCLUDE_ALL_GCS
 103 
 104   // By getting the Threads_lock, we assure that no threads are about to start or
 105   // exit. It is released again in SafepointSynchronize::end().
 106   Threads_lock->lock();
 107 
 108   assert( _state == _not_synchronized, "trying to safepoint synchronize with wrong state");
 109 
 110   int nof_threads = Threads::number_of_threads();
 111 
 112   log_debug(safepoint)("Safepoint synchronization initiated. (%d)", nof_threads);
 113 
 114   RuntimeService::record_safepoint_begin();
 115 
 116   MutexLocker mu(Safepoint_lock);
 117 
 118   // Reset the count of active JNI critical threads
 119   _current_jni_active_count = 0;
 120 
 121   // Set number of threads to wait for, before we initiate the callbacks
 122   _waiting_to_block = nof_threads;


 491       // of suspending threads.
 492       //
 493       // TODO-FIXME: the comments above are vestigial and no longer apply.
 494       // Furthermore, using solaris' schedctl in this particular context confers no benefit
 495       if (VMThreadHintNoPreempt) {
 496         os::hint_no_preempt();
 497       }
 498       ThreadSafepointState* cur_state = current->safepoint_state();
 499       assert(cur_state->type() != ThreadSafepointState::_running, "Thread not suspended at safepoint");
 500       cur_state->restart();
 501       assert(cur_state->is_running(), "safepoint state has not been reset");
 502     }
 503 
 504     RuntimeService::record_safepoint_end();
 505 
 506     // Release threads lock, so threads can be created/destroyed again. It will also starts all threads
 507     // blocked in signal_thread_blocked
 508     Threads_lock->unlock();
 509 
 510   }
 511 #if INCLUDE_ALL_GCS
 512   // If there are any concurrent GC threads resume them.
 513   if (UseConcMarkSweepGC) {
 514     ConcurrentMarkSweepThread::desynchronize(false);
 515   } else if (UseG1GC) {
 516     SuspendibleThreadSet::desynchronize();
 517   }
 518 #endif // INCLUDE_ALL_GCS
 519   // record this time so VMThread can keep track how much time has elapsed
 520   // since last safepoint.
 521   _end_of_last_safepoint = os::javaTimeMillis();
 522 
 523   if (event.should_commit()) {
 524     event.set_safepointId(safepoint_id);
 525     event.commit();
 526   }
 527 }
 528 
 529 bool SafepointSynchronize::is_cleanup_needed() {
 530   // Need a safepoint if some inline cache buffers is non-empty
 531   if (!InlineCacheBuffer::is_empty()) return true;
 532   return false;
 533 }
 534 
 535 static void event_safepoint_cleanup_task_commit(EventSafepointCleanupTask& event, const char* name) {
 536   if (event.should_commit()) {
 537     event.set_safepointId(SafepointSynchronize::safepoint_counter());
 538     event.set_name(name);


1022 
1023   // Should only be poll_return or poll
1024   assert( nm->is_at_poll_or_poll_return(real_return_addr), "should not be at call" );
1025 
1026   // This is a poll immediately before a return. The exception handling code
1027   // has already had the effect of causing the return to occur, so the execution
1028   // will continue immediately after the call. In addition, the oopmap at the
1029   // return point does not mark the return value as an oop (if it is), so
1030   // it needs a handle here to be updated.
1031   if( nm->is_at_poll_return(real_return_addr) ) {
1032     // See if return type is an oop.
1033     bool return_oop = nm->method()->is_returning_oop();
1034     Handle return_value;
1035     if (return_oop) {
1036       // The oop result has been saved on the stack together with all
1037       // the other registers. In order to preserve it over GCs we need
1038       // to keep it in a handle.
1039       oop result = caller_fr.saved_oop_result(&map);
1040       assert(result == NULL || result->is_oop(), "must be oop");
1041       return_value = Handle(thread(), result);
1042       assert(Universe::heap()->is_in_or_null(result), "must be heap pointer");
1043     }
1044 
1045     // Block the thread
1046     SafepointSynchronize::block(thread());
1047 
1048     // restore oop result, if any
1049     if (return_oop) {
1050       caller_fr.set_saved_oop_result(&map, return_value());
1051     }
1052   }
1053 
1054   // This is a safepoint poll. Verify the return address and block.
1055   else {
1056     set_at_poll_safepoint(true);
1057 
1058     // verify the blob built the "return address" correctly
1059     assert(real_return_addr == caller_fr.pc(), "must match");
1060 
1061     // Block the thread
1062     SafepointSynchronize::block(thread());




  43 #include "runtime/compilationPolicy.hpp"
  44 #include "runtime/deoptimization.hpp"
  45 #include "runtime/frame.inline.hpp"
  46 #include "runtime/interfaceSupport.hpp"
  47 #include "runtime/mutexLocker.hpp"
  48 #include "runtime/orderAccess.inline.hpp"
  49 #include "runtime/osThread.hpp"
  50 #include "runtime/safepoint.hpp"
  51 #include "runtime/signature.hpp"
  52 #include "runtime/stubCodeGenerator.hpp"
  53 #include "runtime/stubRoutines.hpp"
  54 #include "runtime/sweeper.hpp"
  55 #include "runtime/synchronizer.hpp"
  56 #include "runtime/thread.inline.hpp"
  57 #include "runtime/timerTrace.hpp"
  58 #include "services/runtimeService.hpp"
  59 #include "trace/tracing.hpp"
  60 #include "trace/traceMacros.hpp"
  61 #include "utilities/events.hpp"
  62 #include "utilities/macros.hpp"




  63 #ifdef COMPILER1
  64 #include "c1/c1_globals.hpp"
  65 #endif
  66 
  67 // --------------------------------------------------------------------------------------------------
  68 // Implementation of Safepoint begin/end
  69 
  70 SafepointSynchronize::SynchronizeState volatile SafepointSynchronize::_state = SafepointSynchronize::_not_synchronized;
  71 volatile int  SafepointSynchronize::_waiting_to_block = 0;
  72 volatile int SafepointSynchronize::_safepoint_counter = 0;
  73 int SafepointSynchronize::_current_jni_active_count = 0;
  74 long  SafepointSynchronize::_end_of_last_safepoint = 0;
  75 static volatile int PageArmed = 0 ;        // safepoint polling page is RO|RW vs PROT_NONE
  76 static volatile int TryingToBlock = 0 ;    // proximate value -- for advisory use only
  77 static bool timeout_error_printed = false;
  78 
  79 // Roll all threads forward to a safepoint and suspend them all
  80 void SafepointSynchronize::begin() {
  81   EventSafepointBegin begin_event;
  82   Thread* myThread = Thread::current();
  83   assert(myThread->is_VM_thread(), "Only VM thread may execute a safepoint");
  84 
  85   if (PrintSafepointStatistics || PrintSafepointStatisticsTimeout > 0) {
  86     _safepoint_begin_time = os::javaTimeNanos();
  87     _ts_of_current_safepoint = tty->time_stamp().seconds();
  88   }
  89 
  90   GC::gc()->synchronize_safepoint();








  91 
  92   // By getting the Threads_lock, we assure that no threads are about to start or
  93   // exit. It is released again in SafepointSynchronize::end().
  94   Threads_lock->lock();
  95 
  96   assert( _state == _not_synchronized, "trying to safepoint synchronize with wrong state");
  97 
  98   int nof_threads = Threads::number_of_threads();
  99 
 100   log_debug(safepoint)("Safepoint synchronization initiated. (%d)", nof_threads);
 101 
 102   RuntimeService::record_safepoint_begin();
 103 
 104   MutexLocker mu(Safepoint_lock);
 105 
 106   // Reset the count of active JNI critical threads
 107   _current_jni_active_count = 0;
 108 
 109   // Set number of threads to wait for, before we initiate the callbacks
 110   _waiting_to_block = nof_threads;


 479       // of suspending threads.
 480       //
 481       // TODO-FIXME: the comments above are vestigial and no longer apply.
 482       // Furthermore, using solaris' schedctl in this particular context confers no benefit
 483       if (VMThreadHintNoPreempt) {
 484         os::hint_no_preempt();
 485       }
 486       ThreadSafepointState* cur_state = current->safepoint_state();
 487       assert(cur_state->type() != ThreadSafepointState::_running, "Thread not suspended at safepoint");
 488       cur_state->restart();
 489       assert(cur_state->is_running(), "safepoint state has not been reset");
 490     }
 491 
 492     RuntimeService::record_safepoint_end();
 493 
 494     // Release threads lock, so threads can be created/destroyed again. It will also starts all threads
 495     // blocked in signal_thread_blocked
 496     Threads_lock->unlock();
 497 
 498   }
 499 
 500   GC::gc()->desynchronize_safepoint();
 501 





 502   // record this time so VMThread can keep track how much time has elapsed
 503   // since last safepoint.
 504   _end_of_last_safepoint = os::javaTimeMillis();
 505 
 506   if (event.should_commit()) {
 507     event.set_safepointId(safepoint_id);
 508     event.commit();
 509   }
 510 }
 511 
 512 bool SafepointSynchronize::is_cleanup_needed() {
 513   // Need a safepoint if some inline cache buffers is non-empty
 514   if (!InlineCacheBuffer::is_empty()) return true;
 515   return false;
 516 }
 517 
 518 static void event_safepoint_cleanup_task_commit(EventSafepointCleanupTask& event, const char* name) {
 519   if (event.should_commit()) {
 520     event.set_safepointId(SafepointSynchronize::safepoint_counter());
 521     event.set_name(name);


1005 
1006   // Should only be poll_return or poll
1007   assert( nm->is_at_poll_or_poll_return(real_return_addr), "should not be at call" );
1008 
1009   // This is a poll immediately before a return. The exception handling code
1010   // has already had the effect of causing the return to occur, so the execution
1011   // will continue immediately after the call. In addition, the oopmap at the
1012   // return point does not mark the return value as an oop (if it is), so
1013   // it needs a handle here to be updated.
1014   if( nm->is_at_poll_return(real_return_addr) ) {
1015     // See if return type is an oop.
1016     bool return_oop = nm->method()->is_returning_oop();
1017     Handle return_value;
1018     if (return_oop) {
1019       // The oop result has been saved on the stack together with all
1020       // the other registers. In order to preserve it over GCs we need
1021       // to keep it in a handle.
1022       oop result = caller_fr.saved_oop_result(&map);
1023       assert(result == NULL || result->is_oop(), "must be oop");
1024       return_value = Handle(thread(), result);
1025       assert(GC::gc()->heap()->is_in_or_null(result), "must be heap pointer");
1026     }
1027 
1028     // Block the thread
1029     SafepointSynchronize::block(thread());
1030 
1031     // restore oop result, if any
1032     if (return_oop) {
1033       caller_fr.set_saved_oop_result(&map, return_value());
1034     }
1035   }
1036 
1037   // This is a safepoint poll. Verify the return address and block.
1038   else {
1039     set_at_poll_safepoint(true);
1040 
1041     // verify the blob built the "return address" correctly
1042     assert(real_return_addr == caller_fr.pc(), "must match");
1043 
1044     // Block the thread
1045     SafepointSynchronize::block(thread());


< prev index next >