Mercurial > hg > truffle
annotate src/share/vm/interpreter/bytecodeStream.hpp @ 1604:b918d354830a
6960865: ldc of unloaded class throws an assert in ciTypeFlow
Summary: Support java_mirror for unloaded klasses, arrays as well as instances. Simplify ciTypeFlow by removing unused path.
Reviewed-by: kvn
author | jrose |
---|---|
date | Sat, 12 Jun 2010 22:53:43 -0700 |
parents | e9ff18c4ace7 |
children | f95d63e2154a |
rev | line source |
---|---|
0 | 1 /* |
1579 | 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
844
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
844
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
844
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
25 // A BytecodeStream is used for fast iteration over the bytecodes | |
26 // of a methodOop. | |
27 // | |
28 // Usage: | |
29 // | |
30 // BytecodeStream s(method); | |
31 // Bytecodes::Code c; | |
32 // while ((c = s.next()) >= 0) { | |
33 // ... | |
34 // } | |
1565 | 35 |
0 | 36 // A RawBytecodeStream is a simple version of BytecodeStream. |
37 // It is used ONLY when we know the bytecodes haven't been rewritten | |
1565 | 38 // yet, such as in the rewriter or the verifier. |
0 | 39 |
1565 | 40 // Here is the common base class for both RawBytecodeStream and BytecodeStream: |
41 class BaseBytecodeStream: StackObj { | |
0 | 42 protected: |
43 // stream buffer | |
44 methodHandle _method; // read from method directly | |
45 | |
46 // reading position | |
47 int _bci; // bci if current bytecode | |
48 int _next_bci; // bci of next bytecode | |
49 int _end_bci; // bci after the current iteration interval | |
50 | |
51 // last bytecode read | |
1565 | 52 Bytecodes::Code _raw_code; |
0 | 53 bool _is_wide; |
1565 | 54 bool _is_raw; // false in 'cooked' BytecodeStream |
55 | |
56 // Construction | |
57 BaseBytecodeStream(methodHandle method) : _method(method) { | |
58 set_interval(0, _method->code_size()); | |
59 _is_raw = false; | |
60 } | |
0 | 61 |
62 public: | |
63 // Iteration control | |
64 void set_interval(int beg_bci, int end_bci) { | |
65 // iterate over the interval [beg_bci, end_bci) | |
66 assert(0 <= beg_bci && beg_bci <= method()->code_size(), "illegal beg_bci"); | |
67 assert(0 <= end_bci && end_bci <= method()->code_size(), "illegal end_bci"); | |
68 // setup of iteration pointers | |
69 _bci = beg_bci; | |
70 _next_bci = beg_bci; | |
71 _end_bci = end_bci; | |
72 } | |
73 void set_start (int beg_bci) { | |
74 set_interval(beg_bci, _method->code_size()); | |
75 } | |
76 | |
1565 | 77 bool is_raw() const { return _is_raw; } |
78 | |
79 // Stream attributes | |
80 methodHandle method() const { return _method; } | |
81 | |
82 int bci() const { return _bci; } | |
83 int next_bci() const { return _next_bci; } | |
84 int end_bci() const { return _end_bci; } | |
85 | |
86 Bytecodes::Code raw_code() const { return _raw_code; } | |
87 bool is_wide() const { return _is_wide; } | |
88 int instruction_size() const { return (_next_bci - _bci); } | |
89 bool is_last_bytecode() const { return _next_bci >= _end_bci; } | |
90 | |
91 address bcp() const { return method()->code_base() + _bci; } | |
92 Bytecode* bytecode() const { return Bytecode_at(bcp()); } | |
93 | |
94 // State changes | |
95 void set_next_bci(int bci) { assert(0 <= bci && bci <= method()->code_size(), "illegal bci"); _next_bci = bci; } | |
96 | |
97 // Bytecode-specific attributes | |
98 int dest() const { return bci() + bytecode()->get_offset_s2(raw_code()); } | |
99 int dest_w() const { return bci() + bytecode()->get_offset_s4(raw_code()); } | |
100 | |
101 // One-byte indices. | |
102 int get_index_u1() const { assert_raw_index_size(1); return *(jubyte*)(bcp()+1); } | |
103 | |
104 protected: | |
105 void assert_raw_index_size(int size) const NOT_DEBUG_RETURN; | |
106 void assert_raw_stream(bool want_raw) const NOT_DEBUG_RETURN; | |
107 }; | |
108 | |
109 class RawBytecodeStream: public BaseBytecodeStream { | |
110 public: | |
111 // Construction | |
112 RawBytecodeStream(methodHandle method) : BaseBytecodeStream(method) { | |
113 _is_raw = true; | |
114 } | |
115 | |
116 public: | |
0 | 117 // Iteration |
118 // Use raw_next() rather than next() for faster method reference | |
119 Bytecodes::Code raw_next() { | |
120 Bytecodes::Code code; | |
121 // set reading position | |
122 _bci = _next_bci; | |
123 assert(!is_last_bytecode(), "caller should check is_last_bytecode()"); | |
124 | |
1565 | 125 address bcp = this->bcp(); |
0 | 126 code = Bytecodes::code_or_bp_at(bcp); |
127 | |
128 // set next bytecode position | |
129 int l = Bytecodes::length_for(code); | |
130 if (l > 0 && (_bci + l) <= _end_bci) { | |
131 assert(code != Bytecodes::_wide && code != Bytecodes::_tableswitch | |
132 && code != Bytecodes::_lookupswitch, "can't be special bytecode"); | |
133 _is_wide = false; | |
134 _next_bci += l; | |
1565 | 135 _raw_code = code; |
0 | 136 return code; |
137 } else { | |
138 return raw_next_special(code); | |
139 } | |
140 } | |
141 Bytecodes::Code raw_next_special(Bytecodes::Code code); | |
142 | |
1565 | 143 // Unsigned indices, widening, with no swapping of bytes |
144 int get_index() const { return (is_wide()) ? get_index_u2_raw(bcp() + 2) : get_index_u1(); } | |
145 // Get an unsigned 2-byte index, with no swapping of bytes. | |
146 int get_index_u2() const { assert(!is_wide(), ""); return get_index_u2_raw(bcp() + 1); } | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
147 |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
148 private: |
1565 | 149 int get_index_u2_raw(address p) const { |
150 assert_raw_index_size(2); assert_raw_stream(true); | |
151 return Bytes::get_Java_u2(p); | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
152 } |
0 | 153 }; |
154 | |
155 // In BytecodeStream, non-java bytecodes will be translated into the | |
156 // corresponding java bytecodes. | |
157 | |
1565 | 158 class BytecodeStream: public BaseBytecodeStream { |
159 Bytecodes::Code _code; | |
160 | |
0 | 161 public: |
162 // Construction | |
1565 | 163 BytecodeStream(methodHandle method) : BaseBytecodeStream(method) { } |
0 | 164 |
165 // Iteration | |
166 Bytecodes::Code next() { | |
1565 | 167 Bytecodes::Code raw_code, code; |
0 | 168 // set reading position |
169 _bci = _next_bci; | |
170 if (is_last_bytecode()) { | |
171 // indicate end of bytecode stream | |
1565 | 172 raw_code = code = Bytecodes::_illegal; |
0 | 173 } else { |
174 // get bytecode | |
1565 | 175 address bcp = this->bcp(); |
176 raw_code = Bytecodes::code_at(bcp); | |
177 code = Bytecodes::java_code(raw_code); | |
0 | 178 // set next bytecode position |
179 // | |
180 // note that we cannot advance before having the | |
181 // tty bytecode otherwise the stepping is wrong! | |
182 // (carefull: length_for(...) must be used first!) | |
183 int l = Bytecodes::length_for(code); | |
184 if (l == 0) l = Bytecodes::length_at(bcp); | |
185 _next_bci += l; | |
186 assert(_bci < _next_bci, "length must be > 0"); | |
187 // set attributes | |
188 _is_wide = false; | |
189 // check for special (uncommon) cases | |
190 if (code == Bytecodes::_wide) { | |
1565 | 191 raw_code = (Bytecodes::Code)bcp[1]; |
192 code = raw_code; // wide BCs are always Java-normal | |
0 | 193 _is_wide = true; |
194 } | |
195 assert(Bytecodes::is_java_code(code), "sanity check"); | |
196 } | |
1565 | 197 _raw_code = raw_code; |
0 | 198 _code = code; |
199 return _code; | |
200 } | |
201 | |
202 bool is_active_breakpoint() const { return Bytecodes::is_active_breakpoint_at(bcp()); } | |
1565 | 203 Bytecodes::Code code() const { return _code; } |
204 | |
205 // Unsigned indices, widening | |
206 int get_index() const { return is_wide() ? bytecode()->get_index_u2(raw_code(), true) : get_index_u1(); } | |
207 // Get an unsigned 2-byte index, swapping the bytes if necessary. | |
208 int get_index_u2() const { assert_raw_stream(false); | |
209 return bytecode()->get_index_u2(raw_code(), false); } | |
210 // Get an unsigned 2-byte index in native order. | |
211 int get_index_u2_cpcache() const { assert_raw_stream(false); | |
212 return bytecode()->get_index_u2_cpcache(raw_code()); } | |
213 int get_index_u4() const { assert_raw_stream(false); | |
214 return bytecode()->get_index_u4(raw_code()); } | |
1570 | 215 bool has_index_u4() const { return bytecode()->has_index_u4(raw_code()); } |
0 | 216 }; |