author | dholmes |
Mon, 06 May 2019 21:23:23 -0400 | |
changeset 54729 | f72402697b2f |
parent 54042 | 6dd6f988b4e4 |
child 54786 | ebf733a324d4 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
49359
59f6547e151f
8199264: Remove universe.inline.hpp to simplify include dependencies
stefank
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 1997, 2018, 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:
1
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
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:
1
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "classfile/stackMapTableFormat.hpp" |
|
27 |
#include "interpreter/bytecodes.hpp" |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13476
diff
changeset
|
28 |
#include "memory/metadataFactory.hpp" |
7397 | 29 |
#include "memory/oopFactory.hpp" |
49359
59f6547e151f
8199264: Remove universe.inline.hpp to simplify include dependencies
stefank
parents:
47216
diff
changeset
|
30 |
#include "memory/universe.hpp" |
54042
6dd6f988b4e4
8219860: Cleanup ClassFileParser::parse_linenumber_table
redestad
parents:
49359
diff
changeset
|
31 |
#include "oops/method.inline.hpp" |
7397 | 32 |
#include "oops/oop.inline.hpp" |
33 |
#include "runtime/handles.inline.hpp" |
|
34 |
#include "runtime/relocator.hpp" |
|
1 | 35 |
|
36 |
#define MAX_METHOD_LENGTH 65535 |
|
37 |
||
38 |
#define MAX_SHORT ((1 << 15) - 1) |
|
39 |
#define MIN_SHORT (- (1 << 15)) |
|
40 |
||
41 |
// Encapsulates a code change request. There are 3 types. |
|
42 |
// General instruction, jump instruction, and table/lookup switches |
|
43 |
// |
|
44 |
class ChangeItem : public ResourceObj { |
|
45 |
int _bci; |
|
46 |
public: |
|
47 |
ChangeItem(int bci) { _bci = bci; } |
|
48 |
virtual bool handle_code_change(Relocator *r) = 0; |
|
49 |
||
50 |
// type info |
|
51 |
virtual bool is_widen() { return false; } |
|
52 |
virtual bool is_jump_widen() { return false; } |
|
53 |
virtual bool is_switch_pad() { return false; } |
|
54 |
||
55 |
// accessors |
|
56 |
int bci() { return _bci; } |
|
57 |
void relocate(int break_bci, int delta) { if (_bci > break_bci) { _bci += delta; } } |
|
58 |
||
59 |
virtual bool adjust(int bci, int delta) { return false; } |
|
60 |
||
61 |
// debug |
|
62 |
virtual void print() = 0; |
|
63 |
}; |
|
64 |
||
65 |
class ChangeWiden : public ChangeItem { |
|
66 |
int _new_ilen; // New length of instruction at bci |
|
67 |
u_char* _inst_buffer; // New bytecodes |
|
68 |
public: |
|
69 |
ChangeWiden(int bci, int new_ilen, u_char* inst_buffer) : ChangeItem(bci) { |
|
70 |
_new_ilen = new_ilen; |
|
71 |
_inst_buffer = inst_buffer; |
|
72 |
} |
|
73 |
||
74 |
// Callback to do instruction |
|
75 |
bool handle_code_change(Relocator *r) { return r->handle_widen(bci(), _new_ilen, _inst_buffer); }; |
|
76 |
||
77 |
bool is_widen() { return true; } |
|
78 |
||
79 |
void print() { tty->print_cr("ChangeWiden. bci: %d New_ilen: %d", bci(), _new_ilen); } |
|
80 |
}; |
|
81 |
||
82 |
class ChangeJumpWiden : public ChangeItem { |
|
83 |
int _delta; // New length of instruction at bci |
|
84 |
public: |
|
85 |
ChangeJumpWiden(int bci, int delta) : ChangeItem(bci) { _delta = delta; } |
|
86 |
||
87 |
// Callback to do instruction |
|
88 |
bool handle_code_change(Relocator *r) { return r->handle_jump_widen(bci(), _delta); }; |
|
89 |
||
90 |
bool is_jump_widen() { return true; } |
|
91 |
||
92 |
// If the bci matches, adjust the delta in the change jump request. |
|
93 |
bool adjust(int jump_bci, int delta) { |
|
94 |
if (bci() == jump_bci) { |
|
95 |
if (_delta > 0) |
|
96 |
_delta += delta; |
|
97 |
else |
|
98 |
_delta -= delta; |
|
99 |
return true; |
|
100 |
} |
|
101 |
return false; |
|
102 |
} |
|
103 |
||
104 |
void print() { tty->print_cr("ChangeJumpWiden. bci: %d Delta: %d", bci(), _delta); } |
|
105 |
}; |
|
106 |
||
107 |
class ChangeSwitchPad : public ChangeItem { |
|
108 |
int _padding; |
|
109 |
bool _is_lookup_switch; |
|
110 |
public: |
|
111 |
ChangeSwitchPad(int bci, int padding, bool is_lookup_switch) : ChangeItem(bci) { |
|
112 |
_padding = padding; |
|
113 |
_is_lookup_switch = is_lookup_switch; |
|
114 |
} |
|
115 |
||
116 |
// Callback to do instruction |
|
117 |
bool handle_code_change(Relocator *r) { return r->handle_switch_pad(bci(), _padding, _is_lookup_switch); }; |
|
118 |
||
119 |
bool is_switch_pad() { return true; } |
|
120 |
int padding() { return _padding; } |
|
121 |
bool is_lookup_switch() { return _is_lookup_switch; } |
|
122 |
||
123 |
void print() { tty->print_cr("ChangeSwitchPad. bci: %d Padding: %d IsLookupSwitch: %d", bci(), _padding, _is_lookup_switch); } |
|
124 |
}; |
|
125 |
||
126 |
//----------------------------------------------------------------------------------------------------------- |
|
127 |
// Relocator code |
|
128 |
||
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
22551
diff
changeset
|
129 |
Relocator::Relocator(const methodHandle& m, RelocatorListener* listener) { |
1 | 130 |
set_method(m); |
131 |
set_code_length(method()->code_size()); |
|
132 |
set_code_array(NULL); |
|
133 |
// Allocate code array and copy bytecodes |
|
134 |
if (!expand_code_array(0)) { |
|
135 |
// Should have at least MAX_METHOD_LENGTH available or the verifier |
|
136 |
// would have failed. |
|
137 |
ShouldNotReachHere(); |
|
138 |
} |
|
139 |
set_compressed_line_number_table(NULL); |
|
140 |
set_compressed_line_number_table_size(0); |
|
141 |
_listener = listener; |
|
142 |
} |
|
143 |
||
144 |
// size is the new size of the instruction at bci. Hence, if size is less than the current |
|
22551 | 145 |
// instruction size, we will shrink the code. |
1 | 146 |
methodHandle Relocator::insert_space_at(int bci, int size, u_char inst_buffer[], TRAPS) { |
147 |
_changes = new GrowableArray<ChangeItem*> (10); |
|
148 |
_changes->push(new ChangeWiden(bci, size, inst_buffer)); |
|
149 |
||
150 |
if (TraceRelocator) { |
|
151 |
tty->print_cr("Space at: %d Size: %d", bci, size); |
|
152 |
_method->print(); |
|
153 |
_method->print_codes(); |
|
154 |
tty->print_cr("-------------------------------------------------"); |
|
155 |
} |
|
156 |
||
157 |
if (!handle_code_changes()) return methodHandle(); |
|
158 |
||
159 |
// Construct the new method |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13476
diff
changeset
|
160 |
methodHandle new_method = Method::clone_with_new_data(method(), |
1 | 161 |
code_array(), code_length(), |
162 |
compressed_line_number_table(), |
|
163 |
compressed_line_number_table_size(), |
|
164 |
CHECK_(methodHandle())); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13476
diff
changeset
|
165 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13476
diff
changeset
|
166 |
// Deallocate the old Method* from metadata |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13476
diff
changeset
|
167 |
ClassLoaderData* loader_data = method()->method_holder()->class_loader_data(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13476
diff
changeset
|
168 |
loader_data->add_to_deallocate_list(method()()); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13476
diff
changeset
|
169 |
|
1 | 170 |
set_method(new_method); |
171 |
||
172 |
if (TraceRelocator) { |
|
173 |
tty->print_cr("-------------------------------------------------"); |
|
174 |
tty->print_cr("new method"); |
|
175 |
_method->print_codes(); |
|
176 |
} |
|
177 |
||
178 |
return new_method; |
|
179 |
} |
|
180 |
||
181 |
||
182 |
bool Relocator::handle_code_changes() { |
|
183 |
assert(_changes != NULL, "changes vector must be initialized"); |
|
184 |
||
185 |
while (!_changes->is_empty()) { |
|
186 |
// Inv: everything is aligned. |
|
187 |
ChangeItem* ci = _changes->first(); |
|
188 |
||
189 |
if (TraceRelocator) { |
|
190 |
ci->print(); |
|
191 |
} |
|
192 |
||
193 |
// Execute operation |
|
194 |
if (!ci->handle_code_change(this)) return false; |
|
195 |
||
22551 | 196 |
// Shuffle items up |
1 | 197 |
for (int index = 1; index < _changes->length(); index++) { |
198 |
_changes->at_put(index-1, _changes->at(index)); |
|
199 |
} |
|
200 |
_changes->pop(); |
|
201 |
} |
|
202 |
return true; |
|
203 |
} |
|
204 |
||
205 |
||
206 |
bool Relocator::is_opcode_lookupswitch(Bytecodes::Code bc) { |
|
207 |
switch (bc) { |
|
208 |
case Bytecodes::_tableswitch: return false; |
|
209 |
case Bytecodes::_lookupswitch: // not rewritten on ia64 |
|
210 |
case Bytecodes::_fast_linearswitch: // rewritten _lookupswitch |
|
211 |
case Bytecodes::_fast_binaryswitch: return true; // rewritten _lookupswitch |
|
212 |
default: ShouldNotReachHere(); |
|
213 |
} |
|
214 |
return true; // dummy |
|
215 |
} |
|
216 |
||
217 |
// We need a special instruction size method, since lookupswitches and tableswitches might not be |
|
22551 | 218 |
// properly aligned during relocation |
1 | 219 |
int Relocator::rc_instr_len(int bci) { |
220 |
Bytecodes::Code bc= code_at(bci); |
|
221 |
switch (bc) { |
|
222 |
// In the case of switch instructions, see if we have the original |
|
223 |
// padding recorded. |
|
224 |
case Bytecodes::_tableswitch: |
|
225 |
case Bytecodes::_lookupswitch: |
|
226 |
case Bytecodes::_fast_linearswitch: |
|
227 |
case Bytecodes::_fast_binaryswitch: |
|
228 |
{ |
|
229 |
int pad = get_orig_switch_pad(bci, is_opcode_lookupswitch(bc)); |
|
230 |
if (pad == -1) { |
|
231 |
return instruction_length_at(bci); |
|
232 |
} |
|
233 |
// Otherwise, depends on the switch type. |
|
234 |
switch (bc) { |
|
235 |
case Bytecodes::_tableswitch: { |
|
236 |
int lo = int_at(bci + 1 + pad + 4 * 1); |
|
237 |
int hi = int_at(bci + 1 + pad + 4 * 2); |
|
238 |
int n = hi - lo + 1; |
|
239 |
return 1 + pad + 4*(3 + n); |
|
240 |
} |
|
241 |
case Bytecodes::_lookupswitch: |
|
242 |
case Bytecodes::_fast_linearswitch: |
|
243 |
case Bytecodes::_fast_binaryswitch: { |
|
244 |
int npairs = int_at(bci + 1 + pad + 4 * 1); |
|
245 |
return 1 + pad + 4*(2 + 2*npairs); |
|
246 |
} |
|
247 |
default: |
|
248 |
ShouldNotReachHere(); |
|
249 |
} |
|
250 |
} |
|
46630
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
38658
diff
changeset
|
251 |
default: |
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
38658
diff
changeset
|
252 |
break; |
1 | 253 |
} |
254 |
return instruction_length_at(bci); |
|
255 |
} |
|
256 |
||
257 |
// If a change item is recorded for "pc", with type "ct", returns the |
|
258 |
// associated padding, else -1. |
|
259 |
int Relocator::get_orig_switch_pad(int bci, bool is_lookup_switch) { |
|
260 |
for (int k = 0; k < _changes->length(); k++) { |
|
261 |
ChangeItem* ci = _changes->at(k); |
|
262 |
if (ci->is_switch_pad()) { |
|
263 |
ChangeSwitchPad* csp = (ChangeSwitchPad*)ci; |
|
264 |
if (csp->is_lookup_switch() == is_lookup_switch && csp->bci() == bci) { |
|
265 |
return csp->padding(); |
|
266 |
} |
|
267 |
} |
|
268 |
} |
|
269 |
return -1; |
|
270 |
} |
|
271 |
||
272 |
||
273 |
// Push a ChangeJumpWiden if it doesn't already exist on the work queue, |
|
274 |
// otherwise adjust the item already there by delta. The calculation for |
|
275 |
// new_delta is wrong for this because it uses the offset stored in the |
|
276 |
// code stream itself which wasn't fixed when item was pushed on the work queue. |
|
277 |
void Relocator::push_jump_widen(int bci, int delta, int new_delta) { |
|
278 |
for (int j = 0; j < _changes->length(); j++) { |
|
279 |
ChangeItem* ci = _changes->at(j); |
|
280 |
if (ci->adjust(bci, delta)) return; |
|
281 |
} |
|
282 |
_changes->push(new ChangeJumpWiden(bci, new_delta)); |
|
283 |
} |
|
284 |
||
285 |
||
286 |
// The current instruction of "c" is a jump; one of its offset starts |
|
287 |
// at "offset" and is a short if "isShort" is "TRUE", |
|
288 |
// and an integer otherwise. If the jump crosses "breakPC", change |
|
289 |
// the span of the jump by "delta". |
|
290 |
void Relocator::change_jump(int bci, int offset, bool is_short, int break_bci, int delta) { |
|
291 |
int bci_delta = (is_short) ? short_at(offset) : int_at(offset); |
|
292 |
int targ = bci + bci_delta; |
|
293 |
||
294 |
if ((bci <= break_bci && targ > break_bci) || |
|
295 |
(bci > break_bci && targ <= break_bci)) { |
|
296 |
int new_delta; |
|
297 |
if (bci_delta > 0) |
|
298 |
new_delta = bci_delta + delta; |
|
299 |
else |
|
300 |
new_delta = bci_delta - delta; |
|
301 |
||
302 |
if (is_short && ((new_delta > MAX_SHORT) || new_delta < MIN_SHORT)) { |
|
303 |
push_jump_widen(bci, delta, new_delta); |
|
304 |
} else if (is_short) { |
|
305 |
short_at_put(offset, new_delta); |
|
306 |
} else { |
|
307 |
int_at_put(offset, new_delta); |
|
308 |
} |
|
309 |
} |
|
310 |
} |
|
311 |
||
312 |
||
313 |
// Changes all jumps crossing "break_bci" by "delta". May enqueue things |
|
314 |
// on "rc->changes" |
|
315 |
void Relocator::change_jumps(int break_bci, int delta) { |
|
316 |
int bci = 0; |
|
317 |
Bytecodes::Code bc; |
|
318 |
// Now, adjust any affected instructions. |
|
319 |
while (bci < code_length()) { |
|
320 |
switch (bc= code_at(bci)) { |
|
321 |
case Bytecodes::_ifeq: |
|
322 |
case Bytecodes::_ifne: |
|
323 |
case Bytecodes::_iflt: |
|
324 |
case Bytecodes::_ifge: |
|
325 |
case Bytecodes::_ifgt: |
|
326 |
case Bytecodes::_ifle: |
|
327 |
case Bytecodes::_if_icmpeq: |
|
328 |
case Bytecodes::_if_icmpne: |
|
329 |
case Bytecodes::_if_icmplt: |
|
330 |
case Bytecodes::_if_icmpge: |
|
331 |
case Bytecodes::_if_icmpgt: |
|
332 |
case Bytecodes::_if_icmple: |
|
333 |
case Bytecodes::_if_acmpeq: |
|
334 |
case Bytecodes::_if_acmpne: |
|
335 |
case Bytecodes::_ifnull: |
|
336 |
case Bytecodes::_ifnonnull: |
|
337 |
case Bytecodes::_goto: |
|
338 |
case Bytecodes::_jsr: |
|
339 |
change_jump(bci, bci+1, true, break_bci, delta); |
|
340 |
break; |
|
341 |
case Bytecodes::_goto_w: |
|
342 |
case Bytecodes::_jsr_w: |
|
343 |
change_jump(bci, bci+1, false, break_bci, delta); |
|
344 |
break; |
|
345 |
case Bytecodes::_tableswitch: |
|
346 |
case Bytecodes::_lookupswitch: |
|
347 |
case Bytecodes::_fast_linearswitch: |
|
348 |
case Bytecodes::_fast_binaryswitch: { |
|
349 |
int recPad = get_orig_switch_pad(bci, (bc != Bytecodes::_tableswitch)); |
|
350 |
int oldPad = (recPad != -1) ? recPad : align(bci+1) - (bci+1); |
|
351 |
if (bci > break_bci) { |
|
352 |
int new_bci = bci + delta; |
|
353 |
int newPad = align(new_bci+1) - (new_bci+1); |
|
354 |
// Do we need to check the padding? |
|
355 |
if (newPad != oldPad) { |
|
356 |
if (recPad == -1) { |
|
357 |
_changes->push(new ChangeSwitchPad(bci, oldPad, (bc != Bytecodes::_tableswitch))); |
|
358 |
} |
|
359 |
} |
|
360 |
} |
|
361 |
||
362 |
// Then the rest, which depend on the kind of switch. |
|
363 |
switch (bc) { |
|
364 |
case Bytecodes::_tableswitch: { |
|
365 |
change_jump(bci, bci +1 + oldPad, false, break_bci, delta); |
|
366 |
// We cannot use the Bytecode_tableswitch abstraction, since the padding might not be correct. |
|
367 |
int lo = int_at(bci + 1 + oldPad + 4 * 1); |
|
368 |
int hi = int_at(bci + 1 + oldPad + 4 * 2); |
|
369 |
int n = hi - lo + 1; |
|
370 |
for (int k = 0; k < n; k++) { |
|
371 |
change_jump(bci, bci +1 + oldPad + 4*(k+3), false, break_bci, delta); |
|
372 |
} |
|
373 |
// Special next-bci calculation here... |
|
374 |
bci += 1 + oldPad + (n+3)*4; |
|
375 |
continue; |
|
376 |
} |
|
377 |
case Bytecodes::_lookupswitch: |
|
378 |
case Bytecodes::_fast_linearswitch: |
|
379 |
case Bytecodes::_fast_binaryswitch: { |
|
380 |
change_jump(bci, bci +1 + oldPad, false, break_bci, delta); |
|
381 |
// We cannot use the Bytecode_lookupswitch abstraction, since the padding might not be correct. |
|
382 |
int npairs = int_at(bci + 1 + oldPad + 4 * 1); |
|
383 |
for (int k = 0; k < npairs; k++) { |
|
384 |
change_jump(bci, bci + 1 + oldPad + 4*(2 + 2*k + 1), false, break_bci, delta); |
|
385 |
} |
|
386 |
/* Special next-bci calculation here... */ |
|
387 |
bci += 1 + oldPad + (2 + (npairs*2))*4; |
|
388 |
continue; |
|
389 |
} |
|
390 |
default: |
|
391 |
ShouldNotReachHere(); |
|
392 |
} |
|
393 |
} |
|
394 |
default: |
|
395 |
break; |
|
396 |
} |
|
397 |
bci += rc_instr_len(bci); |
|
398 |
} |
|
399 |
} |
|
400 |
||
401 |
// The width of instruction at "pc" is changing by "delta". Adjust the |
|
402 |
// exception table, if any, of "rc->mb". |
|
403 |
void Relocator::adjust_exception_table(int bci, int delta) { |
|
13282
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
7397
diff
changeset
|
404 |
ExceptionTable table(_method()); |
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
7397
diff
changeset
|
405 |
for (int index = 0; index < table.length(); index ++) { |
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
7397
diff
changeset
|
406 |
if (table.start_pc(index) > bci) { |
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
7397
diff
changeset
|
407 |
table.set_start_pc(index, table.start_pc(index) + delta); |
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
7397
diff
changeset
|
408 |
table.set_end_pc(index, table.end_pc(index) + delta); |
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
7397
diff
changeset
|
409 |
} else if (bci < table.end_pc(index)) { |
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
7397
diff
changeset
|
410 |
table.set_end_pc(index, table.end_pc(index) + delta); |
1 | 411 |
} |
13282
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
7397
diff
changeset
|
412 |
if (table.handler_pc(index) > bci) |
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
7397
diff
changeset
|
413 |
table.set_handler_pc(index, table.handler_pc(index) + delta); |
1 | 414 |
} |
415 |
} |
|
416 |
||
417 |
||
418 |
// The width of instruction at "bci" is changing by "delta". Adjust the line number table. |
|
419 |
void Relocator::adjust_line_no_table(int bci, int delta) { |
|
420 |
if (method()->has_linenumber_table()) { |
|
421 |
CompressedLineNumberReadStream reader(method()->compressed_linenumber_table()); |
|
422 |
CompressedLineNumberWriteStream writer(64); // plenty big for most line number tables |
|
423 |
while (reader.read_pair()) { |
|
424 |
int adjustment = (reader.bci() > bci) ? delta : 0; |
|
425 |
writer.write_pair(reader.bci() + adjustment, reader.line()); |
|
426 |
} |
|
427 |
writer.write_terminator(); |
|
428 |
set_compressed_line_number_table(writer.buffer()); |
|
429 |
set_compressed_line_number_table_size(writer.position()); |
|
430 |
} |
|
431 |
} |
|
432 |
||
433 |
||
434 |
// The width of instruction at "bci" is changing by "delta". Adjust the local variable table. |
|
435 |
void Relocator::adjust_local_var_table(int bci, int delta) { |
|
436 |
int localvariable_table_length = method()->localvariable_table_length(); |
|
437 |
if (localvariable_table_length > 0) { |
|
438 |
LocalVariableTableElement* table = method()->localvariable_table_start(); |
|
439 |
for (int i = 0; i < localvariable_table_length; i++) { |
|
440 |
u2 current_bci = table[i].start_bci; |
|
441 |
if (current_bci > bci) { |
|
442 |
table[i].start_bci = current_bci + delta; |
|
443 |
} else { |
|
444 |
u2 current_length = table[i].length; |
|
445 |
if (current_bci + current_length > bci) { |
|
446 |
table[i].length = current_length + delta; |
|
447 |
} |
|
448 |
} |
|
449 |
} |
|
450 |
} |
|
451 |
} |
|
452 |
||
6974
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
453 |
// Create a new array, copying the src array but adding a hole at |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
454 |
// the specified location |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13476
diff
changeset
|
455 |
static Array<u1>* insert_hole_at(ClassLoaderData* loader_data, |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13476
diff
changeset
|
456 |
size_t where, int hole_sz, Array<u1>* src) { |
6974
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
457 |
Thread* THREAD = Thread::current(); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13476
diff
changeset
|
458 |
Array<u1>* dst = |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13476
diff
changeset
|
459 |
MetadataFactory::new_array<u1>(loader_data, src->length() + hole_sz, 0, CHECK_NULL); |
6974
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
460 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13476
diff
changeset
|
461 |
address src_addr = (address)src->adr_at(0); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13476
diff
changeset
|
462 |
address dst_addr = (address)dst->adr_at(0); |
6974
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
463 |
|
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
464 |
memcpy(dst_addr, src_addr, where); |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
465 |
memcpy(dst_addr + where + hole_sz, |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
466 |
src_addr + where, src->length() - where); |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
467 |
return dst; |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
468 |
} |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
469 |
|
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
470 |
// The width of instruction at "bci" is changing by "delta". Adjust the stack |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
471 |
// map frames. |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
472 |
void Relocator::adjust_stack_map_table(int bci, int delta) { |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
473 |
if (method()->has_stackmap_table()) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13476
diff
changeset
|
474 |
Array<u1>* data = method()->stackmap_data(); |
13476 | 475 |
// The data in the array is a classfile representation of the stackmap table |
476 |
stack_map_table* sm_table = |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13476
diff
changeset
|
477 |
stack_map_table::at((address)data->adr_at(0)); |
6974
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
478 |
|
13476 | 479 |
int count = sm_table->number_of_entries(); |
480 |
stack_map_frame* frame = sm_table->entries(); |
|
6974
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
481 |
int bci_iter = -1; |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
482 |
bool offset_adjusted = false; // only need to adjust one offset |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
483 |
|
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
484 |
for (int i = 0; i < count; ++i) { |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
485 |
int offset_delta = frame->offset_delta(); |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
486 |
bci_iter += offset_delta; |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
487 |
|
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
488 |
if (!offset_adjusted && bci_iter > bci) { |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
489 |
int new_offset_delta = offset_delta + delta; |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
490 |
|
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
491 |
if (frame->is_valid_offset(new_offset_delta)) { |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
492 |
frame->set_offset_delta(new_offset_delta); |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
493 |
} else { |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
494 |
assert(frame->is_same_frame() || |
13476 | 495 |
frame->is_same_locals_1_stack_item_frame(), |
6974
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
496 |
"Frame must be one of the compressed forms"); |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
497 |
// The new delta exceeds the capacity of the 'same_frame' or |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
498 |
// 'same_frame_1_stack_item_frame' frame types. We need to |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
499 |
// convert these frames to the extended versions, but the extended |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
500 |
// version is bigger and requires more room. So we allocate a |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
501 |
// new array and copy the data, being sure to leave u2-sized hole |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
502 |
// right after the 'frame_type' for the new offset field. |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
503 |
// |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
504 |
// We can safely ignore the reverse situation as a small delta |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
505 |
// can still be used in an extended version of the frame. |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
506 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13476
diff
changeset
|
507 |
size_t frame_offset = (address)frame - (address)data->adr_at(0); |
6974
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
508 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13476
diff
changeset
|
509 |
ClassLoaderData* loader_data = method()->method_holder()->class_loader_data(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13476
diff
changeset
|
510 |
Array<u1>* new_data = insert_hole_at(loader_data, frame_offset + 1, 2, data); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13476
diff
changeset
|
511 |
if (new_data == NULL) { |
6974
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
512 |
return; // out-of-memory? |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
513 |
} |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13476
diff
changeset
|
514 |
// Deallocate old data |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13476
diff
changeset
|
515 |
MetadataFactory::free_array<u1>(loader_data, data); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13476
diff
changeset
|
516 |
data = new_data; |
6974
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
517 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13476
diff
changeset
|
518 |
address frame_addr = (address)(data->adr_at(0) + frame_offset); |
6974
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
519 |
frame = stack_map_frame::at(frame_addr); |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
520 |
|
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
521 |
|
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
522 |
// Now convert the frames in place |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
523 |
if (frame->is_same_frame()) { |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
524 |
same_frame_extended::create_at(frame_addr, new_offset_delta); |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
525 |
} else { |
13476 | 526 |
same_locals_1_stack_item_extended::create_at( |
6974
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
527 |
frame_addr, new_offset_delta, NULL); |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
528 |
// the verification_info_type should already be at the right spot |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
529 |
} |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
530 |
} |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
531 |
offset_adjusted = true; // needs to be done only once, since subsequent |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
532 |
// values are offsets from the current |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
533 |
} |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
534 |
|
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
535 |
// The stack map frame may contain verification types, if so we need to |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
536 |
// check and update any Uninitialized type's bci (no matter where it is). |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
537 |
int number_of_types = frame->number_of_types(); |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
538 |
verification_type_info* types = frame->types(); |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
539 |
|
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
540 |
for (int i = 0; i < number_of_types; ++i) { |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
541 |
if (types->is_uninitialized() && types->bci() > bci) { |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
542 |
types->set_bci(types->bci() + delta); |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
543 |
} |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
544 |
types = types->next(); |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
545 |
} |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
546 |
|
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
547 |
// Full frame has stack values too |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
548 |
full_frame* ff = frame->as_full_frame(); |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
549 |
if (ff != NULL) { |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
550 |
address eol = (address)types; |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
551 |
number_of_types = ff->stack_slots(eol); |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
552 |
types = ff->stack(eol); |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
553 |
for (int i = 0; i < number_of_types; ++i) { |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
554 |
if (types->is_uninitialized() && types->bci() > bci) { |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
555 |
types->set_bci(types->bci() + delta); |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
556 |
} |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
557 |
types = types->next(); |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
558 |
} |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
559 |
} |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
560 |
|
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
561 |
frame = frame->next(); |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
562 |
} |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
563 |
|
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
564 |
method()->set_stackmap_data(data); // in case it has changed |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
565 |
} |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
566 |
} |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
567 |
|
1 | 568 |
|
569 |
bool Relocator::expand_code_array(int delta) { |
|
570 |
int length = MAX2(code_length() + delta, code_length() * (100+code_slop_pct()) / 100); |
|
571 |
||
572 |
if (length > MAX_METHOD_LENGTH) { |
|
573 |
if (delta == 0 && code_length() <= MAX_METHOD_LENGTH) { |
|
574 |
length = MAX_METHOD_LENGTH; |
|
575 |
} else { |
|
576 |
return false; |
|
577 |
} |
|
578 |
} |
|
579 |
||
580 |
unsigned char* new_code_array = NEW_RESOURCE_ARRAY(unsigned char, length); |
|
581 |
if (!new_code_array) return false; |
|
582 |
||
583 |
// Expanding current array |
|
584 |
if (code_array() != NULL) { |
|
585 |
memcpy(new_code_array, code_array(), code_length()); |
|
586 |
} else { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13476
diff
changeset
|
587 |
// Initial copy. Copy directly from Method* |
1 | 588 |
memcpy(new_code_array, method()->code_base(), code_length()); |
589 |
} |
|
590 |
||
591 |
set_code_array(new_code_array); |
|
592 |
set_code_array_length(length); |
|
593 |
||
594 |
return true; |
|
595 |
} |
|
596 |
||
597 |
||
598 |
// The instruction at "bci", whose size is "ilen", is changing size by |
|
599 |
// "delta". Reallocate, move code, recalculate jumps, and enqueue |
|
600 |
// change items as necessary. |
|
601 |
bool Relocator::relocate_code(int bci, int ilen, int delta) { |
|
602 |
int next_bci = bci + ilen; |
|
603 |
if (delta > 0 && code_length() + delta > code_array_length()) { |
|
604 |
// Expand allocated code space, if necessary. |
|
605 |
if (!expand_code_array(delta)) { |
|
606 |
return false; |
|
607 |
} |
|
608 |
} |
|
609 |
||
610 |
// We require 4-byte alignment of code arrays. |
|
611 |
assert(((intptr_t)code_array() & 3) == 0, "check code alignment"); |
|
612 |
// Change jumps before doing the copying; this routine requires aligned switches. |
|
613 |
change_jumps(bci, delta); |
|
614 |
||
615 |
// In case we have shrunken a tableswitch/lookupswitch statement, we store the last |
|
616 |
// bytes that get overwritten. We have to copy the bytes after the change_jumps method |
|
22551 | 617 |
// has been called, since it is likely to update last offset in a tableswitch/lookupswitch |
38658
34f9c45625d8
8140594: Various minor code improvements (compiler)
goetz
parents:
33593
diff
changeset
|
618 |
assert(delta >= -3, "We cannot overwrite more than 3 bytes."); |
34f9c45625d8
8140594: Various minor code improvements (compiler)
goetz
parents:
33593
diff
changeset
|
619 |
if (delta < 0 && delta >= -3) { |
1 | 620 |
memcpy(_overwrite, addr_at(bci + ilen + delta), -delta); |
621 |
} |
|
622 |
||
623 |
memmove(addr_at(next_bci + delta), addr_at(next_bci), code_length() - next_bci); |
|
624 |
set_code_length(code_length() + delta); |
|
625 |
// Also adjust exception tables... |
|
626 |
adjust_exception_table(bci, delta); |
|
627 |
// Line number tables... |
|
628 |
adjust_line_no_table(bci, delta); |
|
629 |
// And local variable table... |
|
630 |
adjust_local_var_table(bci, delta); |
|
631 |
||
6974
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
632 |
// Adjust stack maps |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
633 |
adjust_stack_map_table(bci, delta); |
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
634 |
|
1 | 635 |
// Relocate the pending change stack... |
636 |
for (int j = 0; j < _changes->length(); j++) { |
|
637 |
ChangeItem* ci = _changes->at(j); |
|
638 |
ci->relocate(bci, delta); |
|
639 |
} |
|
640 |
||
641 |
// Notify any listeners about code relocation |
|
642 |
notify(bci, delta, code_length()); |
|
643 |
||
644 |
return true; |
|
645 |
} |
|
646 |
||
647 |
// relocate a general instruction. Called by ChangeWiden class |
|
648 |
bool Relocator::handle_widen(int bci, int new_ilen, u_char inst_buffer[]) { |
|
649 |
int ilen = rc_instr_len(bci); |
|
650 |
if (!relocate_code(bci, ilen, new_ilen - ilen)) |
|
651 |
return false; |
|
652 |
||
653 |
// Insert new bytecode(s) |
|
654 |
for(int k = 0; k < new_ilen; k++) { |
|
655 |
code_at_put(bci + k, (Bytecodes::Code)inst_buffer[k]); |
|
656 |
} |
|
657 |
||
658 |
return true; |
|
659 |
} |
|
660 |
||
661 |
// handle jump_widen instruction. Called be ChangeJumpWiden class |
|
662 |
bool Relocator::handle_jump_widen(int bci, int delta) { |
|
663 |
int ilen = rc_instr_len(bci); |
|
664 |
||
665 |
Bytecodes::Code bc = code_at(bci); |
|
666 |
switch (bc) { |
|
667 |
case Bytecodes::_ifeq: |
|
668 |
case Bytecodes::_ifne: |
|
669 |
case Bytecodes::_iflt: |
|
670 |
case Bytecodes::_ifge: |
|
671 |
case Bytecodes::_ifgt: |
|
672 |
case Bytecodes::_ifle: |
|
673 |
case Bytecodes::_if_icmpeq: |
|
674 |
case Bytecodes::_if_icmpne: |
|
675 |
case Bytecodes::_if_icmplt: |
|
676 |
case Bytecodes::_if_icmpge: |
|
677 |
case Bytecodes::_if_icmpgt: |
|
678 |
case Bytecodes::_if_icmple: |
|
679 |
case Bytecodes::_if_acmpeq: |
|
680 |
case Bytecodes::_if_acmpne: |
|
681 |
case Bytecodes::_ifnull: |
|
682 |
case Bytecodes::_ifnonnull: { |
|
683 |
const int goto_length = Bytecodes::length_for(Bytecodes::_goto); |
|
684 |
||
685 |
// If 'if' points to the next bytecode after goto, it's already handled. |
|
686 |
// it shouldn't be. |
|
687 |
assert (short_at(bci+1) != ilen+goto_length, "if relocation already handled"); |
|
688 |
assert(ilen == 3, "check length"); |
|
689 |
||
690 |
// Convert to 0 if <cond> goto 6 |
|
691 |
// 3 _goto 11 |
|
692 |
// 6 _goto_w <wide delta offset> |
|
693 |
// 11 <else code> |
|
694 |
const int goto_w_length = Bytecodes::length_for(Bytecodes::_goto_w); |
|
695 |
const int add_bci = goto_length + goto_w_length; |
|
696 |
||
697 |
if (!relocate_code(bci, 3, /*delta*/add_bci)) return false; |
|
698 |
||
699 |
// if bytecode points to goto_w instruction |
|
700 |
short_at_put(bci + 1, ilen + goto_length); |
|
701 |
||
702 |
int cbci = bci + ilen; |
|
703 |
// goto around |
|
704 |
code_at_put(cbci, Bytecodes::_goto); |
|
705 |
short_at_put(cbci + 1, add_bci); |
|
706 |
// goto_w <wide delta> |
|
707 |
cbci = cbci + goto_length; |
|
708 |
code_at_put(cbci, Bytecodes::_goto_w); |
|
709 |
if (delta > 0) { |
|
710 |
delta += 2; // goto_w is 2 bytes more than "if" code |
|
711 |
} else { |
|
712 |
delta -= ilen+goto_length; // branch starts at goto_w offset |
|
713 |
} |
|
714 |
int_at_put(cbci + 1, delta); |
|
715 |
break; |
|
716 |
||
717 |
} |
|
718 |
case Bytecodes::_goto: |
|
719 |
case Bytecodes::_jsr: |
|
720 |
assert(ilen == 3, "check length"); |
|
721 |
||
722 |
if (!relocate_code(bci, 3, 2)) return false; |
|
723 |
if (bc == Bytecodes::_goto) |
|
724 |
code_at_put(bci, Bytecodes::_goto_w); |
|
725 |
else |
|
726 |
code_at_put(bci, Bytecodes::_jsr_w); |
|
727 |
||
728 |
// If it's a forward jump, add 2 for the widening. |
|
729 |
if (delta > 0) delta += 2; |
|
730 |
int_at_put(bci + 1, delta); |
|
731 |
break; |
|
732 |
||
733 |
default: ShouldNotReachHere(); |
|
734 |
} |
|
735 |
||
736 |
return true; |
|
737 |
} |
|
738 |
||
739 |
// handle lookup/table switch instructions. Called be ChangeSwitchPad class |
|
740 |
bool Relocator::handle_switch_pad(int bci, int old_pad, bool is_lookup_switch) { |
|
741 |
int ilen = rc_instr_len(bci); |
|
742 |
int new_pad = align(bci+1) - (bci+1); |
|
743 |
int pad_delta = new_pad - old_pad; |
|
744 |
if (pad_delta != 0) { |
|
745 |
int len; |
|
746 |
if (!is_lookup_switch) { |
|
747 |
int low = int_at(bci+1+old_pad+4); |
|
748 |
int high = int_at(bci+1+old_pad+8); |
|
749 |
len = high-low+1 + 3; // 3 for default, hi, lo. |
|
750 |
} else { |
|
751 |
int npairs = int_at(bci+1+old_pad+4); |
|
752 |
len = npairs*2 + 2; // 2 for default, npairs. |
|
753 |
} |
|
754 |
// Because "relocateCode" does a "changeJumps" loop, |
|
755 |
// which parses instructions to determine their length, |
|
756 |
// we need to call that before messing with the current |
|
757 |
// instruction. Since it may also overwrite the current |
|
758 |
// instruction when moving down, remember the possibly |
|
759 |
// overwritten part. |
|
760 |
||
761 |
// Move the code following the instruction... |
|
762 |
if (!relocate_code(bci, ilen, pad_delta)) return false; |
|
763 |
||
764 |
if (pad_delta < 0) { |
|
765 |
// Move the shrunken instruction down. |
|
766 |
memmove(addr_at(bci + 1 + new_pad), |
|
767 |
addr_at(bci + 1 + old_pad), |
|
768 |
len * 4 + pad_delta); |
|
769 |
memmove(addr_at(bci + 1 + new_pad + len*4 + pad_delta), |
|
770 |
_overwrite, -pad_delta); |
|
771 |
} else { |
|
772 |
assert(pad_delta > 0, "check"); |
|
773 |
// Move the expanded instruction up. |
|
774 |
memmove(addr_at(bci +1 + new_pad), |
|
775 |
addr_at(bci +1 + old_pad), |
|
776 |
len * 4); |
|
6974
a013f1c533a5
6991315: RedefineClasses fails with java.lang.VerifyError
kamg
parents:
5547
diff
changeset
|
777 |
memset(addr_at(bci + 1), 0, new_pad); // pad must be 0 |
1 | 778 |
} |
779 |
} |
|
780 |
return true; |
|
781 |
} |