96 uint new_value = (uint)Atomic::add(1, &_n_workers_discovered_strong_classes);
97 if (new_value == n_workers) {
98 // This thread is last. Notify the others.
99 MonitorLockerEx ml(&_lock, Mutex::_no_safepoint_check_flag);
100 _lock.notify_all();
101 }
102 }
103
104 void G1RootProcessor::wait_until_all_strong_classes_discovered() {
105 uint n_workers = _g1h->n_par_threads();
106 assert(ClassUnloadingWithConcurrentMark, "Currently only needed when doing G1 Class Unloading");
107
108 if ((uint)_n_workers_discovered_strong_classes != n_workers) {
109 MonitorLockerEx ml(&_lock, Mutex::_no_safepoint_check_flag);
110 while ((uint)_n_workers_discovered_strong_classes != n_workers) {
111 _lock.wait(Mutex::_no_safepoint_check_flag, 0, false);
112 }
113 }
114 }
115
116 G1RootProcessor::G1RootProcessor(G1CollectedHeap* g1h, bool trace_metadata) :
117 _g1h(g1h),
118 _process_strong_tasks(new SubTasksDone(G1RP_PS_NumElements)),
119 _srs(g1h),
120 _lock(Mutex::leaf, "G1 Root Scanning barrier lock", false, Monitor::_safepoint_check_never),
121 _n_workers_discovered_strong_classes(0),
122 _trace_metadata(trace_metadata) {}
123
124 void G1RootProcessor::evacuate_roots(OopClosure* scan_non_heap_roots,
125 OopClosure* scan_non_heap_weak_roots,
126 CLDClosure* scan_strong_clds,
127 CLDClosure* scan_weak_clds,
128 uint worker_i) {
129 // First scan the shared roots.
130 double ext_roots_start = os::elapsedTime();
131
132 BufferingOopClosure buf_scan_non_heap_roots(scan_non_heap_roots);
133 BufferingOopClosure buf_scan_non_heap_weak_roots(scan_non_heap_weak_roots);
134
135 OopClosure* const weak_roots = &buf_scan_non_heap_weak_roots;
136 OopClosure* const strong_roots = &buf_scan_non_heap_roots;
137
138 // CodeBlobClosures are not interoperable with BufferingOopClosures
139 G1CodeBlobClosure root_code_blobs(scan_non_heap_roots);
140
141 process_java_roots(strong_roots,
142 _trace_metadata ? scan_strong_clds : NULL,
143 scan_strong_clds,
144 _trace_metadata ? NULL : scan_weak_clds,
145 &root_code_blobs);
146
147 // This is the point where this worker thread will not find more strong CLDs/nmethods.
148 // Report this so G1 can synchronize the strong and weak CLDs/nmethods processing.
149 if (_trace_metadata) {
150 worker_has_discovered_all_strong_classes();
151 }
152
153 process_vm_roots(strong_roots, weak_roots);
154
155 // Now the CM ref_processor roots.
156 if (!_process_strong_tasks->is_task_claimed(G1RP_PS_refProcessor_oops_do)) {
157 // We need to treat the discovered reference lists of the
158 // concurrent mark ref processor as roots and keep entries
159 // (which are added by the marking threads) on them live
160 // until they can be processed at the end of marking.
161 _g1h->ref_processor_cm()->weak_oops_do(&buf_scan_non_heap_roots);
162 }
163
164 if (_trace_metadata) {
165 // Barrier to make sure all workers passed
166 // the strong CLD and strong nmethods phases.
167 wait_until_all_strong_classes_discovered();
168
169 // Now take the complement of the strong CLDs.
170 ClassLoaderDataGraph::roots_cld_do(NULL, scan_weak_clds);
171 }
172
173 // Finish up any enqueued closure apps (attributed as object copy time).
174 buf_scan_non_heap_roots.done();
175 buf_scan_non_heap_weak_roots.done();
176
177 double obj_copy_time_sec = buf_scan_non_heap_roots.closure_app_seconds()
178 + buf_scan_non_heap_weak_roots.closure_app_seconds();
179
180 G1GCPhaseTimes* phase_times = _g1h->g1_policy()->phase_times();
181 phase_times->record_time_secs(G1GCPhaseTimes::ObjCopy, worker_i, obj_copy_time_sec);
182
183 double ext_root_time_sec = os::elapsedTime() - ext_roots_start - obj_copy_time_sec;
184
|
96 uint new_value = (uint)Atomic::add(1, &_n_workers_discovered_strong_classes);
97 if (new_value == n_workers) {
98 // This thread is last. Notify the others.
99 MonitorLockerEx ml(&_lock, Mutex::_no_safepoint_check_flag);
100 _lock.notify_all();
101 }
102 }
103
104 void G1RootProcessor::wait_until_all_strong_classes_discovered() {
105 uint n_workers = _g1h->n_par_threads();
106 assert(ClassUnloadingWithConcurrentMark, "Currently only needed when doing G1 Class Unloading");
107
108 if ((uint)_n_workers_discovered_strong_classes != n_workers) {
109 MonitorLockerEx ml(&_lock, Mutex::_no_safepoint_check_flag);
110 while ((uint)_n_workers_discovered_strong_classes != n_workers) {
111 _lock.wait(Mutex::_no_safepoint_check_flag, 0, false);
112 }
113 }
114 }
115
116 G1RootProcessor::G1RootProcessor(G1CollectedHeap* g1h) :
117 _g1h(g1h),
118 _process_strong_tasks(new SubTasksDone(G1RP_PS_NumElements)),
119 _srs(g1h),
120 _lock(Mutex::leaf, "G1 Root Scanning barrier lock", false, Monitor::_safepoint_check_never),
121 _n_workers_discovered_strong_classes(0) {}
122
123 void G1RootProcessor::evacuate_roots(OopClosure* scan_non_heap_roots,
124 OopClosure* scan_non_heap_weak_roots,
125 CLDClosure* scan_strong_clds,
126 CLDClosure* scan_weak_clds,
127 bool trace_metadata,
128 uint worker_i) {
129 // First scan the shared roots.
130 double ext_roots_start = os::elapsedTime();
131
132 BufferingOopClosure buf_scan_non_heap_roots(scan_non_heap_roots);
133 BufferingOopClosure buf_scan_non_heap_weak_roots(scan_non_heap_weak_roots);
134
135 OopClosure* const weak_roots = &buf_scan_non_heap_weak_roots;
136 OopClosure* const strong_roots = &buf_scan_non_heap_roots;
137
138 // CodeBlobClosures are not interoperable with BufferingOopClosures
139 G1CodeBlobClosure root_code_blobs(scan_non_heap_roots);
140
141 process_java_roots(strong_roots,
142 trace_metadata ? scan_strong_clds : NULL,
143 scan_strong_clds,
144 trace_metadata ? NULL : scan_weak_clds,
145 &root_code_blobs);
146
147 // This is the point where this worker thread will not find more strong CLDs/nmethods.
148 // Report this so G1 can synchronize the strong and weak CLDs/nmethods processing.
149 if (trace_metadata) {
150 worker_has_discovered_all_strong_classes();
151 }
152
153 process_vm_roots(strong_roots, weak_roots);
154
155 // Now the CM ref_processor roots.
156 if (!_process_strong_tasks->is_task_claimed(G1RP_PS_refProcessor_oops_do)) {
157 // We need to treat the discovered reference lists of the
158 // concurrent mark ref processor as roots and keep entries
159 // (which are added by the marking threads) on them live
160 // until they can be processed at the end of marking.
161 _g1h->ref_processor_cm()->weak_oops_do(&buf_scan_non_heap_roots);
162 }
163
164 if (trace_metadata) {
165 // Barrier to make sure all workers passed
166 // the strong CLD and strong nmethods phases.
167 wait_until_all_strong_classes_discovered();
168
169 // Now take the complement of the strong CLDs.
170 ClassLoaderDataGraph::roots_cld_do(NULL, scan_weak_clds);
171 }
172
173 // Finish up any enqueued closure apps (attributed as object copy time).
174 buf_scan_non_heap_roots.done();
175 buf_scan_non_heap_weak_roots.done();
176
177 double obj_copy_time_sec = buf_scan_non_heap_roots.closure_app_seconds()
178 + buf_scan_non_heap_weak_roots.closure_app_seconds();
179
180 G1GCPhaseTimes* phase_times = _g1h->g1_policy()->phase_times();
181 phase_times->record_time_secs(G1GCPhaseTimes::ObjCopy, worker_i, obj_copy_time_sec);
182
183 double ext_root_time_sec = os::elapsedTime() - ext_roots_start - obj_copy_time_sec;
184
|