src/share/vm/gc_implementation/g1/heapRegionManager.cpp

Print this page
rev 7056 : [mq]: 8058298
rev 7057 : imported patch review

*** 437,441 **** --- 437,470 ---- void HeapRegionManager::verify_optional() { verify(); } #endif // PRODUCT + void HeapRegionClaimer::initialize(uint n_workers) { + assert(n_workers > 0, "Need at least one worker."); + assert(_claims == NULL, "Must initialize only once."); + _n_workers = n_workers; + _n_regions = G1CollectedHeap::heap()->_hrm._allocated_heapregions_length; + _claims = NEW_C_HEAP_ARRAY(uint, _n_regions, mtGC); + memset(_claims, Unclaimed, sizeof(*_claims) * _n_regions); + } + + uint HeapRegionClaimer::start_region_for_worker(uint worker_id) const { + assert(_n_workers != 0, "Must initialize before use."); + assert(worker_id < _n_workers, "Invalid worker_id."); + return _n_regions * worker_id / _n_workers; + } + + bool HeapRegionClaimer::is_region_claimed(uint region_index) const { + assert(_claims != NULL, "Must initialize before use."); + assert(region_index < _n_regions, "Invalid index."); + return _claims[region_index] == Claimed; + } + + bool HeapRegionClaimer::claim_region(uint region_index) { + assert(_claims != NULL, "Must initialize before use."); + assert(region_index < _n_regions, "Invalid index."); + if (Atomic::cmpxchg(Claimed, &_claims[region_index], Unclaimed) == Unclaimed) { + return true; + } + return false; + } \ No newline at end of file