author | jmasa |
Thu, 29 Mar 2012 19:46:24 -0700 | |
changeset 12507 | 6182ca66bc7b |
parent 7397 | hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/freeList.hpp@5b173b4ca846 |
child 12509 | 6228e2085074 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
7397 | 2 |
* Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4574
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4574
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4574
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
12507 | 25 |
#ifndef SHARE_VM_MEMORY_FREELIST_HPP |
26 |
#define SHARE_VM_MEMORY_FREELIST_HPP |
|
7397 | 27 |
|
28 |
#include "gc_implementation/shared/allocationStats.hpp" |
|
29 |
||
1 | 30 |
class CompactibleFreeListSpace; |
31 |
||
12507 | 32 |
// A class for maintaining a free list of Chunk's. The FreeList |
1 | 33 |
// maintains a the structure of the list (head, tail, etc.) plus |
34 |
// statistics for allocations from the list. The links between items |
|
35 |
// are not part of FreeList. The statistics are |
|
12507 | 36 |
// used to make decisions about coalescing Chunk's when they |
1 | 37 |
// are swept during collection. |
38 |
// |
|
39 |
// See the corresponding .cpp file for a description of the specifics |
|
40 |
// for that implementation. |
|
41 |
||
42 |
class Mutex; |
|
12507 | 43 |
template <class Chunk> class TreeList; |
44 |
template <class Chunk> class PrintTreeCensusClosure; |
|
1 | 45 |
|
12507 | 46 |
template <class Chunk> |
1 | 47 |
class FreeList VALUE_OBJ_CLASS_SPEC { |
48 |
friend class CompactibleFreeListSpace; |
|
578
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
185
diff
changeset
|
49 |
friend class VMStructs; |
12507 | 50 |
friend class PrintTreeCensusClosure<Chunk>; |
4574
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
670
diff
changeset
|
51 |
|
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
670
diff
changeset
|
52 |
private: |
12507 | 53 |
Chunk* _head; // Head of list of free chunks |
54 |
Chunk* _tail; // Tail of list of free chunks |
|
4574
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
670
diff
changeset
|
55 |
size_t _size; // Size in Heap words of each chunk |
1 | 56 |
ssize_t _count; // Number of entries in list |
57 |
size_t _hint; // next larger size list with a positive surplus |
|
58 |
||
4574
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
670
diff
changeset
|
59 |
AllocationStats _allocation_stats; // allocation-related statistics |
1 | 60 |
|
61 |
#ifdef ASSERT |
|
62 |
Mutex* _protecting_lock; |
|
63 |
#endif |
|
64 |
||
65 |
// Asserts false if the protecting lock (if any) is not held. |
|
66 |
void assert_proper_lock_protection_work() const PRODUCT_RETURN; |
|
67 |
void assert_proper_lock_protection() const { |
|
68 |
#ifdef ASSERT |
|
69 |
if (_protecting_lock != NULL) |
|
70 |
assert_proper_lock_protection_work(); |
|
71 |
#endif |
|
72 |
} |
|
73 |
||
74 |
// Initialize the allocation statistics. |
|
75 |
protected: |
|
4574
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
670
diff
changeset
|
76 |
void init_statistics(bool split_birth = false); |
1 | 77 |
void set_count(ssize_t v) { _count = v;} |
4574
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
670
diff
changeset
|
78 |
void increment_count() { |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
670
diff
changeset
|
79 |
_count++; |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
670
diff
changeset
|
80 |
} |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
670
diff
changeset
|
81 |
|
1 | 82 |
void decrement_count() { |
83 |
_count--; |
|
185
cda2a1eb4be5
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
1
diff
changeset
|
84 |
assert(_count >= 0, "Count should not be negative"); |
cda2a1eb4be5
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
1
diff
changeset
|
85 |
} |
1 | 86 |
|
87 |
public: |
|
88 |
// Constructor |
|
89 |
// Construct a list without any entries. |
|
90 |
FreeList(); |
|
91 |
// Construct a list with "fc" as the first (and lone) entry in the list. |
|
12507 | 92 |
FreeList(Chunk* fc); |
1 | 93 |
|
94 |
// Reset the head, tail, hint, and count of a free list. |
|
95 |
void reset(size_t hint); |
|
96 |
||
97 |
// Declare the current free list to be protected by the given lock. |
|
98 |
#ifdef ASSERT |
|
99 |
void set_protecting_lock(Mutex* protecting_lock) { |
|
100 |
_protecting_lock = protecting_lock; |
|
101 |
} |
|
102 |
#endif |
|
103 |
||
104 |
// Accessors. |
|
12507 | 105 |
Chunk* head() const { |
1 | 106 |
assert_proper_lock_protection(); |
107 |
return _head; |
|
108 |
} |
|
12507 | 109 |
void set_head(Chunk* v) { |
1 | 110 |
assert_proper_lock_protection(); |
111 |
_head = v; |
|
112 |
assert(!_head || _head->size() == _size, "bad chunk size"); |
|
113 |
} |
|
114 |
// Set the head of the list and set the prev field of non-null |
|
115 |
// values to NULL. |
|
12507 | 116 |
void link_head(Chunk* v) { |
1 | 117 |
assert_proper_lock_protection(); |
118 |
set_head(v); |
|
119 |
// If this method is not used (just set the head instead), |
|
120 |
// this check can be avoided. |
|
121 |
if (v != NULL) { |
|
122 |
v->linkPrev(NULL); |
|
123 |
} |
|
124 |
} |
|
125 |
||
12507 | 126 |
Chunk* tail() const { |
1 | 127 |
assert_proper_lock_protection(); |
128 |
return _tail; |
|
129 |
} |
|
12507 | 130 |
void set_tail(Chunk* v) { |
1 | 131 |
assert_proper_lock_protection(); |
132 |
_tail = v; |
|
133 |
assert(!_tail || _tail->size() == _size, "bad chunk size"); |
|
134 |
} |
|
135 |
// Set the tail of the list and set the next field of non-null |
|
136 |
// values to NULL. |
|
12507 | 137 |
void link_tail(Chunk* v) { |
1 | 138 |
assert_proper_lock_protection(); |
139 |
set_tail(v); |
|
140 |
if (v != NULL) { |
|
141 |
v->clearNext(); |
|
142 |
} |
|
143 |
} |
|
144 |
||
145 |
// No locking checks in read-accessors: lock-free reads (only) are benign. |
|
146 |
// Readers are expected to have the lock if they are doing work that |
|
147 |
// requires atomicity guarantees in sections of code. |
|
148 |
size_t size() const { |
|
149 |
return _size; |
|
150 |
} |
|
151 |
void set_size(size_t v) { |
|
152 |
assert_proper_lock_protection(); |
|
153 |
_size = v; |
|
154 |
} |
|
155 |
ssize_t count() const { |
|
156 |
return _count; |
|
157 |
} |
|
158 |
size_t hint() const { |
|
159 |
return _hint; |
|
160 |
} |
|
161 |
void set_hint(size_t v) { |
|
162 |
assert_proper_lock_protection(); |
|
163 |
assert(v == 0 || _size < v, "Bad hint"); _hint = v; |
|
164 |
} |
|
165 |
||
166 |
// Accessors for statistics |
|
167 |
AllocationStats* allocation_stats() { |
|
168 |
assert_proper_lock_protection(); |
|
169 |
return &_allocation_stats; |
|
170 |
} |
|
171 |
||
172 |
ssize_t desired() const { |
|
173 |
return _allocation_stats.desired(); |
|
174 |
} |
|
185
cda2a1eb4be5
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
1
diff
changeset
|
175 |
void set_desired(ssize_t v) { |
cda2a1eb4be5
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
1
diff
changeset
|
176 |
assert_proper_lock_protection(); |
cda2a1eb4be5
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
1
diff
changeset
|
177 |
_allocation_stats.set_desired(v); |
cda2a1eb4be5
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
1
diff
changeset
|
178 |
} |
1 | 179 |
void compute_desired(float inter_sweep_current, |
4574
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
670
diff
changeset
|
180 |
float inter_sweep_estimate, |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
670
diff
changeset
|
181 |
float intra_sweep_estimate) { |
1 | 182 |
assert_proper_lock_protection(); |
183 |
_allocation_stats.compute_desired(_count, |
|
184 |
inter_sweep_current, |
|
4574
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
670
diff
changeset
|
185 |
inter_sweep_estimate, |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
670
diff
changeset
|
186 |
intra_sweep_estimate); |
1 | 187 |
} |
188 |
ssize_t coalDesired() const { |
|
189 |
return _allocation_stats.coalDesired(); |
|
190 |
} |
|
191 |
void set_coalDesired(ssize_t v) { |
|
192 |
assert_proper_lock_protection(); |
|
193 |
_allocation_stats.set_coalDesired(v); |
|
194 |
} |
|
195 |
||
196 |
ssize_t surplus() const { |
|
197 |
return _allocation_stats.surplus(); |
|
198 |
} |
|
199 |
void set_surplus(ssize_t v) { |
|
200 |
assert_proper_lock_protection(); |
|
201 |
_allocation_stats.set_surplus(v); |
|
202 |
} |
|
203 |
void increment_surplus() { |
|
204 |
assert_proper_lock_protection(); |
|
205 |
_allocation_stats.increment_surplus(); |
|
206 |
} |
|
207 |
void decrement_surplus() { |
|
208 |
assert_proper_lock_protection(); |
|
209 |
_allocation_stats.decrement_surplus(); |
|
210 |
} |
|
211 |
||
212 |
ssize_t bfrSurp() const { |
|
213 |
return _allocation_stats.bfrSurp(); |
|
214 |
} |
|
215 |
void set_bfrSurp(ssize_t v) { |
|
216 |
assert_proper_lock_protection(); |
|
217 |
_allocation_stats.set_bfrSurp(v); |
|
218 |
} |
|
219 |
ssize_t prevSweep() const { |
|
220 |
return _allocation_stats.prevSweep(); |
|
221 |
} |
|
222 |
void set_prevSweep(ssize_t v) { |
|
223 |
assert_proper_lock_protection(); |
|
224 |
_allocation_stats.set_prevSweep(v); |
|
225 |
} |
|
226 |
ssize_t beforeSweep() const { |
|
227 |
return _allocation_stats.beforeSweep(); |
|
228 |
} |
|
229 |
void set_beforeSweep(ssize_t v) { |
|
230 |
assert_proper_lock_protection(); |
|
231 |
_allocation_stats.set_beforeSweep(v); |
|
232 |
} |
|
233 |
||
234 |
ssize_t coalBirths() const { |
|
235 |
return _allocation_stats.coalBirths(); |
|
236 |
} |
|
237 |
void set_coalBirths(ssize_t v) { |
|
238 |
assert_proper_lock_protection(); |
|
239 |
_allocation_stats.set_coalBirths(v); |
|
240 |
} |
|
241 |
void increment_coalBirths() { |
|
242 |
assert_proper_lock_protection(); |
|
243 |
_allocation_stats.increment_coalBirths(); |
|
244 |
} |
|
245 |
||
246 |
ssize_t coalDeaths() const { |
|
247 |
return _allocation_stats.coalDeaths(); |
|
248 |
} |
|
249 |
void set_coalDeaths(ssize_t v) { |
|
250 |
assert_proper_lock_protection(); |
|
251 |
_allocation_stats.set_coalDeaths(v); |
|
252 |
} |
|
253 |
void increment_coalDeaths() { |
|
254 |
assert_proper_lock_protection(); |
|
255 |
_allocation_stats.increment_coalDeaths(); |
|
256 |
} |
|
257 |
||
258 |
ssize_t splitBirths() const { |
|
259 |
return _allocation_stats.splitBirths(); |
|
260 |
} |
|
261 |
void set_splitBirths(ssize_t v) { |
|
262 |
assert_proper_lock_protection(); |
|
263 |
_allocation_stats.set_splitBirths(v); |
|
264 |
} |
|
265 |
void increment_splitBirths() { |
|
266 |
assert_proper_lock_protection(); |
|
267 |
_allocation_stats.increment_splitBirths(); |
|
268 |
} |
|
269 |
||
270 |
ssize_t splitDeaths() const { |
|
271 |
return _allocation_stats.splitDeaths(); |
|
272 |
} |
|
273 |
void set_splitDeaths(ssize_t v) { |
|
274 |
assert_proper_lock_protection(); |
|
275 |
_allocation_stats.set_splitDeaths(v); |
|
276 |
} |
|
277 |
void increment_splitDeaths() { |
|
278 |
assert_proper_lock_protection(); |
|
279 |
_allocation_stats.increment_splitDeaths(); |
|
280 |
} |
|
281 |
||
282 |
NOT_PRODUCT( |
|
283 |
// For debugging. The "_returnedBytes" in all the lists are summed |
|
284 |
// and compared with the total number of bytes swept during a |
|
285 |
// collection. |
|
286 |
size_t returnedBytes() const { return _allocation_stats.returnedBytes(); } |
|
287 |
void set_returnedBytes(size_t v) { _allocation_stats.set_returnedBytes(v); } |
|
288 |
void increment_returnedBytes_by(size_t v) { |
|
289 |
_allocation_stats.set_returnedBytes(_allocation_stats.returnedBytes() + v); |
|
290 |
} |
|
291 |
) |
|
292 |
||
293 |
// Unlink head of list and return it. Returns NULL if |
|
294 |
// the list is empty. |
|
12507 | 295 |
Chunk* getChunkAtHead(); |
1 | 296 |
|
297 |
// Remove the first "n" or "count", whichever is smaller, chunks from the |
|
298 |
// list, setting "fl", which is required to be empty, to point to them. |
|
12507 | 299 |
void getFirstNChunksFromList(size_t n, FreeList<Chunk>* fl); |
1 | 300 |
|
301 |
// Unlink this chunk from it's free list |
|
12507 | 302 |
void removeChunk(Chunk* fc); |
1 | 303 |
|
304 |
// Add this chunk to this free list. |
|
12507 | 305 |
void returnChunkAtHead(Chunk* fc); |
306 |
void returnChunkAtTail(Chunk* fc); |
|
1 | 307 |
|
308 |
// Similar to returnChunk* but also records some diagnostic |
|
309 |
// information. |
|
12507 | 310 |
void returnChunkAtHead(Chunk* fc, bool record_return); |
311 |
void returnChunkAtTail(Chunk* fc, bool record_return); |
|
1 | 312 |
|
313 |
// Prepend "fl" (whose size is required to be the same as that of "this") |
|
314 |
// to the front of "this" list. |
|
12507 | 315 |
void prepend(FreeList<Chunk>* fl); |
1 | 316 |
|
317 |
// Verify that the chunk is in the list. |
|
318 |
// found. Return NULL if "fc" is not found. |
|
12507 | 319 |
bool verifyChunkInFreeLists(Chunk* fc) const; |
185
cda2a1eb4be5
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
1
diff
changeset
|
320 |
|
4574
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
670
diff
changeset
|
321 |
// Stats verification |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
670
diff
changeset
|
322 |
void verify_stats() const PRODUCT_RETURN; |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
670
diff
changeset
|
323 |
|
185
cda2a1eb4be5
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
1
diff
changeset
|
324 |
// Printing support |
cda2a1eb4be5
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
1
diff
changeset
|
325 |
static void print_labels_on(outputStream* st, const char* c); |
cda2a1eb4be5
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
1
diff
changeset
|
326 |
void print_on(outputStream* st, const char* c = NULL) const; |
1 | 327 |
}; |
7397 | 328 |
|
12507 | 329 |
#endif // SHARE_VM_MEMORY_FREELIST_HPP |