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

Mon, 07 Jul 2014 10:12:40 +0200

author
stefank
date
Mon, 07 Jul 2014 10:12:40 +0200
changeset 6992
2c6ef90f030a
parent 6990
1526a938e670
child 7050
6701abbc4441
permissions
-rw-r--r--

8049421: G1 Class Unloading after completing a concurrent mark cycle
Reviewed-by: tschatzl, ehelin, brutisso, coleenp, roland, iveresov
Contributed-by: stefan.karlsson@oracle.com, mikael.gerdin@oracle.com

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

mercurial