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

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6680
78bbf4d43a14
parent 0
f90c822e73f8
child 7535
7ae4e26cb1e0
permissions
-rw-r--r--

merge

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

mercurial