Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/interpreter/bytecode.hpp
32285 views
1
/*
2
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
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
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*
23
*/
24
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/method.hpp"
31
#ifdef TARGET_ARCH_x86
32
# include "bytes_x86.hpp"
33
#endif
34
#ifdef TARGET_ARCH_aarch32
35
# include "bytes_aarch32.hpp"
36
#endif
37
#ifdef TARGET_ARCH_aarch64
38
# include "bytes_aarch64.hpp"
39
#endif
40
#ifdef TARGET_ARCH_sparc
41
# include "bytes_sparc.hpp"
42
#endif
43
#ifdef TARGET_ARCH_zero
44
# include "bytes_zero.hpp"
45
#endif
46
#ifdef TARGET_ARCH_arm
47
# include "bytes_arm.hpp"
48
#endif
49
#ifdef TARGET_ARCH_ppc
50
# include "bytes_ppc.hpp"
51
#endif
52
53
class ciBytecodeStream;
54
55
// The base class for different kinds of bytecode abstractions.
56
// Provides the primitive operations to manipulate code relative
57
// to the bcp.
58
59
class Bytecode: public StackObj {
60
protected:
61
const address _bcp;
62
const Bytecodes::Code _code;
63
64
// Address computation
65
address addr_at (int offset) const { return (address)_bcp + offset; }
66
u_char byte_at(int offset) const { return *addr_at(offset); }
67
address aligned_addr_at (int offset) const { return (address)round_to((intptr_t)addr_at(offset), jintSize); }
68
int aligned_offset (int offset) const { return aligned_addr_at(offset) - addr_at(0); }
69
70
// Word access:
71
int get_Java_u2_at (int offset) const { return Bytes::get_Java_u2(addr_at(offset)); }
72
int get_Java_u4_at (int offset) const { return Bytes::get_Java_u4(addr_at(offset)); }
73
int get_native_u2_at (int offset) const { return Bytes::get_native_u2(addr_at(offset)); }
74
int get_native_u4_at (int offset) const { return Bytes::get_native_u4(addr_at(offset)); }
75
76
public:
77
Bytecode(Method* method, address bcp): _bcp(bcp), _code(Bytecodes::code_at(method, addr_at(0))) {
78
assert(method != NULL, "this form requires a valid Method*");
79
}
80
// Defined in ciStreams.hpp
81
inline Bytecode(const ciBytecodeStream* stream, address bcp = NULL);
82
83
// Attributes
84
address bcp() const { return _bcp; }
85
int instruction_size() const { return Bytecodes::length_for_code_at(_code, bcp()); }
86
87
Bytecodes::Code code() const { return _code; }
88
Bytecodes::Code java_code() const { return Bytecodes::java_code(code()); }
89
Bytecodes::Code invoke_code() const { return (code() == Bytecodes::_invokehandle) ? code() : java_code(); }
90
91
// Static functions for parsing bytecodes in place.
92
int get_index_u1(Bytecodes::Code bc) const {
93
assert_same_format_as(bc); assert_index_size(1, bc);
94
return *(jubyte*)addr_at(1);
95
}
96
int get_index_u2(Bytecodes::Code bc, bool is_wide = false) const {
97
assert_same_format_as(bc, is_wide); assert_index_size(2, bc, is_wide);
98
address p = addr_at(is_wide ? 2 : 1);
99
if (can_use_native_byte_order(bc, is_wide))
100
return Bytes::get_native_u2(p);
101
else return Bytes::get_Java_u2(p);
102
}
103
int get_index_u1_cpcache(Bytecodes::Code bc) const {
104
assert_same_format_as(bc); assert_index_size(1, bc);
105
return *(jubyte*)addr_at(1) + ConstantPool::CPCACHE_INDEX_TAG;
106
}
107
int get_index_u2_cpcache(Bytecodes::Code bc) const {
108
assert_same_format_as(bc); assert_index_size(2, bc); assert_native_index(bc);
109
return Bytes::get_native_u2(addr_at(1)) + ConstantPool::CPCACHE_INDEX_TAG;
110
}
111
int get_index_u4(Bytecodes::Code bc) const {
112
assert_same_format_as(bc); assert_index_size(4, bc);
113
assert(can_use_native_byte_order(bc), "");
114
return Bytes::get_native_u4(addr_at(1));
115
}
116
bool has_index_u4(Bytecodes::Code bc) const {
117
return bc == Bytecodes::_invokedynamic;
118
}
119
120
int get_offset_s2(Bytecodes::Code bc) const {
121
assert_same_format_as(bc); assert_offset_size(2, bc);
122
return (jshort) Bytes::get_Java_u2(addr_at(1));
123
}
124
int get_offset_s4(Bytecodes::Code bc) const {
125
assert_same_format_as(bc); assert_offset_size(4, bc);
126
return (jint) Bytes::get_Java_u4(addr_at(1));
127
}
128
129
int get_constant_u1(int offset, Bytecodes::Code bc) const {
130
assert_same_format_as(bc); assert_constant_size(1, offset, bc);
131
return *(jbyte*)addr_at(offset);
132
}
133
int get_constant_u2(int offset, Bytecodes::Code bc, bool is_wide = false) const {
134
assert_same_format_as(bc, is_wide); assert_constant_size(2, offset, bc, is_wide);
135
return (jshort) Bytes::get_Java_u2(addr_at(offset));
136
}
137
138
// These are used locally and also from bytecode streams.
139
void assert_same_format_as(Bytecodes::Code testbc, bool is_wide = false) const NOT_DEBUG_RETURN;
140
static void assert_index_size(int required_size, Bytecodes::Code bc, bool is_wide = false) NOT_DEBUG_RETURN;
141
static void assert_offset_size(int required_size, Bytecodes::Code bc, bool is_wide = false) NOT_DEBUG_RETURN;
142
static void assert_constant_size(int required_size, int where, Bytecodes::Code bc, bool is_wide = false) NOT_DEBUG_RETURN;
143
static void assert_native_index(Bytecodes::Code bc, bool is_wide = false) NOT_DEBUG_RETURN;
144
static bool can_use_native_byte_order(Bytecodes::Code bc, bool is_wide = false) {
145
return (!Bytes::is_Java_byte_ordering_different() || Bytecodes::native_byte_order(bc /*, is_wide*/));
146
}
147
};
148
149
150
// Abstractions for lookupswitch bytecode
151
class LookupswitchPair VALUE_OBJ_CLASS_SPEC {
152
private:
153
const address _bcp;
154
155
address addr_at (int offset) const { return _bcp + offset; }
156
int get_Java_u4_at (int offset) const { return Bytes::get_Java_u4(addr_at(offset)); }
157
158
public:
159
LookupswitchPair(address bcp): _bcp(bcp) {}
160
int match() const { return get_Java_u4_at(0 * jintSize); }
161
int offset() const { return get_Java_u4_at(1 * jintSize); }
162
};
163
164
165
class Bytecode_lookupswitch: public Bytecode {
166
public:
167
Bytecode_lookupswitch(Method* method, address bcp): Bytecode(method, bcp) { verify(); }
168
// Defined in ciStreams.hpp
169
inline Bytecode_lookupswitch(const ciBytecodeStream* stream);
170
void verify() const PRODUCT_RETURN;
171
172
// Attributes
173
int default_offset() const { return get_Java_u4_at(aligned_offset(1 + 0*jintSize)); }
174
int number_of_pairs() const { return get_Java_u4_at(aligned_offset(1 + 1*jintSize)); }
175
LookupswitchPair pair_at(int i) const {
176
assert(0 <= i && i < number_of_pairs(), "pair index out of bounds");
177
return LookupswitchPair(aligned_addr_at(1 + (1 + i)*2*jintSize));
178
}
179
};
180
181
class Bytecode_tableswitch: public Bytecode {
182
public:
183
Bytecode_tableswitch(Method* method, address bcp): Bytecode(method, bcp) { verify(); }
184
// Defined in ciStreams.hpp
185
inline Bytecode_tableswitch(const ciBytecodeStream* stream);
186
void verify() const PRODUCT_RETURN;
187
188
// Attributes
189
int default_offset() const { return get_Java_u4_at(aligned_offset(1 + 0*jintSize)); }
190
int low_key() const { return get_Java_u4_at(aligned_offset(1 + 1*jintSize)); }
191
int high_key() const { return get_Java_u4_at(aligned_offset(1 + 2*jintSize)); }
192
int dest_offset_at(int i) const;
193
int length() { return high_key()-low_key()+1; }
194
};
195
196
// Common code for decoding invokes and field references.
197
198
class Bytecode_member_ref: public Bytecode {
199
protected:
200
const methodHandle _method; // method containing the bytecode
201
202
Bytecode_member_ref(methodHandle method, int bci) : Bytecode(method(), method()->bcp_from(bci)), _method(method) {}
203
204
methodHandle method() const { return _method; }
205
ConstantPool* constants() const { return _method->constants(); }
206
ConstantPoolCache* cpcache() const { return _method->constants()->cache(); }
207
ConstantPoolCacheEntry* cpcache_entry() const;
208
209
public:
210
int index() const; // cache index (loaded from instruction)
211
int pool_index() const; // constant pool index
212
Symbol* klass() const; // returns the klass of the method or field
213
Symbol* name() const; // returns the name of the method or field
214
Symbol* signature() const; // returns the signature of the method or field
215
216
BasicType result_type() const; // returns the result type of the getfield or invoke
217
};
218
219
// Abstraction for invoke_{virtual, static, interface, special}
220
221
class Bytecode_invoke: public Bytecode_member_ref {
222
protected:
223
// Constructor that skips verification
224
Bytecode_invoke(methodHandle method, int bci, bool unused) : Bytecode_member_ref(method, bci) {}
225
226
public:
227
Bytecode_invoke(methodHandle method, int bci) : Bytecode_member_ref(method, bci) { verify(); }
228
void verify() const;
229
230
// Attributes
231
methodHandle static_target(TRAPS); // "specified" method (from constant pool)
232
Handle appendix(TRAPS); // if CPCE::has_appendix (from constant pool)
233
234
// Testers
235
bool is_invokeinterface() const { return invoke_code() == Bytecodes::_invokeinterface; }
236
bool is_invokevirtual() const { return invoke_code() == Bytecodes::_invokevirtual; }
237
bool is_invokestatic() const { return invoke_code() == Bytecodes::_invokestatic; }
238
bool is_invokespecial() const { return invoke_code() == Bytecodes::_invokespecial; }
239
bool is_invokedynamic() const { return invoke_code() == Bytecodes::_invokedynamic; }
240
bool is_invokehandle() const { return invoke_code() == Bytecodes::_invokehandle; }
241
242
bool has_receiver() const { return !is_invokestatic() && !is_invokedynamic(); }
243
244
bool is_valid() const { return is_invokeinterface() ||
245
is_invokevirtual() ||
246
is_invokestatic() ||
247
is_invokespecial() ||
248
is_invokedynamic() ||
249
is_invokehandle(); }
250
251
bool has_appendix() { return cpcache_entry()->has_appendix(); }
252
253
private:
254
// Helper to skip verification. Used is_valid() to check if the result is really an invoke
255
inline friend Bytecode_invoke Bytecode_invoke_check(methodHandle method, int bci);
256
};
257
258
inline Bytecode_invoke Bytecode_invoke_check(methodHandle method, int bci) {
259
return Bytecode_invoke(method, bci, false);
260
}
261
262
263
// Abstraction for all field accesses (put/get field/static)
264
class Bytecode_field: public Bytecode_member_ref {
265
public:
266
Bytecode_field(methodHandle method, int bci) : Bytecode_member_ref(method, bci) { verify(); }
267
268
// Testers
269
bool is_getfield() const { return java_code() == Bytecodes::_getfield; }
270
bool is_putfield() const { return java_code() == Bytecodes::_putfield; }
271
bool is_getstatic() const { return java_code() == Bytecodes::_getstatic; }
272
bool is_putstatic() const { return java_code() == Bytecodes::_putstatic; }
273
274
bool is_getter() const { return is_getfield() || is_getstatic(); }
275
bool is_static() const { return is_getstatic() || is_putstatic(); }
276
277
bool is_valid() const { return is_getfield() ||
278
is_putfield() ||
279
is_getstatic() ||
280
is_putstatic(); }
281
void verify() const;
282
};
283
284
// Abstraction for checkcast
285
class Bytecode_checkcast: public Bytecode {
286
public:
287
Bytecode_checkcast(Method* method, address bcp): Bytecode(method, bcp) { verify(); }
288
void verify() const { assert(Bytecodes::java_code(code()) == Bytecodes::_checkcast, "check checkcast"); }
289
290
// Returns index
291
long index() const { return get_index_u2(Bytecodes::_checkcast); };
292
};
293
294
// Abstraction for instanceof
295
class Bytecode_instanceof: public Bytecode {
296
public:
297
Bytecode_instanceof(Method* method, address bcp): Bytecode(method, bcp) { verify(); }
298
void verify() const { assert(code() == Bytecodes::_instanceof, "check instanceof"); }
299
300
// Returns index
301
long index() const { return get_index_u2(Bytecodes::_instanceof); };
302
};
303
304
class Bytecode_new: public Bytecode {
305
public:
306
Bytecode_new(Method* method, address bcp): Bytecode(method, bcp) { verify(); }
307
void verify() const { assert(java_code() == Bytecodes::_new, "check new"); }
308
309
// Returns index
310
long index() const { return get_index_u2(Bytecodes::_new); };
311
};
312
313
class Bytecode_multianewarray: public Bytecode {
314
public:
315
Bytecode_multianewarray(Method* method, address bcp): Bytecode(method, bcp) { verify(); }
316
void verify() const { assert(java_code() == Bytecodes::_multianewarray, "check new"); }
317
318
// Returns index
319
long index() const { return get_index_u2(Bytecodes::_multianewarray); };
320
};
321
322
class Bytecode_anewarray: public Bytecode {
323
public:
324
Bytecode_anewarray(Method* method, address bcp): Bytecode(method, bcp) { verify(); }
325
void verify() const { assert(java_code() == Bytecodes::_anewarray, "check anewarray"); }
326
327
// Returns index
328
long index() const { return get_index_u2(Bytecodes::_anewarray); };
329
};
330
331
// Abstraction for ldc, ldc_w and ldc2_w
332
class Bytecode_loadconstant: public Bytecode {
333
private:
334
const methodHandle _method;
335
336
int raw_index() const;
337
338
public:
339
Bytecode_loadconstant(methodHandle method, int bci): Bytecode(method(), method->bcp_from(bci)), _method(method) { verify(); }
340
341
void verify() const {
342
assert(_method.not_null(), "must supply method");
343
Bytecodes::Code stdc = Bytecodes::java_code(code());
344
assert(stdc == Bytecodes::_ldc ||
345
stdc == Bytecodes::_ldc_w ||
346
stdc == Bytecodes::_ldc2_w, "load constant");
347
}
348
349
// Only non-standard bytecodes (fast_aldc) have reference cache indexes.
350
bool has_cache_index() const { return code() >= Bytecodes::number_of_java_codes; }
351
352
int pool_index() const; // index into constant pool
353
int cache_index() const { // index into reference cache (or -1 if none)
354
return has_cache_index() ? raw_index() : -1;
355
}
356
357
BasicType result_type() const; // returns the result type of the ldc
358
359
oop resolve_constant(TRAPS) const;
360
};
361
362
#endif // SHARE_VM_INTERPRETER_BYTECODE_HPP
363
364