annotate src/share/vm/ci/ciStreams.hpp @ 5479:d13d7aba8c12

8023657: New type profiling points: arguments to call Summary: x86 interpreter and c1 type profiling for arguments at calls Reviewed-by: kvn, twisti
author roland
date Wed, 09 Oct 2013 16:32:21 +0200
parents f6b0eb4e44cf
children 55fb97c4c58d
rev   line source
duke@0 1 /*
coleenp@3602 2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
trims@1472 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1472 20 * or visit www.oracle.com if you need additional information or have any
trims@1472 21 * questions.
duke@0 22 *
duke@0 23 */
duke@0 24
stefank@1879 25 #ifndef SHARE_VM_CI_CISTREAMS_HPP
stefank@1879 26 #define SHARE_VM_CI_CISTREAMS_HPP
stefank@1879 27
stefank@1879 28 #include "ci/ciClassList.hpp"
stefank@1879 29 #include "ci/ciExceptionHandler.hpp"
stefank@1879 30 #include "ci/ciInstanceKlass.hpp"
stefank@1879 31 #include "ci/ciMethod.hpp"
stefank@1879 32 #include "interpreter/bytecode.hpp"
stefank@1879 33
duke@0 34 // ciBytecodeStream
duke@0 35 //
duke@0 36 // The class is used to iterate over the bytecodes of a method.
duke@0 37 // It hides the details of constant pool structure/access by
duke@0 38 // providing accessors for constant pool items. It returns only pure
duke@0 39 // Java bytecodes; VM-internal _fast bytecodes are translated back to
duke@0 40 // their original form during iteration.
duke@0 41 class ciBytecodeStream : StackObj {
duke@0 42 private:
jrose@1485 43 // Handling for the weird bytecodes
jrose@1485 44 Bytecodes::Code next_wide_or_table(Bytecodes::Code); // Handle _wide & complicated inline table
duke@0 45
duke@0 46 static Bytecodes::Code check_java(Bytecodes::Code c) {
duke@0 47 assert(Bytecodes::is_java_code(c), "should not return _fast bytecodes");
duke@0 48 return c;
duke@0 49 }
duke@0 50
jrose@1485 51 static Bytecodes::Code check_defined(Bytecodes::Code c) {
jrose@1485 52 assert(Bytecodes::is_defined(c), "");
jrose@1485 53 return c;
jrose@1485 54 }
jrose@1485 55
duke@0 56 ciMethod* _method; // the method
duke@0 57 ciInstanceKlass* _holder;
duke@0 58 address _bc_start; // Start of current bytecode for table
duke@0 59 address _was_wide; // Address past last wide bytecode
duke@0 60 jint* _table_base; // Aligned start of last table or switch
duke@0 61
duke@0 62 address _start; // Start of bytecodes
duke@0 63 address _end; // Past end of bytecodes
duke@0 64 address _pc; // Current PC
duke@0 65 Bytecodes::Code _bc; // Current bytecode
jrose@1485 66 Bytecodes::Code _raw_bc; // Current bytecode, raw form
duke@0 67
duke@0 68 void reset( address base, unsigned int size ) {
duke@0 69 _bc_start =_was_wide = 0;
jrose@1522 70 _start = _pc = base; _end = base + size;
jrose@1522 71 }
duke@0 72
jrose@1485 73 void assert_wide(bool require_wide) const {
jrose@1485 74 if (require_wide)
jrose@1485 75 { assert(is_wide(), "must be a wide instruction"); }
jrose@1485 76 else { assert(!is_wide(), "must not be a wide instruction"); }
jrose@1485 77 }
jrose@1485 78
never@2027 79 Bytecode bytecode() const { return Bytecode(this, _bc_start); }
never@2027 80 Bytecode next_bytecode() const { return Bytecode(this, _pc); }
jrose@1485 81
duke@0 82 public:
duke@0 83 // End-Of-Bytecodes
duke@0 84 static Bytecodes::Code EOBC() {
duke@0 85 return Bytecodes::_illegal;
duke@0 86 }
duke@0 87
duke@0 88 ciBytecodeStream(ciMethod* m) {
duke@0 89 reset_to_method(m);
duke@0 90 }
duke@0 91
duke@0 92 ciBytecodeStream() {
duke@0 93 reset_to_method(NULL);
duke@0 94 }
duke@0 95
duke@0 96 ciMethod* method() const { return _method; }
duke@0 97
duke@0 98 void reset_to_method(ciMethod* m) {
duke@0 99 _method = m;
duke@0 100 if (m == NULL) {
duke@0 101 _holder = NULL;
duke@0 102 reset(NULL, 0);
duke@0 103 } else {
duke@0 104 _holder = m->holder();
duke@0 105 reset(m->code(), m->code_size());
duke@0 106 }
duke@0 107 }
duke@0 108
duke@0 109 void reset_to_bci( int bci );
duke@0 110
duke@0 111 // Force the iterator to report a certain bci.
duke@0 112 void force_bci(int bci);
duke@0 113
duke@0 114 void set_max_bci( int max ) {
duke@0 115 _end = _start + max;
duke@0 116 }
duke@0 117
jrose@726 118 address cur_bcp() const { return _bc_start; } // Returns bcp to current instruction
jrose@1485 119 int next_bci() const { return _pc - _start; }
duke@0 120 int cur_bci() const { return _bc_start - _start; }
jrose@726 121 int instruction_size() const { return _pc - _bc_start; }
duke@0 122
duke@0 123 Bytecodes::Code cur_bc() const{ return check_java(_bc); }
jrose@1485 124 Bytecodes::Code cur_bc_raw() const { return check_defined(_raw_bc); }
duke@0 125 Bytecodes::Code next_bc() { return Bytecodes::java_code((Bytecodes::Code)* _pc); }
duke@0 126
duke@0 127 // Return current ByteCode and increment PC to next bytecode, skipping all
duke@0 128 // intermediate constants. Returns EOBC at end.
duke@0 129 // Expected usage:
twisti@2662 130 // ciBytecodeStream iter(m);
twisti@2662 131 // while (iter.next() != ciBytecodeStream::EOBC()) { ... }
duke@0 132 Bytecodes::Code next() {
duke@0 133 _bc_start = _pc; // Capture start of bc
duke@0 134 if( _pc >= _end ) return EOBC(); // End-Of-Bytecodes
duke@0 135
duke@0 136 // Fetch Java bytecode
duke@0 137 // All rewritten bytecodes maintain the size of original bytecode.
jrose@1485 138 _bc = Bytecodes::java_code(_raw_bc = (Bytecodes::Code)*_pc);
duke@0 139 int csize = Bytecodes::length_for(_bc); // Expected size
jrose@1485 140 _pc += csize; // Bump PC past bytecode
jrose@1485 141 if (csize == 0) {
jrose@1485 142 _bc = next_wide_or_table(_bc);
duke@0 143 }
duke@0 144 return check_java(_bc);
duke@0 145 }
duke@0 146
jrose@726 147 bool is_wide() const { return ( _pc == _was_wide ); }
duke@0 148
jrose@1485 149 // Does this instruction contain an index which refes into the CP cache?
jrose@1522 150 bool has_cache_index() const { return Bytecodes::uses_cp_cache(cur_bc_raw()); }
jrose@1485 151
twisti@3586 152 bool has_optional_appendix() { return Bytecodes::has_optional_appendix(cur_bc_raw()); }
twisti@3586 153
jrose@1485 154 int get_index_u1() const {
never@2027 155 return bytecode().get_index_u1(cur_bc_raw());
jrose@1485 156 }
jrose@1485 157
jrose@1522 158 int get_index_u1_cpcache() const {
never@2027 159 return bytecode().get_index_u1_cpcache(cur_bc_raw());
jrose@1522 160 }
jrose@1522 161
duke@0 162 // Get a byte index following this bytecode.
duke@0 163 // If prefixed with a wide bytecode, get a wide index.
duke@0 164 int get_index() const {
jrose@1522 165 assert(!has_cache_index(), "else use cpcache variant");
duke@0 166 return (_pc == _was_wide) // was widened?
jrose@1485 167 ? get_index_u2(true) // yes, return wide index
jrose@1485 168 : get_index_u1(); // no, return narrow index
duke@0 169 }
duke@0 170
jrose@1485 171 // Get 2-byte index (byte swapping depending on which bytecode)
jrose@1485 172 int get_index_u2(bool is_wide = false) const {
never@2027 173 return bytecode().get_index_u2(cur_bc_raw(), is_wide);
duke@0 174 }
duke@0 175
jrose@1485 176 // Get 2-byte index in native byte order. (Rewriter::rewrite makes these.)
jrose@1485 177 int get_index_u2_cpcache() const {
never@2027 178 return bytecode().get_index_u2_cpcache(cur_bc_raw());
jrose@726 179 }
jrose@726 180
jrose@726 181 // Get 4-byte index, for invokedynamic.
jrose@1485 182 int get_index_u4() const {
never@2027 183 return bytecode().get_index_u4(cur_bc_raw());
jrose@726 184 }
jrose@726 185
jrose@1485 186 bool has_index_u4() const {
never@2027 187 return bytecode().has_index_u4(cur_bc_raw());
jrose@1485 188 }
duke@0 189
duke@0 190 // Get dimensions byte (multinewarray)
duke@0 191 int get_dimensions() const { return *(unsigned char*)(_pc-1); }
duke@0 192
duke@0 193 // Sign-extended index byte/short, no widening
never@2027 194 int get_constant_u1() const { return bytecode().get_constant_u1(instruction_size()-1, cur_bc_raw()); }
never@2027 195 int get_constant_u2(bool is_wide = false) const { return bytecode().get_constant_u2(instruction_size()-2, cur_bc_raw(), is_wide); }
duke@0 196
duke@0 197 // Get a byte signed constant for "iinc". Invalid for other bytecodes.
duke@0 198 // If prefixed with a wide bytecode, get a wide constant
jrose@1485 199 int get_iinc_con() const {return (_pc==_was_wide) ? (jshort) get_constant_u2(true) : (jbyte) get_constant_u1();}
duke@0 200
duke@0 201 // 2-byte branch offset from current pc
jrose@1485 202 int get_dest() const {
never@2027 203 return cur_bci() + bytecode().get_offset_s2(cur_bc_raw());
duke@0 204 }
duke@0 205
duke@0 206 // 2-byte branch offset from next pc
jrose@1485 207 int next_get_dest() const {
jrose@1485 208 assert(_pc < _end, "");
never@2027 209 return next_bci() + next_bytecode().get_offset_s2(Bytecodes::_ifeq);
duke@0 210 }
duke@0 211
duke@0 212 // 4-byte branch offset from current pc
jrose@1485 213 int get_far_dest() const {
never@2027 214 return cur_bci() + bytecode().get_offset_s4(cur_bc_raw());
duke@0 215 }
duke@0 216
duke@0 217 // For a lookup or switch table, return target destination
duke@0 218 int get_int_table( int index ) const {
duke@0 219 return Bytes::get_Java_u4((address)&_table_base[index]); }
duke@0 220
duke@0 221 // For tableswitch - get length of offset part
duke@0 222 int get_tableswitch_length() { return get_int_table(2)-get_int_table(1)+1; }
duke@0 223
duke@0 224 int get_dest_table( int index ) const {
duke@0 225 return cur_bci() + get_int_table(index); }
duke@0 226
duke@0 227 // --- Constant pool access ---
jrose@1522 228 int get_constant_raw_index() const;
jrose@1522 229 int get_constant_pool_index() const;
jrose@1522 230 int get_constant_cache_index() const;
duke@0 231 int get_field_index();
duke@0 232 int get_method_index();
duke@0 233
duke@0 234 // If this bytecode is a new, newarray, multianewarray, instanceof,
duke@0 235 // or checkcast, get the referenced klass.
duke@0 236 ciKlass* get_klass(bool& will_link);
duke@0 237 int get_klass_index() const;
duke@0 238
duke@0 239 // If this bytecode is one of the ldc variants, get the referenced
jrose@1522 240 // constant. Do not attempt to resolve it, since that would require
jrose@1522 241 // execution of Java code. If it is not resolved, return an unloaded
jrose@1522 242 // object (ciConstant.as_object()->is_loaded() == false).
duke@0 243 ciConstant get_constant();
jrose@1522 244 constantTag get_constant_pool_tag(int index) const;
jrose@1522 245
jrose@1522 246 // True if the klass-using bytecode points to an unresolved klass
jrose@1522 247 bool is_unresolved_klass() const {
jrose@1522 248 constantTag tag = get_constant_pool_tag(get_klass_index());
jrose@1522 249 return tag.is_unresolved_klass();
jrose@1522 250 }
duke@0 251
duke@0 252 // If this bytecode is one of get_field, get_static, put_field,
duke@0 253 // or put_static, get the referenced field.
duke@0 254 ciField* get_field(bool& will_link);
duke@0 255
duke@0 256 ciInstanceKlass* get_declared_field_holder();
duke@0 257 int get_field_holder_index();
duke@0 258 int get_field_signature_index();
duke@0 259
twisti@3698 260 ciMethod* get_method(bool& will_link, ciSignature* *declared_signature_result);
twisti@3698 261 bool has_appendix();
twisti@3698 262 ciObject* get_appendix();
twisti@3698 263 bool has_method_type();
twisti@3698 264 ciMethodType* get_method_type();
twisti@3698 265 ciKlass* get_declared_method_holder();
twisti@3698 266 int get_method_holder_index();
twisti@3698 267 int get_method_signature_index();
jrose@726 268
coleenp@3602 269 // Get the resolved references arrays from the constant pool
coleenp@3602 270 ciObjArray* get_resolved_references();
duke@0 271 };
duke@0 272
duke@0 273
duke@0 274 // ciSignatureStream
duke@0 275 //
duke@0 276 // The class is used to iterate over the elements of a method signature.
duke@0 277 class ciSignatureStream : public StackObj {
duke@0 278 private:
duke@0 279 ciSignature* _sig;
roland@5479 280 int _pos;
roland@5479 281 // holder is a method's holder
roland@5479 282 ciKlass* _holder;
duke@0 283 public:
roland@5479 284 ciSignatureStream(ciSignature* signature, ciKlass* holder = NULL) {
duke@0 285 _sig = signature;
duke@0 286 _pos = 0;
roland@5479 287 _holder = holder;
duke@0 288 }
duke@0 289
duke@0 290 bool at_return_type() { return _pos == _sig->count(); }
duke@0 291
duke@0 292 bool is_done() { return _pos > _sig->count(); }
duke@0 293
duke@0 294 void next() {
duke@0 295 if (_pos <= _sig->count()) {
duke@0 296 _pos++;
duke@0 297 }
duke@0 298 }
duke@0 299
duke@0 300 ciType* type() {
duke@0 301 if (at_return_type()) {
duke@0 302 return _sig->return_type();
duke@0 303 } else {
duke@0 304 return _sig->type_at(_pos);
duke@0 305 }
duke@0 306 }
roland@5479 307
roland@5479 308 // next klass in the signature
roland@5479 309 ciKlass* next_klass() {
roland@5479 310 ciKlass* sig_k;
roland@5479 311 if (_holder != NULL) {
roland@5479 312 sig_k = _holder;
roland@5479 313 _holder = NULL;
roland@5479 314 } else {
roland@5479 315 while (!type()->is_klass()) {
roland@5479 316 next();
roland@5479 317 }
roland@5479 318 assert(!at_return_type(), "passed end of signature");
roland@5479 319 sig_k = type()->as_klass();
roland@5479 320 next();
roland@5479 321 }
roland@5479 322 return sig_k;
roland@5479 323 }
duke@0 324 };
duke@0 325
duke@0 326
duke@0 327 // ciExceptionHandlerStream
duke@0 328 //
duke@0 329 // The class is used to iterate over the exception handlers of
duke@0 330 // a method.
duke@0 331 class ciExceptionHandlerStream : public StackObj {
duke@0 332 private:
duke@0 333 // The method whose handlers we are traversing
duke@0 334 ciMethod* _method;
duke@0 335
duke@0 336 // Our current position in the list of handlers
duke@0 337 int _pos;
duke@0 338 int _end;
duke@0 339
duke@0 340 ciInstanceKlass* _exception_klass;
duke@0 341 int _bci;
duke@0 342 bool _is_exact;
duke@0 343
duke@0 344 public:
duke@0 345 ciExceptionHandlerStream(ciMethod* method) {
duke@0 346 _method = method;
duke@0 347
duke@0 348 // Force loading of method code and handlers.
duke@0 349 _method->code();
duke@0 350
duke@0 351 _pos = 0;
duke@0 352 _end = _method->_handler_count;
duke@0 353 _exception_klass = NULL;
duke@0 354 _bci = -1;
duke@0 355 _is_exact = false;
duke@0 356 }
duke@0 357
duke@0 358 ciExceptionHandlerStream(ciMethod* method, int bci,
duke@0 359 ciInstanceKlass* exception_klass = NULL,
duke@0 360 bool is_exact = false) {
duke@0 361 _method = method;
duke@0 362
duke@0 363 // Force loading of method code and handlers.
duke@0 364 _method->code();
duke@0 365
duke@0 366 _pos = -1;
duke@0 367 _end = _method->_handler_count + 1; // include the rethrow handler
duke@0 368 _exception_klass = (exception_klass != NULL && exception_klass->is_loaded()
duke@0 369 ? exception_klass
duke@0 370 : NULL);
duke@0 371 _bci = bci;
duke@0 372 assert(_bci >= 0, "bci out of range");
duke@0 373 _is_exact = is_exact;
duke@0 374 next();
duke@0 375 }
duke@0 376
duke@0 377 // These methods are currently implemented in an odd way.
duke@0 378 // Count the number of handlers the iterator has ever produced
duke@0 379 // or will ever produce. Do not include the final rethrow handler.
duke@0 380 // That is, a trivial exception handler stream will have a count
duke@0 381 // of zero and produce just the rethrow handler.
duke@0 382 int count();
duke@0 383
duke@0 384 // Count the number of handlers this stream will produce from now on.
duke@0 385 // Include the current handler, and the final rethrow handler.
duke@0 386 // The remaining count will be zero iff is_done() is true,
duke@0 387 int count_remaining();
duke@0 388
duke@0 389 bool is_done() {
duke@0 390 return (_pos >= _end);
duke@0 391 }
duke@0 392
duke@0 393 void next() {
duke@0 394 _pos++;
duke@0 395 if (_bci != -1) {
duke@0 396 // We are not iterating over all handlers...
duke@0 397 while (!is_done()) {
duke@0 398 ciExceptionHandler* handler = _method->_exception_handlers[_pos];
duke@0 399 if (handler->is_in_range(_bci)) {
duke@0 400 if (handler->is_catch_all()) {
duke@0 401 // Found final active catch block.
duke@0 402 _end = _pos+1;
duke@0 403 return;
duke@0 404 } else if (_exception_klass == NULL || !handler->catch_klass()->is_loaded()) {
duke@0 405 // We cannot do any type analysis here. Must conservatively assume
duke@0 406 // catch block is reachable.
duke@0 407 return;
duke@0 408 } else if (_exception_klass->is_subtype_of(handler->catch_klass())) {
duke@0 409 // This catch clause will definitely catch the exception.
duke@0 410 // Final candidate.
duke@0 411 _end = _pos+1;
duke@0 412 return;
duke@0 413 } else if (!_is_exact &&
duke@0 414 handler->catch_klass()->is_subtype_of(_exception_klass)) {
duke@0 415 // This catch block may be reachable.
duke@0 416 return;
duke@0 417 }
duke@0 418 }
duke@0 419
duke@0 420 // The catch block was not pertinent. Go on.
duke@0 421 _pos++;
duke@0 422 }
duke@0 423 } else {
duke@0 424 // This is an iteration over all handlers.
duke@0 425 return;
duke@0 426 }
duke@0 427 }
duke@0 428
duke@0 429 ciExceptionHandler* handler() {
duke@0 430 return _method->_exception_handlers[_pos];
duke@0 431 }
duke@0 432 };
stefank@1879 433
never@2027 434
never@2027 435
never@2027 436 // Implementation for declarations in bytecode.hpp
never@2027 437 Bytecode::Bytecode(const ciBytecodeStream* stream, address bcp): _bcp(bcp != NULL ? bcp : stream->cur_bcp()), _code(Bytecodes::code_at(NULL, addr_at(0))) {}
never@2027 438 Bytecode_lookupswitch::Bytecode_lookupswitch(const ciBytecodeStream* stream): Bytecode(stream) { verify(); }
never@2027 439 Bytecode_tableswitch::Bytecode_tableswitch(const ciBytecodeStream* stream): Bytecode(stream) { verify(); }
never@2027 440
stefank@1879 441 #endif // SHARE_VM_CI_CISTREAMS_HPP