11 * version 2 for more details (a copy is included in the LICENSE file that
12 * accompanied this code).
13 *
14 * You should have received a copy of the GNU General Public License version
15 * 2 along with this work; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19 * or visit www.oracle.com if you need additional information or have any
20 * questions.
21 */
22
23 #include "precompiled.hpp"
24 #include "classfile/classLoaderData.hpp"
25 #include "classfile/stringTable.hpp"
26 #include "classfile/systemDictionary.hpp"
27 #include "code/codeCache.hpp"
28 #include "compiler/oopMap.hpp"
29 #include "gc/shared/oopStorageParState.inline.hpp"
30 #include "gc/z/zGlobals.hpp"
31 #include "gc/z/zNMethodTable.hpp"
32 #include "gc/z/zOopClosures.inline.hpp"
33 #include "gc/z/zRootsIterator.hpp"
34 #include "gc/z/zStat.hpp"
35 #include "gc/z/zThreadLocalData.hpp"
36 #include "memory/resourceArea.hpp"
37 #include "memory/universe.hpp"
38 #include "prims/jvmtiExport.hpp"
39 #include "runtime/atomic.hpp"
40 #include "runtime/jniHandles.hpp"
41 #include "runtime/thread.hpp"
42 #include "runtime/safepoint.hpp"
43 #include "runtime/synchronizer.hpp"
44 #include "services/management.hpp"
45 #include "utilities/debug.hpp"
46 #if INCLUDE_JFR
47 #include "jfr/jfr.hpp"
48 #endif
49
|
11 * version 2 for more details (a copy is included in the LICENSE file that
12 * accompanied this code).
13 *
14 * You should have received a copy of the GNU General Public License version
15 * 2 along with this work; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19 * or visit www.oracle.com if you need additional information or have any
20 * questions.
21 */
22
23 #include "precompiled.hpp"
24 #include "classfile/classLoaderData.hpp"
25 #include "classfile/stringTable.hpp"
26 #include "classfile/systemDictionary.hpp"
27 #include "code/codeCache.hpp"
28 #include "compiler/oopMap.hpp"
29 #include "gc/shared/oopStorageParState.inline.hpp"
30 #include "gc/z/zGlobals.hpp"
31 #include "gc/z/zNMethodBarrier.hpp"
32 #include "gc/z/zNMethodTable.hpp"
33 #include "gc/z/zOopClosures.inline.hpp"
34 #include "gc/z/zRootsIterator.hpp"
35 #include "gc/z/zStat.hpp"
36 #include "gc/z/zThreadLocalData.hpp"
37 #include "memory/resourceArea.hpp"
38 #include "memory/universe.hpp"
39 #include "prims/jvmtiExport.hpp"
40 #include "runtime/atomic.hpp"
41 #include "runtime/jniHandles.hpp"
42 #include "runtime/thread.hpp"
43 #include "runtime/safepoint.hpp"
44 #include "runtime/synchronizer.hpp"
45 #include "services/management.hpp"
46 #include "utilities/debug.hpp"
47 #if INCLUDE_JFR
48 #include "jfr/jfr.hpp"
49 #endif
50
|
116 if (!_claimed && Atomic::cmpxchg(true, &_claimed, false) == false) {
117 (_iter->*F)(is_alive, cl);
118 }
119 }
120
121 template <typename T, void (T::*F)(BoolObjectClosure*, OopClosure*)>
122 ZParallelWeakOopsDo<T, F>::ZParallelWeakOopsDo(T* iter) :
123 _iter(iter),
124 _completed(false) {}
125
126 template <typename T, void (T::*F)(BoolObjectClosure*, OopClosure*)>
127 void ZParallelWeakOopsDo<T, F>::weak_oops_do(BoolObjectClosure* is_alive, OopClosure* cl) {
128 if (!_completed) {
129 (_iter->*F)(is_alive, cl);
130 if (!_completed) {
131 _completed = true;
132 }
133 }
134 }
135
136 ZRootsIterator::ZRootsIterator() :
137 _vm_weak_handles_iter(SystemDictionary::vm_weak_oop_storage()),
138 _jni_handles_iter(JNIHandles::global_handles()),
139 _jni_weak_handles_iter(JNIHandles::weak_global_handles()),
140 _string_table_iter(StringTable::weak_storage()),
141 _universe(this),
142 _object_synchronizer(this),
143 _management(this),
144 _jvmti_export(this),
145 _jvmti_weak_export(this),
146 _jfr_weak(this),
147 _system_dictionary(this),
148 _vm_weak_handles(this),
149 _jni_handles(this),
150 _jni_weak_handles(this),
151 _class_loader_data_graph(this),
152 _threads(this),
153 _code_cache(this),
154 _string_table(this) {
155 assert(SafepointSynchronize::is_at_safepoint(), "Should be at safepoint");
156 ZStatTimer timer(ZSubPhasePauseRootsSetup);
157 Threads::change_thread_claim_parity();
158 ClassLoaderDataGraph::clear_claimed_marks();
159 COMPILER2_PRESENT(DerivedPointerTable::clear());
160 CodeCache::gc_prologue();
161 ZNMethodTable::gc_prologue();
162 }
163
164 ZRootsIterator::~ZRootsIterator() {
165 ZStatTimer timer(ZSubPhasePauseRootsTeardown);
166 ResourceMark rm;
167 ZNMethodTable::gc_epilogue();
168 CodeCache::gc_epilogue();
169 JvmtiExport::gc_epilogue();
170 COMPILER2_PRESENT(DerivedPointerTable::update_pointers());
171 Threads::assert_all_threads_claimed();
172 }
173
174 void ZRootsIterator::do_universe(OopClosure* cl) {
175 ZStatTimer timer(ZSubPhasePauseRootsUniverse);
176 Universe::oops_do(cl);
177 }
178
179 void ZRootsIterator::do_vm_weak_handles(OopClosure* cl) {
180 ZStatTimer timer(ZSubPhasePauseRootsVMWeakHandles);
181 _vm_weak_handles_iter.oops_do(cl);
182 }
183
184 void ZRootsIterator::do_jni_handles(OopClosure* cl) {
185 ZStatTimer timer(ZSubPhasePauseRootsJNIHandles);
186 _jni_handles_iter.oops_do(cl);
187 }
188
|
117 if (!_claimed && Atomic::cmpxchg(true, &_claimed, false) == false) {
118 (_iter->*F)(is_alive, cl);
119 }
120 }
121
122 template <typename T, void (T::*F)(BoolObjectClosure*, OopClosure*)>
123 ZParallelWeakOopsDo<T, F>::ZParallelWeakOopsDo(T* iter) :
124 _iter(iter),
125 _completed(false) {}
126
127 template <typename T, void (T::*F)(BoolObjectClosure*, OopClosure*)>
128 void ZParallelWeakOopsDo<T, F>::weak_oops_do(BoolObjectClosure* is_alive, OopClosure* cl) {
129 if (!_completed) {
130 (_iter->*F)(is_alive, cl);
131 if (!_completed) {
132 _completed = true;
133 }
134 }
135 }
136
137 ZRootsIterator::ZRootsIterator(bool strong_only) :
138 _strong_only(strong_only),
139 _vm_weak_handles_iter(SystemDictionary::vm_weak_oop_storage()),
140 _jni_handles_iter(JNIHandles::global_handles()),
141 _jni_weak_handles_iter(JNIHandles::weak_global_handles()),
142 _string_table_iter(StringTable::weak_storage()),
143 _universe(this),
144 _object_synchronizer(this),
145 _management(this),
146 _jvmti_export(this),
147 _jvmti_weak_export(this),
148 _jfr_weak(this),
149 _system_dictionary(this),
150 _vm_weak_handles(this),
151 _jni_handles(this),
152 _jni_weak_handles(this),
153 _class_loader_data_graph(this),
154 _class_loader_data_graph_strong_only(this),
155 _threads(this),
156 _code_cache(this),
157 _string_table(this) {
158 assert(SafepointSynchronize::is_at_safepoint(), "Should be at safepoint");
159 ZStatTimer timer(ZSubPhasePauseRootsSetup);
160 Threads::change_thread_claim_parity();
161 ClassLoaderDataGraph::clear_claimed_marks();
162 COMPILER2_PRESENT(DerivedPointerTable::clear());
163 if (!ClassUnloading) {
164 ZNMethodTable::gc_prologue();
165 }
166 }
167
168 ZRootsIterator::~ZRootsIterator() {
169 ZStatTimer timer(ZSubPhasePauseRootsTeardown);
170 ResourceMark rm;
171 if (!ClassUnloading) {
172 ZNMethodTable::gc_epilogue();
173 }
174 JvmtiExport::gc_epilogue();
175
176 COMPILER2_PRESENT(DerivedPointerTable::update_pointers());
177 Threads::assert_all_threads_claimed();
178 }
179
180 void ZRootsIterator::do_universe(OopClosure* cl) {
181 ZStatTimer timer(ZSubPhasePauseRootsUniverse);
182 Universe::oops_do(cl);
183 }
184
185 void ZRootsIterator::do_vm_weak_handles(OopClosure* cl) {
186 ZStatTimer timer(ZSubPhasePauseRootsVMWeakHandles);
187 _vm_weak_handles_iter.oops_do(cl);
188 }
189
190 void ZRootsIterator::do_jni_handles(OopClosure* cl) {
191 ZStatTimer timer(ZSubPhasePauseRootsJNIHandles);
192 _jni_handles_iter.oops_do(cl);
193 }
194
|
214
215 void ZRootsIterator::do_jfr_weak(OopClosure* cl) {
216 #if INCLUDE_JFR
217 ZStatTimer timer(ZSubPhasePauseRootsJFRWeak);
218 AlwaysTrueClosure always_alive;
219 Jfr::weak_oops_do(&always_alive, cl);
220 #endif
221 }
222
223 void ZRootsIterator::do_system_dictionary(OopClosure* cl) {
224 ZStatTimer timer(ZSubPhasePauseRootsSystemDictionary);
225 SystemDictionary::oops_do(cl);
226 }
227
228 void ZRootsIterator::do_class_loader_data_graph(OopClosure* cl) {
229 ZStatTimer timer(ZSubPhasePauseRootsClassLoaderDataGraph);
230 CLDToOopClosure cld_cl(cl);
231 ClassLoaderDataGraph::cld_do(&cld_cl);
232 }
233
234 class ZRootsIteratorThreadClosure : public ThreadClosure {
235 private:
236 OopClosure* const _cl;
237
238 public:
239 ZRootsIteratorThreadClosure(OopClosure* cl) :
240 _cl(cl) {}
241
242 virtual void do_thread(Thread* thread) {
243 if (thread->is_Java_thread()) {
244 // Update thread local address bad mask
245 ZThreadLocalData::set_address_bad_mask(thread, ZAddressBadMask);
246 }
247
248 // Process thread oops
249 thread->oops_do(_cl, NULL);
250 }
251 };
252
253 void ZRootsIterator::do_threads(OopClosure* cl) {
254 ZStatTimer timer(ZSubPhasePauseRootsThreads);
255 ResourceMark rm;
256 ZRootsIteratorThreadClosure thread_cl(cl);
257 Threads::possibly_parallel_threads_do(true, &thread_cl);
258 }
259
260 void ZRootsIterator::do_code_cache(OopClosure* cl) {
261 ZStatTimer timer(ZSubPhasePauseRootsCodeCache);
262 ZNMethodTable::oops_do(cl);
263 }
264
265 void ZRootsIterator::do_string_table(OopClosure* cl) {
266 ZStatTimer timer(ZSubPhasePauseRootsStringTable);
267 _string_table_iter.oops_do(cl);
268 }
269
270 void ZRootsIterator::oops_do(OopClosure* cl, bool visit_jvmti_weak_export) {
271 ZStatTimer timer(ZSubPhasePauseRoots);
272 _universe.oops_do(cl);
273 _object_synchronizer.oops_do(cl);
274 _management.oops_do(cl);
275 _jvmti_export.oops_do(cl);
276 _system_dictionary.oops_do(cl);
277 _jni_handles.oops_do(cl);
278 _class_loader_data_graph.oops_do(cl);
279 _threads.oops_do(cl);
280 _code_cache.oops_do(cl);
281 if (!ZWeakRoots) {
282 _jvmti_weak_export.oops_do(cl);
283 _jfr_weak.oops_do(cl);
284 _vm_weak_handles.oops_do(cl);
285 _jni_weak_handles.oops_do(cl);
286 _string_table.oops_do(cl);
287 } else {
288 if (visit_jvmti_weak_export) {
289 _jvmti_weak_export.oops_do(cl);
290 }
291 }
292 }
293
294 ZWeakRootsIterator::ZWeakRootsIterator() :
295 _vm_weak_handles_iter(SystemDictionary::vm_weak_oop_storage()),
296 _jni_weak_handles_iter(JNIHandles::weak_global_handles()),
297 _string_table_iter(StringTable::weak_storage()),
298 _jvmti_weak_export(this),
299 _jfr_weak(this),
300 _vm_weak_handles(this),
301 _jni_weak_handles(this),
302 _string_table(this) {
303 assert(SafepointSynchronize::is_at_safepoint(), "Should be at safepoint");
304 ZStatTimer timer(ZSubPhasePauseWeakRootsSetup);
305 StringTable::reset_dead_counter();
306 }
307
308 ZWeakRootsIterator::~ZWeakRootsIterator() {
309 ZStatTimer timer(ZSubPhasePauseWeakRootsTeardown);
310 StringTable::finish_dead_counter();
311 }
312
313 void ZWeakRootsIterator::do_vm_weak_handles(BoolObjectClosure* is_alive, OopClosure* cl) {
314 ZStatTimer timer(ZSubPhasePauseWeakRootsVMWeakHandles);
315 _vm_weak_handles_iter.weak_oops_do(is_alive, cl);
316 }
317
318 void ZWeakRootsIterator::do_jni_weak_handles(BoolObjectClosure* is_alive, OopClosure* cl) {
319 ZStatTimer timer(ZSubPhasePauseWeakRootsJNIWeakHandles);
320 _jni_weak_handles_iter.weak_oops_do(is_alive, cl);
321 }
322
323 void ZWeakRootsIterator::do_jvmti_weak_export(BoolObjectClosure* is_alive, OopClosure* cl) {
324 ZStatTimer timer(ZSubPhasePauseWeakRootsJVMTIWeakExport);
|
220
221 void ZRootsIterator::do_jfr_weak(OopClosure* cl) {
222 #if INCLUDE_JFR
223 ZStatTimer timer(ZSubPhasePauseRootsJFRWeak);
224 AlwaysTrueClosure always_alive;
225 Jfr::weak_oops_do(&always_alive, cl);
226 #endif
227 }
228
229 void ZRootsIterator::do_system_dictionary(OopClosure* cl) {
230 ZStatTimer timer(ZSubPhasePauseRootsSystemDictionary);
231 SystemDictionary::oops_do(cl);
232 }
233
234 void ZRootsIterator::do_class_loader_data_graph(OopClosure* cl) {
235 ZStatTimer timer(ZSubPhasePauseRootsClassLoaderDataGraph);
236 CLDToOopClosure cld_cl(cl);
237 ClassLoaderDataGraph::cld_do(&cld_cl);
238 }
239
240 void ZRootsIterator::do_class_loader_data_graph_strong_only(OopClosure* cl) {
241 ZStatTimer timer(ZSubPhasePauseRootsClassLoaderDataGraph);
242 ClassLoaderDataGraph::always_strong_oops_do(cl, /* must_claim */ true);
243 }
244
245 class ZCodeBlobClosure : public CodeBlobToOopClosure {
246 public:
247 ZCodeBlobClosure(OopClosure* cl) : CodeBlobToOopClosure(cl, true) {}
248 virtual void do_code_blob(CodeBlob* cb) {
249 CodeBlobToOopClosure::do_code_blob(cb);
250 if (cb->is_nmethod()) {
251 nmethod* nm = (nmethod*) cb;
252 nm->disarm_barrier();
253 }
254 }
255 };
256
257 class ZRootsIteratorThreadClosure : public ThreadClosure {
258 private:
259 OopClosure* const _cl;
260 CodeBlobClosure* const _code_cl;
261
262 public:
263 ZRootsIteratorThreadClosure(OopClosure* cl, CodeBlobClosure* code_cl) :
264 _cl(cl),
265 _code_cl(code_cl) {}
266
267 virtual void do_thread(Thread* thread) {
268 if (thread->is_Java_thread()) {
269 // Update thread local address bad mask
270 ZThreadLocalData::set_address_bad_mask(thread, ZAddressBadMask);
271 }
272
273 // Process thread oops
274 thread->oops_do(_cl, _code_cl);
275 }
276 };
277
278 void ZRootsIterator::do_threads(OopClosure* cl) {
279 ZStatTimer timer(ZSubPhasePauseRootsThreads);
280 ResourceMark rm;
281
282 ZCodeBlobClosure code_cl(cl);
283 ZRootsIteratorThreadClosure thread_cl(cl, ClassUnloading ? &code_cl : NULL);
284 Threads::possibly_parallel_threads_do(true, &thread_cl);
285 }
286
287 void ZRootsIterator::do_code_cache(OopClosure* cl) {
288 ZStatTimer timer(ZSubPhasePauseRootsCodeCache);
289 ZNMethodTable::oops_do(cl);
290 }
291
292 void ZRootsIterator::do_string_table(OopClosure* cl) {
293 ZStatTimer timer(ZSubPhasePauseRootsStringTable);
294 _string_table_iter.oops_do(cl);
295 }
296
297 void ZRootsIterator::oops_do(OopClosure* cl, bool visit_jvmti_weak_export) {
298 ZStatTimer timer(ZSubPhasePauseRoots);
299 _universe.oops_do(cl);
300 _object_synchronizer.oops_do(cl);
301 _management.oops_do(cl);
302 _jvmti_export.oops_do(cl);
303 _system_dictionary.oops_do(cl);
304 _jni_handles.oops_do(cl);
305 _threads.oops_do(cl);
306
307 if (!ClassUnloading) {
308 _code_cache.oops_do(cl);
309 }
310
311 if (!ClassUnloading || !ZWeakRoots || !_strong_only) {
312 _class_loader_data_graph.oops_do(cl);
313 } else {
314 _class_loader_data_graph_strong_only.oops_do(cl);
315 }
316
317 if (!ZWeakRoots) {
318 _jvmti_weak_export.oops_do(cl);
319 _jfr_weak.oops_do(cl);
320 _vm_weak_handles.oops_do(cl);
321 _jni_weak_handles.oops_do(cl);
322 _string_table.oops_do(cl);
323 } else {
324 if (visit_jvmti_weak_export) {
325 _jvmti_weak_export.oops_do(cl);
326 }
327 }
328 }
329
330 ZWeakRootsIterator::ZWeakRootsIterator() :
331 _vm_weak_handles_iter(SystemDictionary::vm_weak_oop_storage()),
332 _jni_weak_handles_iter(JNIHandles::weak_global_handles()),
333 _string_table_iter(StringTable::weak_storage()),
334 _jvmti_weak_export(this),
335 _jfr_weak(this),
336 _vm_weak_handles(this),
337 _jni_weak_handles(this),
338 _string_table(this) {
339 assert(SafepointSynchronize::is_at_safepoint(), "Should be at safepoint");
340 ZStatTimer timer(ZSubPhasePauseWeakRootsSetup);
341 StringTable::reset_dead_counter();
342 ClassLoaderDataGraph::clear_claimed_marks();
343 }
344
345 ZWeakRootsIterator::~ZWeakRootsIterator() {
346 ZStatTimer timer(ZSubPhasePauseWeakRootsTeardown);
347 StringTable::finish_dead_counter();
348 }
349
350 void ZWeakRootsIterator::do_vm_weak_handles(BoolObjectClosure* is_alive, OopClosure* cl) {
351 ZStatTimer timer(ZSubPhasePauseWeakRootsVMWeakHandles);
352 _vm_weak_handles_iter.weak_oops_do(is_alive, cl);
353 }
354
355 void ZWeakRootsIterator::do_jni_weak_handles(BoolObjectClosure* is_alive, OopClosure* cl) {
356 ZStatTimer timer(ZSubPhasePauseWeakRootsJNIWeakHandles);
357 _jni_weak_handles_iter.weak_oops_do(is_alive, cl);
358 }
359
360 void ZWeakRootsIterator::do_jvmti_weak_export(BoolObjectClosure* is_alive, OopClosure* cl) {
361 ZStatTimer timer(ZSubPhasePauseWeakRootsJVMTIWeakExport);
|