author | david |
Tue, 29 Sep 2015 11:02:08 +0200 | |
changeset 33105 | 294e48b4f704 |
parent 29580 | a67a581cfe11 |
child 34158 | 1f8d643b02d5 |
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" |
1 | 30 |
|
31 |
size_t CodeHeap::header_size() { |
|
32 |
return sizeof(HeapBlock); |
|
33 |
} |
|
34 |
||
35 |
||
36 |
// Implementation of Heap |
|
37 |
||
26796 | 38 |
CodeHeap::CodeHeap(const char* name, const int code_blob_type) |
39 |
: _code_blob_type(code_blob_type) { |
|
40 |
_name = name; |
|
1 | 41 |
_number_of_committed_segments = 0; |
42 |
_number_of_reserved_segments = 0; |
|
43 |
_segment_size = 0; |
|
44 |
_log2_segment_size = 0; |
|
45 |
_next_segment = 0; |
|
46 |
_freelist = NULL; |
|
17016
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
47 |
_freelist_segments = 0; |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
48 |
_freelist_length = 0; |
26796 | 49 |
_max_allocated_capacity = 0; |
50 |
_was_full = false; |
|
1 | 51 |
} |
52 |
||
53 |
||
54 |
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
|
55 |
assert( beg < _number_of_committed_segments, "interval begin out of bounds"); |
1 | 56 |
assert(beg < end && end <= _number_of_committed_segments, "interval end out of bounds"); |
57 |
// setup _segmap pointers for faster indexing |
|
58 |
address p = (address)_segmap.low() + beg; |
|
59 |
address q = (address)_segmap.low() + end; |
|
60 |
// initialize interval |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
61 |
while (p < q) *p++ = free_sentinel; |
1 | 62 |
} |
63 |
||
64 |
||
65 |
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
|
66 |
assert( beg < _number_of_committed_segments, "interval begin out of bounds"); |
1 | 67 |
assert(beg < end && end <= _number_of_committed_segments, "interval end out of bounds"); |
68 |
// setup _segmap pointers for faster indexing |
|
69 |
address p = (address)_segmap.low() + beg; |
|
70 |
address q = (address)_segmap.low() + end; |
|
71 |
// initialize interval |
|
72 |
int i = 0; |
|
73 |
while (p < q) { |
|
74 |
*p++ = i++; |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
75 |
if (i == free_sentinel) i = 1; |
1 | 76 |
} |
77 |
} |
|
78 |
||
79 |
||
80 |
static size_t align_to_page_size(size_t size) { |
|
81 |
const size_t alignment = (size_t)os::vm_page_size(); |
|
82 |
assert(is_power_of_2(alignment), "no kidding ???"); |
|
83 |
return (size + alignment - 1) & ~(alignment - 1); |
|
84 |
} |
|
85 |
||
86 |
||
87 |
void CodeHeap::on_code_mapping(char* base, size_t size) { |
|
88 |
#ifdef LINUX |
|
89 |
extern void linux_wrap_code(char* base, size_t size); |
|
90 |
linux_wrap_code(base, size); |
|
91 |
#endif |
|
92 |
} |
|
93 |
||
94 |
||
26796 | 95 |
bool CodeHeap::reserve(ReservedSpace rs, size_t committed_size, size_t segment_size) { |
96 |
assert(rs.size() >= committed_size, "reserved < committed"); |
|
1 | 97 |
assert(segment_size >= sizeof(FreeBlock), "segment size is too small"); |
98 |
assert(is_power_of_2(segment_size), "segment_size must be a power of 2"); |
|
99 |
||
100 |
_segment_size = segment_size; |
|
101 |
_log2_segment_size = exact_log2(segment_size); |
|
102 |
||
103 |
// Reserve and initialize space for _memory. |
|
26700
8107d0778244
8049864: TestParallelHeapSizeFlags fails with unexpected heap size
ehelin
parents:
25366
diff
changeset
|
104 |
size_t page_size = os::vm_page_size(); |
8107d0778244
8049864: TestParallelHeapSizeFlags fails with unexpected heap size
ehelin
parents:
25366
diff
changeset
|
105 |
if (os::can_execute_large_page_memory()) { |
8107d0778244
8049864: TestParallelHeapSizeFlags fails with unexpected heap size
ehelin
parents:
25366
diff
changeset
|
106 |
const size_t min_pages = 8; |
28631 | 107 |
page_size = MIN2(os::page_size_for_region_aligned(committed_size, min_pages), |
108 |
os::page_size_for_region_aligned(rs.size(), min_pages)); |
|
26700
8107d0778244
8049864: TestParallelHeapSizeFlags fails with unexpected heap size
ehelin
parents:
25366
diff
changeset
|
109 |
} |
8107d0778244
8049864: TestParallelHeapSizeFlags fails with unexpected heap size
ehelin
parents:
25366
diff
changeset
|
110 |
|
1 | 111 |
const size_t granularity = os::vm_allocation_granularity(); |
112 |
const size_t c_size = align_size_up(committed_size, page_size); |
|
113 |
||
26796 | 114 |
os::trace_page_sizes(_name, committed_size, rs.size(), page_size, |
1 | 115 |
rs.base(), rs.size()); |
116 |
if (!_memory.initialize(rs, c_size)) { |
|
117 |
return false; |
|
118 |
} |
|
119 |
||
120 |
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
|
121 |
_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
|
122 |
_number_of_reserved_segments = size_to_segments(_memory.reserved_size()); |
1 | 123 |
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
|
124 |
const size_t reserved_segments_alignment = MAX2((size_t)os::vm_page_size(), granularity); |
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
17016
diff
changeset
|
125 |
const size_t reserved_segments_size = align_size_up(_number_of_reserved_segments, reserved_segments_alignment); |
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
17016
diff
changeset
|
126 |
const size_t committed_segments_size = align_to_page_size(_number_of_committed_segments); |
1 | 127 |
|
128 |
// reserve space for _segmap |
|
19319
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
17016
diff
changeset
|
129 |
if (!_segmap.initialize(reserved_segments_size, committed_segments_size)) { |
1 | 130 |
return false; |
131 |
} |
|
13195 | 132 |
|
133 |
MemTracker::record_virtual_memory_type((address)_segmap.low_boundary(), mtCode); |
|
134 |
||
1 | 135 |
assert(_segmap.committed_size() >= (size_t) _number_of_committed_segments, "could not commit enough space for segment map"); |
136 |
assert(_segmap.reserved_size() >= (size_t) _number_of_reserved_segments , "could not reserve enough space for segment map"); |
|
137 |
assert(_segmap.reserved_size() >= _segmap.committed_size() , "just checking"); |
|
138 |
||
139 |
// initialize remaining instance variables |
|
140 |
clear(); |
|
141 |
return true; |
|
142 |
} |
|
143 |
||
144 |
||
145 |
bool CodeHeap::expand_by(size_t size) { |
|
146 |
// expand _memory space |
|
147 |
size_t dm = align_to_page_size(_memory.committed_size() + size) - _memory.committed_size(); |
|
148 |
if (dm > 0) { |
|
149 |
char* base = _memory.low() + _memory.committed_size(); |
|
150 |
if (!_memory.expand_by(dm)) return false; |
|
151 |
on_code_mapping(base, dm); |
|
152 |
size_t i = _number_of_committed_segments; |
|
17016
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
153 |
_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
|
154 |
assert(_number_of_reserved_segments == size_to_segments(_memory.reserved_size()), "number of reserved segments should not change"); |
1 | 155 |
assert(_number_of_reserved_segments >= _number_of_committed_segments, "just checking"); |
156 |
// expand _segmap space |
|
157 |
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
|
158 |
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
|
159 |
return false; |
1 | 160 |
} |
161 |
assert(_segmap.committed_size() >= (size_t) _number_of_committed_segments, "just checking"); |
|
162 |
// initialize additional segmap entries |
|
163 |
mark_segmap_as_free(i, _number_of_committed_segments); |
|
164 |
} |
|
165 |
return true; |
|
166 |
} |
|
167 |
||
168 |
void CodeHeap::clear() { |
|
169 |
_next_segment = 0; |
|
170 |
mark_segmap_as_free(0, _number_of_committed_segments); |
|
171 |
} |
|
172 |
||
173 |
||
27420
04e6f914cce1
8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents:
26809
diff
changeset
|
174 |
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
|
175 |
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
|
176 |
assert(segments_to_size(number_of_segments) >= sizeof(FreeBlock), "not enough room for FreeList"); |
1 | 177 |
|
22551 | 178 |
// 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
|
179 |
NOT_PRODUCT(verify()); |
27420
04e6f914cce1
8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents:
26809
diff
changeset
|
180 |
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
|
181 |
NOT_PRODUCT(verify()); |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
182 |
|
1 | 183 |
if (block != NULL) { |
17016
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
184 |
assert(block->length() >= number_of_segments && block->length() < number_of_segments + CodeCacheMinBlockLength, "sanity check"); |
1 | 185 |
assert(!block->free(), "must be marked free"); |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
186 |
DEBUG_ONLY(memset((void*)block->allocated_space(), badCodeHeapNewVal, instance_size)); |
26796 | 187 |
_max_allocated_capacity = MAX2(_max_allocated_capacity, allocated_capacity()); |
1 | 188 |
return block->allocated_space(); |
189 |
} |
|
190 |
||
17016
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
191 |
// 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
|
192 |
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
|
193 |
|
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
194 |
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
|
195 |
mark_segmap_as_used(_next_segment, _next_segment + number_of_segments); |
1 | 196 |
HeapBlock* b = block_at(_next_segment); |
17016
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
197 |
b->initialize(number_of_segments); |
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
198 |
_next_segment += number_of_segments; |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
199 |
DEBUG_ONLY(memset((void *)b->allocated_space(), badCodeHeapNewVal, instance_size)); |
26796 | 200 |
_max_allocated_capacity = MAX2(_max_allocated_capacity, allocated_capacity()); |
1 | 201 |
return b->allocated_space(); |
202 |
} else { |
|
203 |
return NULL; |
|
204 |
} |
|
205 |
} |
|
206 |
||
207 |
||
208 |
void CodeHeap::deallocate(void* p) { |
|
209 |
assert(p == find_start(p), "illegal deallocation"); |
|
210 |
// Find start of HeapBlock |
|
211 |
HeapBlock* b = (((HeapBlock *)p) - 1); |
|
212 |
assert(b->allocated_space() == p, "sanity check"); |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
213 |
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
|
214 |
segments_to_size(b->length()) - sizeof(HeapBlock))); |
1 | 215 |
add_to_freelist(b); |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
216 |
NOT_PRODUCT(verify()); |
1 | 217 |
} |
218 |
||
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
219 |
/** |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
220 |
* 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
|
221 |
* 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
|
222 |
* 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
|
223 |
* 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
|
224 |
* 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
|
225 |
* 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
|
226 |
* 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
|
227 |
* |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
228 |
* code cache segmap |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
229 |
* ----------- --------- |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
230 |
* seg 1 | nm 1 | -> | 0 | |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
231 |
* seg 2 | nm 1 | -> | 1 | |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
232 |
* ... | nm 1 | -> | .. | |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
233 |
* seg m | nm 2 | -> | 0 | |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
234 |
* 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
|
235 |
* ... | nm 2 | -> | 2 | |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
236 |
* ... | nm 2 | -> | .. | |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
237 |
* ... | nm 2 | -> | 0xFE | |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
238 |
* 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
|
239 |
* ... | nm 2 | -> | | |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
240 |
* |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
241 |
* 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
|
242 |
* 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
|
243 |
* 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
|
244 |
* 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
|
245 |
* 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
|
246 |
* 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
|
247 |
* 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
|
248 |
*/ |
1 | 249 |
void* CodeHeap::find_start(void* p) const { |
250 |
if (!contains(p)) { |
|
251 |
return NULL; |
|
252 |
} |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
253 |
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
|
254 |
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
|
255 |
if (is_segment_unused(seg_map[seg_idx])) { |
1 | 256 |
return NULL; |
257 |
} |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
258 |
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
|
259 |
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
|
260 |
} |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
261 |
|
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
262 |
HeapBlock* h = block_at(seg_idx); |
1 | 263 |
if (h->free()) { |
264 |
return NULL; |
|
265 |
} |
|
266 |
return h->allocated_space(); |
|
267 |
} |
|
268 |
||
269 |
||
270 |
size_t CodeHeap::alignment_unit() const { |
|
271 |
// this will be a power of two |
|
272 |
return _segment_size; |
|
273 |
} |
|
274 |
||
275 |
||
276 |
size_t CodeHeap::alignment_offset() const { |
|
277 |
// The lowest address in any allocated block will be |
|
278 |
// equal to alignment_offset (mod alignment_unit). |
|
279 |
return sizeof(HeapBlock) & (_segment_size - 1); |
|
280 |
} |
|
281 |
||
28493 | 282 |
// Returns the current block if available and used. |
283 |
// If not, it returns the subsequent block (if available), NULL otherwise. |
|
284 |
// Free blocks are merged, therefore there is at most one free block |
|
285 |
// between two used ones. As a result, the subsequent block (if available) is |
|
286 |
// guaranteed to be used. |
|
287 |
void* CodeHeap::next_used(HeapBlock* b) const { |
|
1 | 288 |
if (b != NULL && b->free()) b = next_block(b); |
289 |
assert(b == NULL || !b->free(), "must be in use or at end of heap"); |
|
290 |
return (b == NULL) ? NULL : b->allocated_space(); |
|
291 |
} |
|
292 |
||
293 |
// Returns the first used HeapBlock |
|
294 |
HeapBlock* CodeHeap::first_block() const { |
|
295 |
if (_next_segment > 0) |
|
296 |
return block_at(0); |
|
297 |
return NULL; |
|
298 |
} |
|
299 |
||
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
300 |
HeapBlock* CodeHeap::block_start(void* q) const { |
1 | 301 |
HeapBlock* b = (HeapBlock*)find_start(q); |
302 |
if (b == NULL) return NULL; |
|
303 |
return b - 1; |
|
304 |
} |
|
305 |
||
306 |
// Returns the next Heap block an offset into one |
|
307 |
HeapBlock* CodeHeap::next_block(HeapBlock *b) const { |
|
308 |
if (b == NULL) return NULL; |
|
309 |
size_t i = segment_for(b) + b->length(); |
|
310 |
if (i < _next_segment) |
|
311 |
return block_at(i); |
|
312 |
return NULL; |
|
313 |
} |
|
314 |
||
315 |
||
316 |
// Returns current capacity |
|
317 |
size_t CodeHeap::capacity() const { |
|
318 |
return _memory.committed_size(); |
|
319 |
} |
|
320 |
||
321 |
size_t CodeHeap::max_capacity() const { |
|
322 |
return _memory.reserved_size(); |
|
323 |
} |
|
324 |
||
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
325 |
int CodeHeap::allocated_segments() const { |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
326 |
return (int)_next_segment; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
327 |
} |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
328 |
|
1 | 329 |
size_t CodeHeap::allocated_capacity() const { |
17016
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
330 |
// size of used heap - size on freelist |
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
331 |
return segments_to_size(_next_segment - _freelist_segments); |
1 | 332 |
} |
333 |
||
17016
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
334 |
// Returns size of the unallocated heap block |
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
335 |
size_t CodeHeap::heap_unallocated_capacity() const { |
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
336 |
// Total number of segments - number currently used |
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
337 |
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
|
338 |
} |
12998f95a334
7008325: CodeCache exhausted on sparc starting from hs20b04
kvn
parents:
7397
diff
changeset
|
339 |
|
1 | 340 |
// Free list management |
341 |
||
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
342 |
FreeBlock* CodeHeap::following_block(FreeBlock *b) { |
1 | 343 |
return (FreeBlock*)(((address)b) + _segment_size * b->length()); |
344 |
} |
|
345 |
||
346 |
// Inserts block b after a |
|
347 |
void CodeHeap::insert_after(FreeBlock* a, FreeBlock* b) { |
|
348 |
assert(a != NULL && b != NULL, "must be real pointers"); |
|
349 |
||
350 |
// Link b into the list after a |
|
351 |
b->set_link(a->link()); |
|
352 |
a->set_link(b); |
|
353 |
||
354 |
// See if we can merge blocks |
|
355 |
merge_right(b); // Try to make b bigger |
|
356 |
merge_right(a); // Try to make a include b |
|
357 |
} |
|
358 |
||
359 |
// 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
|
360 |
bool CodeHeap::merge_right(FreeBlock* a) { |
1 | 361 |
assert(a->free(), "must be a free block"); |
362 |
if (following_block(a) == a->link()) { |
|
363 |
assert(a->link() != NULL && a->link()->free(), "must be free too"); |
|
364 |
// Update block a to include the following block |
|
365 |
a->set_length(a->length() + a->link()->length()); |
|
366 |
a->set_link(a->link()->link()); |
|
367 |
// Update find_start map |
|
368 |
size_t beg = segment_for(a); |
|
369 |
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
|
370 |
_freelist_length--; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
371 |
return true; |
1 | 372 |
} |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
373 |
return false; |
1 | 374 |
} |
375 |
||
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
376 |
|
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
377 |
void CodeHeap::add_to_freelist(HeapBlock* a) { |
1 | 378 |
FreeBlock* b = (FreeBlock*)a; |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
379 |
_freelist_length++; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
380 |
|
1 | 381 |
assert(b != _freelist, "cannot be removed twice"); |
382 |
||
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
383 |
|
1 | 384 |
// 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
|
385 |
_freelist_segments += b->length(); |
1 | 386 |
b->set_free(); |
387 |
||
388 |
// First element in list? |
|
389 |
if (_freelist == NULL) { |
|
390 |
_freelist = b; |
|
391 |
b->set_link(NULL); |
|
392 |
return; |
|
393 |
} |
|
394 |
||
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
395 |
// 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
|
396 |
// 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
|
397 |
// 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
|
398 |
if (b < _freelist) { |
1 | 399 |
// Insert first in list |
400 |
b->set_link(_freelist); |
|
401 |
_freelist = b; |
|
402 |
merge_right(_freelist); |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
403 |
return; |
1 | 404 |
} |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
405 |
|
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
406 |
// 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
|
407 |
// is sorted by increasing addresses |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
408 |
FreeBlock* prev = _freelist; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
409 |
FreeBlock* cur = _freelist->link(); |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
410 |
while(cur != NULL && cur < b) { |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
411 |
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
|
412 |
prev = cur; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
413 |
cur = cur->link(); |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
414 |
} |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
415 |
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
|
416 |
insert_after(prev, b); |
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 |
* 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
|
421 |
* @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
|
422 |
*/ |
27420
04e6f914cce1
8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents:
26809
diff
changeset
|
423 |
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
|
424 |
FreeBlock* found_block = NULL; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
425 |
FreeBlock* found_prev = NULL; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
426 |
size_t found_length = 0; |
1 | 427 |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
428 |
FreeBlock* prev = NULL; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
429 |
FreeBlock* cur = _freelist; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
430 |
|
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
431 |
// Search for first block that fits |
1 | 432 |
while(cur != NULL) { |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
433 |
if (cur->length() >= length) { |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
434 |
// 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
|
435 |
found_block = cur; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
436 |
found_prev = prev; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
437 |
found_length = found_block->length(); |
17016
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
438 |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
439 |
break; |
1 | 440 |
} |
441 |
// Next element in list |
|
442 |
prev = cur; |
|
443 |
cur = cur->link(); |
|
444 |
} |
|
445 |
||
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
446 |
if (found_block == NULL) { |
1 | 447 |
// None found |
448 |
return NULL; |
|
449 |
} |
|
450 |
||
451 |
// Exact (or at least good enough) fit. Remove from list. |
|
452 |
// 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
|
453 |
if (found_length - length < CodeCacheMinBlockLength) { |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
454 |
_freelist_length--; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
455 |
length = found_length; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
456 |
if (found_prev == NULL) { |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
457 |
assert(_freelist == found_block, "sanity check"); |
1 | 458 |
_freelist = _freelist->link(); |
459 |
} else { |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
460 |
assert((found_prev->link() == found_block), "sanity check"); |
1 | 461 |
// Unmap element |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
462 |
found_prev->set_link(found_block->link()); |
1 | 463 |
} |
464 |
} else { |
|
465 |
// Truncate block and return a pointer to the following block |
|
466 |
// 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
|
467 |
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
|
468 |
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
|
469 |
|
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
470 |
size_t beg = segment_for(found_block); |
1 | 471 |
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
|
472 |
found_block->set_length(length); |
1 | 473 |
} |
474 |
||
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
475 |
found_block->set_used(); |
17016
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
476 |
_freelist_segments -= length; |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
477 |
return found_block; |
1 | 478 |
} |
479 |
||
480 |
//---------------------------------------------------------------------------- |
|
481 |
// Non-product code |
|
482 |
||
483 |
#ifndef PRODUCT |
|
484 |
||
485 |
void CodeHeap::print() { |
|
486 |
tty->print_cr("The Heap"); |
|
487 |
} |
|
488 |
||
489 |
void CodeHeap::verify() { |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
490 |
if (VerifyCodeCache) { |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
491 |
size_t len = 0; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
492 |
int count = 0; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
493 |
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
|
494 |
len += b->length(); |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
495 |
count++; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
496 |
// 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
|
497 |
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
|
498 |
} |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
499 |
// 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
|
500 |
assert(len == _freelist_segments, "wrong freelist"); |
1 | 501 |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
502 |
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
|
503 |
if (h->free()) count--; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
504 |
} |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
505 |
// 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
|
506 |
// 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
|
507 |
assert(count == 0, "missing free blocks"); |
1 | 508 |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
509 |
// 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
|
510 |
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
|
511 |
if (count > free_block_threshold) { |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
512 |
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
|
513 |
// Double the warning limit |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
514 |
free_block_threshold *= 2; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
515 |
} |
1 | 516 |
} |
517 |
} |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
518 |
|
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
519 |
#endif |