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
50 static const ZStatSubPhase ZSubPhasePauseRootsSetup("Pause Roots Setup");
51 static const ZStatSubPhase ZSubPhasePauseRoots("Pause Roots");
52 static const ZStatSubPhase ZSubPhasePauseRootsTeardown("Pause Roots Teardown");
53 static const ZStatSubPhase ZSubPhasePauseRootsUniverse("Pause Roots Universe");
54 static const ZStatSubPhase ZSubPhasePauseRootsJNIHandles("Pause Roots JNIHandles");
55 static const ZStatSubPhase ZSubPhasePauseRootsObjectSynchronizer("Pause Roots ObjectSynchronizer");
56 static const ZStatSubPhase ZSubPhasePauseRootsManagement("Pause Roots Management");
57 static const ZStatSubPhase ZSubPhasePauseRootsJVMTIExport("Pause Roots JVMTIExport");
58 static const ZStatSubPhase ZSubPhasePauseRootsJVMTIWeakExport("Pause Roots JVMTIWeakExport");
59 static const ZStatSubPhase ZSubPhasePauseRootsSystemDictionary("Pause Roots SystemDictionary");
60 static const ZStatSubPhase ZSubPhasePauseRootsClassLoaderDataGraph("Pause Roots ClassLoaderDataGraph");
61 static const ZStatSubPhase ZSubPhasePauseRootsThreads("Pause Roots Threads");
62 static const ZStatSubPhase ZSubPhasePauseRootsCodeCache("Pause Roots CodeCache");
63
64 static const ZStatSubPhase ZSubPhasePauseWeakRootsSetup("Pause Weak Roots Setup");
65 static const ZStatSubPhase ZSubPhasePauseWeakRoots("Pause Weak Roots");
66 static const ZStatSubPhase ZSubPhasePauseWeakRootsTeardown("Pause Weak Roots Teardown");
67 static const ZStatSubPhase ZSubPhasePauseWeakRootsJVMTIWeakExport("Pause Weak Roots JVMTIWeakExport");
68 static const ZStatSubPhase ZSubPhasePauseWeakRootsJFRWeak("Pause Weak Roots JFRWeak");
69
70 static const ZStatSubPhase ZSubPhaseConcurrentWeakRoots("Concurrent Weak Roots");
71 static const ZStatSubPhase ZSubPhaseConcurrentWeakRootsVMWeakHandles("Concurrent Weak Roots VMWeakHandles");
72 static const ZStatSubPhase ZSubPhaseConcurrentWeakRootsJNIWeakHandles("Concurrent Weak Roots JNIWeakHandles");
73 static const ZStatSubPhase ZSubPhaseConcurrentWeakRootsStringTable("Concurrent Weak Roots StringTable");
74
75 template <typename T, void (T::*F)(OopClosure*)>
76 ZSerialOopsDo<T, F>::ZSerialOopsDo(T* iter) :
77 _iter(iter),
78 _claimed(false) {}
79
80 template <typename T, void (T::*F)(OopClosure*)>
81 void ZSerialOopsDo<T, F>::oops_do(OopClosure* cl) {
82 if (!_claimed && Atomic::cmpxchg(true, &_claimed, false) == false) {
|
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
50 static const ZStatSubPhase ZSubPhasePauseRootsSetup("Pause Roots Setup");
51 static const ZStatSubPhase ZSubPhasePauseRoots("Pause Roots");
52 static const ZStatSubPhase ZSubPhasePauseRootsTeardown("Pause Roots Teardown");
53 static const ZStatSubPhase ZSubPhasePauseRootsUniverse("Pause Roots Universe");
54 static const ZStatSubPhase ZSubPhasePauseRootsObjectSynchronizer("Pause Roots ObjectSynchronizer");
55 static const ZStatSubPhase ZSubPhasePauseRootsManagement("Pause Roots Management");
56 static const ZStatSubPhase ZSubPhasePauseRootsJVMTIExport("Pause Roots JVMTIExport");
57 static const ZStatSubPhase ZSubPhasePauseRootsJVMTIWeakExport("Pause Roots JVMTIWeakExport");
58 static const ZStatSubPhase ZSubPhasePauseRootsSystemDictionary("Pause Roots SystemDictionary");
59 static const ZStatSubPhase ZSubPhasePauseRootsThreads("Pause Roots Threads");
60 static const ZStatSubPhase ZSubPhasePauseRootsCodeCache("Pause Roots CodeCache");
61
62 static const ZStatSubPhase ZSubPhaseConcurrentRootsSetup("Concurrent Roots Setup");
63 static const ZStatSubPhase ZSubPhaseConcurrentRoots("Concurrent Roots");
64 static const ZStatSubPhase ZSubPhaseConcurrentRootsTeardown("Concurrent Roots Teardown");
65 static const ZStatSubPhase ZSubPhaseConcurrentRootsJNIHandles("Concurrent Roots JNIHandles");
66 static const ZStatSubPhase ZSubPhaseConcurrentRootsClassLoaderDataGraph("Concurrent Roots ClassLoaderDataGraph");
67
68 static const ZStatSubPhase ZSubPhasePauseWeakRootsSetup("Pause Weak Roots Setup");
69 static const ZStatSubPhase ZSubPhasePauseWeakRoots("Pause Weak Roots");
70 static const ZStatSubPhase ZSubPhasePauseWeakRootsTeardown("Pause Weak Roots Teardown");
71 static const ZStatSubPhase ZSubPhasePauseWeakRootsJVMTIWeakExport("Pause Weak Roots JVMTIWeakExport");
72 static const ZStatSubPhase ZSubPhasePauseWeakRootsJFRWeak("Pause Weak Roots JFRWeak");
73
74 static const ZStatSubPhase ZSubPhaseConcurrentWeakRoots("Concurrent Weak Roots");
75 static const ZStatSubPhase ZSubPhaseConcurrentWeakRootsVMWeakHandles("Concurrent Weak Roots VMWeakHandles");
76 static const ZStatSubPhase ZSubPhaseConcurrentWeakRootsJNIWeakHandles("Concurrent Weak Roots JNIWeakHandles");
77 static const ZStatSubPhase ZSubPhaseConcurrentWeakRootsStringTable("Concurrent Weak Roots StringTable");
78
79 template <typename T, void (T::*F)(OopClosure*)>
80 ZSerialOopsDo<T, F>::ZSerialOopsDo(T* iter) :
81 _iter(iter),
82 _claimed(false) {}
83
84 template <typename T, void (T::*F)(OopClosure*)>
85 void ZSerialOopsDo<T, F>::oops_do(OopClosure* cl) {
86 if (!_claimed && Atomic::cmpxchg(true, &_claimed, false) == false) {
|
110 (_iter->*F)(is_alive, cl);
111 }
112 }
113
114 template <typename T, void (T::*F)(BoolObjectClosure*, OopClosure*)>
115 ZParallelWeakOopsDo<T, F>::ZParallelWeakOopsDo(T* iter) :
116 _iter(iter),
117 _completed(false) {}
118
119 template <typename T, void (T::*F)(BoolObjectClosure*, OopClosure*)>
120 void ZParallelWeakOopsDo<T, F>::weak_oops_do(BoolObjectClosure* is_alive, OopClosure* cl) {
121 if (!_completed) {
122 (_iter->*F)(is_alive, cl);
123 if (!_completed) {
124 _completed = true;
125 }
126 }
127 }
128
129 ZRootsIterator::ZRootsIterator() :
130 _jni_handles_iter(JNIHandles::global_handles()),
131 _universe(this),
132 _object_synchronizer(this),
133 _management(this),
134 _jvmti_export(this),
135 _jvmti_weak_export(this),
136 _system_dictionary(this),
137 _jni_handles(this),
138 _class_loader_data_graph(this),
139 _threads(this),
140 _code_cache(this) {
141 assert(SafepointSynchronize::is_at_safepoint(), "Should be at safepoint");
142 ZStatTimer timer(ZSubPhasePauseRootsSetup);
143 Threads::change_thread_claim_parity();
144 ClassLoaderDataGraph::clear_claimed_marks();
145 COMPILER2_PRESENT(DerivedPointerTable::clear());
146 CodeCache::gc_prologue();
147 ZNMethodTable::gc_prologue();
148 }
149
150 ZRootsIterator::~ZRootsIterator() {
151 ZStatTimer timer(ZSubPhasePauseRootsTeardown);
152 ResourceMark rm;
153 ZNMethodTable::gc_epilogue();
154 CodeCache::gc_epilogue();
155 JvmtiExport::gc_epilogue();
156 COMPILER2_PRESENT(DerivedPointerTable::update_pointers());
157 Threads::assert_all_threads_claimed();
158 }
159
160 void ZRootsIterator::do_universe(OopClosure* cl) {
161 ZStatTimer timer(ZSubPhasePauseRootsUniverse);
162 Universe::oops_do(cl);
163 }
164
165 void ZRootsIterator::do_jni_handles(OopClosure* cl) {
166 ZStatTimer timer(ZSubPhasePauseRootsJNIHandles);
167 _jni_handles_iter.oops_do(cl);
168 }
169
170 void ZRootsIterator::do_object_synchronizer(OopClosure* cl) {
171 ZStatTimer timer(ZSubPhasePauseRootsObjectSynchronizer);
172 ObjectSynchronizer::oops_do(cl);
173 }
174
175 void ZRootsIterator::do_management(OopClosure* cl) {
176 ZStatTimer timer(ZSubPhasePauseRootsManagement);
177 Management::oops_do(cl);
178 }
179
180 void ZRootsIterator::do_jvmti_export(OopClosure* cl) {
181 ZStatTimer timer(ZSubPhasePauseRootsJVMTIExport);
182 JvmtiExport::oops_do(cl);
183 }
184
185 void ZRootsIterator::do_jvmti_weak_export(OopClosure* cl) {
186 ZStatTimer timer(ZSubPhasePauseRootsJVMTIWeakExport);
187 AlwaysTrueClosure always_alive;
188 JvmtiExport::weak_oops_do(&always_alive, cl);
189 }
190
191 void ZRootsIterator::do_system_dictionary(OopClosure* cl) {
192 ZStatTimer timer(ZSubPhasePauseRootsSystemDictionary);
193 SystemDictionary::oops_do(cl);
194 }
195
196 void ZRootsIterator::do_class_loader_data_graph(OopClosure* cl) {
197 ZStatTimer timer(ZSubPhasePauseRootsClassLoaderDataGraph);
198 CLDToOopClosure cld_cl(cl);
199 ClassLoaderDataGraph::cld_do(&cld_cl);
200 }
201
202 class ZRootsIteratorThreadClosure : public ThreadClosure {
203 private:
204 OopClosure* const _cl;
205
206 public:
207 ZRootsIteratorThreadClosure(OopClosure* cl) :
208 _cl(cl) {}
209
210 virtual void do_thread(Thread* thread) {
211 if (thread->is_Java_thread()) {
212 // Update thread local address bad mask
213 ZThreadLocalData::set_address_bad_mask(thread, ZAddressBadMask);
214 }
215
216 // Process thread oops
217 thread->oops_do(_cl, NULL);
218 }
219 };
220
221 void ZRootsIterator::do_threads(OopClosure* cl) {
222 ZStatTimer timer(ZSubPhasePauseRootsThreads);
223 ResourceMark rm;
224 ZRootsIteratorThreadClosure thread_cl(cl);
225 Threads::possibly_parallel_threads_do(true, &thread_cl);
226 }
227
228 void ZRootsIterator::do_code_cache(OopClosure* cl) {
229 ZStatTimer timer(ZSubPhasePauseRootsCodeCache);
230 ZNMethodTable::oops_do(cl);
231 }
232
233 void ZRootsIterator::oops_do(OopClosure* cl, bool visit_jvmti_weak_export) {
234 ZStatTimer timer(ZSubPhasePauseRoots);
235 _universe.oops_do(cl);
236 _object_synchronizer.oops_do(cl);
237 _management.oops_do(cl);
238 _jvmti_export.oops_do(cl);
239 _system_dictionary.oops_do(cl);
240 _jni_handles.oops_do(cl);
241 _class_loader_data_graph.oops_do(cl);
242 _threads.oops_do(cl);
243 _code_cache.oops_do(cl);
244 if (visit_jvmti_weak_export) {
245 _jvmti_weak_export.oops_do(cl);
246 }
247 }
248
249 ZWeakRootsIterator::ZWeakRootsIterator() :
250 _jvmti_weak_export(this),
251 _jfr_weak(this) {
252 assert(SafepointSynchronize::is_at_safepoint(), "Should be at safepoint");
253 ZStatTimer timer(ZSubPhasePauseWeakRootsSetup);
254 StringTable::reset_dead_counter();
255 }
256
257 ZWeakRootsIterator::~ZWeakRootsIterator() {
258 ZStatTimer timer(ZSubPhasePauseWeakRootsTeardown);
259 StringTable::finish_dead_counter();
260 }
261
262 void ZWeakRootsIterator::do_jvmti_weak_export(BoolObjectClosure* is_alive, OopClosure* cl) {
263 ZStatTimer timer(ZSubPhasePauseWeakRootsJVMTIWeakExport);
264 JvmtiExport::weak_oops_do(is_alive, cl);
265 }
|
114 (_iter->*F)(is_alive, cl);
115 }
116 }
117
118 template <typename T, void (T::*F)(BoolObjectClosure*, OopClosure*)>
119 ZParallelWeakOopsDo<T, F>::ZParallelWeakOopsDo(T* iter) :
120 _iter(iter),
121 _completed(false) {}
122
123 template <typename T, void (T::*F)(BoolObjectClosure*, OopClosure*)>
124 void ZParallelWeakOopsDo<T, F>::weak_oops_do(BoolObjectClosure* is_alive, OopClosure* cl) {
125 if (!_completed) {
126 (_iter->*F)(is_alive, cl);
127 if (!_completed) {
128 _completed = true;
129 }
130 }
131 }
132
133 ZRootsIterator::ZRootsIterator() :
134 _universe(this),
135 _object_synchronizer(this),
136 _management(this),
137 _jvmti_export(this),
138 _jvmti_weak_export(this),
139 _system_dictionary(this),
140 _threads(this),
141 _code_cache(this) {
142 assert(SafepointSynchronize::is_at_safepoint(), "Should be at safepoint");
143 ZStatTimer timer(ZSubPhasePauseRootsSetup);
144 Threads::change_thread_claim_parity();
145 COMPILER2_PRESENT(DerivedPointerTable::clear());
146 CodeCache::gc_prologue();
147 ZNMethodTable::gc_prologue();
148 }
149
150 ZRootsIterator::~ZRootsIterator() {
151 ZStatTimer timer(ZSubPhasePauseRootsTeardown);
152 ResourceMark rm;
153 ZNMethodTable::gc_epilogue();
154 CodeCache::gc_epilogue();
155 JvmtiExport::gc_epilogue();
156 COMPILER2_PRESENT(DerivedPointerTable::update_pointers());
157 Threads::assert_all_threads_claimed();
158 }
159
160 void ZRootsIterator::do_universe(OopClosure* cl) {
161 ZStatTimer timer(ZSubPhasePauseRootsUniverse);
162 Universe::oops_do(cl);
163 }
164
165 void ZRootsIterator::do_object_synchronizer(OopClosure* cl) {
166 ZStatTimer timer(ZSubPhasePauseRootsObjectSynchronizer);
167 ObjectSynchronizer::oops_do(cl);
168 }
169
170 void ZRootsIterator::do_management(OopClosure* cl) {
171 ZStatTimer timer(ZSubPhasePauseRootsManagement);
172 Management::oops_do(cl);
173 }
174
175 void ZRootsIterator::do_jvmti_export(OopClosure* cl) {
176 ZStatTimer timer(ZSubPhasePauseRootsJVMTIExport);
177 JvmtiExport::oops_do(cl);
178 }
179
180 void ZRootsIterator::do_jvmti_weak_export(OopClosure* cl) {
181 ZStatTimer timer(ZSubPhasePauseRootsJVMTIWeakExport);
182 AlwaysTrueClosure always_alive;
183 JvmtiExport::weak_oops_do(&always_alive, cl);
184 }
185
186 void ZRootsIterator::do_system_dictionary(OopClosure* cl) {
187 ZStatTimer timer(ZSubPhasePauseRootsSystemDictionary);
188 SystemDictionary::oops_do(cl);
189 }
190
191 class ZRootsIteratorThreadClosure : public ThreadClosure {
192 private:
193 OopClosure* const _cl;
194
195 public:
196 ZRootsIteratorThreadClosure(OopClosure* cl) :
197 _cl(cl) {}
198
199 virtual void do_thread(Thread* thread) {
200 if (thread->is_Java_thread()) {
201 // Update thread local address bad mask
202 ZThreadLocalData::set_address_bad_mask(thread, ZAddressBadMask);
203 }
204
205 // Process thread oops
206 thread->oops_do(_cl, NULL);
207 }
208 };
209
210 void ZRootsIterator::do_threads(OopClosure* cl) {
211 ZStatTimer timer(ZSubPhasePauseRootsThreads);
212 ResourceMark rm;
213 ZRootsIteratorThreadClosure thread_cl(cl);
214 Threads::possibly_parallel_threads_do(true, &thread_cl);
215 }
216
217 void ZRootsIterator::do_code_cache(OopClosure* cl) {
218 ZStatTimer timer(ZSubPhasePauseRootsCodeCache);
219 ZNMethodTable::oops_do(cl);
220 }
221
222 void ZRootsIterator::oops_do(OopClosure* cl, bool visit_jvmti_weak_export) {
223 ZStatTimer timer(ZSubPhasePauseRoots);
224 _universe.oops_do(cl);
225 _object_synchronizer.oops_do(cl);
226 _management.oops_do(cl);
227 _jvmti_export.oops_do(cl);
228 _system_dictionary.oops_do(cl);
229 _threads.oops_do(cl);
230 _code_cache.oops_do(cl);
231 if (visit_jvmti_weak_export) {
232 _jvmti_weak_export.oops_do(cl);
233 }
234 }
235
236 ZConcurrentRootsIterator::ZConcurrentRootsIterator() :
237 _jni_handles_iter(JNIHandles::global_handles()),
238 _jni_handles(this),
239 _class_loader_data_graph(this) {
240 ZStatTimer timer(ZSubPhaseConcurrentRootsSetup);
241 ClassLoaderDataGraph_lock->lock();
242 ClassLoaderDataGraph::clear_claimed_marks();
243 }
244
245 ZConcurrentRootsIterator::~ZConcurrentRootsIterator() {
246 ZStatTimer timer(ZSubPhaseConcurrentRootsTeardown);
247 ClassLoaderDataGraph_lock->unlock();
248 }
249
250 void ZConcurrentRootsIterator::do_jni_handles(OopClosure* cl) {
251 ZStatTimer timer(ZSubPhaseConcurrentRootsJNIHandles);
252 _jni_handles_iter.oops_do(cl);
253 }
254
255 void ZConcurrentRootsIterator::do_class_loader_data_graph(OopClosure* cl) {
256 ZStatTimer timer(ZSubPhaseConcurrentRootsClassLoaderDataGraph);
257 CLDToOopClosure cld_cl(cl);
258 ClassLoaderDataGraph::cld_do(&cld_cl);
259 }
260
261 void ZConcurrentRootsIterator::oops_do(OopClosure* cl) {
262 ZStatTimer timer(ZSubPhaseConcurrentRoots);
263 _jni_handles.oops_do(cl);
264 _class_loader_data_graph.oops_do(cl);
265 }
266
267 ZWeakRootsIterator::ZWeakRootsIterator() :
268 _jvmti_weak_export(this),
269 _jfr_weak(this) {
270 assert(SafepointSynchronize::is_at_safepoint(), "Should be at safepoint");
271 ZStatTimer timer(ZSubPhasePauseWeakRootsSetup);
272 StringTable::reset_dead_counter();
273 }
274
275 ZWeakRootsIterator::~ZWeakRootsIterator() {
276 ZStatTimer timer(ZSubPhasePauseWeakRootsTeardown);
277 StringTable::finish_dead_counter();
278 }
279
280 void ZWeakRootsIterator::do_jvmti_weak_export(BoolObjectClosure* is_alive, OopClosure* cl) {
281 ZStatTimer timer(ZSubPhasePauseWeakRootsJVMTIWeakExport);
282 JvmtiExport::weak_oops_do(is_alive, cl);
283 }
|