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/bytecodeStream.hpp
32285 views
1
/*
2
* Copyright (c) 1997, 2016, 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_BYTECODESTREAM_HPP
26
#define SHARE_VM_INTERPRETER_BYTECODESTREAM_HPP
27
28
#include "interpreter/bytecode.hpp"
29
#include "memory/allocation.hpp"
30
#include "oops/method.hpp"
31
#include "runtime/handles.inline.hpp"
32
#ifdef TARGET_ARCH_x86
33
# include "bytes_x86.hpp"
34
#endif
35
#ifdef TARGET_ARCH_aarch32
36
# include "bytes_aarch32.hpp"
37
#endif
38
#ifdef TARGET_ARCH_aarch64
39
# include "bytes_aarch64.hpp"
40
#endif
41
#ifdef TARGET_ARCH_sparc
42
# include "bytes_sparc.hpp"
43
#endif
44
#ifdef TARGET_ARCH_zero
45
# include "bytes_zero.hpp"
46
#endif
47
#ifdef TARGET_ARCH_arm
48
# include "bytes_arm.hpp"
49
#endif
50
#ifdef TARGET_ARCH_ppc
51
# include "bytes_ppc.hpp"
52
#endif
53
54
// A BytecodeStream is used for fast iteration over the bytecodes
55
// of a Method*.
56
//
57
// Usage:
58
//
59
// BytecodeStream s(method);
60
// Bytecodes::Code c;
61
// while ((c = s.next()) >= 0) {
62
// ...
63
// }
64
65
// A RawBytecodeStream is a simple version of BytecodeStream.
66
// It is used ONLY when we know the bytecodes haven't been rewritten
67
// yet, such as in the rewriter or the verifier.
68
69
// Here is the common base class for both RawBytecodeStream and BytecodeStream:
70
class BaseBytecodeStream: StackObj {
71
protected:
72
// stream buffer
73
methodHandle _method; // read from method directly
74
75
// reading position
76
int _bci; // bci if current bytecode
77
int _next_bci; // bci of next bytecode
78
int _end_bci; // bci after the current iteration interval
79
80
// last bytecode read
81
Bytecodes::Code _raw_code;
82
bool _is_wide;
83
bool _is_raw; // false in 'cooked' BytecodeStream
84
85
// Construction
86
BaseBytecodeStream(methodHandle method) : _method(method) {
87
set_interval(0, _method->code_size());
88
_is_raw = false;
89
}
90
91
public:
92
// Iteration control
93
void set_interval(int beg_bci, int end_bci) {
94
// iterate over the interval [beg_bci, end_bci)
95
assert(0 <= beg_bci && beg_bci <= method()->code_size(), "illegal beg_bci");
96
assert(0 <= end_bci && end_bci <= method()->code_size(), "illegal end_bci");
97
// setup of iteration pointers
98
_bci = beg_bci;
99
_next_bci = beg_bci;
100
_end_bci = end_bci;
101
}
102
void set_start (int beg_bci) {
103
set_interval(beg_bci, _method->code_size());
104
}
105
106
bool is_raw() const { return _is_raw; }
107
108
// Stream attributes
109
methodHandle method() const { return _method; }
110
111
int bci() const { return _bci; }
112
int next_bci() const { return _next_bci; }
113
int end_bci() const { return _end_bci; }
114
115
Bytecodes::Code raw_code() const { return _raw_code; }
116
bool is_wide() const { return _is_wide; }
117
int instruction_size() const { return (_next_bci - _bci); }
118
bool is_last_bytecode() const { return _next_bci >= _end_bci; }
119
120
address bcp() const { return method()->code_base() + _bci; }
121
Bytecode bytecode() const { return Bytecode(_method(), bcp()); }
122
123
// State changes
124
void set_next_bci(int bci) { assert(0 <= bci && bci <= method()->code_size(), "illegal bci"); _next_bci = bci; }
125
126
// Bytecode-specific attributes
127
int dest() const { return bci() + bytecode().get_offset_s2(raw_code()); }
128
int dest_w() const { return bci() + bytecode().get_offset_s4(raw_code()); }
129
130
// One-byte indices.
131
int get_index_u1() const { assert_raw_index_size(1); return *(jubyte*)(bcp()+1); }
132
133
protected:
134
void assert_raw_index_size(int size) const NOT_DEBUG_RETURN;
135
void assert_raw_stream(bool want_raw) const NOT_DEBUG_RETURN;
136
};
137
138
class RawBytecodeStream: public BaseBytecodeStream {
139
public:
140
// Construction
141
RawBytecodeStream(methodHandle method) : BaseBytecodeStream(method) {
142
_is_raw = true;
143
}
144
145
public:
146
// Iteration
147
// Use raw_next() rather than next() for faster method reference
148
Bytecodes::Code raw_next() {
149
Bytecodes::Code code;
150
// set reading position
151
_bci = _next_bci;
152
assert(!is_last_bytecode(), "caller should check is_last_bytecode()");
153
154
address bcp = this->bcp();
155
code = Bytecodes::code_or_bp_at(bcp);
156
157
// set next bytecode position
158
int len = Bytecodes::length_for(code);
159
if (len > 0 && (_bci <= _end_bci - len)) {
160
assert(code != Bytecodes::_wide && code != Bytecodes::_tableswitch
161
&& code != Bytecodes::_lookupswitch, "can't be special bytecode");
162
_is_wide = false;
163
_next_bci += len;
164
if (_next_bci <= _bci) { // Check for integer overflow
165
code = Bytecodes::_illegal;
166
}
167
_raw_code = code;
168
return code;
169
} else {
170
return raw_next_special(code);
171
}
172
}
173
Bytecodes::Code raw_next_special(Bytecodes::Code code);
174
175
// Unsigned indices, widening, with no swapping of bytes
176
int get_index() const { return (is_wide()) ? get_index_u2_raw(bcp() + 2) : get_index_u1(); }
177
// Get an unsigned 2-byte index, with no swapping of bytes.
178
int get_index_u2() const { assert(!is_wide(), ""); return get_index_u2_raw(bcp() + 1); }
179
180
private:
181
int get_index_u2_raw(address p) const {
182
assert_raw_index_size(2); assert_raw_stream(true);
183
return Bytes::get_Java_u2(p);
184
}
185
};
186
187
// In BytecodeStream, non-java bytecodes will be translated into the
188
// corresponding java bytecodes.
189
190
class BytecodeStream: public BaseBytecodeStream {
191
Bytecodes::Code _code;
192
193
public:
194
// Construction
195
BytecodeStream(methodHandle method) : BaseBytecodeStream(method) { }
196
197
// Iteration
198
Bytecodes::Code next() {
199
Bytecodes::Code raw_code, code;
200
// set reading position
201
_bci = _next_bci;
202
if (is_last_bytecode()) {
203
// indicate end of bytecode stream
204
raw_code = code = Bytecodes::_illegal;
205
} else {
206
// get bytecode
207
address bcp = this->bcp();
208
raw_code = Bytecodes::code_at(_method(), bcp);
209
code = Bytecodes::java_code(raw_code);
210
// set next bytecode position
211
//
212
// note that we cannot advance before having the
213
// tty bytecode otherwise the stepping is wrong!
214
// (carefull: length_for(...) must be used first!)
215
int len = Bytecodes::length_for(code);
216
if (len == 0) len = Bytecodes::length_at(_method(), bcp);
217
if (len <= 0 || (_bci > _end_bci - len) || (_bci - len >= _next_bci)) {
218
raw_code = code = Bytecodes::_illegal;
219
} else {
220
_next_bci += len;
221
assert(_bci < _next_bci, "length must be > 0");
222
// set attributes
223
_is_wide = false;
224
// check for special (uncommon) cases
225
if (code == Bytecodes::_wide) {
226
raw_code = (Bytecodes::Code)bcp[1];
227
code = raw_code; // wide BCs are always Java-normal
228
_is_wide = true;
229
}
230
assert(Bytecodes::is_java_code(code), "sanity check");
231
}
232
}
233
_raw_code = raw_code;
234
_code = code;
235
return _code;
236
}
237
238
bool is_active_breakpoint() const { return Bytecodes::is_active_breakpoint_at(bcp()); }
239
Bytecodes::Code code() const { return _code; }
240
241
// Unsigned indices, widening
242
int get_index() const { return is_wide() ? bytecode().get_index_u2(raw_code(), true) : get_index_u1(); }
243
// Get an unsigned 2-byte index, swapping the bytes if necessary.
244
int get_index_u2() const { assert_raw_stream(false);
245
return bytecode().get_index_u2(raw_code(), false); }
246
// Get an unsigned 2-byte index in native order.
247
int get_index_u2_cpcache() const { assert_raw_stream(false);
248
return bytecode().get_index_u2_cpcache(raw_code()); }
249
int get_index_u4() const { assert_raw_stream(false);
250
return bytecode().get_index_u4(raw_code()); }
251
bool has_index_u4() const { return bytecode().has_index_u4(raw_code()); }
252
};
253
254
#endif // SHARE_VM_INTERPRETER_BYTECODESTREAM_HPP
255
256