src/share/vm/gc_implementation/g1/heapRegionManager.hpp
Print this page
rev 7107 : imported patch 8058298
rev 7108 : imported patch rev1
*** 29,38 ****
--- 29,39 ----
#include "gc_implementation/g1/g1RegionToSpaceMapper.hpp"
#include "gc_implementation/g1/heapRegionSet.hpp"
class HeapRegion;
class HeapRegionClosure;
+ class HeapRegionClaimer;
class FreeRegionList;
class G1HeapRegionTable : public G1BiasedMappedArray<HeapRegion*> {
protected:
virtual HeapRegion* default_value() const { return NULL; }
*** 64,73 ****
--- 65,75 ----
// * max_length() returns the maximum number of regions the heap can have.
//
class HeapRegionManager: public CHeapObj<mtGC> {
friend class VMStructs;
+ friend class HeapRegionClaimer;
G1HeapRegionTable _regions;
G1RegionToSpaceMapper* _heap_mapper;
G1RegionToSpaceMapper* _prev_bitmap_mapper;
*** 97,109 ****
void commit_regions(uint index, size_t num_regions = 1);
void uncommit_regions(uint index, size_t num_regions = 1);
// Notify other data structures about change in the heap layout.
void update_committed_space(HeapWord* old_end, HeapWord* new_end);
- // Calculate the starting region for each worker during parallel iteration so
- // that they do not all start from the same region.
- uint start_region_for_worker(uint worker_i, uint num_workers, uint num_regions) const;
// Find a contiguous set of empty or uncommitted regions of length num and return
// the index of the first region or G1_NO_HRM_INDEX if the search was unsuccessful.
// If only_empty is true, only empty regions are considered.
// Searches from bottom to top of the heap, doing a first-fit.
--- 99,108 ----
*** 221,231 ****
// Apply blk->doHeapRegion() on all committed regions in address order,
// terminating the iteration early if doHeapRegion() returns true.
void iterate(HeapRegionClosure* blk) const;
! void par_iterate(HeapRegionClosure* blk, uint worker_id, uint no_of_par_workers, jint claim_value) const;
// Uncommit up to num_regions_to_remove regions that are completely free.
// Return the actual number of uncommitted regions.
uint shrink_by(uint num_regions_to_remove);
--- 220,230 ----
// Apply blk->doHeapRegion() on all committed regions in address order,
// terminating the iteration early if doHeapRegion() returns true.
void iterate(HeapRegionClosure* blk) const;
! void par_iterate(HeapRegionClosure* blk, uint worker_id, HeapRegionClaimer* hrclaimer) const;
// Uncommit up to num_regions_to_remove regions that are completely free.
// Return the actual number of uncommitted regions.
uint shrink_by(uint num_regions_to_remove);
*** 233,239 ****
--- 232,277 ----
// Do some sanity checking.
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