< prev index next >

src/hotspot/share/gc/z/zLiveMap.cpp

Print this page




  37 static size_t bitmap_size(uint32_t size, size_t nsegments) {
  38   // We need at least one bit per segment
  39   return MAX2<size_t>(size, nsegments) * 2;
  40 }
  41 
  42 ZLiveMap::ZLiveMap(uint32_t size) :
  43     _seqnum(0),
  44     _live_objects(0),
  45     _live_bytes(0),
  46     _segment_live_bits(0),
  47     _segment_claim_bits(0),
  48     _bitmap(bitmap_size(size, nsegments)),
  49     _segment_shift(exact_log2(segment_size())) {}
  50 
  51 void ZLiveMap::reset(size_t index) {
  52   const uint32_t seqnum_initializing = (uint32_t)-1;
  53   bool contention = false;
  54 
  55   // Multiple threads can enter here, make sure only one of them
  56   // resets the marking information while the others busy wait.
  57   for (uint32_t seqnum = OrderAccess::load_acquire(&_seqnum);
  58        seqnum != ZGlobalSeqNum;
  59        seqnum = OrderAccess::load_acquire(&_seqnum)) {
  60     if ((seqnum != seqnum_initializing) &&
  61         (Atomic::cmpxchg(seqnum_initializing, &_seqnum, seqnum) == seqnum)) {
  62       // Reset marking information
  63       _live_bytes = 0;
  64       _live_objects = 0;
  65 
  66       // Clear segment claimed/live bits
  67       segment_live_bits().clear();
  68       segment_claim_bits().clear();
  69 
  70       assert(_seqnum == seqnum_initializing, "Invalid");
  71 
  72       // Make sure the newly reset marking information is ordered
  73       // before the update of the page seqnum, such that when the
  74       // up-to-date seqnum is load acquired, the bit maps will not
  75       // contain stale information.
  76       OrderAccess::release_store(&_seqnum, ZGlobalSeqNum);
  77       break;
  78     }
  79 
  80     // Mark reset contention
  81     if (!contention) {
  82       // Count contention once
  83       ZStatInc(ZCounterMarkSeqNumResetContention);
  84       contention = true;
  85 
  86       log_trace(gc)("Mark seqnum reset contention, thread: " PTR_FORMAT " (%s), map: " PTR_FORMAT ", bit: " SIZE_FORMAT,
  87                     ZThread::id(), ZThread::name(), p2i(this), index);
  88     }
  89   }
  90 }
  91 
  92 void ZLiveMap::reset_segment(BitMap::idx_t segment) {
  93   bool contention = false;
  94 
  95   if (!claim_segment(segment)) {
  96     // Already claimed, wait for live bit to be set




  37 static size_t bitmap_size(uint32_t size, size_t nsegments) {
  38   // We need at least one bit per segment
  39   return MAX2<size_t>(size, nsegments) * 2;
  40 }
  41 
  42 ZLiveMap::ZLiveMap(uint32_t size) :
  43     _seqnum(0),
  44     _live_objects(0),
  45     _live_bytes(0),
  46     _segment_live_bits(0),
  47     _segment_claim_bits(0),
  48     _bitmap(bitmap_size(size, nsegments)),
  49     _segment_shift(exact_log2(segment_size())) {}
  50 
  51 void ZLiveMap::reset(size_t index) {
  52   const uint32_t seqnum_initializing = (uint32_t)-1;
  53   bool contention = false;
  54 
  55   // Multiple threads can enter here, make sure only one of them
  56   // resets the marking information while the others busy wait.
  57   for (uint32_t seqnum = Atomic::load_acquire(&_seqnum);
  58        seqnum != ZGlobalSeqNum;
  59        seqnum = Atomic::load_acquire(&_seqnum)) {
  60     if ((seqnum != seqnum_initializing) &&
  61         (Atomic::cmpxchg(seqnum_initializing, &_seqnum, seqnum) == seqnum)) {
  62       // Reset marking information
  63       _live_bytes = 0;
  64       _live_objects = 0;
  65 
  66       // Clear segment claimed/live bits
  67       segment_live_bits().clear();
  68       segment_claim_bits().clear();
  69 
  70       assert(_seqnum == seqnum_initializing, "Invalid");
  71 
  72       // Make sure the newly reset marking information is ordered
  73       // before the update of the page seqnum, such that when the
  74       // up-to-date seqnum is load acquired, the bit maps will not
  75       // contain stale information.
  76       Atomic::release_store(&_seqnum, ZGlobalSeqNum);
  77       break;
  78     }
  79 
  80     // Mark reset contention
  81     if (!contention) {
  82       // Count contention once
  83       ZStatInc(ZCounterMarkSeqNumResetContention);
  84       contention = true;
  85 
  86       log_trace(gc)("Mark seqnum reset contention, thread: " PTR_FORMAT " (%s), map: " PTR_FORMAT ", bit: " SIZE_FORMAT,
  87                     ZThread::id(), ZThread::name(), p2i(this), index);
  88     }
  89   }
  90 }
  91 
  92 void ZLiveMap::reset_segment(BitMap::idx_t segment) {
  93   bool contention = false;
  94 
  95   if (!claim_segment(segment)) {
  96     // Already claimed, wait for live bit to be set


< prev index next >