27 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
28 #include "gc_implementation/g1/g1CollectorPolicy.hpp"
29 #include "gc_implementation/g1/g1MMUTracker.hpp"
30 #include "gc_implementation/g1/vm_operations_g1.hpp"
31 #include "memory/resourceArea.hpp"
32 #include "runtime/vmThread.hpp"
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:
131 CMCheckpointRootsFinalClosure final_cl(_cm);
132 sprintf(verbose_str, "GC remark");
133 VM_CGC_Operation op(&final_cl, verbose_str);
134 VMThread::execute(&op);
135 }
136 if (cm()->restart_for_overflow() &&
137 G1TraceMarkStackOverflow) {
138 gclog_or_tty->print_cr("Restarting conc marking because of MS overflow "
139 "in remark (restart #%d).", iter);
140 }
141
142 if (cm()->restart_for_overflow()) {
143 if (PrintGC) {
144 gclog_or_tty->date_stamp(PrintGCDateStamps);
145 gclog_or_tty->stamp(PrintGCTimeStamps);
146 gclog_or_tty->print_cr("[GC concurrent-mark-restart-for-overflow]");
147 }
148 }
149 } while (cm()->restart_for_overflow());
150
151 double counting_start_time = os::elapsedVTime();
152 if (!cm()->has_aborted()) {
153 double count_start_sec = os::elapsedTime();
154 if (PrintGC) {
155 gclog_or_tty->date_stamp(PrintGCDateStamps);
156 gclog_or_tty->stamp(PrintGCTimeStamps);
157 gclog_or_tty->print_cr("[GC concurrent-count-start]");
158 }
159
160 _sts.join();
161 _cm->calcDesiredRegions();
162 _sts.leave();
163
164 if (!cm()->has_aborted()) {
165 double count_end_sec = os::elapsedTime();
166 if (PrintGC) {
167 gclog_or_tty->date_stamp(PrintGCDateStamps);
168 gclog_or_tty->stamp(PrintGCTimeStamps);
169 gclog_or_tty->print_cr("[GC concurrent-count-end, %1.7lf]",
170 count_end_sec - count_start_sec);
171 }
172 }
173 }
174
175 double end_time = os::elapsedVTime();
176 _vtime_count_accum += (end_time - counting_start_time);
177 // Update the total virtual time before doing this, since it will try
178 // to measure it to get the vtime for this marking. We purposely
179 // neglect the presumably-short "completeCleanup" phase here.
180 _vtime_accum = (end_time - _vtime_start);
181 if (!cm()->has_aborted()) {
182 if (g1_policy->adaptive_young_list_length()) {
183 double now = os::elapsedTime();
184 double cleanup_prediction_ms = g1_policy->predict_cleanup_time_ms();
185 jlong sleep_time_ms = mmu_tracker->when_ms(now, cleanup_prediction_ms);
186 os::sleep(current_thread, sleep_time_ms, false);
187 }
188
189 CMCleanUp cl_cl(_cm);
190 sprintf(verbose_str, "GC cleanup");
191 VM_CGC_Operation op(&cl_cl, verbose_str);
192 VMThread::execute(&op);
193 } else {
194 // We don't want to update the marking status if a GC pause
195 // is already underway.
196 _sts.join();
197 g1h->set_marking_complete();
198 _sts.leave();
199 }
200
|
27 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
28 #include "gc_implementation/g1/g1CollectorPolicy.hpp"
29 #include "gc_implementation/g1/g1MMUTracker.hpp"
30 #include "gc_implementation/g1/vm_operations_g1.hpp"
31 #include "memory/resourceArea.hpp"
32 #include "runtime/vmThread.hpp"
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 {
49 create_and_start();
50 }
51
52 class CMCheckpointRootsFinalClosure: public VoidClosure {
53
54 ConcurrentMark* _cm;
55 public:
56
57 CMCheckpointRootsFinalClosure(ConcurrentMark* cm) :
58 _cm(cm) {}
59
60 void do_void(){
61 _cm->checkpointRootsFinal(false); // !clear_all_soft_refs
62 }
63 };
64
65 class CMCleanUp: public VoidClosure {
66 ConcurrentMark* _cm;
67 public:
130 CMCheckpointRootsFinalClosure final_cl(_cm);
131 sprintf(verbose_str, "GC remark");
132 VM_CGC_Operation op(&final_cl, verbose_str);
133 VMThread::execute(&op);
134 }
135 if (cm()->restart_for_overflow() &&
136 G1TraceMarkStackOverflow) {
137 gclog_or_tty->print_cr("Restarting conc marking because of MS overflow "
138 "in remark (restart #%d).", iter);
139 }
140
141 if (cm()->restart_for_overflow()) {
142 if (PrintGC) {
143 gclog_or_tty->date_stamp(PrintGCDateStamps);
144 gclog_or_tty->stamp(PrintGCTimeStamps);
145 gclog_or_tty->print_cr("[GC concurrent-mark-restart-for-overflow]");
146 }
147 }
148 } while (cm()->restart_for_overflow());
149
150 double end_time = os::elapsedVTime();
151 // Update the total virtual time before doing this, since it will try
152 // to measure it to get the vtime for this marking. We purposely
153 // neglect the presumably-short "completeCleanup" phase here.
154 _vtime_accum = (end_time - _vtime_start);
155
156 if (!cm()->has_aborted()) {
157 if (g1_policy->adaptive_young_list_length()) {
158 double now = os::elapsedTime();
159 double cleanup_prediction_ms = g1_policy->predict_cleanup_time_ms();
160 jlong sleep_time_ms = mmu_tracker->when_ms(now, cleanup_prediction_ms);
161 os::sleep(current_thread, sleep_time_ms, false);
162 }
163
164 CMCleanUp cl_cl(_cm);
165 sprintf(verbose_str, "GC cleanup");
166 VM_CGC_Operation op(&cl_cl, verbose_str);
167 VMThread::execute(&op);
168 } else {
169 // We don't want to update the marking status if a GC pause
170 // is already underway.
171 _sts.join();
172 g1h->set_marking_complete();
173 _sts.leave();
174 }
175
|