comparison src/share/vm/gc_implementation/g1/heapRegionSet.inline.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 14bd75c9dbfa
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.
45 hr->set_containing_set(NULL); 45 hr->set_containing_set(NULL);
46 assert(_count.length() > 0, hrs_ext_msg(this, "pre-condition")); 46 assert(_count.length() > 0, hrs_ext_msg(this, "pre-condition"));
47 _count.decrement(1u, hr->capacity()); 47 _count.decrement(1u, hr->capacity());
48 } 48 }
49 49
50 inline void FreeRegionList::add_ordered(HeapRegion* hr) {
51 check_mt_safety();
52 assert((length() == 0 && _head == NULL && _tail == NULL) ||
53 (length() > 0 && _head != NULL && _tail != NULL),
54 hrs_ext_msg(this, "invariant"));
55 // add() will verify the region and check mt safety.
56 add(hr);
57
58 // Now link the region
59 if (_head != NULL) {
60 HeapRegion* curr;
61
62 if (_last != NULL && _last->hrs_index() < hr->hrs_index()) {
63 curr = _last;
64 } else {
65 curr = _head;
66 }
67
68 // Find first entry with a Region Index larger than entry to insert.
69 while (curr != NULL && curr->hrs_index() < hr->hrs_index()) {
70 curr = curr->next();
71 }
72
73 hr->set_next(curr);
74
75 if (curr == NULL) {
76 // Adding at the end
77 hr->set_prev(_tail);
78 _tail->set_next(hr);
79 _tail = hr;
80 } else if (curr->prev() == NULL) {
81 // Adding at the beginning
82 hr->set_prev(NULL);
83 _head = hr;
84 curr->set_prev(hr);
85 } else {
86 hr->set_prev(curr->prev());
87 hr->prev()->set_next(hr);
88 curr->set_prev(hr);
89 }
90 } else {
91 // The list was empty
92 _tail = hr;
93 _head = hr;
94 }
95 _last = hr;
96 }
97
50 inline void FreeRegionList::add_as_head(HeapRegion* hr) { 98 inline void FreeRegionList::add_as_head(HeapRegion* hr) {
51 assert((length() == 0 && _head == NULL && _tail == NULL) || 99 assert((length() == 0 && _head == NULL && _tail == NULL) ||
52 (length() > 0 && _head != NULL && _tail != NULL), 100 (length() > 0 && _head != NULL && _tail != NULL),
53 hrs_ext_msg(this, "invariant")); 101 hrs_ext_msg(this, "invariant"));
54 // add() will verify the region and check mt safety. 102 // add() will verify the region and check mt safety.
55 add(hr); 103 add(hr);
56 104
57 // Now link the region. 105 // Now link the region.
58 if (_head != NULL) { 106 if (_head != NULL) {
59 hr->set_next(_head); 107 hr->set_next(_head);
108 _head->set_prev(hr);
60 } else { 109 } else {
61 _tail = hr; 110 _tail = hr;
62 } 111 }
63 _head = hr; 112 _head = hr;
64 } 113 }
66 inline void FreeRegionList::add_as_tail(HeapRegion* hr) { 115 inline void FreeRegionList::add_as_tail(HeapRegion* hr) {
67 check_mt_safety(); 116 check_mt_safety();
68 assert((length() == 0 && _head == NULL && _tail == NULL) || 117 assert((length() == 0 && _head == NULL && _tail == NULL) ||
69 (length() > 0 && _head != NULL && _tail != NULL), 118 (length() > 0 && _head != NULL && _tail != NULL),
70 hrs_ext_msg(this, "invariant")); 119 hrs_ext_msg(this, "invariant"));
71 // add() will verify the region and check mt safety 120 // add() will verify the region and check mt safety.
72 add(hr); 121 add(hr);
73 122
74 // Now link the region. 123 // Now link the region.
75 if (_tail != NULL) { 124 if (_tail != NULL) {
76 _tail->set_next(hr); 125 _tail->set_next(hr);
126 hr->set_prev(_tail);
77 } else { 127 } else {
78 _head = hr; 128 _head = hr;
79 } 129 }
80 _tail = hr; 130 _tail = hr;
81 } 131 }
88 // We need to unlink it first. 138 // We need to unlink it first.
89 HeapRegion* hr = _head; 139 HeapRegion* hr = _head;
90 _head = hr->next(); 140 _head = hr->next();
91 if (_head == NULL) { 141 if (_head == NULL) {
92 _tail = NULL; 142 _tail = NULL;
143 } else {
144 _head->set_prev(NULL);
93 } 145 }
94 hr->set_next(NULL); 146 hr->set_next(NULL);
95 147
96 // remove() will verify the region and check mt safety 148 if (_last == hr) {
149 _last = NULL;
150 }
151
152 // remove() will verify the region and check mt safety.
97 remove(hr); 153 remove(hr);
98 return hr; 154 return hr;
99 } 155 }
100 156
101 inline HeapRegion* FreeRegionList::remove_head_or_null() { 157 inline HeapRegion* FreeRegionList::remove_head_or_null() {
105 } else { 161 } else {
106 return NULL; 162 return NULL;
107 } 163 }
108 } 164 }
109 165
166 inline HeapRegion* FreeRegionList::remove_tail() {
167 assert(!is_empty(), hrs_ext_msg(this, "The list should not be empty"));
168 assert(length() > 0 && _head != NULL && _tail != NULL,
169 hrs_ext_msg(this, "invariant"));
170
171 // We need to unlink it first
172 HeapRegion* hr = _tail;
173
174 _tail = hr->prev();
175 if (_tail == NULL) {
176 _head = NULL;
177 } else {
178 _tail->set_next(NULL);
179 }
180 hr->set_prev(NULL);
181
182 if (_last == hr) {
183 _last = NULL;
184 }
185
186 // remove() will verify the region and check mt safety.
187 remove(hr);
188 return hr;
189 }
190
191 inline HeapRegion* FreeRegionList::remove_tail_or_null() {
192 check_mt_safety();
193
194 if (!is_empty()) {
195 return remove_tail();
196 } else {
197 return NULL;
198 }
199 }
200
201 inline HeapRegion* FreeRegionList::remove_region(bool from_head) {
202 if (from_head) {
203 return remove_head_or_null();
204 } else {
205 return remove_tail_or_null();
206 }
207 }
208
110 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_INLINE_HPP 209 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_INLINE_HPP