src/share/vm/gc_implementation/g1/heapRegion.hpp

Mon, 01 Feb 2016 13:19:14 -0800

author
poonam
date
Mon, 01 Feb 2016 13:19:14 -0800
changeset 8287
dae1435f96b7
parent 7990
1f646daf0d67
child 8604
04d83ba48607
child 9327
f96fcd9e1e1b
permissions
-rw-r--r--

8145442: Add the facility to verify remembered sets for G1
Summary: Implement remembered sets verification for G1 with option VerifyRememberedSets
Reviewed-by: jmasa, mgerdin

ysr@777 1 /*
drchase@6680 2 * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
ysr@777 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ysr@777 4 *
ysr@777 5 * This code is free software; you can redistribute it and/or modify it
ysr@777 6 * under the terms of the GNU General Public License version 2 only, as
ysr@777 7 * published by the Free Software Foundation.
ysr@777 8 *
ysr@777 9 * This code is distributed in the hope that it will be useful, but WITHOUT
ysr@777 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ysr@777 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ysr@777 12 * version 2 for more details (a copy is included in the LICENSE file that
ysr@777 13 * accompanied this code).
ysr@777 14 *
ysr@777 15 * You should have received a copy of the GNU General Public License version
ysr@777 16 * 2 along with this work; if not, write to the Free Software Foundation,
ysr@777 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ysr@777 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
ysr@777 22 *
ysr@777 23 */
ysr@777 24
stefank@2314 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGION_HPP
stefank@2314 26 #define SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGION_HPP
stefank@2314 27
sjohanss@7118 28 #include "gc_implementation/g1/g1AllocationContext.hpp"
mgerdin@6987 29 #include "gc_implementation/g1/g1BlockOffsetTable.hpp"
stefank@2314 30 #include "gc_implementation/g1/g1_specialized_oop_closures.hpp"
brutisso@7195 31 #include "gc_implementation/g1/heapRegionType.hpp"
stefank@2314 32 #include "gc_implementation/g1/survRateGroup.hpp"
stefank@2314 33 #include "gc_implementation/shared/ageTable.hpp"
stefank@2314 34 #include "gc_implementation/shared/spaceDecorator.hpp"
stefank@2314 35 #include "memory/space.inline.hpp"
stefank@2314 36 #include "memory/watermark.hpp"
jprovino@4542 37 #include "utilities/macros.hpp"
stefank@2314 38
ysr@777 39 // A HeapRegion is the smallest piece of a G1CollectedHeap that
ysr@777 40 // can be collected independently.
ysr@777 41
ysr@777 42 // NOTE: Although a HeapRegion is a Space, its
ysr@777 43 // Space::initDirtyCardClosure method must not be called.
ysr@777 44 // The problem is that the existence of this method breaks
ysr@777 45 // the independence of barrier sets from remembered sets.
ysr@777 46 // The solution is to remove this method from the definition
ysr@777 47 // of a Space.
ysr@777 48
ysr@777 49 class HeapRegionRemSet;
ysr@777 50 class HeapRegionRemSetIterator;
ysr@777 51 class HeapRegion;
tonyp@2472 52 class HeapRegionSetBase;
johnc@5548 53 class nmethod;
tonyp@2472 54
tonyp@3713 55 #define HR_FORMAT "%u:(%s)["PTR_FORMAT","PTR_FORMAT","PTR_FORMAT"]"
tonyp@2963 56 #define HR_FORMAT_PARAMS(_hr_) \
tschatzl@7091 57 (_hr_)->hrm_index(), \
brutisso@7195 58 (_hr_)->get_short_type_str(), \
drchase@6680 59 p2i((_hr_)->bottom()), p2i((_hr_)->top()), p2i((_hr_)->end())
ysr@777 60
tschatzl@7091 61 // sentinel value for hrm_index
tschatzl@7091 62 #define G1_NO_HRM_INDEX ((uint) -1)
tonyp@3713 63
ysr@777 64 // A dirty card to oop closure for heap regions. It
ysr@777 65 // knows how to get the G1 heap and how to use the bitmap
ysr@777 66 // in the concurrent marker used by G1 to filter remembered
ysr@777 67 // sets.
ysr@777 68
mgerdin@6986 69 class HeapRegionDCTOC : public DirtyCardToOopClosure {
mgerdin@7971 70 private:
ysr@777 71 HeapRegion* _hr;
mgerdin@7971 72 G1ParPushHeapRSClosure* _rs_scan;
ysr@777 73 G1CollectedHeap* _g1;
ysr@777 74
ysr@777 75 // Walk the given memory region from bottom to (actual) top
ysr@777 76 // looking for objects and applying the oop closure (_cl) to
ysr@777 77 // them. The base implementation of this treats the area as
ysr@777 78 // blocks, where a block may or may not be an object. Sub-
ysr@777 79 // classes should override this to provide more accurate
ysr@777 80 // or possibly more efficient walking.
mgerdin@6986 81 void walk_mem_region(MemRegion mr, HeapWord* bottom, HeapWord* top);
ysr@777 82
ysr@777 83 public:
ysr@777 84 HeapRegionDCTOC(G1CollectedHeap* g1,
mgerdin@7971 85 HeapRegion* hr,
mgerdin@7971 86 G1ParPushHeapRSClosure* cl,
mgerdin@7971 87 CardTableModRefBS::PrecisionStyle precision);
ysr@777 88 };
ysr@777 89
ysr@777 90 // The complicating factor is that BlockOffsetTable diverged
ysr@777 91 // significantly, and we need functionality that is only in the G1 version.
ysr@777 92 // So I copied that code, which led to an alternate G1 version of
ysr@777 93 // OffsetTableContigSpace. If the two versions of BlockOffsetTable could
ysr@777 94 // be reconciled, then G1OffsetTableContigSpace could go away.
ysr@777 95
mgerdin@7647 96 // The idea behind time stamps is the following. We want to keep track of
mgerdin@7647 97 // the highest address where it's safe to scan objects for each region.
mgerdin@7647 98 // This is only relevant for current GC alloc regions so we keep a time stamp
mgerdin@7647 99 // per region to determine if the region has been allocated during the current
mgerdin@7647 100 // GC or not. If the time stamp is current we report a scan_top value which
mgerdin@7647 101 // was saved at the end of the previous GC for retained alloc regions and which is
mgerdin@7647 102 // equal to the bottom for all other regions.
mgerdin@7647 103 // There is a race between card scanners and allocating gc workers where we must ensure
mgerdin@7647 104 // that card scanners do not read the memory allocated by the gc workers.
mgerdin@7647 105 // In order to enforce that, we must not return a value of _top which is more recent than the
mgerdin@7647 106 // time stamp. This is due to the fact that a region may become a gc alloc region at
mgerdin@7647 107 // some point after we've read the timestamp value as being < the current time stamp.
mgerdin@7647 108 // The time stamps are re-initialized to zero at cleanup and at Full GCs.
mgerdin@7647 109 // The current scheme that uses sequential unsigned ints will fail only if we have 4b
ysr@777 110 // evacuation pauses between two cleanups, which is _highly_ unlikely.
mgerdin@6990 111 class G1OffsetTableContigSpace: public CompactibleSpace {
ysr@777 112 friend class VMStructs;
mgerdin@6990 113 HeapWord* _top;
mgerdin@7647 114 HeapWord* volatile _scan_top;
ysr@777 115 protected:
ysr@777 116 G1BlockOffsetArrayContigSpace _offsets;
ysr@777 117 Mutex _par_alloc_lock;
ysr@777 118 volatile unsigned _gc_time_stamp;
tonyp@2715 119 // When we need to retire an allocation region, while other threads
tonyp@2715 120 // are also concurrently trying to allocate into it, we typically
tonyp@2715 121 // allocate a dummy object at the end of the region to ensure that
tonyp@2715 122 // no more allocations can take place in it. However, sometimes we
tonyp@2715 123 // want to know where the end of the last "real" object we allocated
tonyp@2715 124 // into the region was and this is what this keeps track.
tonyp@2715 125 HeapWord* _pre_dummy_top;
ysr@777 126
ysr@777 127 public:
ysr@777 128 G1OffsetTableContigSpace(G1BlockOffsetSharedArray* sharedOffsetArray,
johnc@4065 129 MemRegion mr);
ysr@777 130
mgerdin@6990 131 void set_top(HeapWord* value) { _top = value; }
mgerdin@6990 132 HeapWord* top() const { return _top; }
mgerdin@6990 133
mgerdin@6990 134 protected:
tschatzl@7050 135 // Reset the G1OffsetTableContigSpace.
tschatzl@7050 136 virtual void initialize(MemRegion mr, bool clear_space, bool mangle_space);
tschatzl@7050 137
mgerdin@6990 138 HeapWord** top_addr() { return &_top; }
mgerdin@6990 139 // Allocation helpers (return NULL if full).
mgerdin@6990 140 inline HeapWord* allocate_impl(size_t word_size, HeapWord* end_value);
mgerdin@6990 141 inline HeapWord* par_allocate_impl(size_t word_size, HeapWord* end_value);
mgerdin@6990 142
mgerdin@6990 143 public:
mgerdin@6990 144 void reset_after_compaction() { set_top(compaction_top()); }
mgerdin@6990 145
mgerdin@6990 146 size_t used() const { return byte_size(bottom(), top()); }
mgerdin@6990 147 size_t free() const { return byte_size(top(), end()); }
mgerdin@6990 148 bool is_free_block(const HeapWord* p) const { return p >= top(); }
mgerdin@6990 149
mgerdin@6990 150 MemRegion used_region() const { return MemRegion(bottom(), top()); }
mgerdin@6990 151
mgerdin@6990 152 void object_iterate(ObjectClosure* blk);
mgerdin@6990 153 void safe_object_iterate(ObjectClosure* blk);
mgerdin@6990 154
ysr@777 155 void set_bottom(HeapWord* value);
ysr@777 156 void set_end(HeapWord* value);
ysr@777 157
mgerdin@7647 158 HeapWord* scan_top() const;
mgerdin@7647 159 void record_timestamp();
ysr@777 160 void reset_gc_time_stamp() { _gc_time_stamp = 0; }
tonyp@3957 161 unsigned get_gc_time_stamp() { return _gc_time_stamp; }
mgerdin@7647 162 void record_retained_region();
ysr@777 163
tonyp@2715 164 // See the comment above in the declaration of _pre_dummy_top for an
tonyp@2715 165 // explanation of what it is.
tonyp@2715 166 void set_pre_dummy_top(HeapWord* pre_dummy_top) {
tonyp@2715 167 assert(is_in(pre_dummy_top) && pre_dummy_top <= top(), "pre-condition");
tonyp@2715 168 _pre_dummy_top = pre_dummy_top;
tonyp@2715 169 }
tonyp@2715 170 HeapWord* pre_dummy_top() {
tonyp@2715 171 return (_pre_dummy_top == NULL) ? top() : _pre_dummy_top;
tonyp@2715 172 }
tonyp@2715 173 void reset_pre_dummy_top() { _pre_dummy_top = NULL; }
tonyp@2715 174
tonyp@791 175 virtual void clear(bool mangle_space);
ysr@777 176
ysr@777 177 HeapWord* block_start(const void* p);
ysr@777 178 HeapWord* block_start_const(const void* p) const;
ysr@777 179
mgerdin@6990 180 void prepare_for_compaction(CompactPoint* cp);
mgerdin@6990 181
ysr@777 182 // Add offset table update.
ysr@777 183 virtual HeapWord* allocate(size_t word_size);
ysr@777 184 HeapWord* par_allocate(size_t word_size);
ysr@777 185
mgerdin@7647 186 HeapWord* saved_mark_word() const { ShouldNotReachHere(); return NULL; }
mgerdin@7647 187
ysr@777 188 // MarkSweep support phase3
ysr@777 189 virtual HeapWord* initialize_threshold();
ysr@777 190 virtual HeapWord* cross_threshold(HeapWord* start, HeapWord* end);
ysr@777 191
ysr@777 192 virtual void print() const;
tonyp@2453 193
tonyp@2453 194 void reset_bot() {
tschatzl@7050 195 _offsets.reset_bot();
tonyp@2453 196 }
tonyp@2453 197
tonyp@2453 198 void print_bot_on(outputStream* out) {
tonyp@2453 199 _offsets.print_on(out);
tonyp@2453 200 }
ysr@777 201 };
ysr@777 202
ysr@777 203 class HeapRegion: public G1OffsetTableContigSpace {
ysr@777 204 friend class VMStructs;
ysr@777 205 private:
ysr@777 206
ysr@777 207 // The remembered set for this region.
ysr@777 208 // (Might want to make this "inline" later, to avoid some alloc failure
ysr@777 209 // issues.)
ysr@777 210 HeapRegionRemSet* _rem_set;
ysr@777 211
ysr@777 212 G1BlockOffsetArrayContigSpace* offsets() { return &_offsets; }
ysr@777 213
ysr@777 214 protected:
tonyp@2963 215 // The index of this region in the heap region sequence.
tschatzl@7091 216 uint _hrm_index;
ysr@777 217
sjohanss@7118 218 AllocationContext_t _allocation_context;
sjohanss@7118 219
brutisso@7195 220 HeapRegionType _type;
brutisso@7195 221
ysr@777 222 // For a humongous region, region in which it starts.
ysr@777 223 HeapRegion* _humongous_start_region;
ysr@777 224 // For the start region of a humongous sequence, it's original end().
ysr@777 225 HeapWord* _orig_end;
ysr@777 226
ysr@777 227 // True iff the region is in current collection_set.
ysr@777 228 bool _in_collection_set;
ysr@777 229
ysr@777 230 // True iff an attempt to evacuate an object in the region failed.
ysr@777 231 bool _evacuation_failed;
ysr@777 232
ysr@777 233 // A heap region may be a member one of a number of special subsets, each
stefank@6992 234 // represented as linked lists through the field below. Currently, there
stefank@6992 235 // is only one set:
ysr@777 236 // The collection set.
ysr@777 237 HeapRegion* _next_in_special_set;
ysr@777 238
ysr@777 239 // next region in the young "generation" region set
ysr@777 240 HeapRegion* _next_young_region;
ysr@777 241
apetrusenko@1231 242 // Next region whose cards need cleaning
apetrusenko@1231 243 HeapRegion* _next_dirty_cards_region;
apetrusenko@1231 244
tonyp@2472 245 // Fields used by the HeapRegionSetBase class and subclasses.
tonyp@2472 246 HeapRegion* _next;
jwilhelm@6422 247 HeapRegion* _prev;
tonyp@2472 248 #ifdef ASSERT
tonyp@2472 249 HeapRegionSetBase* _containing_set;
tonyp@2472 250 #endif // ASSERT
tonyp@2472 251
ysr@777 252 // For parallel heapRegion traversal.
ysr@777 253 jint _claimed;
ysr@777 254
ysr@777 255 // We use concurrent marking to determine the amount of live data
ysr@777 256 // in each heap region.
ysr@777 257 size_t _prev_marked_bytes; // Bytes known to be live via last completed marking.
ysr@777 258 size_t _next_marked_bytes; // Bytes known to be live via in-progress marking.
ysr@777 259
tonyp@3714 260 // The calculated GC efficiency of the region.
ysr@777 261 double _gc_efficiency;
ysr@777 262
ysr@777 263 int _young_index_in_cset;
ysr@777 264 SurvRateGroup* _surv_rate_group;
ysr@777 265 int _age_index;
ysr@777 266
ysr@777 267 // The start of the unmarked area. The unmarked area extends from this
ysr@777 268 // word until the top and/or end of the region, and is the part
ysr@777 269 // of the region for which no marking was done, i.e. objects may
ysr@777 270 // have been allocated in this part since the last mark phase.
ysr@777 271 // "prev" is the top at the start of the last completed marking.
ysr@777 272 // "next" is the top at the start of the in-progress marking (if any.)
ysr@777 273 HeapWord* _prev_top_at_mark_start;
ysr@777 274 HeapWord* _next_top_at_mark_start;
ysr@777 275 // If a collection pause is in progress, this is the top at the start
ysr@777 276 // of that pause.
ysr@777 277
ysr@777 278 void init_top_at_mark_start() {
ysr@777 279 assert(_prev_marked_bytes == 0 &&
ysr@777 280 _next_marked_bytes == 0,
ysr@777 281 "Must be called after zero_marked_bytes.");
ysr@777 282 HeapWord* bot = bottom();
ysr@777 283 _prev_top_at_mark_start = bot;
ysr@777 284 _next_top_at_mark_start = bot;
ysr@777 285 }
ysr@777 286
johnc@1829 287 // Cached attributes used in the collection set policy information
johnc@1829 288
johnc@1829 289 // The RSet length that was added to the total value
johnc@1829 290 // for the collection set.
johnc@1829 291 size_t _recorded_rs_length;
johnc@1829 292
johnc@1829 293 // The predicted elapsed time that was added to total value
johnc@1829 294 // for the collection set.
johnc@1829 295 double _predicted_elapsed_time_ms;
johnc@1829 296
johnc@1829 297 // The predicted number of bytes to copy that was added to
johnc@1829 298 // the total value for the collection set.
johnc@1829 299 size_t _predicted_bytes_to_copy;
johnc@1829 300
ysr@777 301 public:
tschatzl@7091 302 HeapRegion(uint hrm_index,
tonyp@2963 303 G1BlockOffsetSharedArray* sharedOffsetArray,
sjohanss@7131 304 MemRegion mr);
ysr@777 305
tschatzl@7050 306 // Initializing the HeapRegion not only resets the data structure, but also
tschatzl@7050 307 // resets the BOT for that heap region.
tschatzl@7050 308 // The default values for clear_space means that we will do the clearing if
tschatzl@7050 309 // there's clearing to be done ourselves. We also always mangle the space.
tschatzl@7050 310 virtual void initialize(MemRegion mr, bool clear_space = false, bool mangle_space = SpaceDecorator::Mangle);
tschatzl@7050 311
johnc@3182 312 static int LogOfHRGrainBytes;
johnc@3182 313 static int LogOfHRGrainWords;
johnc@3182 314
johnc@3182 315 static size_t GrainBytes;
johnc@3182 316 static size_t GrainWords;
johnc@3182 317 static size_t CardsPerRegion;
tonyp@1377 318
tonyp@3176 319 static size_t align_up_to_region_byte_size(size_t sz) {
tonyp@3176 320 return (sz + (size_t) GrainBytes - 1) &
tonyp@3176 321 ~((1 << (size_t) LogOfHRGrainBytes) - 1);
tonyp@3176 322 }
tonyp@3176 323
tschatzl@5701 324 static size_t max_region_size();
tschatzl@5701 325
tonyp@1377 326 // It sets up the heap region size (GrainBytes / GrainWords), as
tonyp@1377 327 // well as other related fields that are based on the heap region
tonyp@1377 328 // size (LogOfHRGrainBytes / LogOfHRGrainWords /
tonyp@1377 329 // CardsPerRegion). All those fields are considered constant
tonyp@1377 330 // throughout the JVM's execution, therefore they should only be set
tonyp@1377 331 // up once during initialization time.
brutisso@5646 332 static void setup_heap_region_size(size_t initial_heap_size, size_t max_heap_size);
ysr@777 333
tonyp@790 334 enum ClaimValues {
johnc@3296 335 InitialClaimValue = 0,
johnc@3296 336 FinalCountClaimValue = 1,
johnc@3296 337 NoteEndClaimValue = 2,
johnc@3296 338 ScrubRemSetClaimValue = 3,
johnc@3296 339 ParVerifyClaimValue = 4,
johnc@3296 340 RebuildRSClaimValue = 5,
tonyp@3691 341 ParEvacFailureClaimValue = 6,
tonyp@3691 342 AggregateCountClaimValue = 7,
johnc@5548 343 VerifyCountClaimValue = 8,
johnc@5548 344 ParMarkRootClaimValue = 9
tonyp@790 345 };
tonyp@790 346
mgerdin@6990 347 // All allocated blocks are occupied by objects in a HeapRegion
mgerdin@6990 348 bool block_is_obj(const HeapWord* p) const;
mgerdin@6990 349
mgerdin@6990 350 // Returns the object size for all valid block starts
mgerdin@6990 351 // and the amount of unallocated words if called on top()
mgerdin@6990 352 size_t block_size(const HeapWord* p) const;
mgerdin@6990 353
mgerdin@6990 354 inline HeapWord* par_allocate_no_bot_updates(size_t word_size);
mgerdin@6990 355 inline HeapWord* allocate_no_bot_updates(size_t word_size);
tonyp@2454 356
tschatzl@7091 357 // If this region is a member of a HeapRegionManager, the index in that
ysr@777 358 // sequence, otherwise -1.
tschatzl@7091 359 uint hrm_index() const { return _hrm_index; }
ysr@777 360
ysr@777 361 // The number of bytes marked live in the region in the last marking phase.
ysr@777 362 size_t marked_bytes() { return _prev_marked_bytes; }
tonyp@2717 363 size_t live_bytes() {
tonyp@2717 364 return (top() - prev_top_at_mark_start()) * HeapWordSize + marked_bytes();
tonyp@2717 365 }
tonyp@2717 366
ysr@777 367 // The number of bytes counted in the next marking.
ysr@777 368 size_t next_marked_bytes() { return _next_marked_bytes; }
ysr@777 369 // The number of bytes live wrt the next marking.
ysr@777 370 size_t next_live_bytes() {
tonyp@2717 371 return
tonyp@2717 372 (top() - next_top_at_mark_start()) * HeapWordSize + next_marked_bytes();
ysr@777 373 }
ysr@777 374
ysr@777 375 // A lower bound on the amount of garbage bytes in the region.
ysr@777 376 size_t garbage_bytes() {
ysr@777 377 size_t used_at_mark_start_bytes =
ysr@777 378 (prev_top_at_mark_start() - bottom()) * HeapWordSize;
ysr@777 379 assert(used_at_mark_start_bytes >= marked_bytes(),
ysr@777 380 "Can't mark more than we have.");
ysr@777 381 return used_at_mark_start_bytes - marked_bytes();
ysr@777 382 }
ysr@777 383
tonyp@3539 384 // Return the amount of bytes we'll reclaim if we collect this
tonyp@3539 385 // region. This includes not only the known garbage bytes in the
tonyp@3539 386 // region but also any unallocated space in it, i.e., [top, end),
tonyp@3539 387 // since it will also be reclaimed if we collect the region.
tonyp@3539 388 size_t reclaimable_bytes() {
tonyp@3539 389 size_t known_live_bytes = live_bytes();
tonyp@3539 390 assert(known_live_bytes <= capacity(), "sanity");
tonyp@3539 391 return capacity() - known_live_bytes;
tonyp@3539 392 }
tonyp@3539 393
ysr@777 394 // An upper bound on the number of live bytes in the region.
ysr@777 395 size_t max_live_bytes() { return used() - garbage_bytes(); }
ysr@777 396
ysr@777 397 void add_to_marked_bytes(size_t incr_bytes) {
ysr@777 398 _next_marked_bytes = _next_marked_bytes + incr_bytes;
johnc@3292 399 assert(_next_marked_bytes <= used(), "invariant" );
ysr@777 400 }
ysr@777 401
ysr@777 402 void zero_marked_bytes() {
ysr@777 403 _prev_marked_bytes = _next_marked_bytes = 0;
ysr@777 404 }
ysr@777 405
brutisso@7195 406 const char* get_type_str() const { return _type.get_str(); }
brutisso@7195 407 const char* get_short_type_str() const { return _type.get_short_str(); }
brutisso@7195 408
brutisso@7195 409 bool is_free() const { return _type.is_free(); }
brutisso@7195 410
brutisso@7195 411 bool is_young() const { return _type.is_young(); }
brutisso@7195 412 bool is_eden() const { return _type.is_eden(); }
brutisso@7195 413 bool is_survivor() const { return _type.is_survivor(); }
brutisso@7195 414
brutisso@7195 415 bool isHumongous() const { return _type.is_humongous(); }
brutisso@7195 416 bool startsHumongous() const { return _type.is_starts_humongous(); }
brutisso@7195 417 bool continuesHumongous() const { return _type.is_continues_humongous(); }
brutisso@7195 418
brutisso@7195 419 bool is_old() const { return _type.is_old(); }
brutisso@7195 420
ysr@777 421 // For a humongous region, region in which it starts.
ysr@777 422 HeapRegion* humongous_start_region() const {
ysr@777 423 return _humongous_start_region;
ysr@777 424 }
ysr@777 425
tonyp@3957 426 // Return the number of distinct regions that are covered by this region:
tonyp@3957 427 // 1 if the region is not humongous, >= 1 if the region is humongous.
tonyp@3957 428 uint region_num() const {
tonyp@3957 429 if (!isHumongous()) {
tonyp@3957 430 return 1U;
tonyp@3957 431 } else {
tonyp@3957 432 assert(startsHumongous(), "doesn't make sense on HC regions");
tonyp@3957 433 assert(capacity() % HeapRegion::GrainBytes == 0, "sanity");
tonyp@3957 434 return (uint) (capacity() >> HeapRegion::LogOfHRGrainBytes);
tonyp@3957 435 }
tonyp@3957 436 }
tonyp@3957 437
tonyp@3957 438 // Return the index + 1 of the last HC regions that's associated
tonyp@3957 439 // with this HS region.
tonyp@3957 440 uint last_hc_index() const {
tonyp@3957 441 assert(startsHumongous(), "don't call this otherwise");
tschatzl@7091 442 return hrm_index() + region_num();
tonyp@3957 443 }
tonyp@3957 444
brutisso@3216 445 // Same as Space::is_in_reserved, but will use the original size of the region.
brutisso@3216 446 // The original size is different only for start humongous regions. They get
brutisso@3216 447 // their _end set up to be the end of the last continues region of the
brutisso@3216 448 // corresponding humongous object.
brutisso@3216 449 bool is_in_reserved_raw(const void* p) const {
brutisso@3216 450 return _bottom <= p && p < _orig_end;
brutisso@3216 451 }
brutisso@3216 452
tonyp@2453 453 // Makes the current region be a "starts humongous" region, i.e.,
tonyp@2453 454 // the first region in a series of one or more contiguous regions
tonyp@2453 455 // that will contain a single "humongous" object. The two parameters
tonyp@2453 456 // are as follows:
tonyp@2453 457 //
tonyp@2453 458 // new_top : The new value of the top field of this region which
tonyp@2453 459 // points to the end of the humongous object that's being
tonyp@2453 460 // allocated. If there is more than one region in the series, top
tonyp@2453 461 // will lie beyond this region's original end field and on the last
tonyp@2453 462 // region in the series.
tonyp@2453 463 //
tonyp@2453 464 // new_end : The new value of the end field of this region which
tonyp@2453 465 // points to the end of the last region in the series. If there is
tonyp@2453 466 // one region in the series (namely: this one) end will be the same
tonyp@2453 467 // as the original end of this region.
tonyp@2453 468 //
tonyp@2453 469 // Updating top and end as described above makes this region look as
tonyp@2453 470 // if it spans the entire space taken up by all the regions in the
tonyp@2453 471 // series and an single allocation moved its top to new_top. This
tonyp@2453 472 // ensures that the space (capacity / allocated) taken up by all
tonyp@2453 473 // humongous regions can be calculated by just looking at the
tonyp@2453 474 // "starts humongous" regions and by ignoring the "continues
tonyp@2453 475 // humongous" regions.
tonyp@2453 476 void set_startsHumongous(HeapWord* new_top, HeapWord* new_end);
ysr@777 477
tonyp@2453 478 // Makes the current region be a "continues humongous'
tonyp@2453 479 // region. first_hr is the "start humongous" region of the series
tonyp@2453 480 // which this region will be part of.
tonyp@2453 481 void set_continuesHumongous(HeapRegion* first_hr);
ysr@777 482
tonyp@2472 483 // Unsets the humongous-related fields on the region.
brutisso@7195 484 void clear_humongous();
tonyp@2472 485
ysr@777 486 // If the region has a remembered set, return a pointer to it.
ysr@777 487 HeapRegionRemSet* rem_set() const {
ysr@777 488 return _rem_set;
ysr@777 489 }
ysr@777 490
ysr@777 491 // True iff the region is in current collection_set.
ysr@777 492 bool in_collection_set() const {
ysr@777 493 return _in_collection_set;
ysr@777 494 }
ysr@777 495 void set_in_collection_set(bool b) {
ysr@777 496 _in_collection_set = b;
ysr@777 497 }
ysr@777 498 HeapRegion* next_in_collection_set() {
ysr@777 499 assert(in_collection_set(), "should only invoke on member of CS.");
ysr@777 500 assert(_next_in_special_set == NULL ||
ysr@777 501 _next_in_special_set->in_collection_set(),
ysr@777 502 "Malformed CS.");
ysr@777 503 return _next_in_special_set;
ysr@777 504 }
ysr@777 505 void set_next_in_collection_set(HeapRegion* r) {
ysr@777 506 assert(in_collection_set(), "should only invoke on member of CS.");
ysr@777 507 assert(r == NULL || r->in_collection_set(), "Malformed CS.");
ysr@777 508 _next_in_special_set = r;
ysr@777 509 }
ysr@777 510
sjohanss@7118 511 void set_allocation_context(AllocationContext_t context) {
sjohanss@7118 512 _allocation_context = context;
sjohanss@7118 513 }
sjohanss@7118 514
sjohanss@7118 515 AllocationContext_t allocation_context() const {
sjohanss@7118 516 return _allocation_context;
sjohanss@7118 517 }
sjohanss@7118 518
tonyp@2472 519 // Methods used by the HeapRegionSetBase class and subclasses.
tonyp@2472 520
jwilhelm@6422 521 // Getter and setter for the next and prev fields used to link regions into
tonyp@2472 522 // linked lists.
tonyp@2472 523 HeapRegion* next() { return _next; }
jwilhelm@6422 524 HeapRegion* prev() { return _prev; }
tonyp@2472 525
tonyp@2472 526 void set_next(HeapRegion* next) { _next = next; }
jwilhelm@6422 527 void set_prev(HeapRegion* prev) { _prev = prev; }
tonyp@2472 528
tonyp@2472 529 // Every region added to a set is tagged with a reference to that
tonyp@2472 530 // set. This is used for doing consistency checking to make sure that
tonyp@2472 531 // the contents of a set are as they should be and it's only
tonyp@2472 532 // available in non-product builds.
tonyp@2472 533 #ifdef ASSERT
tonyp@2472 534 void set_containing_set(HeapRegionSetBase* containing_set) {
tonyp@2472 535 assert((containing_set == NULL && _containing_set != NULL) ||
tonyp@2472 536 (containing_set != NULL && _containing_set == NULL),
tonyp@2472 537 err_msg("containing_set: "PTR_FORMAT" "
tonyp@2472 538 "_containing_set: "PTR_FORMAT,
drchase@6680 539 p2i(containing_set), p2i(_containing_set)));
tonyp@2472 540
tonyp@2472 541 _containing_set = containing_set;
tonyp@2643 542 }
tonyp@2472 543
tonyp@2472 544 HeapRegionSetBase* containing_set() { return _containing_set; }
tonyp@2472 545 #else // ASSERT
tonyp@2472 546 void set_containing_set(HeapRegionSetBase* containing_set) { }
tonyp@2472 547
tonyp@2643 548 // containing_set() is only used in asserts so there's no reason
tonyp@2472 549 // to provide a dummy version of it.
tonyp@2472 550 #endif // ASSERT
tonyp@2472 551
ysr@777 552 HeapRegion* get_next_young_region() { return _next_young_region; }
ysr@777 553 void set_next_young_region(HeapRegion* hr) {
ysr@777 554 _next_young_region = hr;
ysr@777 555 }
ysr@777 556
apetrusenko@1231 557 HeapRegion* get_next_dirty_cards_region() const { return _next_dirty_cards_region; }
apetrusenko@1231 558 HeapRegion** next_dirty_cards_region_addr() { return &_next_dirty_cards_region; }
apetrusenko@1231 559 void set_next_dirty_cards_region(HeapRegion* hr) { _next_dirty_cards_region = hr; }
apetrusenko@1231 560 bool is_on_dirty_cards_region_list() const { return get_next_dirty_cards_region() != NULL; }
apetrusenko@1231 561
tschatzl@7100 562 HeapWord* orig_end() const { return _orig_end; }
tonyp@2963 563
ysr@777 564 // Reset HR stuff to default values.
tschatzl@6404 565 void hr_clear(bool par, bool clear_space, bool locked = false);
tonyp@2849 566 void par_clear();
ysr@777 567
ysr@777 568 // Get the start of the unmarked area in this region.
ysr@777 569 HeapWord* prev_top_at_mark_start() const { return _prev_top_at_mark_start; }
ysr@777 570 HeapWord* next_top_at_mark_start() const { return _next_top_at_mark_start; }
ysr@777 571
ysr@777 572 // Note the start or end of marking. This tells the heap region
ysr@777 573 // that the collector is about to start or has finished (concurrently)
ysr@777 574 // marking the heap.
ysr@777 575
tonyp@3416 576 // Notify the region that concurrent marking is starting. Initialize
tonyp@3416 577 // all fields related to the next marking info.
tonyp@3416 578 inline void note_start_of_marking();
ysr@777 579
tonyp@3416 580 // Notify the region that concurrent marking has finished. Copy the
tonyp@3416 581 // (now finalized) next marking info fields into the prev marking
tonyp@3416 582 // info fields.
tonyp@3416 583 inline void note_end_of_marking();
ysr@777 584
tonyp@3416 585 // Notify the region that it will be used as to-space during a GC
tonyp@3416 586 // and we are about to start copying objects into it.
tonyp@3416 587 inline void note_start_of_copying(bool during_initial_mark);
ysr@777 588
tonyp@3416 589 // Notify the region that it ceases being to-space during a GC and
tonyp@3416 590 // we will not copy objects into it any more.
tonyp@3416 591 inline void note_end_of_copying(bool during_initial_mark);
tonyp@3416 592
tonyp@3416 593 // Notify the region that we are about to start processing
tonyp@3416 594 // self-forwarded objects during evac failure handling.
tonyp@3416 595 void note_self_forwarding_removal_start(bool during_initial_mark,
tonyp@3416 596 bool during_conc_mark);
tonyp@3416 597
tonyp@3416 598 // Notify the region that we have finished processing self-forwarded
tonyp@3416 599 // objects during evac failure handling.
tonyp@3416 600 void note_self_forwarding_removal_end(bool during_initial_mark,
tonyp@3416 601 bool during_conc_mark,
tonyp@3416 602 size_t marked_bytes);
ysr@777 603
ysr@777 604 // Returns "false" iff no object in the region was allocated when the
ysr@777 605 // last mark phase ended.
ysr@777 606 bool is_marked() { return _prev_top_at_mark_start != bottom(); }
ysr@777 607
ysr@777 608 void reset_during_compaction() {
tonyp@3957 609 assert(isHumongous() && startsHumongous(),
tonyp@3957 610 "should only be called for starts humongous regions");
ysr@777 611
ysr@777 612 zero_marked_bytes();
ysr@777 613 init_top_at_mark_start();
ysr@777 614 }
ysr@777 615
ysr@777 616 void calc_gc_efficiency(void);
ysr@777 617 double gc_efficiency() { return _gc_efficiency;}
ysr@777 618
ysr@777 619 int young_index_in_cset() const { return _young_index_in_cset; }
ysr@777 620 void set_young_index_in_cset(int index) {
ysr@777 621 assert( (index == -1) || is_young(), "pre-condition" );
ysr@777 622 _young_index_in_cset = index;
ysr@777 623 }
ysr@777 624
ysr@777 625 int age_in_surv_rate_group() {
ysr@777 626 assert( _surv_rate_group != NULL, "pre-condition" );
ysr@777 627 assert( _age_index > -1, "pre-condition" );
ysr@777 628 return _surv_rate_group->age_in_group(_age_index);
ysr@777 629 }
ysr@777 630
ysr@777 631 void record_surv_words_in_group(size_t words_survived) {
ysr@777 632 assert( _surv_rate_group != NULL, "pre-condition" );
ysr@777 633 assert( _age_index > -1, "pre-condition" );
ysr@777 634 int age_in_group = age_in_surv_rate_group();
ysr@777 635 _surv_rate_group->record_surviving_words(age_in_group, words_survived);
ysr@777 636 }
ysr@777 637
ysr@777 638 int age_in_surv_rate_group_cond() {
ysr@777 639 if (_surv_rate_group != NULL)
ysr@777 640 return age_in_surv_rate_group();
ysr@777 641 else
ysr@777 642 return -1;
ysr@777 643 }
ysr@777 644
ysr@777 645 SurvRateGroup* surv_rate_group() {
ysr@777 646 return _surv_rate_group;
ysr@777 647 }
ysr@777 648
ysr@777 649 void install_surv_rate_group(SurvRateGroup* surv_rate_group) {
ysr@777 650 assert( surv_rate_group != NULL, "pre-condition" );
ysr@777 651 assert( _surv_rate_group == NULL, "pre-condition" );
ysr@777 652 assert( is_young(), "pre-condition" );
ysr@777 653
ysr@777 654 _surv_rate_group = surv_rate_group;
ysr@777 655 _age_index = surv_rate_group->next_age_index();
ysr@777 656 }
ysr@777 657
ysr@777 658 void uninstall_surv_rate_group() {
ysr@777 659 if (_surv_rate_group != NULL) {
ysr@777 660 assert( _age_index > -1, "pre-condition" );
ysr@777 661 assert( is_young(), "pre-condition" );
ysr@777 662
ysr@777 663 _surv_rate_group = NULL;
ysr@777 664 _age_index = -1;
ysr@777 665 } else {
ysr@777 666 assert( _age_index == -1, "pre-condition" );
ysr@777 667 }
ysr@777 668 }
ysr@777 669
brutisso@7195 670 void set_free() { _type.set_free(); }
ysr@777 671
brutisso@7195 672 void set_eden() { _type.set_eden(); }
brutisso@7195 673 void set_eden_pre_gc() { _type.set_eden_pre_gc(); }
brutisso@7195 674 void set_survivor() { _type.set_survivor(); }
ysr@777 675
brutisso@7195 676 void set_old() { _type.set_old(); }
ysr@777 677
ysr@777 678 // Determine if an object has been allocated since the last
ysr@777 679 // mark performed by the collector. This returns true iff the object
ysr@777 680 // is within the unmarked area of the region.
ysr@777 681 bool obj_allocated_since_prev_marking(oop obj) const {
ysr@777 682 return (HeapWord *) obj >= prev_top_at_mark_start();
ysr@777 683 }
ysr@777 684 bool obj_allocated_since_next_marking(oop obj) const {
ysr@777 685 return (HeapWord *) obj >= next_top_at_mark_start();
ysr@777 686 }
ysr@777 687
ysr@777 688 // For parallel heapRegion traversal.
ysr@777 689 bool claimHeapRegion(int claimValue);
ysr@777 690 jint claim_value() { return _claimed; }
ysr@777 691 // Use this carefully: only when you're sure no one is claiming...
ysr@777 692 void set_claim_value(int claimValue) { _claimed = claimValue; }
ysr@777 693
ysr@777 694 // Returns the "evacuation_failed" property of the region.
ysr@777 695 bool evacuation_failed() { return _evacuation_failed; }
ysr@777 696
ysr@777 697 // Sets the "evacuation_failed" property of the region.
ysr@777 698 void set_evacuation_failed(bool b) {
ysr@777 699 _evacuation_failed = b;
ysr@777 700
ysr@777 701 if (b) {
ysr@777 702 _next_marked_bytes = 0;
ysr@777 703 }
ysr@777 704 }
ysr@777 705
ysr@777 706 // Requires that "mr" be entirely within the region.
ysr@777 707 // Apply "cl->do_object" to all objects that intersect with "mr".
ysr@777 708 // If the iteration encounters an unparseable portion of the region,
ysr@777 709 // or if "cl->abort()" is true after a closure application,
ysr@777 710 // terminate the iteration and return the address of the start of the
ysr@777 711 // subregion that isn't done. (The two can be distinguished by querying
ysr@777 712 // "cl->abort()".) Return of "NULL" indicates that the iteration
ysr@777 713 // completed.
ysr@777 714 HeapWord*
ysr@777 715 object_iterate_mem_careful(MemRegion mr, ObjectClosure* cl);
ysr@777 716
tonyp@2849 717 // filter_young: if true and the region is a young region then we
tonyp@2849 718 // skip the iteration.
tonyp@2849 719 // card_ptr: if not NULL, and we decide that the card is not young
tonyp@2849 720 // and we iterate over it, we'll clean the card before we start the
tonyp@2849 721 // iteration.
ysr@777 722 HeapWord*
ysr@777 723 oops_on_card_seq_iterate_careful(MemRegion mr,
johnc@2021 724 FilterOutOfRegionClosure* cl,
tonyp@2849 725 bool filter_young,
tonyp@2849 726 jbyte* card_ptr);
ysr@777 727
johnc@1829 728 size_t recorded_rs_length() const { return _recorded_rs_length; }
johnc@1829 729 double predicted_elapsed_time_ms() const { return _predicted_elapsed_time_ms; }
johnc@1829 730 size_t predicted_bytes_to_copy() const { return _predicted_bytes_to_copy; }
johnc@1829 731
johnc@1829 732 void set_recorded_rs_length(size_t rs_length) {
johnc@1829 733 _recorded_rs_length = rs_length;
johnc@1829 734 }
johnc@1829 735
johnc@1829 736 void set_predicted_elapsed_time_ms(double ms) {
johnc@1829 737 _predicted_elapsed_time_ms = ms;
johnc@1829 738 }
johnc@1829 739
johnc@1829 740 void set_predicted_bytes_to_copy(size_t bytes) {
johnc@1829 741 _predicted_bytes_to_copy = bytes;
johnc@1829 742 }
johnc@1829 743
tonyp@3957 744 virtual CompactibleSpace* next_compaction_space() const;
ysr@777 745
ysr@777 746 virtual void reset_after_compaction();
ysr@777 747
johnc@5548 748 // Routines for managing a list of code roots (attached to the
johnc@5548 749 // this region's RSet) that point into this heap region.
johnc@5548 750 void add_strong_code_root(nmethod* nm);
mgerdin@7208 751 void add_strong_code_root_locked(nmethod* nm);
johnc@5548 752 void remove_strong_code_root(nmethod* nm);
johnc@5548 753
johnc@5548 754 // Applies blk->do_code_blob() to each of the entries in
johnc@5548 755 // the strong code roots list for this region
johnc@5548 756 void strong_code_roots_do(CodeBlobClosure* blk) const;
johnc@5548 757
johnc@5548 758 // Verify that the entries on the strong code root list for this
johnc@5548 759 // region are live and include at least one pointer into this region.
johnc@5548 760 void verify_strong_code_roots(VerifyOption vo, bool* failures) const;
johnc@5548 761
ysr@777 762 void print() const;
ysr@777 763 void print_on(outputStream* st) const;
ysr@777 764
johnc@2969 765 // vo == UsePrevMarking -> use "prev" marking information,
johnc@2969 766 // vo == UseNextMarking -> use "next" marking information
johnc@2969 767 // vo == UseMarkWord -> use the mark word in the object header
johnc@2969 768 //
tonyp@1246 769 // NOTE: Only the "prev" marking information is guaranteed to be
tonyp@1246 770 // consistent most of the time, so most calls to this should use
johnc@2969 771 // vo == UsePrevMarking.
johnc@2969 772 // Currently, there is only one case where this is called with
johnc@2969 773 // vo == UseNextMarking, which is to verify the "next" marking
johnc@2969 774 // information at the end of remark.
johnc@2969 775 // Currently there is only one place where this is called with
johnc@2969 776 // vo == UseMarkWord, which is to verify the marking during a
johnc@2969 777 // full GC.
brutisso@3711 778 void verify(VerifyOption vo, bool *failures) const;
tonyp@1246 779
tonyp@1246 780 // Override; it uses the "prev" marking information
brutisso@3711 781 virtual void verify() const;
poonam@8287 782
poonam@8287 783 void verify_rem_set(VerifyOption vo, bool *failures) const;
poonam@8287 784 void verify_rem_set() const;
ysr@777 785 };
ysr@777 786
ysr@777 787 // HeapRegionClosure is used for iterating over regions.
ysr@777 788 // Terminates the iteration when the "doHeapRegion" method returns "true".
ysr@777 789 class HeapRegionClosure : public StackObj {
tschatzl@7091 790 friend class HeapRegionManager;
ysr@777 791 friend class G1CollectedHeap;
ysr@777 792
ysr@777 793 bool _complete;
ysr@777 794 void incomplete() { _complete = false; }
ysr@777 795
ysr@777 796 public:
ysr@777 797 HeapRegionClosure(): _complete(true) {}
ysr@777 798
ysr@777 799 // Typically called on each region until it returns true.
ysr@777 800 virtual bool doHeapRegion(HeapRegion* r) = 0;
ysr@777 801
ysr@777 802 // True after iteration if the closure was applied to all heap regions
ysr@777 803 // and returned "false" in all cases.
ysr@777 804 bool complete() { return _complete; }
ysr@777 805 };
ysr@777 806
stefank@2314 807 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGION_HPP

mercurial