src/hotspot/share/gc/g1/g1ConcurrentMarkThread.cpp
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 54756 845f5a35241b
child 58679 9c3209ff7550
equal deleted inserted replaced
58677:13588c901957 58678:9cf78a70fa4f
    29 #include "gc/g1/g1ConcurrentMark.inline.hpp"
    29 #include "gc/g1/g1ConcurrentMark.inline.hpp"
    30 #include "gc/g1/g1ConcurrentMarkThread.inline.hpp"
    30 #include "gc/g1/g1ConcurrentMarkThread.inline.hpp"
    31 #include "gc/g1/g1MMUTracker.hpp"
    31 #include "gc/g1/g1MMUTracker.hpp"
    32 #include "gc/g1/g1Policy.hpp"
    32 #include "gc/g1/g1Policy.hpp"
    33 #include "gc/g1/g1RemSet.hpp"
    33 #include "gc/g1/g1RemSet.hpp"
       
    34 #include "gc/g1/g1Trace.hpp"
    34 #include "gc/g1/g1VMOperations.hpp"
    35 #include "gc/g1/g1VMOperations.hpp"
    35 #include "gc/shared/concurrentGCPhaseManager.hpp"
    36 #include "gc/shared/concurrentGCPhaseManager.hpp"
    36 #include "gc/shared/gcId.hpp"
    37 #include "gc/shared/gcId.hpp"
    37 #include "gc/shared/gcTrace.hpp"
       
    38 #include "gc/shared/gcTraceTime.inline.hpp"
    38 #include "gc/shared/gcTraceTime.inline.hpp"
    39 #include "gc/shared/suspendibleThreadSet.hpp"
    39 #include "gc/shared/suspendibleThreadSet.hpp"
    40 #include "logging/log.hpp"
    40 #include "logging/log.hpp"
    41 #include "memory/resourceArea.hpp"
    41 #include "memory/resourceArea.hpp"
    42 #include "runtime/handles.inline.hpp"
    42 #include "runtime/handles.inline.hpp"
   105   void do_void(){
   105   void do_void(){
   106     _cm->cleanup();
   106     _cm->cleanup();
   107   }
   107   }
   108 };
   108 };
   109 
   109 
   110 double G1ConcurrentMarkThread::mmu_sleep_time(G1Policy* g1_policy, bool remark) {
   110 double G1ConcurrentMarkThread::mmu_delay_end(G1Policy* g1_policy, bool remark) {
   111   // There are 3 reasons to use SuspendibleThreadSetJoiner.
   111   // There are 3 reasons to use SuspendibleThreadSetJoiner.
   112   // 1. To avoid concurrency problem.
   112   // 1. To avoid concurrency problem.
   113   //    - G1MMUTracker::add_pause(), when_sec() and its variation(when_ms() etc..) can be called
   113   //    - G1MMUTracker::add_pause(), when_sec() and its variation(when_ms() etc..) can be called
   114   //      concurrently from ConcurrentMarkThread and VMThread.
   114   //      concurrently from ConcurrentMarkThread and VMThread.
   115   // 2. If currently a gc is running, but it has not yet updated the MMU,
   115   // 2. If currently a gc is running, but it has not yet updated the MMU,
   117   // 3. If currently a gc is running, ConcurrentMarkThread will wait it to be finished.
   117   // 3. If currently a gc is running, ConcurrentMarkThread will wait it to be finished.
   118   //    And then sleep for predicted amount of time by delay_to_keep_mmu().
   118   //    And then sleep for predicted amount of time by delay_to_keep_mmu().
   119   SuspendibleThreadSetJoiner sts_join;
   119   SuspendibleThreadSetJoiner sts_join;
   120 
   120 
   121   const G1Analytics* analytics = g1_policy->analytics();
   121   const G1Analytics* analytics = g1_policy->analytics();
   122   double now = os::elapsedTime();
       
   123   double prediction_ms = remark ? analytics->predict_remark_time_ms()
   122   double prediction_ms = remark ? analytics->predict_remark_time_ms()
   124                                 : analytics->predict_cleanup_time_ms();
   123                                 : analytics->predict_cleanup_time_ms();
       
   124   double prediction = prediction_ms / MILLIUNITS;
   125   G1MMUTracker *mmu_tracker = g1_policy->mmu_tracker();
   125   G1MMUTracker *mmu_tracker = g1_policy->mmu_tracker();
   126   return mmu_tracker->when_ms(now, prediction_ms);
   126   double now = os::elapsedTime();
       
   127   return now + mmu_tracker->when_sec(now, prediction);
   127 }
   128 }
   128 
   129 
   129 void G1ConcurrentMarkThread::delay_to_keep_mmu(G1Policy* g1_policy, bool remark) {
   130 void G1ConcurrentMarkThread::delay_to_keep_mmu(G1Policy* g1_policy, bool remark) {
   130   if (g1_policy->use_adaptive_young_list_length()) {
   131   if (g1_policy->use_adaptive_young_list_length()) {
   131     jlong sleep_time_ms = mmu_sleep_time(g1_policy, remark);
   132     double delay_end_sec = mmu_delay_end(g1_policy, remark);
   132     if (!_cm->has_aborted() && sleep_time_ms > 0) {
   133     // Wait for timeout or thread termination request.
   133       os::sleep(this, sleep_time_ms, false);
   134     MonitorLocker ml(CGC_lock, Monitor::_no_safepoint_check_flag);
       
   135     while (!_cm->has_aborted()) {
       
   136       double sleep_time_sec = (delay_end_sec - os::elapsedTime());
       
   137       jlong sleep_time_ms = ceil(sleep_time_sec * MILLIUNITS);
       
   138       if (sleep_time_ms <= 0) {
       
   139         break;                  // Passed end time.
       
   140       } else if (ml.wait(sleep_time_ms, Monitor::_no_safepoint_check_flag)) {
       
   141         break;                  // Timeout => reached end time.
       
   142       } else if (should_terminate()) {
       
   143         break;                  // Wakeup for pending termination request.
       
   144       }
       
   145       // Other (possibly spurious) wakeup.  Retry with updated sleep time.
   134     }
   146     }
   135   }
   147   }
   136 }
   148 }
   137 
   149 
   138 class G1ConcPhaseTimer : public GCTraceConcTimeImpl<LogLevel::Info, LOG_TAGS(gc, marking)> {
   150 class G1ConcPhaseTimer : public GCTraceConcTimeImpl<LogLevel::Info, LOG_TAGS(gc, marking)> {
   266       HandleMark   hm;
   278       HandleMark   hm;
   267       double cycle_start = os::elapsedVTime();
   279       double cycle_start = os::elapsedVTime();
   268 
   280 
   269       {
   281       {
   270         G1ConcPhase p(G1ConcurrentPhase::CLEAR_CLAIMED_MARKS, this);
   282         G1ConcPhase p(G1ConcurrentPhase::CLEAR_CLAIMED_MARKS, this);
   271         MutexLocker ml(ClassLoaderDataGraph_lock);
       
   272         ClassLoaderDataGraph::clear_claimed_marks();
   283         ClassLoaderDataGraph::clear_claimed_marks();
   273       }
   284       }
   274 
   285 
   275       // We have to ensure that we finish scanning the root regions
   286       // We have to ensure that we finish scanning the root regions
   276       // before the next GC takes place. To ensure this we have to
   287       // before the next GC takes place. To ensure this we have to