33
34 // ======= Concurrent Mark Thread ========
35
36 // The CM thread is created when the G1 garbage collector is used
37
38 SurrogateLockerThread*
39 ConcurrentMarkThread::_slt = NULL;
40
41 ConcurrentMarkThread::ConcurrentMarkThread(ConcurrentMark* cm) :
42 ConcurrentGCThread(),
43 _cm(cm),
44 _started(false),
45 _in_progress(false),
46 _vtime_accum(0.0),
47 _vtime_mark_accum(0.0),
48 _vtime_count_accum(0.0)
49 {
50 create_and_start();
51 }
52
53 class CMCheckpointRootsInitialClosure: public VoidClosure {
54
55 ConcurrentMark* _cm;
56 public:
57
58 CMCheckpointRootsInitialClosure(ConcurrentMark* cm) :
59 _cm(cm) {}
60
61 void do_void(){
62 _cm->checkpointRootsInitial();
63 }
64 };
65
66 class CMCheckpointRootsFinalClosure: public VoidClosure {
67
68 ConcurrentMark* _cm;
69 public:
70
71 CMCheckpointRootsFinalClosure(ConcurrentMark* cm) :
72 _cm(cm) {}
73
74 void do_void(){
75 _cm->checkpointRootsFinal(false); // !clear_all_soft_refs
76 }
77 };
78
79 class CMCleanUp: public VoidClosure {
80 ConcurrentMark* _cm;
81 public:
82
83 CMCleanUp(ConcurrentMark* cm) :
84 _cm(cm) {}
85
97
98 G1CollectedHeap* g1h = G1CollectedHeap::heap();
99 G1CollectorPolicy* g1_policy = g1h->g1_policy();
100 G1MMUTracker *mmu_tracker = g1_policy->mmu_tracker();
101 Thread *current_thread = Thread::current();
102
103 while (!_should_terminate) {
104 // wait until started is set.
105 sleepBeforeNextCycle();
106 {
107 ResourceMark rm;
108 HandleMark hm;
109 double cycle_start = os::elapsedVTime();
110 double mark_start_sec = os::elapsedTime();
111 char verbose_str[128];
112
113 if (PrintGC) {
114 gclog_or_tty->date_stamp(PrintGCDateStamps);
115 gclog_or_tty->stamp(PrintGCTimeStamps);
116 gclog_or_tty->print_cr("[GC concurrent-mark-start]");
117 }
118
119 if (!g1_policy->in_young_gc_mode()) {
120 // this ensures the flag is not set if we bail out of the marking
121 // cycle; normally the flag is cleared immediately after cleanup
122 g1h->set_marking_complete();
123
124 if (g1_policy->adaptive_young_list_length()) {
125 double now = os::elapsedTime();
126 double init_prediction_ms = g1_policy->predict_init_time_ms();
127 jlong sleep_time_ms = mmu_tracker->when_ms(now, init_prediction_ms);
128 os::sleep(current_thread, sleep_time_ms, false);
129 }
130
131 // We don't have to skip here if we've been asked to restart, because
132 // in the worst case we just enqueue a new VM operation to start a
133 // marking. Note that the init operation resets has_aborted()
134 CMCheckpointRootsInitialClosure init_cl(_cm);
135 strcpy(verbose_str, "GC initial-mark");
136 VM_CGC_Operation op(&init_cl, verbose_str);
137 VMThread::execute(&op);
138 }
139
140 int iter = 0;
141 do {
142 iter++;
143 if (!cm()->has_aborted()) {
144 _cm->markFromRoots();
145 }
146
147 double mark_end_time = os::elapsedVTime();
148 double mark_end_sec = os::elapsedTime();
149 _vtime_mark_accum += (mark_end_time - cycle_start);
150 if (!cm()->has_aborted()) {
151 if (g1_policy->adaptive_young_list_length()) {
152 double now = os::elapsedTime();
153 double remark_prediction_ms = g1_policy->predict_remark_time_ms();
154 jlong sleep_time_ms = mmu_tracker->when_ms(now, remark_prediction_ms);
155 os::sleep(current_thread, sleep_time_ms, false);
156 }
157
|
33
34 // ======= Concurrent Mark Thread ========
35
36 // The CM thread is created when the G1 garbage collector is used
37
38 SurrogateLockerThread*
39 ConcurrentMarkThread::_slt = NULL;
40
41 ConcurrentMarkThread::ConcurrentMarkThread(ConcurrentMark* cm) :
42 ConcurrentGCThread(),
43 _cm(cm),
44 _started(false),
45 _in_progress(false),
46 _vtime_accum(0.0),
47 _vtime_mark_accum(0.0),
48 _vtime_count_accum(0.0)
49 {
50 create_and_start();
51 }
52
53 class CMCheckpointRootsFinalClosure: public VoidClosure {
54
55 ConcurrentMark* _cm;
56 public:
57
58 CMCheckpointRootsFinalClosure(ConcurrentMark* cm) :
59 _cm(cm) {}
60
61 void do_void(){
62 _cm->checkpointRootsFinal(false); // !clear_all_soft_refs
63 }
64 };
65
66 class CMCleanUp: public VoidClosure {
67 ConcurrentMark* _cm;
68 public:
69
70 CMCleanUp(ConcurrentMark* cm) :
71 _cm(cm) {}
72
84
85 G1CollectedHeap* g1h = G1CollectedHeap::heap();
86 G1CollectorPolicy* g1_policy = g1h->g1_policy();
87 G1MMUTracker *mmu_tracker = g1_policy->mmu_tracker();
88 Thread *current_thread = Thread::current();
89
90 while (!_should_terminate) {
91 // wait until started is set.
92 sleepBeforeNextCycle();
93 {
94 ResourceMark rm;
95 HandleMark hm;
96 double cycle_start = os::elapsedVTime();
97 double mark_start_sec = os::elapsedTime();
98 char verbose_str[128];
99
100 if (PrintGC) {
101 gclog_or_tty->date_stamp(PrintGCDateStamps);
102 gclog_or_tty->stamp(PrintGCTimeStamps);
103 gclog_or_tty->print_cr("[GC concurrent-mark-start]");
104 }
105
106 int iter = 0;
107 do {
108 iter++;
109 if (!cm()->has_aborted()) {
110 _cm->markFromRoots();
111 }
112
113 double mark_end_time = os::elapsedVTime();
114 double mark_end_sec = os::elapsedTime();
115 _vtime_mark_accum += (mark_end_time - cycle_start);
116 if (!cm()->has_aborted()) {
117 if (g1_policy->adaptive_young_list_length()) {
118 double now = os::elapsedTime();
119 double remark_prediction_ms = g1_policy->predict_remark_time_ms();
120 jlong sleep_time_ms = mmu_tracker->when_ms(now, remark_prediction_ms);
121 os::sleep(current_thread, sleep_time_ms, false);
122 }
123
|