src/share/vm/ci/ciStreams.hpp

changeset 1920
ab102d5d923e
parent 1573
dd57230ba8fe
child 1934
e9ff18c4ace7
     1.1 --- a/src/share/vm/ci/ciStreams.hpp	Fri May 21 02:59:24 2010 -0700
     1.2 +++ b/src/share/vm/ci/ciStreams.hpp	Sun May 23 01:38:26 2010 -0700
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright 1999-2009 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * Copyright 1999-2010 Sun Microsystems, Inc.  All Rights Reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -31,15 +31,19 @@
    1.11  // their original form during iteration.
    1.12  class ciBytecodeStream : StackObj {
    1.13  private:
    1.14 - // Handling for the weird bytecodes
    1.15 -  Bytecodes::Code wide();       // Handle wide bytecode
    1.16 -  Bytecodes::Code table(Bytecodes::Code); // Handle complicated inline table
    1.17 +  // Handling for the weird bytecodes
    1.18 +  Bytecodes::Code next_wide_or_table(Bytecodes::Code); // Handle _wide & complicated inline table
    1.19  
    1.20    static Bytecodes::Code check_java(Bytecodes::Code c) {
    1.21      assert(Bytecodes::is_java_code(c), "should not return _fast bytecodes");
    1.22      return c;
    1.23    }
    1.24  
    1.25 +  static Bytecodes::Code check_defined(Bytecodes::Code c) {
    1.26 +    assert(Bytecodes::is_defined(c), "");
    1.27 +    return c;
    1.28 +  }
    1.29 +
    1.30    ciMethod* _method;           // the method
    1.31    ciInstanceKlass* _holder;
    1.32    address _bc_start;            // Start of current bytecode for table
    1.33 @@ -50,11 +54,21 @@
    1.34    address _end;                    // Past end of bytecodes
    1.35    address _pc;                     // Current PC
    1.36    Bytecodes::Code _bc;             // Current bytecode
    1.37 +  Bytecodes::Code _raw_bc;         // Current bytecode, raw form
    1.38  
    1.39    void reset( address base, unsigned int size ) {
    1.40      _bc_start =_was_wide = 0;
    1.41      _start = _pc = base; _end = base + size; }
    1.42  
    1.43 +  void assert_wide(bool require_wide) const {
    1.44 +    if (require_wide)
    1.45 +         { assert(is_wide(),  "must be a wide instruction"); }
    1.46 +    else { assert(!is_wide(), "must not be a wide instruction"); }
    1.47 +  }
    1.48 +
    1.49 +  Bytecode* bytecode() const { return Bytecode_at(_bc_start); }
    1.50 +  Bytecode* next_bytecode() const { return Bytecode_at(_pc); }
    1.51 +
    1.52  public:
    1.53    // End-Of-Bytecodes
    1.54    static Bytecodes::Code EOBC() {
    1.55 @@ -92,11 +106,12 @@
    1.56    }
    1.57  
    1.58    address cur_bcp() const       { return _bc_start; }  // Returns bcp to current instruction
    1.59 -  int next_bci() const          { return _pc -_start; }
    1.60 +  int next_bci() const          { return _pc - _start; }
    1.61    int cur_bci() const           { return _bc_start - _start; }
    1.62    int instruction_size() const  { return _pc - _bc_start; }
    1.63  
    1.64    Bytecodes::Code cur_bc() const{ return check_java(_bc); }
    1.65 +  Bytecodes::Code cur_bc_raw() const { return check_defined(_raw_bc); }
    1.66    Bytecodes::Code next_bc()     { return Bytecodes::java_code((Bytecodes::Code)* _pc); }
    1.67  
    1.68    // Return current ByteCode and increment PC to next bytecode, skipping all
    1.69 @@ -109,85 +124,76 @@
    1.70  
    1.71      // Fetch Java bytecode
    1.72      // All rewritten bytecodes maintain the size of original bytecode.
    1.73 -    _bc = Bytecodes::java_code((Bytecodes::Code)*_pc);
    1.74 +    _bc = Bytecodes::java_code(_raw_bc = (Bytecodes::Code)*_pc);
    1.75      int csize = Bytecodes::length_for(_bc); // Expected size
    1.76 -
    1.77 -    if( _bc == Bytecodes::_wide ) {
    1.78 -      _bc=wide();                           // Handle wide bytecode
    1.79 -    } else if( csize == 0 ) {
    1.80 -      _bc=table(_bc);                       // Handle inline tables
    1.81 -    } else {
    1.82 -      _pc += csize;                         // Bump PC past bytecode
    1.83 +    _pc += csize;                           // Bump PC past bytecode
    1.84 +    if (csize == 0) {
    1.85 +      _bc = next_wide_or_table(_bc);
    1.86      }
    1.87      return check_java(_bc);
    1.88    }
    1.89  
    1.90    bool is_wide() const { return ( _pc == _was_wide ); }
    1.91  
    1.92 +  // Does this instruction contain an index which refes into the CP cache?
    1.93 +  bool uses_cp_cache() const { return Bytecodes::uses_cp_cache(cur_bc_raw()); }
    1.94 +
    1.95 +  int get_index_u1() const {
    1.96 +    return bytecode()->get_index_u1(cur_bc_raw());
    1.97 +  }
    1.98 +
    1.99    // Get a byte index following this bytecode.
   1.100    // If prefixed with a wide bytecode, get a wide index.
   1.101    int get_index() const {
   1.102 -    assert_index_size(is_wide() ? 2 : 1);
   1.103      return (_pc == _was_wide)   // was widened?
   1.104 -      ? Bytes::get_Java_u2(_bc_start+2) // yes, return wide index
   1.105 -      : _bc_start[1];           // no, return narrow index
   1.106 +      ? get_index_u2(true)      // yes, return wide index
   1.107 +      : get_index_u1();         // no, return narrow index
   1.108    }
   1.109  
   1.110 -  // Get 2-byte index (getfield/putstatic/etc)
   1.111 -  int get_index_big() const {
   1.112 -    assert_index_size(2);
   1.113 -    return Bytes::get_Java_u2(_bc_start+1);
   1.114 +  // Get 2-byte index (byte swapping depending on which bytecode)
   1.115 +  int get_index_u2(bool is_wide = false) const {
   1.116 +    return bytecode()->get_index_u2(cur_bc_raw(), is_wide);
   1.117    }
   1.118  
   1.119 -  // Get 2-byte index (or 4-byte, for invokedynamic)
   1.120 -  int get_index_int() const {
   1.121 -    return has_giant_index() ? get_index_giant() : get_index_big();
   1.122 +  // Get 2-byte index in native byte order.  (Rewriter::rewrite makes these.)
   1.123 +  int get_index_u2_cpcache() const {
   1.124 +    return bytecode()->get_index_u2_cpcache(cur_bc_raw());
   1.125    }
   1.126  
   1.127    // Get 4-byte index, for invokedynamic.
   1.128 -  int get_index_giant() const {
   1.129 -    assert_index_size(4);
   1.130 -    return Bytes::get_native_u4(_bc_start+1);
   1.131 +  int get_index_u4() const {
   1.132 +    return bytecode()->get_index_u4(cur_bc_raw());
   1.133    }
   1.134  
   1.135 -  bool has_giant_index() const { return (cur_bc() == Bytecodes::_invokedynamic); }
   1.136 +  bool has_index_u4() const {
   1.137 +    return bytecode()->has_index_u4(cur_bc_raw());
   1.138 +  }
   1.139  
   1.140    // Get dimensions byte (multinewarray)
   1.141    int get_dimensions() const { return *(unsigned char*)(_pc-1); }
   1.142  
   1.143    // Sign-extended index byte/short, no widening
   1.144 -  int get_byte() const { return (int8_t)(_pc[-1]); }
   1.145 -  int get_short() const { return (int16_t)Bytes::get_Java_u2(_pc-2); }
   1.146 -  int get_long() const  { return (int32_t)Bytes::get_Java_u4(_pc-4); }
   1.147 +  int get_constant_u1()                     const { return bytecode()->get_constant_u1(instruction_size()-1, cur_bc_raw()); }
   1.148 +  int get_constant_u2(bool is_wide = false) const { return bytecode()->get_constant_u2(instruction_size()-2, cur_bc_raw(), is_wide); }
   1.149  
   1.150    // Get a byte signed constant for "iinc".  Invalid for other bytecodes.
   1.151    // If prefixed with a wide bytecode, get a wide constant
   1.152 -  int get_iinc_con() const {return (_pc==_was_wide) ? get_short() :get_byte();}
   1.153 +  int get_iinc_con() const {return (_pc==_was_wide) ? (jshort) get_constant_u2(true) : (jbyte) get_constant_u1();}
   1.154  
   1.155    // 2-byte branch offset from current pc
   1.156 -  int get_dest( ) const {
   1.157 -    assert( Bytecodes::length_at(_bc_start) == sizeof(jshort)+1,  "get_dest called with bad bytecode" );
   1.158 -    return _bc_start-_start + (short)Bytes::get_Java_u2(_pc-2);
   1.159 +  int get_dest() const {
   1.160 +    return cur_bci() + bytecode()->get_offset_s2(cur_bc_raw());
   1.161    }
   1.162  
   1.163    // 2-byte branch offset from next pc
   1.164 -  int next_get_dest( ) const {
   1.165 -    address next_bc_start = _pc;
   1.166 -    assert( _pc < _end, "" );
   1.167 -    Bytecodes::Code next_bc = (Bytecodes::Code)*_pc;
   1.168 -    assert( next_bc != Bytecodes::_wide, "");
   1.169 -    int next_csize = Bytecodes::length_for(next_bc);
   1.170 -    assert( next_csize != 0, "" );
   1.171 -    assert( next_bc <= Bytecodes::_jsr_w, "");
   1.172 -    address next_pc = _pc + next_csize;
   1.173 -    assert( Bytecodes::length_at(next_bc_start) == sizeof(jshort)+1,  "next_get_dest called with bad bytecode" );
   1.174 -    return next_bc_start-_start + (short)Bytes::get_Java_u2(next_pc-2);
   1.175 +  int next_get_dest() const {
   1.176 +    assert(_pc < _end, "");
   1.177 +    return next_bci() + next_bytecode()->get_offset_s2(Bytecodes::_ifeq);
   1.178    }
   1.179  
   1.180    // 4-byte branch offset from current pc
   1.181 -  int get_far_dest( ) const {
   1.182 -    assert( Bytecodes::length_at(_bc_start) == sizeof(jint)+1, "dest4 called with bad bytecode" );
   1.183 -    return _bc_start-_start + (int)Bytes::get_Java_u4(_pc-4);
   1.184 +  int get_far_dest() const {
   1.185 +    return cur_bci() + bytecode()->get_offset_s4(cur_bc_raw());
   1.186    }
   1.187  
   1.188    // For a lookup or switch table, return target destination
   1.189 @@ -234,22 +240,6 @@
   1.190  
   1.191    ciCPCache*  get_cpcache();
   1.192    ciCallSite* get_call_site();
   1.193 -
   1.194 - private:
   1.195 -  void assert_index_size(int required_size) const {
   1.196 -#ifdef ASSERT
   1.197 -    int isize = instruction_size() - (is_wide() ? 1 : 0) - 1;
   1.198 -    if (isize == 2 &&  cur_bc() == Bytecodes::_iinc)
   1.199 -      isize = 1;
   1.200 -    else if (isize <= 2)
   1.201 -      ;                         // no change
   1.202 -    else if (has_giant_index())
   1.203 -      isize = 4;
   1.204 -    else
   1.205 -      isize = 2;
   1.206 -    assert(isize = required_size, "wrong index size");
   1.207 -#endif
   1.208 -  }
   1.209  };
   1.210  
   1.211  

mercurial