annotate src/share/vm/ci/ciStreams.hpp @ 666:ebebd376f657

6805522: Server VM fails with assertion (block1->start() != block2->start(),"successors have unique bcis") Reviewed-by: kvn
author never
date Mon, 23 Mar 2009 13:58:58 -0700
parents a61af66fc99e
children be93aad57795
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 1999-2005 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 // ciBytecodeStream
a61af66fc99e Initial load
duke
parents:
diff changeset
26 //
a61af66fc99e Initial load
duke
parents:
diff changeset
27 // The class is used to iterate over the bytecodes of a method.
a61af66fc99e Initial load
duke
parents:
diff changeset
28 // It hides the details of constant pool structure/access by
a61af66fc99e Initial load
duke
parents:
diff changeset
29 // providing accessors for constant pool items. It returns only pure
a61af66fc99e Initial load
duke
parents:
diff changeset
30 // Java bytecodes; VM-internal _fast bytecodes are translated back to
a61af66fc99e Initial load
duke
parents:
diff changeset
31 // their original form during iteration.
a61af66fc99e Initial load
duke
parents:
diff changeset
32 class ciBytecodeStream : StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
33 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // Handling for the weird bytecodes
a61af66fc99e Initial load
duke
parents:
diff changeset
35 Bytecodes::Code wide(); // Handle wide bytecode
a61af66fc99e Initial load
duke
parents:
diff changeset
36 Bytecodes::Code table(Bytecodes::Code); // Handle complicated inline table
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 static Bytecodes::Code check_java(Bytecodes::Code c) {
a61af66fc99e Initial load
duke
parents:
diff changeset
39 assert(Bytecodes::is_java_code(c), "should not return _fast bytecodes");
a61af66fc99e Initial load
duke
parents:
diff changeset
40 return c;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 }
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43 ciMethod* _method; // the method
a61af66fc99e Initial load
duke
parents:
diff changeset
44 ciInstanceKlass* _holder;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 address _bc_start; // Start of current bytecode for table
a61af66fc99e Initial load
duke
parents:
diff changeset
46 address _was_wide; // Address past last wide bytecode
a61af66fc99e Initial load
duke
parents:
diff changeset
47 jint* _table_base; // Aligned start of last table or switch
a61af66fc99e Initial load
duke
parents:
diff changeset
48
a61af66fc99e Initial load
duke
parents:
diff changeset
49 address _start; // Start of bytecodes
a61af66fc99e Initial load
duke
parents:
diff changeset
50 address _end; // Past end of bytecodes
a61af66fc99e Initial load
duke
parents:
diff changeset
51 address _pc; // Current PC
a61af66fc99e Initial load
duke
parents:
diff changeset
52 Bytecodes::Code _bc; // Current bytecode
a61af66fc99e Initial load
duke
parents:
diff changeset
53
a61af66fc99e Initial load
duke
parents:
diff changeset
54 void reset( address base, unsigned int size ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
55 _bc_start =_was_wide = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 _start = _pc = base; _end = base + size; }
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
59 // End-Of-Bytecodes
a61af66fc99e Initial load
duke
parents:
diff changeset
60 static Bytecodes::Code EOBC() {
a61af66fc99e Initial load
duke
parents:
diff changeset
61 return Bytecodes::_illegal;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 }
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 ciBytecodeStream(ciMethod* m) {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 reset_to_method(m);
a61af66fc99e Initial load
duke
parents:
diff changeset
66 }
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 ciBytecodeStream() {
a61af66fc99e Initial load
duke
parents:
diff changeset
69 reset_to_method(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
70 }
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 ciMethod* method() const { return _method; }
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74 void reset_to_method(ciMethod* m) {
a61af66fc99e Initial load
duke
parents:
diff changeset
75 _method = m;
a61af66fc99e Initial load
duke
parents:
diff changeset
76 if (m == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
77 _holder = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
78 reset(NULL, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
79 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 _holder = m->holder();
a61af66fc99e Initial load
duke
parents:
diff changeset
81 reset(m->code(), m->code_size());
a61af66fc99e Initial load
duke
parents:
diff changeset
82 }
a61af66fc99e Initial load
duke
parents:
diff changeset
83 }
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85 void reset_to_bci( int bci );
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 // Force the iterator to report a certain bci.
a61af66fc99e Initial load
duke
parents:
diff changeset
88 void force_bci(int bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 void set_max_bci( int max ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 _end = _start + max;
a61af66fc99e Initial load
duke
parents:
diff changeset
92 }
a61af66fc99e Initial load
duke
parents:
diff changeset
93
a61af66fc99e Initial load
duke
parents:
diff changeset
94 address cur_bcp() { return _bc_start; } // Returns bcp to current instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
95 int next_bci() const { return _pc -_start; }
a61af66fc99e Initial load
duke
parents:
diff changeset
96 int cur_bci() const { return _bc_start - _start; }
a61af66fc99e Initial load
duke
parents:
diff changeset
97
a61af66fc99e Initial load
duke
parents:
diff changeset
98 Bytecodes::Code cur_bc() const{ return check_java(_bc); }
a61af66fc99e Initial load
duke
parents:
diff changeset
99 Bytecodes::Code next_bc() { return Bytecodes::java_code((Bytecodes::Code)* _pc); }
a61af66fc99e Initial load
duke
parents:
diff changeset
100
a61af66fc99e Initial load
duke
parents:
diff changeset
101 // Return current ByteCode and increment PC to next bytecode, skipping all
a61af66fc99e Initial load
duke
parents:
diff changeset
102 // intermediate constants. Returns EOBC at end.
a61af66fc99e Initial load
duke
parents:
diff changeset
103 // Expected usage:
a61af66fc99e Initial load
duke
parents:
diff changeset
104 // while( (bc = iter.next()) != EOBC() ) { ... }
a61af66fc99e Initial load
duke
parents:
diff changeset
105 Bytecodes::Code next() {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 _bc_start = _pc; // Capture start of bc
a61af66fc99e Initial load
duke
parents:
diff changeset
107 if( _pc >= _end ) return EOBC(); // End-Of-Bytecodes
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109 // Fetch Java bytecode
a61af66fc99e Initial load
duke
parents:
diff changeset
110 // All rewritten bytecodes maintain the size of original bytecode.
a61af66fc99e Initial load
duke
parents:
diff changeset
111 _bc = Bytecodes::java_code((Bytecodes::Code)*_pc);
a61af66fc99e Initial load
duke
parents:
diff changeset
112 int csize = Bytecodes::length_for(_bc); // Expected size
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114 if( _bc == Bytecodes::_wide ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 _bc=wide(); // Handle wide bytecode
a61af66fc99e Initial load
duke
parents:
diff changeset
116 } else if( csize == 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
117 _bc=table(_bc); // Handle inline tables
a61af66fc99e Initial load
duke
parents:
diff changeset
118 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
119 _pc += csize; // Bump PC past bytecode
a61af66fc99e Initial load
duke
parents:
diff changeset
120 }
a61af66fc99e Initial load
duke
parents:
diff changeset
121 return check_java(_bc);
a61af66fc99e Initial load
duke
parents:
diff changeset
122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 bool is_wide() { return ( _pc == _was_wide ); }
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 // Get a byte index following this bytecode.
a61af66fc99e Initial load
duke
parents:
diff changeset
127 // If prefixed with a wide bytecode, get a wide index.
a61af66fc99e Initial load
duke
parents:
diff changeset
128 int get_index() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
129 return (_pc == _was_wide) // was widened?
a61af66fc99e Initial load
duke
parents:
diff changeset
130 ? Bytes::get_Java_u2(_bc_start+2) // yes, return wide index
a61af66fc99e Initial load
duke
parents:
diff changeset
131 : _bc_start[1]; // no, return narrow index
a61af66fc99e Initial load
duke
parents:
diff changeset
132 }
a61af66fc99e Initial load
duke
parents:
diff changeset
133
a61af66fc99e Initial load
duke
parents:
diff changeset
134 // Set a byte index following this bytecode.
a61af66fc99e Initial load
duke
parents:
diff changeset
135 // If prefixed with a wide bytecode, get a wide index.
a61af66fc99e Initial load
duke
parents:
diff changeset
136 void put_index(int idx) {
a61af66fc99e Initial load
duke
parents:
diff changeset
137 if (_pc == _was_wide) // was widened?
a61af66fc99e Initial load
duke
parents:
diff changeset
138 Bytes::put_Java_u2(_bc_start+2,idx); // yes, set wide index
a61af66fc99e Initial load
duke
parents:
diff changeset
139 else
a61af66fc99e Initial load
duke
parents:
diff changeset
140 _bc_start[1]=idx; // no, set narrow index
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 // Get 2-byte index (getfield/putstatic/etc)
a61af66fc99e Initial load
duke
parents:
diff changeset
144 int get_index_big() const { return Bytes::get_Java_u2(_bc_start+1); }
a61af66fc99e Initial load
duke
parents:
diff changeset
145
a61af66fc99e Initial load
duke
parents:
diff changeset
146 // Get dimensions byte (multinewarray)
a61af66fc99e Initial load
duke
parents:
diff changeset
147 int get_dimensions() const { return *(unsigned char*)(_pc-1); }
a61af66fc99e Initial load
duke
parents:
diff changeset
148
a61af66fc99e Initial load
duke
parents:
diff changeset
149 // Get unsigned index fast
a61af66fc99e Initial load
duke
parents:
diff changeset
150 int get_index_fast() const { return Bytes::get_native_u2(_pc-2); }
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152 // Sign-extended index byte/short, no widening
a61af66fc99e Initial load
duke
parents:
diff changeset
153 int get_byte() const { return (int8_t)(_pc[-1]); }
a61af66fc99e Initial load
duke
parents:
diff changeset
154 int get_short() const { return (int16_t)Bytes::get_Java_u2(_pc-2); }
a61af66fc99e Initial load
duke
parents:
diff changeset
155 int get_long() const { return (int32_t)Bytes::get_Java_u4(_pc-4); }
a61af66fc99e Initial load
duke
parents:
diff changeset
156
a61af66fc99e Initial load
duke
parents:
diff changeset
157 // Get a byte signed constant for "iinc". Invalid for other bytecodes.
a61af66fc99e Initial load
duke
parents:
diff changeset
158 // If prefixed with a wide bytecode, get a wide constant
a61af66fc99e Initial load
duke
parents:
diff changeset
159 int get_iinc_con() const {return (_pc==_was_wide) ? get_short() :get_byte();}
a61af66fc99e Initial load
duke
parents:
diff changeset
160
a61af66fc99e Initial load
duke
parents:
diff changeset
161 // 2-byte branch offset from current pc
a61af66fc99e Initial load
duke
parents:
diff changeset
162 int get_dest( ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
163 assert( Bytecodes::length_at(_bc_start) == sizeof(jshort)+1, "get_dest called with bad bytecode" );
a61af66fc99e Initial load
duke
parents:
diff changeset
164 return _bc_start-_start + (short)Bytes::get_Java_u2(_pc-2);
a61af66fc99e Initial load
duke
parents:
diff changeset
165 }
a61af66fc99e Initial load
duke
parents:
diff changeset
166
a61af66fc99e Initial load
duke
parents:
diff changeset
167 // 2-byte branch offset from next pc
a61af66fc99e Initial load
duke
parents:
diff changeset
168 int next_get_dest( ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
169 address next_bc_start = _pc;
a61af66fc99e Initial load
duke
parents:
diff changeset
170 assert( _pc < _end, "" );
a61af66fc99e Initial load
duke
parents:
diff changeset
171 Bytecodes::Code next_bc = (Bytecodes::Code)*_pc;
a61af66fc99e Initial load
duke
parents:
diff changeset
172 assert( next_bc != Bytecodes::_wide, "");
a61af66fc99e Initial load
duke
parents:
diff changeset
173 int next_csize = Bytecodes::length_for(next_bc);
a61af66fc99e Initial load
duke
parents:
diff changeset
174 assert( next_csize != 0, "" );
a61af66fc99e Initial load
duke
parents:
diff changeset
175 assert( next_bc <= Bytecodes::_jsr_w, "");
a61af66fc99e Initial load
duke
parents:
diff changeset
176 address next_pc = _pc + next_csize;
a61af66fc99e Initial load
duke
parents:
diff changeset
177 assert( Bytecodes::length_at(next_bc_start) == sizeof(jshort)+1, "next_get_dest called with bad bytecode" );
a61af66fc99e Initial load
duke
parents:
diff changeset
178 return next_bc_start-_start + (short)Bytes::get_Java_u2(next_pc-2);
a61af66fc99e Initial load
duke
parents:
diff changeset
179 }
a61af66fc99e Initial load
duke
parents:
diff changeset
180
a61af66fc99e Initial load
duke
parents:
diff changeset
181 // 4-byte branch offset from current pc
a61af66fc99e Initial load
duke
parents:
diff changeset
182 int get_far_dest( ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
183 assert( Bytecodes::length_at(_bc_start) == sizeof(jint)+1, "dest4 called with bad bytecode" );
a61af66fc99e Initial load
duke
parents:
diff changeset
184 return _bc_start-_start + (int)Bytes::get_Java_u4(_pc-4);
a61af66fc99e Initial load
duke
parents:
diff changeset
185 }
a61af66fc99e Initial load
duke
parents:
diff changeset
186
a61af66fc99e Initial load
duke
parents:
diff changeset
187 // For a lookup or switch table, return target destination
a61af66fc99e Initial load
duke
parents:
diff changeset
188 int get_int_table( int index ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
189 return Bytes::get_Java_u4((address)&_table_base[index]); }
a61af66fc99e Initial load
duke
parents:
diff changeset
190
a61af66fc99e Initial load
duke
parents:
diff changeset
191 // For tableswitch - get length of offset part
a61af66fc99e Initial load
duke
parents:
diff changeset
192 int get_tableswitch_length() { return get_int_table(2)-get_int_table(1)+1; }
a61af66fc99e Initial load
duke
parents:
diff changeset
193
a61af66fc99e Initial load
duke
parents:
diff changeset
194 int get_dest_table( int index ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
195 return cur_bci() + get_int_table(index); }
a61af66fc99e Initial load
duke
parents:
diff changeset
196
a61af66fc99e Initial load
duke
parents:
diff changeset
197 // --- Constant pool access ---
a61af66fc99e Initial load
duke
parents:
diff changeset
198 int get_constant_index() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
199 int get_field_index();
a61af66fc99e Initial load
duke
parents:
diff changeset
200 int get_method_index();
a61af66fc99e Initial load
duke
parents:
diff changeset
201
a61af66fc99e Initial load
duke
parents:
diff changeset
202 // If this bytecode is a new, newarray, multianewarray, instanceof,
a61af66fc99e Initial load
duke
parents:
diff changeset
203 // or checkcast, get the referenced klass.
a61af66fc99e Initial load
duke
parents:
diff changeset
204 ciKlass* get_klass(bool& will_link);
a61af66fc99e Initial load
duke
parents:
diff changeset
205 int get_klass_index() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
206
a61af66fc99e Initial load
duke
parents:
diff changeset
207 // If this bytecode is one of the ldc variants, get the referenced
a61af66fc99e Initial load
duke
parents:
diff changeset
208 // constant
a61af66fc99e Initial load
duke
parents:
diff changeset
209 ciConstant get_constant();
a61af66fc99e Initial load
duke
parents:
diff changeset
210 // True if the ldc variant points to an unresolved string
a61af66fc99e Initial load
duke
parents:
diff changeset
211 bool is_unresolved_string() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
212 // True if the ldc variant points to an unresolved klass
a61af66fc99e Initial load
duke
parents:
diff changeset
213 bool is_unresolved_klass() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
214
a61af66fc99e Initial load
duke
parents:
diff changeset
215 // If this bytecode is one of get_field, get_static, put_field,
a61af66fc99e Initial load
duke
parents:
diff changeset
216 // or put_static, get the referenced field.
a61af66fc99e Initial load
duke
parents:
diff changeset
217 ciField* get_field(bool& will_link);
a61af66fc99e Initial load
duke
parents:
diff changeset
218
a61af66fc99e Initial load
duke
parents:
diff changeset
219 ciInstanceKlass* get_declared_field_holder();
a61af66fc99e Initial load
duke
parents:
diff changeset
220 int get_field_holder_index();
a61af66fc99e Initial load
duke
parents:
diff changeset
221 int get_field_signature_index();
a61af66fc99e Initial load
duke
parents:
diff changeset
222
a61af66fc99e Initial load
duke
parents:
diff changeset
223 // If this is a method invocation bytecode, get the invoked method.
a61af66fc99e Initial load
duke
parents:
diff changeset
224 ciMethod* get_method(bool& will_link);
a61af66fc99e Initial load
duke
parents:
diff changeset
225 ciKlass* get_declared_method_holder();
a61af66fc99e Initial load
duke
parents:
diff changeset
226 int get_method_holder_index();
a61af66fc99e Initial load
duke
parents:
diff changeset
227 int get_method_signature_index();
a61af66fc99e Initial load
duke
parents:
diff changeset
228 };
a61af66fc99e Initial load
duke
parents:
diff changeset
229
a61af66fc99e Initial load
duke
parents:
diff changeset
230
a61af66fc99e Initial load
duke
parents:
diff changeset
231 // ciSignatureStream
a61af66fc99e Initial load
duke
parents:
diff changeset
232 //
a61af66fc99e Initial load
duke
parents:
diff changeset
233 // The class is used to iterate over the elements of a method signature.
a61af66fc99e Initial load
duke
parents:
diff changeset
234 class ciSignatureStream : public StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
235 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
236 ciSignature* _sig;
a61af66fc99e Initial load
duke
parents:
diff changeset
237 int _pos;
a61af66fc99e Initial load
duke
parents:
diff changeset
238 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
239 ciSignatureStream(ciSignature* signature) {
a61af66fc99e Initial load
duke
parents:
diff changeset
240 _sig = signature;
a61af66fc99e Initial load
duke
parents:
diff changeset
241 _pos = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
242 }
a61af66fc99e Initial load
duke
parents:
diff changeset
243
a61af66fc99e Initial load
duke
parents:
diff changeset
244 bool at_return_type() { return _pos == _sig->count(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
245
a61af66fc99e Initial load
duke
parents:
diff changeset
246 bool is_done() { return _pos > _sig->count(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
247
a61af66fc99e Initial load
duke
parents:
diff changeset
248 void next() {
a61af66fc99e Initial load
duke
parents:
diff changeset
249 if (_pos <= _sig->count()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
250 _pos++;
a61af66fc99e Initial load
duke
parents:
diff changeset
251 }
a61af66fc99e Initial load
duke
parents:
diff changeset
252 }
a61af66fc99e Initial load
duke
parents:
diff changeset
253
a61af66fc99e Initial load
duke
parents:
diff changeset
254 ciType* type() {
a61af66fc99e Initial load
duke
parents:
diff changeset
255 if (at_return_type()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
256 return _sig->return_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
257 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
258 return _sig->type_at(_pos);
a61af66fc99e Initial load
duke
parents:
diff changeset
259 }
a61af66fc99e Initial load
duke
parents:
diff changeset
260 }
a61af66fc99e Initial load
duke
parents:
diff changeset
261 };
a61af66fc99e Initial load
duke
parents:
diff changeset
262
a61af66fc99e Initial load
duke
parents:
diff changeset
263
a61af66fc99e Initial load
duke
parents:
diff changeset
264 // ciExceptionHandlerStream
a61af66fc99e Initial load
duke
parents:
diff changeset
265 //
a61af66fc99e Initial load
duke
parents:
diff changeset
266 // The class is used to iterate over the exception handlers of
a61af66fc99e Initial load
duke
parents:
diff changeset
267 // a method.
a61af66fc99e Initial load
duke
parents:
diff changeset
268 class ciExceptionHandlerStream : public StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
269 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
270 // The method whose handlers we are traversing
a61af66fc99e Initial load
duke
parents:
diff changeset
271 ciMethod* _method;
a61af66fc99e Initial load
duke
parents:
diff changeset
272
a61af66fc99e Initial load
duke
parents:
diff changeset
273 // Our current position in the list of handlers
a61af66fc99e Initial load
duke
parents:
diff changeset
274 int _pos;
a61af66fc99e Initial load
duke
parents:
diff changeset
275 int _end;
a61af66fc99e Initial load
duke
parents:
diff changeset
276
a61af66fc99e Initial load
duke
parents:
diff changeset
277 ciInstanceKlass* _exception_klass;
a61af66fc99e Initial load
duke
parents:
diff changeset
278 int _bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
279 bool _is_exact;
a61af66fc99e Initial load
duke
parents:
diff changeset
280
a61af66fc99e Initial load
duke
parents:
diff changeset
281 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
282 ciExceptionHandlerStream(ciMethod* method) {
a61af66fc99e Initial load
duke
parents:
diff changeset
283 _method = method;
a61af66fc99e Initial load
duke
parents:
diff changeset
284
a61af66fc99e Initial load
duke
parents:
diff changeset
285 // Force loading of method code and handlers.
a61af66fc99e Initial load
duke
parents:
diff changeset
286 _method->code();
a61af66fc99e Initial load
duke
parents:
diff changeset
287
a61af66fc99e Initial load
duke
parents:
diff changeset
288 _pos = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
289 _end = _method->_handler_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
290 _exception_klass = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
291 _bci = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
292 _is_exact = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
293 }
a61af66fc99e Initial load
duke
parents:
diff changeset
294
a61af66fc99e Initial load
duke
parents:
diff changeset
295 ciExceptionHandlerStream(ciMethod* method, int bci,
a61af66fc99e Initial load
duke
parents:
diff changeset
296 ciInstanceKlass* exception_klass = NULL,
a61af66fc99e Initial load
duke
parents:
diff changeset
297 bool is_exact = false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
298 _method = method;
a61af66fc99e Initial load
duke
parents:
diff changeset
299
a61af66fc99e Initial load
duke
parents:
diff changeset
300 // Force loading of method code and handlers.
a61af66fc99e Initial load
duke
parents:
diff changeset
301 _method->code();
a61af66fc99e Initial load
duke
parents:
diff changeset
302
a61af66fc99e Initial load
duke
parents:
diff changeset
303 _pos = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
304 _end = _method->_handler_count + 1; // include the rethrow handler
a61af66fc99e Initial load
duke
parents:
diff changeset
305 _exception_klass = (exception_klass != NULL && exception_klass->is_loaded()
a61af66fc99e Initial load
duke
parents:
diff changeset
306 ? exception_klass
a61af66fc99e Initial load
duke
parents:
diff changeset
307 : NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
308 _bci = bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
309 assert(_bci >= 0, "bci out of range");
a61af66fc99e Initial load
duke
parents:
diff changeset
310 _is_exact = is_exact;
a61af66fc99e Initial load
duke
parents:
diff changeset
311 next();
a61af66fc99e Initial load
duke
parents:
diff changeset
312 }
a61af66fc99e Initial load
duke
parents:
diff changeset
313
a61af66fc99e Initial load
duke
parents:
diff changeset
314 // These methods are currently implemented in an odd way.
a61af66fc99e Initial load
duke
parents:
diff changeset
315 // Count the number of handlers the iterator has ever produced
a61af66fc99e Initial load
duke
parents:
diff changeset
316 // or will ever produce. Do not include the final rethrow handler.
a61af66fc99e Initial load
duke
parents:
diff changeset
317 // That is, a trivial exception handler stream will have a count
a61af66fc99e Initial load
duke
parents:
diff changeset
318 // of zero and produce just the rethrow handler.
a61af66fc99e Initial load
duke
parents:
diff changeset
319 int count();
a61af66fc99e Initial load
duke
parents:
diff changeset
320
a61af66fc99e Initial load
duke
parents:
diff changeset
321 // Count the number of handlers this stream will produce from now on.
a61af66fc99e Initial load
duke
parents:
diff changeset
322 // Include the current handler, and the final rethrow handler.
a61af66fc99e Initial load
duke
parents:
diff changeset
323 // The remaining count will be zero iff is_done() is true,
a61af66fc99e Initial load
duke
parents:
diff changeset
324 int count_remaining();
a61af66fc99e Initial load
duke
parents:
diff changeset
325
a61af66fc99e Initial load
duke
parents:
diff changeset
326 bool is_done() {
a61af66fc99e Initial load
duke
parents:
diff changeset
327 return (_pos >= _end);
a61af66fc99e Initial load
duke
parents:
diff changeset
328 }
a61af66fc99e Initial load
duke
parents:
diff changeset
329
a61af66fc99e Initial load
duke
parents:
diff changeset
330 void next() {
a61af66fc99e Initial load
duke
parents:
diff changeset
331 _pos++;
a61af66fc99e Initial load
duke
parents:
diff changeset
332 if (_bci != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
333 // We are not iterating over all handlers...
a61af66fc99e Initial load
duke
parents:
diff changeset
334 while (!is_done()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
335 ciExceptionHandler* handler = _method->_exception_handlers[_pos];
a61af66fc99e Initial load
duke
parents:
diff changeset
336 if (handler->is_in_range(_bci)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
337 if (handler->is_catch_all()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
338 // Found final active catch block.
a61af66fc99e Initial load
duke
parents:
diff changeset
339 _end = _pos+1;
a61af66fc99e Initial load
duke
parents:
diff changeset
340 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
341 } else if (_exception_klass == NULL || !handler->catch_klass()->is_loaded()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
342 // We cannot do any type analysis here. Must conservatively assume
a61af66fc99e Initial load
duke
parents:
diff changeset
343 // catch block is reachable.
a61af66fc99e Initial load
duke
parents:
diff changeset
344 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
345 } else if (_exception_klass->is_subtype_of(handler->catch_klass())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
346 // This catch clause will definitely catch the exception.
a61af66fc99e Initial load
duke
parents:
diff changeset
347 // Final candidate.
a61af66fc99e Initial load
duke
parents:
diff changeset
348 _end = _pos+1;
a61af66fc99e Initial load
duke
parents:
diff changeset
349 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
350 } else if (!_is_exact &&
a61af66fc99e Initial load
duke
parents:
diff changeset
351 handler->catch_klass()->is_subtype_of(_exception_klass)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
352 // This catch block may be reachable.
a61af66fc99e Initial load
duke
parents:
diff changeset
353 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
354 }
a61af66fc99e Initial load
duke
parents:
diff changeset
355 }
a61af66fc99e Initial load
duke
parents:
diff changeset
356
a61af66fc99e Initial load
duke
parents:
diff changeset
357 // The catch block was not pertinent. Go on.
a61af66fc99e Initial load
duke
parents:
diff changeset
358 _pos++;
a61af66fc99e Initial load
duke
parents:
diff changeset
359 }
a61af66fc99e Initial load
duke
parents:
diff changeset
360 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
361 // This is an iteration over all handlers.
a61af66fc99e Initial load
duke
parents:
diff changeset
362 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
363 }
a61af66fc99e Initial load
duke
parents:
diff changeset
364 }
a61af66fc99e Initial load
duke
parents:
diff changeset
365
a61af66fc99e Initial load
duke
parents:
diff changeset
366 ciExceptionHandler* handler() {
a61af66fc99e Initial load
duke
parents:
diff changeset
367 return _method->_exception_handlers[_pos];
a61af66fc99e Initial load
duke
parents:
diff changeset
368 }
a61af66fc99e Initial load
duke
parents:
diff changeset
369 };