--- old/src/share/vm/gc_implementation/g1/heapRegionManager.cpp 2014-09-17 10:13:59.832455770 +0200 +++ new/src/share/vm/gc_implementation/g1/heapRegionManager.cpp 2014-09-17 10:13:59.744458720 +0200 @@ -439,3 +439,32 @@ } #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