Mercurial > hg > graal-jvmci-8
comparison src/share/vm/gc_implementation/g1/heapRegionSeq.hpp @ 20336:6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
Summary: Let HeapRegionSeq manage the heap region and auxiliary data to decrease the amount of responsibilities of G1CollectedHeap, and encapsulate this work from other code.
Reviewed-by: jwilhelm, jmasa, mgerdin, brutisso
author | tschatzl |
---|---|
date | Tue, 19 Aug 2014 10:50:27 +0200 |
parents | eec72fa4b108 |
children | 1f1d373cd044 |
comparison
equal
deleted
inserted
replaced
20335:eec72fa4b108 | 20336:6701abbc4441 |
---|---|
24 | 24 |
25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSEQ_HPP | 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSEQ_HPP |
26 #define SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSEQ_HPP | 26 #define SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSEQ_HPP |
27 | 27 |
28 #include "gc_implementation/g1/g1BiasedArray.hpp" | 28 #include "gc_implementation/g1/g1BiasedArray.hpp" |
29 #include "gc_implementation/g1/heapRegionSet.hpp" | |
29 | 30 |
30 class HeapRegion; | 31 class HeapRegion; |
31 class HeapRegionClosure; | 32 class HeapRegionClosure; |
32 class FreeRegionList; | 33 class FreeRegionList; |
33 | 34 |
34 class G1HeapRegionTable : public G1BiasedMappedArray<HeapRegion*> { | 35 class G1HeapRegionTable : public G1BiasedMappedArray<HeapRegion*> { |
35 protected: | 36 protected: |
36 virtual HeapRegion* default_value() const { return NULL; } | 37 virtual HeapRegion* default_value() const { return NULL; } |
37 }; | 38 }; |
38 | 39 |
39 // This class keeps track of the region metadata (i.e., HeapRegion | 40 // This class keeps track of the region metadata (i.e., HeapRegion |
40 // instances). They are kept in the _regions array in address | 41 // instances). They are kept in the _regions array in address |
41 // order. A region's index in the array corresponds to its index in | 42 // order. A region's index in the array corresponds to its index in |
62 class HeapRegionSeq: public CHeapObj<mtGC> { | 63 class HeapRegionSeq: public CHeapObj<mtGC> { |
63 friend class VMStructs; | 64 friend class VMStructs; |
64 | 65 |
65 G1HeapRegionTable _regions; | 66 G1HeapRegionTable _regions; |
66 | 67 |
67 // The number of regions committed in the heap. | 68 ReservedSpace _reserved; |
68 uint _committed_length; | 69 VirtualSpace _storage; |
69 | 70 |
70 // A hint for which index to start searching from for humongous | 71 FreeRegionList _free_list; |
71 // allocations. | 72 |
72 uint _next_search_index; | 73 // The number of regions committed in the heap. |
73 | 74 uint _num_committed; |
74 // The number of regions for which we have allocated HeapRegions for. | 75 |
75 uint _allocated_length; | 76 // Internal only. The highest heap region +1 we allocated a HeapRegion instance for. |
76 | 77 uint _allocated_heapregions_length; |
77 // Find a contiguous set of empty regions of length num, starting | 78 |
78 // from the given index. | 79 HeapWord* heap_bottom() const { return _regions.bottom_address_mapped(); } |
79 uint find_contiguous_from(uint from, uint num); | 80 HeapWord* heap_top() const { return heap_bottom() + _num_committed * HeapRegion::GrainWords; } |
80 | 81 HeapWord* heap_end() const {return _regions.end_address_mapped(); } |
81 void increment_allocated_length() { | 82 |
82 assert(_allocated_length < max_length(), "pre-condition"); | 83 void make_regions_available(uint index, uint num_regions = 1); |
83 _allocated_length++; | 84 |
84 } | 85 // Pass down commit calls to the VirtualSpace. |
85 | 86 void commit_regions(uint index, size_t num_regions = 1); |
86 void increment_length() { | 87 void uncommit_regions(uint index, size_t num_regions = 1); |
87 assert(length() < max_length(), "pre-condition"); | 88 |
88 _committed_length++; | 89 // Notify other data structures about change in the heap layout. |
89 } | 90 void update_committed_space(HeapWord* old_end, HeapWord* new_end); |
90 | 91 // Calculate the starting region for each worker during parallel iteration so |
91 void decrement_length() { | 92 // that they do not all start from the same region. |
92 assert(length() > 0, "pre-condition"); | 93 uint start_region_for_worker(uint worker_i, uint num_workers, uint num_regions) const; |
93 _committed_length--; | 94 |
94 } | 95 // Finds the next sequence of unavailable regions starting from start_idx. Returns the |
95 | 96 // length of the sequence found. If this result is zero, no such sequence could be found, |
96 HeapWord* heap_bottom() const { return _regions.bottom_address_mapped(); } | 97 // otherwise res_idx indicates the start index of these regions. |
97 HeapWord* heap_end() const {return _regions.end_address_mapped(); } | 98 uint find_unavailable_from_idx(uint start_idx, uint* res_idx) const; |
98 | 99 // Finds the next sequence of empty regions starting from start_idx, going backwards in |
99 public: | 100 // the heap. Returns the length of the sequence found. If this value is zero, no |
100 // Empty contructor, we'll initialize it with the initialize() method. | 101 // sequence could be found, otherwise res_idx contains the start index of this range. |
101 HeapRegionSeq() : _regions(), _committed_length(0), _next_search_index(0), _allocated_length(0) { } | 102 uint find_empty_from_idx_reverse(uint start_idx, uint* res_idx) const; |
102 | 103 #ifdef ASSERT |
103 void initialize(HeapWord* bottom, HeapWord* end); | 104 public: |
105 bool is_free(HeapRegion* hr) const; | |
106 #endif | |
107 // Returns whether the given region is available for allocation. | |
108 bool is_available(uint region) const; | |
109 | |
110 // Allocate a new HeapRegion for the given index. | |
111 HeapRegion* new_heap_region(uint hrs_index); | |
112 public: | |
113 // Empty constructor, we'll initialize it with the initialize() method. | |
114 HeapRegionSeq() : _regions(), _reserved(), _storage(), _num_committed(0), | |
115 _free_list("Master Free List", new MasterFreeRegionListMtSafeChecker()), | |
116 _allocated_heapregions_length(0) | |
117 { } | |
118 | |
119 void initialize(ReservedSpace reserved); | |
120 | |
121 // Return the "dummy" region used for G1AllocRegion. This is currently a hardwired | |
122 // new HeapRegion that owns HeapRegion at index 0. Since at the moment we commit | |
123 // the heap from the lowest address, this region (and its associated data | |
124 // structures) are available and we do not need to check further. | |
125 HeapRegion* get_dummy_region() { return new_heap_region(0); } | |
104 | 126 |
105 // Return the HeapRegion at the given index. Assume that the index | 127 // Return the HeapRegion at the given index. Assume that the index |
106 // is valid. | 128 // is valid. |
107 inline HeapRegion* at(uint index) const; | 129 inline HeapRegion* at(uint index) const; |
108 | 130 |
109 // If addr is within the committed space return its corresponding | 131 // If addr is within the committed space return its corresponding |
110 // HeapRegion, otherwise return NULL. | 132 // HeapRegion, otherwise return NULL. |
111 inline HeapRegion* addr_to_region(HeapWord* addr) const; | 133 inline HeapRegion* addr_to_region(HeapWord* addr) const; |
112 | 134 |
135 // Insert the given region into the free region list. | |
136 inline void insert_into_free_list(HeapRegion* hr); | |
137 | |
138 // Insert the given region list into the global free region list. | |
139 void insert_list_into_free_list(FreeRegionList* list) { | |
140 _free_list.add_ordered(list); | |
141 } | |
142 | |
143 HeapRegion* allocate_free_region(bool is_old) { | |
144 HeapRegion* hr = _free_list.remove_region(is_old); | |
145 | |
146 if (hr != NULL) { | |
147 assert(hr->next() == NULL, "Single region should not have next"); | |
148 assert(is_available(hr->hrs_index()), "Must be committed"); | |
149 } | |
150 return hr; | |
151 } | |
152 | |
153 inline void allocate_free_regions_starting_at(uint first, uint num_regions); | |
154 | |
155 // Remove all regions from the free list. | |
156 void remove_all_free_regions() { | |
157 _free_list.remove_all(); | |
158 } | |
159 | |
160 // Return the number of committed free regions in the heap. | |
161 uint num_free_regions() const { | |
162 return _free_list.length(); | |
163 } | |
164 | |
165 size_t total_capacity_bytes() const { | |
166 return num_free_regions() * HeapRegion::GrainBytes; | |
167 } | |
168 | |
169 // Return the number of available (uncommitted) regions. | |
170 uint available() const { return max_length() - length(); } | |
171 | |
113 // Return the number of regions that have been committed in the heap. | 172 // Return the number of regions that have been committed in the heap. |
114 uint length() const { return _committed_length; } | 173 uint length() const { return _num_committed; } |
115 | 174 |
116 // Return the maximum number of regions in the heap. | 175 // Return the maximum number of regions in the heap. |
117 uint max_length() const { return (uint)_regions.length(); } | 176 uint max_length() const { return (uint)_regions.length(); } |
118 | 177 |
119 // Expand the sequence to reflect that the heap has grown from | 178 MemRegion committed() const { return MemRegion(heap_bottom(), heap_top()); } |
120 // old_end to new_end. Either create new HeapRegions, or re-use | 179 |
121 // existing ones, and return them in the given list. Returns the | 180 MemRegion reserved() const { return MemRegion(heap_bottom(), heap_end()); } |
122 // memory region that covers the newly-created regions. If a | 181 |
123 // HeapRegion allocation fails, the result memory region might be | 182 // Expand the sequence to reflect that the heap has grown. Either create new |
124 // smaller than the desired one. | 183 // HeapRegions, or re-use existing ones. Returns the number of regions the |
125 MemRegion expand_by(HeapWord* old_end, HeapWord* new_end, | 184 // sequence was expanded by. If a HeapRegion allocation fails, the resulting |
126 FreeRegionList* list); | 185 // number of regions might be smaller than what's desired. |
127 | 186 uint expand_by(uint num_regions); |
128 // Return the number of contiguous regions at the end of the sequence | 187 |
129 // that are available for allocation. | 188 // Makes sure that the regions from start to start+num_regions-1 are available |
130 uint free_suffix(); | 189 // for allocation. Returns the number of regions that were committed to achieve |
131 | 190 // this. |
132 // Find a contiguous set of empty regions of length num and return | 191 uint expand_at(uint start, uint num_regions); |
133 // the index of the first region or G1_NULL_HRS_INDEX if the | 192 |
134 // search was unsuccessful. | 193 // Find a contiguous set of empty or uncommitted regions of length num and return |
135 uint find_contiguous(uint num); | 194 // the index of the first region or G1_NO_HRS_INDEX if the search was unsuccessful. |
195 // If only_empty is true, only empty regions are considered. | |
196 // Searches from bottom to top of the heap, doing a first-fit. | |
197 uint find_contiguous(size_t num, bool only_empty); | |
198 | |
199 HeapRegion* next_region_in_heap(const HeapRegion* r) const; | |
136 | 200 |
137 // Apply blk->doHeapRegion() on all committed regions in address order, | 201 // Apply blk->doHeapRegion() on all committed regions in address order, |
138 // terminating the iteration early if doHeapRegion() returns true. | 202 // terminating the iteration early if doHeapRegion() returns true. |
139 void iterate(HeapRegionClosure* blk) const; | 203 void iterate(HeapRegionClosure* blk) const; |
140 | 204 |
141 // As above, but start the iteration from hr and loop around. If hr | 205 void par_iterate(HeapRegionClosure* blk, uint worker_id, uint no_of_par_workers, jint claim_value) const; |
142 // is NULL, we start from the first region in the heap. | 206 |
143 void iterate_from(HeapRegion* hr, HeapRegionClosure* blk) const; | 207 // Uncommit up to num_regions_to_remove regions that are completely free. |
144 | 208 // Return the actual number of uncommitted regions. |
145 // Tag as uncommitted as many regions that are completely free as | |
146 // possible, up to num_regions_to_remove, from the suffix of the committed | |
147 // sequence. Return the actual number of removed regions. | |
148 uint shrink_by(uint num_regions_to_remove); | 209 uint shrink_by(uint num_regions_to_remove); |
210 | |
211 void verify(); | |
149 | 212 |
150 // Do some sanity checking. | 213 // Do some sanity checking. |
151 void verify_optional() PRODUCT_RETURN; | 214 void verify_optional() PRODUCT_RETURN; |
152 }; | 215 }; |
153 | 216 |