Mercurial > hg > graal-compiler
comparison src/share/vm/gc_implementation/g1/heapRegionSet.hpp @ 17773:8ee855b4e667
8036025: Sort the freelist in order to shrink the heap
Summary: The free list is being maintained in a sorted fashion and old and humongous regions are allocated from the bottom of the heap while young regions are allocated at the top.
Reviewed-by: tschatzl, mgerdin
Contributed-by: jesper.wilhelmsson@oracle.com, staffan.friberg@oracle.com
author | jwilhelm |
---|---|
date | Fri, 28 Feb 2014 15:27:09 +0100 |
parents | 58fc1b1523dc |
children | 78bbf4d43a14 |
comparison
equal
deleted
inserted
replaced
17763:6e7e363c5a8f | 17773:8ee855b4e667 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
189 void bulk_remove(const HeapRegionSetCount& removed) { | 189 void bulk_remove(const HeapRegionSetCount& removed) { |
190 _count.decrement(removed.length(), removed.capacity()); | 190 _count.decrement(removed.length(), removed.capacity()); |
191 } | 191 } |
192 }; | 192 }; |
193 | 193 |
194 // A set that links all the regions added to it in a singly-linked | 194 // A set that links all the regions added to it in a doubly-linked |
195 // list. We should try to avoid doing operations that iterate over | 195 // list. We should try to avoid doing operations that iterate over |
196 // such lists in performance critical paths. Typically we should | 196 // such lists in performance critical paths. Typically we should |
197 // add / remove one region at a time or concatenate two lists. All | 197 // add / remove one region at a time or concatenate two lists. There are |
198 // those operations are done in constant time. | 198 // two ways to treat your lists, ordered and un-ordered. All un-ordered |
199 // operations are done in constant time. To keep a list ordered only use | |
200 // add_ordered() to add elements to the list. If a list is not ordered | |
201 // from start, there is no way to sort it later. | |
199 | 202 |
200 class FreeRegionListIterator; | 203 class FreeRegionListIterator; |
201 | 204 |
202 class FreeRegionList : public HeapRegionSetBase { | 205 class FreeRegionList : public HeapRegionSetBase { |
203 friend class FreeRegionListIterator; | 206 friend class FreeRegionListIterator; |
204 | 207 |
205 private: | 208 private: |
206 HeapRegion* _head; | 209 HeapRegion* _head; |
207 HeapRegion* _tail; | 210 HeapRegion* _tail; |
208 | 211 |
212 // _last is used to keep track of where we added an element the last | |
213 // time in ordered lists. It helps to improve performance when adding | |
214 // several ordered items in a row. | |
215 HeapRegion* _last; | |
216 | |
209 static uint _unrealistically_long_length; | 217 static uint _unrealistically_long_length; |
210 | 218 |
211 void add_as_head_or_tail(FreeRegionList* from_list, bool as_head); | 219 void add_as_head_or_tail(FreeRegionList* from_list, bool as_head); |
212 | 220 |
213 protected: | 221 protected: |
227 HeapRegion* head() { return _head; } | 235 HeapRegion* head() { return _head; } |
228 HeapRegion* tail() { return _tail; } | 236 HeapRegion* tail() { return _tail; } |
229 | 237 |
230 static void set_unrealistically_long_length(uint len); | 238 static void set_unrealistically_long_length(uint len); |
231 | 239 |
240 // Add hr to the list. The region should not be a member of another set. | |
241 // Assumes that the list is ordered and will preserve that order. The order | |
242 // is determined by hrs_index. | |
243 inline void add_ordered(HeapRegion* hr); | |
244 | |
232 // It adds hr to the list as the new head. The region should not be | 245 // It adds hr to the list as the new head. The region should not be |
233 // a member of another set. | 246 // a member of another set. |
234 inline void add_as_head(HeapRegion* hr); | 247 inline void add_as_head(HeapRegion* hr); |
235 | 248 |
236 // It adds hr to the list as the new tail. The region should not be | 249 // It adds hr to the list as the new tail. The region should not be |
241 // list is not empty so it will return a non-NULL value. | 254 // list is not empty so it will return a non-NULL value. |
242 inline HeapRegion* remove_head(); | 255 inline HeapRegion* remove_head(); |
243 | 256 |
244 // Convenience method. | 257 // Convenience method. |
245 inline HeapRegion* remove_head_or_null(); | 258 inline HeapRegion* remove_head_or_null(); |
259 | |
260 // Removes and returns the last element (_tail) of the list. It assumes | |
261 // that the list isn't empty so that it can return a non-NULL value. | |
262 inline HeapRegion* remove_tail(); | |
263 | |
264 // Convenience method | |
265 inline HeapRegion* remove_tail_or_null(); | |
266 | |
267 // Removes from head or tail based on the given argument. | |
268 inline HeapRegion* remove_region(bool from_head); | |
269 | |
270 // Merge two ordered lists. The result is also ordered. The order is | |
271 // determined by hrs_index. | |
272 void add_ordered(FreeRegionList* from_list); | |
246 | 273 |
247 // It moves the regions from from_list to this list and empties | 274 // It moves the regions from from_list to this list and empties |
248 // from_list. The new regions will appear in the same order as they | 275 // from_list. The new regions will appear in the same order as they |
249 // were in from_list and be linked in the beginning of this list. | 276 // were in from_list and be linked in the beginning of this list. |
250 void add_as_head(FreeRegionList* from_list); | 277 void add_as_head(FreeRegionList* from_list); |
274 // regions of a HeapRegionLinkedList instance. | 301 // regions of a HeapRegionLinkedList instance. |
275 | 302 |
276 class FreeRegionListIterator : public StackObj { | 303 class FreeRegionListIterator : public StackObj { |
277 private: | 304 private: |
278 FreeRegionList* _list; | 305 FreeRegionList* _list; |
279 HeapRegion* _curr; | 306 HeapRegion* _curr; |
280 | 307 |
281 public: | 308 public: |
282 bool more_available() { | 309 bool more_available() { |
283 return _curr != NULL; | 310 return _curr != NULL; |
284 } | 311 } |
294 _list->verify_region(hr); | 321 _list->verify_region(hr); |
295 _curr = hr->next(); | 322 _curr = hr->next(); |
296 return hr; | 323 return hr; |
297 } | 324 } |
298 | 325 |
299 FreeRegionListIterator(FreeRegionList* list) | 326 FreeRegionListIterator(FreeRegionList* list) : _curr(NULL), _list(list) { |
300 : _curr(NULL), _list(list) { | |
301 _curr = list->head(); | 327 _curr = list->head(); |
302 } | 328 } |
303 }; | 329 }; |
304 | 330 |
305 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_HPP | 331 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_HPP |