Wed, 12 Jan 2011 13:06:00 -0500
7007068: G1: refine the BOT during evac failure handling
Summary: During evacuation failure handling we refine the BOT to reflect the location of all the objects in the regions we scan. The changeset includes some minor cleanup: a) non-product print_on() method on the G1 BOT class, b) added more complete BOT verification during heap / region verification, c) slight modification to the BOT set up for humongous regions to be more consistent with the BOT set up during evac failure handling, and d) removed a couple of unused methods.
Reviewed-by: johnc, ysr
1 /*
2 * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGION_HPP
26 #define SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGION_HPP
28 #include "gc_implementation/g1/g1BlockOffsetTable.inline.hpp"
29 #include "gc_implementation/g1/g1_specialized_oop_closures.hpp"
30 #include "gc_implementation/g1/survRateGroup.hpp"
31 #include "gc_implementation/shared/ageTable.hpp"
32 #include "gc_implementation/shared/spaceDecorator.hpp"
33 #include "memory/space.inline.hpp"
34 #include "memory/watermark.hpp"
36 #ifndef SERIALGC
38 // A HeapRegion is the smallest piece of a G1CollectedHeap that
39 // can be collected independently.
41 // NOTE: Although a HeapRegion is a Space, its
42 // Space::initDirtyCardClosure method must not be called.
43 // The problem is that the existence of this method breaks
44 // the independence of barrier sets from remembered sets.
45 // The solution is to remove this method from the definition
46 // of a Space.
48 class CompactibleSpace;
49 class ContiguousSpace;
50 class HeapRegionRemSet;
51 class HeapRegionRemSetIterator;
52 class HeapRegion;
54 // A dirty card to oop closure for heap regions. It
55 // knows how to get the G1 heap and how to use the bitmap
56 // in the concurrent marker used by G1 to filter remembered
57 // sets.
59 class HeapRegionDCTOC : public ContiguousSpaceDCTOC {
60 public:
61 // Specification of possible DirtyCardToOopClosure filtering.
62 enum FilterKind {
63 NoFilterKind,
64 IntoCSFilterKind,
65 OutOfRegionFilterKind
66 };
68 protected:
69 HeapRegion* _hr;
70 FilterKind _fk;
71 G1CollectedHeap* _g1;
73 void walk_mem_region_with_cl(MemRegion mr,
74 HeapWord* bottom, HeapWord* top,
75 OopClosure* cl);
77 // We don't specialize this for FilteringClosure; filtering is handled by
78 // the "FilterKind" mechanism. But we provide this to avoid a compiler
79 // warning.
80 void walk_mem_region_with_cl(MemRegion mr,
81 HeapWord* bottom, HeapWord* top,
82 FilteringClosure* cl) {
83 HeapRegionDCTOC::walk_mem_region_with_cl(mr, bottom, top,
84 (OopClosure*)cl);
85 }
87 // Get the actual top of the area on which the closure will
88 // operate, given where the top is assumed to be (the end of the
89 // memory region passed to do_MemRegion) and where the object
90 // at the top is assumed to start. For example, an object may
91 // start at the top but actually extend past the assumed top,
92 // in which case the top becomes the end of the object.
93 HeapWord* get_actual_top(HeapWord* top, HeapWord* top_obj) {
94 return ContiguousSpaceDCTOC::get_actual_top(top, top_obj);
95 }
97 // Walk the given memory region from bottom to (actual) top
98 // looking for objects and applying the oop closure (_cl) to
99 // them. The base implementation of this treats the area as
100 // blocks, where a block may or may not be an object. Sub-
101 // classes should override this to provide more accurate
102 // or possibly more efficient walking.
103 void walk_mem_region(MemRegion mr, HeapWord* bottom, HeapWord* top) {
104 Filtering_DCTOC::walk_mem_region(mr, bottom, top);
105 }
107 public:
108 HeapRegionDCTOC(G1CollectedHeap* g1,
109 HeapRegion* hr, OopClosure* cl,
110 CardTableModRefBS::PrecisionStyle precision,
111 FilterKind fk);
112 };
115 // The complicating factor is that BlockOffsetTable diverged
116 // significantly, and we need functionality that is only in the G1 version.
117 // So I copied that code, which led to an alternate G1 version of
118 // OffsetTableContigSpace. If the two versions of BlockOffsetTable could
119 // be reconciled, then G1OffsetTableContigSpace could go away.
121 // The idea behind time stamps is the following. Doing a save_marks on
122 // all regions at every GC pause is time consuming (if I remember
123 // well, 10ms or so). So, we would like to do that only for regions
124 // that are GC alloc regions. To achieve this, we use time
125 // stamps. For every evacuation pause, G1CollectedHeap generates a
126 // unique time stamp (essentially a counter that gets
127 // incremented). Every time we want to call save_marks on a region,
128 // we set the saved_mark_word to top and also copy the current GC
129 // time stamp to the time stamp field of the space. Reading the
130 // saved_mark_word involves checking the time stamp of the
131 // region. If it is the same as the current GC time stamp, then we
132 // can safely read the saved_mark_word field, as it is valid. If the
133 // time stamp of the region is not the same as the current GC time
134 // stamp, then we instead read top, as the saved_mark_word field is
135 // invalid. Time stamps (on the regions and also on the
136 // G1CollectedHeap) are reset at every cleanup (we iterate over
137 // the regions anyway) and at the end of a Full GC. The current scheme
138 // that uses sequential unsigned ints will fail only if we have 4b
139 // evacuation pauses between two cleanups, which is _highly_ unlikely.
141 class G1OffsetTableContigSpace: public ContiguousSpace {
142 friend class VMStructs;
143 protected:
144 G1BlockOffsetArrayContigSpace _offsets;
145 Mutex _par_alloc_lock;
146 volatile unsigned _gc_time_stamp;
148 public:
149 // Constructor. If "is_zeroed" is true, the MemRegion "mr" may be
150 // assumed to contain zeros.
151 G1OffsetTableContigSpace(G1BlockOffsetSharedArray* sharedOffsetArray,
152 MemRegion mr, bool is_zeroed = false);
154 void set_bottom(HeapWord* value);
155 void set_end(HeapWord* value);
157 virtual HeapWord* saved_mark_word() const;
158 virtual void set_saved_mark();
159 void reset_gc_time_stamp() { _gc_time_stamp = 0; }
161 virtual void initialize(MemRegion mr, bool clear_space, bool mangle_space);
162 virtual void clear(bool mangle_space);
164 HeapWord* block_start(const void* p);
165 HeapWord* block_start_const(const void* p) const;
167 // Add offset table update.
168 virtual HeapWord* allocate(size_t word_size);
169 HeapWord* par_allocate(size_t word_size);
171 // MarkSweep support phase3
172 virtual HeapWord* initialize_threshold();
173 virtual HeapWord* cross_threshold(HeapWord* start, HeapWord* end);
175 virtual void print() const;
177 void reset_bot() {
178 _offsets.zero_bottom_entry();
179 _offsets.initialize_threshold();
180 }
182 void update_bot_for_object(HeapWord* start, size_t word_size) {
183 _offsets.alloc_block(start, word_size);
184 }
186 void print_bot_on(outputStream* out) {
187 _offsets.print_on(out);
188 }
189 };
191 class HeapRegion: public G1OffsetTableContigSpace {
192 friend class VMStructs;
193 private:
195 enum HumongousType {
196 NotHumongous = 0,
197 StartsHumongous,
198 ContinuesHumongous
199 };
201 // The next filter kind that should be used for a "new_dcto_cl" call with
202 // the "traditional" signature.
203 HeapRegionDCTOC::FilterKind _next_fk;
205 // Requires that the region "mr" be dense with objects, and begin and end
206 // with an object.
207 void oops_in_mr_iterate(MemRegion mr, OopClosure* cl);
209 // The remembered set for this region.
210 // (Might want to make this "inline" later, to avoid some alloc failure
211 // issues.)
212 HeapRegionRemSet* _rem_set;
214 G1BlockOffsetArrayContigSpace* offsets() { return &_offsets; }
216 protected:
217 // If this region is a member of a HeapRegionSeq, the index in that
218 // sequence, otherwise -1.
219 int _hrs_index;
221 HumongousType _humongous_type;
222 // For a humongous region, region in which it starts.
223 HeapRegion* _humongous_start_region;
224 // For the start region of a humongous sequence, it's original end().
225 HeapWord* _orig_end;
227 // True iff the region is in current collection_set.
228 bool _in_collection_set;
230 // True iff the region is on the unclean list, waiting to be zero filled.
231 bool _is_on_unclean_list;
233 // True iff the region is on the free list, ready for allocation.
234 bool _is_on_free_list;
236 // Is this or has it been an allocation region in the current collection
237 // pause.
238 bool _is_gc_alloc_region;
240 // True iff an attempt to evacuate an object in the region failed.
241 bool _evacuation_failed;
243 // A heap region may be a member one of a number of special subsets, each
244 // represented as linked lists through the field below. Currently, these
245 // sets include:
246 // The collection set.
247 // The set of allocation regions used in a collection pause.
248 // Spaces that may contain gray objects.
249 HeapRegion* _next_in_special_set;
251 // next region in the young "generation" region set
252 HeapRegion* _next_young_region;
254 // Next region whose cards need cleaning
255 HeapRegion* _next_dirty_cards_region;
257 // For parallel heapRegion traversal.
258 jint _claimed;
260 // We use concurrent marking to determine the amount of live data
261 // in each heap region.
262 size_t _prev_marked_bytes; // Bytes known to be live via last completed marking.
263 size_t _next_marked_bytes; // Bytes known to be live via in-progress marking.
265 // See "sort_index" method. -1 means is not in the array.
266 int _sort_index;
268 // <PREDICTION>
269 double _gc_efficiency;
270 // </PREDICTION>
272 enum YoungType {
273 NotYoung, // a region is not young
274 Young, // a region is young
275 Survivor // a region is young and it contains
276 // survivor
277 };
279 volatile YoungType _young_type;
280 int _young_index_in_cset;
281 SurvRateGroup* _surv_rate_group;
282 int _age_index;
284 // The start of the unmarked area. The unmarked area extends from this
285 // word until the top and/or end of the region, and is the part
286 // of the region for which no marking was done, i.e. objects may
287 // have been allocated in this part since the last mark phase.
288 // "prev" is the top at the start of the last completed marking.
289 // "next" is the top at the start of the in-progress marking (if any.)
290 HeapWord* _prev_top_at_mark_start;
291 HeapWord* _next_top_at_mark_start;
292 // If a collection pause is in progress, this is the top at the start
293 // of that pause.
295 // We've counted the marked bytes of objects below here.
296 HeapWord* _top_at_conc_mark_count;
298 void init_top_at_mark_start() {
299 assert(_prev_marked_bytes == 0 &&
300 _next_marked_bytes == 0,
301 "Must be called after zero_marked_bytes.");
302 HeapWord* bot = bottom();
303 _prev_top_at_mark_start = bot;
304 _next_top_at_mark_start = bot;
305 _top_at_conc_mark_count = bot;
306 }
308 jint _zfs; // A member of ZeroFillState. Protected by ZF_lock.
309 Thread* _zero_filler; // If _zfs is ZeroFilling, the thread that (last)
310 // made it so.
312 void set_young_type(YoungType new_type) {
313 //assert(_young_type != new_type, "setting the same type" );
314 // TODO: add more assertions here
315 _young_type = new_type;
316 }
318 // Cached attributes used in the collection set policy information
320 // The RSet length that was added to the total value
321 // for the collection set.
322 size_t _recorded_rs_length;
324 // The predicted elapsed time that was added to total value
325 // for the collection set.
326 double _predicted_elapsed_time_ms;
328 // The predicted number of bytes to copy that was added to
329 // the total value for the collection set.
330 size_t _predicted_bytes_to_copy;
332 public:
333 // If "is_zeroed" is "true", the region "mr" can be assumed to contain zeros.
334 HeapRegion(G1BlockOffsetSharedArray* sharedOffsetArray,
335 MemRegion mr, bool is_zeroed);
337 static int LogOfHRGrainBytes;
338 static int LogOfHRGrainWords;
339 // The normal type of these should be size_t. However, they used to
340 // be members of an enum before and they are assumed by the
341 // compilers to be ints. To avoid going and fixing all their uses,
342 // I'm declaring them as ints. I'm not anticipating heap region
343 // sizes to reach anywhere near 2g, so using an int here is safe.
344 static int GrainBytes;
345 static int GrainWords;
346 static int CardsPerRegion;
348 // It sets up the heap region size (GrainBytes / GrainWords), as
349 // well as other related fields that are based on the heap region
350 // size (LogOfHRGrainBytes / LogOfHRGrainWords /
351 // CardsPerRegion). All those fields are considered constant
352 // throughout the JVM's execution, therefore they should only be set
353 // up once during initialization time.
354 static void setup_heap_region_size(uintx min_heap_size);
356 enum ClaimValues {
357 InitialClaimValue = 0,
358 FinalCountClaimValue = 1,
359 NoteEndClaimValue = 2,
360 ScrubRemSetClaimValue = 3,
361 ParVerifyClaimValue = 4,
362 RebuildRSClaimValue = 5
363 };
365 // Concurrent refinement requires contiguous heap regions (in which TLABs
366 // might be allocated) to be zero-filled. Each region therefore has a
367 // zero-fill-state.
368 enum ZeroFillState {
369 NotZeroFilled,
370 ZeroFilling,
371 ZeroFilled,
372 Allocated
373 };
375 // If this region is a member of a HeapRegionSeq, the index in that
376 // sequence, otherwise -1.
377 int hrs_index() const { return _hrs_index; }
378 void set_hrs_index(int index) { _hrs_index = index; }
380 // The number of bytes marked live in the region in the last marking phase.
381 size_t marked_bytes() { return _prev_marked_bytes; }
382 // The number of bytes counted in the next marking.
383 size_t next_marked_bytes() { return _next_marked_bytes; }
384 // The number of bytes live wrt the next marking.
385 size_t next_live_bytes() {
386 return (top() - next_top_at_mark_start())
387 * HeapWordSize
388 + next_marked_bytes();
389 }
391 // A lower bound on the amount of garbage bytes in the region.
392 size_t garbage_bytes() {
393 size_t used_at_mark_start_bytes =
394 (prev_top_at_mark_start() - bottom()) * HeapWordSize;
395 assert(used_at_mark_start_bytes >= marked_bytes(),
396 "Can't mark more than we have.");
397 return used_at_mark_start_bytes - marked_bytes();
398 }
400 // An upper bound on the number of live bytes in the region.
401 size_t max_live_bytes() { return used() - garbage_bytes(); }
403 void add_to_marked_bytes(size_t incr_bytes) {
404 _next_marked_bytes = _next_marked_bytes + incr_bytes;
405 guarantee( _next_marked_bytes <= used(), "invariant" );
406 }
408 void zero_marked_bytes() {
409 _prev_marked_bytes = _next_marked_bytes = 0;
410 }
412 bool isHumongous() const { return _humongous_type != NotHumongous; }
413 bool startsHumongous() const { return _humongous_type == StartsHumongous; }
414 bool continuesHumongous() const { return _humongous_type == ContinuesHumongous; }
415 // For a humongous region, region in which it starts.
416 HeapRegion* humongous_start_region() const {
417 return _humongous_start_region;
418 }
420 // Makes the current region be a "starts humongous" region, i.e.,
421 // the first region in a series of one or more contiguous regions
422 // that will contain a single "humongous" object. The two parameters
423 // are as follows:
424 //
425 // new_top : The new value of the top field of this region which
426 // points to the end of the humongous object that's being
427 // allocated. If there is more than one region in the series, top
428 // will lie beyond this region's original end field and on the last
429 // region in the series.
430 //
431 // new_end : The new value of the end field of this region which
432 // points to the end of the last region in the series. If there is
433 // one region in the series (namely: this one) end will be the same
434 // as the original end of this region.
435 //
436 // Updating top and end as described above makes this region look as
437 // if it spans the entire space taken up by all the regions in the
438 // series and an single allocation moved its top to new_top. This
439 // ensures that the space (capacity / allocated) taken up by all
440 // humongous regions can be calculated by just looking at the
441 // "starts humongous" regions and by ignoring the "continues
442 // humongous" regions.
443 void set_startsHumongous(HeapWord* new_top, HeapWord* new_end);
445 // Makes the current region be a "continues humongous'
446 // region. first_hr is the "start humongous" region of the series
447 // which this region will be part of.
448 void set_continuesHumongous(HeapRegion* first_hr);
450 // If the region has a remembered set, return a pointer to it.
451 HeapRegionRemSet* rem_set() const {
452 return _rem_set;
453 }
455 // True iff the region is in current collection_set.
456 bool in_collection_set() const {
457 return _in_collection_set;
458 }
459 void set_in_collection_set(bool b) {
460 _in_collection_set = b;
461 }
462 HeapRegion* next_in_collection_set() {
463 assert(in_collection_set(), "should only invoke on member of CS.");
464 assert(_next_in_special_set == NULL ||
465 _next_in_special_set->in_collection_set(),
466 "Malformed CS.");
467 return _next_in_special_set;
468 }
469 void set_next_in_collection_set(HeapRegion* r) {
470 assert(in_collection_set(), "should only invoke on member of CS.");
471 assert(r == NULL || r->in_collection_set(), "Malformed CS.");
472 _next_in_special_set = r;
473 }
475 // True iff it is or has been an allocation region in the current
476 // collection pause.
477 bool is_gc_alloc_region() const {
478 return _is_gc_alloc_region;
479 }
480 void set_is_gc_alloc_region(bool b) {
481 _is_gc_alloc_region = b;
482 }
483 HeapRegion* next_gc_alloc_region() {
484 assert(is_gc_alloc_region(), "should only invoke on member of CS.");
485 assert(_next_in_special_set == NULL ||
486 _next_in_special_set->is_gc_alloc_region(),
487 "Malformed CS.");
488 return _next_in_special_set;
489 }
490 void set_next_gc_alloc_region(HeapRegion* r) {
491 assert(is_gc_alloc_region(), "should only invoke on member of CS.");
492 assert(r == NULL || r->is_gc_alloc_region(), "Malformed CS.");
493 _next_in_special_set = r;
494 }
496 bool is_on_free_list() {
497 return _is_on_free_list;
498 }
500 void set_on_free_list(bool b) {
501 _is_on_free_list = b;
502 }
504 HeapRegion* next_from_free_list() {
505 assert(is_on_free_list(),
506 "Should only invoke on free space.");
507 assert(_next_in_special_set == NULL ||
508 _next_in_special_set->is_on_free_list(),
509 "Malformed Free List.");
510 return _next_in_special_set;
511 }
513 void set_next_on_free_list(HeapRegion* r) {
514 assert(r == NULL || r->is_on_free_list(), "Malformed free list.");
515 _next_in_special_set = r;
516 }
518 bool is_on_unclean_list() {
519 return _is_on_unclean_list;
520 }
522 void set_on_unclean_list(bool b);
524 HeapRegion* next_from_unclean_list() {
525 assert(is_on_unclean_list(),
526 "Should only invoke on unclean space.");
527 assert(_next_in_special_set == NULL ||
528 _next_in_special_set->is_on_unclean_list(),
529 "Malformed unclean List.");
530 return _next_in_special_set;
531 }
533 void set_next_on_unclean_list(HeapRegion* r);
535 HeapRegion* get_next_young_region() { return _next_young_region; }
536 void set_next_young_region(HeapRegion* hr) {
537 _next_young_region = hr;
538 }
540 HeapRegion* get_next_dirty_cards_region() const { return _next_dirty_cards_region; }
541 HeapRegion** next_dirty_cards_region_addr() { return &_next_dirty_cards_region; }
542 void set_next_dirty_cards_region(HeapRegion* hr) { _next_dirty_cards_region = hr; }
543 bool is_on_dirty_cards_region_list() const { return get_next_dirty_cards_region() != NULL; }
545 // Allows logical separation between objects allocated before and after.
546 void save_marks();
548 // Reset HR stuff to default values.
549 void hr_clear(bool par, bool clear_space);
551 void initialize(MemRegion mr, bool clear_space, bool mangle_space);
553 // Ensure that "this" is zero-filled.
554 void ensure_zero_filled();
555 // This one requires that the calling thread holds ZF_mon.
556 void ensure_zero_filled_locked();
558 // Get the start of the unmarked area in this region.
559 HeapWord* prev_top_at_mark_start() const { return _prev_top_at_mark_start; }
560 HeapWord* next_top_at_mark_start() const { return _next_top_at_mark_start; }
562 // Apply "cl->do_oop" to (the addresses of) all reference fields in objects
563 // allocated in the current region before the last call to "save_mark".
564 void oop_before_save_marks_iterate(OopClosure* cl);
566 // This call determines the "filter kind" argument that will be used for
567 // the next call to "new_dcto_cl" on this region with the "traditional"
568 // signature (i.e., the call below.) The default, in the absence of a
569 // preceding call to this method, is "NoFilterKind", and a call to this
570 // method is necessary for each such call, or else it reverts to the
571 // default.
572 // (This is really ugly, but all other methods I could think of changed a
573 // lot of main-line code for G1.)
574 void set_next_filter_kind(HeapRegionDCTOC::FilterKind nfk) {
575 _next_fk = nfk;
576 }
578 DirtyCardToOopClosure*
579 new_dcto_closure(OopClosure* cl,
580 CardTableModRefBS::PrecisionStyle precision,
581 HeapRegionDCTOC::FilterKind fk);
583 #if WHASSUP
584 DirtyCardToOopClosure*
585 new_dcto_closure(OopClosure* cl,
586 CardTableModRefBS::PrecisionStyle precision,
587 HeapWord* boundary) {
588 assert(boundary == NULL, "This arg doesn't make sense here.");
589 DirtyCardToOopClosure* res = new_dcto_closure(cl, precision, _next_fk);
590 _next_fk = HeapRegionDCTOC::NoFilterKind;
591 return res;
592 }
593 #endif
595 //
596 // Note the start or end of marking. This tells the heap region
597 // that the collector is about to start or has finished (concurrently)
598 // marking the heap.
599 //
601 // Note the start of a marking phase. Record the
602 // start of the unmarked area of the region here.
603 void note_start_of_marking(bool during_initial_mark) {
604 init_top_at_conc_mark_count();
605 _next_marked_bytes = 0;
606 if (during_initial_mark && is_young() && !is_survivor())
607 _next_top_at_mark_start = bottom();
608 else
609 _next_top_at_mark_start = top();
610 }
612 // Note the end of a marking phase. Install the start of
613 // the unmarked area that was captured at start of marking.
614 void note_end_of_marking() {
615 _prev_top_at_mark_start = _next_top_at_mark_start;
616 _prev_marked_bytes = _next_marked_bytes;
617 _next_marked_bytes = 0;
619 guarantee(_prev_marked_bytes <=
620 (size_t) (prev_top_at_mark_start() - bottom()) * HeapWordSize,
621 "invariant");
622 }
624 // After an evacuation, we need to update _next_top_at_mark_start
625 // to be the current top. Note this is only valid if we have only
626 // ever evacuated into this region. If we evacuate, allocate, and
627 // then evacuate we are in deep doodoo.
628 void note_end_of_copying() {
629 assert(top() >= _next_top_at_mark_start, "Increase only");
630 _next_top_at_mark_start = top();
631 }
633 // Returns "false" iff no object in the region was allocated when the
634 // last mark phase ended.
635 bool is_marked() { return _prev_top_at_mark_start != bottom(); }
637 // If "is_marked()" is true, then this is the index of the region in
638 // an array constructed at the end of marking of the regions in a
639 // "desirability" order.
640 int sort_index() {
641 return _sort_index;
642 }
643 void set_sort_index(int i) {
644 _sort_index = i;
645 }
647 void init_top_at_conc_mark_count() {
648 _top_at_conc_mark_count = bottom();
649 }
651 void set_top_at_conc_mark_count(HeapWord *cur) {
652 assert(bottom() <= cur && cur <= end(), "Sanity.");
653 _top_at_conc_mark_count = cur;
654 }
656 HeapWord* top_at_conc_mark_count() {
657 return _top_at_conc_mark_count;
658 }
660 void reset_during_compaction() {
661 guarantee( isHumongous() && startsHumongous(),
662 "should only be called for humongous regions");
664 zero_marked_bytes();
665 init_top_at_mark_start();
666 }
668 // <PREDICTION>
669 void calc_gc_efficiency(void);
670 double gc_efficiency() { return _gc_efficiency;}
671 // </PREDICTION>
673 bool is_young() const { return _young_type != NotYoung; }
674 bool is_survivor() const { return _young_type == Survivor; }
676 int young_index_in_cset() const { return _young_index_in_cset; }
677 void set_young_index_in_cset(int index) {
678 assert( (index == -1) || is_young(), "pre-condition" );
679 _young_index_in_cset = index;
680 }
682 int age_in_surv_rate_group() {
683 assert( _surv_rate_group != NULL, "pre-condition" );
684 assert( _age_index > -1, "pre-condition" );
685 return _surv_rate_group->age_in_group(_age_index);
686 }
688 void record_surv_words_in_group(size_t words_survived) {
689 assert( _surv_rate_group != NULL, "pre-condition" );
690 assert( _age_index > -1, "pre-condition" );
691 int age_in_group = age_in_surv_rate_group();
692 _surv_rate_group->record_surviving_words(age_in_group, words_survived);
693 }
695 int age_in_surv_rate_group_cond() {
696 if (_surv_rate_group != NULL)
697 return age_in_surv_rate_group();
698 else
699 return -1;
700 }
702 SurvRateGroup* surv_rate_group() {
703 return _surv_rate_group;
704 }
706 void install_surv_rate_group(SurvRateGroup* surv_rate_group) {
707 assert( surv_rate_group != NULL, "pre-condition" );
708 assert( _surv_rate_group == NULL, "pre-condition" );
709 assert( is_young(), "pre-condition" );
711 _surv_rate_group = surv_rate_group;
712 _age_index = surv_rate_group->next_age_index();
713 }
715 void uninstall_surv_rate_group() {
716 if (_surv_rate_group != NULL) {
717 assert( _age_index > -1, "pre-condition" );
718 assert( is_young(), "pre-condition" );
720 _surv_rate_group = NULL;
721 _age_index = -1;
722 } else {
723 assert( _age_index == -1, "pre-condition" );
724 }
725 }
727 void set_young() { set_young_type(Young); }
729 void set_survivor() { set_young_type(Survivor); }
731 void set_not_young() { set_young_type(NotYoung); }
733 // Determine if an object has been allocated since the last
734 // mark performed by the collector. This returns true iff the object
735 // is within the unmarked area of the region.
736 bool obj_allocated_since_prev_marking(oop obj) const {
737 return (HeapWord *) obj >= prev_top_at_mark_start();
738 }
739 bool obj_allocated_since_next_marking(oop obj) const {
740 return (HeapWord *) obj >= next_top_at_mark_start();
741 }
743 // For parallel heapRegion traversal.
744 bool claimHeapRegion(int claimValue);
745 jint claim_value() { return _claimed; }
746 // Use this carefully: only when you're sure no one is claiming...
747 void set_claim_value(int claimValue) { _claimed = claimValue; }
749 // Returns the "evacuation_failed" property of the region.
750 bool evacuation_failed() { return _evacuation_failed; }
752 // Sets the "evacuation_failed" property of the region.
753 void set_evacuation_failed(bool b) {
754 _evacuation_failed = b;
756 if (b) {
757 init_top_at_conc_mark_count();
758 _next_marked_bytes = 0;
759 }
760 }
762 // Requires that "mr" be entirely within the region.
763 // Apply "cl->do_object" to all objects that intersect with "mr".
764 // If the iteration encounters an unparseable portion of the region,
765 // or if "cl->abort()" is true after a closure application,
766 // terminate the iteration and return the address of the start of the
767 // subregion that isn't done. (The two can be distinguished by querying
768 // "cl->abort()".) Return of "NULL" indicates that the iteration
769 // completed.
770 HeapWord*
771 object_iterate_mem_careful(MemRegion mr, ObjectClosure* cl);
773 // In this version - if filter_young is true and the region
774 // is a young region then we skip the iteration.
775 HeapWord*
776 oops_on_card_seq_iterate_careful(MemRegion mr,
777 FilterOutOfRegionClosure* cl,
778 bool filter_young);
780 // A version of block start that is guaranteed to find *some* block
781 // boundary at or before "p", but does not object iteration, and may
782 // therefore be used safely when the heap is unparseable.
783 HeapWord* block_start_careful(const void* p) const {
784 return _offsets.block_start_careful(p);
785 }
787 // Requires that "addr" is within the region. Returns the start of the
788 // first ("careful") block that starts at or after "addr", or else the
789 // "end" of the region if there is no such block.
790 HeapWord* next_block_start_careful(HeapWord* addr);
792 // Returns the zero-fill-state of the current region.
793 ZeroFillState zero_fill_state() { return (ZeroFillState)_zfs; }
794 bool zero_fill_is_allocated() { return _zfs == Allocated; }
795 Thread* zero_filler() { return _zero_filler; }
797 // Indicate that the contents of the region are unknown, and therefore
798 // might require zero-filling.
799 void set_zero_fill_needed() {
800 set_zero_fill_state_work(NotZeroFilled);
801 }
802 void set_zero_fill_in_progress(Thread* t) {
803 set_zero_fill_state_work(ZeroFilling);
804 _zero_filler = t;
805 }
806 void set_zero_fill_complete();
807 void set_zero_fill_allocated() {
808 set_zero_fill_state_work(Allocated);
809 }
811 void set_zero_fill_state_work(ZeroFillState zfs);
813 // This is called when a full collection shrinks the heap.
814 // We want to set the heap region to a value which says
815 // it is no longer part of the heap. For now, we'll let "NotZF" fill
816 // that role.
817 void reset_zero_fill() {
818 set_zero_fill_state_work(NotZeroFilled);
819 _zero_filler = NULL;
820 }
822 size_t recorded_rs_length() const { return _recorded_rs_length; }
823 double predicted_elapsed_time_ms() const { return _predicted_elapsed_time_ms; }
824 size_t predicted_bytes_to_copy() const { return _predicted_bytes_to_copy; }
826 void set_recorded_rs_length(size_t rs_length) {
827 _recorded_rs_length = rs_length;
828 }
830 void set_predicted_elapsed_time_ms(double ms) {
831 _predicted_elapsed_time_ms = ms;
832 }
834 void set_predicted_bytes_to_copy(size_t bytes) {
835 _predicted_bytes_to_copy = bytes;
836 }
838 #define HeapRegion_OOP_SINCE_SAVE_MARKS_DECL(OopClosureType, nv_suffix) \
839 virtual void oop_since_save_marks_iterate##nv_suffix(OopClosureType* cl);
840 SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES(HeapRegion_OOP_SINCE_SAVE_MARKS_DECL)
842 CompactibleSpace* next_compaction_space() const;
844 virtual void reset_after_compaction();
846 void print() const;
847 void print_on(outputStream* st) const;
849 // use_prev_marking == true -> use "prev" marking information,
850 // use_prev_marking == false -> use "next" marking information
851 // NOTE: Only the "prev" marking information is guaranteed to be
852 // consistent most of the time, so most calls to this should use
853 // use_prev_marking == true. Currently, there is only one case where
854 // this is called with use_prev_marking == false, which is to verify
855 // the "next" marking information at the end of remark.
856 void verify(bool allow_dirty, bool use_prev_marking, bool *failures) const;
858 // Override; it uses the "prev" marking information
859 virtual void verify(bool allow_dirty) const;
861 #ifdef DEBUG
862 HeapWord* allocate(size_t size);
863 #endif
864 };
866 // HeapRegionClosure is used for iterating over regions.
867 // Terminates the iteration when the "doHeapRegion" method returns "true".
868 class HeapRegionClosure : public StackObj {
869 friend class HeapRegionSeq;
870 friend class G1CollectedHeap;
872 bool _complete;
873 void incomplete() { _complete = false; }
875 public:
876 HeapRegionClosure(): _complete(true) {}
878 // Typically called on each region until it returns true.
879 virtual bool doHeapRegion(HeapRegion* r) = 0;
881 // True after iteration if the closure was applied to all heap regions
882 // and returned "false" in all cases.
883 bool complete() { return _complete; }
884 };
886 // A linked lists of heap regions. It leaves the "next" field
887 // unspecified; that's up to subtypes.
888 class RegionList VALUE_OBJ_CLASS_SPEC {
889 protected:
890 virtual HeapRegion* get_next(HeapRegion* chr) = 0;
891 virtual void set_next(HeapRegion* chr,
892 HeapRegion* new_next) = 0;
894 HeapRegion* _hd;
895 HeapRegion* _tl;
896 size_t _sz;
898 // Protected constructor because this type is only meaningful
899 // when the _get/_set next functions are defined.
900 RegionList() : _hd(NULL), _tl(NULL), _sz(0) {}
901 public:
902 void reset() {
903 _hd = NULL;
904 _tl = NULL;
905 _sz = 0;
906 }
907 HeapRegion* hd() { return _hd; }
908 HeapRegion* tl() { return _tl; }
909 size_t sz() { return _sz; }
910 size_t length();
912 bool well_formed() {
913 return
914 ((hd() == NULL && tl() == NULL && sz() == 0)
915 || (hd() != NULL && tl() != NULL && sz() > 0))
916 && (sz() == length());
917 }
918 virtual void insert_before_head(HeapRegion* r);
919 void prepend_list(RegionList* new_list);
920 virtual HeapRegion* pop();
921 void dec_sz() { _sz--; }
922 // Requires that "r" is an element of the list, and is not the tail.
923 void delete_after(HeapRegion* r);
924 };
926 class EmptyNonHRegionList: public RegionList {
927 protected:
928 // Protected constructor because this type is only meaningful
929 // when the _get/_set next functions are defined.
930 EmptyNonHRegionList() : RegionList() {}
932 public:
933 void insert_before_head(HeapRegion* r) {
934 // assert(r->is_empty(), "Better be empty");
935 assert(!r->isHumongous(), "Better not be humongous.");
936 RegionList::insert_before_head(r);
937 }
938 void prepend_list(EmptyNonHRegionList* new_list) {
939 // assert(new_list->hd() == NULL || new_list->hd()->is_empty(),
940 // "Better be empty");
941 assert(new_list->hd() == NULL || !new_list->hd()->isHumongous(),
942 "Better not be humongous.");
943 // assert(new_list->tl() == NULL || new_list->tl()->is_empty(),
944 // "Better be empty");
945 assert(new_list->tl() == NULL || !new_list->tl()->isHumongous(),
946 "Better not be humongous.");
947 RegionList::prepend_list(new_list);
948 }
949 };
951 class UncleanRegionList: public EmptyNonHRegionList {
952 public:
953 HeapRegion* get_next(HeapRegion* hr) {
954 return hr->next_from_unclean_list();
955 }
956 void set_next(HeapRegion* hr, HeapRegion* new_next) {
957 hr->set_next_on_unclean_list(new_next);
958 }
960 UncleanRegionList() : EmptyNonHRegionList() {}
962 void insert_before_head(HeapRegion* r) {
963 assert(!r->is_on_free_list(),
964 "Better not already be on free list");
965 assert(!r->is_on_unclean_list(),
966 "Better not already be on unclean list");
967 r->set_zero_fill_needed();
968 r->set_on_unclean_list(true);
969 EmptyNonHRegionList::insert_before_head(r);
970 }
971 void prepend_list(UncleanRegionList* new_list) {
972 assert(new_list->tl() == NULL || !new_list->tl()->is_on_free_list(),
973 "Better not already be on free list");
974 assert(new_list->tl() == NULL || new_list->tl()->is_on_unclean_list(),
975 "Better already be marked as on unclean list");
976 assert(new_list->hd() == NULL || !new_list->hd()->is_on_free_list(),
977 "Better not already be on free list");
978 assert(new_list->hd() == NULL || new_list->hd()->is_on_unclean_list(),
979 "Better already be marked as on unclean list");
980 EmptyNonHRegionList::prepend_list(new_list);
981 }
982 HeapRegion* pop() {
983 HeapRegion* res = RegionList::pop();
984 if (res != NULL) res->set_on_unclean_list(false);
985 return res;
986 }
987 };
989 // Local Variables: ***
990 // c-indentation-style: gnu ***
991 // End: ***
993 #endif // SERIALGC
995 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGION_HPP