27 #include "code/codeCache.hpp" |
27 #include "code/codeCache.hpp" |
28 #include "gc/shared/oopStorageParState.hpp" |
28 #include "gc/shared/oopStorageParState.hpp" |
29 #include "gc/shenandoah/shenandoahCodeRoots.hpp" |
29 #include "gc/shenandoah/shenandoahCodeRoots.hpp" |
30 #include "gc/shenandoah/shenandoahHeap.hpp" |
30 #include "gc/shenandoah/shenandoahHeap.hpp" |
31 #include "gc/shenandoah/shenandoahPhaseTimings.hpp" |
31 #include "gc/shenandoah/shenandoahPhaseTimings.hpp" |
32 #include "gc/shared/strongRootsScope.hpp" |
32 #include "gc/shenandoah/shenandoahSharedVariables.hpp" |
33 #include "gc/shared/weakProcessor.hpp" |
|
34 #include "gc/shared/weakProcessorPhaseTimes.hpp" |
|
35 #include "gc/shared/workgroup.hpp" |
|
36 #include "memory/allocation.hpp" |
|
37 #include "memory/iterator.hpp" |
33 #include "memory/iterator.hpp" |
38 |
34 |
39 class ShenandoahSerialRoot { |
35 class ShenandoahSerialRoot { |
40 public: |
36 public: |
41 typedef void (*OopsDo)(OopClosure*); |
37 typedef void (*OopsDo)(OopClosure*); |
42 private: |
38 private: |
43 volatile bool _claimed; |
39 ShenandoahSharedFlag _claimed; |
44 const OopsDo _oops_do; |
40 const OopsDo _oops_do; |
45 const ShenandoahPhaseTimings::GCParPhases _phase; |
41 const ShenandoahPhaseTimings::GCParPhases _phase; |
46 |
42 |
47 public: |
43 public: |
48 ShenandoahSerialRoot(OopsDo oops_do, ShenandoahPhaseTimings::GCParPhases); |
44 ShenandoahSerialRoot(OopsDo oops_do, ShenandoahPhaseTimings::GCParPhases); |
54 ShenandoahSerialRoot _universe_root; |
50 ShenandoahSerialRoot _universe_root; |
55 ShenandoahSerialRoot _object_synchronizer_root; |
51 ShenandoahSerialRoot _object_synchronizer_root; |
56 ShenandoahSerialRoot _management_root; |
52 ShenandoahSerialRoot _management_root; |
57 ShenandoahSerialRoot _system_dictionary_root; |
53 ShenandoahSerialRoot _system_dictionary_root; |
58 ShenandoahSerialRoot _jvmti_root; |
54 ShenandoahSerialRoot _jvmti_root; |
59 ShenandoahSerialRoot _jni_handle_root; |
|
60 public: |
55 public: |
61 ShenandoahSerialRoots(); |
56 ShenandoahSerialRoots(); |
62 void oops_do(OopClosure* cl, uint worker_id); |
57 void oops_do(OopClosure* cl, uint worker_id); |
63 }; |
58 }; |
64 |
59 |
|
60 class ShenandoahWeakSerialRoot { |
|
61 typedef void (*WeakOopsDo)(BoolObjectClosure*, OopClosure*); |
|
62 private: |
|
63 ShenandoahSharedFlag _claimed; |
|
64 const WeakOopsDo _weak_oops_do; |
|
65 const ShenandoahPhaseTimings::GCParPhases _phase; |
|
66 |
|
67 public: |
|
68 ShenandoahWeakSerialRoot(WeakOopsDo oops_do, ShenandoahPhaseTimings::GCParPhases); |
|
69 void weak_oops_do(BoolObjectClosure* is_alive, OopClosure* keep_alive, uint worker_id); |
|
70 }; |
|
71 |
|
72 #if INCLUDE_JVMTI |
|
73 class ShenandoahJVMTIWeakRoot : public ShenandoahWeakSerialRoot { |
|
74 public: |
|
75 ShenandoahJVMTIWeakRoot(); |
|
76 }; |
|
77 #endif // INCLUDE_JVMTI |
|
78 |
|
79 #if INCLUDE_JFR |
|
80 class ShenandoahJFRWeakRoot : public ShenandoahWeakSerialRoot { |
|
81 public: |
|
82 ShenandoahJFRWeakRoot(); |
|
83 }; |
|
84 #endif // INCLUDE_JFR |
|
85 |
|
86 class ShenandoahSerialWeakRoots { |
|
87 private: |
|
88 JVMTI_ONLY(ShenandoahJVMTIWeakRoot _jvmti_weak_roots;) |
|
89 JFR_ONLY(ShenandoahJFRWeakRoot _jfr_weak_roots;) |
|
90 public: |
|
91 void weak_oops_do(BoolObjectClosure* is_alive, OopClosure* keep_alive, uint worker_id); |
|
92 void weak_oops_do(OopClosure* cl, uint worker_id); |
|
93 }; |
|
94 |
|
95 template <bool CONCURRENT> |
|
96 class ShenandoahVMRoot { |
|
97 private: |
|
98 OopStorage::ParState<CONCURRENT, false /* is_const */> _itr; |
|
99 const ShenandoahPhaseTimings::GCParPhases _phase; |
|
100 public: |
|
101 ShenandoahVMRoot(OopStorage* storage, ShenandoahPhaseTimings::GCParPhases phase); |
|
102 |
|
103 template <typename Closure> |
|
104 void oops_do(Closure* cl, uint worker_id); |
|
105 }; |
|
106 |
|
107 template <bool CONCURRENT> |
|
108 class ShenandoahWeakRoot : public ShenandoahVMRoot<CONCURRENT> { |
|
109 public: |
|
110 ShenandoahWeakRoot(OopStorage* storage, ShenandoahPhaseTimings::GCParPhases phase); |
|
111 }; |
|
112 |
|
113 template <> |
|
114 class ShenandoahWeakRoot<false /*concurrent*/> { |
|
115 private: |
|
116 OopStorage::ParState<false /*concurrent*/, false /*is_const*/> _itr; |
|
117 const ShenandoahPhaseTimings::GCParPhases _phase; |
|
118 |
|
119 public: |
|
120 ShenandoahWeakRoot(OopStorage* storage, ShenandoahPhaseTimings::GCParPhases phase); |
|
121 |
|
122 template <typename IsAliveClosure, typename KeepAliveClosure> |
|
123 void weak_oops_do(IsAliveClosure* is_alive, KeepAliveClosure* keep_alive, uint worker_id); |
|
124 }; |
|
125 |
|
126 template <bool CONCURRENT> |
|
127 class ShenandoahWeakRoots { |
|
128 private: |
|
129 ShenandoahWeakRoot<CONCURRENT> _jni_roots; |
|
130 ShenandoahWeakRoot<CONCURRENT> _string_table_roots; |
|
131 ShenandoahWeakRoot<CONCURRENT> _resolved_method_table_roots; |
|
132 ShenandoahWeakRoot<CONCURRENT> _vm_roots; |
|
133 |
|
134 public: |
|
135 ShenandoahWeakRoots(); |
|
136 |
|
137 template <typename Closure> |
|
138 void oops_do(Closure* cl, uint worker_id = 0); |
|
139 }; |
|
140 |
|
141 template <> |
|
142 class ShenandoahWeakRoots<false /*concurrent */> { |
|
143 private: |
|
144 ShenandoahWeakRoot<false /*concurrent*/> _jni_roots; |
|
145 ShenandoahWeakRoot<false /*concurrent*/> _string_table_roots; |
|
146 ShenandoahWeakRoot<false /*concurrent*/> _resolved_method_table_roots; |
|
147 ShenandoahWeakRoot<false /*concurrent*/> _vm_roots; |
|
148 public: |
|
149 ShenandoahWeakRoots(); |
|
150 |
|
151 template <typename Closure> |
|
152 void oops_do(Closure* cl, uint worker_id = 0); |
|
153 |
|
154 template <typename IsAliveClosure, typename KeepAliveClosure> |
|
155 void weak_oops_do(IsAliveClosure* is_alive, KeepAliveClosure* keep_alive, uint worker_id); |
|
156 }; |
|
157 |
|
158 template <bool CONCURRENT> |
|
159 class ShenandoahVMRoots { |
|
160 private: |
|
161 ShenandoahVMRoot<CONCURRENT> _jni_handle_roots; |
|
162 ShenandoahVMRoot<CONCURRENT> _vm_global_roots; |
|
163 |
|
164 public: |
|
165 ShenandoahVMRoots(); |
|
166 |
|
167 template <typename T> |
|
168 void oops_do(T* cl, uint worker_id = 0); |
|
169 }; |
|
170 |
65 class ShenandoahThreadRoots { |
171 class ShenandoahThreadRoots { |
66 private: |
172 private: |
67 const bool _is_par; |
173 const bool _is_par; |
68 public: |
174 public: |
69 ShenandoahThreadRoots(bool is_par); |
175 ShenandoahThreadRoots(bool is_par); |
71 |
177 |
72 void oops_do(OopClosure* oops_cl, CodeBlobClosure* code_cl, uint worker_id); |
178 void oops_do(OopClosure* oops_cl, CodeBlobClosure* code_cl, uint worker_id); |
73 void threads_do(ThreadClosure* tc, uint worker_id); |
179 void threads_do(ThreadClosure* tc, uint worker_id); |
74 }; |
180 }; |
75 |
181 |
76 class ShenandoahWeakRoots { |
|
77 private: |
|
78 WeakProcessorPhaseTimes _process_timings; |
|
79 WeakProcessor::Task _task; |
|
80 public: |
|
81 ShenandoahWeakRoots(uint n_workers); |
|
82 ~ShenandoahWeakRoots(); |
|
83 |
|
84 template <typename IsAlive, typename KeepAlive> |
|
85 void oops_do(IsAlive* is_alive, KeepAlive* keep_alive, uint worker_id); |
|
86 }; |
|
87 |
|
88 class ShenandoahStringDedupRoots { |
182 class ShenandoahStringDedupRoots { |
89 public: |
183 public: |
90 ShenandoahStringDedupRoots(); |
184 ShenandoahStringDedupRoots(); |
91 ~ShenandoahStringDedupRoots(); |
185 ~ShenandoahStringDedupRoots(); |
92 |
186 |
123 }; |
220 }; |
124 |
221 |
125 template <typename ITR> |
222 template <typename ITR> |
126 class ShenandoahRootScanner : public ShenandoahRootProcessor { |
223 class ShenandoahRootScanner : public ShenandoahRootProcessor { |
127 private: |
224 private: |
128 ShenandoahSerialRoots _serial_roots; |
225 ShenandoahSerialRoots _serial_roots; |
129 ShenandoahClassLoaderDataRoots _cld_roots; |
226 ShenandoahThreadRoots _thread_roots; |
130 ShenandoahThreadRoots _thread_roots; |
227 ShenandoahCodeCacheRoots<ITR> _code_roots; |
131 ShenandoahCodeCacheRoots<ITR> _code_roots; |
228 ShenandoahVMRoots<false /*concurrent*/ > _vm_roots; |
|
229 ShenandoahClassLoaderDataRoots<false /*concurrent*/, false /*single threaded*/> |
|
230 _cld_roots; |
132 public: |
231 public: |
133 ShenandoahRootScanner(uint n_workers, ShenandoahPhaseTimings::Phase phase); |
232 ShenandoahRootScanner(uint n_workers, ShenandoahPhaseTimings::Phase phase); |
134 |
233 |
135 // Apply oops, clds and blobs to all strongly reachable roots in the system, |
234 // Apply oops, clds and blobs to all strongly reachable roots in the system, |
136 // during class unloading cycle |
235 // during class unloading cycle |
144 }; |
243 }; |
145 |
244 |
146 typedef ShenandoahRootScanner<ShenandoahAllCodeRootsIterator> ShenandoahAllRootScanner; |
245 typedef ShenandoahRootScanner<ShenandoahAllCodeRootsIterator> ShenandoahAllRootScanner; |
147 typedef ShenandoahRootScanner<ShenandoahCsetCodeRootsIterator> ShenandoahCSetRootScanner; |
246 typedef ShenandoahRootScanner<ShenandoahCsetCodeRootsIterator> ShenandoahCSetRootScanner; |
148 |
247 |
|
248 // This scanner is only for SH::object_iteration() and only supports single-threaded |
|
249 // root scanning |
|
250 class ShenandoahHeapIterationRootScanner : public ShenandoahRootProcessor { |
|
251 private: |
|
252 ShenandoahSerialRoots _serial_roots; |
|
253 ShenandoahThreadRoots _thread_roots; |
|
254 ShenandoahVMRoots<false /*concurrent*/> _vm_roots; |
|
255 ShenandoahClassLoaderDataRoots<false /*concurrent*/, true /*single threaded*/> |
|
256 _cld_roots; |
|
257 ShenandoahSerialWeakRoots _serial_weak_roots; |
|
258 ShenandoahWeakRoots<false /*concurrent*/> _weak_roots; |
|
259 ShenandoahStringDedupRoots _dedup_roots; |
|
260 ShenandoahCodeCacheRoots<ShenandoahAllCodeRootsIterator> _code_roots; |
|
261 |
|
262 public: |
|
263 ShenandoahHeapIterationRootScanner(); |
|
264 |
|
265 void roots_do(OopClosure* cl); |
|
266 void strong_roots_do(OopClosure* cl); |
|
267 }; |
|
268 |
149 // Evacuate all roots at a safepoint |
269 // Evacuate all roots at a safepoint |
150 class ShenandoahRootEvacuator : public ShenandoahRootProcessor { |
270 class ShenandoahRootEvacuator : public ShenandoahRootProcessor { |
151 private: |
271 private: |
152 ShenandoahSerialRoots _serial_roots; |
272 ShenandoahSerialRoots _serial_roots; |
153 ShenandoahClassLoaderDataRoots _cld_roots; |
273 ShenandoahVMRoots<false /*concurrent*/> _vm_roots; |
154 ShenandoahThreadRoots _thread_roots; |
274 ShenandoahClassLoaderDataRoots<false /*concurrent*/, false /*single threaded*/> |
155 ShenandoahWeakRoots _weak_roots; |
275 _cld_roots; |
156 ShenandoahStringDedupRoots _dedup_roots; |
276 ShenandoahThreadRoots _thread_roots; |
|
277 ShenandoahSerialWeakRoots _serial_weak_roots; |
|
278 ShenandoahWeakRoots<false /*concurrent*/> _weak_roots; |
|
279 ShenandoahStringDedupRoots _dedup_roots; |
157 ShenandoahCodeCacheRoots<ShenandoahCsetCodeRootsIterator> _code_roots; |
280 ShenandoahCodeCacheRoots<ShenandoahCsetCodeRootsIterator> _code_roots; |
158 |
281 bool _include_concurrent_roots; |
159 public: |
282 |
160 ShenandoahRootEvacuator(uint n_workers, ShenandoahPhaseTimings::Phase phase); |
283 public: |
|
284 ShenandoahRootEvacuator(uint n_workers, ShenandoahPhaseTimings::Phase phase, bool include_concurrent_roots); |
161 |
285 |
162 void roots_do(uint worker_id, OopClosure* oops); |
286 void roots_do(uint worker_id, OopClosure* oops); |
163 }; |
287 }; |
164 |
288 |
165 // Update all roots at a safepoint |
289 // Update all roots at a safepoint |
166 class ShenandoahRootUpdater : public ShenandoahRootProcessor { |
290 class ShenandoahRootUpdater : public ShenandoahRootProcessor { |
167 private: |
291 private: |
168 ShenandoahSerialRoots _serial_roots; |
292 ShenandoahSerialRoots _serial_roots; |
169 ShenandoahClassLoaderDataRoots _cld_roots; |
293 ShenandoahVMRoots<false /*concurrent*/> _vm_roots; |
170 ShenandoahThreadRoots _thread_roots; |
294 ShenandoahClassLoaderDataRoots<false /*concurrent*/, false /*single threaded*/> |
171 ShenandoahWeakRoots _weak_roots; |
295 _cld_roots; |
172 ShenandoahStringDedupRoots _dedup_roots; |
296 ShenandoahThreadRoots _thread_roots; |
|
297 ShenandoahSerialWeakRoots _serial_weak_roots; |
|
298 ShenandoahWeakRoots<false /*concurrent*/> _weak_roots; |
|
299 ShenandoahStringDedupRoots _dedup_roots; |
173 ShenandoahCodeCacheRoots<ShenandoahCsetCodeRootsIterator> _code_roots; |
300 ShenandoahCodeCacheRoots<ShenandoahCsetCodeRootsIterator> _code_roots; |
174 const bool _update_code_cache; |
301 |
175 |
302 public: |
176 public: |
303 ShenandoahRootUpdater(uint n_workers, ShenandoahPhaseTimings::Phase phase); |
177 ShenandoahRootUpdater(uint n_workers, ShenandoahPhaseTimings::Phase phase, bool update_code_cache); |
|
178 |
304 |
179 template<typename IsAlive, typename KeepAlive> |
305 template<typename IsAlive, typename KeepAlive> |
180 void roots_do(uint worker_id, IsAlive* is_alive, KeepAlive* keep_alive); |
306 void roots_do(uint worker_id, IsAlive* is_alive, KeepAlive* keep_alive); |
181 }; |
307 }; |
182 |
308 |
183 // Adjuster all roots at a safepoint during full gc |
309 // Adjuster all roots at a safepoint during full gc |
184 class ShenandoahRootAdjuster : public ShenandoahRootProcessor { |
310 class ShenandoahRootAdjuster : public ShenandoahRootProcessor { |
185 private: |
311 private: |
186 ShenandoahSerialRoots _serial_roots; |
312 ShenandoahSerialRoots _serial_roots; |
187 ShenandoahClassLoaderDataRoots _cld_roots; |
313 ShenandoahVMRoots<false /*concurrent*/> _vm_roots; |
188 ShenandoahThreadRoots _thread_roots; |
314 ShenandoahClassLoaderDataRoots<false /*concurrent*/, false /*single threaded*/> |
189 ShenandoahWeakRoots _weak_roots; |
315 _cld_roots; |
190 ShenandoahStringDedupRoots _dedup_roots; |
316 ShenandoahThreadRoots _thread_roots; |
191 ShenandoahCodeCacheRoots<ShenandoahAllCodeRootsIterator> _code_roots; |
317 ShenandoahSerialWeakRoots _serial_weak_roots; |
|
318 ShenandoahWeakRoots<false /*concurrent*/> _weak_roots; |
|
319 ShenandoahStringDedupRoots _dedup_roots; |
|
320 ShenandoahCodeCacheRoots<ShenandoahAllCodeRootsIterator> _code_roots; |
192 |
321 |
193 public: |
322 public: |
194 ShenandoahRootAdjuster(uint n_workers, ShenandoahPhaseTimings::Phase phase); |
323 ShenandoahRootAdjuster(uint n_workers, ShenandoahPhaseTimings::Phase phase); |
195 |
324 |
196 void roots_do(uint worker_id, OopClosure* oops); |
325 void roots_do(uint worker_id, OopClosure* oops); |