comparison src/share/vm/memory/sharedHeap.hpp @ 23224:79b13c9a93e8

8075210: Refactor strong root processing in order to allow G1 to evolve separately from GenCollectedHeap Summary: Create a G1RootProcessor and move SharedHeap root processing to GenCollectedHeap Reviewed-by: brutisso, tschatzl, ehelin
author mgerdin
date Mon, 01 Dec 2014 15:24:56 +0100
parents 2c6ef90f030a
children dd9cc155639c
comparison
equal deleted inserted replaced
23223:8f8f1d578796 23224:79b13c9a93e8
59 // 2) SubTasksDone has a variable _n_threads that is used in 59 // 2) SubTasksDone has a variable _n_threads that is used in
60 // all_tasks_completed() to determine completion. all_tasks_complete() 60 // all_tasks_completed() to determine completion. all_tasks_complete()
61 // counts the number of tasks that have been done and then reset 61 // counts the number of tasks that have been done and then reset
62 // the SubTasksDone so that it can be used again. When the number of 62 // the SubTasksDone so that it can be used again. When the number of
63 // tasks is set to the number of GC workers, then _n_threads must 63 // tasks is set to the number of GC workers, then _n_threads must
64 // be set to the number of active GC workers. G1CollectedHeap, 64 // be set to the number of active GC workers. G1RootProcessor and
65 // HRInto_G1RemSet, GenCollectedHeap and SharedHeap have SubTasksDone. 65 // GenCollectedHeap have SubTasksDone.
66 // This seems too many.
67 // 3) SequentialSubTasksDone has an _n_threads that is used in 66 // 3) SequentialSubTasksDone has an _n_threads that is used in
68 // a way similar to SubTasksDone and has the same dependency on the 67 // a way similar to SubTasksDone and has the same dependency on the
69 // number of active GC workers. CompactibleFreeListSpace and Space 68 // number of active GC workers. CompactibleFreeListSpace and Space
70 // have SequentialSubTasksDone's. 69 // have SequentialSubTasksDone's.
71 // Example of using SubTasksDone and SequentialSubTasksDone 70 //
72 // G1CollectedHeap::g1_process_roots() 71 // Examples of using SubTasksDone and SequentialSubTasksDone:
73 // to SharedHeap::process_roots() and uses 72 // G1RootProcessor and GenCollectedHeap::process_roots() use
74 // SubTasksDone* _process_strong_tasks to claim tasks. 73 // SubTasksDone* _process_strong_tasks to claim tasks for workers
75 // process_roots() calls 74 //
75 // GenCollectedHeap::gen_process_roots() calls
76 // rem_set()->younger_refs_iterate() 76 // rem_set()->younger_refs_iterate()
77 // to scan the card table and which eventually calls down into 77 // to scan the card table and which eventually calls down into
78 // CardTableModRefBS::par_non_clean_card_iterate_work(). This method 78 // CardTableModRefBS::par_non_clean_card_iterate_work(). This method
79 // uses SequentialSubTasksDone* _pst to claim tasks. 79 // uses SequentialSubTasksDone* _pst to claim tasks.
80 // Both SubTasksDone and SequentialSubTasksDone call their method 80 // Both SubTasksDone and SequentialSubTasksDone call their method
102 friend class VMStructs; 102 friend class VMStructs;
103 103
104 friend class VM_GC_Operation; 104 friend class VM_GC_Operation;
105 friend class VM_CGC_Operation; 105 friend class VM_CGC_Operation;
106 106
107 private:
108 // For claiming strong_roots tasks.
109 SubTasksDone* _process_strong_tasks;
110
111 protected: 107 protected:
112 // There should be only a single instance of "SharedHeap" in a program. 108 // There should be only a single instance of "SharedHeap" in a program.
113 // This is enforced with the protected constructor below, which will also 109 // This is enforced with the protected constructor below, which will also
114 // set the static pointer "_sh" to that instance. 110 // set the static pointer "_sh" to that instance.
115 static SharedHeap* _sh; 111 static SharedHeap* _sh;
142 138
143 public: 139 public:
144 static SharedHeap* heap() { return _sh; } 140 static SharedHeap* heap() { return _sh; }
145 141
146 void set_barrier_set(BarrierSet* bs); 142 void set_barrier_set(BarrierSet* bs);
147 SubTasksDone* process_strong_tasks() { return _process_strong_tasks; }
148 143
149 // Does operations required after initialization has been done. 144 // Does operations required after initialization has been done.
150 virtual void post_initialize(); 145 virtual void post_initialize();
151 146
152 // Initialization of ("weak") reference processing support 147 // Initialization of ("weak") reference processing support
199 194
200 // Call these in sequential code around process_roots. 195 // Call these in sequential code around process_roots.
201 // strong_roots_prologue calls change_strong_roots_parity, if 196 // strong_roots_prologue calls change_strong_roots_parity, if
202 // parallel tasks are enabled. 197 // parallel tasks are enabled.
203 class StrongRootsScope : public MarkingCodeBlobClosure::MarkScope { 198 class StrongRootsScope : public MarkingCodeBlobClosure::MarkScope {
204 // Used to implement the Thread work barrier.
205 static Monitor* _lock;
206
207 SharedHeap* _sh; 199 SharedHeap* _sh;
208 volatile jint _n_workers_done_with_threads;
209 200
210 public: 201 public:
211 StrongRootsScope(SharedHeap* heap, bool activate = true); 202 StrongRootsScope(SharedHeap* heap, bool activate = true);
212 ~StrongRootsScope();
213
214 // Mark that this thread is done with the Threads work.
215 void mark_worker_done_with_threads(uint n_workers);
216 // Wait until all n_workers are done with the Threads work.
217 void wait_until_all_workers_done_with_threads(uint n_workers);
218 }; 203 };
219 friend class StrongRootsScope; 204 friend class StrongRootsScope;
220 205
221 // The current active StrongRootScope
222 StrongRootsScope* _strong_roots_scope;
223
224 StrongRootsScope* active_strong_roots_scope() const;
225
226 private: 206 private:
227 void register_strong_roots_scope(StrongRootsScope* scope);
228 void unregister_strong_roots_scope(StrongRootsScope* scope);
229 void change_strong_roots_parity(); 207 void change_strong_roots_parity();
230 208
231 public: 209 public:
232 enum ScanningOption {
233 SO_None = 0x0,
234 SO_AllCodeCache = 0x8,
235 SO_ScavengeCodeCache = 0x10
236 };
237
238 FlexibleWorkGang* workers() const { return _workers; } 210 FlexibleWorkGang* workers() const { return _workers; }
239
240 // Invoke the "do_oop" method the closure "roots" on all root locations.
241 // The "so" argument determines which roots the closure is applied to:
242 // "SO_None" does none;
243 // "SO_AllCodeCache" applies the closure to all elements of the CodeCache.
244 // "SO_ScavengeCodeCache" applies the closure to elements on the scavenge root list in the CodeCache.
245 void process_roots(bool activate_scope,
246 ScanningOption so,
247 OopClosure* strong_roots,
248 OopClosure* weak_roots,
249 CLDClosure* strong_cld_closure,
250 CLDClosure* weak_cld_closure,
251 CodeBlobClosure* code_roots);
252 void process_all_roots(bool activate_scope,
253 ScanningOption so,
254 OopClosure* roots,
255 CLDClosure* cld_closure,
256 CodeBlobClosure* code_roots);
257 void process_strong_roots(bool activate_scope,
258 ScanningOption so,
259 OopClosure* roots,
260 CLDClosure* cld_closure,
261 CodeBlobClosure* code_roots);
262
263
264 // Apply "root_closure" to the JNI weak roots..
265 void process_weak_roots(OopClosure* root_closure);
266 211
267 // The functions below are helper functions that a subclass of 212 // The functions below are helper functions that a subclass of
268 // "SharedHeap" can use in the implementation of its virtual 213 // "SharedHeap" can use in the implementation of its virtual
269 // functions. 214 // functions.
270 215
275 virtual void gc_epilogue(bool full) = 0; 220 virtual void gc_epilogue(bool full) = 0;
276 221
277 // Sets the number of parallel threads that will be doing tasks 222 // Sets the number of parallel threads that will be doing tasks
278 // (such as process roots) subsequently. 223 // (such as process roots) subsequently.
279 virtual void set_par_threads(uint t); 224 virtual void set_par_threads(uint t);
280
281 int n_termination();
282 void set_n_termination(int t);
283 225
284 // 226 //
285 // New methods from CollectedHeap 227 // New methods from CollectedHeap
286 // 228 //
287 229
290 size_t bytes_before, 232 size_t bytes_before,
291 size_t bytes_after, 233 size_t bytes_after,
292 size_t capacity); 234 size_t capacity);
293 }; 235 };
294 236
295 inline SharedHeap::ScanningOption operator|(SharedHeap::ScanningOption so0, SharedHeap::ScanningOption so1) {
296 return static_cast<SharedHeap::ScanningOption>(static_cast<int>(so0) | static_cast<int>(so1));
297 }
298
299 #endif // SHARE_VM_MEMORY_SHAREDHEAP_HPP 237 #endif // SHARE_VM_MEMORY_SHAREDHEAP_HPP