24 |
24 |
25 #ifndef SHARE_VM_GC_G1_HEAPREGIONMANAGER_HPP |
25 #ifndef SHARE_VM_GC_G1_HEAPREGIONMANAGER_HPP |
26 #define SHARE_VM_GC_G1_HEAPREGIONMANAGER_HPP |
26 #define SHARE_VM_GC_G1_HEAPREGIONMANAGER_HPP |
27 |
27 |
28 #include "gc/g1/g1BiasedArray.hpp" |
28 #include "gc/g1/g1BiasedArray.hpp" |
|
29 #include "gc/g1/g1CollectorPolicy.hpp" |
29 #include "gc/g1/g1RegionToSpaceMapper.hpp" |
30 #include "gc/g1/g1RegionToSpaceMapper.hpp" |
30 #include "gc/g1/heapRegionSet.hpp" |
31 #include "gc/g1/heapRegionSet.hpp" |
|
32 #include "gc/shared/collectorPolicy.hpp" |
31 #include "services/memoryUsage.hpp" |
33 #include "services/memoryUsage.hpp" |
32 |
34 |
33 class HeapRegion; |
35 class HeapRegion; |
34 class HeapRegionClosure; |
36 class HeapRegionClosure; |
35 class HeapRegionClaimer; |
37 class HeapRegionClaimer; |
69 |
71 |
70 class HeapRegionManager: public CHeapObj<mtGC> { |
72 class HeapRegionManager: public CHeapObj<mtGC> { |
71 friend class VMStructs; |
73 friend class VMStructs; |
72 friend class HeapRegionClaimer; |
74 friend class HeapRegionClaimer; |
73 |
75 |
74 G1HeapRegionTable _regions; |
|
75 |
|
76 G1RegionToSpaceMapper* _heap_mapper; |
|
77 G1RegionToSpaceMapper* _prev_bitmap_mapper; |
|
78 G1RegionToSpaceMapper* _next_bitmap_mapper; |
|
79 G1RegionToSpaceMapper* _bot_mapper; |
76 G1RegionToSpaceMapper* _bot_mapper; |
80 G1RegionToSpaceMapper* _cardtable_mapper; |
77 G1RegionToSpaceMapper* _cardtable_mapper; |
81 G1RegionToSpaceMapper* _card_counts_mapper; |
78 G1RegionToSpaceMapper* _card_counts_mapper; |
82 |
79 |
83 FreeRegionList _free_list; |
|
84 |
|
85 // Each bit in this bitmap indicates that the corresponding region is available |
80 // Each bit in this bitmap indicates that the corresponding region is available |
86 // for allocation. |
81 // for allocation. |
87 CHeapBitMap _available_map; |
82 CHeapBitMap _available_map; |
88 |
83 |
89 // The number of regions committed in the heap. |
84 // The number of regions committed in the heap. |
93 uint _allocated_heapregions_length; |
88 uint _allocated_heapregions_length; |
94 |
89 |
95 HeapWord* heap_bottom() const { return _regions.bottom_address_mapped(); } |
90 HeapWord* heap_bottom() const { return _regions.bottom_address_mapped(); } |
96 HeapWord* heap_end() const {return _regions.end_address_mapped(); } |
91 HeapWord* heap_end() const {return _regions.end_address_mapped(); } |
97 |
92 |
98 void make_regions_available(uint index, uint num_regions = 1, WorkGang* pretouch_gang = NULL); |
|
99 |
|
100 // Pass down commit calls to the VirtualSpace. |
93 // Pass down commit calls to the VirtualSpace. |
101 void commit_regions(uint index, size_t num_regions = 1, WorkGang* pretouch_gang = NULL); |
94 void commit_regions(uint index, size_t num_regions = 1, WorkGang* pretouch_gang = NULL); |
102 void uncommit_regions(uint index, size_t num_regions = 1); |
|
103 |
95 |
104 // Notify other data structures about change in the heap layout. |
96 // Notify other data structures about change in the heap layout. |
105 void update_committed_space(HeapWord* old_end, HeapWord* new_end); |
97 void update_committed_space(HeapWord* old_end, HeapWord* new_end); |
106 |
98 |
107 // Find a contiguous set of empty or uncommitted regions of length num and return |
99 // Find a contiguous set of empty or uncommitted regions of length num and return |
115 uint find_unavailable_from_idx(uint start_idx, uint* res_idx) const; |
107 uint find_unavailable_from_idx(uint start_idx, uint* res_idx) const; |
116 // Finds the next sequence of empty regions starting from start_idx, going backwards in |
108 // Finds the next sequence of empty regions starting from start_idx, going backwards in |
117 // the heap. Returns the length of the sequence found. If this value is zero, no |
109 // the heap. Returns the length of the sequence found. If this value is zero, no |
118 // sequence could be found, otherwise res_idx contains the start index of this range. |
110 // sequence could be found, otherwise res_idx contains the start index of this range. |
119 uint find_empty_from_idx_reverse(uint start_idx, uint* res_idx) const; |
111 uint find_empty_from_idx_reverse(uint start_idx, uint* res_idx) const; |
|
112 |
|
113 protected: |
|
114 G1HeapRegionTable _regions; |
|
115 G1RegionToSpaceMapper* _heap_mapper; |
|
116 G1RegionToSpaceMapper* _prev_bitmap_mapper; |
|
117 G1RegionToSpaceMapper* _next_bitmap_mapper; |
|
118 FreeRegionList _free_list; |
|
119 |
|
120 void make_regions_available(uint index, uint num_regions = 1, WorkGang* pretouch_gang = NULL); |
|
121 void uncommit_regions(uint index, size_t num_regions = 1); |
120 // Allocate a new HeapRegion for the given index. |
122 // Allocate a new HeapRegion for the given index. |
121 HeapRegion* new_heap_region(uint hrm_index); |
123 HeapRegion* new_heap_region(uint hrm_index); |
122 #ifdef ASSERT |
124 #ifdef ASSERT |
123 public: |
125 public: |
124 bool is_free(HeapRegion* hr) const; |
126 bool is_free(HeapRegion* hr) const; |
125 #endif |
127 #endif |
126 public: |
128 public: |
127 // Empty constructor, we'll initialize it with the initialize() method. |
129 // Empty constructor, we'll initialize it with the initialize() method. |
128 HeapRegionManager(); |
130 HeapRegionManager(); |
129 |
131 |
130 void initialize(G1RegionToSpaceMapper* heap_storage, |
132 static HeapRegionManager* create_manager(G1CollectedHeap* heap, G1CollectorPolicy* policy); |
131 G1RegionToSpaceMapper* prev_bitmap, |
133 |
132 G1RegionToSpaceMapper* next_bitmap, |
134 virtual void initialize(G1RegionToSpaceMapper* heap_storage, |
133 G1RegionToSpaceMapper* bot, |
135 G1RegionToSpaceMapper* prev_bitmap, |
134 G1RegionToSpaceMapper* cardtable, |
136 G1RegionToSpaceMapper* next_bitmap, |
135 G1RegionToSpaceMapper* card_counts); |
137 G1RegionToSpaceMapper* bot, |
|
138 G1RegionToSpaceMapper* cardtable, |
|
139 G1RegionToSpaceMapper* card_counts); |
|
140 |
|
141 // Prepare heap regions before and after full collection. |
|
142 // Nothing to be done in this class. |
|
143 virtual void prepare_for_full_collection_start() {} |
|
144 virtual void prepare_for_full_collection_end() {} |
136 |
145 |
137 // Return the "dummy" region used for G1AllocRegion. This is currently a hardwired |
146 // Return the "dummy" region used for G1AllocRegion. This is currently a hardwired |
138 // new HeapRegion that owns HeapRegion at index 0. Since at the moment we commit |
147 // new HeapRegion that owns HeapRegion at index 0. Since at the moment we commit |
139 // the heap from the lowest address, this region (and its associated data |
148 // the heap from the lowest address, this region (and its associated data |
140 // structures) are available and we do not need to check further. |
149 // structures) are available and we do not need to check further. |
141 HeapRegion* get_dummy_region() { return new_heap_region(0); } |
150 virtual HeapRegion* get_dummy_region() { return new_heap_region(0); } |
142 |
151 |
143 // Return the HeapRegion at the given index. Assume that the index |
152 // Return the HeapRegion at the given index. Assume that the index |
144 // is valid. |
153 // is valid. |
145 inline HeapRegion* at(uint index) const; |
154 inline HeapRegion* at(uint index) const; |
146 |
155 |
165 // Insert the given region list into the global free region list. |
174 // Insert the given region list into the global free region list. |
166 void insert_list_into_free_list(FreeRegionList* list) { |
175 void insert_list_into_free_list(FreeRegionList* list) { |
167 _free_list.add_ordered(list); |
176 _free_list.add_ordered(list); |
168 } |
177 } |
169 |
178 |
170 HeapRegion* allocate_free_region(bool is_old) { |
179 virtual HeapRegion* allocate_free_region(HeapRegionType type) { |
171 HeapRegion* hr = _free_list.remove_region(is_old); |
180 HeapRegion* hr = _free_list.remove_region(!type.is_young()); |
172 |
181 |
173 if (hr != NULL) { |
182 if (hr != NULL) { |
174 assert(hr->next() == NULL, "Single region should not have next"); |
183 assert(hr->next() == NULL, "Single region should not have next"); |
175 assert(is_available(hr->hrm_index()), "Must be committed"); |
184 assert(is_available(hr->hrm_index()), "Must be committed"); |
176 } |
185 } |
200 uint length() const { return _num_committed; } |
209 uint length() const { return _num_committed; } |
201 |
210 |
202 // Return the maximum number of regions in the heap. |
211 // Return the maximum number of regions in the heap. |
203 uint max_length() const { return (uint)_regions.length(); } |
212 uint max_length() const { return (uint)_regions.length(); } |
204 |
213 |
|
214 // Return maximum number of regions that heap can expand to. |
|
215 virtual uint max_expandable_length() const { return (uint)_regions.length(); } |
|
216 |
205 MemoryUsage get_auxiliary_data_memory_usage() const; |
217 MemoryUsage get_auxiliary_data_memory_usage() const; |
206 |
218 |
207 MemRegion reserved() const { return MemRegion(heap_bottom(), heap_end()); } |
219 MemRegion reserved() const { return MemRegion(heap_bottom(), heap_end()); } |
208 |
220 |
209 // Expand the sequence to reflect that the heap has grown. Either create new |
221 // Expand the sequence to reflect that the heap has grown. Either create new |
210 // HeapRegions, or re-use existing ones. Returns the number of regions the |
222 // HeapRegions, or re-use existing ones. Returns the number of regions the |
211 // sequence was expanded by. If a HeapRegion allocation fails, the resulting |
223 // sequence was expanded by. If a HeapRegion allocation fails, the resulting |
212 // number of regions might be smaller than what's desired. |
224 // number of regions might be smaller than what's desired. |
213 uint expand_by(uint num_regions, WorkGang* pretouch_workers); |
225 virtual uint expand_by(uint num_regions, WorkGang* pretouch_workers); |
214 |
226 |
215 // Makes sure that the regions from start to start+num_regions-1 are available |
227 // Makes sure that the regions from start to start+num_regions-1 are available |
216 // for allocation. Returns the number of regions that were committed to achieve |
228 // for allocation. Returns the number of regions that were committed to achieve |
217 // this. |
229 // this. |
218 uint expand_at(uint start, uint num_regions, WorkGang* pretouch_workers); |
230 virtual uint expand_at(uint start, uint num_regions, WorkGang* pretouch_workers); |
219 |
231 |
220 // Find a contiguous set of empty regions of length num. Returns the start index of |
232 // Find a contiguous set of empty regions of length num. Returns the start index of |
221 // that set, or G1_NO_HRM_INDEX. |
233 // that set, or G1_NO_HRM_INDEX. |
222 uint find_contiguous_only_empty(size_t num) { return find_contiguous(num, true); } |
234 virtual uint find_contiguous_only_empty(size_t num) { return find_contiguous(num, true); } |
223 // Find a contiguous set of empty or unavailable regions of length num. Returns the |
235 // Find a contiguous set of empty or unavailable regions of length num. Returns the |
224 // start index of that set, or G1_NO_HRM_INDEX. |
236 // start index of that set, or G1_NO_HRM_INDEX. |
225 uint find_contiguous_empty_or_unavailable(size_t num) { return find_contiguous(num, false); } |
237 virtual uint find_contiguous_empty_or_unavailable(size_t num) { return find_contiguous(num, false); } |
226 |
238 |
227 HeapRegion* next_region_in_heap(const HeapRegion* r) const; |
239 HeapRegion* next_region_in_heap(const HeapRegion* r) const; |
228 |
240 |
229 // Find the highest free or uncommitted region in the reserved heap, |
241 // Find the highest free or uncommitted region in the reserved heap, |
230 // and if uncommitted, commit it. If none are available, return G1_NO_HRM_INDEX. |
242 // and if uncommitted, commit it. If none are available, return G1_NO_HRM_INDEX. |
231 // Set the 'expanded' boolean true if a new region was committed. |
243 // Set the 'expanded' boolean true if a new region was committed. |
232 uint find_highest_free(bool* expanded); |
244 virtual uint find_highest_free(bool* expanded); |
233 |
245 |
234 // Allocate the regions that contain the address range specified, committing the |
246 // Allocate the regions that contain the address range specified, committing the |
235 // regions if necessary. Return false if any of the regions is already committed |
247 // regions if necessary. Return false if any of the regions is already committed |
236 // and not free, and return the number of regions newly committed in commit_count. |
248 // and not free, and return the number of regions newly committed in commit_count. |
237 bool allocate_containing_regions(MemRegion range, size_t* commit_count, WorkGang* pretouch_workers); |
249 bool allocate_containing_regions(MemRegion range, size_t* commit_count, WorkGang* pretouch_workers); |
242 |
254 |
243 void par_iterate(HeapRegionClosure* blk, HeapRegionClaimer* hrclaimer, const uint start_index) const; |
255 void par_iterate(HeapRegionClosure* blk, HeapRegionClaimer* hrclaimer, const uint start_index) const; |
244 |
256 |
245 // Uncommit up to num_regions_to_remove regions that are completely free. |
257 // Uncommit up to num_regions_to_remove regions that are completely free. |
246 // Return the actual number of uncommitted regions. |
258 // Return the actual number of uncommitted regions. |
247 uint shrink_by(uint num_regions_to_remove); |
259 virtual uint shrink_by(uint num_regions_to_remove); |
248 |
260 |
249 // Uncommit a number of regions starting at the specified index, which must be available, |
261 // Uncommit a number of regions starting at the specified index, which must be available, |
250 // empty, and free. |
262 // empty, and free. |
251 void shrink_at(uint index, size_t num_regions); |
263 void shrink_at(uint index, size_t num_regions); |
252 |
264 |
253 void verify(); |
265 virtual void verify(); |
254 |
266 |
255 // Do some sanity checking. |
267 // Do some sanity checking. |
256 void verify_optional() PRODUCT_RETURN; |
268 void verify_optional() PRODUCT_RETURN; |
257 }; |
269 }; |
258 |
270 |