--- old/src/share/vm/gc_implementation/g1/heapRegion.hpp 2014-09-17 10:13:58.752491958 +0200 +++ new/src/share/vm/gc_implementation/g1/heapRegion.hpp 2014-09-17 10:13:58.628496112 +0200 @@ -776,44 +776,4 @@ bool complete() { return _complete; } }; -// The HeapRegionClaimer is used during parallel iteration over heap regions, -// allowing workers to claim heap regions, gaining exclusive rights to these regions. -class HeapRegionClaimer { - uint _n_workers; - uint _n_regions; - uint* _claims; - - static const uint Unclaimed = 0; - static const uint Claimed = 1; - - public: - HeapRegionClaimer() : _n_workers(0), _n_regions(0), _claims(NULL) {} - - HeapRegionClaimer(uint n_workers) : _n_workers(n_workers), _n_regions(0), _claims(NULL) { - initialize(n_workers); - } - - ~HeapRegionClaimer() { - if (_claims != NULL) { - FREE_C_HEAP_ARRAY(uint, _claims, mtGC); - } - } - - inline uint n_regions() const { - return _n_regions; - } - - inline void initialize(uint n_workers); - - // Calculate the starting region for given worker so - // that they do not all start from the same region. - inline uint start_region_for_worker(uint worker_id) const; - - // Check if region has been claimed with this HRClaimer. - inline bool is_region_claimed(uint region_index) const; - - // Claim the given region, returns true if successfully claimed. - inline bool claim_region(uint region_index); -}; - #endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGION_HPP --- old/src/share/vm/gc_implementation/g1/heapRegion.inline.hpp 2014-09-17 10:13:59.324472792 +0200 +++ new/src/share/vm/gc_implementation/g1/heapRegion.inline.hpp 2014-09-17 10:13:59.200476946 +0200 @@ -195,33 +195,4 @@ } } -inline 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); -} - -inline 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; -} - -inline 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; -} - -inline 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; -} #endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGION_INLINE_HPP --- 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 --- old/src/share/vm/gc_implementation/g1/heapRegionManager.hpp 2014-09-17 10:14:01.136412079 +0200 +++ new/src/share/vm/gc_implementation/g1/heapRegionManager.hpp 2014-09-17 10:14:00.988417038 +0200 @@ -31,6 +31,7 @@ class HeapRegion; class HeapRegionClosure; +class HeapRegionClaimer; class FreeRegionList; class G1HeapRegionTable : public G1BiasedMappedArray { @@ -233,5 +234,44 @@ void verify_optional() PRODUCT_RETURN; }; +// The HeapRegionClaimer is used during parallel iteration over heap regions, +// allowing workers to claim heap regions, gaining exclusive rights to these regions. +class HeapRegionClaimer : public StackObj { + uint _n_workers; + uint _n_regions; + uint* _claims; + + static const uint Unclaimed = 0; + static const uint Claimed = 1; + + public: + HeapRegionClaimer() : _n_workers(0), _n_regions(0), _claims(NULL) {} + + HeapRegionClaimer(uint n_workers) : _n_workers(n_workers), _n_regions(0), _claims(NULL) { + initialize(n_workers); + } + + ~HeapRegionClaimer() { + if (_claims != NULL) { + FREE_C_HEAP_ARRAY(uint, _claims, mtGC); + } + } + + inline uint n_regions() const { + return _n_regions; + } + + void initialize(uint n_workers); + + // Calculate the starting region for given worker so + // that they do not all start from the same region. + uint start_region_for_worker(uint worker_id) const; + + // Check if region has been claimed with this HRClaimer. + bool is_region_claimed(uint region_index) const; + + // Claim the given region, returns true if successfully claimed. + bool claim_region(uint region_index); +}; #endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONMANAGER_HPP