119 // so that we can reason about all the region groups in the heap using
120 // the same interface (namely, the HeapRegionSetBase API).
121
122 class HeapRegionSet : public HeapRegionSetBase {
123 public:
124 HeapRegionSet(const char* name, HeapRegionSetChecker* checker):
125 HeapRegionSetBase(name, checker) {
126 }
127
128 void bulk_remove(const uint removed) {
129 _length -= removed;
130 }
131 };
132
133 // A set that links all the regions added to it in a doubly-linked
134 // sorted list. We should try to avoid doing operations that iterate over
135 // such lists in performance critical paths. Typically we should
136 // add / remove one region at a time or concatenate two lists.
137
138 class FreeRegionListIterator;
139
140 class FreeRegionList : public HeapRegionSetBase {
141 friend class FreeRegionListIterator;
142
143 private:
144 HeapRegion* _head;
145 HeapRegion* _tail;
146
147 // _last is used to keep track of where we added an element the last
148 // time. It helps to improve performance when adding several ordered items in a row.
149 HeapRegion* _last;
150
151 static uint _unrealistically_long_length;
152
153 inline HeapRegion* remove_from_head_impl();
154 inline HeapRegion* remove_from_tail_impl();
155
156 protected:
157 // See the comment for HeapRegionSetBase::clear()
158 virtual void clear();
159
160 public:
161 FreeRegionList(const char* name, HeapRegionSetChecker* checker = NULL):
162 HeapRegionSetBase(name, checker) {
163 clear();
164 }
165
166 void verify_list();
167
168 #ifdef ASSERT
169 bool contains(HeapRegion* hr) const {
170 return hr->containing_set() == this;
171 }
172 #endif
173
174 static void set_unrealistically_long_length(uint len);
175
176 // Add hr to the list. The region should not be a member of another set.
177 // Assumes that the list is ordered and will preserve that order. The order
178 // is determined by hrm_index.
179 inline void add_ordered(HeapRegion* hr);
180
181 // Removes from head or tail based on the given argument.
182 HeapRegion* remove_region(bool from_head);
183
184 HeapRegion* remove_region_with_node_index(bool from_head,
185 const uint requested_node_index,
186 uint* region_node_index);
187
188 // Merge two ordered lists. The result is also ordered. The order is
189 // determined by hrm_index.
190 void add_ordered(FreeRegionList* from_list);
191
192 // It empties the list by removing all regions from it.
193 void remove_all();
194
195 // Remove all (contiguous) regions from first to first + num_regions -1 from
196 // this list.
197 // Num_regions must be > 1.
198 void remove_starting_at(HeapRegion* first, uint num_regions);
199
200 virtual void verify();
201
202 uint num_of_regions_in_range(uint start, uint end) const;
203 };
204
205 // Iterator class that provides a convenient way to iterate over the
206 // regions of a FreeRegionList.
207
208 class FreeRegionListIterator : public StackObj {
209 private:
210 FreeRegionList* _list;
211 HeapRegion* _curr;
212
213 public:
214 bool more_available() {
215 return _curr != NULL;
216 }
217
218 HeapRegion* get_next() {
219 assert(more_available(),
220 "get_next() should be called when more regions are available");
221
222 // If we are going to introduce a count in the iterator we should
|
119 // so that we can reason about all the region groups in the heap using
120 // the same interface (namely, the HeapRegionSetBase API).
121
122 class HeapRegionSet : public HeapRegionSetBase {
123 public:
124 HeapRegionSet(const char* name, HeapRegionSetChecker* checker):
125 HeapRegionSetBase(name, checker) {
126 }
127
128 void bulk_remove(const uint removed) {
129 _length -= removed;
130 }
131 };
132
133 // A set that links all the regions added to it in a doubly-linked
134 // sorted list. We should try to avoid doing operations that iterate over
135 // such lists in performance critical paths. Typically we should
136 // add / remove one region at a time or concatenate two lists.
137
138 class FreeRegionListIterator;
139 class G1NUMA;
140
141 class FreeRegionList : public HeapRegionSetBase {
142 friend class FreeRegionListIterator;
143
144 private:
145
146 // This class is only initialized if there are multiple active nodes.
147 class NodeInfo : public CHeapObj<mtGC> {
148 G1NUMA* _numa;
149 uint* _length_of_node;
150 uint _num_nodes;
151
152 public:
153 NodeInfo();
154 ~NodeInfo();
155
156 inline void increase_length(uint node_index);
157 inline void decrease_length(uint node_index);
158
159 inline uint length(uint index) const;
160
161 void clear();
162
163 void add(NodeInfo* info);
164 };
165
166 HeapRegion* _head;
167 HeapRegion* _tail;
168
169 // _last is used to keep track of where we added an element the last
170 // time. It helps to improve performance when adding several ordered items in a row.
171 HeapRegion* _last;
172
173 NodeInfo* _node_info;
174
175 static uint _unrealistically_long_length;
176
177 inline HeapRegion* remove_from_head_impl();
178 inline HeapRegion* remove_from_tail_impl();
179
180 inline void increase_length(uint node_index);
181 inline void decrease_length(uint node_index);
182
183 protected:
184 // See the comment for HeapRegionSetBase::clear()
185 virtual void clear();
186
187 public:
188 FreeRegionList(const char* name, HeapRegionSetChecker* checker = NULL);
189 ~FreeRegionList();
190
191 void verify_list();
192
193 #ifdef ASSERT
194 bool contains(HeapRegion* hr) const {
195 return hr->containing_set() == this;
196 }
197 #endif
198
199 static void set_unrealistically_long_length(uint len);
200
201 // Add hr to the list. The region should not be a member of another set.
202 // Assumes that the list is ordered and will preserve that order. The order
203 // is determined by hrm_index.
204 inline void add_ordered(HeapRegion* hr);
205
206 // Removes from head or tail based on the given argument.
207 HeapRegion* remove_region(bool from_head);
208
209 HeapRegion* remove_region_with_node_index(bool from_head,
210 uint requested_node_index);
211
212 // Merge two ordered lists. The result is also ordered. The order is
213 // determined by hrm_index.
214 void add_ordered(FreeRegionList* from_list);
215
216 // It empties the list by removing all regions from it.
217 void remove_all();
218
219 // Remove all (contiguous) regions from first to first + num_regions -1 from
220 // this list.
221 // Num_regions must be > 1.
222 void remove_starting_at(HeapRegion* first, uint num_regions);
223
224 virtual void verify();
225
226 uint num_of_regions_in_range(uint start, uint end) const;
227
228 using HeapRegionSetBase::length;
229 uint length(uint node_index) const;
230 };
231
232 // Iterator class that provides a convenient way to iterate over the
233 // regions of a FreeRegionList.
234
235 class FreeRegionListIterator : public StackObj {
236 private:
237 FreeRegionList* _list;
238 HeapRegion* _curr;
239
240 public:
241 bool more_available() {
242 return _curr != NULL;
243 }
244
245 HeapRegion* get_next() {
246 assert(more_available(),
247 "get_next() should be called when more regions are available");
248
249 // If we are going to introduce a count in the iterator we should
|