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