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