author | jrose |
Wed, 02 Jun 2010 22:45:42 -0700 | |
changeset 5702 | 201c5cde25bb |
parent 5547 | f4b087cbb361 |
parent 5688 | 9052dc91ea67 |
child 5882 | 6b2aecc4f7d8 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
5702 | 2 |
* Copyright (c) 1997, 2010, 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:
4567
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4567
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:
4567
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
25 |
// Base class for different kinds of abstractions working |
|
26 |
// relative to an objects 'this' pointer. |
|
27 |
||
28 |
class ThisRelativeObj VALUE_OBJ_CLASS_SPEC { |
|
29 |
public: |
|
30 |
// Address computation |
|
31 |
address addr_at (int offset) const { return (address)this + offset; } |
|
5688 | 32 |
int byte_at (int offset) const { return *(addr_at(offset)); } |
1 | 33 |
address aligned_addr_at (int offset) const { return (address)round_to((intptr_t)addr_at(offset), jintSize); } |
34 |
int aligned_offset (int offset) const { return aligned_addr_at(offset) - addr_at(0); } |
|
35 |
||
5688 | 36 |
// Word access: |
37 |
int get_Java_u2_at (int offset) const { return Bytes::get_Java_u2(addr_at(offset)); } |
|
38 |
int get_Java_u4_at (int offset) const { return Bytes::get_Java_u4(addr_at(offset)); } |
|
39 |
int get_native_u2_at (int offset) const { return Bytes::get_native_u2(addr_at(offset)); } |
|
40 |
int get_native_u4_at (int offset) const { return Bytes::get_native_u4(addr_at(offset)); } |
|
1 | 41 |
}; |
42 |
||
43 |
||
44 |
// The base class for different kinds of bytecode abstractions. |
|
45 |
// Provides the primitive operations to manipulate code relative |
|
46 |
// to an objects 'this' pointer. |
|
5688 | 47 |
// FIXME: Make this a ResourceObj, include the enclosing methodOop, and cache the opcode. |
1 | 48 |
|
49 |
class Bytecode: public ThisRelativeObj { |
|
50 |
protected: |
|
51 |
u_char byte_at(int offset) const { return *addr_at(offset); } |
|
5688 | 52 |
bool check_must_rewrite(Bytecodes::Code bc) const; |
1 | 53 |
|
54 |
public: |
|
55 |
// Attributes |
|
56 |
address bcp() const { return addr_at(0); } |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
57 |
int instruction_size() const { return Bytecodes::length_at(bcp()); } |
1 | 58 |
|
5688 | 59 |
// Warning: Use code() with caution on live bytecode streams. 4926272 |
1 | 60 |
Bytecodes::Code code() const { return Bytecodes::code_at(addr_at(0)); } |
61 |
Bytecodes::Code java_code() const { return Bytecodes::java_code(code()); } |
|
5688 | 62 |
bool must_rewrite(Bytecodes::Code code) const { return Bytecodes::can_rewrite(code) && check_must_rewrite(code); } |
1 | 63 |
|
64 |
// Creation |
|
65 |
inline friend Bytecode* Bytecode_at(address bcp); |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
66 |
|
5688 | 67 |
// Static functions for parsing bytecodes in place. |
68 |
int get_index_u1(Bytecodes::Code bc) const { |
|
69 |
assert_same_format_as(bc); assert_index_size(1, bc); |
|
70 |
return *(jubyte*)addr_at(1); |
|
71 |
} |
|
72 |
int get_index_u2(Bytecodes::Code bc, bool is_wide = false) const { |
|
73 |
assert_same_format_as(bc, is_wide); assert_index_size(2, bc, is_wide); |
|
74 |
address p = addr_at(is_wide ? 2 : 1); |
|
75 |
if (can_use_native_byte_order(bc, is_wide)) |
|
76 |
return Bytes::get_native_u2(p); |
|
77 |
else return Bytes::get_Java_u2(p); |
|
78 |
} |
|
79 |
int get_index_u2_cpcache(Bytecodes::Code bc) const { |
|
80 |
assert_same_format_as(bc); assert_index_size(2, bc); assert_native_index(bc); |
|
81 |
return Bytes::get_native_u2(addr_at(1)) DEBUG_ONLY(+ constantPoolOopDesc::CPCACHE_INDEX_TAG); |
|
82 |
} |
|
83 |
int get_index_u4(Bytecodes::Code bc) const { |
|
84 |
assert_same_format_as(bc); assert_index_size(4, bc); |
|
85 |
assert(can_use_native_byte_order(bc), ""); |
|
86 |
return Bytes::get_native_u4(addr_at(1)); |
|
87 |
} |
|
88 |
bool has_index_u4(Bytecodes::Code bc) const { |
|
89 |
return bc == Bytecodes::_invokedynamic; |
|
90 |
} |
|
91 |
||
92 |
int get_offset_s2(Bytecodes::Code bc) const { |
|
93 |
assert_same_format_as(bc); assert_offset_size(2, bc); |
|
94 |
return (jshort) Bytes::get_Java_u2(addr_at(1)); |
|
95 |
} |
|
96 |
int get_offset_s4(Bytecodes::Code bc) const { |
|
97 |
assert_same_format_as(bc); assert_offset_size(4, bc); |
|
98 |
return (jint) Bytes::get_Java_u4(addr_at(1)); |
|
99 |
} |
|
100 |
||
101 |
int get_constant_u1(int offset, Bytecodes::Code bc) const { |
|
102 |
assert_same_format_as(bc); assert_constant_size(1, offset, bc); |
|
103 |
return *(jbyte*)addr_at(offset); |
|
104 |
} |
|
105 |
int get_constant_u2(int offset, Bytecodes::Code bc, bool is_wide = false) const { |
|
106 |
assert_same_format_as(bc, is_wide); assert_constant_size(2, offset, bc, is_wide); |
|
107 |
return (jshort) Bytes::get_Java_u2(addr_at(offset)); |
|
108 |
} |
|
109 |
||
110 |
// These are used locally and also from bytecode streams. |
|
111 |
void assert_same_format_as(Bytecodes::Code testbc, bool is_wide = false) const NOT_DEBUG_RETURN; |
|
112 |
static void assert_index_size(int required_size, Bytecodes::Code bc, bool is_wide = false) NOT_DEBUG_RETURN; |
|
113 |
static void assert_offset_size(int required_size, Bytecodes::Code bc, bool is_wide = false) NOT_DEBUG_RETURN; |
|
114 |
static void assert_constant_size(int required_size, int where, Bytecodes::Code bc, bool is_wide = false) NOT_DEBUG_RETURN; |
|
115 |
static void assert_native_index(Bytecodes::Code bc, bool is_wide = false) NOT_DEBUG_RETURN; |
|
116 |
static bool can_use_native_byte_order(Bytecodes::Code bc, bool is_wide = false) { |
|
117 |
return (!Bytes::is_Java_byte_ordering_different() || Bytecodes::native_byte_order(bc /*, is_wide*/)); |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
118 |
} |
1 | 119 |
}; |
120 |
||
121 |
inline Bytecode* Bytecode_at(address bcp) { |
|
5688 | 122 |
// Warning: Use with caution on live bytecode streams. 4926272 |
1 | 123 |
return (Bytecode*)bcp; |
124 |
} |
|
125 |
||
126 |
||
127 |
// Abstractions for lookupswitch bytecode |
|
128 |
||
129 |
class LookupswitchPair: ThisRelativeObj { |
|
130 |
private: |
|
131 |
int _match; |
|
132 |
int _offset; |
|
133 |
||
134 |
public: |
|
5688 | 135 |
int match() const { return get_Java_u4_at(0 * jintSize); } |
136 |
int offset() const { return get_Java_u4_at(1 * jintSize); } |
|
1 | 137 |
}; |
138 |
||
139 |
||
140 |
class Bytecode_lookupswitch: public Bytecode { |
|
141 |
public: |
|
142 |
void verify() const PRODUCT_RETURN; |
|
143 |
||
144 |
// Attributes |
|
5688 | 145 |
int default_offset() const { return get_Java_u4_at(aligned_offset(1 + 0*jintSize)); } |
146 |
int number_of_pairs() const { return get_Java_u4_at(aligned_offset(1 + 1*jintSize)); } |
|
1 | 147 |
LookupswitchPair* pair_at(int i) const { assert(0 <= i && i < number_of_pairs(), "pair index out of bounds"); |
148 |
return (LookupswitchPair*)aligned_addr_at(1 + (1 + i)*2*jintSize); } |
|
149 |
// Creation |
|
150 |
inline friend Bytecode_lookupswitch* Bytecode_lookupswitch_at(address bcp); |
|
151 |
}; |
|
152 |
||
153 |
inline Bytecode_lookupswitch* Bytecode_lookupswitch_at(address bcp) { |
|
154 |
Bytecode_lookupswitch* b = (Bytecode_lookupswitch*)bcp; |
|
155 |
debug_only(b->verify()); |
|
156 |
return b; |
|
157 |
} |
|
158 |
||
159 |
||
160 |
class Bytecode_tableswitch: public Bytecode { |
|
161 |
public: |
|
162 |
void verify() const PRODUCT_RETURN; |
|
163 |
||
164 |
// Attributes |
|
5688 | 165 |
int default_offset() const { return get_Java_u4_at(aligned_offset(1 + 0*jintSize)); } |
166 |
int low_key() const { return get_Java_u4_at(aligned_offset(1 + 1*jintSize)); } |
|
167 |
int high_key() const { return get_Java_u4_at(aligned_offset(1 + 2*jintSize)); } |
|
1 | 168 |
int dest_offset_at(int i) const; |
169 |
int length() { return high_key()-low_key()+1; } |
|
170 |
||
171 |
// Creation |
|
172 |
inline friend Bytecode_tableswitch* Bytecode_tableswitch_at(address bcp); |
|
173 |
}; |
|
174 |
||
175 |
inline Bytecode_tableswitch* Bytecode_tableswitch_at(address bcp) { |
|
176 |
Bytecode_tableswitch* b = (Bytecode_tableswitch*)bcp; |
|
177 |
debug_only(b->verify()); |
|
178 |
return b; |
|
179 |
} |
|
180 |
||
181 |
||
182 |
// Abstraction for invoke_{virtual, static, interface, special} |
|
183 |
||
184 |
class Bytecode_invoke: public ResourceObj { |
|
185 |
protected: |
|
186 |
methodHandle _method; // method containing the bytecode |
|
187 |
int _bci; // position of the bytecode |
|
188 |
||
189 |
Bytecode_invoke(methodHandle method, int bci) : _method(method), _bci(bci) {} |
|
190 |
||
191 |
public: |
|
192 |
void verify() const; |
|
193 |
||
194 |
// Attributes |
|
195 |
methodHandle method() const { return _method; } |
|
196 |
int bci() const { return _bci; } |
|
197 |
address bcp() const { return _method->bcp_from(bci()); } |
|
198 |
||
199 |
int index() const; // the constant pool index for the invoke |
|
200 |
symbolOop name() const; // returns the name of the invoked method |
|
201 |
symbolOop signature() const; // returns the signature of the invoked method |
|
202 |
BasicType result_type(Thread *thread) const; // returns the result type of the invoke |
|
203 |
||
204 |
Bytecodes::Code code() const { return Bytecodes::code_at(bcp(), _method()); } |
|
205 |
Bytecodes::Code adjusted_invoke_code() const { return Bytecodes::java_code(code()); } |
|
206 |
||
207 |
methodHandle static_target(TRAPS); // "specified" method (from constant pool) |
|
208 |
||
209 |
// Testers |
|
210 |
bool is_invokeinterface() const { return adjusted_invoke_code() == Bytecodes::_invokeinterface; } |
|
211 |
bool is_invokevirtual() const { return adjusted_invoke_code() == Bytecodes::_invokevirtual; } |
|
212 |
bool is_invokestatic() const { return adjusted_invoke_code() == Bytecodes::_invokestatic; } |
|
213 |
bool is_invokespecial() const { return adjusted_invoke_code() == Bytecodes::_invokespecial; } |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
214 |
bool is_invokedynamic() const { return adjusted_invoke_code() == Bytecodes::_invokedynamic; } |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
215 |
|
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4564
diff
changeset
|
216 |
bool has_receiver() const { return !is_invokestatic() && !is_invokedynamic(); } |
1 | 217 |
|
218 |
bool is_valid() const { return is_invokeinterface() || |
|
219 |
is_invokevirtual() || |
|
220 |
is_invokestatic() || |
|
4564
55dfb20908d0
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
3261
diff
changeset
|
221 |
is_invokespecial() || |
55dfb20908d0
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
3261
diff
changeset
|
222 |
is_invokedynamic(); } |
1 | 223 |
|
224 |
// Creation |
|
225 |
inline friend Bytecode_invoke* Bytecode_invoke_at(methodHandle method, int bci); |
|
226 |
||
227 |
// Like Bytecode_invoke_at. Instead it returns NULL if the bci is not at an invoke. |
|
228 |
inline friend Bytecode_invoke* Bytecode_invoke_at_check(methodHandle method, int bci); |
|
229 |
}; |
|
230 |
||
231 |
inline Bytecode_invoke* Bytecode_invoke_at(methodHandle method, int bci) { |
|
232 |
Bytecode_invoke* b = new Bytecode_invoke(method, bci); |
|
233 |
debug_only(b->verify()); |
|
234 |
return b; |
|
235 |
} |
|
236 |
||
237 |
inline Bytecode_invoke* Bytecode_invoke_at_check(methodHandle method, int bci) { |
|
238 |
Bytecode_invoke* b = new Bytecode_invoke(method, bci); |
|
239 |
return b->is_valid() ? b : NULL; |
|
240 |
} |
|
241 |
||
242 |
||
243 |
// Abstraction for all field accesses (put/get field/static_ |
|
244 |
class Bytecode_field: public Bytecode { |
|
245 |
public: |
|
246 |
void verify() const; |
|
247 |
||
248 |
int index() const; |
|
249 |
bool is_static() const; |
|
250 |
||
251 |
// Creation |
|
252 |
inline friend Bytecode_field* Bytecode_field_at(const methodOop method, address bcp); |
|
253 |
}; |
|
254 |
||
255 |
inline Bytecode_field* Bytecode_field_at(const methodOop method, address bcp) { |
|
256 |
Bytecode_field* b = (Bytecode_field*)bcp; |
|
257 |
debug_only(b->verify()); |
|
258 |
return b; |
|
259 |
} |
|
260 |
||
261 |
||
262 |
// Abstraction for checkcast |
|
263 |
||
264 |
class Bytecode_checkcast: public Bytecode { |
|
265 |
public: |
|
266 |
void verify() const { assert(Bytecodes::java_code(code()) == Bytecodes::_checkcast, "check checkcast"); } |
|
267 |
||
268 |
// Returns index |
|
5688 | 269 |
long index() const { return get_index_u2(Bytecodes::_checkcast); }; |
1 | 270 |
|
271 |
// Creation |
|
272 |
inline friend Bytecode_checkcast* Bytecode_checkcast_at(address bcp); |
|
273 |
}; |
|
274 |
||
275 |
inline Bytecode_checkcast* Bytecode_checkcast_at(address bcp) { |
|
276 |
Bytecode_checkcast* b = (Bytecode_checkcast*)bcp; |
|
277 |
debug_only(b->verify()); |
|
278 |
return b; |
|
279 |
} |
|
280 |
||
281 |
||
282 |
// Abstraction for instanceof |
|
283 |
||
284 |
class Bytecode_instanceof: public Bytecode { |
|
285 |
public: |
|
286 |
void verify() const { assert(code() == Bytecodes::_instanceof, "check instanceof"); } |
|
287 |
||
288 |
// Returns index |
|
5688 | 289 |
long index() const { return get_index_u2(Bytecodes::_instanceof); }; |
1 | 290 |
|
291 |
// Creation |
|
292 |
inline friend Bytecode_instanceof* Bytecode_instanceof_at(address bcp); |
|
293 |
}; |
|
294 |
||
295 |
inline Bytecode_instanceof* Bytecode_instanceof_at(address bcp) { |
|
296 |
Bytecode_instanceof* b = (Bytecode_instanceof*)bcp; |
|
297 |
debug_only(b->verify()); |
|
298 |
return b; |
|
299 |
} |
|
300 |
||
301 |
||
302 |
class Bytecode_new: public Bytecode { |
|
303 |
public: |
|
304 |
void verify() const { assert(java_code() == Bytecodes::_new, "check new"); } |
|
305 |
||
306 |
// Returns index |
|
5688 | 307 |
long index() const { return get_index_u2(Bytecodes::_new); }; |
1 | 308 |
|
309 |
// Creation |
|
310 |
inline friend Bytecode_new* Bytecode_new_at(address bcp); |
|
311 |
}; |
|
312 |
||
313 |
inline Bytecode_new* Bytecode_new_at(address bcp) { |
|
314 |
Bytecode_new* b = (Bytecode_new*)bcp; |
|
315 |
debug_only(b->verify()); |
|
316 |
return b; |
|
317 |
} |
|
318 |
||
319 |
||
320 |
class Bytecode_multianewarray: public Bytecode { |
|
321 |
public: |
|
322 |
void verify() const { assert(java_code() == Bytecodes::_multianewarray, "check new"); } |
|
323 |
||
324 |
// Returns index |
|
5688 | 325 |
long index() const { return get_index_u2(Bytecodes::_multianewarray); }; |
1 | 326 |
|
327 |
// Creation |
|
328 |
inline friend Bytecode_multianewarray* Bytecode_multianewarray_at(address bcp); |
|
329 |
}; |
|
330 |
||
331 |
inline Bytecode_multianewarray* Bytecode_multianewarray_at(address bcp) { |
|
332 |
Bytecode_multianewarray* b = (Bytecode_multianewarray*)bcp; |
|
333 |
debug_only(b->verify()); |
|
334 |
return b; |
|
335 |
} |
|
336 |
||
337 |
||
338 |
class Bytecode_anewarray: public Bytecode { |
|
339 |
public: |
|
340 |
void verify() const { assert(java_code() == Bytecodes::_anewarray, "check anewarray"); } |
|
341 |
||
342 |
// Returns index |
|
5688 | 343 |
long index() const { return get_index_u2(Bytecodes::_anewarray); }; |
1 | 344 |
|
345 |
// Creation |
|
346 |
inline friend Bytecode_anewarray* Bytecode_anewarray_at(address bcp); |
|
347 |
}; |
|
348 |
||
349 |
inline Bytecode_anewarray* Bytecode_anewarray_at(address bcp) { |
|
350 |
Bytecode_anewarray* b = (Bytecode_anewarray*)bcp; |
|
351 |
debug_only(b->verify()); |
|
352 |
return b; |
|
353 |
} |
|
354 |
||
355 |
||
356 |
// Abstraction for ldc, ldc_w and ldc2_w |
|
357 |
||
358 |
class Bytecode_loadconstant: public Bytecode { |
|
359 |
public: |
|
360 |
void verify() const { |
|
361 |
Bytecodes::Code stdc = Bytecodes::java_code(code()); |
|
362 |
assert(stdc == Bytecodes::_ldc || |
|
363 |
stdc == Bytecodes::_ldc_w || |
|
364 |
stdc == Bytecodes::_ldc2_w, "load constant"); |
|
365 |
} |
|
366 |
||
367 |
int index() const; |
|
368 |
||
369 |
inline friend Bytecode_loadconstant* Bytecode_loadconstant_at(const methodOop method, address bcp); |
|
370 |
}; |
|
371 |
||
372 |
inline Bytecode_loadconstant* Bytecode_loadconstant_at(const methodOop method, address bcp) { |
|
373 |
Bytecode_loadconstant* b = (Bytecode_loadconstant*)bcp; |
|
374 |
debug_only(b->verify()); |
|
375 |
return b; |
|
376 |
} |