author | dholmes |
Sat, 23 Jun 2018 01:32:41 -0400 | |
changeset 50735 | 2f2af62dfac7 |
parent 47688 | 3d1e3786d66e |
child 54943 | 6cbb5c2255e3 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
29580
a67a581cfe11
8073315: Enable gcc -Wtype-limits and fix upcoming issues.
goetz
parents:
28636
diff
changeset
|
2 |
* Copyright (c) 1997, 2015, 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:
4493
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4493
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:
4493
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "memory/heap.hpp" |
|
27 |
#include "oops/oop.inline.hpp" |
|
28 |
#include "runtime/os.hpp" |
|
13195 | 29 |
#include "services/memTracker.hpp" |
46625 | 30 |
#include "utilities/align.hpp" |
1 | 31 |
|
32 |
size_t CodeHeap::header_size() { |
|
33 |
return sizeof(HeapBlock); |
|
34 |
} |
|
35 |
||
36 |
||
37 |
// Implementation of Heap |
|
38 |
||
26796 | 39 |
CodeHeap::CodeHeap(const char* name, const int code_blob_type) |
40 |
: _code_blob_type(code_blob_type) { |
|
41 |
_name = name; |
|
1 | 42 |
_number_of_committed_segments = 0; |
43 |
_number_of_reserved_segments = 0; |
|
44 |
_segment_size = 0; |
|
45 |
_log2_segment_size = 0; |
|
46 |
_next_segment = 0; |
|
47 |
_freelist = NULL; |
|
17016
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
48 |
_freelist_segments = 0; |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
49 |
_freelist_length = 0; |
26796 | 50 |
_max_allocated_capacity = 0; |
34158
1f8d643b02d5
8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents:
29580
diff
changeset
|
51 |
_blob_count = 0; |
1f8d643b02d5
8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents:
29580
diff
changeset
|
52 |
_nmethod_count = 0; |
1f8d643b02d5
8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents:
29580
diff
changeset
|
53 |
_adapter_count = 0; |
1f8d643b02d5
8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents:
29580
diff
changeset
|
54 |
_full_count = 0; |
1 | 55 |
} |
56 |
||
57 |
||
58 |
void CodeHeap::mark_segmap_as_free(size_t beg, size_t end) { |
|
29580
a67a581cfe11
8073315: Enable gcc -Wtype-limits and fix upcoming issues.
goetz
parents:
28636
diff
changeset
|
59 |
assert( beg < _number_of_committed_segments, "interval begin out of bounds"); |
1 | 60 |
assert(beg < end && end <= _number_of_committed_segments, "interval end out of bounds"); |
61 |
// setup _segmap pointers for faster indexing |
|
62 |
address p = (address)_segmap.low() + beg; |
|
63 |
address q = (address)_segmap.low() + end; |
|
64 |
// initialize interval |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
65 |
while (p < q) *p++ = free_sentinel; |
1 | 66 |
} |
67 |
||
68 |
||
69 |
void CodeHeap::mark_segmap_as_used(size_t beg, size_t end) { |
|
29580
a67a581cfe11
8073315: Enable gcc -Wtype-limits and fix upcoming issues.
goetz
parents:
28636
diff
changeset
|
70 |
assert( beg < _number_of_committed_segments, "interval begin out of bounds"); |
1 | 71 |
assert(beg < end && end <= _number_of_committed_segments, "interval end out of bounds"); |
72 |
// setup _segmap pointers for faster indexing |
|
73 |
address p = (address)_segmap.low() + beg; |
|
74 |
address q = (address)_segmap.low() + end; |
|
75 |
// initialize interval |
|
76 |
int i = 0; |
|
77 |
while (p < q) { |
|
78 |
*p++ = i++; |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
79 |
if (i == free_sentinel) i = 1; |
1 | 80 |
} |
81 |
} |
|
82 |
||
83 |
||
84 |
static size_t align_to_page_size(size_t size) { |
|
85 |
const size_t alignment = (size_t)os::vm_page_size(); |
|
86 |
assert(is_power_of_2(alignment), "no kidding ???"); |
|
87 |
return (size + alignment - 1) & ~(alignment - 1); |
|
88 |
} |
|
89 |
||
90 |
||
91 |
void CodeHeap::on_code_mapping(char* base, size_t size) { |
|
92 |
#ifdef LINUX |
|
93 |
extern void linux_wrap_code(char* base, size_t size); |
|
94 |
linux_wrap_code(base, size); |
|
95 |
#endif |
|
96 |
} |
|
97 |
||
98 |
||
26796 | 99 |
bool CodeHeap::reserve(ReservedSpace rs, size_t committed_size, size_t segment_size) { |
100 |
assert(rs.size() >= committed_size, "reserved < committed"); |
|
1 | 101 |
assert(segment_size >= sizeof(FreeBlock), "segment size is too small"); |
102 |
assert(is_power_of_2(segment_size), "segment_size must be a power of 2"); |
|
103 |
||
104 |
_segment_size = segment_size; |
|
105 |
_log2_segment_size = exact_log2(segment_size); |
|
106 |
||
107 |
// Reserve and initialize space for _memory. |
|
26700
8107d0778244
8049864: TestParallelHeapSizeFlags fails with unexpected heap size
ehelin
parents:
25366
diff
changeset
|
108 |
size_t page_size = os::vm_page_size(); |
8107d0778244
8049864: TestParallelHeapSizeFlags fails with unexpected heap size
ehelin
parents:
25366
diff
changeset
|
109 |
if (os::can_execute_large_page_memory()) { |
8107d0778244
8049864: TestParallelHeapSizeFlags fails with unexpected heap size
ehelin
parents:
25366
diff
changeset
|
110 |
const size_t min_pages = 8; |
28631 | 111 |
page_size = MIN2(os::page_size_for_region_aligned(committed_size, min_pages), |
112 |
os::page_size_for_region_aligned(rs.size(), min_pages)); |
|
26700
8107d0778244
8049864: TestParallelHeapSizeFlags fails with unexpected heap size
ehelin
parents:
25366
diff
changeset
|
113 |
} |
8107d0778244
8049864: TestParallelHeapSizeFlags fails with unexpected heap size
ehelin
parents:
25366
diff
changeset
|
114 |
|
1 | 115 |
const size_t granularity = os::vm_allocation_granularity(); |
46619
a3919f5e8d2b
8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents:
43945
diff
changeset
|
116 |
const size_t c_size = align_up(committed_size, page_size); |
1 | 117 |
|
26796 | 118 |
os::trace_page_sizes(_name, committed_size, rs.size(), page_size, |
1 | 119 |
rs.base(), rs.size()); |
120 |
if (!_memory.initialize(rs, c_size)) { |
|
121 |
return false; |
|
122 |
} |
|
123 |
||
124 |
on_code_mapping(_memory.low(), _memory.committed_size()); |
|
17016
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
125 |
_number_of_committed_segments = size_to_segments(_memory.committed_size()); |
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
126 |
_number_of_reserved_segments = size_to_segments(_memory.reserved_size()); |
1 | 127 |
assert(_number_of_reserved_segments >= _number_of_committed_segments, "just checking"); |
19319
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
17016
diff
changeset
|
128 |
const size_t reserved_segments_alignment = MAX2((size_t)os::vm_page_size(), granularity); |
46619
a3919f5e8d2b
8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents:
43945
diff
changeset
|
129 |
const size_t reserved_segments_size = align_up(_number_of_reserved_segments, reserved_segments_alignment); |
19319
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
17016
diff
changeset
|
130 |
const size_t committed_segments_size = align_to_page_size(_number_of_committed_segments); |
1 | 131 |
|
132 |
// reserve space for _segmap |
|
19319
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
17016
diff
changeset
|
133 |
if (!_segmap.initialize(reserved_segments_size, committed_segments_size)) { |
1 | 134 |
return false; |
135 |
} |
|
13195 | 136 |
|
137 |
MemTracker::record_virtual_memory_type((address)_segmap.low_boundary(), mtCode); |
|
138 |
||
1 | 139 |
assert(_segmap.committed_size() >= (size_t) _number_of_committed_segments, "could not commit enough space for segment map"); |
140 |
assert(_segmap.reserved_size() >= (size_t) _number_of_reserved_segments , "could not reserve enough space for segment map"); |
|
141 |
assert(_segmap.reserved_size() >= _segmap.committed_size() , "just checking"); |
|
142 |
||
143 |
// initialize remaining instance variables |
|
144 |
clear(); |
|
145 |
return true; |
|
146 |
} |
|
147 |
||
148 |
||
149 |
bool CodeHeap::expand_by(size_t size) { |
|
150 |
// expand _memory space |
|
151 |
size_t dm = align_to_page_size(_memory.committed_size() + size) - _memory.committed_size(); |
|
152 |
if (dm > 0) { |
|
35590
39a11b5f4283
8065334: CodeHeap expansion fails although there is uncommitted memory
thartmann
parents:
34158
diff
changeset
|
153 |
// Use at least the available uncommitted space if 'size' is larger |
39a11b5f4283
8065334: CodeHeap expansion fails although there is uncommitted memory
thartmann
parents:
34158
diff
changeset
|
154 |
if (_memory.uncommitted_size() != 0 && dm > _memory.uncommitted_size()) { |
39a11b5f4283
8065334: CodeHeap expansion fails although there is uncommitted memory
thartmann
parents:
34158
diff
changeset
|
155 |
dm = _memory.uncommitted_size(); |
39a11b5f4283
8065334: CodeHeap expansion fails although there is uncommitted memory
thartmann
parents:
34158
diff
changeset
|
156 |
} |
1 | 157 |
char* base = _memory.low() + _memory.committed_size(); |
158 |
if (!_memory.expand_by(dm)) return false; |
|
159 |
on_code_mapping(base, dm); |
|
160 |
size_t i = _number_of_committed_segments; |
|
17016
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
161 |
_number_of_committed_segments = size_to_segments(_memory.committed_size()); |
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
162 |
assert(_number_of_reserved_segments == size_to_segments(_memory.reserved_size()), "number of reserved segments should not change"); |
1 | 163 |
assert(_number_of_reserved_segments >= _number_of_committed_segments, "just checking"); |
164 |
// expand _segmap space |
|
165 |
size_t ds = align_to_page_size(_number_of_committed_segments) - _segmap.committed_size(); |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
166 |
if ((ds > 0) && !_segmap.expand_by(ds)) { |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
167 |
return false; |
1 | 168 |
} |
169 |
assert(_segmap.committed_size() >= (size_t) _number_of_committed_segments, "just checking"); |
|
170 |
// initialize additional segmap entries |
|
171 |
mark_segmap_as_free(i, _number_of_committed_segments); |
|
172 |
} |
|
173 |
return true; |
|
174 |
} |
|
175 |
||
176 |
void CodeHeap::clear() { |
|
177 |
_next_segment = 0; |
|
178 |
mark_segmap_as_free(0, _number_of_committed_segments); |
|
179 |
} |
|
180 |
||
181 |
||
27420
04e6f914cce1
8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents:
26809
diff
changeset
|
182 |
void* CodeHeap::allocate(size_t instance_size) { |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
183 |
size_t number_of_segments = size_to_segments(instance_size + header_size()); |
17016
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
184 |
assert(segments_to_size(number_of_segments) >= sizeof(FreeBlock), "not enough room for FreeList"); |
1 | 185 |
|
22551 | 186 |
// First check if we can satisfy request from freelist |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
187 |
NOT_PRODUCT(verify()); |
27420
04e6f914cce1
8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents:
26809
diff
changeset
|
188 |
HeapBlock* block = search_freelist(number_of_segments); |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
189 |
NOT_PRODUCT(verify()); |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
190 |
|
1 | 191 |
if (block != NULL) { |
17016
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
192 |
assert(block->length() >= number_of_segments && block->length() < number_of_segments + CodeCacheMinBlockLength, "sanity check"); |
1 | 193 |
assert(!block->free(), "must be marked free"); |
43945
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
42650
diff
changeset
|
194 |
guarantee((char*) block >= _memory.low_boundary() && (char*) block < _memory.high(), |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
42650
diff
changeset
|
195 |
"The newly allocated block " INTPTR_FORMAT " is not within the heap " |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
42650
diff
changeset
|
196 |
"starting with " INTPTR_FORMAT " and ending with " INTPTR_FORMAT, |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
42650
diff
changeset
|
197 |
p2i(block), p2i(_memory.low_boundary()), p2i(_memory.high())); |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
198 |
DEBUG_ONLY(memset((void*)block->allocated_space(), badCodeHeapNewVal, instance_size)); |
26796 | 199 |
_max_allocated_capacity = MAX2(_max_allocated_capacity, allocated_capacity()); |
34158
1f8d643b02d5
8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents:
29580
diff
changeset
|
200 |
_blob_count++; |
1 | 201 |
return block->allocated_space(); |
202 |
} |
|
203 |
||
17016
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
204 |
// Ensure minimum size for allocation to the heap. |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
205 |
number_of_segments = MAX2((int)CodeCacheMinBlockLength, (int)number_of_segments); |
17016
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
206 |
|
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
207 |
if (_next_segment + number_of_segments <= _number_of_committed_segments) { |
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
208 |
mark_segmap_as_used(_next_segment, _next_segment + number_of_segments); |
1 | 209 |
HeapBlock* b = block_at(_next_segment); |
17016
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
210 |
b->initialize(number_of_segments); |
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
211 |
_next_segment += number_of_segments; |
43945
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
42650
diff
changeset
|
212 |
guarantee((char*) b >= _memory.low_boundary() && (char*) block < _memory.high(), |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
42650
diff
changeset
|
213 |
"The newly allocated block " INTPTR_FORMAT " is not within the heap " |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
42650
diff
changeset
|
214 |
"starting with " INTPTR_FORMAT " and ending with " INTPTR_FORMAT, |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
42650
diff
changeset
|
215 |
p2i(b), p2i(_memory.low_boundary()), p2i(_memory.high())); |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
216 |
DEBUG_ONLY(memset((void *)b->allocated_space(), badCodeHeapNewVal, instance_size)); |
26796 | 217 |
_max_allocated_capacity = MAX2(_max_allocated_capacity, allocated_capacity()); |
34158
1f8d643b02d5
8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents:
29580
diff
changeset
|
218 |
_blob_count++; |
1 | 219 |
return b->allocated_space(); |
220 |
} else { |
|
221 |
return NULL; |
|
222 |
} |
|
223 |
} |
|
224 |
||
47688 | 225 |
void CodeHeap::deallocate_tail(void* p, size_t used_size) { |
226 |
assert(p == find_start(p), "illegal deallocation"); |
|
227 |
// Find start of HeapBlock |
|
228 |
HeapBlock* b = (((HeapBlock *)p) - 1); |
|
229 |
assert(b->allocated_space() == p, "sanity check"); |
|
230 |
size_t used_number_of_segments = size_to_segments(used_size + header_size()); |
|
231 |
size_t actual_number_of_segments = b->length(); |
|
232 |
guarantee(used_number_of_segments <= actual_number_of_segments, "Must be!"); |
|
233 |
guarantee(b == block_at(_next_segment - actual_number_of_segments), "Intermediate allocation!"); |
|
234 |
size_t number_of_segments_to_deallocate = actual_number_of_segments - used_number_of_segments; |
|
235 |
_next_segment -= number_of_segments_to_deallocate; |
|
236 |
mark_segmap_as_free(_next_segment, _next_segment + number_of_segments_to_deallocate); |
|
237 |
b->initialize(used_number_of_segments); |
|
238 |
} |
|
1 | 239 |
|
240 |
void CodeHeap::deallocate(void* p) { |
|
241 |
assert(p == find_start(p), "illegal deallocation"); |
|
242 |
// Find start of HeapBlock |
|
243 |
HeapBlock* b = (((HeapBlock *)p) - 1); |
|
244 |
assert(b->allocated_space() == p, "sanity check"); |
|
43945
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
42650
diff
changeset
|
245 |
guarantee((char*) b >= _memory.low_boundary() && (char*) b < _memory.high(), |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
42650
diff
changeset
|
246 |
"The block to be deallocated " INTPTR_FORMAT " is not within the heap " |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
42650
diff
changeset
|
247 |
"starting with " INTPTR_FORMAT " and ending with " INTPTR_FORMAT, |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
42650
diff
changeset
|
248 |
p2i(b), p2i(_memory.low_boundary()), p2i(_memory.high())); |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
249 |
DEBUG_ONLY(memset((void *)b->allocated_space(), badCodeHeapFreeVal, |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
250 |
segments_to_size(b->length()) - sizeof(HeapBlock))); |
1 | 251 |
add_to_freelist(b); |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
252 |
NOT_PRODUCT(verify()); |
1 | 253 |
} |
254 |
||
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
255 |
/** |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
256 |
* Uses segment map to find the the start (header) of a nmethod. This works as follows: |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
257 |
* The memory of the code cache is divided into 'segments'. The size of a segment is |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
258 |
* determined by -XX:CodeCacheSegmentSize=XX. Allocation in the code cache can only |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
259 |
* happen at segment boundaries. A pointer in the code cache can be mapped to a segment |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
260 |
* by calling segment_for(addr). Each time memory is requested from the code cache, |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
261 |
* the segmap is updated accordingly. See the following example, which illustrates the |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
262 |
* state of code cache and the segment map: (seg -> segment, nm ->nmethod) |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
263 |
* |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
264 |
* code cache segmap |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
265 |
* ----------- --------- |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
266 |
* seg 1 | nm 1 | -> | 0 | |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
267 |
* seg 2 | nm 1 | -> | 1 | |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
268 |
* ... | nm 1 | -> | .. | |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
269 |
* seg m | nm 2 | -> | 0 | |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
270 |
* seg m+1 | nm 2 | -> | 1 | |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
271 |
* ... | nm 2 | -> | 2 | |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
272 |
* ... | nm 2 | -> | .. | |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
273 |
* ... | nm 2 | -> | 0xFE | |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
274 |
* seg m+n | nm 2 | -> | 1 | |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
275 |
* ... | nm 2 | -> | | |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
276 |
* |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
277 |
* A value of '0' in the segmap indicates that this segment contains the beginning of |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
278 |
* an nmethod. Let's walk through a simple example: If we want to find the start of |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
279 |
* an nmethod that falls into seg 2, we read the value of the segmap[2]. The value |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
280 |
* is an offset that points to the segment that contains the start of the nmethod. |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
281 |
* Another example: If we want to get the start of nm 2, and we happen to get a pointer |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
282 |
* that points to seg m+n, we first read seg[n+m], which returns '1'. So we have to |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
283 |
* do one more read of the segmap[m+n-1] to finally get the segment header. |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
284 |
*/ |
1 | 285 |
void* CodeHeap::find_start(void* p) const { |
286 |
if (!contains(p)) { |
|
287 |
return NULL; |
|
288 |
} |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
289 |
size_t seg_idx = segment_for(p); |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
290 |
address seg_map = (address)_segmap.low(); |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
291 |
if (is_segment_unused(seg_map[seg_idx])) { |
1 | 292 |
return NULL; |
293 |
} |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
294 |
while (seg_map[seg_idx] > 0) { |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
295 |
seg_idx -= (int)seg_map[seg_idx]; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
296 |
} |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
297 |
|
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
298 |
HeapBlock* h = block_at(seg_idx); |
1 | 299 |
if (h->free()) { |
300 |
return NULL; |
|
301 |
} |
|
302 |
return h->allocated_space(); |
|
303 |
} |
|
304 |
||
42650 | 305 |
CodeBlob* CodeHeap::find_blob_unsafe(void* start) const { |
306 |
CodeBlob* result = (CodeBlob*)CodeHeap::find_start(start); |
|
307 |
if (result != NULL && result->blob_contains((address)start)) { |
|
308 |
return result; |
|
309 |
} |
|
310 |
return NULL; |
|
311 |
} |
|
1 | 312 |
|
313 |
size_t CodeHeap::alignment_unit() const { |
|
314 |
// this will be a power of two |
|
315 |
return _segment_size; |
|
316 |
} |
|
317 |
||
318 |
||
319 |
size_t CodeHeap::alignment_offset() const { |
|
320 |
// The lowest address in any allocated block will be |
|
321 |
// equal to alignment_offset (mod alignment_unit). |
|
322 |
return sizeof(HeapBlock) & (_segment_size - 1); |
|
323 |
} |
|
324 |
||
28493 | 325 |
// Returns the current block if available and used. |
326 |
// If not, it returns the subsequent block (if available), NULL otherwise. |
|
327 |
// Free blocks are merged, therefore there is at most one free block |
|
328 |
// between two used ones. As a result, the subsequent block (if available) is |
|
329 |
// guaranteed to be used. |
|
330 |
void* CodeHeap::next_used(HeapBlock* b) const { |
|
1 | 331 |
if (b != NULL && b->free()) b = next_block(b); |
332 |
assert(b == NULL || !b->free(), "must be in use or at end of heap"); |
|
333 |
return (b == NULL) ? NULL : b->allocated_space(); |
|
334 |
} |
|
335 |
||
336 |
// Returns the first used HeapBlock |
|
337 |
HeapBlock* CodeHeap::first_block() const { |
|
338 |
if (_next_segment > 0) |
|
339 |
return block_at(0); |
|
340 |
return NULL; |
|
341 |
} |
|
342 |
||
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
343 |
HeapBlock* CodeHeap::block_start(void* q) const { |
1 | 344 |
HeapBlock* b = (HeapBlock*)find_start(q); |
345 |
if (b == NULL) return NULL; |
|
346 |
return b - 1; |
|
347 |
} |
|
348 |
||
349 |
// Returns the next Heap block an offset into one |
|
350 |
HeapBlock* CodeHeap::next_block(HeapBlock *b) const { |
|
351 |
if (b == NULL) return NULL; |
|
352 |
size_t i = segment_for(b) + b->length(); |
|
353 |
if (i < _next_segment) |
|
354 |
return block_at(i); |
|
355 |
return NULL; |
|
356 |
} |
|
357 |
||
358 |
||
359 |
// Returns current capacity |
|
360 |
size_t CodeHeap::capacity() const { |
|
361 |
return _memory.committed_size(); |
|
362 |
} |
|
363 |
||
364 |
size_t CodeHeap::max_capacity() const { |
|
365 |
return _memory.reserved_size(); |
|
366 |
} |
|
367 |
||
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
368 |
int CodeHeap::allocated_segments() const { |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
369 |
return (int)_next_segment; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
370 |
} |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
371 |
|
1 | 372 |
size_t CodeHeap::allocated_capacity() const { |
17016
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
373 |
// size of used heap - size on freelist |
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
374 |
return segments_to_size(_next_segment - _freelist_segments); |
1 | 375 |
} |
376 |
||
17016
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
377 |
// Returns size of the unallocated heap block |
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
378 |
size_t CodeHeap::heap_unallocated_capacity() const { |
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
379 |
// Total number of segments - number currently used |
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
380 |
return segments_to_size(_number_of_reserved_segments - _next_segment); |
7715
12998f95a334
7008325: CodeCache exhausted on sparc starting from hs20b04
kvn
parents:
7397
diff
changeset
|
381 |
} |
12998f95a334
7008325: CodeCache exhausted on sparc starting from hs20b04
kvn
parents:
7397
diff
changeset
|
382 |
|
1 | 383 |
// Free list management |
384 |
||
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
385 |
FreeBlock* CodeHeap::following_block(FreeBlock *b) { |
1 | 386 |
return (FreeBlock*)(((address)b) + _segment_size * b->length()); |
387 |
} |
|
388 |
||
389 |
// Inserts block b after a |
|
390 |
void CodeHeap::insert_after(FreeBlock* a, FreeBlock* b) { |
|
391 |
assert(a != NULL && b != NULL, "must be real pointers"); |
|
392 |
||
393 |
// Link b into the list after a |
|
394 |
b->set_link(a->link()); |
|
395 |
a->set_link(b); |
|
396 |
||
397 |
// See if we can merge blocks |
|
398 |
merge_right(b); // Try to make b bigger |
|
399 |
merge_right(a); // Try to make a include b |
|
400 |
} |
|
401 |
||
402 |
// Try to merge this block with the following block |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
403 |
bool CodeHeap::merge_right(FreeBlock* a) { |
1 | 404 |
assert(a->free(), "must be a free block"); |
405 |
if (following_block(a) == a->link()) { |
|
406 |
assert(a->link() != NULL && a->link()->free(), "must be free too"); |
|
407 |
// Update block a to include the following block |
|
408 |
a->set_length(a->length() + a->link()->length()); |
|
409 |
a->set_link(a->link()->link()); |
|
410 |
// Update find_start map |
|
411 |
size_t beg = segment_for(a); |
|
412 |
mark_segmap_as_used(beg, beg + a->length()); |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
413 |
_freelist_length--; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
414 |
return true; |
1 | 415 |
} |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
416 |
return false; |
1 | 417 |
} |
418 |
||
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
419 |
|
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
420 |
void CodeHeap::add_to_freelist(HeapBlock* a) { |
1 | 421 |
FreeBlock* b = (FreeBlock*)a; |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
422 |
_freelist_length++; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
423 |
|
1 | 424 |
assert(b != _freelist, "cannot be removed twice"); |
425 |
||
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
426 |
|
1 | 427 |
// Mark as free and update free space count |
17016
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
428 |
_freelist_segments += b->length(); |
1 | 429 |
b->set_free(); |
430 |
||
431 |
// First element in list? |
|
432 |
if (_freelist == NULL) { |
|
433 |
_freelist = b; |
|
434 |
b->set_link(NULL); |
|
435 |
return; |
|
436 |
} |
|
437 |
||
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
438 |
// Since the freelist is ordered (smaller addresses -> larger addresses) and the |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
439 |
// element we want to insert into the freelist has a smaller address than the first |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
440 |
// element, we can simply add 'b' as the first element and we are done. |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
441 |
if (b < _freelist) { |
1 | 442 |
// Insert first in list |
443 |
b->set_link(_freelist); |
|
444 |
_freelist = b; |
|
445 |
merge_right(_freelist); |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
446 |
return; |
1 | 447 |
} |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
448 |
|
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
449 |
// Scan for right place to put into list. List |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
450 |
// is sorted by increasing addresses |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
451 |
FreeBlock* prev = _freelist; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
452 |
FreeBlock* cur = _freelist->link(); |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
453 |
while(cur != NULL && cur < b) { |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
454 |
assert(prev < cur, "Freelist must be ordered"); |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
455 |
prev = cur; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
456 |
cur = cur->link(); |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
457 |
} |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
458 |
assert((prev < b) && (cur == NULL || b < cur), "free-list must be ordered"); |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
459 |
insert_after(prev, b); |
1 | 460 |
} |
461 |
||
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
462 |
/** |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
463 |
* Search freelist for an entry on the list with the best fit. |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
464 |
* @return NULL, if no one was found |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
465 |
*/ |
27420
04e6f914cce1
8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents:
26809
diff
changeset
|
466 |
FreeBlock* CodeHeap::search_freelist(size_t length) { |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
467 |
FreeBlock* found_block = NULL; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
468 |
FreeBlock* found_prev = NULL; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
469 |
size_t found_length = 0; |
1 | 470 |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
471 |
FreeBlock* prev = NULL; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
472 |
FreeBlock* cur = _freelist; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
473 |
|
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
474 |
// Search for first block that fits |
1 | 475 |
while(cur != NULL) { |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
476 |
if (cur->length() >= length) { |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
477 |
// Remember block, its previous element, and its length |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
478 |
found_block = cur; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
479 |
found_prev = prev; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
480 |
found_length = found_block->length(); |
17016
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
481 |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
482 |
break; |
1 | 483 |
} |
484 |
// Next element in list |
|
485 |
prev = cur; |
|
486 |
cur = cur->link(); |
|
487 |
} |
|
488 |
||
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
489 |
if (found_block == NULL) { |
1 | 490 |
// None found |
491 |
return NULL; |
|
492 |
} |
|
493 |
||
494 |
// Exact (or at least good enough) fit. Remove from list. |
|
495 |
// Don't leave anything on the freelist smaller than CodeCacheMinBlockLength. |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
496 |
if (found_length - length < CodeCacheMinBlockLength) { |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
497 |
_freelist_length--; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
498 |
length = found_length; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
499 |
if (found_prev == NULL) { |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
500 |
assert(_freelist == found_block, "sanity check"); |
1 | 501 |
_freelist = _freelist->link(); |
502 |
} else { |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
503 |
assert((found_prev->link() == found_block), "sanity check"); |
1 | 504 |
// Unmap element |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
505 |
found_prev->set_link(found_block->link()); |
1 | 506 |
} |
507 |
} else { |
|
508 |
// Truncate block and return a pointer to the following block |
|
509 |
// Set used bit and length on new block |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
510 |
found_block->set_length(found_length - length); |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
511 |
found_block = following_block(found_block); |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
512 |
|
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
513 |
size_t beg = segment_for(found_block); |
1 | 514 |
mark_segmap_as_used(beg, beg + length); |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
515 |
found_block->set_length(length); |
1 | 516 |
} |
517 |
||
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
518 |
found_block->set_used(); |
17016
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
519 |
_freelist_segments -= length; |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
520 |
return found_block; |
1 | 521 |
} |
522 |
||
523 |
//---------------------------------------------------------------------------- |
|
524 |
// Non-product code |
|
525 |
||
526 |
#ifndef PRODUCT |
|
527 |
||
528 |
void CodeHeap::print() { |
|
529 |
tty->print_cr("The Heap"); |
|
530 |
} |
|
531 |
||
532 |
void CodeHeap::verify() { |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
533 |
if (VerifyCodeCache) { |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
534 |
size_t len = 0; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
535 |
int count = 0; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
536 |
for(FreeBlock* b = _freelist; b != NULL; b = b->link()) { |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
537 |
len += b->length(); |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
538 |
count++; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
539 |
// Check if we have merged all free blocks |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
540 |
assert(merge_right(b) == false, "Missed merging opportunity"); |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
541 |
} |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
542 |
// Verify that freelist contains the right amount of free space |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
543 |
assert(len == _freelist_segments, "wrong freelist"); |
1 | 544 |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
545 |
for(HeapBlock* h = first_block(); h != NULL; h = next_block(h)) { |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
546 |
if (h->free()) count--; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
547 |
} |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
548 |
// Verify that the freelist contains the same number of blocks |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
549 |
// than free blocks found on the full list. |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
550 |
assert(count == 0, "missing free blocks"); |
1 | 551 |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
552 |
// Verify that the number of free blocks is not out of hand. |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
553 |
static int free_block_threshold = 10000; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
554 |
if (count > free_block_threshold) { |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
555 |
warning("CodeHeap: # of free blocks > %d", free_block_threshold); |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
556 |
// Double the warning limit |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
557 |
free_block_threshold *= 2; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
558 |
} |
1 | 559 |
} |
560 |
} |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
561 |
|
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
562 |
#endif |