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