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