author | aph |
Thu, 11 Dec 2014 13:11:53 -0800 | |
changeset 29180 | 50369728b00e |
parent 26432 | 9b974e2eae27 |
child 27880 | afb974a04396 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
24002
diff
changeset
|
2 |
* Copyright (c) 1997, 2014, 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:
2105
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
2105
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:
2105
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "asm/codeBuffer.hpp" |
|
27 |
#include "compiler/disassembler.hpp" |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
28 |
#include "memory/gcLocker.hpp" |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
29 |
#include "oops/methodData.hpp" |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
30 |
#include "oops/oop.inline.hpp" |
25715
d5a8dbdc5150
8049325: Introduce and clean up umbrella headers for the files in the cpu subdirectories.
goetz
parents:
24424
diff
changeset
|
31 |
#include "runtime/icache.hpp" |
7397 | 32 |
#include "utilities/copy.hpp" |
10983
9ab65f4cec18
7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents:
10964
diff
changeset
|
33 |
#include "utilities/xmlstream.hpp" |
1 | 34 |
|
35 |
// The structure of a CodeSection: |
|
36 |
// |
|
37 |
// _start -> +----------------+ |
|
38 |
// | machine code...| |
|
39 |
// _end -> |----------------| |
|
40 |
// | | |
|
41 |
// | (empty) | |
|
42 |
// | | |
|
43 |
// | | |
|
44 |
// +----------------+ |
|
45 |
// _limit -> | | |
|
46 |
// |
|
47 |
// _locs_start -> +----------------+ |
|
48 |
// |reloc records...| |
|
49 |
// |----------------| |
|
50 |
// _locs_end -> | | |
|
51 |
// | | |
|
52 |
// | (empty) | |
|
53 |
// | | |
|
54 |
// | | |
|
55 |
// +----------------+ |
|
56 |
// _locs_limit -> | | |
|
57 |
// The _end (resp. _limit) pointer refers to the first |
|
58 |
// unused (resp. unallocated) byte. |
|
59 |
||
60 |
// The structure of the CodeBuffer while code is being accumulated: |
|
61 |
// |
|
62 |
// _total_start -> \ |
|
63 |
// _insts._start -> +----------------+ |
|
64 |
// | | |
|
65 |
// | Code | |
|
66 |
// | | |
|
67 |
// _stubs._start -> |----------------| |
|
68 |
// | | |
|
69 |
// | Stubs | (also handlers for deopt/exception) |
|
70 |
// | | |
|
71 |
// _consts._start -> |----------------| |
|
72 |
// | | |
|
73 |
// | Constants | |
|
74 |
// | | |
|
75 |
// +----------------+ |
|
76 |
// + _total_size -> | | |
|
77 |
// |
|
78 |
// When the code and relocations are copied to the code cache, |
|
79 |
// the empty parts of each section are removed, and everything |
|
80 |
// is copied into contiguous locations. |
|
81 |
||
82 |
typedef CodeBuffer::csize_t csize_t; // file-local definition |
|
83 |
||
6418 | 84 |
// External buffer, in a predefined CodeBlob. |
1 | 85 |
// Important: The code_start must be taken exactly, and not realigned. |
6418 | 86 |
CodeBuffer::CodeBuffer(CodeBlob* blob) { |
1 | 87 |
initialize_misc("static buffer"); |
6418 | 88 |
initialize(blob->content_begin(), blob->content_size()); |
10983
9ab65f4cec18
7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents:
10964
diff
changeset
|
89 |
verify_section_allocation(); |
1 | 90 |
} |
91 |
||
92 |
void CodeBuffer::initialize(csize_t code_size, csize_t locs_size) { |
|
93 |
// Compute maximal alignment. |
|
94 |
int align = _insts.alignment(); |
|
95 |
// Always allow for empty slop around each section. |
|
96 |
int slop = (int) CodeSection::end_slop(); |
|
97 |
||
98 |
assert(blob() == NULL, "only once"); |
|
99 |
set_blob(BufferBlob::create(_name, code_size + (align+slop) * (SECT_LIMIT+1))); |
|
100 |
if (blob() == NULL) { |
|
101 |
// The assembler constructor will throw a fatal on an empty CodeBuffer. |
|
102 |
return; // caller must test this |
|
103 |
} |
|
104 |
||
105 |
// Set up various pointers into the blob. |
|
106 |
initialize(_total_start, _total_size); |
|
107 |
||
6418 | 108 |
assert((uintptr_t)insts_begin() % CodeEntryAlignment == 0, "instruction start not code entry aligned"); |
1 | 109 |
|
110 |
pd_initialize(); |
|
111 |
||
112 |
if (locs_size != 0) { |
|
113 |
_insts.initialize_locs(locs_size / sizeof(relocInfo)); |
|
114 |
} |
|
115 |
||
10983
9ab65f4cec18
7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents:
10964
diff
changeset
|
116 |
verify_section_allocation(); |
1 | 117 |
} |
118 |
||
119 |
||
120 |
CodeBuffer::~CodeBuffer() { |
|
10983
9ab65f4cec18
7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents:
10964
diff
changeset
|
121 |
verify_section_allocation(); |
9ab65f4cec18
7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents:
10964
diff
changeset
|
122 |
|
1 | 123 |
// If we allocate our code buffer from the CodeCache |
124 |
// via a BufferBlob, and it's not permanent, then |
|
125 |
// free the BufferBlob. |
|
126 |
// The rest of the memory will be freed when the ResourceObj |
|
127 |
// is released. |
|
128 |
for (CodeBuffer* cb = this; cb != NULL; cb = cb->before_expand()) { |
|
129 |
// Previous incarnations of this buffer are held live, so that internal |
|
130 |
// addresses constructed before expansions will not be confused. |
|
131 |
cb->free_blob(); |
|
132 |
} |
|
2025
a13c4b3f024e
6782260: Memory leak in CodeBuffer::create_patch_overflow
never
parents:
670
diff
changeset
|
133 |
|
a13c4b3f024e
6782260: Memory leak in CodeBuffer::create_patch_overflow
never
parents:
670
diff
changeset
|
134 |
// free any overflow storage |
a13c4b3f024e
6782260: Memory leak in CodeBuffer::create_patch_overflow
never
parents:
670
diff
changeset
|
135 |
delete _overflow_arena; |
a13c4b3f024e
6782260: Memory leak in CodeBuffer::create_patch_overflow
never
parents:
670
diff
changeset
|
136 |
|
26432 | 137 |
// Claim is that stack allocation ensures resources are cleaned up. |
138 |
// This is resource clean up, let's hope that all were properly copied out. |
|
139 |
free_strings(); |
|
140 |
||
1 | 141 |
#ifdef ASSERT |
6180 | 142 |
// Save allocation type to execute assert in ~ResourceObj() |
143 |
// which is called after this destructor. |
|
7440
eabaf35910a1
6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents:
7397
diff
changeset
|
144 |
assert(_default_oop_recorder.allocated_on_stack(), "should be embedded object"); |
6180 | 145 |
ResourceObj::allocation_type at = _default_oop_recorder.get_allocation_type(); |
1 | 146 |
Copy::fill_to_bytes(this, sizeof(*this), badResourceValue); |
6180 | 147 |
ResourceObj::set_allocation_type((address)(&_default_oop_recorder), at); |
1 | 148 |
#endif |
149 |
} |
|
150 |
||
151 |
void CodeBuffer::initialize_oop_recorder(OopRecorder* r) { |
|
152 |
assert(_oop_recorder == &_default_oop_recorder && _default_oop_recorder.is_unused(), "do this once"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
153 |
DEBUG_ONLY(_default_oop_recorder.freeze()); // force unused OR to be frozen |
1 | 154 |
_oop_recorder = r; |
155 |
} |
|
156 |
||
157 |
void CodeBuffer::initialize_section_size(CodeSection* cs, csize_t size) { |
|
158 |
assert(cs != &_insts, "insts is the memory provider, not the consumer"); |
|
159 |
csize_t slop = CodeSection::end_slop(); // margin between sections |
|
160 |
int align = cs->alignment(); |
|
161 |
assert(is_power_of_2(align), "sanity"); |
|
162 |
address start = _insts._start; |
|
163 |
address limit = _insts._limit; |
|
164 |
address middle = limit - size; |
|
165 |
middle -= (intptr_t)middle & (align-1); // align the division point downward |
|
166 |
guarantee(middle - slop > start, "need enough space to divide up"); |
|
167 |
_insts._limit = middle - slop; // subtract desired space, plus slop |
|
168 |
cs->initialize(middle, limit - middle); |
|
169 |
assert(cs->start() == middle, "sanity"); |
|
170 |
assert(cs->limit() == limit, "sanity"); |
|
171 |
// give it some relocations to start with, if the main section has them |
|
172 |
if (_insts.has_locs()) cs->initialize_locs(1); |
|
173 |
} |
|
174 |
||
175 |
void CodeBuffer::freeze_section(CodeSection* cs) { |
|
176 |
CodeSection* next_cs = (cs == consts())? NULL: code_section(cs->index()+1); |
|
177 |
csize_t frozen_size = cs->size(); |
|
178 |
if (next_cs != NULL) { |
|
179 |
frozen_size = next_cs->align_at_start(frozen_size); |
|
180 |
} |
|
181 |
address old_limit = cs->limit(); |
|
182 |
address new_limit = cs->start() + frozen_size; |
|
183 |
relocInfo* old_locs_limit = cs->locs_limit(); |
|
184 |
relocInfo* new_locs_limit = cs->locs_end(); |
|
185 |
// Patch the limits. |
|
186 |
cs->_limit = new_limit; |
|
187 |
cs->_locs_limit = new_locs_limit; |
|
188 |
cs->_frozen = true; |
|
189 |
if (!next_cs->is_allocated() && !next_cs->is_frozen()) { |
|
190 |
// Give remaining buffer space to the following section. |
|
191 |
next_cs->initialize(new_limit, old_limit - new_limit); |
|
192 |
next_cs->initialize_shared_locs(new_locs_limit, |
|
193 |
old_locs_limit - new_locs_limit); |
|
194 |
} |
|
195 |
} |
|
196 |
||
197 |
void CodeBuffer::set_blob(BufferBlob* blob) { |
|
198 |
_blob = blob; |
|
199 |
if (blob != NULL) { |
|
6418 | 200 |
address start = blob->content_begin(); |
201 |
address end = blob->content_end(); |
|
1 | 202 |
// Round up the starting address. |
203 |
int align = _insts.alignment(); |
|
204 |
start += (-(intptr_t)start) & (align-1); |
|
205 |
_total_start = start; |
|
206 |
_total_size = end - start; |
|
207 |
} else { |
|
6432
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
208 |
#ifdef ASSERT |
1 | 209 |
// Clean out dangling pointers. |
210 |
_total_start = badAddress; |
|
6432
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
211 |
_consts._start = _consts._end = badAddress; |
1 | 212 |
_insts._start = _insts._end = badAddress; |
213 |
_stubs._start = _stubs._end = badAddress; |
|
6432
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
214 |
#endif //ASSERT |
1 | 215 |
} |
216 |
} |
|
217 |
||
218 |
void CodeBuffer::free_blob() { |
|
219 |
if (_blob != NULL) { |
|
220 |
BufferBlob::free(_blob); |
|
221 |
set_blob(NULL); |
|
222 |
} |
|
223 |
} |
|
224 |
||
225 |
const char* CodeBuffer::code_section_name(int n) { |
|
226 |
#ifdef PRODUCT |
|
227 |
return NULL; |
|
228 |
#else //PRODUCT |
|
229 |
switch (n) { |
|
6432
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
230 |
case SECT_CONSTS: return "consts"; |
1 | 231 |
case SECT_INSTS: return "insts"; |
232 |
case SECT_STUBS: return "stubs"; |
|
233 |
default: return NULL; |
|
234 |
} |
|
235 |
#endif //PRODUCT |
|
236 |
} |
|
237 |
||
238 |
int CodeBuffer::section_index_of(address addr) const { |
|
239 |
for (int n = 0; n < (int)SECT_LIMIT; n++) { |
|
240 |
const CodeSection* cs = code_section(n); |
|
241 |
if (cs->allocates(addr)) return n; |
|
242 |
} |
|
243 |
return SECT_NONE; |
|
244 |
} |
|
245 |
||
246 |
int CodeBuffer::locator(address addr) const { |
|
247 |
for (int n = 0; n < (int)SECT_LIMIT; n++) { |
|
248 |
const CodeSection* cs = code_section(n); |
|
249 |
if (cs->allocates(addr)) { |
|
250 |
return locator(addr - cs->start(), n); |
|
251 |
} |
|
252 |
} |
|
253 |
return -1; |
|
254 |
} |
|
255 |
||
256 |
address CodeBuffer::locator_address(int locator) const { |
|
257 |
if (locator < 0) return NULL; |
|
258 |
address start = code_section(locator_sect(locator))->start(); |
|
259 |
return start + locator_pos(locator); |
|
260 |
} |
|
261 |
||
14626
0cf4eccf130f
8003240: x86: move MacroAssembler into separate file
twisti
parents:
14624
diff
changeset
|
262 |
bool CodeBuffer::is_backward_branch(Label& L) { |
0cf4eccf130f
8003240: x86: move MacroAssembler into separate file
twisti
parents:
14624
diff
changeset
|
263 |
return L.is_bound() && insts_end() <= locator_address(L.loc()); |
0cf4eccf130f
8003240: x86: move MacroAssembler into separate file
twisti
parents:
14624
diff
changeset
|
264 |
} |
0cf4eccf130f
8003240: x86: move MacroAssembler into separate file
twisti
parents:
14624
diff
changeset
|
265 |
|
1 | 266 |
address CodeBuffer::decode_begin() { |
267 |
address begin = _insts.start(); |
|
268 |
if (_decode_begin != NULL && _decode_begin > begin) |
|
269 |
begin = _decode_begin; |
|
270 |
return begin; |
|
271 |
} |
|
272 |
||
273 |
||
274 |
GrowableArray<int>* CodeBuffer::create_patch_overflow() { |
|
275 |
if (_overflow_arena == NULL) { |
|
25946 | 276 |
_overflow_arena = new (mtCode) Arena(mtCode); |
1 | 277 |
} |
278 |
return new (_overflow_arena) GrowableArray<int>(_overflow_arena, 8, 0, 0); |
|
279 |
} |
|
280 |
||
281 |
||
282 |
// Helper function for managing labels and their target addresses. |
|
283 |
// Returns a sensible address, and if it is not the label's final |
|
284 |
// address, notes the dependency (at 'branch_pc') on the label. |
|
285 |
address CodeSection::target(Label& L, address branch_pc) { |
|
286 |
if (L.is_bound()) { |
|
287 |
int loc = L.loc(); |
|
288 |
if (index() == CodeBuffer::locator_sect(loc)) { |
|
289 |
return start() + CodeBuffer::locator_pos(loc); |
|
290 |
} else { |
|
291 |
return outer()->locator_address(loc); |
|
292 |
} |
|
293 |
} else { |
|
294 |
assert(allocates2(branch_pc), "sanity"); |
|
295 |
address base = start(); |
|
296 |
int patch_loc = CodeBuffer::locator(branch_pc - base, index()); |
|
297 |
L.add_patch_at(outer(), patch_loc); |
|
298 |
||
299 |
// Need to return a pc, doesn't matter what it is since it will be |
|
300 |
// replaced during resolution later. |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
347
diff
changeset
|
301 |
// Don't return NULL or badAddress, since branches shouldn't overflow. |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
347
diff
changeset
|
302 |
// Don't return base either because that could overflow displacements |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
347
diff
changeset
|
303 |
// for shorter branches. It will get checked when bound. |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
347
diff
changeset
|
304 |
return branch_pc; |
1 | 305 |
} |
306 |
} |
|
307 |
||
308 |
void CodeSection::relocate(address at, RelocationHolder const& spec, int format) { |
|
309 |
Relocation* reloc = spec.reloc(); |
|
310 |
relocInfo::relocType rtype = (relocInfo::relocType) reloc->type(); |
|
311 |
if (rtype == relocInfo::none) return; |
|
312 |
||
313 |
// The assertion below has been adjusted, to also work for |
|
314 |
// relocation for fixup. Sometimes we want to put relocation |
|
315 |
// information for the next instruction, since it will be patched |
|
316 |
// with a call. |
|
317 |
assert(start() <= at && at <= end()+1, |
|
318 |
"cannot relocate data outside code boundaries"); |
|
319 |
||
320 |
if (!has_locs()) { |
|
321 |
// no space for relocation information provided => code cannot be |
|
322 |
// relocated. Make sure that relocate is only called with rtypes |
|
323 |
// that can be ignored for this kind of code. |
|
324 |
assert(rtype == relocInfo::none || |
|
325 |
rtype == relocInfo::runtime_call_type || |
|
326 |
rtype == relocInfo::internal_word_type|| |
|
327 |
rtype == relocInfo::section_word_type || |
|
328 |
rtype == relocInfo::external_word_type, |
|
329 |
"code needs relocation information"); |
|
330 |
// leave behind an indication that we attempted a relocation |
|
331 |
DEBUG_ONLY(_locs_start = _locs_limit = (relocInfo*)badAddress); |
|
332 |
return; |
|
333 |
} |
|
334 |
||
335 |
// Advance the point, noting the offset we'll have to record. |
|
336 |
csize_t offset = at - locs_point(); |
|
337 |
set_locs_point(at); |
|
338 |
||
339 |
// Test for a couple of overflow conditions; maybe expand the buffer. |
|
340 |
relocInfo* end = locs_end(); |
|
341 |
relocInfo* req = end + relocInfo::length_limit; |
|
342 |
// Check for (potential) overflow |
|
343 |
if (req >= locs_limit() || offset >= relocInfo::offset_limit()) { |
|
344 |
req += (uint)offset / (uint)relocInfo::offset_limit(); |
|
345 |
if (req >= locs_limit()) { |
|
346 |
// Allocate or reallocate. |
|
347 |
expand_locs(locs_count() + (req - end)); |
|
348 |
// reload pointer |
|
349 |
end = locs_end(); |
|
350 |
} |
|
351 |
} |
|
352 |
||
353 |
// If the offset is giant, emit filler relocs, of type 'none', but |
|
354 |
// each carrying the largest possible offset, to advance the locs_point. |
|
355 |
while (offset >= relocInfo::offset_limit()) { |
|
356 |
assert(end < locs_limit(), "adjust previous paragraph of code"); |
|
357 |
*end++ = filler_relocInfo(); |
|
358 |
offset -= filler_relocInfo().addr_offset(); |
|
359 |
} |
|
360 |
||
361 |
// If it's a simple reloc with no data, we'll just write (rtype | offset). |
|
362 |
(*end) = relocInfo(rtype, offset, format); |
|
363 |
||
364 |
// If it has data, insert the prefix, as (data_prefix_tag | data1), data2. |
|
365 |
end->initialize(this, reloc); |
|
366 |
} |
|
367 |
||
368 |
void CodeSection::initialize_locs(int locs_capacity) { |
|
369 |
assert(_locs_start == NULL, "only one locs init step, please"); |
|
370 |
// Apply a priori lower limits to relocation size: |
|
371 |
csize_t min_locs = MAX2(size() / 16, (csize_t)4); |
|
372 |
if (locs_capacity < min_locs) locs_capacity = min_locs; |
|
373 |
relocInfo* locs_start = NEW_RESOURCE_ARRAY(relocInfo, locs_capacity); |
|
374 |
_locs_start = locs_start; |
|
375 |
_locs_end = locs_start; |
|
376 |
_locs_limit = locs_start + locs_capacity; |
|
377 |
_locs_own = true; |
|
378 |
} |
|
379 |
||
380 |
void CodeSection::initialize_shared_locs(relocInfo* buf, int length) { |
|
381 |
assert(_locs_start == NULL, "do this before locs are allocated"); |
|
382 |
// Internal invariant: locs buf must be fully aligned. |
|
383 |
// See copy_relocations_to() below. |
|
384 |
while ((uintptr_t)buf % HeapWordSize != 0 && length > 0) { |
|
385 |
++buf; --length; |
|
386 |
} |
|
387 |
if (length > 0) { |
|
388 |
_locs_start = buf; |
|
389 |
_locs_end = buf; |
|
390 |
_locs_limit = buf + length; |
|
391 |
_locs_own = false; |
|
392 |
} |
|
393 |
} |
|
394 |
||
395 |
void CodeSection::initialize_locs_from(const CodeSection* source_cs) { |
|
396 |
int lcount = source_cs->locs_count(); |
|
397 |
if (lcount != 0) { |
|
398 |
initialize_shared_locs(source_cs->locs_start(), lcount); |
|
399 |
_locs_end = _locs_limit = _locs_start + lcount; |
|
400 |
assert(is_allocated(), "must have copied code already"); |
|
401 |
set_locs_point(start() + source_cs->locs_point_off()); |
|
402 |
} |
|
403 |
assert(this->locs_count() == source_cs->locs_count(), "sanity"); |
|
404 |
} |
|
405 |
||
406 |
void CodeSection::expand_locs(int new_capacity) { |
|
407 |
if (_locs_start == NULL) { |
|
408 |
initialize_locs(new_capacity); |
|
409 |
return; |
|
410 |
} else { |
|
411 |
int old_count = locs_count(); |
|
412 |
int old_capacity = locs_capacity(); |
|
413 |
if (new_capacity < old_capacity * 2) |
|
414 |
new_capacity = old_capacity * 2; |
|
415 |
relocInfo* locs_start; |
|
416 |
if (_locs_own) { |
|
417 |
locs_start = REALLOC_RESOURCE_ARRAY(relocInfo, _locs_start, old_capacity, new_capacity); |
|
418 |
} else { |
|
419 |
locs_start = NEW_RESOURCE_ARRAY(relocInfo, new_capacity); |
|
5883
8dc4bdc132d5
6730276: JDI_REGRESSION tests fail with "Error: count must be non-zero" error on x86
kvn
parents:
5547
diff
changeset
|
420 |
Copy::conjoint_jbytes(_locs_start, locs_start, old_capacity * sizeof(relocInfo)); |
1 | 421 |
_locs_own = true; |
422 |
} |
|
423 |
_locs_start = locs_start; |
|
424 |
_locs_end = locs_start + old_count; |
|
425 |
_locs_limit = locs_start + new_capacity; |
|
426 |
} |
|
427 |
} |
|
428 |
||
429 |
||
430 |
/// Support for emitting the code to its final location. |
|
431 |
/// The pattern is the same for all functions. |
|
432 |
/// We iterate over all the sections, padding each to alignment. |
|
433 |
||
6418 | 434 |
csize_t CodeBuffer::total_content_size() const { |
435 |
csize_t size_so_far = 0; |
|
1 | 436 |
for (int n = 0; n < (int)SECT_LIMIT; n++) { |
437 |
const CodeSection* cs = code_section(n); |
|
438 |
if (cs->is_empty()) continue; // skip trivial section |
|
6418 | 439 |
size_so_far = cs->align_at_start(size_so_far); |
440 |
size_so_far += cs->size(); |
|
1 | 441 |
} |
6418 | 442 |
return size_so_far; |
1 | 443 |
} |
444 |
||
445 |
void CodeBuffer::compute_final_layout(CodeBuffer* dest) const { |
|
446 |
address buf = dest->_total_start; |
|
447 |
csize_t buf_offset = 0; |
|
6418 | 448 |
assert(dest->_total_size >= total_content_size(), "must be big enough"); |
1 | 449 |
|
450 |
{ |
|
451 |
// not sure why this is here, but why not... |
|
452 |
int alignSize = MAX2((intx) sizeof(jdouble), CodeEntryAlignment); |
|
453 |
assert( (dest->_total_start - _insts.start()) % alignSize == 0, "copy must preserve alignment"); |
|
454 |
} |
|
455 |
||
456 |
const CodeSection* prev_cs = NULL; |
|
457 |
CodeSection* prev_dest_cs = NULL; |
|
6432
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
458 |
|
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
459 |
for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) { |
1 | 460 |
// figure compact layout of each section |
461 |
const CodeSection* cs = code_section(n); |
|
6432
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
462 |
csize_t csize = cs->size(); |
1 | 463 |
|
464 |
CodeSection* dest_cs = dest->code_section(n); |
|
465 |
if (!cs->is_empty()) { |
|
466 |
// Compute initial padding; assign it to the previous non-empty guy. |
|
467 |
// Cf. figure_expanded_capacities. |
|
468 |
csize_t padding = cs->align_at_start(buf_offset) - buf_offset; |
|
469 |
if (padding != 0) { |
|
470 |
buf_offset += padding; |
|
471 |
assert(prev_dest_cs != NULL, "sanity"); |
|
472 |
prev_dest_cs->_limit += padding; |
|
473 |
} |
|
474 |
#ifdef ASSERT |
|
6432
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
475 |
if (prev_cs != NULL && prev_cs->is_frozen() && n < (SECT_LIMIT - 1)) { |
1 | 476 |
// Make sure the ends still match up. |
477 |
// This is important because a branch in a frozen section |
|
478 |
// might target code in a following section, via a Label, |
|
479 |
// and without a relocation record. See Label::patch_instructions. |
|
480 |
address dest_start = buf+buf_offset; |
|
481 |
csize_t start2start = cs->start() - prev_cs->start(); |
|
482 |
csize_t dest_start2start = dest_start - prev_dest_cs->start(); |
|
483 |
assert(start2start == dest_start2start, "cannot stretch frozen sect"); |
|
484 |
} |
|
485 |
#endif //ASSERT |
|
486 |
prev_dest_cs = dest_cs; |
|
487 |
prev_cs = cs; |
|
488 |
} |
|
489 |
||
490 |
debug_only(dest_cs->_start = NULL); // defeat double-initialization assert |
|
491 |
dest_cs->initialize(buf+buf_offset, csize); |
|
492 |
dest_cs->set_end(buf+buf_offset+csize); |
|
493 |
assert(dest_cs->is_allocated(), "must always be allocated"); |
|
494 |
assert(cs->is_empty() == dest_cs->is_empty(), "sanity"); |
|
495 |
||
496 |
buf_offset += csize; |
|
497 |
} |
|
498 |
||
499 |
// Done calculating sections; did it come out to the right end? |
|
6418 | 500 |
assert(buf_offset == total_content_size(), "sanity"); |
10983
9ab65f4cec18
7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents:
10964
diff
changeset
|
501 |
dest->verify_section_allocation(); |
1 | 502 |
} |
503 |
||
14816 | 504 |
// Append an oop reference that keeps the class alive. |
14588
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14294
diff
changeset
|
505 |
static void append_oop_references(GrowableArray<oop>* oops, Klass* k) { |
14816 | 506 |
oop cl = k->klass_holder(); |
14588
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14294
diff
changeset
|
507 |
if (cl != NULL && !oops->contains(cl)) { |
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14294
diff
changeset
|
508 |
oops->append(cl); |
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14294
diff
changeset
|
509 |
} |
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14294
diff
changeset
|
510 |
} |
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14294
diff
changeset
|
511 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
512 |
void CodeBuffer::finalize_oop_references(methodHandle mh) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
513 |
No_Safepoint_Verifier nsv; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
514 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
515 |
GrowableArray<oop> oops; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
516 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
517 |
// Make sure that immediate metadata records something in the OopRecorder |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
518 |
for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
519 |
// pull code out of each section |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
520 |
CodeSection* cs = code_section(n); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
521 |
if (cs->is_empty()) continue; // skip trivial section |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
522 |
RelocIterator iter(cs); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
523 |
while (iter.next()) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
524 |
if (iter.type() == relocInfo::metadata_type) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
525 |
metadata_Relocation* md = iter.metadata_reloc(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
526 |
if (md->metadata_is_immediate()) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
527 |
Metadata* m = md->metadata_value(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
528 |
if (oop_recorder()->is_real(m)) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
529 |
if (m->is_methodData()) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
530 |
m = ((MethodData*)m)->method(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
531 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
532 |
if (m->is_method()) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
533 |
m = ((Method*)m)->method_holder(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
534 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
535 |
if (m->is_klass()) { |
14588
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14294
diff
changeset
|
536 |
append_oop_references(&oops, (Klass*)m); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
537 |
} else { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
538 |
// XXX This will currently occur for MDO which don't |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
539 |
// have a backpointer. This has to be fixed later. |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
540 |
m->print(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
541 |
ShouldNotReachHere(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
542 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
543 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
544 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
545 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
546 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
547 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
548 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
549 |
if (!oop_recorder()->is_unused()) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
550 |
for (int i = 0; i < oop_recorder()->metadata_count(); i++) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
551 |
Metadata* m = oop_recorder()->metadata_at(i); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
552 |
if (oop_recorder()->is_real(m)) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
553 |
if (m->is_methodData()) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
554 |
m = ((MethodData*)m)->method(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
555 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
556 |
if (m->is_method()) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
557 |
m = ((Method*)m)->method_holder(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
558 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
559 |
if (m->is_klass()) { |
14588
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14294
diff
changeset
|
560 |
append_oop_references(&oops, (Klass*)m); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
561 |
} else { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
562 |
m->print(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
563 |
ShouldNotReachHere(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
564 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
565 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
566 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
567 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
568 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
569 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
570 |
// Add the class loader of Method* for the nmethod itself |
14588
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14294
diff
changeset
|
571 |
append_oop_references(&oops, mh->method_holder()); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
572 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
573 |
// Add any oops that we've found |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
574 |
Thread* thread = Thread::current(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
575 |
for (int i = 0; i < oops.length(); i++) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
576 |
oop_recorder()->find_index((jobject)thread->handle_area()->allocate_handle(oops.at(i))); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
577 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
578 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
579 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
580 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
581 |
|
6432
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
582 |
csize_t CodeBuffer::total_offset_of(CodeSection* cs) const { |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
583 |
csize_t size_so_far = 0; |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
584 |
for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) { |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
585 |
const CodeSection* cur_cs = code_section(n); |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
586 |
if (!cur_cs->is_empty()) { |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
587 |
size_so_far = cur_cs->align_at_start(size_so_far); |
1 | 588 |
} |
6432
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
589 |
if (cur_cs->index() == cs->index()) { |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
590 |
return size_so_far; |
1 | 591 |
} |
6432
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
592 |
size_so_far += cur_cs->size(); |
1 | 593 |
} |
594 |
ShouldNotReachHere(); |
|
595 |
return -1; |
|
596 |
} |
|
597 |
||
598 |
csize_t CodeBuffer::total_relocation_size() const { |
|
599 |
csize_t lsize = copy_relocations_to(NULL); // dry run only |
|
6418 | 600 |
csize_t csize = total_content_size(); |
1 | 601 |
csize_t total = RelocIterator::locs_and_index_size(csize, lsize); |
602 |
return (csize_t) align_size_up(total, HeapWordSize); |
|
603 |
} |
|
604 |
||
605 |
csize_t CodeBuffer::copy_relocations_to(CodeBlob* dest) const { |
|
606 |
address buf = NULL; |
|
607 |
csize_t buf_offset = 0; |
|
608 |
csize_t buf_limit = 0; |
|
609 |
if (dest != NULL) { |
|
610 |
buf = (address)dest->relocation_begin(); |
|
611 |
buf_limit = (address)dest->relocation_end() - buf; |
|
612 |
assert((uintptr_t)buf % HeapWordSize == 0, "buf must be fully aligned"); |
|
613 |
assert(buf_limit % HeapWordSize == 0, "buf must be evenly sized"); |
|
614 |
} |
|
615 |
// if dest == NULL, this is just the sizing pass |
|
616 |
||
617 |
csize_t code_end_so_far = 0; |
|
618 |
csize_t code_point_so_far = 0; |
|
6432
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
619 |
for (int n = (int) SECT_FIRST; n < (int)SECT_LIMIT; n++) { |
1 | 620 |
// pull relocs out of each section |
621 |
const CodeSection* cs = code_section(n); |
|
622 |
assert(!(cs->is_empty() && cs->locs_count() > 0), "sanity"); |
|
623 |
if (cs->is_empty()) continue; // skip trivial section |
|
624 |
relocInfo* lstart = cs->locs_start(); |
|
625 |
relocInfo* lend = cs->locs_end(); |
|
626 |
csize_t lsize = (csize_t)( (address)lend - (address)lstart ); |
|
627 |
csize_t csize = cs->size(); |
|
628 |
code_end_so_far = cs->align_at_start(code_end_so_far); |
|
629 |
||
630 |
if (lsize > 0) { |
|
631 |
// Figure out how to advance the combined relocation point |
|
632 |
// first to the beginning of this section. |
|
633 |
// We'll insert one or more filler relocs to span that gap. |
|
634 |
// (Don't bother to improve this by editing the first reloc's offset.) |
|
635 |
csize_t new_code_point = code_end_so_far; |
|
636 |
for (csize_t jump; |
|
637 |
code_point_so_far < new_code_point; |
|
638 |
code_point_so_far += jump) { |
|
639 |
jump = new_code_point - code_point_so_far; |
|
640 |
relocInfo filler = filler_relocInfo(); |
|
641 |
if (jump >= filler.addr_offset()) { |
|
642 |
jump = filler.addr_offset(); |
|
643 |
} else { // else shrink the filler to fit |
|
644 |
filler = relocInfo(relocInfo::none, jump); |
|
645 |
} |
|
646 |
if (buf != NULL) { |
|
647 |
assert(buf_offset + (csize_t)sizeof(filler) <= buf_limit, "filler in bounds"); |
|
648 |
*(relocInfo*)(buf+buf_offset) = filler; |
|
649 |
} |
|
650 |
buf_offset += sizeof(filler); |
|
651 |
} |
|
652 |
||
653 |
// Update code point and end to skip past this section: |
|
654 |
csize_t last_code_point = code_end_so_far + cs->locs_point_off(); |
|
655 |
assert(code_point_so_far <= last_code_point, "sanity"); |
|
656 |
code_point_so_far = last_code_point; // advance past this guy's relocs |
|
657 |
} |
|
658 |
code_end_so_far += csize; // advance past this guy's instructions too |
|
659 |
||
660 |
// Done with filler; emit the real relocations: |
|
661 |
if (buf != NULL && lsize != 0) { |
|
662 |
assert(buf_offset + lsize <= buf_limit, "target in bounds"); |
|
663 |
assert((uintptr_t)lstart % HeapWordSize == 0, "sane start"); |
|
664 |
if (buf_offset % HeapWordSize == 0) { |
|
665 |
// Use wordwise copies if possible: |
|
666 |
Copy::disjoint_words((HeapWord*)lstart, |
|
667 |
(HeapWord*)(buf+buf_offset), |
|
668 |
(lsize + HeapWordSize-1) / HeapWordSize); |
|
669 |
} else { |
|
5883
8dc4bdc132d5
6730276: JDI_REGRESSION tests fail with "Error: count must be non-zero" error on x86
kvn
parents:
5547
diff
changeset
|
670 |
Copy::conjoint_jbytes(lstart, buf+buf_offset, lsize); |
1 | 671 |
} |
672 |
} |
|
673 |
buf_offset += lsize; |
|
674 |
} |
|
675 |
||
676 |
// Align end of relocation info in target. |
|
677 |
while (buf_offset % HeapWordSize != 0) { |
|
678 |
if (buf != NULL) { |
|
679 |
relocInfo padding = relocInfo(relocInfo::none, 0); |
|
680 |
assert(buf_offset + (csize_t)sizeof(padding) <= buf_limit, "padding in bounds"); |
|
681 |
*(relocInfo*)(buf+buf_offset) = padding; |
|
682 |
} |
|
683 |
buf_offset += sizeof(relocInfo); |
|
684 |
} |
|
685 |
||
6418 | 686 |
assert(code_end_so_far == total_content_size(), "sanity"); |
1 | 687 |
|
688 |
// Account for index: |
|
689 |
if (buf != NULL) { |
|
690 |
RelocIterator::create_index(dest->relocation_begin(), |
|
691 |
buf_offset / sizeof(relocInfo), |
|
692 |
dest->relocation_end()); |
|
693 |
} |
|
694 |
||
695 |
return buf_offset; |
|
696 |
} |
|
697 |
||
698 |
void CodeBuffer::copy_code_to(CodeBlob* dest_blob) { |
|
699 |
#ifndef PRODUCT |
|
700 |
if (PrintNMethods && (WizardMode || Verbose)) { |
|
701 |
tty->print("done with CodeBuffer:"); |
|
702 |
((CodeBuffer*)this)->print(); |
|
703 |
} |
|
704 |
#endif //PRODUCT |
|
705 |
||
6418 | 706 |
CodeBuffer dest(dest_blob); |
707 |
assert(dest_blob->content_size() >= total_content_size(), "good sizing"); |
|
1 | 708 |
this->compute_final_layout(&dest); |
709 |
relocate_code_to(&dest); |
|
710 |
||
16368
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
711 |
// transfer strings and comments from buffer to blob |
26432 | 712 |
dest_blob->set_strings(_code_strings); |
1 | 713 |
|
714 |
// Done moving code bytes; were they the right size? |
|
6418 | 715 |
assert(round_to(dest.total_content_size(), oopSize) == dest_blob->content_size(), "sanity"); |
1 | 716 |
|
717 |
// Flush generated code |
|
6418 | 718 |
ICache::invalidate_range(dest_blob->code_begin(), dest_blob->code_size()); |
1 | 719 |
} |
720 |
||
6432
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
721 |
// Move all my code into another code buffer. Consult applicable |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
722 |
// relocs to repair embedded addresses. The layout in the destination |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
723 |
// CodeBuffer is different to the source CodeBuffer: the destination |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
724 |
// CodeBuffer gets the final layout (consts, insts, stubs in order of |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
725 |
// ascending address). |
1 | 726 |
void CodeBuffer::relocate_code_to(CodeBuffer* dest) const { |
10964
97771fdc4ad2
7103380: assertion failure with -XX:+PrintNativeNMethods
never
parents:
7440
diff
changeset
|
727 |
address dest_end = dest->_total_start + dest->_total_size; |
97771fdc4ad2
7103380: assertion failure with -XX:+PrintNativeNMethods
never
parents:
7440
diff
changeset
|
728 |
address dest_filled = NULL; |
6432
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
729 |
for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) { |
1 | 730 |
// pull code out of each section |
731 |
const CodeSection* cs = code_section(n); |
|
732 |
if (cs->is_empty()) continue; // skip trivial section |
|
733 |
CodeSection* dest_cs = dest->code_section(n); |
|
734 |
assert(cs->size() == dest_cs->size(), "sanity"); |
|
735 |
csize_t usize = dest_cs->size(); |
|
736 |
csize_t wsize = align_size_up(usize, HeapWordSize); |
|
737 |
assert(dest_cs->start() + wsize <= dest_end, "no overflow"); |
|
738 |
// Copy the code as aligned machine words. |
|
739 |
// This may also include an uninitialized partial word at the end. |
|
740 |
Copy::disjoint_words((HeapWord*)cs->start(), |
|
741 |
(HeapWord*)dest_cs->start(), |
|
742 |
wsize / HeapWordSize); |
|
743 |
||
744 |
if (dest->blob() == NULL) { |
|
745 |
// Destination is a final resting place, not just another buffer. |
|
746 |
// Normalize uninitialized bytes in the final padding. |
|
747 |
Copy::fill_to_bytes(dest_cs->end(), dest_cs->remaining(), |
|
748 |
Assembler::code_fill_byte()); |
|
749 |
} |
|
10964
97771fdc4ad2
7103380: assertion failure with -XX:+PrintNativeNMethods
never
parents:
7440
diff
changeset
|
750 |
// Keep track of the highest filled address |
97771fdc4ad2
7103380: assertion failure with -XX:+PrintNativeNMethods
never
parents:
7440
diff
changeset
|
751 |
dest_filled = MAX2(dest_filled, dest_cs->end() + dest_cs->remaining()); |
1 | 752 |
|
753 |
assert(cs->locs_start() != (relocInfo*)badAddress, |
|
754 |
"this section carries no reloc storage, but reloc was attempted"); |
|
755 |
||
756 |
// Make the new code copy use the old copy's relocations: |
|
757 |
dest_cs->initialize_locs_from(cs); |
|
14624 | 758 |
} |
1 | 759 |
|
14624 | 760 |
// Do relocation after all sections are copied. |
761 |
// This is necessary if the code uses constants in stubs, which are |
|
762 |
// relocated when the corresponding instruction in the code (e.g., a |
|
763 |
// call) is relocated. Stubs are placed behind the main code |
|
764 |
// section, so that section has to be copied before relocating. |
|
765 |
for (int n = (int) SECT_FIRST; n < (int)SECT_LIMIT; n++) { |
|
766 |
// pull code out of each section |
|
767 |
const CodeSection* cs = code_section(n); |
|
768 |
if (cs->is_empty()) continue; // skip trivial section |
|
769 |
CodeSection* dest_cs = dest->code_section(n); |
|
1 | 770 |
{ // Repair the pc relative information in the code after the move |
771 |
RelocIterator iter(dest_cs); |
|
772 |
while (iter.next()) { |
|
773 |
iter.reloc()->fix_relocation_after_move(this, dest); |
|
774 |
} |
|
775 |
} |
|
776 |
} |
|
10964
97771fdc4ad2
7103380: assertion failure with -XX:+PrintNativeNMethods
never
parents:
7440
diff
changeset
|
777 |
|
14294 | 778 |
if (dest->blob() == NULL && dest_filled != NULL) { |
10964
97771fdc4ad2
7103380: assertion failure with -XX:+PrintNativeNMethods
never
parents:
7440
diff
changeset
|
779 |
// Destination is a final resting place, not just another buffer. |
97771fdc4ad2
7103380: assertion failure with -XX:+PrintNativeNMethods
never
parents:
7440
diff
changeset
|
780 |
// Normalize uninitialized bytes in the final padding. |
97771fdc4ad2
7103380: assertion failure with -XX:+PrintNativeNMethods
never
parents:
7440
diff
changeset
|
781 |
Copy::fill_to_bytes(dest_filled, dest_end - dest_filled, |
97771fdc4ad2
7103380: assertion failure with -XX:+PrintNativeNMethods
never
parents:
7440
diff
changeset
|
782 |
Assembler::code_fill_byte()); |
97771fdc4ad2
7103380: assertion failure with -XX:+PrintNativeNMethods
never
parents:
7440
diff
changeset
|
783 |
|
97771fdc4ad2
7103380: assertion failure with -XX:+PrintNativeNMethods
never
parents:
7440
diff
changeset
|
784 |
} |
1 | 785 |
} |
786 |
||
787 |
csize_t CodeBuffer::figure_expanded_capacities(CodeSection* which_cs, |
|
788 |
csize_t amount, |
|
789 |
csize_t* new_capacity) { |
|
790 |
csize_t new_total_cap = 0; |
|
791 |
||
6432
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
792 |
for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) { |
1 | 793 |
const CodeSection* sect = code_section(n); |
794 |
||
795 |
if (!sect->is_empty()) { |
|
6432
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
796 |
// Compute initial padding; assign it to the previous section, |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
797 |
// even if it's empty (e.g. consts section can be empty). |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
798 |
// Cf. compute_final_layout |
1 | 799 |
csize_t padding = sect->align_at_start(new_total_cap) - new_total_cap; |
800 |
if (padding != 0) { |
|
801 |
new_total_cap += padding; |
|
6432
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
802 |
assert(n - 1 >= SECT_FIRST, "sanity"); |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
803 |
new_capacity[n - 1] += padding; |
1 | 804 |
} |
805 |
} |
|
806 |
||
807 |
csize_t exp = sect->size(); // 100% increase |
|
808 |
if ((uint)exp < 4*K) exp = 4*K; // minimum initial increase |
|
809 |
if (sect == which_cs) { |
|
810 |
if (exp < amount) exp = amount; |
|
811 |
if (StressCodeBuffers) exp = amount; // expand only slightly |
|
812 |
} else if (n == SECT_INSTS) { |
|
813 |
// scale down inst increases to a more modest 25% |
|
814 |
exp = 4*K + ((exp - 4*K) >> 2); |
|
815 |
if (StressCodeBuffers) exp = amount / 2; // expand only slightly |
|
816 |
} else if (sect->is_empty()) { |
|
817 |
// do not grow an empty secondary section |
|
818 |
exp = 0; |
|
819 |
} |
|
820 |
// Allow for inter-section slop: |
|
821 |
exp += CodeSection::end_slop(); |
|
822 |
csize_t new_cap = sect->size() + exp; |
|
823 |
if (new_cap < sect->capacity()) { |
|
824 |
// No need to expand after all. |
|
825 |
new_cap = sect->capacity(); |
|
826 |
} |
|
827 |
new_capacity[n] = new_cap; |
|
828 |
new_total_cap += new_cap; |
|
829 |
} |
|
830 |
||
831 |
return new_total_cap; |
|
832 |
} |
|
833 |
||
834 |
void CodeBuffer::expand(CodeSection* which_cs, csize_t amount) { |
|
835 |
#ifndef PRODUCT |
|
836 |
if (PrintNMethods && (WizardMode || Verbose)) { |
|
837 |
tty->print("expanding CodeBuffer:"); |
|
838 |
this->print(); |
|
839 |
} |
|
840 |
||
841 |
if (StressCodeBuffers && blob() != NULL) { |
|
842 |
static int expand_count = 0; |
|
843 |
if (expand_count >= 0) expand_count += 1; |
|
844 |
if (expand_count > 100 && is_power_of_2(expand_count)) { |
|
845 |
tty->print_cr("StressCodeBuffers: have expanded %d times", expand_count); |
|
846 |
// simulate an occasional allocation failure: |
|
847 |
free_blob(); |
|
848 |
} |
|
849 |
} |
|
850 |
#endif //PRODUCT |
|
851 |
||
852 |
// Resizing must be allowed |
|
853 |
{ |
|
854 |
if (blob() == NULL) return; // caller must check for blob == NULL |
|
855 |
for (int n = 0; n < (int)SECT_LIMIT; n++) { |
|
856 |
guarantee(!code_section(n)->is_frozen(), "resizing not allowed when frozen"); |
|
857 |
} |
|
858 |
} |
|
859 |
||
860 |
// Figure new capacity for each section. |
|
861 |
csize_t new_capacity[SECT_LIMIT]; |
|
862 |
csize_t new_total_cap |
|
863 |
= figure_expanded_capacities(which_cs, amount, new_capacity); |
|
864 |
||
865 |
// Create a new (temporary) code buffer to hold all the new data |
|
866 |
CodeBuffer cb(name(), new_total_cap, 0); |
|
867 |
if (cb.blob() == NULL) { |
|
868 |
// Failed to allocate in code cache. |
|
869 |
free_blob(); |
|
870 |
return; |
|
871 |
} |
|
872 |
||
873 |
// Create an old code buffer to remember which addresses used to go where. |
|
874 |
// This will be useful when we do final assembly into the code cache, |
|
875 |
// because we will need to know how to warp any internal address that |
|
876 |
// has been created at any time in this CodeBuffer's past. |
|
877 |
CodeBuffer* bxp = new CodeBuffer(_total_start, _total_size); |
|
878 |
bxp->take_over_code_from(this); // remember the old undersized blob |
|
879 |
DEBUG_ONLY(this->_blob = NULL); // silence a later assert |
|
880 |
bxp->_before_expand = this->_before_expand; |
|
881 |
this->_before_expand = bxp; |
|
882 |
||
883 |
// Give each section its required (expanded) capacity. |
|
6432
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
884 |
for (int n = (int)SECT_LIMIT-1; n >= SECT_FIRST; n--) { |
1 | 885 |
CodeSection* cb_sect = cb.code_section(n); |
886 |
CodeSection* this_sect = code_section(n); |
|
887 |
if (new_capacity[n] == 0) continue; // already nulled out |
|
6432
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
888 |
if (n != SECT_INSTS) { |
1 | 889 |
cb.initialize_section_size(cb_sect, new_capacity[n]); |
890 |
} |
|
891 |
assert(cb_sect->capacity() >= new_capacity[n], "big enough"); |
|
892 |
address cb_start = cb_sect->start(); |
|
893 |
cb_sect->set_end(cb_start + this_sect->size()); |
|
894 |
if (this_sect->mark() == NULL) { |
|
895 |
cb_sect->clear_mark(); |
|
896 |
} else { |
|
897 |
cb_sect->set_mark(cb_start + this_sect->mark_off()); |
|
898 |
} |
|
899 |
} |
|
900 |
||
901 |
// Move all the code and relocations to the new blob: |
|
902 |
relocate_code_to(&cb); |
|
903 |
||
904 |
// Copy the temporary code buffer into the current code buffer. |
|
905 |
// Basically, do {*this = cb}, except for some control information. |
|
906 |
this->take_over_code_from(&cb); |
|
907 |
cb.set_blob(NULL); |
|
908 |
||
909 |
// Zap the old code buffer contents, to avoid mistakenly using them. |
|
910 |
debug_only(Copy::fill_to_bytes(bxp->_total_start, bxp->_total_size, |
|
911 |
badCodeHeapFreeVal)); |
|
912 |
||
913 |
_decode_begin = NULL; // sanity |
|
914 |
||
915 |
// Make certain that the new sections are all snugly inside the new blob. |
|
10983
9ab65f4cec18
7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents:
10964
diff
changeset
|
916 |
verify_section_allocation(); |
1 | 917 |
|
918 |
#ifndef PRODUCT |
|
919 |
if (PrintNMethods && (WizardMode || Verbose)) { |
|
920 |
tty->print("expanded CodeBuffer:"); |
|
921 |
this->print(); |
|
922 |
} |
|
923 |
#endif //PRODUCT |
|
924 |
} |
|
925 |
||
926 |
void CodeBuffer::take_over_code_from(CodeBuffer* cb) { |
|
927 |
// Must already have disposed of the old blob somehow. |
|
928 |
assert(blob() == NULL, "must be empty"); |
|
929 |
#ifdef ASSERT |
|
930 |
||
931 |
#endif |
|
932 |
// Take the new blob away from cb. |
|
933 |
set_blob(cb->blob()); |
|
934 |
// Take over all the section pointers. |
|
935 |
for (int n = 0; n < (int)SECT_LIMIT; n++) { |
|
936 |
CodeSection* cb_sect = cb->code_section(n); |
|
937 |
CodeSection* this_sect = code_section(n); |
|
938 |
this_sect->take_over_code_from(cb_sect); |
|
939 |
} |
|
940 |
_overflow_arena = cb->_overflow_arena; |
|
941 |
// Make sure the old cb won't try to use it or free it. |
|
942 |
DEBUG_ONLY(cb->_blob = (BufferBlob*)badAddress); |
|
943 |
} |
|
944 |
||
10983
9ab65f4cec18
7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents:
10964
diff
changeset
|
945 |
void CodeBuffer::verify_section_allocation() { |
1 | 946 |
address tstart = _total_start; |
10983
9ab65f4cec18
7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents:
10964
diff
changeset
|
947 |
if (tstart == badAddress) return; // smashed by set_blob(NULL) |
1 | 948 |
address tend = tstart + _total_size; |
949 |
if (_blob != NULL) { |
|
10983
9ab65f4cec18
7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents:
10964
diff
changeset
|
950 |
|
9ab65f4cec18
7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents:
10964
diff
changeset
|
951 |
guarantee(tstart >= _blob->content_begin(), "sanity"); |
9ab65f4cec18
7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents:
10964
diff
changeset
|
952 |
guarantee(tend <= _blob->content_end(), "sanity"); |
1 | 953 |
} |
6432
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
954 |
// Verify disjointness. |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
955 |
for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) { |
1 | 956 |
CodeSection* sect = code_section(n); |
6432
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
957 |
if (!sect->is_allocated() || sect->is_empty()) continue; |
10983
9ab65f4cec18
7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents:
10964
diff
changeset
|
958 |
guarantee((intptr_t)sect->start() % sect->alignment() == 0 |
1 | 959 |
|| sect->is_empty() || _blob == NULL, |
960 |
"start is aligned"); |
|
6432
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
961 |
for (int m = (int) SECT_FIRST; m < (int) SECT_LIMIT; m++) { |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
962 |
CodeSection* other = code_section(m); |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
963 |
if (!other->is_allocated() || other == sect) continue; |
10983
9ab65f4cec18
7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents:
10964
diff
changeset
|
964 |
guarantee(!other->contains(sect->start() ), "sanity"); |
6432
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
965 |
// limit is an exclusive address and can be the start of another |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
966 |
// section. |
10983
9ab65f4cec18
7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents:
10964
diff
changeset
|
967 |
guarantee(!other->contains(sect->limit() - 1), "sanity"); |
6432
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
6418
diff
changeset
|
968 |
} |
10983
9ab65f4cec18
7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents:
10964
diff
changeset
|
969 |
guarantee(sect->end() <= tend, "sanity"); |
9ab65f4cec18
7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents:
10964
diff
changeset
|
970 |
guarantee(sect->end() <= sect->limit(), "sanity"); |
1 | 971 |
} |
972 |
} |
|
10983
9ab65f4cec18
7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents:
10964
diff
changeset
|
973 |
|
9ab65f4cec18
7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents:
10964
diff
changeset
|
974 |
void CodeBuffer::log_section_sizes(const char* name) { |
9ab65f4cec18
7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents:
10964
diff
changeset
|
975 |
if (xtty != NULL) { |
24002
4e6a72032a99
8005079: fix LogCompilation for incremental inlining
roland
parents:
22234
diff
changeset
|
976 |
ttyLocker ttyl; |
10983
9ab65f4cec18
7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents:
10964
diff
changeset
|
977 |
// log info about buffer usage |
9ab65f4cec18
7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents:
10964
diff
changeset
|
978 |
xtty->print_cr("<blob name='%s' size='%d'>", name, _total_size); |
9ab65f4cec18
7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents:
10964
diff
changeset
|
979 |
for (int n = (int) CodeBuffer::SECT_FIRST; n < (int) CodeBuffer::SECT_LIMIT; n++) { |
9ab65f4cec18
7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents:
10964
diff
changeset
|
980 |
CodeSection* sect = code_section(n); |
9ab65f4cec18
7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents:
10964
diff
changeset
|
981 |
if (!sect->is_allocated() || sect->is_empty()) continue; |
9ab65f4cec18
7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents:
10964
diff
changeset
|
982 |
xtty->print_cr("<sect index='%d' size='" SIZE_FORMAT "' free='" SIZE_FORMAT "'/>", |
9ab65f4cec18
7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents:
10964
diff
changeset
|
983 |
n, sect->limit() - sect->start(), sect->limit() - sect->end()); |
9ab65f4cec18
7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents:
10964
diff
changeset
|
984 |
} |
9ab65f4cec18
7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents:
10964
diff
changeset
|
985 |
xtty->print_cr("</blob>"); |
9ab65f4cec18
7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents:
10964
diff
changeset
|
986 |
} |
9ab65f4cec18
7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents:
10964
diff
changeset
|
987 |
} |
1 | 988 |
|
989 |
#ifndef PRODUCT |
|
990 |
||
991 |
void CodeSection::dump() { |
|
992 |
address ptr = start(); |
|
993 |
for (csize_t step; ptr < end(); ptr += step) { |
|
994 |
step = end() - ptr; |
|
995 |
if (step > jintSize * 4) step = jintSize * 4; |
|
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
24002
diff
changeset
|
996 |
tty->print(INTPTR_FORMAT ": ", p2i(ptr)); |
1 | 997 |
while (step > 0) { |
998 |
tty->print(" " PTR32_FORMAT, *(jint*)ptr); |
|
999 |
ptr += jintSize; |
|
1000 |
} |
|
1001 |
tty->cr(); |
|
1002 |
} |
|
1003 |
} |
|
1004 |
||
1005 |
||
1006 |
void CodeSection::decode() { |
|
1007 |
Disassembler::decode(start(), end()); |
|
1008 |
} |
|
1009 |
||
1010 |
||
1011 |
void CodeBuffer::block_comment(intptr_t offset, const char * comment) { |
|
26432 | 1012 |
_code_strings.add_comment(offset, comment); |
16368
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1013 |
} |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1014 |
|
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1015 |
const char* CodeBuffer::code_string(const char* str) { |
26432 | 1016 |
return _code_strings.add_string(str); |
1 | 1017 |
} |
1018 |
||
16368
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1019 |
class CodeString: public CHeapObj<mtCode> { |
1 | 1020 |
private: |
16368
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1021 |
friend class CodeStrings; |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1022 |
const char * _string; |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1023 |
CodeString* _next; |
1 | 1024 |
intptr_t _offset; |
1025 |
||
16368
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1026 |
~CodeString() { |
1 | 1027 |
assert(_next == NULL, "wrong interface for freeing list"); |
16368
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1028 |
os::free((void*)_string, mtCode); |
1 | 1029 |
} |
1030 |
||
16368
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1031 |
bool is_comment() const { return _offset >= 0; } |
1 | 1032 |
|
16368
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1033 |
public: |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1034 |
CodeString(const char * string, intptr_t offset = -1) |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1035 |
: _next(NULL), _offset(offset) { |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1036 |
_string = os::strdup(string, mtCode); |
1 | 1037 |
} |
13887
89b873bcc55b
7200163: add CodeComments functionality to assember stubs
kvn
parents:
13728
diff
changeset
|
1038 |
|
16368
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1039 |
const char * string() const { return _string; } |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1040 |
intptr_t offset() const { assert(_offset >= 0, "offset for non comment?"); return _offset; } |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1041 |
CodeString* next() const { return _next; } |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1042 |
|
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1043 |
void set_next(CodeString* next) { _next = next; } |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1044 |
|
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1045 |
CodeString* first_comment() { |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1046 |
if (is_comment()) { |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1047 |
return this; |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1048 |
} else { |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1049 |
return next_comment(); |
13887
89b873bcc55b
7200163: add CodeComments functionality to assember stubs
kvn
parents:
13728
diff
changeset
|
1050 |
} |
16368
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1051 |
} |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1052 |
CodeString* next_comment() const { |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1053 |
CodeString* s = _next; |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1054 |
while (s != NULL && !s->is_comment()) { |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1055 |
s = s->_next; |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1056 |
} |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1057 |
return s; |
13887
89b873bcc55b
7200163: add CodeComments functionality to assember stubs
kvn
parents:
13728
diff
changeset
|
1058 |
} |
1 | 1059 |
}; |
1060 |
||
16368
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1061 |
CodeString* CodeStrings::find(intptr_t offset) const { |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1062 |
CodeString* a = _strings->first_comment(); |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1063 |
while (a != NULL && a->offset() != offset) { |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1064 |
a = a->next_comment(); |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1065 |
} |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1066 |
return a; |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1067 |
} |
1 | 1068 |
|
16368
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1069 |
// Convenience for add_comment. |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1070 |
CodeString* CodeStrings::find_last(intptr_t offset) const { |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1071 |
CodeString* a = find(offset); |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1072 |
if (a != NULL) { |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1073 |
CodeString* c = NULL; |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1074 |
while (((c = a->next_comment()) != NULL) && (c->offset() == offset)) { |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1075 |
a = c; |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1076 |
} |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1077 |
} |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1078 |
return a; |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1079 |
} |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1080 |
|
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1081 |
void CodeStrings::add_comment(intptr_t offset, const char * comment) { |
26432 | 1082 |
check_valid(); |
16368
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1083 |
CodeString* c = new CodeString(comment, offset); |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1084 |
CodeString* inspos = (_strings == NULL) ? NULL : find_last(offset); |
13887
89b873bcc55b
7200163: add CodeComments functionality to assember stubs
kvn
parents:
13728
diff
changeset
|
1085 |
|
89b873bcc55b
7200163: add CodeComments functionality to assember stubs
kvn
parents:
13728
diff
changeset
|
1086 |
if (inspos) { |
89b873bcc55b
7200163: add CodeComments functionality to assember stubs
kvn
parents:
13728
diff
changeset
|
1087 |
// insert after already existing comments with same offset |
89b873bcc55b
7200163: add CodeComments functionality to assember stubs
kvn
parents:
13728
diff
changeset
|
1088 |
c->set_next(inspos->next()); |
89b873bcc55b
7200163: add CodeComments functionality to assember stubs
kvn
parents:
13728
diff
changeset
|
1089 |
inspos->set_next(c); |
1 | 1090 |
} else { |
13887
89b873bcc55b
7200163: add CodeComments functionality to assember stubs
kvn
parents:
13728
diff
changeset
|
1091 |
// no comments with such offset, yet. Insert before anything else. |
16368
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1092 |
c->set_next(_strings); |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1093 |
_strings = c; |
1 | 1094 |
} |
1095 |
} |
|
1096 |
||
16368
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1097 |
void CodeStrings::assign(CodeStrings& other) { |
26432 | 1098 |
other.check_valid(); |
1099 |
// Cannot do following because CodeStrings constructor is not alway run! |
|
1100 |
assert(is_null(), "Cannot assign onto non-empty CodeStrings"); |
|
16368
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1101 |
_strings = other._strings; |
26432 | 1102 |
other.set_null_and_invalidate(); |
1103 |
} |
|
1104 |
||
1105 |
// Deep copy of CodeStrings for consistent memory management. |
|
1106 |
// Only used for actual disassembly so this is cheaper than reference counting |
|
1107 |
// for the "normal" fastdebug case. |
|
1108 |
void CodeStrings::copy(CodeStrings& other) { |
|
1109 |
other.check_valid(); |
|
1110 |
check_valid(); |
|
1111 |
assert(is_null(), "Cannot copy onto non-empty CodeStrings"); |
|
1112 |
CodeString* n = other._strings; |
|
1113 |
CodeString** ps = &_strings; |
|
1114 |
while (n != NULL) { |
|
1115 |
*ps = new CodeString(n->string(),n->offset()); |
|
1116 |
ps = &((*ps)->_next); |
|
1117 |
n = n->next(); |
|
1118 |
} |
|
1 | 1119 |
} |
1120 |
||
16368
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1121 |
void CodeStrings::print_block_comment(outputStream* stream, intptr_t offset) const { |
26432 | 1122 |
check_valid(); |
1123 |
if (_strings != NULL) { |
|
16368
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1124 |
CodeString* c = find(offset); |
1 | 1125 |
while (c && c->offset() == offset) { |
347
df859fcca515
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
1
diff
changeset
|
1126 |
stream->bol(); |
1 | 1127 |
stream->print(" ;; "); |
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
24002
diff
changeset
|
1128 |
stream->print_cr("%s", c->string()); |
16368
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1129 |
c = c->next_comment(); |
1 | 1130 |
} |
1131 |
} |
|
1132 |
} |
|
1133 |
||
26432 | 1134 |
// Also sets isNull() |
16368
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1135 |
void CodeStrings::free() { |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1136 |
CodeString* n = _strings; |
1 | 1137 |
while (n) { |
1138 |
// unlink the node from the list saving a pointer to the next |
|
16368
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1139 |
CodeString* p = n->next(); |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1140 |
n->set_next(NULL); |
1 | 1141 |
delete n; |
1142 |
n = p; |
|
1143 |
} |
|
26432 | 1144 |
set_null_and_invalidate(); |
1 | 1145 |
} |
1146 |
||
16368
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1147 |
const char* CodeStrings::add_string(const char * string) { |
26432 | 1148 |
check_valid(); |
16368
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1149 |
CodeString* s = new CodeString(string); |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1150 |
s->set_next(_strings); |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1151 |
_strings = s; |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1152 |
assert(s->string() != NULL, "should have a string"); |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1153 |
return s->string(); |
713209c45a82
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
14816
diff
changeset
|
1154 |
} |
1 | 1155 |
|
1156 |
void CodeBuffer::decode() { |
|
13887
89b873bcc55b
7200163: add CodeComments functionality to assember stubs
kvn
parents:
13728
diff
changeset
|
1157 |
ttyLocker ttyl; |
6418 | 1158 |
Disassembler::decode(decode_begin(), insts_end()); |
1159 |
_decode_begin = insts_end(); |
|
1 | 1160 |
} |
1161 |
||
1162 |
||
1163 |
void CodeBuffer::skip_decode() { |
|
6418 | 1164 |
_decode_begin = insts_end(); |
1 | 1165 |
} |
1166 |
||
1167 |
||
1168 |
void CodeBuffer::decode_all() { |
|
13887
89b873bcc55b
7200163: add CodeComments functionality to assember stubs
kvn
parents:
13728
diff
changeset
|
1169 |
ttyLocker ttyl; |
1 | 1170 |
for (int n = 0; n < (int)SECT_LIMIT; n++) { |
1171 |
// dump contents of each section |
|
1172 |
CodeSection* cs = code_section(n); |
|
1173 |
tty->print_cr("! %s:", code_section_name(n)); |
|
1174 |
if (cs != consts()) |
|
1175 |
cs->decode(); |
|
1176 |
else |
|
1177 |
cs->dump(); |
|
1178 |
} |
|
1179 |
} |
|
1180 |
||
1181 |
||
1182 |
void CodeSection::print(const char* name) { |
|
1183 |
csize_t locs_size = locs_end() - locs_start(); |
|
1184 |
tty->print_cr(" %7s.code = " PTR_FORMAT " : " PTR_FORMAT " : " PTR_FORMAT " (%d of %d)%s", |
|
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
24002
diff
changeset
|
1185 |
name, p2i(start()), p2i(end()), p2i(limit()), size(), capacity(), |
1 | 1186 |
is_frozen()? " [frozen]": ""); |
1187 |
tty->print_cr(" %7s.locs = " PTR_FORMAT " : " PTR_FORMAT " : " PTR_FORMAT " (%d of %d) point=%d", |
|
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
24002
diff
changeset
|
1188 |
name, p2i(locs_start()), p2i(locs_end()), p2i(locs_limit()), locs_size, locs_capacity(), locs_point_off()); |
1 | 1189 |
if (PrintRelocations) { |
1190 |
RelocIterator iter(this); |
|
1191 |
iter.print(); |
|
1192 |
} |
|
1193 |
} |
|
1194 |
||
1195 |
void CodeBuffer::print() { |
|
1196 |
if (this == NULL) { |
|
1197 |
tty->print_cr("NULL CodeBuffer pointer"); |
|
1198 |
return; |
|
1199 |
} |
|
1200 |
||
1201 |
tty->print_cr("CodeBuffer:"); |
|
1202 |
for (int n = 0; n < (int)SECT_LIMIT; n++) { |
|
1203 |
// print each section |
|
1204 |
CodeSection* cs = code_section(n); |
|
1205 |
cs->print(code_section_name(n)); |
|
1206 |
} |
|
1207 |
} |
|
1208 |
||
1209 |
#endif // PRODUCT |