author | rbackman |
Tue, 06 Mar 2012 12:36:59 +0100 | |
changeset 12377 | ae6def2813e0 |
parent 10979 | c25dd872c62f |
child 13391 | 30245956af37 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
7913 | 2 |
* Copyright (c) 1997, 2011, 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 |
||
7397 | 25 |
#ifndef SHARE_VM_INTERPRETER_BYTECODE_HPP |
26 |
#define SHARE_VM_INTERPRETER_BYTECODE_HPP |
|
27 |
||
28 |
#include "interpreter/bytecodes.hpp" |
|
29 |
#include "memory/allocation.hpp" |
|
30 |
#include "oops/methodOop.hpp" |
|
31 |
#ifdef TARGET_ARCH_x86 |
|
32 |
# include "bytes_x86.hpp" |
|
33 |
#endif |
|
34 |
#ifdef TARGET_ARCH_sparc |
|
35 |
# include "bytes_sparc.hpp" |
|
36 |
#endif |
|
37 |
#ifdef TARGET_ARCH_zero |
|
38 |
# include "bytes_zero.hpp" |
|
39 |
#endif |
|
8107
78e5bd944384
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
8076
diff
changeset
|
40 |
#ifdef TARGET_ARCH_arm |
78e5bd944384
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
8076
diff
changeset
|
41 |
# include "bytes_arm.hpp" |
78e5bd944384
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
8076
diff
changeset
|
42 |
#endif |
78e5bd944384
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
8076
diff
changeset
|
43 |
#ifdef TARGET_ARCH_ppc |
78e5bd944384
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
8076
diff
changeset
|
44 |
# include "bytes_ppc.hpp" |
78e5bd944384
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
8076
diff
changeset
|
45 |
#endif |
7397 | 46 |
|
7913 | 47 |
class ciBytecodeStream; |
48 |
||
49 |
// The base class for different kinds of bytecode abstractions. |
|
50 |
// Provides the primitive operations to manipulate code relative |
|
51 |
// to the bcp. |
|
1 | 52 |
|
7913 | 53 |
class Bytecode: public StackObj { |
54 |
protected: |
|
55 |
const address _bcp; |
|
56 |
const Bytecodes::Code _code; |
|
57 |
||
1 | 58 |
// Address computation |
7913 | 59 |
address addr_at (int offset) const { return (address)_bcp + offset; } |
60 |
u_char byte_at(int offset) const { return *addr_at(offset); } |
|
1 | 61 |
address aligned_addr_at (int offset) const { return (address)round_to((intptr_t)addr_at(offset), jintSize); } |
62 |
int aligned_offset (int offset) const { return aligned_addr_at(offset) - addr_at(0); } |
|
63 |
||
5688 | 64 |
// Word access: |
65 |
int get_Java_u2_at (int offset) const { return Bytes::get_Java_u2(addr_at(offset)); } |
|
66 |
int get_Java_u4_at (int offset) const { return Bytes::get_Java_u4(addr_at(offset)); } |
|
67 |
int get_native_u2_at (int offset) const { return Bytes::get_native_u2(addr_at(offset)); } |
|
68 |
int get_native_u4_at (int offset) const { return Bytes::get_native_u4(addr_at(offset)); } |
|
1 | 69 |
|
70 |
public: |
|
7913 | 71 |
Bytecode(methodOop method, address bcp): _bcp(bcp), _code(Bytecodes::code_at(method, addr_at(0))) { |
72 |
assert(method != NULL, "this form requires a valid methodOop"); |
|
73 |
} |
|
74 |
// Defined in ciStreams.hpp |
|
75 |
inline Bytecode(const ciBytecodeStream* stream, address bcp = NULL); |
|
1 | 76 |
|
7913 | 77 |
// Attributes |
78 |
address bcp() const { return _bcp; } |
|
79 |
int instruction_size() const { return Bytecodes::length_for_code_at(_code, bcp()); } |
|
80 |
||
81 |
Bytecodes::Code code() const { return _code; } |
|
1 | 82 |
Bytecodes::Code java_code() const { return Bytecodes::java_code(code()); } |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
83 |
|
5688 | 84 |
// Static functions for parsing bytecodes in place. |
85 |
int get_index_u1(Bytecodes::Code bc) const { |
|
86 |
assert_same_format_as(bc); assert_index_size(1, bc); |
|
87 |
return *(jubyte*)addr_at(1); |
|
88 |
} |
|
89 |
int get_index_u2(Bytecodes::Code bc, bool is_wide = false) const { |
|
90 |
assert_same_format_as(bc, is_wide); assert_index_size(2, bc, is_wide); |
|
91 |
address p = addr_at(is_wide ? 2 : 1); |
|
92 |
if (can_use_native_byte_order(bc, is_wide)) |
|
7913 | 93 |
return Bytes::get_native_u2(p); |
5688 | 94 |
else return Bytes::get_Java_u2(p); |
95 |
} |
|
5882 | 96 |
int get_index_u1_cpcache(Bytecodes::Code bc) const { |
97 |
assert_same_format_as(bc); assert_index_size(1, bc); |
|
98 |
return *(jubyte*)addr_at(1) + constantPoolOopDesc::CPCACHE_INDEX_TAG; |
|
99 |
} |
|
5688 | 100 |
int get_index_u2_cpcache(Bytecodes::Code bc) const { |
101 |
assert_same_format_as(bc); assert_index_size(2, bc); assert_native_index(bc); |
|
5882 | 102 |
return Bytes::get_native_u2(addr_at(1)) + constantPoolOopDesc::CPCACHE_INDEX_TAG; |
5688 | 103 |
} |
104 |
int get_index_u4(Bytecodes::Code bc) const { |
|
105 |
assert_same_format_as(bc); assert_index_size(4, bc); |
|
106 |
assert(can_use_native_byte_order(bc), ""); |
|
107 |
return Bytes::get_native_u4(addr_at(1)); |
|
108 |
} |
|
109 |
bool has_index_u4(Bytecodes::Code bc) const { |
|
110 |
return bc == Bytecodes::_invokedynamic; |
|
111 |
} |
|
112 |
||
113 |
int get_offset_s2(Bytecodes::Code bc) const { |
|
114 |
assert_same_format_as(bc); assert_offset_size(2, bc); |
|
115 |
return (jshort) Bytes::get_Java_u2(addr_at(1)); |
|
116 |
} |
|
117 |
int get_offset_s4(Bytecodes::Code bc) const { |
|
118 |
assert_same_format_as(bc); assert_offset_size(4, bc); |
|
119 |
return (jint) Bytes::get_Java_u4(addr_at(1)); |
|
120 |
} |
|
121 |
||
122 |
int get_constant_u1(int offset, Bytecodes::Code bc) const { |
|
123 |
assert_same_format_as(bc); assert_constant_size(1, offset, bc); |
|
124 |
return *(jbyte*)addr_at(offset); |
|
125 |
} |
|
126 |
int get_constant_u2(int offset, Bytecodes::Code bc, bool is_wide = false) const { |
|
127 |
assert_same_format_as(bc, is_wide); assert_constant_size(2, offset, bc, is_wide); |
|
128 |
return (jshort) Bytes::get_Java_u2(addr_at(offset)); |
|
129 |
} |
|
130 |
||
131 |
// These are used locally and also from bytecode streams. |
|
132 |
void assert_same_format_as(Bytecodes::Code testbc, bool is_wide = false) const NOT_DEBUG_RETURN; |
|
133 |
static void assert_index_size(int required_size, Bytecodes::Code bc, bool is_wide = false) NOT_DEBUG_RETURN; |
|
134 |
static void assert_offset_size(int required_size, Bytecodes::Code bc, bool is_wide = false) NOT_DEBUG_RETURN; |
|
135 |
static void assert_constant_size(int required_size, int where, Bytecodes::Code bc, bool is_wide = false) NOT_DEBUG_RETURN; |
|
136 |
static void assert_native_index(Bytecodes::Code bc, bool is_wide = false) NOT_DEBUG_RETURN; |
|
137 |
static bool can_use_native_byte_order(Bytecodes::Code bc, bool is_wide = false) { |
|
138 |
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
|
139 |
} |
1 | 140 |
}; |
141 |
||
142 |
||
143 |
// Abstractions for lookupswitch bytecode |
|
7913 | 144 |
class LookupswitchPair VALUE_OBJ_CLASS_SPEC { |
1 | 145 |
private: |
7913 | 146 |
const address _bcp; |
147 |
||
148 |
address addr_at (int offset) const { return _bcp + offset; } |
|
149 |
int get_Java_u4_at (int offset) const { return Bytes::get_Java_u4(addr_at(offset)); } |
|
1 | 150 |
|
151 |
public: |
|
7913 | 152 |
LookupswitchPair(address bcp): _bcp(bcp) {} |
5688 | 153 |
int match() const { return get_Java_u4_at(0 * jintSize); } |
154 |
int offset() const { return get_Java_u4_at(1 * jintSize); } |
|
1 | 155 |
}; |
156 |
||
157 |
||
158 |
class Bytecode_lookupswitch: public Bytecode { |
|
159 |
public: |
|
7913 | 160 |
Bytecode_lookupswitch(methodOop method, address bcp): Bytecode(method, bcp) { verify(); } |
161 |
// Defined in ciStreams.hpp |
|
162 |
inline Bytecode_lookupswitch(const ciBytecodeStream* stream); |
|
1 | 163 |
void verify() const PRODUCT_RETURN; |
164 |
||
165 |
// Attributes |
|
5688 | 166 |
int default_offset() const { return get_Java_u4_at(aligned_offset(1 + 0*jintSize)); } |
167 |
int number_of_pairs() const { return get_Java_u4_at(aligned_offset(1 + 1*jintSize)); } |
|
7913 | 168 |
LookupswitchPair pair_at(int i) const { |
169 |
assert(0 <= i && i < number_of_pairs(), "pair index out of bounds"); |
|
170 |
return LookupswitchPair(aligned_addr_at(1 + (1 + i)*2*jintSize)); |
|
171 |
} |
|
1 | 172 |
}; |
173 |
||
174 |
class Bytecode_tableswitch: public Bytecode { |
|
175 |
public: |
|
7913 | 176 |
Bytecode_tableswitch(methodOop method, address bcp): Bytecode(method, bcp) { verify(); } |
177 |
// Defined in ciStreams.hpp |
|
178 |
inline Bytecode_tableswitch(const ciBytecodeStream* stream); |
|
1 | 179 |
void verify() const PRODUCT_RETURN; |
180 |
||
181 |
// Attributes |
|
5688 | 182 |
int default_offset() const { return get_Java_u4_at(aligned_offset(1 + 0*jintSize)); } |
183 |
int low_key() const { return get_Java_u4_at(aligned_offset(1 + 1*jintSize)); } |
|
184 |
int high_key() const { return get_Java_u4_at(aligned_offset(1 + 2*jintSize)); } |
|
1 | 185 |
int dest_offset_at(int i) const; |
186 |
int length() { return high_key()-low_key()+1; } |
|
187 |
}; |
|
188 |
||
5882 | 189 |
// Common code for decoding invokes and field references. |
1 | 190 |
|
7913 | 191 |
class Bytecode_member_ref: public Bytecode { |
1 | 192 |
protected: |
7913 | 193 |
const methodHandle _method; // method containing the bytecode |
1 | 194 |
|
7913 | 195 |
Bytecode_member_ref(methodHandle method, int bci) : Bytecode(method(), method()->bcp_from(bci)), _method(method) {} |
196 |
||
197 |
methodHandle method() const { return _method; } |
|
5882 | 198 |
|
199 |
public: |
|
200 |
int index() const; // cache index (loaded from instruction) |
|
201 |
int pool_index() const; // constant pool index |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7913
diff
changeset
|
202 |
Symbol* name() const; // returns the name of the method or field |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7913
diff
changeset
|
203 |
Symbol* signature() const; // returns the signature of the method or field |
5882 | 204 |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7913
diff
changeset
|
205 |
BasicType result_type() const; // returns the result type of the getfield or invoke |
5882 | 206 |
}; |
207 |
||
208 |
// Abstraction for invoke_{virtual, static, interface, special} |
|
209 |
||
210 |
class Bytecode_invoke: public Bytecode_member_ref { |
|
211 |
protected: |
|
7913 | 212 |
// Constructor that skips verification |
213 |
Bytecode_invoke(methodHandle method, int bci, bool unused) : Bytecode_member_ref(method, bci) {} |
|
1 | 214 |
|
215 |
public: |
|
7913 | 216 |
Bytecode_invoke(methodHandle method, int bci) : Bytecode_member_ref(method, bci) { verify(); } |
1 | 217 |
void verify() const; |
218 |
||
219 |
// Attributes |
|
220 |
methodHandle static_target(TRAPS); // "specified" method (from constant pool) |
|
221 |
||
222 |
// Testers |
|
5882 | 223 |
bool is_invokeinterface() const { return java_code() == Bytecodes::_invokeinterface; } |
224 |
bool is_invokevirtual() const { return java_code() == Bytecodes::_invokevirtual; } |
|
225 |
bool is_invokestatic() const { return java_code() == Bytecodes::_invokestatic; } |
|
226 |
bool is_invokespecial() const { return java_code() == Bytecodes::_invokespecial; } |
|
227 |
bool is_invokedynamic() const { return java_code() == Bytecodes::_invokedynamic; } |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
228 |
|
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4564
diff
changeset
|
229 |
bool has_receiver() const { return !is_invokestatic() && !is_invokedynamic(); } |
1 | 230 |
|
231 |
bool is_valid() const { return is_invokeinterface() || |
|
232 |
is_invokevirtual() || |
|
233 |
is_invokestatic() || |
|
4564
55dfb20908d0
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
3261
diff
changeset
|
234 |
is_invokespecial() || |
55dfb20908d0
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
3261
diff
changeset
|
235 |
is_invokedynamic(); } |
1 | 236 |
|
10979
c25dd872c62f
7106774: JSR 292: nightly test inlineMHTarget fails with wrong result
twisti
parents:
8107
diff
changeset
|
237 |
bool is_method_handle_invoke() const { |
c25dd872c62f
7106774: JSR 292: nightly test inlineMHTarget fails with wrong result
twisti
parents:
8107
diff
changeset
|
238 |
return (is_invokedynamic() || |
c25dd872c62f
7106774: JSR 292: nightly test inlineMHTarget fails with wrong result
twisti
parents:
8107
diff
changeset
|
239 |
(is_invokevirtual() && |
c25dd872c62f
7106774: JSR 292: nightly test inlineMHTarget fails with wrong result
twisti
parents:
8107
diff
changeset
|
240 |
method()->constants()->klass_ref_at_noresolve(index()) == vmSymbols::java_lang_invoke_MethodHandle() && |
c25dd872c62f
7106774: JSR 292: nightly test inlineMHTarget fails with wrong result
twisti
parents:
8107
diff
changeset
|
241 |
methodOopDesc::is_method_handle_invoke_name(name()))); |
c25dd872c62f
7106774: JSR 292: nightly test inlineMHTarget fails with wrong result
twisti
parents:
8107
diff
changeset
|
242 |
} |
c25dd872c62f
7106774: JSR 292: nightly test inlineMHTarget fails with wrong result
twisti
parents:
8107
diff
changeset
|
243 |
|
7913 | 244 |
// Helper to skip verification. Used is_valid() to check if the result is really an invoke |
245 |
inline friend Bytecode_invoke Bytecode_invoke_check(methodHandle method, int bci); |
|
1 | 246 |
}; |
247 |
||
7913 | 248 |
inline Bytecode_invoke Bytecode_invoke_check(methodHandle method, int bci) { |
249 |
return Bytecode_invoke(method, bci, false); |
|
1 | 250 |
} |
251 |
||
252 |
||
5882 | 253 |
// Abstraction for all field accesses (put/get field/static) |
254 |
class Bytecode_field: public Bytecode_member_ref { |
|
7913 | 255 |
public: |
256 |
Bytecode_field(methodHandle method, int bci) : Bytecode_member_ref(method, bci) { verify(); } |
|
5882 | 257 |
|
258 |
// Testers |
|
259 |
bool is_getfield() const { return java_code() == Bytecodes::_getfield; } |
|
260 |
bool is_putfield() const { return java_code() == Bytecodes::_putfield; } |
|
261 |
bool is_getstatic() const { return java_code() == Bytecodes::_getstatic; } |
|
262 |
bool is_putstatic() const { return java_code() == Bytecodes::_putstatic; } |
|
263 |
||
264 |
bool is_getter() const { return is_getfield() || is_getstatic(); } |
|
265 |
bool is_static() const { return is_getstatic() || is_putstatic(); } |
|
266 |
||
267 |
bool is_valid() const { return is_getfield() || |
|
268 |
is_putfield() || |
|
269 |
is_getstatic() || |
|
270 |
is_putstatic(); } |
|
1 | 271 |
void verify() const; |
272 |
}; |
|
273 |
||
274 |
// Abstraction for checkcast |
|
275 |
class Bytecode_checkcast: public Bytecode { |
|
276 |
public: |
|
7913 | 277 |
Bytecode_checkcast(methodOop method, address bcp): Bytecode(method, bcp) { verify(); } |
1 | 278 |
void verify() const { assert(Bytecodes::java_code(code()) == Bytecodes::_checkcast, "check checkcast"); } |
279 |
||
280 |
// Returns index |
|
5688 | 281 |
long index() const { return get_index_u2(Bytecodes::_checkcast); }; |
1 | 282 |
}; |
283 |
||
284 |
// Abstraction for instanceof |
|
285 |
class Bytecode_instanceof: public Bytecode { |
|
286 |
public: |
|
7913 | 287 |
Bytecode_instanceof(methodOop method, address bcp): Bytecode(method, bcp) { verify(); } |
1 | 288 |
void verify() const { assert(code() == Bytecodes::_instanceof, "check instanceof"); } |
289 |
||
290 |
// Returns index |
|
5688 | 291 |
long index() const { return get_index_u2(Bytecodes::_instanceof); }; |
1 | 292 |
}; |
293 |
||
294 |
class Bytecode_new: public Bytecode { |
|
295 |
public: |
|
7913 | 296 |
Bytecode_new(methodOop method, address bcp): Bytecode(method, bcp) { verify(); } |
1 | 297 |
void verify() const { assert(java_code() == Bytecodes::_new, "check new"); } |
298 |
||
299 |
// Returns index |
|
5688 | 300 |
long index() const { return get_index_u2(Bytecodes::_new); }; |
1 | 301 |
}; |
302 |
||
303 |
class Bytecode_multianewarray: public Bytecode { |
|
304 |
public: |
|
7913 | 305 |
Bytecode_multianewarray(methodOop method, address bcp): Bytecode(method, bcp) { verify(); } |
1 | 306 |
void verify() const { assert(java_code() == Bytecodes::_multianewarray, "check new"); } |
307 |
||
308 |
// Returns index |
|
5688 | 309 |
long index() const { return get_index_u2(Bytecodes::_multianewarray); }; |
1 | 310 |
}; |
311 |
||
312 |
class Bytecode_anewarray: public Bytecode { |
|
313 |
public: |
|
7913 | 314 |
Bytecode_anewarray(methodOop method, address bcp): Bytecode(method, bcp) { verify(); } |
1 | 315 |
void verify() const { assert(java_code() == Bytecodes::_anewarray, "check anewarray"); } |
316 |
||
317 |
// Returns index |
|
5688 | 318 |
long index() const { return get_index_u2(Bytecodes::_anewarray); }; |
1 | 319 |
}; |
320 |
||
321 |
// Abstraction for ldc, ldc_w and ldc2_w |
|
7913 | 322 |
class Bytecode_loadconstant: public Bytecode { |
5882 | 323 |
private: |
7913 | 324 |
const methodHandle _method; |
5882 | 325 |
|
326 |
int raw_index() const; |
|
327 |
||
1 | 328 |
public: |
7913 | 329 |
Bytecode_loadconstant(methodHandle method, int bci): Bytecode(method(), method->bcp_from(bci)), _method(method) { verify(); } |
5882 | 330 |
|
1 | 331 |
void verify() const { |
5882 | 332 |
assert(_method.not_null(), "must supply method"); |
1 | 333 |
Bytecodes::Code stdc = Bytecodes::java_code(code()); |
334 |
assert(stdc == Bytecodes::_ldc || |
|
335 |
stdc == Bytecodes::_ldc_w || |
|
336 |
stdc == Bytecodes::_ldc2_w, "load constant"); |
|
337 |
} |
|
338 |
||
5882 | 339 |
// Only non-standard bytecodes (fast_aldc) have CP cache indexes. |
340 |
bool has_cache_index() const { return code() >= Bytecodes::number_of_java_codes; } |
|
1 | 341 |
|
5882 | 342 |
int pool_index() const; // index into constant pool |
343 |
int cache_index() const { // index into CP cache (or -1 if none) |
|
344 |
return has_cache_index() ? raw_index() : -1; |
|
345 |
} |
|
346 |
||
347 |
BasicType result_type() const; // returns the result type of the ldc |
|
348 |
||
349 |
oop resolve_constant(TRAPS) const; |
|
1 | 350 |
}; |
351 |
||
7397 | 352 |
#endif // SHARE_VM_INTERPRETER_BYTECODE_HPP |