Mercurial > hg > truffle
annotate src/share/vm/memory/freeList.cpp @ 7788:dbbe8ce3bfa5
commands: accept 'server0' as a vm, accept version number which have '-...' suffix (-internal, -ea...)
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Wed, 13 Feb 2013 18:33:54 +0100 |
parents | 685df3c6f84b |
children | db9981fd3124 |
rev | line source |
---|---|
0 | 1 /* |
6842
b9a9ed0f8eeb
7197424: update copyright year to match last edit in jdk8 hotspot repository
mikael
parents:
6028
diff
changeset
|
2 * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
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 | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1145
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1145
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1145
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
6026 | 26 #include "memory/freeBlockDictionary.hpp" |
27 #include "memory/freeList.hpp" | |
6885 | 28 #include "memory/metablock.hpp" |
29 #include "memory/metachunk.hpp" | |
1972 | 30 #include "memory/sharedHeap.hpp" |
31 #include "runtime/globals.hpp" | |
32 #include "runtime/mutex.hpp" | |
33 #include "runtime/vmThread.hpp" | |
0 | 34 |
6026 | 35 #ifndef SERIALGC |
36 #include "gc_implementation/concurrentMarkSweep/freeChunk.hpp" | |
37 #endif // SERIALGC | |
38 | |
0 | 39 // Free list. A FreeList is used to access a linked list of chunks |
40 // of space in the heap. The head and tail are maintained so that | |
41 // items can be (as in the current implementation) added at the | |
42 // at the tail of the list and removed from the head of the list to | |
43 // maintain a FIFO queue. | |
44 | |
6026 | 45 template <class Chunk> |
46 FreeList<Chunk>::FreeList() : | |
0 | 47 _head(NULL), _tail(NULL) |
48 #ifdef ASSERT | |
49 , _protecting_lock(NULL) | |
50 #endif | |
51 { | |
52 _size = 0; | |
53 _count = 0; | |
54 } | |
55 | |
6026 | 56 template <class Chunk> |
57 FreeList<Chunk>::FreeList(Chunk* fc) : | |
0 | 58 _head(fc), _tail(fc) |
59 #ifdef ASSERT | |
60 , _protecting_lock(NULL) | |
61 #endif | |
62 { | |
63 _size = fc->size(); | |
64 _count = 1; | |
65 } | |
66 | |
6026 | 67 template <class Chunk> |
6885 | 68 void FreeList<Chunk>::link_head(Chunk* v) { |
69 assert_proper_lock_protection(); | |
70 set_head(v); | |
71 // If this method is not used (just set the head instead), | |
72 // this check can be avoided. | |
73 if (v != NULL) { | |
74 v->link_prev(NULL); | |
75 } | |
76 } | |
77 | |
78 | |
79 | |
80 template <class Chunk> | |
81 void FreeList<Chunk>::reset() { | |
82 // Don't set the _size to 0 because this method is | |
83 // used with a existing list that has a size but which has | |
84 // been emptied. | |
85 // Don't clear the _protecting_lock of an existing list. | |
0 | 86 set_count(0); |
87 set_head(NULL); | |
88 set_tail(NULL); | |
89 } | |
90 | |
6026 | 91 template <class Chunk> |
6885 | 92 void FreeList<Chunk>::initialize() { |
93 #ifdef ASSERT | |
94 // Needed early because it might be checked in other initializing code. | |
95 set_protecting_lock(NULL); | |
96 #endif | |
97 reset(); | |
98 set_size(0); | |
0 | 99 } |
100 | |
6885 | 101 template <class Chunk_t> |
102 Chunk_t* FreeList<Chunk_t>::get_chunk_at_head() { | |
0 | 103 assert_proper_lock_protection(); |
104 assert(head() == NULL || head()->prev() == NULL, "list invariant"); | |
105 assert(tail() == NULL || tail()->next() == NULL, "list invariant"); | |
6885 | 106 Chunk_t* fc = head(); |
0 | 107 if (fc != NULL) { |
6885 | 108 Chunk_t* nextFC = fc->next(); |
0 | 109 if (nextFC != NULL) { |
110 // The chunk fc being removed has a "next". Set the "next" to the | |
111 // "prev" of fc. | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
112 nextFC->link_prev(NULL); |
0 | 113 } else { // removed tail of list |
114 link_tail(NULL); | |
115 } | |
116 link_head(nextFC); | |
117 decrement_count(); | |
118 } | |
119 assert(head() == NULL || head()->prev() == NULL, "list invariant"); | |
120 assert(tail() == NULL || tail()->next() == NULL, "list invariant"); | |
121 return fc; | |
122 } | |
123 | |
124 | |
6026 | 125 template <class Chunk> |
126 void FreeList<Chunk>::getFirstNChunksFromList(size_t n, FreeList<Chunk>* fl) { | |
0 | 127 assert_proper_lock_protection(); |
128 assert(fl->count() == 0, "Precondition"); | |
129 if (count() > 0) { | |
130 int k = 1; | |
131 fl->set_head(head()); n--; | |
6026 | 132 Chunk* tl = head(); |
0 | 133 while (tl->next() != NULL && n > 0) { |
134 tl = tl->next(); n--; k++; | |
135 } | |
136 assert(tl != NULL, "Loop Inv."); | |
137 | |
138 // First, fix up the list we took from. | |
6026 | 139 Chunk* new_head = tl->next(); |
0 | 140 set_head(new_head); |
141 set_count(count() - k); | |
142 if (new_head == NULL) { | |
143 set_tail(NULL); | |
144 } else { | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
145 new_head->link_prev(NULL); |
0 | 146 } |
147 // Now we can fix up the tail. | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
148 tl->link_next(NULL); |
0 | 149 // And return the result. |
150 fl->set_tail(tl); | |
151 fl->set_count(k); | |
152 } | |
153 } | |
154 | |
155 // Remove this chunk from the list | |
6026 | 156 template <class Chunk> |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
157 void FreeList<Chunk>::remove_chunk(Chunk*fc) { |
0 | 158 assert_proper_lock_protection(); |
159 assert(head() != NULL, "Remove from empty list"); | |
160 assert(fc != NULL, "Remove a NULL chunk"); | |
161 assert(size() == fc->size(), "Wrong list"); | |
162 assert(head() == NULL || head()->prev() == NULL, "list invariant"); | |
163 assert(tail() == NULL || tail()->next() == NULL, "list invariant"); | |
164 | |
6026 | 165 Chunk* prevFC = fc->prev(); |
166 Chunk* nextFC = fc->next(); | |
0 | 167 if (nextFC != NULL) { |
168 // The chunk fc being removed has a "next". Set the "next" to the | |
169 // "prev" of fc. | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
170 nextFC->link_prev(prevFC); |
0 | 171 } else { // removed tail of list |
172 link_tail(prevFC); | |
173 } | |
174 if (prevFC == NULL) { // removed head of list | |
175 link_head(nextFC); | |
176 assert(nextFC == NULL || nextFC->prev() == NULL, | |
177 "Prev of head should be NULL"); | |
178 } else { | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
179 prevFC->link_next(nextFC); |
0 | 180 assert(tail() != prevFC || prevFC->next() == NULL, |
181 "Next of tail should be NULL"); | |
182 } | |
183 decrement_count(); | |
1777
179464550c7d
6983930: CMS: Various small cleanups ca September 2010
ysr
parents:
1552
diff
changeset
|
184 assert(((head() == NULL) + (tail() == NULL) + (count() == 0)) % 3 == 0, |
179464550c7d
6983930: CMS: Various small cleanups ca September 2010
ysr
parents:
1552
diff
changeset
|
185 "H/T/C Inconsistency"); |
0 | 186 // clear next and prev fields of fc, debug only |
187 NOT_PRODUCT( | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
188 fc->link_prev(NULL); |
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
189 fc->link_next(NULL); |
0 | 190 ) |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
191 assert(fc->is_free(), "Should still be a free chunk"); |
0 | 192 assert(head() == NULL || head()->prev() == NULL, "list invariant"); |
193 assert(tail() == NULL || tail()->next() == NULL, "list invariant"); | |
194 assert(head() == NULL || head()->size() == size(), "wrong item on list"); | |
195 assert(tail() == NULL || tail()->size() == size(), "wrong item on list"); | |
196 } | |
197 | |
198 // Add this chunk at the head of the list. | |
6026 | 199 template <class Chunk> |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
200 void FreeList<Chunk>::return_chunk_at_head(Chunk* chunk, bool record_return) { |
0 | 201 assert_proper_lock_protection(); |
202 assert(chunk != NULL, "insert a NULL chunk"); | |
203 assert(size() == chunk->size(), "Wrong size"); | |
204 assert(head() == NULL || head()->prev() == NULL, "list invariant"); | |
205 assert(tail() == NULL || tail()->next() == NULL, "list invariant"); | |
206 | |
6026 | 207 Chunk* oldHead = head(); |
0 | 208 assert(chunk != oldHead, "double insertion"); |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
209 chunk->link_after(oldHead); |
0 | 210 link_head(chunk); |
211 if (oldHead == NULL) { // only chunk in list | |
212 assert(tail() == NULL, "inconsistent FreeList"); | |
213 link_tail(chunk); | |
214 } | |
215 increment_count(); // of # of chunks in list | |
216 assert(head() == NULL || head()->prev() == NULL, "list invariant"); | |
217 assert(tail() == NULL || tail()->next() == NULL, "list invariant"); | |
218 assert(head() == NULL || head()->size() == size(), "wrong item on list"); | |
219 assert(tail() == NULL || tail()->size() == size(), "wrong item on list"); | |
220 } | |
221 | |
6026 | 222 template <class Chunk> |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
223 void FreeList<Chunk>::return_chunk_at_head(Chunk* chunk) { |
0 | 224 assert_proper_lock_protection(); |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
225 return_chunk_at_head(chunk, true); |
0 | 226 } |
227 | |
228 // Add this chunk at the tail of the list. | |
6026 | 229 template <class Chunk> |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
230 void FreeList<Chunk>::return_chunk_at_tail(Chunk* chunk, bool record_return) { |
0 | 231 assert_proper_lock_protection(); |
232 assert(head() == NULL || head()->prev() == NULL, "list invariant"); | |
233 assert(tail() == NULL || tail()->next() == NULL, "list invariant"); | |
234 assert(chunk != NULL, "insert a NULL chunk"); | |
235 assert(size() == chunk->size(), "wrong size"); | |
236 | |
6026 | 237 Chunk* oldTail = tail(); |
0 | 238 assert(chunk != oldTail, "double insertion"); |
239 if (oldTail != NULL) { | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
240 oldTail->link_after(chunk); |
0 | 241 } else { // only chunk in list |
242 assert(head() == NULL, "inconsistent FreeList"); | |
243 link_head(chunk); | |
244 } | |
245 link_tail(chunk); | |
246 increment_count(); // of # of chunks in list | |
247 assert(head() == NULL || head()->prev() == NULL, "list invariant"); | |
248 assert(tail() == NULL || tail()->next() == NULL, "list invariant"); | |
249 assert(head() == NULL || head()->size() == size(), "wrong item on list"); | |
250 assert(tail() == NULL || tail()->size() == size(), "wrong item on list"); | |
251 } | |
252 | |
6026 | 253 template <class Chunk> |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
254 void FreeList<Chunk>::return_chunk_at_tail(Chunk* chunk) { |
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
255 return_chunk_at_tail(chunk, true); |
0 | 256 } |
257 | |
6026 | 258 template <class Chunk> |
259 void FreeList<Chunk>::prepend(FreeList<Chunk>* fl) { | |
0 | 260 assert_proper_lock_protection(); |
261 if (fl->count() > 0) { | |
262 if (count() == 0) { | |
263 set_head(fl->head()); | |
264 set_tail(fl->tail()); | |
265 set_count(fl->count()); | |
266 } else { | |
267 // Both are non-empty. | |
6026 | 268 Chunk* fl_tail = fl->tail(); |
269 Chunk* this_head = head(); | |
0 | 270 assert(fl_tail->next() == NULL, "Well-formedness of fl"); |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
271 fl_tail->link_next(this_head); |
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
272 this_head->link_prev(fl_tail); |
0 | 273 set_head(fl->head()); |
274 set_count(count() + fl->count()); | |
275 } | |
276 fl->set_head(NULL); | |
277 fl->set_tail(NULL); | |
278 fl->set_count(0); | |
279 } | |
280 } | |
281 | |
6885 | 282 // verify_chunk_in_free_lists() is used to verify that an item is in this free list. |
0 | 283 // It is used as a debugging aid. |
6026 | 284 template <class Chunk> |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
285 bool FreeList<Chunk>::verify_chunk_in_free_list(Chunk* fc) const { |
0 | 286 // This is an internal consistency check, not part of the check that the |
287 // chunk is in the free lists. | |
288 guarantee(fc->size() == size(), "Wrong list is being searched"); | |
6026 | 289 Chunk* curFC = head(); |
0 | 290 while (curFC) { |
291 // This is an internal consistency check. | |
292 guarantee(size() == curFC->size(), "Chunk is in wrong list."); | |
293 if (fc == curFC) { | |
294 return true; | |
295 } | |
296 curFC = curFC->next(); | |
297 } | |
298 return false; | |
299 } | |
300 | |
301 #ifndef PRODUCT | |
6026 | 302 template <class Chunk> |
303 void FreeList<Chunk>::assert_proper_lock_protection_work() const { | |
6885 | 304 assert(protecting_lock() != NULL, "Don't call this directly"); |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
196
diff
changeset
|
305 assert(ParallelGCThreads > 0, "Don't call this directly"); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
196
diff
changeset
|
306 Thread* thr = Thread::current(); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
196
diff
changeset
|
307 if (thr->is_VM_thread() || thr->is_ConcurrentGC_thread()) { |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
196
diff
changeset
|
308 // assert that we are holding the freelist lock |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
196
diff
changeset
|
309 } else if (thr->is_GC_task_thread()) { |
6885 | 310 assert(protecting_lock()->owned_by_self(), "FreeList RACE DETECTED"); |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
196
diff
changeset
|
311 } else if (thr->is_Java_thread()) { |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
196
diff
changeset
|
312 assert(!SafepointSynchronize::is_at_safepoint(), "Should not be executing"); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
196
diff
changeset
|
313 } else { |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
196
diff
changeset
|
314 ShouldNotReachHere(); // unaccounted thread type? |
0 | 315 } |
316 } | |
317 #endif | |
12
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
318 |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
319 // Print the "label line" for free list stats. |
6026 | 320 template <class Chunk> |
321 void FreeList<Chunk>::print_labels_on(outputStream* st, const char* c) { | |
12
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
322 st->print("%16s\t", c); |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
323 st->print("%14s\t" "%14s\t" "%14s\t" "%14s\t" "%14s\t" |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
324 "%14s\t" "%14s\t" "%14s\t" "%14s\t" "%14s\t" "\n", |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
325 "bfrsurp", "surplus", "desired", "prvSwep", "bfrSwep", |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
326 "count", "cBirths", "cDeaths", "sBirths", "sDeaths"); |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
327 } |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
328 |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
329 // Print the AllocationStats for the given free list. If the second argument |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
330 // to the call is a non-null string, it is printed in the first column; |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
331 // otherwise, if the argument is null (the default), then the size of the |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
332 // (free list) block is printed in the first column. |
6885 | 333 template <class Chunk_t> |
334 void FreeList<Chunk_t>::print_on(outputStream* st, const char* c) const { | |
12
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
335 if (c != NULL) { |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
336 st->print("%16s", c); |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
337 } else { |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
338 st->print(SIZE_FORMAT_W(16), size()); |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
339 } |
6432c3bb6240
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
0
diff
changeset
|
340 } |
6026 | 341 |
6885 | 342 template class FreeList<Metablock>; |
343 template class FreeList<Metachunk>; | |
6026 | 344 #ifndef SERIALGC |
345 template class FreeList<FreeChunk>; | |
346 #endif // SERIALGC |