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