author | goetz |
Fri, 04 Jul 2014 11:46:01 +0200 | |
changeset 25715 | d5a8dbdc5150 |
parent 13728 | 882756847a04 |
child 33593 | 60764a78fa5c |
permissions | -rw-r--r-- |
1 | 1 |
/* |
25715
d5a8dbdc5150
8049325: Introduce and clean up umbrella headers for the files in the cpu subdirectories.
goetz
parents:
13728
diff
changeset
|
2 |
* Copyright (c) 1997, 2014, 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:
3261
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
3261
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:
3261
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 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" |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8107
diff
changeset
|
30 |
#include "oops/method.hpp" |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8107
diff
changeset
|
31 |
#include "runtime/handles.inline.hpp" |
25715
d5a8dbdc5150
8049325: Introduce and clean up umbrella headers for the files in the cpu subdirectories.
goetz
parents:
13728
diff
changeset
|
32 |
#include "utilities/bytes.hpp" |
7397 | 33 |
|
1 | 34 |
// A BytecodeStream is used for fast iteration over the bytecodes |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8107
diff
changeset
|
35 |
// of a Method*. |
1 | 36 |
// |
37 |
// Usage: |
|
38 |
// |
|
39 |
// BytecodeStream s(method); |
|
40 |
// Bytecodes::Code c; |
|
41 |
// while ((c = s.next()) >= 0) { |
|
42 |
// ... |
|
43 |
// } |
|
5688 | 44 |
|
1 | 45 |
// A RawBytecodeStream is a simple version of BytecodeStream. |
46 |
// It is used ONLY when we know the bytecodes haven't been rewritten |
|
5688 | 47 |
// yet, such as in the rewriter or the verifier. |
1 | 48 |
|
5688 | 49 |
// Here is the common base class for both RawBytecodeStream and BytecodeStream: |
50 |
class BaseBytecodeStream: StackObj { |
|
1 | 51 |
protected: |
52 |
// stream buffer |
|
53 |
methodHandle _method; // read from method directly |
|
54 |
||
55 |
// reading position |
|
56 |
int _bci; // bci if current bytecode |
|
57 |
int _next_bci; // bci of next bytecode |
|
58 |
int _end_bci; // bci after the current iteration interval |
|
59 |
||
60 |
// last bytecode read |
|
5688 | 61 |
Bytecodes::Code _raw_code; |
1 | 62 |
bool _is_wide; |
5688 | 63 |
bool _is_raw; // false in 'cooked' BytecodeStream |
64 |
||
65 |
// Construction |
|
66 |
BaseBytecodeStream(methodHandle method) : _method(method) { |
|
67 |
set_interval(0, _method->code_size()); |
|
68 |
_is_raw = false; |
|
69 |
} |
|
1 | 70 |
|
71 |
public: |
|
72 |
// Iteration control |
|
73 |
void set_interval(int beg_bci, int end_bci) { |
|
74 |
// iterate over the interval [beg_bci, end_bci) |
|
75 |
assert(0 <= beg_bci && beg_bci <= method()->code_size(), "illegal beg_bci"); |
|
76 |
assert(0 <= end_bci && end_bci <= method()->code_size(), "illegal end_bci"); |
|
77 |
// setup of iteration pointers |
|
78 |
_bci = beg_bci; |
|
79 |
_next_bci = beg_bci; |
|
80 |
_end_bci = end_bci; |
|
81 |
} |
|
82 |
void set_start (int beg_bci) { |
|
83 |
set_interval(beg_bci, _method->code_size()); |
|
84 |
} |
|
85 |
||
5688 | 86 |
bool is_raw() const { return _is_raw; } |
87 |
||
88 |
// Stream attributes |
|
89 |
methodHandle method() const { return _method; } |
|
90 |
||
91 |
int bci() const { return _bci; } |
|
92 |
int next_bci() const { return _next_bci; } |
|
93 |
int end_bci() const { return _end_bci; } |
|
94 |
||
95 |
Bytecodes::Code raw_code() const { return _raw_code; } |
|
96 |
bool is_wide() const { return _is_wide; } |
|
97 |
int instruction_size() const { return (_next_bci - _bci); } |
|
98 |
bool is_last_bytecode() const { return _next_bci >= _end_bci; } |
|
99 |
||
100 |
address bcp() const { return method()->code_base() + _bci; } |
|
7913 | 101 |
Bytecode bytecode() const { return Bytecode(_method(), bcp()); } |
5688 | 102 |
|
103 |
// State changes |
|
104 |
void set_next_bci(int bci) { assert(0 <= bci && bci <= method()->code_size(), "illegal bci"); _next_bci = bci; } |
|
105 |
||
106 |
// Bytecode-specific attributes |
|
7913 | 107 |
int dest() const { return bci() + bytecode().get_offset_s2(raw_code()); } |
108 |
int dest_w() const { return bci() + bytecode().get_offset_s4(raw_code()); } |
|
5688 | 109 |
|
110 |
// One-byte indices. |
|
111 |
int get_index_u1() const { assert_raw_index_size(1); return *(jubyte*)(bcp()+1); } |
|
112 |
||
113 |
protected: |
|
114 |
void assert_raw_index_size(int size) const NOT_DEBUG_RETURN; |
|
115 |
void assert_raw_stream(bool want_raw) const NOT_DEBUG_RETURN; |
|
116 |
}; |
|
117 |
||
118 |
class RawBytecodeStream: public BaseBytecodeStream { |
|
119 |
public: |
|
120 |
// Construction |
|
121 |
RawBytecodeStream(methodHandle method) : BaseBytecodeStream(method) { |
|
122 |
_is_raw = true; |
|
123 |
} |
|
124 |
||
125 |
public: |
|
1 | 126 |
// Iteration |
127 |
// Use raw_next() rather than next() for faster method reference |
|
128 |
Bytecodes::Code raw_next() { |
|
129 |
Bytecodes::Code code; |
|
130 |
// set reading position |
|
131 |
_bci = _next_bci; |
|
132 |
assert(!is_last_bytecode(), "caller should check is_last_bytecode()"); |
|
133 |
||
5688 | 134 |
address bcp = this->bcp(); |
1 | 135 |
code = Bytecodes::code_or_bp_at(bcp); |
136 |
||
137 |
// set next bytecode position |
|
138 |
int l = Bytecodes::length_for(code); |
|
139 |
if (l > 0 && (_bci + l) <= _end_bci) { |
|
140 |
assert(code != Bytecodes::_wide && code != Bytecodes::_tableswitch |
|
141 |
&& code != Bytecodes::_lookupswitch, "can't be special bytecode"); |
|
142 |
_is_wide = false; |
|
143 |
_next_bci += l; |
|
5688 | 144 |
_raw_code = code; |
1 | 145 |
return code; |
146 |
} else { |
|
147 |
return raw_next_special(code); |
|
148 |
} |
|
149 |
} |
|
150 |
Bytecodes::Code raw_next_special(Bytecodes::Code code); |
|
151 |
||
5688 | 152 |
// Unsigned indices, widening, with no swapping of bytes |
153 |
int get_index() const { return (is_wide()) ? get_index_u2_raw(bcp() + 2) : get_index_u1(); } |
|
154 |
// Get an unsigned 2-byte index, with no swapping of bytes. |
|
155 |
int get_index_u2() const { assert(!is_wide(), ""); return get_index_u2_raw(bcp() + 1); } |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
156 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
157 |
private: |
5688 | 158 |
int get_index_u2_raw(address p) const { |
159 |
assert_raw_index_size(2); assert_raw_stream(true); |
|
160 |
return Bytes::get_Java_u2(p); |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
161 |
} |
1 | 162 |
}; |
163 |
||
164 |
// In BytecodeStream, non-java bytecodes will be translated into the |
|
165 |
// corresponding java bytecodes. |
|
166 |
||
5688 | 167 |
class BytecodeStream: public BaseBytecodeStream { |
168 |
Bytecodes::Code _code; |
|
169 |
||
1 | 170 |
public: |
171 |
// Construction |
|
5688 | 172 |
BytecodeStream(methodHandle method) : BaseBytecodeStream(method) { } |
1 | 173 |
|
174 |
// Iteration |
|
175 |
Bytecodes::Code next() { |
|
5688 | 176 |
Bytecodes::Code raw_code, code; |
1 | 177 |
// set reading position |
178 |
_bci = _next_bci; |
|
179 |
if (is_last_bytecode()) { |
|
180 |
// indicate end of bytecode stream |
|
5688 | 181 |
raw_code = code = Bytecodes::_illegal; |
1 | 182 |
} else { |
183 |
// get bytecode |
|
5688 | 184 |
address bcp = this->bcp(); |
7913 | 185 |
raw_code = Bytecodes::code_at(_method(), bcp); |
5688 | 186 |
code = Bytecodes::java_code(raw_code); |
1 | 187 |
// set next bytecode position |
188 |
// |
|
189 |
// note that we cannot advance before having the |
|
190 |
// tty bytecode otherwise the stepping is wrong! |
|
191 |
// (carefull: length_for(...) must be used first!) |
|
192 |
int l = Bytecodes::length_for(code); |
|
7913 | 193 |
if (l == 0) l = Bytecodes::length_at(_method(), bcp); |
1 | 194 |
_next_bci += l; |
195 |
assert(_bci < _next_bci, "length must be > 0"); |
|
196 |
// set attributes |
|
197 |
_is_wide = false; |
|
198 |
// check for special (uncommon) cases |
|
199 |
if (code == Bytecodes::_wide) { |
|
5688 | 200 |
raw_code = (Bytecodes::Code)bcp[1]; |
201 |
code = raw_code; // wide BCs are always Java-normal |
|
1 | 202 |
_is_wide = true; |
203 |
} |
|
204 |
assert(Bytecodes::is_java_code(code), "sanity check"); |
|
205 |
} |
|
5688 | 206 |
_raw_code = raw_code; |
1 | 207 |
_code = code; |
208 |
return _code; |
|
209 |
} |
|
210 |
||
211 |
bool is_active_breakpoint() const { return Bytecodes::is_active_breakpoint_at(bcp()); } |
|
5688 | 212 |
Bytecodes::Code code() const { return _code; } |
213 |
||
214 |
// Unsigned indices, widening |
|
7913 | 215 |
int get_index() const { return is_wide() ? bytecode().get_index_u2(raw_code(), true) : get_index_u1(); } |
5688 | 216 |
// Get an unsigned 2-byte index, swapping the bytes if necessary. |
217 |
int get_index_u2() const { assert_raw_stream(false); |
|
7913 | 218 |
return bytecode().get_index_u2(raw_code(), false); } |
5688 | 219 |
// Get an unsigned 2-byte index in native order. |
220 |
int get_index_u2_cpcache() const { assert_raw_stream(false); |
|
7913 | 221 |
return bytecode().get_index_u2_cpcache(raw_code()); } |
5688 | 222 |
int get_index_u4() const { assert_raw_stream(false); |
7913 | 223 |
return bytecode().get_index_u4(raw_code()); } |
224 |
bool has_index_u4() const { return bytecode().has_index_u4(raw_code()); } |
|
1 | 225 |
}; |
7397 | 226 |
|
227 |
#endif // SHARE_VM_INTERPRETER_BYTECODESTREAM_HPP |