40 // Space::initDirtyCardClosure method must not be called. |
40 // Space::initDirtyCardClosure method must not be called. |
41 // The problem is that the existence of this method breaks |
41 // The problem is that the existence of this method breaks |
42 // the independence of barrier sets from remembered sets. |
42 // the independence of barrier sets from remembered sets. |
43 // The solution is to remove this method from the definition |
43 // The solution is to remove this method from the definition |
44 // of a Space. |
44 // of a Space. |
|
45 |
|
46 // Each heap region is self contained. top() and end() can never |
|
47 // be set beyond the end of the region. For humongous objects, |
|
48 // the first region is a StartsHumongous region. If the humongous |
|
49 // object is larger than a heap region, the following regions will |
|
50 // be of type ContinuesHumongous. In this case the top() of the |
|
51 // StartHumongous region and all ContinuesHumongous regions except |
|
52 // the last will point to their own end. For the last ContinuesHumongous |
|
53 // region, top() will equal the object's top. |
45 |
54 |
46 class G1CollectedHeap; |
55 class G1CollectedHeap; |
47 class HeapRegionRemSet; |
56 class HeapRegionRemSet; |
48 class HeapRegionRemSetIterator; |
57 class HeapRegionRemSetIterator; |
49 class HeapRegion; |
58 class HeapRegion; |
387 |
396 |
388 // A lower bound on the amount of garbage bytes in the region. |
397 // A lower bound on the amount of garbage bytes in the region. |
389 size_t garbage_bytes() { |
398 size_t garbage_bytes() { |
390 size_t used_at_mark_start_bytes = |
399 size_t used_at_mark_start_bytes = |
391 (prev_top_at_mark_start() - bottom()) * HeapWordSize; |
400 (prev_top_at_mark_start() - bottom()) * HeapWordSize; |
392 assert(used_at_mark_start_bytes >= marked_bytes(), |
|
393 "Can't mark more than we have."); |
|
394 return used_at_mark_start_bytes - marked_bytes(); |
401 return used_at_mark_start_bytes - marked_bytes(); |
395 } |
402 } |
396 |
403 |
397 // Return the amount of bytes we'll reclaim if we collect this |
404 // Return the amount of bytes we'll reclaim if we collect this |
398 // region. This includes not only the known garbage bytes in the |
405 // region. This includes not only the known garbage bytes in the |
407 // An upper bound on the number of live bytes in the region. |
414 // An upper bound on the number of live bytes in the region. |
408 size_t max_live_bytes() { return used() - garbage_bytes(); } |
415 size_t max_live_bytes() { return used() - garbage_bytes(); } |
409 |
416 |
410 void add_to_marked_bytes(size_t incr_bytes) { |
417 void add_to_marked_bytes(size_t incr_bytes) { |
411 _next_marked_bytes = _next_marked_bytes + incr_bytes; |
418 _next_marked_bytes = _next_marked_bytes + incr_bytes; |
412 assert(_next_marked_bytes <= used(), "invariant" ); |
|
413 } |
419 } |
414 |
420 |
415 void zero_marked_bytes() { |
421 void zero_marked_bytes() { |
416 _prev_marked_bytes = _next_marked_bytes = 0; |
422 _prev_marked_bytes = _next_marked_bytes = 0; |
417 } |
423 } |
443 // For a humongous region, region in which it starts. |
449 // For a humongous region, region in which it starts. |
444 HeapRegion* humongous_start_region() const { |
450 HeapRegion* humongous_start_region() const { |
445 return _humongous_start_region; |
451 return _humongous_start_region; |
446 } |
452 } |
447 |
453 |
448 // Return the number of distinct regions that are covered by this region: |
|
449 // 1 if the region is not humongous, >= 1 if the region is humongous. |
|
450 uint region_num() const { |
|
451 if (!is_humongous()) { |
|
452 return 1U; |
|
453 } else { |
|
454 assert(is_starts_humongous(), "doesn't make sense on HC regions"); |
|
455 assert(capacity() % HeapRegion::GrainBytes == 0, "sanity"); |
|
456 return (uint) (capacity() >> HeapRegion::LogOfHRGrainBytes); |
|
457 } |
|
458 } |
|
459 |
|
460 // Return the index + 1 of the last HC regions that's associated |
|
461 // with this HS region. |
|
462 uint last_hc_index() const { |
|
463 assert(is_starts_humongous(), "don't call this otherwise"); |
|
464 return hrm_index() + region_num(); |
|
465 } |
|
466 |
|
467 // Same as Space::is_in_reserved, but will use the original size of the region. |
|
468 // The original size is different only for start humongous regions. They get |
|
469 // their _end set up to be the end of the last continues region of the |
|
470 // corresponding humongous object. |
|
471 bool is_in_reserved_raw(const void* p) const { |
|
472 return _bottom <= p && p < orig_end(); |
|
473 } |
|
474 |
|
475 // Makes the current region be a "starts humongous" region, i.e., |
454 // Makes the current region be a "starts humongous" region, i.e., |
476 // the first region in a series of one or more contiguous regions |
455 // the first region in a series of one or more contiguous regions |
477 // that will contain a single "humongous" object. The two parameters |
456 // that will contain a single "humongous" object. |
478 // are as follows: |
|
479 // |
457 // |
480 // new_top : The new value of the top field of this region which |
458 // obj_top : points to the end of the humongous object that's being |
481 // points to the end of the humongous object that's being |
459 // allocated. |
482 // allocated. If there is more than one region in the series, top |
460 void set_starts_humongous(HeapWord* obj_top); |
483 // will lie beyond this region's original end field and on the last |
|
484 // region in the series. |
|
485 // |
|
486 // new_end : The new value of the end field of this region which |
|
487 // points to the end of the last region in the series. If there is |
|
488 // one region in the series (namely: this one) end will be the same |
|
489 // as the original end of this region. |
|
490 // |
|
491 // Updating top and end as described above makes this region look as |
|
492 // if it spans the entire space taken up by all the regions in the |
|
493 // series and an single allocation moved its top to new_top. This |
|
494 // ensures that the space (capacity / allocated) taken up by all |
|
495 // humongous regions can be calculated by just looking at the |
|
496 // "starts humongous" regions and by ignoring the "continues |
|
497 // humongous" regions. |
|
498 void set_starts_humongous(HeapWord* new_top, HeapWord* new_end); |
|
499 |
461 |
500 // Makes the current region be a "continues humongous' |
462 // Makes the current region be a "continues humongous' |
501 // region. first_hr is the "start humongous" region of the series |
463 // region. first_hr is the "start humongous" region of the series |
502 // which this region will be part of. |
464 // which this region will be part of. |
503 void set_continues_humongous(HeapRegion* first_hr); |
465 void set_continues_humongous(HeapRegion* first_hr); |
564 HeapRegion* get_next_dirty_cards_region() const { return _next_dirty_cards_region; } |
526 HeapRegion* get_next_dirty_cards_region() const { return _next_dirty_cards_region; } |
565 HeapRegion** next_dirty_cards_region_addr() { return &_next_dirty_cards_region; } |
527 HeapRegion** next_dirty_cards_region_addr() { return &_next_dirty_cards_region; } |
566 void set_next_dirty_cards_region(HeapRegion* hr) { _next_dirty_cards_region = hr; } |
528 void set_next_dirty_cards_region(HeapRegion* hr) { _next_dirty_cards_region = hr; } |
567 bool is_on_dirty_cards_region_list() const { return get_next_dirty_cards_region() != NULL; } |
529 bool is_on_dirty_cards_region_list() const { return get_next_dirty_cards_region() != NULL; } |
568 |
530 |
569 // For the start region of a humongous sequence, it's original end(). |
|
570 HeapWord* orig_end() const { return _bottom + GrainWords; } |
|
571 |
|
572 // Reset HR stuff to default values. |
531 // Reset HR stuff to default values. |
573 void hr_clear(bool par, bool clear_space, bool locked = false); |
532 void hr_clear(bool par, bool clear_space, bool locked = false); |
574 void par_clear(); |
533 void par_clear(); |
575 |
534 |
576 // Get the start of the unmarked area in this region. |
535 // Get the start of the unmarked area in this region. |
612 // Returns "false" iff no object in the region was allocated when the |
571 // Returns "false" iff no object in the region was allocated when the |
613 // last mark phase ended. |
572 // last mark phase ended. |
614 bool is_marked() { return _prev_top_at_mark_start != bottom(); } |
573 bool is_marked() { return _prev_top_at_mark_start != bottom(); } |
615 |
574 |
616 void reset_during_compaction() { |
575 void reset_during_compaction() { |
617 assert(is_starts_humongous(), |
576 assert(is_humongous(), |
618 "should only be called for starts humongous regions"); |
577 "should only be called for humongous regions"); |
619 |
578 |
620 zero_marked_bytes(); |
579 zero_marked_bytes(); |
621 init_top_at_mark_start(); |
580 init_top_at_mark_start(); |
622 } |
581 } |
623 |
582 |