459 while (low < high) {
460 size_t diff = pointer_delta(high, low);
461 // Must add one below to bias toward the high amount. Otherwise, if
462 // "high" were at the desired value, and "low" were one less, we
463 // would not converge on "high". This is not symmetric, because
464 // we set "high" to a block start, which might be the right one,
465 // which we don't do for "low".
466 HeapWord* middle = low + (diff+1)/2;
467 if (middle == high) return high;
468 HeapWord* mid_bs = block_start_careful(middle);
469 if (mid_bs < addr) {
470 low = middle;
471 } else {
472 high = mid_bs;
473 }
474 }
475 assert(low == high && low >= addr, "Didn't work.");
476 return low;
477 }
478
479 void HeapRegion::initialize(MemRegion mr, bool clear_space, bool mangle_space) {
480 G1OffsetTableContigSpace::initialize(mr, false, mangle_space);
481 hr_clear(false/*par*/, clear_space);
482 }
483 #ifdef _MSC_VER // the use of 'this' below gets a warning, make it go away
484 #pragma warning( disable:4355 ) // 'this' : used in base member initializer list
485 #endif // _MSC_VER
486
487
488 HeapRegion::HeapRegion(uint hrs_index,
489 G1BlockOffsetSharedArray* sharedOffsetArray,
490 MemRegion mr, bool is_zeroed) :
491 G1OffsetTableContigSpace(sharedOffsetArray, mr, is_zeroed),
492 _hrs_index(hrs_index),
493 _humongous_type(NotHumongous), _humongous_start_region(NULL),
494 _in_collection_set(false),
495 _next_in_special_set(NULL), _orig_end(NULL),
496 _claimed(InitialClaimValue), _evacuation_failed(false),
497 _prev_marked_bytes(0), _next_marked_bytes(0), _gc_efficiency(0.0),
498 _young_type(NotYoung), _next_young_region(NULL),
499 _next_dirty_cards_region(NULL), _next(NULL), _pending_removal(false),
500 #ifdef ASSERT
501 _containing_set(NULL),
502 #endif // ASSERT
503 _young_index_in_cset(-1), _surv_rate_group(NULL), _age_index(-1),
504 _rem_set(NULL), _recorded_rs_length(0), _predicted_elapsed_time_ms(0),
505 _predicted_bytes_to_copy(0)
506 {
507 _orig_end = mr.end();
508 // Note that initialize() will set the start of the unmarked area of the
509 // region.
510 this->initialize(mr, !is_zeroed, SpaceDecorator::Mangle);
511 set_top(bottom());
512 set_saved_mark();
513
514 _rem_set = new HeapRegionRemSet(sharedOffsetArray, this);
515
516 assert(HeapRegionRemSet::num_par_rem_sets() > 0, "Invariant.");
517 }
518
519 CompactibleSpace* HeapRegion::next_compaction_space() const {
520 // We're not using an iterator given that it will wrap around when
521 // it reaches the last region and this is not what we want here.
522 G1CollectedHeap* g1h = G1CollectedHeap::heap();
523 uint index = hrs_index() + 1;
524 while (index < g1h->n_regions()) {
525 HeapRegion* hr = g1h->region_at(index);
526 if (!hr->isHumongous()) {
527 return hr;
528 }
529 index += 1;
530 }
891 gclog_or_tty->print_cr("BOT look up for end - 1: "PTR_FORMAT" "
892 " yielded "PTR_FORMAT", expecting "PTR_FORMAT,
893 addr_4, b_start_4, p);
894 *failures = true;
895 return;
896 }
897 }
898
899 if (is_humongous && object_num > 1) {
900 gclog_or_tty->print_cr("region ["PTR_FORMAT","PTR_FORMAT"] is humongous "
901 "but has "SIZE_FORMAT", objects",
902 bottom(), end(), object_num);
903 *failures = true;
904 return;
905 }
906 }
907
908 // G1OffsetTableContigSpace code; copied from space.cpp. Hope this can go
909 // away eventually.
910
911 void G1OffsetTableContigSpace::initialize(MemRegion mr, bool clear_space, bool mangle_space) {
912 // false ==> we'll do the clearing if there's clearing to be done.
913 ContiguousSpace::initialize(mr, false, mangle_space);
914 _offsets.zero_bottom_entry();
915 _offsets.initialize_threshold();
916 if (clear_space) clear(mangle_space);
917 }
918
919 void G1OffsetTableContigSpace::clear(bool mangle_space) {
920 ContiguousSpace::clear(mangle_space);
921 _offsets.zero_bottom_entry();
922 _offsets.initialize_threshold();
923 }
924
925 void G1OffsetTableContigSpace::set_bottom(HeapWord* new_bottom) {
926 Space::set_bottom(new_bottom);
927 _offsets.set_bottom(new_bottom);
928 }
929
930 void G1OffsetTableContigSpace::set_end(HeapWord* new_end) {
931 Space::set_end(new_end);
932 _offsets.resize(new_end - bottom());
933 }
934
935 void G1OffsetTableContigSpace::print() const {
936 print_short();
937 gclog_or_tty->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", "
938 INTPTR_FORMAT ", " INTPTR_FORMAT ")",
966 // The order of these is important, as another thread might be
967 // about to start scanning this region. If it does so after
968 // set_saved_mark and before _gc_time_stamp = ..., then the latter
969 // will be false, and it will pick up top() as the high water mark
970 // of region. If it does so after _gc_time_stamp = ..., then it
971 // will pick up the right saved_mark_word() as the high water mark
972 // of the region. Either way, the behaviour will be correct.
973 ContiguousSpace::set_saved_mark();
974 OrderAccess::storestore();
975 _gc_time_stamp = curr_gc_time_stamp;
976 // No need to do another barrier to flush the writes above. If
977 // this is called in parallel with other threads trying to
978 // allocate into the region, the caller should call this while
979 // holding a lock and when the lock is released the writes will be
980 // flushed.
981 }
982 }
983
984 G1OffsetTableContigSpace::
985 G1OffsetTableContigSpace(G1BlockOffsetSharedArray* sharedOffsetArray,
986 MemRegion mr, bool is_zeroed) :
987 _offsets(sharedOffsetArray, mr),
988 _par_alloc_lock(Mutex::leaf, "OffsetTableContigSpace par alloc lock", true),
989 _gc_time_stamp(0)
990 {
991 _offsets.set_space(this);
992 initialize(mr, !is_zeroed, SpaceDecorator::Mangle);
993 }
|
459 while (low < high) {
460 size_t diff = pointer_delta(high, low);
461 // Must add one below to bias toward the high amount. Otherwise, if
462 // "high" were at the desired value, and "low" were one less, we
463 // would not converge on "high". This is not symmetric, because
464 // we set "high" to a block start, which might be the right one,
465 // which we don't do for "low".
466 HeapWord* middle = low + (diff+1)/2;
467 if (middle == high) return high;
468 HeapWord* mid_bs = block_start_careful(middle);
469 if (mid_bs < addr) {
470 low = middle;
471 } else {
472 high = mid_bs;
473 }
474 }
475 assert(low == high && low >= addr, "Didn't work.");
476 return low;
477 }
478
479 #ifdef _MSC_VER // the use of 'this' below gets a warning, make it go away
480 #pragma warning( disable:4355 ) // 'this' : used in base member initializer list
481 #endif // _MSC_VER
482
483
484 HeapRegion::HeapRegion(uint hrs_index,
485 G1BlockOffsetSharedArray* sharedOffsetArray,
486 MemRegion mr) :
487 G1OffsetTableContigSpace(sharedOffsetArray, mr),
488 _hrs_index(hrs_index),
489 _humongous_type(NotHumongous), _humongous_start_region(NULL),
490 _in_collection_set(false),
491 _next_in_special_set(NULL), _orig_end(NULL),
492 _claimed(InitialClaimValue), _evacuation_failed(false),
493 _prev_marked_bytes(0), _next_marked_bytes(0), _gc_efficiency(0.0),
494 _young_type(NotYoung), _next_young_region(NULL),
495 _next_dirty_cards_region(NULL), _next(NULL), _pending_removal(false),
496 #ifdef ASSERT
497 _containing_set(NULL),
498 #endif // ASSERT
499 _young_index_in_cset(-1), _surv_rate_group(NULL), _age_index(-1),
500 _rem_set(NULL), _recorded_rs_length(0), _predicted_elapsed_time_ms(0),
501 _predicted_bytes_to_copy(0)
502 {
503 _orig_end = mr.end();
504 // Note that initialize() will set the start of the unmarked area of the
505 // region.
506 hr_clear(false /*par*/, false /*clear_space*/);
507 set_top(bottom());
508 set_saved_mark();
509
510 _rem_set = new HeapRegionRemSet(sharedOffsetArray, this);
511
512 assert(HeapRegionRemSet::num_par_rem_sets() > 0, "Invariant.");
513 }
514
515 CompactibleSpace* HeapRegion::next_compaction_space() const {
516 // We're not using an iterator given that it will wrap around when
517 // it reaches the last region and this is not what we want here.
518 G1CollectedHeap* g1h = G1CollectedHeap::heap();
519 uint index = hrs_index() + 1;
520 while (index < g1h->n_regions()) {
521 HeapRegion* hr = g1h->region_at(index);
522 if (!hr->isHumongous()) {
523 return hr;
524 }
525 index += 1;
526 }
887 gclog_or_tty->print_cr("BOT look up for end - 1: "PTR_FORMAT" "
888 " yielded "PTR_FORMAT", expecting "PTR_FORMAT,
889 addr_4, b_start_4, p);
890 *failures = true;
891 return;
892 }
893 }
894
895 if (is_humongous && object_num > 1) {
896 gclog_or_tty->print_cr("region ["PTR_FORMAT","PTR_FORMAT"] is humongous "
897 "but has "SIZE_FORMAT", objects",
898 bottom(), end(), object_num);
899 *failures = true;
900 return;
901 }
902 }
903
904 // G1OffsetTableContigSpace code; copied from space.cpp. Hope this can go
905 // away eventually.
906
907 void G1OffsetTableContigSpace::clear(bool mangle_space) {
908 ContiguousSpace::clear(mangle_space);
909 _offsets.zero_bottom_entry();
910 _offsets.initialize_threshold();
911 }
912
913 void G1OffsetTableContigSpace::set_bottom(HeapWord* new_bottom) {
914 Space::set_bottom(new_bottom);
915 _offsets.set_bottom(new_bottom);
916 }
917
918 void G1OffsetTableContigSpace::set_end(HeapWord* new_end) {
919 Space::set_end(new_end);
920 _offsets.resize(new_end - bottom());
921 }
922
923 void G1OffsetTableContigSpace::print() const {
924 print_short();
925 gclog_or_tty->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", "
926 INTPTR_FORMAT ", " INTPTR_FORMAT ")",
954 // The order of these is important, as another thread might be
955 // about to start scanning this region. If it does so after
956 // set_saved_mark and before _gc_time_stamp = ..., then the latter
957 // will be false, and it will pick up top() as the high water mark
958 // of region. If it does so after _gc_time_stamp = ..., then it
959 // will pick up the right saved_mark_word() as the high water mark
960 // of the region. Either way, the behaviour will be correct.
961 ContiguousSpace::set_saved_mark();
962 OrderAccess::storestore();
963 _gc_time_stamp = curr_gc_time_stamp;
964 // No need to do another barrier to flush the writes above. If
965 // this is called in parallel with other threads trying to
966 // allocate into the region, the caller should call this while
967 // holding a lock and when the lock is released the writes will be
968 // flushed.
969 }
970 }
971
972 G1OffsetTableContigSpace::
973 G1OffsetTableContigSpace(G1BlockOffsetSharedArray* sharedOffsetArray,
974 MemRegion mr) :
975 _offsets(sharedOffsetArray, mr),
976 _par_alloc_lock(Mutex::leaf, "OffsetTableContigSpace par alloc lock", true),
977 _gc_time_stamp(0)
978 {
979 _offsets.set_space(this);
980 // false ==> we'll do the clearing if there's clearing to be done.
981 ContiguousSpace::initialize(mr, false, SpaceDecorator::Mangle);
982 _offsets.zero_bottom_entry();
983 _offsets.initialize_threshold();
984 }
|