annotate src/share/vm/gc_implementation/g1/heapRegion.hpp @ 2741:8229bd737950

7075646: G1: fix inconsistencies in the monitoring data Summary: Fixed a few inconsistencies in the monitoring data, in particular when reported from jstat. Reviewed-by: jmasa, brutisso, johnc
author tonyp
date Fri, 23 Sep 2011 16:07:49 -0400
parents 4dfb2df418f2
children 65a8ff39a6da
rev   line source
ysr@342 1 /*
tonyp@2018 2 * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
ysr@342 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ysr@342 4 *
ysr@342 5 * This code is free software; you can redistribute it and/or modify it
ysr@342 6 * under the terms of the GNU General Public License version 2 only, as
ysr@342 7 * published by the Free Software Foundation.
ysr@342 8 *
ysr@342 9 * This code is distributed in the hope that it will be useful, but WITHOUT
ysr@342 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ysr@342 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ysr@342 12 * version 2 for more details (a copy is included in the LICENSE file that
ysr@342 13 * accompanied this code).
ysr@342 14 *
ysr@342 15 * You should have received a copy of the GNU General Public License version
ysr@342 16 * 2 along with this work; if not, write to the Free Software Foundation,
ysr@342 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ysr@342 18 *
trims@1472 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1472 20 * or visit www.oracle.com if you need additional information or have any
trims@1472 21 * questions.
ysr@342 22 *
ysr@342 23 */
ysr@342 24
stefank@1879 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGION_HPP
stefank@1879 26 #define SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGION_HPP
stefank@1879 27
stefank@1879 28 #include "gc_implementation/g1/g1BlockOffsetTable.inline.hpp"
stefank@1879 29 #include "gc_implementation/g1/g1_specialized_oop_closures.hpp"
stefank@1879 30 #include "gc_implementation/g1/survRateGroup.hpp"
stefank@1879 31 #include "gc_implementation/shared/ageTable.hpp"
stefank@1879 32 #include "gc_implementation/shared/spaceDecorator.hpp"
stefank@1879 33 #include "memory/space.inline.hpp"
stefank@1879 34 #include "memory/watermark.hpp"
stefank@1879 35
ysr@342 36 #ifndef SERIALGC
ysr@342 37
ysr@342 38 // A HeapRegion is the smallest piece of a G1CollectedHeap that
ysr@342 39 // can be collected independently.
ysr@342 40
ysr@342 41 // NOTE: Although a HeapRegion is a Space, its
ysr@342 42 // Space::initDirtyCardClosure method must not be called.
ysr@342 43 // The problem is that the existence of this method breaks
ysr@342 44 // the independence of barrier sets from remembered sets.
ysr@342 45 // The solution is to remove this method from the definition
ysr@342 46 // of a Space.
ysr@342 47
ysr@342 48 class CompactibleSpace;
ysr@342 49 class ContiguousSpace;
ysr@342 50 class HeapRegionRemSet;
ysr@342 51 class HeapRegionRemSetIterator;
ysr@342 52 class HeapRegion;
tonyp@2037 53 class HeapRegionSetBase;
tonyp@2037 54
tonyp@2528 55 #define HR_FORMAT SIZE_FORMAT":(%s)["PTR_FORMAT","PTR_FORMAT","PTR_FORMAT"]"
tonyp@2528 56 #define HR_FORMAT_PARAMS(_hr_) \
tonyp@2528 57 (_hr_)->hrs_index(), \
tonyp@2528 58 (_hr_)->is_survivor() ? "S" : (_hr_)->is_young() ? "E" : "-", \
tonyp@2528 59 (_hr_)->bottom(), (_hr_)->top(), (_hr_)->end()
ysr@342 60
ysr@342 61 // A dirty card to oop closure for heap regions. It
ysr@342 62 // knows how to get the G1 heap and how to use the bitmap
ysr@342 63 // in the concurrent marker used by G1 to filter remembered
ysr@342 64 // sets.
ysr@342 65
ysr@342 66 class HeapRegionDCTOC : public ContiguousSpaceDCTOC {
ysr@342 67 public:
ysr@342 68 // Specification of possible DirtyCardToOopClosure filtering.
ysr@342 69 enum FilterKind {
ysr@342 70 NoFilterKind,
ysr@342 71 IntoCSFilterKind,
ysr@342 72 OutOfRegionFilterKind
ysr@342 73 };
ysr@342 74
ysr@342 75 protected:
ysr@342 76 HeapRegion* _hr;
ysr@342 77 FilterKind _fk;
ysr@342 78 G1CollectedHeap* _g1;
ysr@342 79
ysr@342 80 void walk_mem_region_with_cl(MemRegion mr,
ysr@342 81 HeapWord* bottom, HeapWord* top,
ysr@342 82 OopClosure* cl);
ysr@342 83
ysr@342 84 // We don't specialize this for FilteringClosure; filtering is handled by
ysr@342 85 // the "FilterKind" mechanism. But we provide this to avoid a compiler
ysr@342 86 // warning.
ysr@342 87 void walk_mem_region_with_cl(MemRegion mr,
ysr@342 88 HeapWord* bottom, HeapWord* top,
ysr@342 89 FilteringClosure* cl) {
ysr@342 90 HeapRegionDCTOC::walk_mem_region_with_cl(mr, bottom, top,
ysr@342 91 (OopClosure*)cl);
ysr@342 92 }
ysr@342 93
ysr@342 94 // Get the actual top of the area on which the closure will
ysr@342 95 // operate, given where the top is assumed to be (the end of the
ysr@342 96 // memory region passed to do_MemRegion) and where the object
ysr@342 97 // at the top is assumed to start. For example, an object may
ysr@342 98 // start at the top but actually extend past the assumed top,
ysr@342 99 // in which case the top becomes the end of the object.
ysr@342 100 HeapWord* get_actual_top(HeapWord* top, HeapWord* top_obj) {
ysr@342 101 return ContiguousSpaceDCTOC::get_actual_top(top, top_obj);
ysr@342 102 }
ysr@342 103
ysr@342 104 // Walk the given memory region from bottom to (actual) top
ysr@342 105 // looking for objects and applying the oop closure (_cl) to
ysr@342 106 // them. The base implementation of this treats the area as
ysr@342 107 // blocks, where a block may or may not be an object. Sub-
ysr@342 108 // classes should override this to provide more accurate
ysr@342 109 // or possibly more efficient walking.
ysr@342 110 void walk_mem_region(MemRegion mr, HeapWord* bottom, HeapWord* top) {
ysr@342 111 Filtering_DCTOC::walk_mem_region(mr, bottom, top);
ysr@342 112 }
ysr@342 113
ysr@342 114 public:
ysr@342 115 HeapRegionDCTOC(G1CollectedHeap* g1,
ysr@342 116 HeapRegion* hr, OopClosure* cl,
ysr@342 117 CardTableModRefBS::PrecisionStyle precision,
ysr@342 118 FilterKind fk);
ysr@342 119 };
ysr@342 120
ysr@342 121 // The complicating factor is that BlockOffsetTable diverged
ysr@342 122 // significantly, and we need functionality that is only in the G1 version.
ysr@342 123 // So I copied that code, which led to an alternate G1 version of
ysr@342 124 // OffsetTableContigSpace. If the two versions of BlockOffsetTable could
ysr@342 125 // be reconciled, then G1OffsetTableContigSpace could go away.
ysr@342 126
ysr@342 127 // The idea behind time stamps is the following. Doing a save_marks on
ysr@342 128 // all regions at every GC pause is time consuming (if I remember
ysr@342 129 // well, 10ms or so). So, we would like to do that only for regions
ysr@342 130 // that are GC alloc regions. To achieve this, we use time
ysr@342 131 // stamps. For every evacuation pause, G1CollectedHeap generates a
ysr@342 132 // unique time stamp (essentially a counter that gets
ysr@342 133 // incremented). Every time we want to call save_marks on a region,
ysr@342 134 // we set the saved_mark_word to top and also copy the current GC
ysr@342 135 // time stamp to the time stamp field of the space. Reading the
ysr@342 136 // saved_mark_word involves checking the time stamp of the
ysr@342 137 // region. If it is the same as the current GC time stamp, then we
ysr@342 138 // can safely read the saved_mark_word field, as it is valid. If the
ysr@342 139 // time stamp of the region is not the same as the current GC time
ysr@342 140 // stamp, then we instead read top, as the saved_mark_word field is
ysr@342 141 // invalid. Time stamps (on the regions and also on the
ysr@342 142 // G1CollectedHeap) are reset at every cleanup (we iterate over
ysr@342 143 // the regions anyway) and at the end of a Full GC. The current scheme
ysr@342 144 // that uses sequential unsigned ints will fail only if we have 4b
ysr@342 145 // evacuation pauses between two cleanups, which is _highly_ unlikely.
ysr@342 146
ysr@342 147 class G1OffsetTableContigSpace: public ContiguousSpace {
ysr@342 148 friend class VMStructs;
ysr@342 149 protected:
ysr@342 150 G1BlockOffsetArrayContigSpace _offsets;
ysr@342 151 Mutex _par_alloc_lock;
ysr@342 152 volatile unsigned _gc_time_stamp;
tonyp@2280 153 // When we need to retire an allocation region, while other threads
tonyp@2280 154 // are also concurrently trying to allocate into it, we typically
tonyp@2280 155 // allocate a dummy object at the end of the region to ensure that
tonyp@2280 156 // no more allocations can take place in it. However, sometimes we
tonyp@2280 157 // want to know where the end of the last "real" object we allocated
tonyp@2280 158 // into the region was and this is what this keeps track.
tonyp@2280 159 HeapWord* _pre_dummy_top;
ysr@342 160
ysr@342 161 public:
ysr@342 162 // Constructor. If "is_zeroed" is true, the MemRegion "mr" may be
ysr@342 163 // assumed to contain zeros.
ysr@342 164 G1OffsetTableContigSpace(G1BlockOffsetSharedArray* sharedOffsetArray,
ysr@342 165 MemRegion mr, bool is_zeroed = false);
ysr@342 166
ysr@342 167 void set_bottom(HeapWord* value);
ysr@342 168 void set_end(HeapWord* value);
ysr@342 169
ysr@342 170 virtual HeapWord* saved_mark_word() const;
ysr@342 171 virtual void set_saved_mark();
ysr@342 172 void reset_gc_time_stamp() { _gc_time_stamp = 0; }
ysr@342 173
tonyp@2280 174 // See the comment above in the declaration of _pre_dummy_top for an
tonyp@2280 175 // explanation of what it is.
tonyp@2280 176 void set_pre_dummy_top(HeapWord* pre_dummy_top) {
tonyp@2280 177 assert(is_in(pre_dummy_top) && pre_dummy_top <= top(), "pre-condition");
tonyp@2280 178 _pre_dummy_top = pre_dummy_top;
tonyp@2280 179 }
tonyp@2280 180 HeapWord* pre_dummy_top() {
tonyp@2280 181 return (_pre_dummy_top == NULL) ? top() : _pre_dummy_top;
tonyp@2280 182 }
tonyp@2280 183 void reset_pre_dummy_top() { _pre_dummy_top = NULL; }
tonyp@2280 184
tonyp@356 185 virtual void initialize(MemRegion mr, bool clear_space, bool mangle_space);
tonyp@356 186 virtual void clear(bool mangle_space);
ysr@342 187
ysr@342 188 HeapWord* block_start(const void* p);
ysr@342 189 HeapWord* block_start_const(const void* p) const;
ysr@342 190
ysr@342 191 // Add offset table update.
ysr@342 192 virtual HeapWord* allocate(size_t word_size);
ysr@342 193 HeapWord* par_allocate(size_t word_size);
ysr@342 194
ysr@342 195 // MarkSweep support phase3
ysr@342 196 virtual HeapWord* initialize_threshold();
ysr@342 197 virtual HeapWord* cross_threshold(HeapWord* start, HeapWord* end);
ysr@342 198
ysr@342 199 virtual void print() const;
tonyp@2018 200
tonyp@2018 201 void reset_bot() {
tonyp@2018 202 _offsets.zero_bottom_entry();
tonyp@2018 203 _offsets.initialize_threshold();
tonyp@2018 204 }
tonyp@2018 205
tonyp@2018 206 void update_bot_for_object(HeapWord* start, size_t word_size) {
tonyp@2018 207 _offsets.alloc_block(start, word_size);
tonyp@2018 208 }
tonyp@2018 209
tonyp@2018 210 void print_bot_on(outputStream* out) {
tonyp@2018 211 _offsets.print_on(out);
tonyp@2018 212 }
ysr@342 213 };
ysr@342 214
ysr@342 215 class HeapRegion: public G1OffsetTableContigSpace {
ysr@342 216 friend class VMStructs;
ysr@342 217 private:
ysr@342 218
tonyp@355 219 enum HumongousType {
tonyp@355 220 NotHumongous = 0,
tonyp@355 221 StartsHumongous,
tonyp@355 222 ContinuesHumongous
tonyp@355 223 };
tonyp@355 224
ysr@342 225 // Requires that the region "mr" be dense with objects, and begin and end
ysr@342 226 // with an object.
ysr@342 227 void oops_in_mr_iterate(MemRegion mr, OopClosure* cl);
ysr@342 228
ysr@342 229 // The remembered set for this region.
ysr@342 230 // (Might want to make this "inline" later, to avoid some alloc failure
ysr@342 231 // issues.)
ysr@342 232 HeapRegionRemSet* _rem_set;
ysr@342 233
ysr@342 234 G1BlockOffsetArrayContigSpace* offsets() { return &_offsets; }
ysr@342 235
ysr@342 236 protected:
tonyp@2528 237 // The index of this region in the heap region sequence.
tonyp@2528 238 size_t _hrs_index;
ysr@342 239
tonyp@355 240 HumongousType _humongous_type;
ysr@342 241 // For a humongous region, region in which it starts.
ysr@342 242 HeapRegion* _humongous_start_region;
ysr@342 243 // For the start region of a humongous sequence, it's original end().
ysr@342 244 HeapWord* _orig_end;
ysr@342 245
ysr@342 246 // True iff the region is in current collection_set.
ysr@342 247 bool _in_collection_set;
ysr@342 248
ysr@342 249 // True iff an attempt to evacuate an object in the region failed.
ysr@342 250 bool _evacuation_failed;
ysr@342 251
ysr@342 252 // A heap region may be a member one of a number of special subsets, each
ysr@342 253 // represented as linked lists through the field below. Currently, these
ysr@342 254 // sets include:
ysr@342 255 // The collection set.
ysr@342 256 // The set of allocation regions used in a collection pause.
ysr@342 257 // Spaces that may contain gray objects.
ysr@342 258 HeapRegion* _next_in_special_set;
ysr@342 259
ysr@342 260 // next region in the young "generation" region set
ysr@342 261 HeapRegion* _next_young_region;
ysr@342 262
apetrusenko@796 263 // Next region whose cards need cleaning
apetrusenko@796 264 HeapRegion* _next_dirty_cards_region;
apetrusenko@796 265
tonyp@2037 266 // Fields used by the HeapRegionSetBase class and subclasses.
tonyp@2037 267 HeapRegion* _next;
tonyp@2037 268 #ifdef ASSERT
tonyp@2037 269 HeapRegionSetBase* _containing_set;
tonyp@2037 270 #endif // ASSERT
tonyp@2037 271 bool _pending_removal;
tonyp@2037 272
ysr@342 273 // For parallel heapRegion traversal.
ysr@342 274 jint _claimed;
ysr@342 275
ysr@342 276 // We use concurrent marking to determine the amount of live data
ysr@342 277 // in each heap region.
ysr@342 278 size_t _prev_marked_bytes; // Bytes known to be live via last completed marking.
ysr@342 279 size_t _next_marked_bytes; // Bytes known to be live via in-progress marking.
ysr@342 280
ysr@342 281 // See "sort_index" method. -1 means is not in the array.
ysr@342 282 int _sort_index;
ysr@342 283
ysr@342 284 // <PREDICTION>
ysr@342 285 double _gc_efficiency;
ysr@342 286 // </PREDICTION>
ysr@342 287
ysr@342 288 enum YoungType {
ysr@342 289 NotYoung, // a region is not young
ysr@342 290 Young, // a region is young
tonyp@2528 291 Survivor // a region is young and it contains survivors
ysr@342 292 };
ysr@342 293
johnc@1586 294 volatile YoungType _young_type;
ysr@342 295 int _young_index_in_cset;
ysr@342 296 SurvRateGroup* _surv_rate_group;
ysr@342 297 int _age_index;
ysr@342 298
ysr@342 299 // The start of the unmarked area. The unmarked area extends from this
ysr@342 300 // word until the top and/or end of the region, and is the part
ysr@342 301 // of the region for which no marking was done, i.e. objects may
ysr@342 302 // have been allocated in this part since the last mark phase.
ysr@342 303 // "prev" is the top at the start of the last completed marking.
ysr@342 304 // "next" is the top at the start of the in-progress marking (if any.)
ysr@342 305 HeapWord* _prev_top_at_mark_start;
ysr@342 306 HeapWord* _next_top_at_mark_start;
ysr@342 307 // If a collection pause is in progress, this is the top at the start
ysr@342 308 // of that pause.
ysr@342 309
ysr@342 310 // We've counted the marked bytes of objects below here.
ysr@342 311 HeapWord* _top_at_conc_mark_count;
ysr@342 312
ysr@342 313 void init_top_at_mark_start() {
ysr@342 314 assert(_prev_marked_bytes == 0 &&
ysr@342 315 _next_marked_bytes == 0,
ysr@342 316 "Must be called after zero_marked_bytes.");
ysr@342 317 HeapWord* bot = bottom();
ysr@342 318 _prev_top_at_mark_start = bot;
ysr@342 319 _next_top_at_mark_start = bot;
ysr@342 320 _top_at_conc_mark_count = bot;
ysr@342 321 }
ysr@342 322
ysr@342 323 void set_young_type(YoungType new_type) {
ysr@342 324 //assert(_young_type != new_type, "setting the same type" );
ysr@342 325 // TODO: add more assertions here
ysr@342 326 _young_type = new_type;
ysr@342 327 }
ysr@342 328
johnc@1394 329 // Cached attributes used in the collection set policy information
johnc@1394 330
johnc@1394 331 // The RSet length that was added to the total value
johnc@1394 332 // for the collection set.
johnc@1394 333 size_t _recorded_rs_length;
johnc@1394 334
johnc@1394 335 // The predicted elapsed time that was added to total value
johnc@1394 336 // for the collection set.
johnc@1394 337 double _predicted_elapsed_time_ms;
johnc@1394 338
johnc@1394 339 // The predicted number of bytes to copy that was added to
johnc@1394 340 // the total value for the collection set.
johnc@1394 341 size_t _predicted_bytes_to_copy;
johnc@1394 342
ysr@342 343 public:
ysr@342 344 // If "is_zeroed" is "true", the region "mr" can be assumed to contain zeros.
tonyp@2528 345 HeapRegion(size_t hrs_index,
tonyp@2528 346 G1BlockOffsetSharedArray* sharedOffsetArray,
ysr@342 347 MemRegion mr, bool is_zeroed);
ysr@342 348
tonyp@942 349 static int LogOfHRGrainBytes;
tonyp@942 350 static int LogOfHRGrainWords;
tonyp@942 351 // The normal type of these should be size_t. However, they used to
tonyp@942 352 // be members of an enum before and they are assumed by the
tonyp@942 353 // compilers to be ints. To avoid going and fixing all their uses,
tonyp@942 354 // I'm declaring them as ints. I'm not anticipating heap region
tonyp@942 355 // sizes to reach anywhere near 2g, so using an int here is safe.
tonyp@942 356 static int GrainBytes;
tonyp@942 357 static int GrainWords;
tonyp@942 358 static int CardsPerRegion;
tonyp@942 359
tonyp@2741 360 static size_t align_up_to_region_byte_size(size_t sz) {
tonyp@2741 361 return (sz + (size_t) GrainBytes - 1) &
tonyp@2741 362 ~((1 << (size_t) LogOfHRGrainBytes) - 1);
tonyp@2741 363 }
tonyp@2741 364
tonyp@942 365 // It sets up the heap region size (GrainBytes / GrainWords), as
tonyp@942 366 // well as other related fields that are based on the heap region
tonyp@942 367 // size (LogOfHRGrainBytes / LogOfHRGrainWords /
tonyp@942 368 // CardsPerRegion). All those fields are considered constant
tonyp@942 369 // throughout the JVM's execution, therefore they should only be set
tonyp@942 370 // up once during initialization time.
tonyp@942 371 static void setup_heap_region_size(uintx min_heap_size);
ysr@342 372
tonyp@355 373 enum ClaimValues {
tonyp@355 374 InitialClaimValue = 0,
tonyp@355 375 FinalCountClaimValue = 1,
tonyp@355 376 NoteEndClaimValue = 2,
tonyp@390 377 ScrubRemSetClaimValue = 3,
apetrusenko@626 378 ParVerifyClaimValue = 4,
apetrusenko@626 379 RebuildRSClaimValue = 5
tonyp@355 380 };
tonyp@355 381
tonyp@2019 382 inline HeapWord* par_allocate_no_bot_updates(size_t word_size) {
tonyp@2019 383 assert(is_young(), "we can only skip BOT updates on young regions");
tonyp@2019 384 return ContiguousSpace::par_allocate(word_size);
tonyp@2019 385 }
tonyp@2019 386 inline HeapWord* allocate_no_bot_updates(size_t word_size) {
tonyp@2019 387 assert(is_young(), "we can only skip BOT updates on young regions");
tonyp@2019 388 return ContiguousSpace::allocate(word_size);
tonyp@2019 389 }
tonyp@2019 390
ysr@342 391 // If this region is a member of a HeapRegionSeq, the index in that
ysr@342 392 // sequence, otherwise -1.
tonyp@2528 393 size_t hrs_index() const { return _hrs_index; }
ysr@342 394
ysr@342 395 // The number of bytes marked live in the region in the last marking phase.
ysr@342 396 size_t marked_bytes() { return _prev_marked_bytes; }
tonyp@2282 397 size_t live_bytes() {
tonyp@2282 398 return (top() - prev_top_at_mark_start()) * HeapWordSize + marked_bytes();
tonyp@2282 399 }
tonyp@2282 400
ysr@342 401 // The number of bytes counted in the next marking.
ysr@342 402 size_t next_marked_bytes() { return _next_marked_bytes; }
ysr@342 403 // The number of bytes live wrt the next marking.
ysr@342 404 size_t next_live_bytes() {
tonyp@2282 405 return
tonyp@2282 406 (top() - next_top_at_mark_start()) * HeapWordSize + next_marked_bytes();
ysr@342 407 }
ysr@342 408
ysr@342 409 // A lower bound on the amount of garbage bytes in the region.
ysr@342 410 size_t garbage_bytes() {
ysr@342 411 size_t used_at_mark_start_bytes =
ysr@342 412 (prev_top_at_mark_start() - bottom()) * HeapWordSize;
ysr@342 413 assert(used_at_mark_start_bytes >= marked_bytes(),
ysr@342 414 "Can't mark more than we have.");
ysr@342 415 return used_at_mark_start_bytes - marked_bytes();
ysr@342 416 }
ysr@342 417
ysr@342 418 // An upper bound on the number of live bytes in the region.
ysr@342 419 size_t max_live_bytes() { return used() - garbage_bytes(); }
ysr@342 420
ysr@342 421 void add_to_marked_bytes(size_t incr_bytes) {
ysr@342 422 _next_marked_bytes = _next_marked_bytes + incr_bytes;
ysr@342 423 guarantee( _next_marked_bytes <= used(), "invariant" );
ysr@342 424 }
ysr@342 425
ysr@342 426 void zero_marked_bytes() {
ysr@342 427 _prev_marked_bytes = _next_marked_bytes = 0;
ysr@342 428 }
ysr@342 429
tonyp@355 430 bool isHumongous() const { return _humongous_type != NotHumongous; }
tonyp@355 431 bool startsHumongous() const { return _humongous_type == StartsHumongous; }
tonyp@355 432 bool continuesHumongous() const { return _humongous_type == ContinuesHumongous; }
ysr@342 433 // For a humongous region, region in which it starts.
ysr@342 434 HeapRegion* humongous_start_region() const {
ysr@342 435 return _humongous_start_region;
ysr@342 436 }
ysr@342 437
tonyp@2018 438 // Makes the current region be a "starts humongous" region, i.e.,
tonyp@2018 439 // the first region in a series of one or more contiguous regions
tonyp@2018 440 // that will contain a single "humongous" object. The two parameters
tonyp@2018 441 // are as follows:
tonyp@2018 442 //
tonyp@2018 443 // new_top : The new value of the top field of this region which
tonyp@2018 444 // points to the end of the humongous object that's being
tonyp@2018 445 // allocated. If there is more than one region in the series, top
tonyp@2018 446 // will lie beyond this region's original end field and on the last
tonyp@2018 447 // region in the series.
tonyp@2018 448 //
tonyp@2018 449 // new_end : The new value of the end field of this region which
tonyp@2018 450 // points to the end of the last region in the series. If there is
tonyp@2018 451 // one region in the series (namely: this one) end will be the same
tonyp@2018 452 // as the original end of this region.
tonyp@2018 453 //
tonyp@2018 454 // Updating top and end as described above makes this region look as
tonyp@2018 455 // if it spans the entire space taken up by all the regions in the
tonyp@2018 456 // series and an single allocation moved its top to new_top. This
tonyp@2018 457 // ensures that the space (capacity / allocated) taken up by all
tonyp@2018 458 // humongous regions can be calculated by just looking at the
tonyp@2018 459 // "starts humongous" regions and by ignoring the "continues
tonyp@2018 460 // humongous" regions.
tonyp@2018 461 void set_startsHumongous(HeapWord* new_top, HeapWord* new_end);
ysr@342 462
tonyp@2018 463 // Makes the current region be a "continues humongous'
tonyp@2018 464 // region. first_hr is the "start humongous" region of the series
tonyp@2018 465 // which this region will be part of.
tonyp@2018 466 void set_continuesHumongous(HeapRegion* first_hr);
ysr@342 467
tonyp@2037 468 // Unsets the humongous-related fields on the region.
tonyp@2037 469 void set_notHumongous();
tonyp@2037 470
ysr@342 471 // If the region has a remembered set, return a pointer to it.
ysr@342 472 HeapRegionRemSet* rem_set() const {
ysr@342 473 return _rem_set;
ysr@342 474 }
ysr@342 475
ysr@342 476 // True iff the region is in current collection_set.
ysr@342 477 bool in_collection_set() const {
ysr@342 478 return _in_collection_set;
ysr@342 479 }
ysr@342 480 void set_in_collection_set(bool b) {
ysr@342 481 _in_collection_set = b;
ysr@342 482 }
ysr@342 483 HeapRegion* next_in_collection_set() {
ysr@342 484 assert(in_collection_set(), "should only invoke on member of CS.");
ysr@342 485 assert(_next_in_special_set == NULL ||
ysr@342 486 _next_in_special_set->in_collection_set(),
ysr@342 487 "Malformed CS.");
ysr@342 488 return _next_in_special_set;
ysr@342 489 }
ysr@342 490 void set_next_in_collection_set(HeapRegion* r) {
ysr@342 491 assert(in_collection_set(), "should only invoke on member of CS.");
ysr@342 492 assert(r == NULL || r->in_collection_set(), "Malformed CS.");
ysr@342 493 _next_in_special_set = r;
ysr@342 494 }
ysr@342 495
tonyp@2037 496 // Methods used by the HeapRegionSetBase class and subclasses.
tonyp@2037 497
tonyp@2037 498 // Getter and setter for the next field used to link regions into
tonyp@2037 499 // linked lists.
tonyp@2037 500 HeapRegion* next() { return _next; }
tonyp@2037 501
tonyp@2037 502 void set_next(HeapRegion* next) { _next = next; }
tonyp@2037 503
tonyp@2037 504 // Every region added to a set is tagged with a reference to that
tonyp@2037 505 // set. This is used for doing consistency checking to make sure that
tonyp@2037 506 // the contents of a set are as they should be and it's only
tonyp@2037 507 // available in non-product builds.
tonyp@2037 508 #ifdef ASSERT
tonyp@2037 509 void set_containing_set(HeapRegionSetBase* containing_set) {
tonyp@2037 510 assert((containing_set == NULL && _containing_set != NULL) ||
tonyp@2037 511 (containing_set != NULL && _containing_set == NULL),
tonyp@2037 512 err_msg("containing_set: "PTR_FORMAT" "
tonyp@2037 513 "_containing_set: "PTR_FORMAT,
tonyp@2037 514 containing_set, _containing_set));
tonyp@2037 515
tonyp@2037 516 _containing_set = containing_set;
tonyp@2208 517 }
tonyp@2037 518
tonyp@2037 519 HeapRegionSetBase* containing_set() { return _containing_set; }
tonyp@2037 520 #else // ASSERT
tonyp@2037 521 void set_containing_set(HeapRegionSetBase* containing_set) { }
tonyp@2037 522
tonyp@2208 523 // containing_set() is only used in asserts so there's no reason
tonyp@2037 524 // to provide a dummy version of it.
tonyp@2037 525 #endif // ASSERT
tonyp@2037 526
tonyp@2037 527 // If we want to remove regions from a list in bulk we can simply tag
tonyp@2037 528 // them with the pending_removal tag and call the
tonyp@2037 529 // remove_all_pending() method on the list.
tonyp@2037 530
tonyp@2037 531 bool pending_removal() { return _pending_removal; }
tonyp@2037 532
tonyp@2037 533 void set_pending_removal(bool pending_removal) {
tonyp@2208 534 if (pending_removal) {
tonyp@2208 535 assert(!_pending_removal && containing_set() != NULL,
tonyp@2208 536 "can only set pending removal to true if it's false and "
tonyp@2208 537 "the region belongs to a region set");
tonyp@2208 538 } else {
tonyp@2208 539 assert( _pending_removal && containing_set() == NULL,
tonyp@2208 540 "can only set pending removal to false if it's true and "
tonyp@2208 541 "the region does not belong to a region set");
tonyp@2208 542 }
tonyp@2037 543
tonyp@2037 544 _pending_removal = pending_removal;
ysr@342 545 }
ysr@342 546
ysr@342 547 HeapRegion* get_next_young_region() { return _next_young_region; }
ysr@342 548 void set_next_young_region(HeapRegion* hr) {
ysr@342 549 _next_young_region = hr;
ysr@342 550 }
ysr@342 551
apetrusenko@796 552 HeapRegion* get_next_dirty_cards_region() const { return _next_dirty_cards_region; }
apetrusenko@796 553 HeapRegion** next_dirty_cards_region_addr() { return &_next_dirty_cards_region; }
apetrusenko@796 554 void set_next_dirty_cards_region(HeapRegion* hr) { _next_dirty_cards_region = hr; }
apetrusenko@796 555 bool is_on_dirty_cards_region_list() const { return get_next_dirty_cards_region() != NULL; }
apetrusenko@796 556
tonyp@2528 557 HeapWord* orig_end() { return _orig_end; }
tonyp@2528 558
ysr@342 559 // Allows logical separation between objects allocated before and after.
ysr@342 560 void save_marks();
ysr@342 561
ysr@342 562 // Reset HR stuff to default values.
ysr@342 563 void hr_clear(bool par, bool clear_space);
tonyp@2414 564 void par_clear();
ysr@342 565
tonyp@356 566 void initialize(MemRegion mr, bool clear_space, bool mangle_space);
ysr@342 567
ysr@342 568 // Get the start of the unmarked area in this region.
ysr@342 569 HeapWord* prev_top_at_mark_start() const { return _prev_top_at_mark_start; }
ysr@342 570 HeapWord* next_top_at_mark_start() const { return _next_top_at_mark_start; }
ysr@342 571
ysr@342 572 // Apply "cl->do_oop" to (the addresses of) all reference fields in objects
ysr@342 573 // allocated in the current region before the last call to "save_mark".
ysr@342 574 void oop_before_save_marks_iterate(OopClosure* cl);
ysr@342 575
ysr@342 576 DirtyCardToOopClosure*
ysr@342 577 new_dcto_closure(OopClosure* cl,
ysr@342 578 CardTableModRefBS::PrecisionStyle precision,
ysr@342 579 HeapRegionDCTOC::FilterKind fk);
ysr@342 580
ysr@342 581 // Note the start or end of marking. This tells the heap region
ysr@342 582 // that the collector is about to start or has finished (concurrently)
ysr@342 583 // marking the heap.
ysr@342 584
ysr@342 585 // Note the start of a marking phase. Record the
ysr@342 586 // start of the unmarked area of the region here.
ysr@342 587 void note_start_of_marking(bool during_initial_mark) {
ysr@342 588 init_top_at_conc_mark_count();
ysr@342 589 _next_marked_bytes = 0;
ysr@342 590 if (during_initial_mark && is_young() && !is_survivor())
ysr@342 591 _next_top_at_mark_start = bottom();
ysr@342 592 else
ysr@342 593 _next_top_at_mark_start = top();
ysr@342 594 }
ysr@342 595
ysr@342 596 // Note the end of a marking phase. Install the start of
ysr@342 597 // the unmarked area that was captured at start of marking.
ysr@342 598 void note_end_of_marking() {
ysr@342 599 _prev_top_at_mark_start = _next_top_at_mark_start;
ysr@342 600 _prev_marked_bytes = _next_marked_bytes;
ysr@342 601 _next_marked_bytes = 0;
ysr@342 602
ysr@342 603 guarantee(_prev_marked_bytes <=
ysr@342 604 (size_t) (prev_top_at_mark_start() - bottom()) * HeapWordSize,
ysr@342 605 "invariant");
ysr@342 606 }
ysr@342 607
ysr@342 608 // After an evacuation, we need to update _next_top_at_mark_start
ysr@342 609 // to be the current top. Note this is only valid if we have only
ysr@342 610 // ever evacuated into this region. If we evacuate, allocate, and
ysr@342 611 // then evacuate we are in deep doodoo.
ysr@342 612 void note_end_of_copying() {
tonyp@1021 613 assert(top() >= _next_top_at_mark_start, "Increase only");
tonyp@1021 614 _next_top_at_mark_start = top();
ysr@342 615 }
ysr@342 616
ysr@342 617 // Returns "false" iff no object in the region was allocated when the
ysr@342 618 // last mark phase ended.
ysr@342 619 bool is_marked() { return _prev_top_at_mark_start != bottom(); }
ysr@342 620
ysr@342 621 // If "is_marked()" is true, then this is the index of the region in
ysr@342 622 // an array constructed at the end of marking of the regions in a
ysr@342 623 // "desirability" order.
ysr@342 624 int sort_index() {
ysr@342 625 return _sort_index;
ysr@342 626 }
ysr@342 627 void set_sort_index(int i) {
ysr@342 628 _sort_index = i;
ysr@342 629 }
ysr@342 630
ysr@342 631 void init_top_at_conc_mark_count() {
ysr@342 632 _top_at_conc_mark_count = bottom();
ysr@342 633 }
ysr@342 634
ysr@342 635 void set_top_at_conc_mark_count(HeapWord *cur) {
ysr@342 636 assert(bottom() <= cur && cur <= end(), "Sanity.");
ysr@342 637 _top_at_conc_mark_count = cur;
ysr@342 638 }
ysr@342 639
ysr@342 640 HeapWord* top_at_conc_mark_count() {
ysr@342 641 return _top_at_conc_mark_count;
ysr@342 642 }
ysr@342 643
ysr@342 644 void reset_during_compaction() {
ysr@342 645 guarantee( isHumongous() && startsHumongous(),
ysr@342 646 "should only be called for humongous regions");
ysr@342 647
ysr@342 648 zero_marked_bytes();
ysr@342 649 init_top_at_mark_start();
ysr@342 650 }
ysr@342 651
ysr@342 652 // <PREDICTION>
ysr@342 653 void calc_gc_efficiency(void);
ysr@342 654 double gc_efficiency() { return _gc_efficiency;}
ysr@342 655 // </PREDICTION>
ysr@342 656
ysr@342 657 bool is_young() const { return _young_type != NotYoung; }
ysr@342 658 bool is_survivor() const { return _young_type == Survivor; }
ysr@342 659
ysr@342 660 int young_index_in_cset() const { return _young_index_in_cset; }
ysr@342 661 void set_young_index_in_cset(int index) {
ysr@342 662 assert( (index == -1) || is_young(), "pre-condition" );
ysr@342 663 _young_index_in_cset = index;
ysr@342 664 }
ysr@342 665
ysr@342 666 int age_in_surv_rate_group() {
ysr@342 667 assert( _surv_rate_group != NULL, "pre-condition" );
ysr@342 668 assert( _age_index > -1, "pre-condition" );
ysr@342 669 return _surv_rate_group->age_in_group(_age_index);
ysr@342 670 }
ysr@342 671
ysr@342 672 void record_surv_words_in_group(size_t words_survived) {
ysr@342 673 assert( _surv_rate_group != NULL, "pre-condition" );
ysr@342 674 assert( _age_index > -1, "pre-condition" );
ysr@342 675 int age_in_group = age_in_surv_rate_group();
ysr@342 676 _surv_rate_group->record_surviving_words(age_in_group, words_survived);
ysr@342 677 }
ysr@342 678
ysr@342 679 int age_in_surv_rate_group_cond() {
ysr@342 680 if (_surv_rate_group != NULL)
ysr@342 681 return age_in_surv_rate_group();
ysr@342 682 else
ysr@342 683 return -1;
ysr@342 684 }
ysr@342 685
ysr@342 686 SurvRateGroup* surv_rate_group() {
ysr@342 687 return _surv_rate_group;
ysr@342 688 }
ysr@342 689
ysr@342 690 void install_surv_rate_group(SurvRateGroup* surv_rate_group) {
ysr@342 691 assert( surv_rate_group != NULL, "pre-condition" );
ysr@342 692 assert( _surv_rate_group == NULL, "pre-condition" );
ysr@342 693 assert( is_young(), "pre-condition" );
ysr@342 694
ysr@342 695 _surv_rate_group = surv_rate_group;
ysr@342 696 _age_index = surv_rate_group->next_age_index();
ysr@342 697 }
ysr@342 698
ysr@342 699 void uninstall_surv_rate_group() {
ysr@342 700 if (_surv_rate_group != NULL) {
ysr@342 701 assert( _age_index > -1, "pre-condition" );
ysr@342 702 assert( is_young(), "pre-condition" );
ysr@342 703
ysr@342 704 _surv_rate_group = NULL;
ysr@342 705 _age_index = -1;
ysr@342 706 } else {
ysr@342 707 assert( _age_index == -1, "pre-condition" );
ysr@342 708 }
ysr@342 709 }
ysr@342 710
ysr@342 711 void set_young() { set_young_type(Young); }
ysr@342 712
ysr@342 713 void set_survivor() { set_young_type(Survivor); }
ysr@342 714
ysr@342 715 void set_not_young() { set_young_type(NotYoung); }
ysr@342 716
ysr@342 717 // Determine if an object has been allocated since the last
ysr@342 718 // mark performed by the collector. This returns true iff the object
ysr@342 719 // is within the unmarked area of the region.
ysr@342 720 bool obj_allocated_since_prev_marking(oop obj) const {
ysr@342 721 return (HeapWord *) obj >= prev_top_at_mark_start();
ysr@342 722 }
ysr@342 723 bool obj_allocated_since_next_marking(oop obj) const {
ysr@342 724 return (HeapWord *) obj >= next_top_at_mark_start();
ysr@342 725 }
ysr@342 726
ysr@342 727 // For parallel heapRegion traversal.
ysr@342 728 bool claimHeapRegion(int claimValue);
ysr@342 729 jint claim_value() { return _claimed; }
ysr@342 730 // Use this carefully: only when you're sure no one is claiming...
ysr@342 731 void set_claim_value(int claimValue) { _claimed = claimValue; }
ysr@342 732
ysr@342 733 // Returns the "evacuation_failed" property of the region.
ysr@342 734 bool evacuation_failed() { return _evacuation_failed; }
ysr@342 735
ysr@342 736 // Sets the "evacuation_failed" property of the region.
ysr@342 737 void set_evacuation_failed(bool b) {
ysr@342 738 _evacuation_failed = b;
ysr@342 739
ysr@342 740 if (b) {
ysr@342 741 init_top_at_conc_mark_count();
ysr@342 742 _next_marked_bytes = 0;
ysr@342 743 }
ysr@342 744 }
ysr@342 745
ysr@342 746 // Requires that "mr" be entirely within the region.
ysr@342 747 // Apply "cl->do_object" to all objects that intersect with "mr".
ysr@342 748 // If the iteration encounters an unparseable portion of the region,
ysr@342 749 // or if "cl->abort()" is true after a closure application,
ysr@342 750 // terminate the iteration and return the address of the start of the
ysr@342 751 // subregion that isn't done. (The two can be distinguished by querying
ysr@342 752 // "cl->abort()".) Return of "NULL" indicates that the iteration
ysr@342 753 // completed.
ysr@342 754 HeapWord*
ysr@342 755 object_iterate_mem_careful(MemRegion mr, ObjectClosure* cl);
ysr@342 756
tonyp@2414 757 // filter_young: if true and the region is a young region then we
tonyp@2414 758 // skip the iteration.
tonyp@2414 759 // card_ptr: if not NULL, and we decide that the card is not young
tonyp@2414 760 // and we iterate over it, we'll clean the card before we start the
tonyp@2414 761 // iteration.
ysr@342 762 HeapWord*
ysr@342 763 oops_on_card_seq_iterate_careful(MemRegion mr,
johnc@1586 764 FilterOutOfRegionClosure* cl,
tonyp@2414 765 bool filter_young,
tonyp@2414 766 jbyte* card_ptr);
ysr@342 767
ysr@342 768 // A version of block start that is guaranteed to find *some* block
ysr@342 769 // boundary at or before "p", but does not object iteration, and may
ysr@342 770 // therefore be used safely when the heap is unparseable.
ysr@342 771 HeapWord* block_start_careful(const void* p) const {
ysr@342 772 return _offsets.block_start_careful(p);
ysr@342 773 }
ysr@342 774
ysr@342 775 // Requires that "addr" is within the region. Returns the start of the
ysr@342 776 // first ("careful") block that starts at or after "addr", or else the
ysr@342 777 // "end" of the region if there is no such block.
ysr@342 778 HeapWord* next_block_start_careful(HeapWord* addr);
ysr@342 779
johnc@1394 780 size_t recorded_rs_length() const { return _recorded_rs_length; }
johnc@1394 781 double predicted_elapsed_time_ms() const { return _predicted_elapsed_time_ms; }
johnc@1394 782 size_t predicted_bytes_to_copy() const { return _predicted_bytes_to_copy; }
johnc@1394 783
johnc@1394 784 void set_recorded_rs_length(size_t rs_length) {
johnc@1394 785 _recorded_rs_length = rs_length;
johnc@1394 786 }
johnc@1394 787
johnc@1394 788 void set_predicted_elapsed_time_ms(double ms) {
johnc@1394 789 _predicted_elapsed_time_ms = ms;
johnc@1394 790 }
johnc@1394 791
johnc@1394 792 void set_predicted_bytes_to_copy(size_t bytes) {
johnc@1394 793 _predicted_bytes_to_copy = bytes;
johnc@1394 794 }
johnc@1394 795
ysr@342 796 #define HeapRegion_OOP_SINCE_SAVE_MARKS_DECL(OopClosureType, nv_suffix) \
ysr@342 797 virtual void oop_since_save_marks_iterate##nv_suffix(OopClosureType* cl);
ysr@342 798 SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES(HeapRegion_OOP_SINCE_SAVE_MARKS_DECL)
ysr@342 799
ysr@342 800 CompactibleSpace* next_compaction_space() const;
ysr@342 801
ysr@342 802 virtual void reset_after_compaction();
ysr@342 803
ysr@342 804 void print() const;
ysr@342 805 void print_on(outputStream* st) const;
ysr@342 806
johnc@2534 807 // vo == UsePrevMarking -> use "prev" marking information,
johnc@2534 808 // vo == UseNextMarking -> use "next" marking information
johnc@2534 809 // vo == UseMarkWord -> use the mark word in the object header
johnc@2534 810 //
tonyp@811 811 // NOTE: Only the "prev" marking information is guaranteed to be
tonyp@811 812 // consistent most of the time, so most calls to this should use
johnc@2534 813 // vo == UsePrevMarking.
johnc@2534 814 // Currently, there is only one case where this is called with
johnc@2534 815 // vo == UseNextMarking, which is to verify the "next" marking
johnc@2534 816 // information at the end of remark.
johnc@2534 817 // Currently there is only one place where this is called with
johnc@2534 818 // vo == UseMarkWord, which is to verify the marking during a
johnc@2534 819 // full GC.
johnc@2534 820 void verify(bool allow_dirty, VerifyOption vo, bool *failures) const;
tonyp@811 821
tonyp@811 822 // Override; it uses the "prev" marking information
ysr@342 823 virtual void verify(bool allow_dirty) const;
ysr@342 824 };
ysr@342 825
ysr@342 826 // HeapRegionClosure is used for iterating over regions.
ysr@342 827 // Terminates the iteration when the "doHeapRegion" method returns "true".
ysr@342 828 class HeapRegionClosure : public StackObj {
ysr@342 829 friend class HeapRegionSeq;
ysr@342 830 friend class G1CollectedHeap;
ysr@342 831
ysr@342 832 bool _complete;
ysr@342 833 void incomplete() { _complete = false; }
ysr@342 834
ysr@342 835 public:
ysr@342 836 HeapRegionClosure(): _complete(true) {}
ysr@342 837
ysr@342 838 // Typically called on each region until it returns true.
ysr@342 839 virtual bool doHeapRegion(HeapRegion* r) = 0;
ysr@342 840
ysr@342 841 // True after iteration if the closure was applied to all heap regions
ysr@342 842 // and returned "false" in all cases.
ysr@342 843 bool complete() { return _complete; }
ysr@342 844 };
ysr@342 845
ysr@342 846 #endif // SERIALGC
stefank@1879 847
stefank@1879 848 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGION_HPP