Mercurial > hg > truffle
annotate src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp @ 796:29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
Reviewed-by: iveresov, tonyp
author | apetrusenko |
---|---|
date | Tue, 19 May 2009 04:05:31 -0700 |
parents | 4ac7d97e6101 |
children | d44bdab1c03d |
rev | line source |
---|---|
342 | 1 /* |
579 | 2 * Copyright 2001-2009 Sun Microsystems, Inc. All Rights Reserved. |
342 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 // A "G1CollectedHeap" is an implementation of a java heap for HotSpot. | |
26 // It uses the "Garbage First" heap organization and algorithm, which | |
27 // may combine concurrent marking with parallel, incremental compaction of | |
28 // heap subsets that will yield large amounts of garbage. | |
29 | |
30 class HeapRegion; | |
31 class HeapRegionSeq; | |
32 class PermanentGenerationSpec; | |
33 class GenerationSpec; | |
34 class OopsInHeapRegionClosure; | |
35 class G1ScanHeapEvacClosure; | |
36 class ObjectClosure; | |
37 class SpaceClosure; | |
38 class CompactibleSpaceClosure; | |
39 class Space; | |
40 class G1CollectorPolicy; | |
41 class GenRemSet; | |
42 class G1RemSet; | |
43 class HeapRegionRemSetIterator; | |
44 class ConcurrentMark; | |
45 class ConcurrentMarkThread; | |
46 class ConcurrentG1Refine; | |
47 class ConcurrentZFThread; | |
48 | |
49 // If want to accumulate detailed statistics on work queues | |
50 // turn this on. | |
51 #define G1_DETAILED_STATS 0 | |
52 | |
53 #if G1_DETAILED_STATS | |
54 # define IF_G1_DETAILED_STATS(code) code | |
55 #else | |
56 # define IF_G1_DETAILED_STATS(code) | |
57 #endif | |
58 | |
59 typedef GenericTaskQueue<oop*> RefToScanQueue; | |
60 typedef GenericTaskQueueSet<oop*> RefToScanQueueSet; | |
61 | |
62 enum G1GCThreadGroups { | |
63 G1CRGroup = 0, | |
64 G1ZFGroup = 1, | |
65 G1CMGroup = 2, | |
66 G1CLGroup = 3 | |
67 }; | |
68 | |
69 enum GCAllocPurpose { | |
70 GCAllocForTenured, | |
71 GCAllocForSurvived, | |
72 GCAllocPurposeCount | |
73 }; | |
74 | |
75 class YoungList : public CHeapObj { | |
76 private: | |
77 G1CollectedHeap* _g1h; | |
78 | |
79 HeapRegion* _head; | |
80 | |
81 HeapRegion* _scan_only_head; | |
82 HeapRegion* _scan_only_tail; | |
83 size_t _length; | |
84 size_t _scan_only_length; | |
85 | |
86 size_t _last_sampled_rs_lengths; | |
87 size_t _sampled_rs_lengths; | |
88 HeapRegion* _curr; | |
89 HeapRegion* _curr_scan_only; | |
90 | |
91 HeapRegion* _survivor_head; | |
545 | 92 HeapRegion* _survivor_tail; |
342 | 93 size_t _survivor_length; |
94 | |
95 void empty_list(HeapRegion* list); | |
96 | |
97 public: | |
98 YoungList(G1CollectedHeap* g1h); | |
99 | |
100 void push_region(HeapRegion* hr); | |
101 void add_survivor_region(HeapRegion* hr); | |
102 HeapRegion* pop_region(); | |
103 void empty_list(); | |
104 bool is_empty() { return _length == 0; } | |
105 size_t length() { return _length; } | |
106 size_t scan_only_length() { return _scan_only_length; } | |
545 | 107 size_t survivor_length() { return _survivor_length; } |
342 | 108 |
109 void rs_length_sampling_init(); | |
110 bool rs_length_sampling_more(); | |
111 void rs_length_sampling_next(); | |
112 | |
113 void reset_sampled_info() { | |
114 _last_sampled_rs_lengths = 0; | |
115 } | |
116 size_t sampled_rs_lengths() { return _last_sampled_rs_lengths; } | |
117 | |
118 // for development purposes | |
119 void reset_auxilary_lists(); | |
120 HeapRegion* first_region() { return _head; } | |
121 HeapRegion* first_scan_only_region() { return _scan_only_head; } | |
122 HeapRegion* first_survivor_region() { return _survivor_head; } | |
545 | 123 HeapRegion* last_survivor_region() { return _survivor_tail; } |
342 | 124 HeapRegion* par_get_next_scan_only_region() { |
125 MutexLockerEx x(ParGCRareEvent_lock, Mutex::_no_safepoint_check_flag); | |
126 HeapRegion* ret = _curr_scan_only; | |
127 if (ret != NULL) | |
128 _curr_scan_only = ret->get_next_young_region(); | |
129 return ret; | |
130 } | |
131 | |
132 // debugging | |
133 bool check_list_well_formed(); | |
134 bool check_list_empty(bool ignore_scan_only_list, | |
135 bool check_sample = true); | |
136 void print(); | |
137 }; | |
138 | |
139 class RefineCardTableEntryClosure; | |
140 class G1CollectedHeap : public SharedHeap { | |
141 friend class VM_G1CollectForAllocation; | |
142 friend class VM_GenCollectForPermanentAllocation; | |
143 friend class VM_G1CollectFull; | |
144 friend class VM_G1IncCollectionPause; | |
145 friend class VMStructs; | |
146 | |
147 // Closures used in implementation. | |
148 friend class G1ParCopyHelper; | |
149 friend class G1IsAliveClosure; | |
150 friend class G1EvacuateFollowersClosure; | |
151 friend class G1ParScanThreadState; | |
152 friend class G1ParScanClosureSuper; | |
153 friend class G1ParEvacuateFollowersClosure; | |
154 friend class G1ParTask; | |
155 friend class G1FreeGarbageRegionClosure; | |
156 friend class RefineCardTableEntryClosure; | |
157 friend class G1PrepareCompactClosure; | |
158 friend class RegionSorter; | |
159 friend class CountRCClosure; | |
160 friend class EvacPopObjClosure; | |
796
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
678
diff
changeset
|
161 friend class G1ParCleanupCTTask; |
342 | 162 |
163 // Other related classes. | |
164 friend class G1MarkSweep; | |
165 | |
166 private: | |
167 enum SomePrivateConstants { | |
168 VeryLargeInBytes = HeapRegion::GrainBytes/2, | |
169 VeryLargeInWords = VeryLargeInBytes/HeapWordSize, | |
170 MinHeapDeltaBytes = 10 * HeapRegion::GrainBytes, // FIXME | |
171 NumAPIs = HeapRegion::MaxAge | |
172 }; | |
173 | |
174 // The one and only G1CollectedHeap, so static functions can find it. | |
175 static G1CollectedHeap* _g1h; | |
176 | |
177 // Storage for the G1 heap (excludes the permanent generation). | |
178 VirtualSpace _g1_storage; | |
179 MemRegion _g1_reserved; | |
180 | |
181 // The part of _g1_storage that is currently committed. | |
182 MemRegion _g1_committed; | |
183 | |
184 // The maximum part of _g1_storage that has ever been committed. | |
185 MemRegion _g1_max_committed; | |
186 | |
187 // The number of regions that are completely free. | |
188 size_t _free_regions; | |
189 | |
190 // The number of regions we could create by expansion. | |
191 size_t _expansion_regions; | |
192 | |
193 // Return the number of free regions in the heap (by direct counting.) | |
194 size_t count_free_regions(); | |
195 // Return the number of free regions on the free and unclean lists. | |
196 size_t count_free_regions_list(); | |
197 | |
198 // The block offset table for the G1 heap. | |
199 G1BlockOffsetSharedArray* _bot_shared; | |
200 | |
201 // Move all of the regions off the free lists, then rebuild those free | |
202 // lists, before and after full GC. | |
203 void tear_down_region_lists(); | |
204 void rebuild_region_lists(); | |
205 // This sets all non-empty regions to need zero-fill (which they will if | |
206 // they are empty after full collection.) | |
207 void set_used_regions_to_need_zero_fill(); | |
208 | |
209 // The sequence of all heap regions in the heap. | |
210 HeapRegionSeq* _hrs; | |
211 | |
212 // The region from which normal-sized objects are currently being | |
213 // allocated. May be NULL. | |
214 HeapRegion* _cur_alloc_region; | |
215 | |
216 // Postcondition: cur_alloc_region == NULL. | |
217 void abandon_cur_alloc_region(); | |
636 | 218 void abandon_gc_alloc_regions(); |
342 | 219 |
220 // The to-space memory regions into which objects are being copied during | |
221 // a GC. | |
222 HeapRegion* _gc_alloc_regions[GCAllocPurposeCount]; | |
545 | 223 size_t _gc_alloc_region_counts[GCAllocPurposeCount]; |
636 | 224 // These are the regions, one per GCAllocPurpose, that are half-full |
225 // at the end of a collection and that we want to reuse during the | |
226 // next collection. | |
227 HeapRegion* _retained_gc_alloc_regions[GCAllocPurposeCount]; | |
228 // This specifies whether we will keep the last half-full region at | |
229 // the end of a collection so that it can be reused during the next | |
230 // collection (this is specified per GCAllocPurpose) | |
231 bool _retain_gc_alloc_region[GCAllocPurposeCount]; | |
342 | 232 |
233 // A list of the regions that have been set to be alloc regions in the | |
234 // current collection. | |
235 HeapRegion* _gc_alloc_region_list; | |
236 | |
237 // When called by par thread, require par_alloc_during_gc_lock() to be held. | |
238 void push_gc_alloc_region(HeapRegion* hr); | |
239 | |
240 // This should only be called single-threaded. Undeclares all GC alloc | |
241 // regions. | |
242 void forget_alloc_region_list(); | |
243 | |
244 // Should be used to set an alloc region, because there's other | |
245 // associated bookkeeping. | |
246 void set_gc_alloc_region(int purpose, HeapRegion* r); | |
247 | |
248 // Check well-formedness of alloc region list. | |
249 bool check_gc_alloc_regions(); | |
250 | |
251 // Outside of GC pauses, the number of bytes used in all regions other | |
252 // than the current allocation region. | |
253 size_t _summary_bytes_used; | |
254 | |
526 | 255 // This is used for a quick test on whether a reference points into |
256 // the collection set or not. Basically, we have an array, with one | |
257 // byte per region, and that byte denotes whether the corresponding | |
258 // region is in the collection set or not. The entry corresponding | |
259 // the bottom of the heap, i.e., region 0, is pointed to by | |
260 // _in_cset_fast_test_base. The _in_cset_fast_test field has been | |
261 // biased so that it actually points to address 0 of the address | |
262 // space, to make the test as fast as possible (we can simply shift | |
263 // the address to address into it, instead of having to subtract the | |
264 // bottom of the heap from the address before shifting it; basically | |
265 // it works in the same way the card table works). | |
266 bool* _in_cset_fast_test; | |
267 | |
268 // The allocated array used for the fast test on whether a reference | |
269 // points into the collection set or not. This field is also used to | |
270 // free the array. | |
271 bool* _in_cset_fast_test_base; | |
272 | |
273 // The length of the _in_cset_fast_test_base array. | |
274 size_t _in_cset_fast_test_length; | |
275 | |
353
9bb2c10ac07b
6723570: G1: assertion failure: p == current_top or oop(p)->is_oop(),"p is not a block start" (revisited!)
iveresov
parents:
342
diff
changeset
|
276 volatile unsigned _gc_time_stamp; |
342 | 277 |
278 size_t* _surviving_young_words; | |
279 | |
280 void setup_surviving_young_words(); | |
281 void update_surviving_young_words(size_t* surv_young_words); | |
282 void cleanup_surviving_young_words(); | |
283 | |
284 protected: | |
285 | |
286 // Returns "true" iff none of the gc alloc regions have any allocations | |
287 // since the last call to "save_marks". | |
288 bool all_alloc_regions_no_allocs_since_save_marks(); | |
545 | 289 // Perform finalization stuff on all allocation regions. |
290 void retire_all_alloc_regions(); | |
342 | 291 |
292 // The number of regions allocated to hold humongous objects. | |
293 int _num_humongous_regions; | |
294 YoungList* _young_list; | |
295 | |
296 // The current policy object for the collector. | |
297 G1CollectorPolicy* _g1_policy; | |
298 | |
299 // Parallel allocation lock to protect the current allocation region. | |
300 Mutex _par_alloc_during_gc_lock; | |
301 Mutex* par_alloc_during_gc_lock() { return &_par_alloc_during_gc_lock; } | |
302 | |
303 // If possible/desirable, allocate a new HeapRegion for normal object | |
304 // allocation sufficient for an allocation of the given "word_size". | |
305 // If "do_expand" is true, will attempt to expand the heap if necessary | |
306 // to to satisfy the request. If "zero_filled" is true, requires a | |
307 // zero-filled region. | |
308 // (Returning NULL will trigger a GC.) | |
309 virtual HeapRegion* newAllocRegion_work(size_t word_size, | |
310 bool do_expand, | |
311 bool zero_filled); | |
312 | |
313 virtual HeapRegion* newAllocRegion(size_t word_size, | |
314 bool zero_filled = true) { | |
315 return newAllocRegion_work(word_size, false, zero_filled); | |
316 } | |
317 virtual HeapRegion* newAllocRegionWithExpansion(int purpose, | |
318 size_t word_size, | |
319 bool zero_filled = true); | |
320 | |
321 // Attempt to allocate an object of the given (very large) "word_size". | |
322 // Returns "NULL" on failure. | |
323 virtual HeapWord* humongousObjAllocate(size_t word_size); | |
324 | |
325 // If possible, allocate a block of the given word_size, else return "NULL". | |
326 // Returning NULL will trigger GC or heap expansion. | |
327 // These two methods have rather awkward pre- and | |
328 // post-conditions. If they are called outside a safepoint, then | |
329 // they assume that the caller is holding the heap lock. Upon return | |
330 // they release the heap lock, if they are returning a non-NULL | |
331 // value. attempt_allocation_slow() also dirties the cards of a | |
332 // newly-allocated young region after it releases the heap | |
333 // lock. This change in interface was the neatest way to achieve | |
334 // this card dirtying without affecting mem_allocate(), which is a | |
335 // more frequently called method. We tried two or three different | |
336 // approaches, but they were even more hacky. | |
337 HeapWord* attempt_allocation(size_t word_size, | |
338 bool permit_collection_pause = true); | |
339 | |
340 HeapWord* attempt_allocation_slow(size_t word_size, | |
341 bool permit_collection_pause = true); | |
342 | |
343 // Allocate blocks during garbage collection. Will ensure an | |
344 // allocation region, either by picking one or expanding the | |
345 // heap, and then allocate a block of the given size. The block | |
346 // may not be a humongous - it must fit into a single heap region. | |
347 HeapWord* allocate_during_gc(GCAllocPurpose purpose, size_t word_size); | |
348 HeapWord* par_allocate_during_gc(GCAllocPurpose purpose, size_t word_size); | |
349 | |
350 HeapWord* allocate_during_gc_slow(GCAllocPurpose purpose, | |
351 HeapRegion* alloc_region, | |
352 bool par, | |
353 size_t word_size); | |
354 | |
355 // Ensure that no further allocations can happen in "r", bearing in mind | |
356 // that parallel threads might be attempting allocations. | |
357 void par_allocate_remaining_space(HeapRegion* r); | |
358 | |
545 | 359 // Retires an allocation region when it is full or at the end of a |
360 // GC pause. | |
361 void retire_alloc_region(HeapRegion* alloc_region, bool par); | |
362 | |
342 | 363 // Helper function for two callbacks below. |
364 // "full", if true, indicates that the GC is for a System.gc() request, | |
365 // and should collect the entire heap. If "clear_all_soft_refs" is true, | |
366 // all soft references are cleared during the GC. If "full" is false, | |
367 // "word_size" describes the allocation that the GC should | |
368 // attempt (at least) to satisfy. | |
369 void do_collection(bool full, bool clear_all_soft_refs, | |
370 size_t word_size); | |
371 | |
372 // Callback from VM_G1CollectFull operation. | |
373 // Perform a full collection. | |
374 void do_full_collection(bool clear_all_soft_refs); | |
375 | |
376 // Resize the heap if necessary after a full collection. If this is | |
377 // after a collect-for allocation, "word_size" is the allocation size, | |
378 // and will be considered part of the used portion of the heap. | |
379 void resize_if_necessary_after_full_collection(size_t word_size); | |
380 | |
381 // Callback from VM_G1CollectForAllocation operation. | |
382 // This function does everything necessary/possible to satisfy a | |
383 // failed allocation request (including collection, expansion, etc.) | |
384 HeapWord* satisfy_failed_allocation(size_t word_size); | |
385 | |
386 // Attempting to expand the heap sufficiently | |
387 // to support an allocation of the given "word_size". If | |
388 // successful, perform the allocation and return the address of the | |
389 // allocated block, or else "NULL". | |
390 virtual HeapWord* expand_and_allocate(size_t word_size); | |
391 | |
392 public: | |
393 // Expand the garbage-first heap by at least the given size (in bytes!). | |
394 // (Rounds up to a HeapRegion boundary.) | |
395 virtual void expand(size_t expand_bytes); | |
396 | |
397 // Do anything common to GC's. | |
398 virtual void gc_prologue(bool full); | |
399 virtual void gc_epilogue(bool full); | |
400 | |
526 | 401 // We register a region with the fast "in collection set" test. We |
402 // simply set to true the array slot corresponding to this region. | |
403 void register_region_with_in_cset_fast_test(HeapRegion* r) { | |
404 assert(_in_cset_fast_test_base != NULL, "sanity"); | |
405 assert(r->in_collection_set(), "invariant"); | |
406 int index = r->hrs_index(); | |
407 assert(0 <= (size_t) index && (size_t) index < _in_cset_fast_test_length, | |
408 "invariant"); | |
409 assert(!_in_cset_fast_test_base[index], "invariant"); | |
410 _in_cset_fast_test_base[index] = true; | |
411 } | |
412 | |
413 // This is a fast test on whether a reference points into the | |
414 // collection set or not. It does not assume that the reference | |
415 // points into the heap; if it doesn't, it will return false. | |
416 bool in_cset_fast_test(oop obj) { | |
417 assert(_in_cset_fast_test != NULL, "sanity"); | |
418 if (_g1_committed.contains((HeapWord*) obj)) { | |
419 // no need to subtract the bottom of the heap from obj, | |
420 // _in_cset_fast_test is biased | |
421 size_t index = ((size_t) obj) >> HeapRegion::LogOfHRGrainBytes; | |
422 bool ret = _in_cset_fast_test[index]; | |
423 // let's make sure the result is consistent with what the slower | |
424 // test returns | |
425 assert( ret || !obj_in_cs(obj), "sanity"); | |
426 assert(!ret || obj_in_cs(obj), "sanity"); | |
427 return ret; | |
428 } else { | |
429 return false; | |
430 } | |
431 } | |
432 | |
342 | 433 protected: |
434 | |
435 // Shrink the garbage-first heap by at most the given size (in bytes!). | |
436 // (Rounds down to a HeapRegion boundary.) | |
437 virtual void shrink(size_t expand_bytes); | |
438 void shrink_helper(size_t expand_bytes); | |
439 | |
440 // Do an incremental collection: identify a collection set, and evacuate | |
441 // its live objects elsewhere. | |
442 virtual void do_collection_pause(); | |
443 | |
444 // The guts of the incremental collection pause, executed by the vm | |
677 | 445 // thread. |
446 virtual void do_collection_pause_at_safepoint(); | |
342 | 447 |
448 // Actually do the work of evacuating the collection set. | |
449 virtual void evacuate_collection_set(); | |
450 | |
451 // If this is an appropriate right time, do a collection pause. | |
452 // The "word_size" argument, if non-zero, indicates the size of an | |
453 // allocation request that is prompting this query. | |
454 void do_collection_pause_if_appropriate(size_t word_size); | |
455 | |
456 // The g1 remembered set of the heap. | |
457 G1RemSet* _g1_rem_set; | |
458 // And it's mod ref barrier set, used to track updates for the above. | |
459 ModRefBarrierSet* _mr_bs; | |
460 | |
616
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
545
diff
changeset
|
461 // A set of cards that cover the objects for which the Rsets should be updated |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
545
diff
changeset
|
462 // concurrently after the collection. |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
545
diff
changeset
|
463 DirtyCardQueueSet _dirty_card_queue_set; |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
545
diff
changeset
|
464 |
342 | 465 // The Heap Region Rem Set Iterator. |
466 HeapRegionRemSetIterator** _rem_set_iterator; | |
467 | |
468 // The closure used to refine a single card. | |
469 RefineCardTableEntryClosure* _refine_cte_cl; | |
470 | |
471 // A function to check the consistency of dirty card logs. | |
472 void check_ct_logs_at_safepoint(); | |
473 | |
474 // After a collection pause, make the regions in the CS into free | |
475 // regions. | |
476 void free_collection_set(HeapRegion* cs_head); | |
477 | |
478 // Applies "scan_non_heap_roots" to roots outside the heap, | |
479 // "scan_rs" to roots inside the heap (having done "set_region" to | |
480 // indicate the region in which the root resides), and does "scan_perm" | |
481 // (setting the generation to the perm generation.) If "scan_rs" is | |
482 // NULL, then this step is skipped. The "worker_i" | |
483 // param is for use with parallel roots processing, and should be | |
484 // the "i" of the calling parallel worker thread's work(i) function. | |
485 // In the sequential case this param will be ignored. | |
486 void g1_process_strong_roots(bool collecting_perm_gen, | |
487 SharedHeap::ScanningOption so, | |
488 OopClosure* scan_non_heap_roots, | |
489 OopsInHeapRegionClosure* scan_rs, | |
490 OopsInHeapRegionClosure* scan_so, | |
491 OopsInGenClosure* scan_perm, | |
492 int worker_i); | |
493 | |
494 void scan_scan_only_set(OopsInHeapRegionClosure* oc, | |
495 int worker_i); | |
496 void scan_scan_only_region(HeapRegion* hr, | |
497 OopsInHeapRegionClosure* oc, | |
498 int worker_i); | |
499 | |
500 // Apply "blk" to all the weak roots of the system. These include | |
501 // JNI weak roots, the code cache, system dictionary, symbol table, | |
502 // string table, and referents of reachable weak refs. | |
503 void g1_process_weak_roots(OopClosure* root_closure, | |
504 OopClosure* non_root_closure); | |
505 | |
506 // Invoke "save_marks" on all heap regions. | |
507 void save_marks(); | |
508 | |
509 // Free a heap region. | |
510 void free_region(HeapRegion* hr); | |
511 // A component of "free_region", exposed for 'batching'. | |
512 // All the params after "hr" are out params: the used bytes of the freed | |
513 // region(s), the number of H regions cleared, the number of regions | |
514 // freed, and pointers to the head and tail of a list of freed contig | |
515 // regions, linked throught the "next_on_unclean_list" field. | |
516 void free_region_work(HeapRegion* hr, | |
517 size_t& pre_used, | |
518 size_t& cleared_h, | |
519 size_t& freed_regions, | |
520 UncleanRegionList* list, | |
521 bool par = false); | |
522 | |
523 | |
524 // The concurrent marker (and the thread it runs in.) | |
525 ConcurrentMark* _cm; | |
526 ConcurrentMarkThread* _cmThread; | |
527 bool _mark_in_progress; | |
528 | |
529 // The concurrent refiner. | |
530 ConcurrentG1Refine* _cg1r; | |
531 | |
532 // The concurrent zero-fill thread. | |
533 ConcurrentZFThread* _czft; | |
534 | |
535 // The parallel task queues | |
536 RefToScanQueueSet *_task_queues; | |
537 | |
538 // True iff a evacuation has failed in the current collection. | |
539 bool _evacuation_failed; | |
540 | |
541 // Set the attribute indicating whether evacuation has failed in the | |
542 // current collection. | |
543 void set_evacuation_failed(bool b) { _evacuation_failed = b; } | |
544 | |
545 // Failed evacuations cause some logical from-space objects to have | |
546 // forwarding pointers to themselves. Reset them. | |
547 void remove_self_forwarding_pointers(); | |
548 | |
549 // When one is non-null, so is the other. Together, they each pair is | |
550 // an object with a preserved mark, and its mark value. | |
551 GrowableArray<oop>* _objs_with_preserved_marks; | |
552 GrowableArray<markOop>* _preserved_marks_of_objs; | |
553 | |
554 // Preserve the mark of "obj", if necessary, in preparation for its mark | |
555 // word being overwritten with a self-forwarding-pointer. | |
556 void preserve_mark_if_necessary(oop obj, markOop m); | |
557 | |
558 // The stack of evac-failure objects left to be scanned. | |
559 GrowableArray<oop>* _evac_failure_scan_stack; | |
560 // The closure to apply to evac-failure objects. | |
561 | |
562 OopsInHeapRegionClosure* _evac_failure_closure; | |
563 // Set the field above. | |
564 void | |
565 set_evac_failure_closure(OopsInHeapRegionClosure* evac_failure_closure) { | |
566 _evac_failure_closure = evac_failure_closure; | |
567 } | |
568 | |
569 // Push "obj" on the scan stack. | |
570 void push_on_evac_failure_scan_stack(oop obj); | |
571 // Process scan stack entries until the stack is empty. | |
572 void drain_evac_failure_scan_stack(); | |
573 // True iff an invocation of "drain_scan_stack" is in progress; to | |
574 // prevent unnecessary recursion. | |
575 bool _drain_in_progress; | |
576 | |
577 // Do any necessary initialization for evacuation-failure handling. | |
578 // "cl" is the closure that will be used to process evac-failure | |
579 // objects. | |
580 void init_for_evac_failure(OopsInHeapRegionClosure* cl); | |
581 // Do any necessary cleanup for evacuation-failure handling data | |
582 // structures. | |
583 void finalize_for_evac_failure(); | |
584 | |
585 // An attempt to evacuate "obj" has failed; take necessary steps. | |
586 void handle_evacuation_failure(oop obj); | |
587 oop handle_evacuation_failure_par(OopsInHeapRegionClosure* cl, oop obj); | |
588 void handle_evacuation_failure_common(oop obj, markOop m); | |
589 | |
590 | |
591 // Ensure that the relevant gc_alloc regions are set. | |
592 void get_gc_alloc_regions(); | |
636 | 593 // We're done with GC alloc regions. We are going to tear down the |
594 // gc alloc list and remove the gc alloc tag from all the regions on | |
595 // that list. However, we will also retain the last (i.e., the one | |
596 // that is half-full) GC alloc region, per GCAllocPurpose, for | |
597 // possible reuse during the next collection, provided | |
598 // _retain_gc_alloc_region[] indicates that it should be the | |
599 // case. Said regions are kept in the _retained_gc_alloc_regions[] | |
600 // array. If the parameter totally is set, we will not retain any | |
601 // regions, irrespective of what _retain_gc_alloc_region[] | |
602 // indicates. | |
603 void release_gc_alloc_regions(bool totally); | |
604 #ifndef PRODUCT | |
605 // Useful for debugging. | |
606 void print_gc_alloc_regions(); | |
607 #endif // !PRODUCT | |
342 | 608 |
609 // ("Weak") Reference processing support | |
610 ReferenceProcessor* _ref_processor; | |
611 | |
612 enum G1H_process_strong_roots_tasks { | |
613 G1H_PS_mark_stack_oops_do, | |
614 G1H_PS_refProcessor_oops_do, | |
615 // Leave this one last. | |
616 G1H_PS_NumElements | |
617 }; | |
618 | |
619 SubTasksDone* _process_strong_tasks; | |
620 | |
621 // List of regions which require zero filling. | |
622 UncleanRegionList _unclean_region_list; | |
623 bool _unclean_regions_coming; | |
624 | |
625 public: | |
626 void set_refine_cte_cl_concurrency(bool concurrent); | |
627 | |
628 RefToScanQueue *task_queue(int i); | |
629 | |
616
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
545
diff
changeset
|
630 // A set of cards where updates happened during the GC |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
545
diff
changeset
|
631 DirtyCardQueueSet& dirty_card_queue_set() { return _dirty_card_queue_set; } |
4f360ec815ba
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
545
diff
changeset
|
632 |
342 | 633 // Create a G1CollectedHeap with the specified policy. |
634 // Must call the initialize method afterwards. | |
635 // May not return if something goes wrong. | |
636 G1CollectedHeap(G1CollectorPolicy* policy); | |
637 | |
638 // Initialize the G1CollectedHeap to have the initial and | |
639 // maximum sizes, permanent generation, and remembered and barrier sets | |
640 // specified by the policy object. | |
641 jint initialize(); | |
642 | |
643 void ref_processing_init(); | |
644 | |
645 void set_par_threads(int t) { | |
646 SharedHeap::set_par_threads(t); | |
647 _process_strong_tasks->set_par_threads(t); | |
648 } | |
649 | |
650 virtual CollectedHeap::Name kind() const { | |
651 return CollectedHeap::G1CollectedHeap; | |
652 } | |
653 | |
654 // The current policy object for the collector. | |
655 G1CollectorPolicy* g1_policy() const { return _g1_policy; } | |
656 | |
657 // Adaptive size policy. No such thing for g1. | |
658 virtual AdaptiveSizePolicy* size_policy() { return NULL; } | |
659 | |
660 // The rem set and barrier set. | |
661 G1RemSet* g1_rem_set() const { return _g1_rem_set; } | |
662 ModRefBarrierSet* mr_bs() const { return _mr_bs; } | |
663 | |
664 // The rem set iterator. | |
665 HeapRegionRemSetIterator* rem_set_iterator(int i) { | |
666 return _rem_set_iterator[i]; | |
667 } | |
668 | |
669 HeapRegionRemSetIterator* rem_set_iterator() { | |
670 return _rem_set_iterator[0]; | |
671 } | |
672 | |
673 unsigned get_gc_time_stamp() { | |
674 return _gc_time_stamp; | |
675 } | |
676 | |
677 void reset_gc_time_stamp() { | |
678 _gc_time_stamp = 0; | |
353
9bb2c10ac07b
6723570: G1: assertion failure: p == current_top or oop(p)->is_oop(),"p is not a block start" (revisited!)
iveresov
parents:
342
diff
changeset
|
679 OrderAccess::fence(); |
9bb2c10ac07b
6723570: G1: assertion failure: p == current_top or oop(p)->is_oop(),"p is not a block start" (revisited!)
iveresov
parents:
342
diff
changeset
|
680 } |
9bb2c10ac07b
6723570: G1: assertion failure: p == current_top or oop(p)->is_oop(),"p is not a block start" (revisited!)
iveresov
parents:
342
diff
changeset
|
681 |
9bb2c10ac07b
6723570: G1: assertion failure: p == current_top or oop(p)->is_oop(),"p is not a block start" (revisited!)
iveresov
parents:
342
diff
changeset
|
682 void increment_gc_time_stamp() { |
9bb2c10ac07b
6723570: G1: assertion failure: p == current_top or oop(p)->is_oop(),"p is not a block start" (revisited!)
iveresov
parents:
342
diff
changeset
|
683 ++_gc_time_stamp; |
9bb2c10ac07b
6723570: G1: assertion failure: p == current_top or oop(p)->is_oop(),"p is not a block start" (revisited!)
iveresov
parents:
342
diff
changeset
|
684 OrderAccess::fence(); |
342 | 685 } |
686 | |
687 void iterate_dirty_card_closure(bool concurrent, int worker_i); | |
688 | |
689 // The shared block offset table array. | |
690 G1BlockOffsetSharedArray* bot_shared() const { return _bot_shared; } | |
691 | |
692 // Reference Processing accessor | |
693 ReferenceProcessor* ref_processor() { return _ref_processor; } | |
694 | |
695 // Reserved (g1 only; super method includes perm), capacity and the used | |
696 // portion in bytes. | |
697 size_t g1_reserved_obj_bytes() { return _g1_reserved.byte_size(); } | |
698 virtual size_t capacity() const; | |
699 virtual size_t used() const; | |
700 size_t recalculate_used() const; | |
701 #ifndef PRODUCT | |
702 size_t recalculate_used_regions() const; | |
703 #endif // PRODUCT | |
704 | |
705 // These virtual functions do the actual allocation. | |
706 virtual HeapWord* mem_allocate(size_t word_size, | |
707 bool is_noref, | |
708 bool is_tlab, | |
709 bool* gc_overhead_limit_was_exceeded); | |
710 | |
711 // Some heaps may offer a contiguous region for shared non-blocking | |
712 // allocation, via inlined code (by exporting the address of the top and | |
713 // end fields defining the extent of the contiguous allocation region.) | |
714 // But G1CollectedHeap doesn't yet support this. | |
715 | |
716 // Return an estimate of the maximum allocation that could be performed | |
717 // without triggering any collection or expansion activity. In a | |
718 // generational collector, for example, this is probably the largest | |
719 // allocation that could be supported (without expansion) in the youngest | |
720 // generation. It is "unsafe" because no locks are taken; the result | |
721 // should be treated as an approximation, not a guarantee, for use in | |
722 // heuristic resizing decisions. | |
723 virtual size_t unsafe_max_alloc(); | |
724 | |
725 virtual bool is_maximal_no_gc() const { | |
726 return _g1_storage.uncommitted_size() == 0; | |
727 } | |
728 | |
729 // The total number of regions in the heap. | |
730 size_t n_regions(); | |
731 | |
732 // The number of regions that are completely free. | |
733 size_t max_regions(); | |
734 | |
735 // The number of regions that are completely free. | |
736 size_t free_regions(); | |
737 | |
738 // The number of regions that are not completely free. | |
739 size_t used_regions() { return n_regions() - free_regions(); } | |
740 | |
741 // True iff the ZF thread should run. | |
742 bool should_zf(); | |
743 | |
744 // The number of regions available for "regular" expansion. | |
745 size_t expansion_regions() { return _expansion_regions; } | |
746 | |
747 #ifndef PRODUCT | |
748 bool regions_accounted_for(); | |
749 bool print_region_accounting_info(); | |
750 void print_region_counts(); | |
751 #endif | |
752 | |
753 HeapRegion* alloc_region_from_unclean_list(bool zero_filled); | |
754 HeapRegion* alloc_region_from_unclean_list_locked(bool zero_filled); | |
755 | |
756 void put_region_on_unclean_list(HeapRegion* r); | |
757 void put_region_on_unclean_list_locked(HeapRegion* r); | |
758 | |
759 void prepend_region_list_on_unclean_list(UncleanRegionList* list); | |
760 void prepend_region_list_on_unclean_list_locked(UncleanRegionList* list); | |
761 | |
762 void set_unclean_regions_coming(bool b); | |
763 void set_unclean_regions_coming_locked(bool b); | |
764 // Wait for cleanup to be complete. | |
765 void wait_for_cleanup_complete(); | |
766 // Like above, but assumes that the calling thread owns the Heap_lock. | |
767 void wait_for_cleanup_complete_locked(); | |
768 | |
769 // Return the head of the unclean list. | |
770 HeapRegion* peek_unclean_region_list_locked(); | |
771 // Remove and return the head of the unclean list. | |
772 HeapRegion* pop_unclean_region_list_locked(); | |
773 | |
774 // List of regions which are zero filled and ready for allocation. | |
775 HeapRegion* _free_region_list; | |
776 // Number of elements on the free list. | |
777 size_t _free_region_list_size; | |
778 | |
779 // If the head of the unclean list is ZeroFilled, move it to the free | |
780 // list. | |
781 bool move_cleaned_region_to_free_list_locked(); | |
782 bool move_cleaned_region_to_free_list(); | |
783 | |
784 void put_free_region_on_list_locked(HeapRegion* r); | |
785 void put_free_region_on_list(HeapRegion* r); | |
786 | |
787 // Remove and return the head element of the free list. | |
788 HeapRegion* pop_free_region_list_locked(); | |
789 | |
790 // If "zero_filled" is true, we first try the free list, then we try the | |
791 // unclean list, zero-filling the result. If "zero_filled" is false, we | |
792 // first try the unclean list, then the zero-filled list. | |
793 HeapRegion* alloc_free_region_from_lists(bool zero_filled); | |
794 | |
795 // Verify the integrity of the region lists. | |
796 void remove_allocated_regions_from_lists(); | |
797 bool verify_region_lists(); | |
798 bool verify_region_lists_locked(); | |
799 size_t unclean_region_list_length(); | |
800 size_t free_region_list_length(); | |
801 | |
802 // Perform a collection of the heap; intended for use in implementing | |
803 // "System.gc". This probably implies as full a collection as the | |
804 // "CollectedHeap" supports. | |
805 virtual void collect(GCCause::Cause cause); | |
806 | |
807 // The same as above but assume that the caller holds the Heap_lock. | |
808 void collect_locked(GCCause::Cause cause); | |
809 | |
810 // This interface assumes that it's being called by the | |
811 // vm thread. It collects the heap assuming that the | |
812 // heap lock is already held and that we are executing in | |
813 // the context of the vm thread. | |
814 virtual void collect_as_vm_thread(GCCause::Cause cause); | |
815 | |
816 // True iff a evacuation has failed in the most-recent collection. | |
817 bool evacuation_failed() { return _evacuation_failed; } | |
818 | |
819 // Free a region if it is totally full of garbage. Returns the number of | |
820 // bytes freed (0 ==> didn't free it). | |
821 size_t free_region_if_totally_empty(HeapRegion *hr); | |
822 void free_region_if_totally_empty_work(HeapRegion *hr, | |
823 size_t& pre_used, | |
824 size_t& cleared_h_regions, | |
825 size_t& freed_regions, | |
826 UncleanRegionList* list, | |
827 bool par = false); | |
828 | |
829 // If we've done free region work that yields the given changes, update | |
830 // the relevant global variables. | |
831 void finish_free_region_work(size_t pre_used, | |
832 size_t cleared_h_regions, | |
833 size_t freed_regions, | |
834 UncleanRegionList* list); | |
835 | |
836 | |
837 // Returns "TRUE" iff "p" points into the allocated area of the heap. | |
838 virtual bool is_in(const void* p) const; | |
839 | |
840 // Return "TRUE" iff the given object address is within the collection | |
841 // set. | |
842 inline bool obj_in_cs(oop obj); | |
843 | |
844 // Return "TRUE" iff the given object address is in the reserved | |
845 // region of g1 (excluding the permanent generation). | |
846 bool is_in_g1_reserved(const void* p) const { | |
847 return _g1_reserved.contains(p); | |
848 } | |
849 | |
850 // Returns a MemRegion that corresponds to the space that has been | |
851 // committed in the heap | |
852 MemRegion g1_committed() { | |
853 return _g1_committed; | |
854 } | |
855 | |
856 NOT_PRODUCT( bool is_in_closed_subset(const void* p) const; ) | |
857 | |
858 // Dirty card table entries covering a list of young regions. | |
859 void dirtyCardsForYoungRegions(CardTableModRefBS* ct_bs, HeapRegion* list); | |
860 | |
861 // This resets the card table to all zeros. It is used after | |
862 // a collection pause which used the card table to claim cards. | |
863 void cleanUpCardTable(); | |
864 | |
865 // Iteration functions. | |
866 | |
867 // Iterate over all the ref-containing fields of all objects, calling | |
868 // "cl.do_oop" on each. | |
678 | 869 virtual void oop_iterate(OopClosure* cl) { |
870 oop_iterate(cl, true); | |
871 } | |
872 void oop_iterate(OopClosure* cl, bool do_perm); | |
342 | 873 |
874 // Same as above, restricted to a memory region. | |
678 | 875 virtual void oop_iterate(MemRegion mr, OopClosure* cl) { |
876 oop_iterate(mr, cl, true); | |
877 } | |
878 void oop_iterate(MemRegion mr, OopClosure* cl, bool do_perm); | |
342 | 879 |
880 // Iterate over all objects, calling "cl.do_object" on each. | |
678 | 881 virtual void object_iterate(ObjectClosure* cl) { |
882 object_iterate(cl, true); | |
883 } | |
884 virtual void safe_object_iterate(ObjectClosure* cl) { | |
885 object_iterate(cl, true); | |
886 } | |
887 void object_iterate(ObjectClosure* cl, bool do_perm); | |
342 | 888 |
889 // Iterate over all objects allocated since the last collection, calling | |
890 // "cl.do_object" on each. The heap must have been initialized properly | |
891 // to support this function, or else this call will fail. | |
892 virtual void object_iterate_since_last_GC(ObjectClosure* cl); | |
893 | |
894 // Iterate over all spaces in use in the heap, in ascending address order. | |
895 virtual void space_iterate(SpaceClosure* cl); | |
896 | |
897 // Iterate over heap regions, in address order, terminating the | |
898 // iteration early if the "doHeapRegion" method returns "true". | |
899 void heap_region_iterate(HeapRegionClosure* blk); | |
900 | |
901 // Iterate over heap regions starting with r (or the first region if "r" | |
902 // is NULL), in address order, terminating early if the "doHeapRegion" | |
903 // method returns "true". | |
904 void heap_region_iterate_from(HeapRegion* r, HeapRegionClosure* blk); | |
905 | |
906 // As above but starting from the region at index idx. | |
907 void heap_region_iterate_from(int idx, HeapRegionClosure* blk); | |
908 | |
909 HeapRegion* region_at(size_t idx); | |
910 | |
911 // Divide the heap region sequence into "chunks" of some size (the number | |
912 // of regions divided by the number of parallel threads times some | |
913 // overpartition factor, currently 4). Assumes that this will be called | |
914 // in parallel by ParallelGCThreads worker threads with discinct worker | |
915 // ids in the range [0..max(ParallelGCThreads-1, 1)], that all parallel | |
916 // calls will use the same "claim_value", and that that claim value is | |
917 // different from the claim_value of any heap region before the start of | |
918 // the iteration. Applies "blk->doHeapRegion" to each of the regions, by | |
919 // attempting to claim the first region in each chunk, and, if | |
920 // successful, applying the closure to each region in the chunk (and | |
921 // setting the claim value of the second and subsequent regions of the | |
922 // chunk.) For now requires that "doHeapRegion" always returns "false", | |
923 // i.e., that a closure never attempt to abort a traversal. | |
924 void heap_region_par_iterate_chunked(HeapRegionClosure* blk, | |
925 int worker, | |
926 jint claim_value); | |
927 | |
390 | 928 // It resets all the region claim values to the default. |
929 void reset_heap_region_claim_values(); | |
930 | |
355 | 931 #ifdef ASSERT |
932 bool check_heap_region_claim_values(jint claim_value); | |
933 #endif // ASSERT | |
934 | |
342 | 935 // Iterate over the regions (if any) in the current collection set. |
936 void collection_set_iterate(HeapRegionClosure* blk); | |
937 | |
938 // As above but starting from region r | |
939 void collection_set_iterate_from(HeapRegion* r, HeapRegionClosure *blk); | |
940 | |
941 // Returns the first (lowest address) compactible space in the heap. | |
942 virtual CompactibleSpace* first_compactible_space(); | |
943 | |
944 // A CollectedHeap will contain some number of spaces. This finds the | |
945 // space containing a given address, or else returns NULL. | |
946 virtual Space* space_containing(const void* addr) const; | |
947 | |
948 // A G1CollectedHeap will contain some number of heap regions. This | |
949 // finds the region containing a given address, or else returns NULL. | |
950 HeapRegion* heap_region_containing(const void* addr) const; | |
951 | |
952 // Like the above, but requires "addr" to be in the heap (to avoid a | |
953 // null-check), and unlike the above, may return an continuing humongous | |
954 // region. | |
955 HeapRegion* heap_region_containing_raw(const void* addr) const; | |
956 | |
957 // A CollectedHeap is divided into a dense sequence of "blocks"; that is, | |
958 // each address in the (reserved) heap is a member of exactly | |
959 // one block. The defining characteristic of a block is that it is | |
960 // possible to find its size, and thus to progress forward to the next | |
961 // block. (Blocks may be of different sizes.) Thus, blocks may | |
962 // represent Java objects, or they might be free blocks in a | |
963 // free-list-based heap (or subheap), as long as the two kinds are | |
964 // distinguishable and the size of each is determinable. | |
965 | |
966 // Returns the address of the start of the "block" that contains the | |
967 // address "addr". We say "blocks" instead of "object" since some heaps | |
968 // may not pack objects densely; a chunk may either be an object or a | |
969 // non-object. | |
970 virtual HeapWord* block_start(const void* addr) const; | |
971 | |
972 // Requires "addr" to be the start of a chunk, and returns its size. | |
973 // "addr + size" is required to be the start of a new chunk, or the end | |
974 // of the active area of the heap. | |
975 virtual size_t block_size(const HeapWord* addr) const; | |
976 | |
977 // Requires "addr" to be the start of a block, and returns "TRUE" iff | |
978 // the block is an object. | |
979 virtual bool block_is_obj(const HeapWord* addr) const; | |
980 | |
981 // Does this heap support heap inspection? (+PrintClassHistogram) | |
982 virtual bool supports_heap_inspection() const { return true; } | |
983 | |
984 // Section on thread-local allocation buffers (TLABs) | |
985 // See CollectedHeap for semantics. | |
986 | |
987 virtual bool supports_tlab_allocation() const; | |
988 virtual size_t tlab_capacity(Thread* thr) const; | |
989 virtual size_t unsafe_max_tlab_alloc(Thread* thr) const; | |
990 virtual HeapWord* allocate_new_tlab(size_t size); | |
991 | |
992 // Can a compiler initialize a new object without store barriers? | |
993 // This permission only extends from the creation of a new object | |
994 // via a TLAB up to the first subsequent safepoint. | |
995 virtual bool can_elide_tlab_store_barriers() const { | |
996 // Since G1's TLAB's may, on occasion, come from non-young regions | |
997 // as well. (Is there a flag controlling that? XXX) | |
998 return false; | |
999 } | |
1000 | |
1001 // Can a compiler elide a store barrier when it writes | |
1002 // a permanent oop into the heap? Applies when the compiler | |
1003 // is storing x to the heap, where x->is_perm() is true. | |
1004 virtual bool can_elide_permanent_oop_store_barriers() const { | |
1005 // At least until perm gen collection is also G1-ified, at | |
1006 // which point this should return false. | |
1007 return true; | |
1008 } | |
1009 | |
1010 virtual bool allocs_are_zero_filled(); | |
1011 | |
1012 // The boundary between a "large" and "small" array of primitives, in | |
1013 // words. | |
1014 virtual size_t large_typearray_limit(); | |
1015 | |
1016 // Returns "true" iff the given word_size is "very large". | |
1017 static bool isHumongous(size_t word_size) { | |
1018 return word_size >= VeryLargeInWords; | |
1019 } | |
1020 | |
1021 // Update mod union table with the set of dirty cards. | |
1022 void updateModUnion(); | |
1023 | |
1024 // Set the mod union bits corresponding to the given memRegion. Note | |
1025 // that this is always a safe operation, since it doesn't clear any | |
1026 // bits. | |
1027 void markModUnionRange(MemRegion mr); | |
1028 | |
1029 // Records the fact that a marking phase is no longer in progress. | |
1030 void set_marking_complete() { | |
1031 _mark_in_progress = false; | |
1032 } | |
1033 void set_marking_started() { | |
1034 _mark_in_progress = true; | |
1035 } | |
1036 bool mark_in_progress() { | |
1037 return _mark_in_progress; | |
1038 } | |
1039 | |
1040 // Print the maximum heap capacity. | |
1041 virtual size_t max_capacity() const; | |
1042 | |
1043 virtual jlong millis_since_last_gc(); | |
1044 | |
1045 // Perform any cleanup actions necessary before allowing a verification. | |
1046 virtual void prepare_for_verify(); | |
1047 | |
1048 // Perform verification. | |
1049 virtual void verify(bool allow_dirty, bool silent); | |
1050 virtual void print() const; | |
1051 virtual void print_on(outputStream* st) const; | |
1052 | |
1053 virtual void print_gc_threads_on(outputStream* st) const; | |
1054 virtual void gc_threads_do(ThreadClosure* tc) const; | |
1055 | |
1056 // Override | |
1057 void print_tracing_info() const; | |
1058 | |
1059 // If "addr" is a pointer into the (reserved?) heap, returns a positive | |
1060 // number indicating the "arena" within the heap in which "addr" falls. | |
1061 // Or else returns 0. | |
1062 virtual int addr_to_arena_id(void* addr) const; | |
1063 | |
1064 // Convenience function to be used in situations where the heap type can be | |
1065 // asserted to be this type. | |
1066 static G1CollectedHeap* heap(); | |
1067 | |
1068 void empty_young_list(); | |
1069 bool should_set_young_locked(); | |
1070 | |
1071 void set_region_short_lived_locked(HeapRegion* hr); | |
1072 // add appropriate methods for any other surv rate groups | |
1073 | |
1074 void young_list_rs_length_sampling_init() { | |
1075 _young_list->rs_length_sampling_init(); | |
1076 } | |
1077 bool young_list_rs_length_sampling_more() { | |
1078 return _young_list->rs_length_sampling_more(); | |
1079 } | |
1080 void young_list_rs_length_sampling_next() { | |
1081 _young_list->rs_length_sampling_next(); | |
1082 } | |
1083 size_t young_list_sampled_rs_lengths() { | |
1084 return _young_list->sampled_rs_lengths(); | |
1085 } | |
1086 | |
1087 size_t young_list_length() { return _young_list->length(); } | |
1088 size_t young_list_scan_only_length() { | |
1089 return _young_list->scan_only_length(); } | |
1090 | |
1091 HeapRegion* pop_region_from_young_list() { | |
1092 return _young_list->pop_region(); | |
1093 } | |
1094 | |
1095 HeapRegion* young_list_first_region() { | |
1096 return _young_list->first_region(); | |
1097 } | |
1098 | |
1099 // debugging | |
1100 bool check_young_list_well_formed() { | |
1101 return _young_list->check_list_well_formed(); | |
1102 } | |
1103 bool check_young_list_empty(bool ignore_scan_only_list, | |
1104 bool check_sample = true); | |
1105 | |
1106 // *** Stuff related to concurrent marking. It's not clear to me that so | |
1107 // many of these need to be public. | |
1108 | |
1109 // The functions below are helper functions that a subclass of | |
1110 // "CollectedHeap" can use in the implementation of its virtual | |
1111 // functions. | |
1112 // This performs a concurrent marking of the live objects in a | |
1113 // bitmap off to the side. | |
1114 void doConcurrentMark(); | |
1115 | |
1116 // This is called from the marksweep collector which then does | |
1117 // a concurrent mark and verifies that the results agree with | |
1118 // the stop the world marking. | |
1119 void checkConcurrentMark(); | |
1120 void do_sync_mark(); | |
1121 | |
1122 bool isMarkedPrev(oop obj) const; | |
1123 bool isMarkedNext(oop obj) const; | |
1124 | |
1125 // Determine if an object is dead, given the object and also | |
1126 // the region to which the object belongs. An object is dead | |
1127 // iff a) it was not allocated since the last mark and b) it | |
1128 // is not marked. | |
1129 | |
1130 bool is_obj_dead(const oop obj, const HeapRegion* hr) const { | |
1131 return | |
1132 !hr->obj_allocated_since_prev_marking(obj) && | |
1133 !isMarkedPrev(obj); | |
1134 } | |
1135 | |
1136 // This is used when copying an object to survivor space. | |
1137 // If the object is marked live, then we mark the copy live. | |
1138 // If the object is allocated since the start of this mark | |
1139 // cycle, then we mark the copy live. | |
1140 // If the object has been around since the previous mark | |
1141 // phase, and hasn't been marked yet during this phase, | |
1142 // then we don't mark it, we just wait for the | |
1143 // current marking cycle to get to it. | |
1144 | |
1145 // This function returns true when an object has been | |
1146 // around since the previous marking and hasn't yet | |
1147 // been marked during this marking. | |
1148 | |
1149 bool is_obj_ill(const oop obj, const HeapRegion* hr) const { | |
1150 return | |
1151 !hr->obj_allocated_since_next_marking(obj) && | |
1152 !isMarkedNext(obj); | |
1153 } | |
1154 | |
1155 // Determine if an object is dead, given only the object itself. | |
1156 // This will find the region to which the object belongs and | |
1157 // then call the region version of the same function. | |
1158 | |
1159 // Added if it is in permanent gen it isn't dead. | |
1160 // Added if it is NULL it isn't dead. | |
1161 | |
1162 bool is_obj_dead(oop obj) { | |
1163 HeapRegion* hr = heap_region_containing(obj); | |
1164 if (hr == NULL) { | |
1165 if (Universe::heap()->is_in_permanent(obj)) | |
1166 return false; | |
1167 else if (obj == NULL) return false; | |
1168 else return true; | |
1169 } | |
1170 else return is_obj_dead(obj, hr); | |
1171 } | |
1172 | |
1173 bool is_obj_ill(oop obj) { | |
1174 HeapRegion* hr = heap_region_containing(obj); | |
1175 if (hr == NULL) { | |
1176 if (Universe::heap()->is_in_permanent(obj)) | |
1177 return false; | |
1178 else if (obj == NULL) return false; | |
1179 else return true; | |
1180 } | |
1181 else return is_obj_ill(obj, hr); | |
1182 } | |
1183 | |
1184 // The following is just to alert the verification code | |
1185 // that a full collection has occurred and that the | |
1186 // remembered sets are no longer up to date. | |
1187 bool _full_collection; | |
1188 void set_full_collection() { _full_collection = true;} | |
1189 void clear_full_collection() {_full_collection = false;} | |
1190 bool full_collection() {return _full_collection;} | |
1191 | |
1192 ConcurrentMark* concurrent_mark() const { return _cm; } | |
1193 ConcurrentG1Refine* concurrent_g1_refine() const { return _cg1r; } | |
1194 | |
796
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
678
diff
changeset
|
1195 // The dirty cards region list is used to record a subset of regions |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
678
diff
changeset
|
1196 // whose cards need clearing. The list if populated during the |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
678
diff
changeset
|
1197 // remembered set scanning and drained during the card table |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
678
diff
changeset
|
1198 // cleanup. Although the methods are reentrant, population/draining |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
678
diff
changeset
|
1199 // phases must not overlap. For synchronization purposes the last |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
678
diff
changeset
|
1200 // element on the list points to itself. |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
678
diff
changeset
|
1201 HeapRegion* _dirty_cards_region_list; |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
678
diff
changeset
|
1202 void push_dirty_cards_region(HeapRegion* hr); |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
678
diff
changeset
|
1203 HeapRegion* pop_dirty_cards_region(); |
29e7d79232b9
6819065: G1: eliminate high serial card table clearing time
apetrusenko
parents:
678
diff
changeset
|
1204 |
342 | 1205 public: |
1206 void stop_conc_gc_threads(); | |
1207 | |
1208 // <NEW PREDICTION> | |
1209 | |
1210 double predict_region_elapsed_time_ms(HeapRegion* hr, bool young); | |
1211 void check_if_region_is_too_expensive(double predicted_time_ms); | |
1212 size_t pending_card_num(); | |
1213 size_t max_pending_card_num(); | |
1214 size_t cards_scanned(); | |
1215 | |
1216 // </NEW PREDICTION> | |
1217 | |
1218 protected: | |
1219 size_t _max_heap_capacity; | |
1220 | |
1221 // debug_only(static void check_for_valid_allocation_state();) | |
1222 | |
1223 public: | |
1224 // Temporary: call to mark things unimplemented for the G1 heap (e.g., | |
1225 // MemoryService). In productization, we can make this assert false | |
1226 // to catch such places (as well as searching for calls to this...) | |
1227 static void g1_unimplemented(); | |
1228 | |
1229 }; | |
1230 | |
1231 // Local Variables: *** | |
1232 // c-indentation-style: gnu *** | |
1233 // End: *** |