< prev index next >

src/share/vm/gc/g1/concurrentMarkThread.cpp

Print this page




  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "gc/g1/concurrentMarkThread.inline.hpp"
  27 #include "gc/g1/g1CollectedHeap.inline.hpp"
  28 #include "gc/g1/g1CollectorPolicy.hpp"
  29 #include "gc/g1/g1Log.hpp"
  30 #include "gc/g1/g1MMUTracker.hpp"
  31 #include "gc/g1/suspendibleThreadSet.hpp"
  32 #include "gc/g1/vm_operations_g1.hpp"

  33 #include "gc/shared/gcTrace.hpp"
  34 #include "memory/resourceArea.hpp"
  35 #include "runtime/vmThread.hpp"
  36 
  37 // ======= Concurrent Mark Thread ========
  38 
  39 // The CM thread is created when the G1 garbage collector is used
  40 
  41 SurrogateLockerThread*
  42      ConcurrentMarkThread::_slt = NULL;
  43 
  44 ConcurrentMarkThread::ConcurrentMarkThread(ConcurrentMark* cm) :
  45   ConcurrentGCThread(),
  46   _cm(cm),
  47   _state(Idle),
  48   _vtime_accum(0.0),
  49   _vtime_mark_accum(0.0) {
  50 
  51   set_name("G1 Main Marker");
  52   create_and_start();


  68 class CMCleanUp: public VoidClosure {
  69   ConcurrentMark* _cm;
  70 public:
  71 
  72   CMCleanUp(ConcurrentMark* cm) :
  73     _cm(cm) {}
  74 
  75   void do_void(){
  76     _cm->cleanup();
  77   }
  78 };
  79 
  80 // We want to avoid that the logging from the concurrent thread is mixed
  81 // with the logging from a STW GC. So, if necessary join the STS to ensure
  82 // that the logging is done either before or after the STW logging.
  83 void ConcurrentMarkThread::cm_log(bool doit, bool join_sts, const char* fmt, ...) {
  84   if (doit) {
  85     SuspendibleThreadSetJoiner sts_joiner(join_sts);
  86     va_list args;
  87     va_start(args, fmt);
  88     gclog_or_tty->gclog_stamp(cm()->concurrent_gc_id());
  89     gclog_or_tty->vprint_cr(fmt, args);
  90     va_end(args);
  91   }
  92 }
  93 
  94 void ConcurrentMarkThread::run() {
  95   initialize_in_thread();
  96   _vtime_start = os::elapsedVTime();
  97   wait_for_universe_init();
  98 
  99   G1CollectedHeap* g1h = G1CollectedHeap::heap();
 100   G1CollectorPolicy* g1_policy = g1h->g1_policy();
 101   G1MMUTracker *mmu_tracker = g1_policy->mmu_tracker();
 102   Thread *current_thread = Thread::current();
 103 
 104   while (!_should_terminate) {
 105     // wait until started is set.
 106     sleepBeforeNextCycle();
 107     if (_should_terminate) {
 108       break;
 109     }
 110 

 111     {
 112       ResourceMark rm;
 113       HandleMark   hm;
 114       double cycle_start = os::elapsedVTime();
 115 
 116       // We have to ensure that we finish scanning the root regions
 117       // before the next GC takes place. To ensure this we have to
 118       // make sure that we do not join the STS until the root regions
 119       // have been scanned. If we did then it's possible that a
 120       // subsequent GC could block us from joining the STS and proceed
 121       // without the root regions have been scanned which would be a
 122       // correctness issue.
 123 
 124       if (!cm()->has_aborted()) {
 125         _cm->scanRootRegions();
 126       }
 127 
 128       double mark_start_sec = os::elapsedTime();
 129       cm_log(G1Log::fine(), true, "[GC concurrent-mark-start]");
 130 




  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "gc/g1/concurrentMarkThread.inline.hpp"
  27 #include "gc/g1/g1CollectedHeap.inline.hpp"
  28 #include "gc/g1/g1CollectorPolicy.hpp"
  29 #include "gc/g1/g1Log.hpp"
  30 #include "gc/g1/g1MMUTracker.hpp"
  31 #include "gc/g1/suspendibleThreadSet.hpp"
  32 #include "gc/g1/vm_operations_g1.hpp"
  33 #include "gc/shared/gcId.hpp"
  34 #include "gc/shared/gcTrace.hpp"
  35 #include "memory/resourceArea.hpp"
  36 #include "runtime/vmThread.hpp"
  37 
  38 // ======= Concurrent Mark Thread ========
  39 
  40 // The CM thread is created when the G1 garbage collector is used
  41 
  42 SurrogateLockerThread*
  43      ConcurrentMarkThread::_slt = NULL;
  44 
  45 ConcurrentMarkThread::ConcurrentMarkThread(ConcurrentMark* cm) :
  46   ConcurrentGCThread(),
  47   _cm(cm),
  48   _state(Idle),
  49   _vtime_accum(0.0),
  50   _vtime_mark_accum(0.0) {
  51 
  52   set_name("G1 Main Marker");
  53   create_and_start();


  69 class CMCleanUp: public VoidClosure {
  70   ConcurrentMark* _cm;
  71 public:
  72 
  73   CMCleanUp(ConcurrentMark* cm) :
  74     _cm(cm) {}
  75 
  76   void do_void(){
  77     _cm->cleanup();
  78   }
  79 };
  80 
  81 // We want to avoid that the logging from the concurrent thread is mixed
  82 // with the logging from a STW GC. So, if necessary join the STS to ensure
  83 // that the logging is done either before or after the STW logging.
  84 void ConcurrentMarkThread::cm_log(bool doit, bool join_sts, const char* fmt, ...) {
  85   if (doit) {
  86     SuspendibleThreadSetJoiner sts_joiner(join_sts);
  87     va_list args;
  88     va_start(args, fmt);
  89     gclog_or_tty->gclog_stamp();
  90     gclog_or_tty->vprint_cr(fmt, args);
  91     va_end(args);
  92   }
  93 }
  94 
  95 void ConcurrentMarkThread::run() {
  96   initialize_in_thread();
  97   _vtime_start = os::elapsedVTime();
  98   wait_for_universe_init();
  99 
 100   G1CollectedHeap* g1h = G1CollectedHeap::heap();
 101   G1CollectorPolicy* g1_policy = g1h->g1_policy();
 102   G1MMUTracker *mmu_tracker = g1_policy->mmu_tracker();
 103   Thread *current_thread = Thread::current();
 104 
 105   while (!_should_terminate) {
 106     // wait until started is set.
 107     sleepBeforeNextCycle();
 108     if (_should_terminate) {
 109       break;
 110     }
 111 
 112     GCIdMark gc_id_mark;
 113     {
 114       ResourceMark rm;
 115       HandleMark   hm;
 116       double cycle_start = os::elapsedVTime();
 117 
 118       // We have to ensure that we finish scanning the root regions
 119       // before the next GC takes place. To ensure this we have to
 120       // make sure that we do not join the STS until the root regions
 121       // have been scanned. If we did then it's possible that a
 122       // subsequent GC could block us from joining the STS and proceed
 123       // without the root regions have been scanned which would be a
 124       // correctness issue.
 125 
 126       if (!cm()->has_aborted()) {
 127         _cm->scanRootRegions();
 128       }
 129 
 130       double mark_start_sec = os::elapsedTime();
 131       cm_log(G1Log::fine(), true, "[GC concurrent-mark-start]");
 132 


< prev index next >