author | lucy |
Wed, 20 Nov 2019 09:12:07 +0100 | |
changeset 59145 | ea044aedc2b6 |
parent 54943 | 6cbb5c2255e3 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
54943 | 2 |
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
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; |
|
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
48 |
_last_insert_point = NULL; |
17016
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
49 |
_freelist_segments = 0; |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
50 |
_freelist_length = 0; |
26796 | 51 |
_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
|
52 |
_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
|
53 |
_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
|
54 |
_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
|
55 |
_full_count = 0; |
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
56 |
_fragmentation_count = 0; |
1 | 57 |
} |
58 |
||
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
59 |
// Dummy initialization of template array. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
60 |
char CodeHeap::segmap_template[] = {0}; |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
61 |
|
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
62 |
// This template array is used to (re)initialize the segmap, |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
63 |
// replacing a 1..254 loop. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
64 |
void CodeHeap::init_segmap_template() { |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
65 |
assert(free_sentinel == 255, "Segment map logic changed!"); |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
66 |
for (int i = 0; i <= free_sentinel; i++) { |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
67 |
segmap_template[i] = i; |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
68 |
} |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
69 |
} |
1 | 70 |
|
54943 | 71 |
// The segmap is marked free for that part of the heap |
72 |
// which has not been allocated yet (beyond _next_segment). |
|
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
73 |
// The range of segments to be marked is given by [beg..end). |
54943 | 74 |
// "Allocated" space in this context means there exists a |
75 |
// HeapBlock or a FreeBlock describing this space. |
|
76 |
// This method takes segment map indices as range boundaries |
|
1 | 77 |
void CodeHeap::mark_segmap_as_free(size_t beg, size_t end) { |
54943 | 78 |
assert( beg < _number_of_committed_segments, "interval begin out of bounds"); |
79 |
assert(beg < end && end <= _number_of_committed_segments, "interval end out of bounds"); |
|
80 |
// Don't do unpredictable things in PRODUCT build |
|
81 |
if (beg < end) { |
|
82 |
// setup _segmap pointers for faster indexing |
|
83 |
address p = (address)_segmap.low() + beg; |
|
84 |
address q = (address)_segmap.low() + end; |
|
85 |
// initialize interval |
|
86 |
memset(p, free_sentinel, q-p); |
|
87 |
} |
|
1 | 88 |
} |
89 |
||
54943 | 90 |
// Don't get confused here. |
91 |
// All existing blocks, no matter if they are used() or free(), |
|
92 |
// have their segmap marked as used. This allows to find the |
|
93 |
// block header (HeapBlock or FreeBlock) for any pointer |
|
94 |
// within the allocated range (upper limit: _next_segment). |
|
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
95 |
// This method takes segment map indices as range boundaries. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
96 |
// The range of segments to be marked is given by [beg..end). |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
97 |
void CodeHeap::mark_segmap_as_used(size_t beg, size_t end, bool is_FreeBlock_join) { |
54943 | 98 |
assert( beg < _number_of_committed_segments, "interval begin out of bounds"); |
99 |
assert(beg < end && end <= _number_of_committed_segments, "interval end out of bounds"); |
|
100 |
// Don't do unpredictable things in PRODUCT build |
|
101 |
if (beg < end) { |
|
102 |
// setup _segmap pointers for faster indexing |
|
103 |
address p = (address)_segmap.low() + beg; |
|
104 |
address q = (address)_segmap.low() + end; |
|
105 |
// initialize interval |
|
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
106 |
// If we are joining two free blocks, the segmap range for each |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
107 |
// block is consistent. To create a consistent segmap range for |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
108 |
// the blocks combined, we have three choices: |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
109 |
// 1 - Do a full init from beg to end. Not very efficient because |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
110 |
// the segmap range for the left block is potentially initialized |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
111 |
// over and over again. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
112 |
// 2 - Carry over the last segmap element value of the left block |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
113 |
// and initialize the segmap range of the right block starting |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
114 |
// with that value. Saves initializing the left block's segmap |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
115 |
// over and over again. Very efficient if FreeBlocks mostly |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
116 |
// are appended to the right. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
117 |
// 3 - Take full advantage of the segmap being almost correct with |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
118 |
// the two blocks combined. Lets assume the left block consists |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
119 |
// of m segments. The the segmap looks like |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
120 |
// ... (m-2) (m-1) (m) 0 1 2 3 ... |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
121 |
// By substituting the '0' by '1', we create a valid, but |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
122 |
// suboptimal, segmap range covering the two blocks combined. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
123 |
// We introduced an extra hop for the find_block_for() iteration. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
124 |
// |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
125 |
// When this method is called with is_FreeBlock_join == true, the |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
126 |
// segmap index beg must select the first segment of the right block. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
127 |
// Otherwise, it has to select the first segment of the left block. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
128 |
// Variant 3 is used for all FreeBlock joins. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
129 |
if (is_FreeBlock_join && (beg > 0)) { |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
130 |
#ifndef PRODUCT |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
131 |
FreeBlock* pBlock = (FreeBlock*)block_at(beg); |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
132 |
assert(beg + pBlock->length() == end, "Internal error: (%d - %d) != %d", (unsigned int)end, (unsigned int)beg, (unsigned int)(pBlock->length())); |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
133 |
assert(*p == 0, "Begin index does not select a block start segment, *p = %2.2x", *p); |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
134 |
#endif |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
135 |
// If possible, extend the previous hop. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
136 |
if (*(p-1) < (free_sentinel-1)) { |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
137 |
*p = *(p-1) + 1; |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
138 |
} else { |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
139 |
*p = 1; |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
140 |
} |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
141 |
if (_fragmentation_count++ >= fragmentation_limit) { |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
142 |
defrag_segmap(true); |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
143 |
_fragmentation_count = 0; |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
144 |
} |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
145 |
} else { |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
146 |
size_t n_bulk = free_sentinel-1; // bulk processing uses template indices [1..254]. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
147 |
// Use shortcut for blocks <= 255 segments. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
148 |
// Special case bulk processing: [0..254]. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
149 |
if ((end - beg) <= n_bulk) { |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
150 |
memcpy(p, &segmap_template[0], end - beg); |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
151 |
} else { |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
152 |
*p++ = 0; // block header marker |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
153 |
while (p < q) { |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
154 |
if ((p+n_bulk) <= q) { |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
155 |
memcpy(p, &segmap_template[1], n_bulk); |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
156 |
p += n_bulk; |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
157 |
} else { |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
158 |
memcpy(p, &segmap_template[1], q-p); |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
159 |
p = q; |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
160 |
} |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
161 |
} |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
162 |
} |
54943 | 163 |
} |
1 | 164 |
} |
165 |
} |
|
166 |
||
54943 | 167 |
void CodeHeap::invalidate(size_t beg, size_t end, size_t hdr_size) { |
168 |
#ifndef PRODUCT |
|
169 |
// Fill the given range with some bad value. |
|
170 |
// length is expected to be in segment_size units. |
|
171 |
// This prevents inadvertent execution of code leftover from previous use. |
|
172 |
char* p = low_boundary() + segments_to_size(beg) + hdr_size; |
|
173 |
memset(p, badCodeHeapNewVal, segments_to_size(end-beg)-hdr_size); |
|
174 |
#endif |
|
175 |
} |
|
176 |
||
177 |
void CodeHeap::clear(size_t beg, size_t end) { |
|
178 |
mark_segmap_as_free(beg, end); |
|
179 |
invalidate(beg, end, 0); |
|
180 |
} |
|
181 |
||
182 |
void CodeHeap::clear() { |
|
183 |
_next_segment = 0; |
|
184 |
clear(_next_segment, _number_of_committed_segments); |
|
185 |
} |
|
186 |
||
1 | 187 |
|
188 |
static size_t align_to_page_size(size_t size) { |
|
189 |
const size_t alignment = (size_t)os::vm_page_size(); |
|
190 |
assert(is_power_of_2(alignment), "no kidding ???"); |
|
191 |
return (size + alignment - 1) & ~(alignment - 1); |
|
192 |
} |
|
193 |
||
194 |
||
195 |
void CodeHeap::on_code_mapping(char* base, size_t size) { |
|
196 |
#ifdef LINUX |
|
197 |
extern void linux_wrap_code(char* base, size_t size); |
|
198 |
linux_wrap_code(base, size); |
|
199 |
#endif |
|
200 |
} |
|
201 |
||
202 |
||
26796 | 203 |
bool CodeHeap::reserve(ReservedSpace rs, size_t committed_size, size_t segment_size) { |
204 |
assert(rs.size() >= committed_size, "reserved < committed"); |
|
1 | 205 |
assert(segment_size >= sizeof(FreeBlock), "segment size is too small"); |
206 |
assert(is_power_of_2(segment_size), "segment_size must be a power of 2"); |
|
207 |
||
208 |
_segment_size = segment_size; |
|
209 |
_log2_segment_size = exact_log2(segment_size); |
|
210 |
||
211 |
// Reserve and initialize space for _memory. |
|
26700
8107d0778244
8049864: TestParallelHeapSizeFlags fails with unexpected heap size
ehelin
parents:
25366
diff
changeset
|
212 |
size_t page_size = os::vm_page_size(); |
8107d0778244
8049864: TestParallelHeapSizeFlags fails with unexpected heap size
ehelin
parents:
25366
diff
changeset
|
213 |
if (os::can_execute_large_page_memory()) { |
8107d0778244
8049864: TestParallelHeapSizeFlags fails with unexpected heap size
ehelin
parents:
25366
diff
changeset
|
214 |
const size_t min_pages = 8; |
28631 | 215 |
page_size = MIN2(os::page_size_for_region_aligned(committed_size, min_pages), |
216 |
os::page_size_for_region_aligned(rs.size(), min_pages)); |
|
26700
8107d0778244
8049864: TestParallelHeapSizeFlags fails with unexpected heap size
ehelin
parents:
25366
diff
changeset
|
217 |
} |
8107d0778244
8049864: TestParallelHeapSizeFlags fails with unexpected heap size
ehelin
parents:
25366
diff
changeset
|
218 |
|
1 | 219 |
const size_t granularity = os::vm_allocation_granularity(); |
46619
a3919f5e8d2b
8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents:
43945
diff
changeset
|
220 |
const size_t c_size = align_up(committed_size, page_size); |
1 | 221 |
|
26796 | 222 |
os::trace_page_sizes(_name, committed_size, rs.size(), page_size, |
1 | 223 |
rs.base(), rs.size()); |
224 |
if (!_memory.initialize(rs, c_size)) { |
|
225 |
return false; |
|
226 |
} |
|
227 |
||
228 |
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
|
229 |
_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
|
230 |
_number_of_reserved_segments = size_to_segments(_memory.reserved_size()); |
1 | 231 |
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
|
232 |
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
|
233 |
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
|
234 |
const size_t committed_segments_size = align_to_page_size(_number_of_committed_segments); |
1 | 235 |
|
236 |
// reserve space for _segmap |
|
19319
0ad35be0733a
8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents:
17016
diff
changeset
|
237 |
if (!_segmap.initialize(reserved_segments_size, committed_segments_size)) { |
1 | 238 |
return false; |
239 |
} |
|
13195 | 240 |
|
241 |
MemTracker::record_virtual_memory_type((address)_segmap.low_boundary(), mtCode); |
|
242 |
||
1 | 243 |
assert(_segmap.committed_size() >= (size_t) _number_of_committed_segments, "could not commit enough space for segment map"); |
244 |
assert(_segmap.reserved_size() >= (size_t) _number_of_reserved_segments , "could not reserve enough space for segment map"); |
|
245 |
assert(_segmap.reserved_size() >= _segmap.committed_size() , "just checking"); |
|
246 |
||
54943 | 247 |
// initialize remaining instance variables, heap memory and segmap |
1 | 248 |
clear(); |
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
249 |
init_segmap_template(); |
1 | 250 |
return true; |
251 |
} |
|
252 |
||
253 |
||
254 |
bool CodeHeap::expand_by(size_t size) { |
|
255 |
// expand _memory space |
|
256 |
size_t dm = align_to_page_size(_memory.committed_size() + size) - _memory.committed_size(); |
|
257 |
if (dm > 0) { |
|
35590
39a11b5f4283
8065334: CodeHeap expansion fails although there is uncommitted memory
thartmann
parents:
34158
diff
changeset
|
258 |
// 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
|
259 |
if (_memory.uncommitted_size() != 0 && dm > _memory.uncommitted_size()) { |
39a11b5f4283
8065334: CodeHeap expansion fails although there is uncommitted memory
thartmann
parents:
34158
diff
changeset
|
260 |
dm = _memory.uncommitted_size(); |
39a11b5f4283
8065334: CodeHeap expansion fails although there is uncommitted memory
thartmann
parents:
34158
diff
changeset
|
261 |
} |
1 | 262 |
char* base = _memory.low() + _memory.committed_size(); |
263 |
if (!_memory.expand_by(dm)) return false; |
|
264 |
on_code_mapping(base, dm); |
|
265 |
size_t i = _number_of_committed_segments; |
|
17016
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
266 |
_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
|
267 |
assert(_number_of_reserved_segments == size_to_segments(_memory.reserved_size()), "number of reserved segments should not change"); |
1 | 268 |
assert(_number_of_reserved_segments >= _number_of_committed_segments, "just checking"); |
269 |
// expand _segmap space |
|
270 |
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
|
271 |
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
|
272 |
return false; |
1 | 273 |
} |
274 |
assert(_segmap.committed_size() >= (size_t) _number_of_committed_segments, "just checking"); |
|
54943 | 275 |
// initialize additional space (heap memory and segmap) |
276 |
clear(i, _number_of_committed_segments); |
|
1 | 277 |
} |
278 |
return true; |
|
279 |
} |
|
280 |
||
281 |
||
27420
04e6f914cce1
8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents:
26809
diff
changeset
|
282 |
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
|
283 |
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
|
284 |
assert(segments_to_size(number_of_segments) >= sizeof(FreeBlock), "not enough room for FreeList"); |
1 | 285 |
|
22551 | 286 |
// 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
|
287 |
NOT_PRODUCT(verify()); |
27420
04e6f914cce1
8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents:
26809
diff
changeset
|
288 |
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
|
289 |
NOT_PRODUCT(verify()); |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
290 |
|
1 | 291 |
if (block != NULL) { |
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
292 |
assert(!block->free(), "must not be marked free"); |
43945
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
42650
diff
changeset
|
293 |
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
|
294 |
"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
|
295 |
"starting with " INTPTR_FORMAT " and ending with " INTPTR_FORMAT, |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
42650
diff
changeset
|
296 |
p2i(block), p2i(_memory.low_boundary()), p2i(_memory.high())); |
26796 | 297 |
_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
|
298 |
_blob_count++; |
1 | 299 |
return block->allocated_space(); |
300 |
} |
|
301 |
||
17016
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
302 |
// 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
|
303 |
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
|
304 |
|
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
305 |
if (_next_segment + number_of_segments <= _number_of_committed_segments) { |
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
306 |
mark_segmap_as_used(_next_segment, _next_segment + number_of_segments, false); |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
307 |
block = block_at(_next_segment); |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
308 |
block->initialize(number_of_segments); |
17016
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
309 |
_next_segment += number_of_segments; |
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
310 |
guarantee((char*) block >= _memory.low_boundary() && (char*) block < _memory.high(), |
43945
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
42650
diff
changeset
|
311 |
"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
|
312 |
"starting with " INTPTR_FORMAT " and ending with " INTPTR_FORMAT, |
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
313 |
p2i(block), p2i(_memory.low_boundary()), p2i(_memory.high())); |
26796 | 314 |
_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
|
315 |
_blob_count++; |
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
316 |
return block->allocated_space(); |
1 | 317 |
} else { |
318 |
return NULL; |
|
319 |
} |
|
320 |
} |
|
321 |
||
54943 | 322 |
// Split the given block into two at the given segment. |
323 |
// This is helpful when a block was allocated too large |
|
324 |
// to trim off the unused space at the end (interpreter). |
|
325 |
// It also helps with splitting a large free block during allocation. |
|
326 |
// Usage state (used or free) must be set by caller since |
|
327 |
// we don't know if the resulting blocks will be used or free. |
|
328 |
// split_at is the segment number (relative to segment_for(b)) |
|
329 |
// where the split happens. The segment with relative |
|
330 |
// number split_at is the first segment of the split-off block. |
|
331 |
HeapBlock* CodeHeap::split_block(HeapBlock *b, size_t split_at) { |
|
332 |
if (b == NULL) return NULL; |
|
333 |
// After the split, both blocks must have a size of at least CodeCacheMinBlockLength |
|
334 |
assert((split_at >= CodeCacheMinBlockLength) && (split_at + CodeCacheMinBlockLength <= b->length()), |
|
335 |
"split position(%d) out of range [0..%d]", (int)split_at, (int)b->length()); |
|
336 |
size_t split_segment = segment_for(b) + split_at; |
|
337 |
size_t b_size = b->length(); |
|
338 |
size_t newb_size = b_size - split_at; |
|
339 |
||
340 |
HeapBlock* newb = block_at(split_segment); |
|
341 |
newb->set_length(newb_size); |
|
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
342 |
mark_segmap_as_used(segment_for(newb), segment_for(newb) + newb_size, false); |
54943 | 343 |
b->set_length(split_at); |
344 |
return newb; |
|
345 |
} |
|
346 |
||
47688 | 347 |
void CodeHeap::deallocate_tail(void* p, size_t used_size) { |
348 |
assert(p == find_start(p), "illegal deallocation"); |
|
349 |
// Find start of HeapBlock |
|
350 |
HeapBlock* b = (((HeapBlock *)p) - 1); |
|
351 |
assert(b->allocated_space() == p, "sanity check"); |
|
54943 | 352 |
|
47688 | 353 |
size_t actual_number_of_segments = b->length(); |
54943 | 354 |
size_t used_number_of_segments = size_to_segments(used_size + header_size()); |
355 |
size_t unused_number_of_segments = actual_number_of_segments - used_number_of_segments; |
|
47688 | 356 |
guarantee(used_number_of_segments <= actual_number_of_segments, "Must be!"); |
54943 | 357 |
|
358 |
HeapBlock* f = split_block(b, used_number_of_segments); |
|
359 |
add_to_freelist(f); |
|
360 |
NOT_PRODUCT(verify()); |
|
47688 | 361 |
} |
1 | 362 |
|
363 |
void CodeHeap::deallocate(void* p) { |
|
364 |
assert(p == find_start(p), "illegal deallocation"); |
|
365 |
// Find start of HeapBlock |
|
366 |
HeapBlock* b = (((HeapBlock *)p) - 1); |
|
367 |
assert(b->allocated_space() == p, "sanity check"); |
|
43945
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
42650
diff
changeset
|
368 |
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
|
369 |
"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
|
370 |
"starting with " INTPTR_FORMAT " and ending with " INTPTR_FORMAT, |
e7f2e49d2274
8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents:
42650
diff
changeset
|
371 |
p2i(b), p2i(_memory.low_boundary()), p2i(_memory.high())); |
1 | 372 |
add_to_freelist(b); |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
373 |
NOT_PRODUCT(verify()); |
1 | 374 |
} |
375 |
||
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
376 |
/** |
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
377 |
* The segment map is used to quickly find the the start (header) of a |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
378 |
* code block (e.g. nmethod) when only a pointer to a location inside the |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
379 |
* code block is known. This works as follows: |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
380 |
* - The storage reserved for the code heap is divided into 'segments'. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
381 |
* - The size of a segment is determined by -XX:CodeCacheSegmentSize=<#bytes>. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
382 |
* - The size must be a power of two to allow the use of shift operations |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
383 |
* to quickly convert between segment index and segment address. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
384 |
* - Segment start addresses should be aligned to be multiples of CodeCacheSegmentSize. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
385 |
* - It seems beneficial for CodeCacheSegmentSize to be equal to os::page_size(). |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
386 |
* - Allocation in the code cache can only happen at segment start addresses. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
387 |
* - Allocation in the code cache is in units of CodeCacheSegmentSize. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
388 |
* - A pointer in the code cache can be mapped to a segment by calling |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
389 |
* segment_for(addr). |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
390 |
* - The segment map is a byte array where array element [i] is related |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
391 |
* to the i-th segment in the code heap. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
392 |
* - Each time memory is allocated/deallocated from the code cache, |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
393 |
* the segment map is updated accordingly. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
394 |
* Note: deallocation does not cause the memory to become "free", as |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
395 |
* indicated by the segment map state "free_sentinel". Deallocation |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
396 |
* just changes the block state from "used" to "free". |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
397 |
* - Elements of the segment map (byte) array are interpreted |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
398 |
* as unsigned integer. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
399 |
* - Element values normally identify an offset backwards (in segment |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
400 |
* size units) from the associated segment towards the start of |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
401 |
* the block. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
402 |
* - Some values have a special meaning: |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
403 |
* 0 - This segment is the start of a block (HeapBlock or FreeBlock). |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
404 |
* 255 - The free_sentinel value. This is a free segment, i.e. it is |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
405 |
* not yet allocated and thus does not belong to any block. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
406 |
* - The value of the current element has to be subtracted from the |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
407 |
* current index to get closer to the start. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
408 |
* - If the value of the then current element is zero, the block start |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
409 |
* segment is found and iteration stops. Otherwise, start over with the |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
410 |
* previous step. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
411 |
* |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
412 |
* The following example illustrates a possible state of code cache |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
413 |
* and the segment map: (seg -> segment, nm ->nmethod) |
23214
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 |
* code cache segmap |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
416 |
* ----------- --------- |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
417 |
* seg 1 | nm 1 | -> | 0 | |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
418 |
* seg 2 | nm 1 | -> | 1 | |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
419 |
* ... | nm 1 | -> | .. | |
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
420 |
* seg m-1 | nm 1 | -> | m-1 | |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
421 |
* seg m | nm 2 | -> | 0 | |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
422 |
* 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
|
423 |
* ... | nm 2 | -> | 2 | |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
424 |
* ... | nm 2 | -> | .. | |
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
425 |
* ... | nm 2 | -> | 0xFE | (free_sentinel-1) |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
426 |
* ... | nm 2 | -> | 1 | |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
427 |
* seg m+n | nm 2 | -> | 2 | |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
428 |
* ... | nm 2 | -> | | |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
429 |
* |
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
430 |
* How to read: |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
431 |
* A value of '0' in the segmap indicates that this segment contains the |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
432 |
* beginning of a CodeHeap block. Let's walk through a simple example: |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
433 |
* |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
434 |
* We want to find the start of the block that contains nm 1, and we are |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
435 |
* given a pointer that points into segment m-2. We then read the value |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
436 |
* of segmap[m-2]. The value is an offset that points to the segment |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
437 |
* which contains the start of the block. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
438 |
* |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
439 |
* Another example: We want to locate the start of nm 2, and we happen to |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
440 |
* get a pointer that points into seg m+n. We first read seg[n+m], which |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
441 |
* returns '2'. So we have to update our segment map index (ix -= segmap[n+m]) |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
442 |
* and start over. |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
443 |
*/ |
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
444 |
|
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
445 |
// Find block which contains the passed pointer, |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
446 |
// regardless of the block being used or free. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
447 |
// NULL is returned if anything invalid is detected. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
448 |
void* CodeHeap::find_block_for(void* p) const { |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
449 |
// Check the pointer to be in committed range. |
1 | 450 |
if (!contains(p)) { |
451 |
return NULL; |
|
452 |
} |
|
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
453 |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
454 |
address seg_map = (address)_segmap.low(); |
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
455 |
size_t seg_idx = segment_for(p); |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
456 |
|
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
457 |
// This may happen in special cases. Just ignore. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
458 |
// Example: PPC ICache stub generation. |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
459 |
if (is_segment_unused(seg_map[seg_idx])) { |
1 | 460 |
return NULL; |
461 |
} |
|
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
462 |
|
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
463 |
// Iterate the segment map chain to find the start of the block. |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
464 |
while (seg_map[seg_idx] > 0) { |
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
465 |
// Don't check each segment index to refer to a used segment. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
466 |
// This method is called extremely often. Therefore, any checking |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
467 |
// has a significant impact on performance. Rely on CodeHeap::verify() |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
468 |
// to do the job on request. |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
469 |
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
|
470 |
} |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
471 |
|
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
472 |
return address_for(seg_idx); |
1 | 473 |
} |
474 |
||
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
475 |
// Find block which contains the passed pointer. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
476 |
// The block must be used, i.e. must not be a FreeBlock. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
477 |
// Return a pointer that points past the block header. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
478 |
void* CodeHeap::find_start(void* p) const { |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
479 |
HeapBlock* h = (HeapBlock*)find_block_for(p); |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
480 |
return ((h == NULL) || h->free()) ? NULL : h->allocated_space(); |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
481 |
} |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
482 |
|
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
483 |
// Find block which contains the passed pointer. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
484 |
// Same as find_start(p), but with additional safety net. |
42650 | 485 |
CodeBlob* CodeHeap::find_blob_unsafe(void* start) const { |
486 |
CodeBlob* result = (CodeBlob*)CodeHeap::find_start(start); |
|
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
487 |
return (result != NULL && result->blob_contains((address)start)) ? result : NULL; |
42650 | 488 |
} |
1 | 489 |
|
490 |
size_t CodeHeap::alignment_unit() const { |
|
491 |
// this will be a power of two |
|
492 |
return _segment_size; |
|
493 |
} |
|
494 |
||
495 |
||
496 |
size_t CodeHeap::alignment_offset() const { |
|
497 |
// The lowest address in any allocated block will be |
|
498 |
// equal to alignment_offset (mod alignment_unit). |
|
499 |
return sizeof(HeapBlock) & (_segment_size - 1); |
|
500 |
} |
|
501 |
||
28493 | 502 |
// Returns the current block if available and used. |
503 |
// If not, it returns the subsequent block (if available), NULL otherwise. |
|
504 |
// Free blocks are merged, therefore there is at most one free block |
|
505 |
// between two used ones. As a result, the subsequent block (if available) is |
|
506 |
// guaranteed to be used. |
|
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
507 |
// The returned pointer points past the block header. |
28493 | 508 |
void* CodeHeap::next_used(HeapBlock* b) const { |
1 | 509 |
if (b != NULL && b->free()) b = next_block(b); |
510 |
assert(b == NULL || !b->free(), "must be in use or at end of heap"); |
|
511 |
return (b == NULL) ? NULL : b->allocated_space(); |
|
512 |
} |
|
513 |
||
514 |
// Returns the first used HeapBlock |
|
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
515 |
// The returned pointer points to the block header. |
1 | 516 |
HeapBlock* CodeHeap::first_block() const { |
517 |
if (_next_segment > 0) |
|
518 |
return block_at(0); |
|
519 |
return NULL; |
|
520 |
} |
|
521 |
||
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
522 |
// The returned pointer points to the block header. |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
523 |
HeapBlock* CodeHeap::block_start(void* q) const { |
1 | 524 |
HeapBlock* b = (HeapBlock*)find_start(q); |
525 |
if (b == NULL) return NULL; |
|
526 |
return b - 1; |
|
527 |
} |
|
528 |
||
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
529 |
// Returns the next Heap block. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
530 |
// The returned pointer points to the block header. |
1 | 531 |
HeapBlock* CodeHeap::next_block(HeapBlock *b) const { |
532 |
if (b == NULL) return NULL; |
|
533 |
size_t i = segment_for(b) + b->length(); |
|
534 |
if (i < _next_segment) |
|
535 |
return block_at(i); |
|
536 |
return NULL; |
|
537 |
} |
|
538 |
||
539 |
||
540 |
// Returns current capacity |
|
541 |
size_t CodeHeap::capacity() const { |
|
542 |
return _memory.committed_size(); |
|
543 |
} |
|
544 |
||
545 |
size_t CodeHeap::max_capacity() const { |
|
546 |
return _memory.reserved_size(); |
|
547 |
} |
|
548 |
||
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
549 |
int CodeHeap::allocated_segments() const { |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
550 |
return (int)_next_segment; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
551 |
} |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
552 |
|
1 | 553 |
size_t CodeHeap::allocated_capacity() const { |
17016
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
554 |
// size of used heap - size on freelist |
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
555 |
return segments_to_size(_next_segment - _freelist_segments); |
1 | 556 |
} |
557 |
||
17016
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
558 |
// Returns size of the unallocated heap block |
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
559 |
size_t CodeHeap::heap_unallocated_capacity() const { |
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
560 |
// Total number of segments - number currently used |
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
561 |
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
|
562 |
} |
12998f95a334
7008325: CodeCache exhausted on sparc starting from hs20b04
kvn
parents:
7397
diff
changeset
|
563 |
|
1 | 564 |
// Free list management |
565 |
||
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
566 |
FreeBlock* CodeHeap::following_block(FreeBlock *b) { |
1 | 567 |
return (FreeBlock*)(((address)b) + _segment_size * b->length()); |
568 |
} |
|
569 |
||
570 |
// Inserts block b after a |
|
571 |
void CodeHeap::insert_after(FreeBlock* a, FreeBlock* b) { |
|
572 |
assert(a != NULL && b != NULL, "must be real pointers"); |
|
573 |
||
574 |
// Link b into the list after a |
|
575 |
b->set_link(a->link()); |
|
576 |
a->set_link(b); |
|
577 |
||
578 |
// See if we can merge blocks |
|
579 |
merge_right(b); // Try to make b bigger |
|
580 |
merge_right(a); // Try to make a include b |
|
581 |
} |
|
582 |
||
583 |
// 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
|
584 |
bool CodeHeap::merge_right(FreeBlock* a) { |
1 | 585 |
assert(a->free(), "must be a free block"); |
586 |
if (following_block(a) == a->link()) { |
|
587 |
assert(a->link() != NULL && a->link()->free(), "must be free too"); |
|
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
588 |
|
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
589 |
// Remember linked (following) block. invalidate should only zap header of this block. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
590 |
size_t follower = segment_for(a->link()); |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
591 |
// Merge block a to include the following block. |
1 | 592 |
a->set_length(a->length() + a->link()->length()); |
593 |
a->set_link(a->link()->link()); |
|
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
594 |
|
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
595 |
// Update the segment map and invalidate block contents. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
596 |
mark_segmap_as_used(follower, segment_for(a) + a->length(), true); |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
597 |
// Block contents has already been invalidated by add_to_freelist. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
598 |
// What's left is the header of the following block which now is |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
599 |
// in the middle of the merged block. Just zap one segment. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
600 |
invalidate(follower, follower + 1, 0); |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
601 |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
602 |
_freelist_length--; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
603 |
return true; |
1 | 604 |
} |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
605 |
return false; |
1 | 606 |
} |
607 |
||
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
608 |
|
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
609 |
void CodeHeap::add_to_freelist(HeapBlock* a) { |
1 | 610 |
FreeBlock* b = (FreeBlock*)a; |
54943 | 611 |
size_t bseg = segment_for(b); |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
612 |
_freelist_length++; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
613 |
|
1 | 614 |
assert(b != _freelist, "cannot be removed twice"); |
615 |
||
616 |
// 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
|
617 |
_freelist_segments += b->length(); |
1 | 618 |
b->set_free(); |
54943 | 619 |
invalidate(bseg, bseg + b->length(), sizeof(FreeBlock)); |
1 | 620 |
|
621 |
// First element in list? |
|
622 |
if (_freelist == NULL) { |
|
54943 | 623 |
b->set_link(NULL); |
1 | 624 |
_freelist = b; |
625 |
return; |
|
626 |
} |
|
627 |
||
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
628 |
// 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
|
629 |
// 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
|
630 |
// 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
|
631 |
if (b < _freelist) { |
1 | 632 |
// Insert first in list |
633 |
b->set_link(_freelist); |
|
634 |
_freelist = b; |
|
635 |
merge_right(_freelist); |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
636 |
return; |
1 | 637 |
} |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
638 |
|
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
639 |
// Scan for right place to put into list. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
640 |
// List is sorted by increasing addresses. |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
641 |
FreeBlock* prev = _freelist; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
642 |
FreeBlock* cur = _freelist->link(); |
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
643 |
if ((_freelist_length > freelist_limit) && (_last_insert_point != NULL)) { |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
644 |
_last_insert_point = (FreeBlock*)find_block_for(_last_insert_point); |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
645 |
if ((_last_insert_point != NULL) && _last_insert_point->free() && (_last_insert_point < b)) { |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
646 |
prev = _last_insert_point; |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
647 |
cur = prev->link(); |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
648 |
} |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
649 |
} |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
650 |
while(cur != NULL && cur < b) { |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
651 |
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
|
652 |
prev = cur; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
653 |
cur = cur->link(); |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
654 |
} |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
655 |
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
|
656 |
insert_after(prev, b); |
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
657 |
_last_insert_point = prev; |
1 | 658 |
} |
659 |
||
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
660 |
/** |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
661 |
* 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
|
662 |
* @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
|
663 |
*/ |
54943 | 664 |
HeapBlock* CodeHeap::search_freelist(size_t length) { |
665 |
FreeBlock* found_block = NULL; |
|
666 |
FreeBlock* found_prev = NULL; |
|
667 |
size_t found_length = _next_segment; // max it out to begin with |
|
1 | 668 |
|
54943 | 669 |
HeapBlock* res = NULL; |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
670 |
FreeBlock* prev = NULL; |
54943 | 671 |
FreeBlock* cur = _freelist; |
672 |
||
673 |
length = length < CodeCacheMinBlockLength ? CodeCacheMinBlockLength : length; |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
674 |
|
54943 | 675 |
// Search for best-fitting block |
1 | 676 |
while(cur != NULL) { |
54943 | 677 |
size_t cur_length = cur->length(); |
678 |
if (cur_length == length) { |
|
679 |
// We have a perfect fit |
|
680 |
found_block = cur; |
|
681 |
found_prev = prev; |
|
682 |
found_length = cur_length; |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
683 |
break; |
54943 | 684 |
} else if ((cur_length > length) && (cur_length < found_length)) { |
685 |
// This is a new, closer fit. Remember block, its previous element, and its length |
|
686 |
found_block = cur; |
|
687 |
found_prev = prev; |
|
688 |
found_length = cur_length; |
|
1 | 689 |
} |
690 |
// Next element in list |
|
691 |
prev = cur; |
|
692 |
cur = cur->link(); |
|
693 |
} |
|
694 |
||
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
695 |
if (found_block == NULL) { |
1 | 696 |
// None found |
697 |
return NULL; |
|
698 |
} |
|
699 |
||
700 |
// Exact (or at least good enough) fit. Remove from list. |
|
701 |
// 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
|
702 |
if (found_length - length < CodeCacheMinBlockLength) { |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
703 |
_freelist_length--; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
704 |
length = found_length; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
705 |
if (found_prev == NULL) { |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
706 |
assert(_freelist == found_block, "sanity check"); |
1 | 707 |
_freelist = _freelist->link(); |
708 |
} else { |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
709 |
assert((found_prev->link() == found_block), "sanity check"); |
1 | 710 |
// Unmap element |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
711 |
found_prev->set_link(found_block->link()); |
1 | 712 |
} |
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
713 |
res = (HeapBlock*)found_block; |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
714 |
// sizeof(HeapBlock) < sizeof(FreeBlock). |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
715 |
// Invalidate the additional space that FreeBlock occupies. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
716 |
// The rest of the block should already be invalidated. |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
717 |
// This is necessary due to a dubious assert in nmethod.cpp(PcDescCache::reset_to()). |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
718 |
// Can't use invalidate() here because it works on segment_size units (too coarse). |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
719 |
DEBUG_ONLY(memset((void*)res->allocated_space(), badCodeHeapNewVal, sizeof(FreeBlock) - sizeof(HeapBlock))); |
1 | 720 |
} else { |
54943 | 721 |
// Truncate the free block and return the truncated part |
722 |
// as new HeapBlock. The remaining free block does not |
|
723 |
// need to be updated, except for it's length. Truncating |
|
724 |
// the segment map does not invalidate the leading part. |
|
725 |
res = split_block(found_block, found_length - length); |
|
1 | 726 |
} |
727 |
||
54943 | 728 |
res->set_used(); |
17016
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
16670
diff
changeset
|
729 |
_freelist_segments -= length; |
54943 | 730 |
return res; |
1 | 731 |
} |
732 |
||
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
733 |
int CodeHeap::defrag_segmap(bool do_defrag) { |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
734 |
int extra_hops_used = 0; |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
735 |
int extra_hops_free = 0; |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
736 |
int blocks_used = 0; |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
737 |
int blocks_free = 0; |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
738 |
for(HeapBlock* h = first_block(); h != NULL; h = next_block(h)) { |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
739 |
size_t beg = segment_for(h); |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
740 |
size_t end = segment_for(h) + h->length(); |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
741 |
int extra_hops = segmap_hops(beg, end); |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
742 |
if (h->free()) { |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
743 |
extra_hops_free += extra_hops; |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
744 |
blocks_free++; |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
745 |
} else { |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
746 |
extra_hops_used += extra_hops; |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
747 |
blocks_used++; |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
748 |
} |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
749 |
if (do_defrag && (extra_hops > 0)) { |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
750 |
mark_segmap_as_used(beg, end, false); |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
751 |
} |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
752 |
} |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
753 |
return extra_hops_used + extra_hops_free; |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
754 |
} |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
755 |
|
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
756 |
// Count the hops required to get from the last segment of a |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
757 |
// heap block to the block header segment. For the optimal case, |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
758 |
// #hops = ((#segments-1)+(free_sentinel-2))/(free_sentinel-1) |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
759 |
// The range of segments to be checked is given by [beg..end). |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
760 |
// Return the number of extra hops required. There may be extra hops |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
761 |
// due to the is_FreeBlock_join optimization in mark_segmap_as_used(). |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
762 |
int CodeHeap::segmap_hops(size_t beg, size_t end) { |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
763 |
if (beg < end) { |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
764 |
// setup _segmap pointers for faster indexing |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
765 |
address p = (address)_segmap.low() + beg; |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
766 |
int hops_expected = (int)(((end-beg-1)+(free_sentinel-2))/(free_sentinel-1)); |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
767 |
int nhops = 0; |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
768 |
size_t ix = end-beg-1; |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
769 |
while (p[ix] > 0) { |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
770 |
ix -= p[ix]; |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
771 |
nhops++; |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
772 |
} |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
773 |
return (nhops > hops_expected) ? nhops - hops_expected : 0; |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
774 |
} |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
775 |
return 0; |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
776 |
} |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
777 |
|
1 | 778 |
//---------------------------------------------------------------------------- |
779 |
// Non-product code |
|
780 |
||
781 |
#ifndef PRODUCT |
|
782 |
||
783 |
void CodeHeap::print() { |
|
784 |
tty->print_cr("The Heap"); |
|
785 |
} |
|
786 |
||
787 |
void CodeHeap::verify() { |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
788 |
if (VerifyCodeCache) { |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
789 |
size_t len = 0; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
790 |
int count = 0; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
791 |
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
|
792 |
len += b->length(); |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
793 |
count++; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
794 |
// 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
|
795 |
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
|
796 |
} |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
797 |
// 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
|
798 |
assert(len == _freelist_segments, "wrong freelist"); |
1 | 799 |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
800 |
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
|
801 |
if (h->free()) count--; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
802 |
} |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
803 |
// 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
|
804 |
// 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
|
805 |
assert(count == 0, "missing free blocks"); |
1 | 806 |
|
54943 | 807 |
//---< all free block memory must have been invalidated >--- |
808 |
for(FreeBlock* b = _freelist; b != NULL; b = b->link()) { |
|
809 |
for (char* c = (char*)b + sizeof(FreeBlock); c < (char*)b + segments_to_size(b->length()); c++) { |
|
810 |
assert(*c == (char)badCodeHeapNewVal, "FreeBlock@" PTR_FORMAT "(" PTR_FORMAT ") not invalidated @byte %d", p2i(b), b->length(), (int)(c - (char*)b)); |
|
811 |
} |
|
812 |
} |
|
813 |
||
814 |
address seg_map = (address)_segmap.low(); |
|
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
815 |
size_t nseg = 0; |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
816 |
int extra_hops = 0; |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
817 |
count = 0; |
54943 | 818 |
for(HeapBlock* b = first_block(); b != NULL; b = next_block(b)) { |
819 |
size_t seg1 = segment_for(b); |
|
820 |
size_t segn = seg1 + b->length(); |
|
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
821 |
extra_hops += segmap_hops(seg1, segn); |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
822 |
count++; |
54943 | 823 |
for (size_t i = seg1; i < segn; i++) { |
824 |
nseg++; |
|
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
825 |
//---< Verify segment map marking >--- |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
826 |
// All allocated segments, no matter if in a free or used block, |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
827 |
// must be marked "in use". |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
828 |
assert(!is_segment_unused(seg_map[i]), "CodeHeap: unused segment. seg_map[%d]([%d..%d]) = %d, %s block", (int)i, (int)seg1, (int)segn, seg_map[i], b->free()? "free":"used"); |
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
829 |
assert((unsigned char)seg_map[i] < free_sentinel, "CodeHeap: seg_map[%d]([%d..%d]) = %d (out of range)", (int)i, (int)seg1, (int)segn, seg_map[i]); |
54943 | 830 |
} |
831 |
} |
|
832 |
assert(nseg == _next_segment, "CodeHeap: segment count mismatch. found %d, expected %d.", (int)nseg, (int)_next_segment); |
|
59145
ea044aedc2b6
8231460: Performance issue (CodeHeap) with large free blocks
lucy
parents:
54943
diff
changeset
|
833 |
assert((count == 0) || (extra_hops < (16 + 2*count)), "CodeHeap: many extra hops due to optimization. blocks: %d, extra hops: %d.", count, extra_hops); |
54943 | 834 |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
835 |
// 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
|
836 |
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
|
837 |
if (count > free_block_threshold) { |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
838 |
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
|
839 |
// Double the warning limit |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
840 |
free_block_threshold *= 2; |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
841 |
} |
1 | 842 |
} |
843 |
} |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
844 |
|
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
845 |
#endif |