src/share/vm/ci/ciStreams.hpp

changeset 1161
be93aad57795
parent 435
a61af66fc99e
child 1279
bd02caa94611
     1.1 --- a/src/share/vm/ci/ciStreams.hpp	Mon Apr 20 14:48:03 2009 -0700
     1.2 +++ b/src/share/vm/ci/ciStreams.hpp	Tue Apr 21 23:21:04 2009 -0700
     1.3 @@ -91,9 +91,10 @@
     1.4      _end = _start + max;
     1.5    }
     1.6  
     1.7 -  address cur_bcp()             { return _bc_start; }  // Returns bcp to current instruction
     1.8 +  address cur_bcp() const       { return _bc_start; }  // Returns bcp to current instruction
     1.9    int next_bci() const          { return _pc -_start; }
    1.10    int cur_bci() const           { return _bc_start - _start; }
    1.11 +  int instruction_size() const  { return _pc - _bc_start; }
    1.12  
    1.13    Bytecodes::Code cur_bc() const{ return check_java(_bc); }
    1.14    Bytecodes::Code next_bc()     { return Bytecodes::java_code((Bytecodes::Code)* _pc); }
    1.15 @@ -121,34 +122,39 @@
    1.16      return check_java(_bc);
    1.17    }
    1.18  
    1.19 -  bool is_wide()  { return ( _pc == _was_wide ); }
    1.20 +  bool is_wide() const { return ( _pc == _was_wide ); }
    1.21  
    1.22    // Get a byte index following this bytecode.
    1.23    // If prefixed with a wide bytecode, get a wide index.
    1.24    int get_index() const {
    1.25 +    assert_index_size(is_wide() ? 2 : 1);
    1.26      return (_pc == _was_wide)   // was widened?
    1.27        ? Bytes::get_Java_u2(_bc_start+2) // yes, return wide index
    1.28        : _bc_start[1];           // no, return narrow index
    1.29    }
    1.30  
    1.31 -  // Set a byte index following this bytecode.
    1.32 -  // If prefixed with a wide bytecode, get a wide index.
    1.33 -  void put_index(int idx) {
    1.34 -      if (_pc == _was_wide)     // was widened?
    1.35 -         Bytes::put_Java_u2(_bc_start+2,idx);   // yes, set wide index
    1.36 -      else
    1.37 -         _bc_start[1]=idx;              // no, set narrow index
    1.38 +  // Get 2-byte index (getfield/putstatic/etc)
    1.39 +  int get_index_big() const {
    1.40 +    assert_index_size(2);
    1.41 +    return Bytes::get_Java_u2(_bc_start+1);
    1.42    }
    1.43  
    1.44 -  // Get 2-byte index (getfield/putstatic/etc)
    1.45 -  int get_index_big() const { return Bytes::get_Java_u2(_bc_start+1); }
    1.46 +  // Get 2-byte index (or 4-byte, for invokedynamic)
    1.47 +  int get_index_int() const {
    1.48 +    return has_giant_index() ? get_index_giant() : get_index_big();
    1.49 +  }
    1.50 +
    1.51 +  // Get 4-byte index, for invokedynamic.
    1.52 +  int get_index_giant() const {
    1.53 +    assert_index_size(4);
    1.54 +    return Bytes::get_native_u4(_bc_start+1);
    1.55 +  }
    1.56 +
    1.57 +  bool has_giant_index() const { return (cur_bc() == Bytecodes::_invokedynamic); }
    1.58  
    1.59    // Get dimensions byte (multinewarray)
    1.60    int get_dimensions() const { return *(unsigned char*)(_pc-1); }
    1.61  
    1.62 -  // Get unsigned index fast
    1.63 -  int get_index_fast() const { return Bytes::get_native_u2(_pc-2); }
    1.64 -
    1.65    // Sign-extended index byte/short, no widening
    1.66    int get_byte() const { return (int8_t)(_pc[-1]); }
    1.67    int get_short() const { return (int16_t)Bytes::get_Java_u2(_pc-2); }
    1.68 @@ -225,6 +231,22 @@
    1.69    ciKlass*  get_declared_method_holder();
    1.70    int       get_method_holder_index();
    1.71    int       get_method_signature_index();
    1.72 +
    1.73 + private:
    1.74 +  void assert_index_size(int required_size) const {
    1.75 +#ifdef ASSERT
    1.76 +    int isize = instruction_size() - (is_wide() ? 1 : 0) - 1;
    1.77 +    if (isize == 2 &&  cur_bc() == Bytecodes::_iinc)
    1.78 +      isize = 1;
    1.79 +    else if (isize <= 2)
    1.80 +      ;                         // no change
    1.81 +    else if (has_giant_index())
    1.82 +      isize = 4;
    1.83 +    else
    1.84 +      isize = 2;
    1.85 +    assert(isize = required_size, "wrong index size");
    1.86 +#endif
    1.87 +  }
    1.88  };
    1.89  
    1.90  

mercurial