author | phh |
Sat, 30 Nov 2019 14:33:05 -0800 | |
changeset 59330 | 5b96c12f909d |
parent 59154 | 0c2e1808f800 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
49708
diff
changeset
|
2 |
* Copyright (c) 2001, 2019, 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 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
49708
diff
changeset
|
25 |
#ifndef SHARE_MEMORY_FREELIST_HPP |
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
49708
diff
changeset
|
26 |
#define SHARE_MEMORY_FREELIST_HPP |
7397 | 27 |
|
12507 | 28 |
// A class for maintaining a free list of Chunk's. The FreeList |
1 | 29 |
// maintains a the structure of the list (head, tail, etc.) plus |
30 |
// statistics for allocations from the list. The links between items |
|
31 |
// are not part of FreeList. The statistics are |
|
12507 | 32 |
// used to make decisions about coalescing Chunk's when they |
1 | 33 |
// are swept during collection. |
34 |
// |
|
35 |
// See the corresponding .cpp file for a description of the specifics |
|
36 |
// for that implementation. |
|
37 |
||
38 |
class Mutex; |
|
39 |
||
14123
944e56f74fba
7045397: NPG: Add freelists to class loader arenas.
jmasa
parents:
13963
diff
changeset
|
40 |
template <class Chunk_t> |
49364
601146c66cad
8173070: Remove ValueObj class for allocation subclassing for runtime code
coleenp
parents:
47216
diff
changeset
|
41 |
class FreeList { |
578
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
185
diff
changeset
|
42 |
friend class VMStructs; |
4574
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
670
diff
changeset
|
43 |
|
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
670
diff
changeset
|
44 |
private: |
14123
944e56f74fba
7045397: NPG: Add freelists to class loader arenas.
jmasa
parents:
13963
diff
changeset
|
45 |
Chunk_t* _head; // Head of list of free chunks |
944e56f74fba
7045397: NPG: Add freelists to class loader arenas.
jmasa
parents:
13963
diff
changeset
|
46 |
Chunk_t* _tail; // Tail of list of free chunks |
4574
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
670
diff
changeset
|
47 |
size_t _size; // Size in Heap words of each chunk |
1 | 48 |
ssize_t _count; // Number of entries in list |
49 |
||
14123
944e56f74fba
7045397: NPG: Add freelists to class loader arenas.
jmasa
parents:
13963
diff
changeset
|
50 |
protected: |
1 | 51 |
|
52 |
#ifdef ASSERT |
|
53 |
Mutex* _protecting_lock; |
|
27251
7d667f91ec8d
6979279: remove special-case code for ParallelGCThreads==0
mlarsson
parents:
22234
diff
changeset
|
54 |
void assert_proper_lock_protection_work() const; |
1 | 55 |
#endif |
56 |
||
57 |
// Asserts false if the protecting lock (if any) is not held. |
|
58 |
void assert_proper_lock_protection() const { |
|
27251
7d667f91ec8d
6979279: remove special-case code for ParallelGCThreads==0
mlarsson
parents:
22234
diff
changeset
|
59 |
DEBUG_ONLY(assert_proper_lock_protection_work()); |
1 | 60 |
} |
61 |
||
4574
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
670
diff
changeset
|
62 |
void increment_count() { |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
670
diff
changeset
|
63 |
_count++; |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
670
diff
changeset
|
64 |
} |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
670
diff
changeset
|
65 |
|
1 | 66 |
void decrement_count() { |
67 |
_count--; |
|
185
cda2a1eb4be5
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
1
diff
changeset
|
68 |
assert(_count >= 0, "Count should not be negative"); |
cda2a1eb4be5
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
1
diff
changeset
|
69 |
} |
1 | 70 |
|
71 |
public: |
|
72 |
// Constructor |
|
73 |
// Construct a list without any entries. |
|
74 |
FreeList(); |
|
75 |
||
14123
944e56f74fba
7045397: NPG: Add freelists to class loader arenas.
jmasa
parents:
13963
diff
changeset
|
76 |
// Do initialization |
944e56f74fba
7045397: NPG: Add freelists to class loader arenas.
jmasa
parents:
13963
diff
changeset
|
77 |
void initialize(); |
944e56f74fba
7045397: NPG: Add freelists to class loader arenas.
jmasa
parents:
13963
diff
changeset
|
78 |
|
944e56f74fba
7045397: NPG: Add freelists to class loader arenas.
jmasa
parents:
13963
diff
changeset
|
79 |
// Reset the head, tail, and count of a free list. |
944e56f74fba
7045397: NPG: Add freelists to class loader arenas.
jmasa
parents:
13963
diff
changeset
|
80 |
void reset(); |
1 | 81 |
|
82 |
// Declare the current free list to be protected by the given lock. |
|
83 |
#ifdef ASSERT |
|
14123
944e56f74fba
7045397: NPG: Add freelists to class loader arenas.
jmasa
parents:
13963
diff
changeset
|
84 |
Mutex* protecting_lock() const { return _protecting_lock; } |
944e56f74fba
7045397: NPG: Add freelists to class loader arenas.
jmasa
parents:
13963
diff
changeset
|
85 |
void set_protecting_lock(Mutex* v) { |
944e56f74fba
7045397: NPG: Add freelists to class loader arenas.
jmasa
parents:
13963
diff
changeset
|
86 |
_protecting_lock = v; |
1 | 87 |
} |
88 |
#endif |
|
89 |
||
90 |
// Accessors. |
|
14123
944e56f74fba
7045397: NPG: Add freelists to class loader arenas.
jmasa
parents:
13963
diff
changeset
|
91 |
Chunk_t* head() const { |
1 | 92 |
assert_proper_lock_protection(); |
93 |
return _head; |
|
94 |
} |
|
14123
944e56f74fba
7045397: NPG: Add freelists to class loader arenas.
jmasa
parents:
13963
diff
changeset
|
95 |
void set_head(Chunk_t* v) { |
1 | 96 |
assert_proper_lock_protection(); |
97 |
_head = v; |
|
98 |
assert(!_head || _head->size() == _size, "bad chunk size"); |
|
99 |
} |
|
100 |
// Set the head of the list and set the prev field of non-null |
|
101 |
// values to NULL. |
|
14123
944e56f74fba
7045397: NPG: Add freelists to class loader arenas.
jmasa
parents:
13963
diff
changeset
|
102 |
void link_head(Chunk_t* v); |
1 | 103 |
|
14123
944e56f74fba
7045397: NPG: Add freelists to class loader arenas.
jmasa
parents:
13963
diff
changeset
|
104 |
Chunk_t* tail() const { |
1 | 105 |
assert_proper_lock_protection(); |
106 |
return _tail; |
|
107 |
} |
|
14123
944e56f74fba
7045397: NPG: Add freelists to class loader arenas.
jmasa
parents:
13963
diff
changeset
|
108 |
void set_tail(Chunk_t* v) { |
1 | 109 |
assert_proper_lock_protection(); |
110 |
_tail = v; |
|
111 |
assert(!_tail || _tail->size() == _size, "bad chunk size"); |
|
112 |
} |
|
113 |
// Set the tail of the list and set the next field of non-null |
|
114 |
// values to NULL. |
|
14123
944e56f74fba
7045397: NPG: Add freelists to class loader arenas.
jmasa
parents:
13963
diff
changeset
|
115 |
void link_tail(Chunk_t* v) { |
1 | 116 |
assert_proper_lock_protection(); |
117 |
set_tail(v); |
|
118 |
if (v != NULL) { |
|
12509
6228e2085074
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
12507
diff
changeset
|
119 |
v->clear_next(); |
1 | 120 |
} |
121 |
} |
|
122 |
||
123 |
// No locking checks in read-accessors: lock-free reads (only) are benign. |
|
124 |
// Readers are expected to have the lock if they are doing work that |
|
125 |
// requires atomicity guarantees in sections of code. |
|
126 |
size_t size() const { |
|
127 |
return _size; |
|
128 |
} |
|
129 |
void set_size(size_t v) { |
|
130 |
assert_proper_lock_protection(); |
|
131 |
_size = v; |
|
132 |
} |
|
14123
944e56f74fba
7045397: NPG: Add freelists to class loader arenas.
jmasa
parents:
13963
diff
changeset
|
133 |
ssize_t count() const { return _count; } |
944e56f74fba
7045397: NPG: Add freelists to class loader arenas.
jmasa
parents:
13963
diff
changeset
|
134 |
void set_count(ssize_t v) { _count = v;} |
1 | 135 |
|
14123
944e56f74fba
7045397: NPG: Add freelists to class loader arenas.
jmasa
parents:
13963
diff
changeset
|
136 |
size_t get_better_size() { return size(); } |
1 | 137 |
|
14123
944e56f74fba
7045397: NPG: Add freelists to class loader arenas.
jmasa
parents:
13963
diff
changeset
|
138 |
size_t returned_bytes() const { ShouldNotReachHere(); return 0; } |
944e56f74fba
7045397: NPG: Add freelists to class loader arenas.
jmasa
parents:
13963
diff
changeset
|
139 |
void set_returned_bytes(size_t v) {} |
944e56f74fba
7045397: NPG: Add freelists to class loader arenas.
jmasa
parents:
13963
diff
changeset
|
140 |
void increment_returned_bytes_by(size_t v) {} |
1 | 141 |
|
142 |
// Unlink head of list and return it. Returns NULL if |
|
143 |
// the list is empty. |
|
14123
944e56f74fba
7045397: NPG: Add freelists to class loader arenas.
jmasa
parents:
13963
diff
changeset
|
144 |
Chunk_t* get_chunk_at_head(); |
1 | 145 |
|
146 |
// Remove the first "n" or "count", whichever is smaller, chunks from the |
|
147 |
// list, setting "fl", which is required to be empty, to point to them. |
|
14123
944e56f74fba
7045397: NPG: Add freelists to class loader arenas.
jmasa
parents:
13963
diff
changeset
|
148 |
void getFirstNChunksFromList(size_t n, FreeList<Chunk_t>* fl); |
1 | 149 |
|
150 |
// Unlink this chunk from it's free list |
|
14123
944e56f74fba
7045397: NPG: Add freelists to class loader arenas.
jmasa
parents:
13963
diff
changeset
|
151 |
void remove_chunk(Chunk_t* fc); |
1 | 152 |
|
153 |
// Add this chunk to this free list. |
|
14123
944e56f74fba
7045397: NPG: Add freelists to class loader arenas.
jmasa
parents:
13963
diff
changeset
|
154 |
void return_chunk_at_head(Chunk_t* fc); |
944e56f74fba
7045397: NPG: Add freelists to class loader arenas.
jmasa
parents:
13963
diff
changeset
|
155 |
void return_chunk_at_tail(Chunk_t* fc); |
1 | 156 |
|
157 |
// Similar to returnChunk* but also records some diagnostic |
|
158 |
// information. |
|
14123
944e56f74fba
7045397: NPG: Add freelists to class loader arenas.
jmasa
parents:
13963
diff
changeset
|
159 |
void return_chunk_at_head(Chunk_t* fc, bool record_return); |
944e56f74fba
7045397: NPG: Add freelists to class loader arenas.
jmasa
parents:
13963
diff
changeset
|
160 |
void return_chunk_at_tail(Chunk_t* fc, bool record_return); |
1 | 161 |
|
162 |
// Prepend "fl" (whose size is required to be the same as that of "this") |
|
163 |
// to the front of "this" list. |
|
14123
944e56f74fba
7045397: NPG: Add freelists to class loader arenas.
jmasa
parents:
13963
diff
changeset
|
164 |
void prepend(FreeList<Chunk_t>* fl); |
1 | 165 |
|
166 |
// Verify that the chunk is in the list. |
|
167 |
// found. Return NULL if "fc" is not found. |
|
14123
944e56f74fba
7045397: NPG: Add freelists to class loader arenas.
jmasa
parents:
13963
diff
changeset
|
168 |
bool verify_chunk_in_free_list(Chunk_t* fc) const; |
185
cda2a1eb4be5
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
1
diff
changeset
|
169 |
|
cda2a1eb4be5
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
1
diff
changeset
|
170 |
// Printing support |
cda2a1eb4be5
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
1
diff
changeset
|
171 |
static void print_labels_on(outputStream* st, const char* c); |
cda2a1eb4be5
6668743: CMS: Consolidate block statistics reporting code
ysr
parents:
1
diff
changeset
|
172 |
void print_on(outputStream* st, const char* c = NULL) const; |
1 | 173 |
}; |
7397 | 174 |
|
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
49708
diff
changeset
|
175 |
#endif // SHARE_MEMORY_FREELIST_HPP |