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