comparison src/share/vm/memory/sharedHeap.hpp @ 20804:7848fc12602b

Merge with jdk8u40-b25
author Gilles Duboscq <gilles.m.duboscq@oracle.com>
date Tue, 07 Apr 2015 14:58:49 +0200
parents 89152779163c 2c6ef90f030a
children dd9cc155639c
comparison
equal deleted inserted replaced
20184:84105dcdb05b 20804:7848fc12602b
67 // 3) SequentialSubTasksDone has an _n_threads that is used in 67 // 3) SequentialSubTasksDone has an _n_threads that is used in
68 // a way similar to SubTasksDone and has the same dependency on the 68 // a way similar to SubTasksDone and has the same dependency on the
69 // number of active GC workers. CompactibleFreeListSpace and Space 69 // number of active GC workers. CompactibleFreeListSpace and Space
70 // have SequentialSubTasksDone's. 70 // have SequentialSubTasksDone's.
71 // Example of using SubTasksDone and SequentialSubTasksDone 71 // Example of using SubTasksDone and SequentialSubTasksDone
72 // G1CollectedHeap::g1_process_strong_roots() calls 72 // G1CollectedHeap::g1_process_roots()
73 // process_strong_roots(false, // no scoping; this is parallel code 73 // to SharedHeap::process_roots() and uses
74 // is_scavenging, so,
75 // &buf_scan_non_heap_roots,
76 // &eager_scan_code_roots);
77 // which delegates to SharedHeap::process_strong_roots() and uses
78 // SubTasksDone* _process_strong_tasks to claim tasks. 74 // SubTasksDone* _process_strong_tasks to claim tasks.
79 // process_strong_roots() calls 75 // process_roots() calls
80 // rem_set()->younger_refs_iterate() 76 // rem_set()->younger_refs_iterate()
81 // to scan the card table and which eventually calls down into 77 // to scan the card table and which eventually calls down into
82 // CardTableModRefBS::par_non_clean_card_iterate_work(). This method 78 // CardTableModRefBS::par_non_clean_card_iterate_work(). This method
83 // uses SequentialSubTasksDone* _pst to claim tasks. 79 // uses SequentialSubTasksDone* _pst to claim tasks.
84 // Both SubTasksDone and SequentialSubTasksDone call their method 80 // Both SubTasksDone and SequentialSubTasksDone call their method
161 GenRemSet* rem_set() { return _rem_set; } 157 GenRemSet* rem_set() { return _rem_set; }
162 158
163 // Iteration functions. 159 // Iteration functions.
164 void oop_iterate(ExtendedOopClosure* cl) = 0; 160 void oop_iterate(ExtendedOopClosure* cl) = 0;
165 161
166 // Same as above, restricted to a memory region.
167 virtual void oop_iterate(MemRegion mr, ExtendedOopClosure* cl) = 0;
168
169 // Iterate over all spaces in use in the heap, in an undefined order. 162 // Iterate over all spaces in use in the heap, in an undefined order.
170 virtual void space_iterate(SpaceClosure* cl) = 0; 163 virtual void space_iterate(SpaceClosure* cl) = 0;
171 164
172 // A SharedHeap will contain some number of spaces. This finds the 165 // A SharedHeap will contain some number of spaces. This finds the
173 // space whose reserved area contains the given address, or else returns 166 // space whose reserved area contains the given address, or else returns
183 // whose threads invoke "process_strong_roots" must 176 // whose threads invoke "process_strong_roots" must
184 // call "change_strong_roots_parity" in sequential code starting such a 177 // call "change_strong_roots_parity" in sequential code starting such a
185 // task. (This also means that a parallel thread may only call 178 // task. (This also means that a parallel thread may only call
186 // process_strong_roots once.) 179 // process_strong_roots once.)
187 // 180 //
188 // For calls to process_strong_roots by sequential code, the parity is 181 // For calls to process_roots by sequential code, the parity is
189 // updated automatically. 182 // updated automatically.
190 // 183 //
191 // The idea is that objects representing fine-grained tasks, such as 184 // The idea is that objects representing fine-grained tasks, such as
192 // threads, will contain a "parity" field. A task will is claimed in the 185 // threads, will contain a "parity" field. A task will is claimed in the
193 // current "process_strong_roots" call only if its parity field is the 186 // current "process_roots" call only if its parity field is the
194 // same as the "strong_roots_parity"; task claiming is accomplished by 187 // same as the "strong_roots_parity"; task claiming is accomplished by
195 // updating the parity field to the strong_roots_parity with a CAS. 188 // updating the parity field to the strong_roots_parity with a CAS.
196 // 189 //
197 // If the client meats this spec, then strong_roots_parity() will have 190 // If the client meats this spec, then strong_roots_parity() will have
198 // the following properties: 191 // the following properties:
199 // a) to return a different value than was returned before the last 192 // a) to return a different value than was returned before the last
200 // call to change_strong_roots_parity, and 193 // call to change_strong_roots_parity, and
201 // c) to never return a distinguished value (zero) with which such 194 // c) to never return a distinguished value (zero) with which such
202 // task-claiming variables may be initialized, to indicate "never 195 // task-claiming variables may be initialized, to indicate "never
203 // claimed". 196 // claimed".
204 private:
205 void change_strong_roots_parity();
206 public: 197 public:
207 int strong_roots_parity() { return _strong_roots_parity; } 198 int strong_roots_parity() { return _strong_roots_parity; }
208 199
209 // Call these in sequential code around process_strong_roots. 200 // Call these in sequential code around process_roots.
210 // strong_roots_prologue calls change_strong_roots_parity, if 201 // strong_roots_prologue calls change_strong_roots_parity, if
211 // parallel tasks are enabled. 202 // parallel tasks are enabled.
212 class StrongRootsScope : public MarkingCodeBlobClosure::MarkScope { 203 class StrongRootsScope : public MarkingCodeBlobClosure::MarkScope {
213 public: 204 // Used to implement the Thread work barrier.
214 StrongRootsScope(SharedHeap* outer, bool activate = true); 205 static Monitor* _lock;
206
207 SharedHeap* _sh;
208 volatile jint _n_workers_done_with_threads;
209
210 public:
211 StrongRootsScope(SharedHeap* heap, bool activate = true);
215 ~StrongRootsScope(); 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);
216 }; 218 };
217 friend class StrongRootsScope; 219 friend class StrongRootsScope;
218 220
221 // The current active StrongRootScope
222 StrongRootsScope* _strong_roots_scope;
223
224 StrongRootsScope* active_strong_roots_scope() const;
225
226 private:
227 void register_strong_roots_scope(StrongRootsScope* scope);
228 void unregister_strong_roots_scope(StrongRootsScope* scope);
229 void change_strong_roots_parity();
230
231 public:
219 enum ScanningOption { 232 enum ScanningOption {
220 SO_None = 0x0, 233 SO_None = 0x0,
221 SO_AllClasses = 0x1, 234 SO_AllCodeCache = 0x8,
222 SO_SystemClasses = 0x2, 235 SO_ScavengeCodeCache = 0x10
223 SO_Strings = 0x4,
224 SO_CodeCache = 0x8
225 }; 236 };
226 237
227 FlexibleWorkGang* workers() const { return _workers; } 238 FlexibleWorkGang* workers() const { return _workers; }
228 239
229 // Invoke the "do_oop" method the closure "roots" on all root locations. 240 // Invoke the "do_oop" method the closure "roots" on all root locations.
230 // The "so" argument determines which roots the closure is applied to: 241 // The "so" argument determines which roots the closure is applied to:
231 // "SO_None" does none; 242 // "SO_None" does none;
232 // "SO_AllClasses" applies the closure to all entries in the SystemDictionary; 243 // "SO_AllCodeCache" applies the closure to all elements of the CodeCache.
233 // "SO_SystemClasses" to all the "system" classes and loaders; 244 // "SO_ScavengeCodeCache" applies the closure to elements on the scavenge root list in the CodeCache.
234 // "SO_Strings" applies the closure to all entries in StringTable; 245 void process_roots(bool activate_scope,
235 // "SO_CodeCache" applies the closure to all elements of the CodeCache. 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);
236 void process_strong_roots(bool activate_scope, 257 void process_strong_roots(bool activate_scope,
237 bool is_scavenging,
238 ScanningOption so, 258 ScanningOption so,
239 OopClosure* roots, 259 OopClosure* roots,
240 CodeBlobClosure* code_roots, 260 CLDClosure* cld_closure,
241 KlassClosure* klass_closure); 261 CodeBlobClosure* code_roots);
242 262
243 // Apply "blk" to all the weak roots of the system. These include 263
244 // JNI weak roots, the code cache, system dictionary, symbol table, 264 // Apply "root_closure" to the JNI weak roots..
245 // string table. 265 void process_weak_roots(OopClosure* root_closure);
246 void process_weak_roots(OopClosure* root_closure,
247 CodeBlobClosure* code_roots);
248 266
249 // The functions below are helper functions that a subclass of 267 // The functions below are helper functions that a subclass of
250 // "SharedHeap" can use in the implementation of its virtual 268 // "SharedHeap" can use in the implementation of its virtual
251 // functions. 269 // functions.
252 270
255 // Do anything common to GC's. 273 // Do anything common to GC's.
256 virtual void gc_prologue(bool full) = 0; 274 virtual void gc_prologue(bool full) = 0;
257 virtual void gc_epilogue(bool full) = 0; 275 virtual void gc_epilogue(bool full) = 0;
258 276
259 // Sets the number of parallel threads that will be doing tasks 277 // Sets the number of parallel threads that will be doing tasks
260 // (such as process strong roots) subsequently. 278 // (such as process roots) subsequently.
261 virtual void set_par_threads(uint t); 279 virtual void set_par_threads(uint t);
262 280
263 int n_termination(); 281 int n_termination();
264 void set_n_termination(int t); 282 void set_n_termination(int t);
265 283
272 size_t bytes_before, 290 size_t bytes_before,
273 size_t bytes_after, 291 size_t bytes_after,
274 size_t capacity); 292 size_t capacity);
275 }; 293 };
276 294
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
277 #endif // SHARE_VM_MEMORY_SHAREDHEAP_HPP 299 #endif // SHARE_VM_MEMORY_SHAREDHEAP_HPP