comparison src/share/vm/gc_implementation/g1/heapRegionSet.inline.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 14bd75c9dbfa
children a8ea2f110d87
comparison
equal deleted inserted replaced
20335:eec72fa4b108 20336:6701abbc4441
28 #include "gc_implementation/g1/heapRegionSet.hpp" 28 #include "gc_implementation/g1/heapRegionSet.hpp"
29 29
30 inline void HeapRegionSetBase::add(HeapRegion* hr) { 30 inline void HeapRegionSetBase::add(HeapRegion* hr) {
31 check_mt_safety(); 31 check_mt_safety();
32 assert(hr->containing_set() == NULL, hrs_ext_msg(this, "should not already have a containing set %u")); 32 assert(hr->containing_set() == NULL, hrs_ext_msg(this, "should not already have a containing set %u"));
33 assert(hr->next() == NULL && hr->prev() == NULL, hrs_ext_msg(this, "should not already be linked")); 33 assert(hr->next() == NULL, hrs_ext_msg(this, "should not already be linked"));
34 assert(hr->prev() == NULL, hrs_ext_msg(this, "should not already be linked"));
34 35
35 _count.increment(1u, hr->capacity()); 36 _count.increment(1u, hr->capacity());
36 hr->set_containing_set(this); 37 hr->set_containing_set(this);
37 verify_region(hr); 38 verify_region(hr);
38 } 39 }
39 40
40 inline void HeapRegionSetBase::remove(HeapRegion* hr) { 41 inline void HeapRegionSetBase::remove(HeapRegion* hr) {
41 check_mt_safety(); 42 check_mt_safety();
42 verify_region(hr); 43 verify_region(hr);
43 assert(hr->next() == NULL && hr->prev() == NULL, hrs_ext_msg(this, "should already be unlinked")); 44 assert(hr->next() == NULL, hrs_ext_msg(this, "should already be unlinked"));
45 assert(hr->prev() == NULL, hrs_ext_msg(this, "should already be unlinked"));
44 46
45 hr->set_containing_set(NULL); 47 hr->set_containing_set(NULL);
46 assert(_count.length() > 0, hrs_ext_msg(this, "pre-condition")); 48 assert(_count.length() > 0, hrs_ext_msg(this, "pre-condition"));
47 _count.decrement(1u, hr->capacity()); 49 _count.decrement(1u, hr->capacity());
48 } 50 }
49 51
50 inline void FreeRegionList::add_ordered(HeapRegion* hr) { 52 inline void FreeRegionList::add_ordered(HeapRegion* hr) {
51 check_mt_safety(); 53 assert((length() == 0 && _head == NULL && _tail == NULL && _last == NULL) ||
52 assert((length() == 0 && _head == NULL && _tail == NULL) ||
53 (length() > 0 && _head != NULL && _tail != NULL), 54 (length() > 0 && _head != NULL && _tail != NULL),
54 hrs_ext_msg(this, "invariant")); 55 hrs_ext_msg(this, "invariant"));
55 // add() will verify the region and check mt safety. 56 // add() will verify the region and check mt safety.
56 add(hr); 57 add(hr);
57 58
93 _head = hr; 94 _head = hr;
94 } 95 }
95 _last = hr; 96 _last = hr;
96 } 97 }
97 98
98 inline void FreeRegionList::add_as_head(HeapRegion* hr) { 99 inline HeapRegion* FreeRegionList::remove_from_head_impl() {
99 assert((length() == 0 && _head == NULL && _tail == NULL) || 100 HeapRegion* result = _head;
100 (length() > 0 && _head != NULL && _tail != NULL), 101 _head = result->next();
101 hrs_ext_msg(this, "invariant"));
102 // add() will verify the region and check mt safety.
103 add(hr);
104
105 // Now link the region.
106 if (_head != NULL) {
107 hr->set_next(_head);
108 _head->set_prev(hr);
109 } else {
110 _tail = hr;
111 }
112 _head = hr;
113 }
114
115 inline void FreeRegionList::add_as_tail(HeapRegion* hr) {
116 check_mt_safety();
117 assert((length() == 0 && _head == NULL && _tail == NULL) ||
118 (length() > 0 && _head != NULL && _tail != NULL),
119 hrs_ext_msg(this, "invariant"));
120 // add() will verify the region and check mt safety.
121 add(hr);
122
123 // Now link the region.
124 if (_tail != NULL) {
125 _tail->set_next(hr);
126 hr->set_prev(_tail);
127 } else {
128 _head = hr;
129 }
130 _tail = hr;
131 }
132
133 inline HeapRegion* FreeRegionList::remove_head() {
134 assert(!is_empty(), hrs_ext_msg(this, "the list should not be empty"));
135 assert(length() > 0 && _head != NULL && _tail != NULL,
136 hrs_ext_msg(this, "invariant"));
137
138 // We need to unlink it first.
139 HeapRegion* hr = _head;
140 _head = hr->next();
141 if (_head == NULL) { 102 if (_head == NULL) {
142 _tail = NULL; 103 _tail = NULL;
143 } else { 104 } else {
144 _head->set_prev(NULL); 105 _head->set_prev(NULL);
145 } 106 }
146 hr->set_next(NULL); 107 result->set_next(NULL);
108 return result;
109 }
110
111 inline HeapRegion* FreeRegionList::remove_from_tail_impl() {
112 HeapRegion* result = _tail;
113
114 _tail = result->prev();
115 if (_tail == NULL) {
116 _head = NULL;
117 } else {
118 _tail->set_next(NULL);
119 }
120 result->set_prev(NULL);
121 return result;
122 }
123
124 inline HeapRegion* FreeRegionList::remove_region(bool from_head) {
125 check_mt_safety();
126 verify_optional();
127
128 if (is_empty()) {
129 return NULL;
130 }
131 assert(length() > 0 && _head != NULL && _tail != NULL,
132 hrs_ext_msg(this, "invariant"));
133
134 HeapRegion* hr;
135
136 if (from_head) {
137 hr = remove_from_head_impl();
138 } else {
139 hr = remove_from_tail_impl();
140 }
147 141
148 if (_last == hr) { 142 if (_last == hr) {
149 _last = NULL; 143 _last = NULL;
150 } 144 }
151 145
152 // remove() will verify the region and check mt safety. 146 // remove() will verify the region and check mt safety.
153 remove(hr); 147 remove(hr);
154 return hr; 148 return hr;
155 } 149 }
156 150
157 inline HeapRegion* FreeRegionList::remove_head_or_null() { 151 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_INLINE_HPP
158 check_mt_safety();
159 if (!is_empty()) {
160 return remove_head();
161 } else {
162 return NULL;
163 }
164 }
165 152
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
209 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_INLINE_HPP