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