hotspot/src/share/vm/runtime/safepoint.cpp
changeset 33763 cec2333f839c
parent 33589 7cbd1b2c139b
child 34666 1c7168ea0034
equal deleted inserted replaced
33756:fc1eddc092e7 33763:cec2333f839c
    31 #include "code/pcDesc.hpp"
    31 #include "code/pcDesc.hpp"
    32 #include "code/scopeDesc.hpp"
    32 #include "code/scopeDesc.hpp"
    33 #include "gc/shared/collectedHeap.hpp"
    33 #include "gc/shared/collectedHeap.hpp"
    34 #include "gc/shared/gcLocker.inline.hpp"
    34 #include "gc/shared/gcLocker.inline.hpp"
    35 #include "interpreter/interpreter.hpp"
    35 #include "interpreter/interpreter.hpp"
       
    36 #include "logging/log.hpp"
    36 #include "memory/resourceArea.hpp"
    37 #include "memory/resourceArea.hpp"
    37 #include "memory/universe.inline.hpp"
    38 #include "memory/universe.inline.hpp"
    38 #include "oops/oop.inline.hpp"
    39 #include "oops/oop.inline.hpp"
    39 #include "oops/symbol.hpp"
    40 #include "oops/symbol.hpp"
    40 #include "runtime/atomic.inline.hpp"
    41 #include "runtime/atomic.inline.hpp"
   102 
   103 
   103   assert( _state == _not_synchronized, "trying to safepoint synchronize with wrong state");
   104   assert( _state == _not_synchronized, "trying to safepoint synchronize with wrong state");
   104 
   105 
   105   int nof_threads = Threads::number_of_threads();
   106   int nof_threads = Threads::number_of_threads();
   106 
   107 
   107   if (TraceSafepoint) {
   108   log_debug(safepoint)("Safepoint synchronization initiated. (%d)", nof_threads);
   108     tty->print_cr("Safepoint synchronization initiated. (%d)", nof_threads);
       
   109   }
       
   110 
   109 
   111   RuntimeService::record_safepoint_begin();
   110   RuntimeService::record_safepoint_begin();
   112 
   111 
   113   MutexLocker mu(Safepoint_lock);
   112   MutexLocker mu(Safepoint_lock);
   114 
   113 
   217            //   steps -= NNN
   216            //   steps -= NNN
   218            //   steps >>= 1
   217            //   steps >>= 1
   219            //   steps = MIN(steps, 2000-100)
   218            //   steps = MIN(steps, 2000-100)
   220            //   if (iterations != 0) steps -= NNN
   219            //   if (iterations != 0) steps -= NNN
   221         }
   220         }
   222         if (TraceSafepoint && Verbose) cur_state->print();
   221         if (log_is_enabled(Trace, safepoint)) {
       
   222           ResourceMark rm;
       
   223           cur_state->print_on(LogHandle(safepoint)::debug_stream());
       
   224         }
   223       }
   225       }
   224     }
   226     }
   225 
   227 
   226     if (PrintSafepointStatistics && iterations == 0) {
   228     if (PrintSafepointStatistics && iterations == 0) {
   227       begin_statistics(nof_threads, still_running);
   229       begin_statistics(nof_threads, still_running);
   314     update_statistics_on_spin_end();
   316     update_statistics_on_spin_end();
   315   }
   317   }
   316 
   318 
   317   // wait until all threads are stopped
   319   // wait until all threads are stopped
   318   while (_waiting_to_block > 0) {
   320   while (_waiting_to_block > 0) {
   319     if (TraceSafepoint) tty->print_cr("Waiting for %d thread(s) to block", _waiting_to_block);
   321     log_debug(safepoint)("Waiting for %d thread(s) to block", _waiting_to_block);
   320     if (!SafepointTimeout || timeout_error_printed) {
   322     if (!SafepointTimeout || timeout_error_printed) {
   321       Safepoint_lock->wait(true);  // true, means with no safepoint checks
   323       Safepoint_lock->wait(true);  // true, means with no safepoint checks
   322     } else {
   324     } else {
   323       // Compute remaining time
   325       // Compute remaining time
   324       jlong remaining_time = safepoint_limit_time - os::javaTimeNanos();
   326       jlong remaining_time = safepoint_limit_time - os::javaTimeNanos();
   360 #endif // ASSERT
   362 #endif // ASSERT
   361 
   363 
   362   // Update the count of active JNI critical regions
   364   // Update the count of active JNI critical regions
   363   GC_locker::set_jni_lock_count(_current_jni_active_count);
   365   GC_locker::set_jni_lock_count(_current_jni_active_count);
   364 
   366 
   365   if (TraceSafepoint) {
   367   if (log_is_enabled(Debug, safepoint)) {
   366     VM_Operation *op = VMThread::vm_operation();
   368     VM_Operation *op = VMThread::vm_operation();
   367     tty->print_cr("Entering safepoint region: %s", (op != NULL) ? op->name() : "no vm operation");
   369     log_debug(safepoint)("Entering safepoint region: %s",
       
   370                          (op != NULL) ? op->name() : "no vm operation");
   368   }
   371   }
   369 
   372 
   370   RuntimeService::record_safepoint_synchronized();
   373   RuntimeService::record_safepoint_synchronized();
   371   if (PrintSafepointStatistics) {
   374   if (PrintSafepointStatistics) {
   372     update_statistics_on_sync_end(os::javaTimeNanos());
   375     update_statistics_on_sync_end(os::javaTimeNanos());
   426     // Set to not synchronized, so the threads will not go into the signal_thread_blocked method
   429     // Set to not synchronized, so the threads will not go into the signal_thread_blocked method
   427     // when they get restarted.
   430     // when they get restarted.
   428     _state = _not_synchronized;
   431     _state = _not_synchronized;
   429     OrderAccess::fence();
   432     OrderAccess::fence();
   430 
   433 
   431     if (TraceSafepoint) {
   434     log_debug(safepoint)("Leaving safepoint region");
   432        tty->print_cr("Leaving safepoint region");
       
   433     }
       
   434 
   435 
   435     // Start suspended threads
   436     // Start suspended threads
   436     for(JavaThread *current = Threads::first(); current; current = current->next()) {
   437     for(JavaThread *current = Threads::first(); current; current = current->next()) {
   437       // A problem occurring on Solaris is when attempting to restart threads
   438       // A problem occurring on Solaris is when attempting to restart threads
   438       // the first #cpus - 1 go well, but then the VMThread is preempted when we get
   439       // the first #cpus - 1 go well, but then the VMThread is preempted when we get
   917                _at_poll_safepoint);
   918                _at_poll_safepoint);
   918 
   919 
   919   _thread->print_thread_state_on(st);
   920   _thread->print_thread_state_on(st);
   920 }
   921 }
   921 
   922 
   922 
       
   923 // ---------------------------------------------------------------------------------------------------------------------
   923 // ---------------------------------------------------------------------------------------------------------------------
   924 
   924 
   925 // Block the thread at the safepoint poll or poll return.
   925 // Block the thread at the safepoint poll or poll return.
   926 void ThreadSafepointState::handle_polling_page_exception() {
   926 void ThreadSafepointState::handle_polling_page_exception() {
   927 
   927