src/share/vm/interpreter/bytecode.hpp

changeset 1957
136b78722a08
parent 1934
e9ff18c4ace7
child 2314
f95d63e2154a
     1.1 --- a/src/share/vm/interpreter/bytecode.hpp	Mon Jun 07 14:17:01 2010 -0700
     1.2 +++ b/src/share/vm/interpreter/bytecode.hpp	Wed Jun 09 18:50:45 2010 -0700
     1.3 @@ -76,9 +76,13 @@
     1.4            return Bytes::get_native_u2(p);
     1.5      else  return Bytes::get_Java_u2(p);
     1.6    }
     1.7 +  int get_index_u1_cpcache(Bytecodes::Code bc) const {
     1.8 +    assert_same_format_as(bc); assert_index_size(1, bc);
     1.9 +    return *(jubyte*)addr_at(1) + constantPoolOopDesc::CPCACHE_INDEX_TAG;
    1.10 +  }
    1.11    int get_index_u2_cpcache(Bytecodes::Code bc) const {
    1.12      assert_same_format_as(bc); assert_index_size(2, bc); assert_native_index(bc);
    1.13 -    return Bytes::get_native_u2(addr_at(1)) DEBUG_ONLY(+ constantPoolOopDesc::CPCACHE_INDEX_TAG);
    1.14 +    return Bytes::get_native_u2(addr_at(1)) + constantPoolOopDesc::CPCACHE_INDEX_TAG;
    1.15    }
    1.16    int get_index_u4(Bytecodes::Code bc) const {
    1.17      assert_same_format_as(bc); assert_index_size(4, bc);
    1.18 @@ -152,7 +156,7 @@
    1.19  
    1.20  inline Bytecode_lookupswitch* Bytecode_lookupswitch_at(address bcp) {
    1.21    Bytecode_lookupswitch* b = (Bytecode_lookupswitch*)bcp;
    1.22 -  debug_only(b->verify());
    1.23 +  DEBUG_ONLY(b->verify());
    1.24    return b;
    1.25  }
    1.26  
    1.27 @@ -174,44 +178,56 @@
    1.28  
    1.29  inline Bytecode_tableswitch* Bytecode_tableswitch_at(address bcp) {
    1.30    Bytecode_tableswitch* b = (Bytecode_tableswitch*)bcp;
    1.31 -  debug_only(b->verify());
    1.32 +  DEBUG_ONLY(b->verify());
    1.33    return b;
    1.34  }
    1.35  
    1.36  
    1.37 -// Abstraction for invoke_{virtual, static, interface, special}
    1.38 +// Common code for decoding invokes and field references.
    1.39  
    1.40 -class Bytecode_invoke: public ResourceObj {
    1.41 +class Bytecode_member_ref: public ResourceObj {
    1.42   protected:
    1.43    methodHandle _method;                          // method containing the bytecode
    1.44    int          _bci;                             // position of the bytecode
    1.45  
    1.46 -  Bytecode_invoke(methodHandle method, int bci)  : _method(method), _bci(bci) {}
    1.47 +  Bytecode_member_ref(methodHandle method, int bci)  : _method(method), _bci(bci) {}
    1.48 +
    1.49 + public:
    1.50 +  // Attributes
    1.51 +  methodHandle method() const                    { return _method; }
    1.52 +  int          bci() const                       { return _bci; }
    1.53 +  address      bcp() const                       { return _method->bcp_from(bci()); }
    1.54 +  Bytecode*    bytecode() const                  { return Bytecode_at(bcp()); }
    1.55 +
    1.56 +  int          index() const;                    // cache index (loaded from instruction)
    1.57 +  int          pool_index() const;               // constant pool index
    1.58 +  symbolOop    name() const;                     // returns the name of the method or field
    1.59 +  symbolOop    signature() const;                // returns the signature of the method or field
    1.60 +
    1.61 +  BasicType    result_type(Thread* thread) const; // returns the result type of the getfield or invoke
    1.62 +
    1.63 +  Bytecodes::Code code() const                   { return Bytecodes::code_at(bcp(), _method()); }
    1.64 +  Bytecodes::Code java_code() const              { return Bytecodes::java_code(code()); }
    1.65 +};
    1.66 +
    1.67 +// Abstraction for invoke_{virtual, static, interface, special}
    1.68 +
    1.69 +class Bytecode_invoke: public Bytecode_member_ref {
    1.70 + protected:
    1.71 +  Bytecode_invoke(methodHandle method, int bci)  : Bytecode_member_ref(method, bci) {}
    1.72  
    1.73   public:
    1.74    void verify() const;
    1.75  
    1.76    // Attributes
    1.77 -  methodHandle method() const                    { return _method; }
    1.78 -  int          bci() const                       { return _bci; }
    1.79 -  address      bcp() const                       { return _method->bcp_from(bci()); }
    1.80 -
    1.81 -  int          index() const;                    // the constant pool index for the invoke
    1.82 -  symbolOop    name() const;                     // returns the name of the invoked method
    1.83 -  symbolOop    signature() const;                // returns the signature of the invoked method
    1.84 -  BasicType    result_type(Thread *thread) const; // returns the result type of the invoke
    1.85 -
    1.86 -  Bytecodes::Code code() const                   { return Bytecodes::code_at(bcp(), _method()); }
    1.87 -  Bytecodes::Code adjusted_invoke_code() const   { return Bytecodes::java_code(code()); }
    1.88 -
    1.89    methodHandle static_target(TRAPS);             // "specified" method   (from constant pool)
    1.90  
    1.91    // Testers
    1.92 -  bool is_invokeinterface() const                { return adjusted_invoke_code() == Bytecodes::_invokeinterface; }
    1.93 -  bool is_invokevirtual() const                  { return adjusted_invoke_code() == Bytecodes::_invokevirtual; }
    1.94 -  bool is_invokestatic() const                   { return adjusted_invoke_code() == Bytecodes::_invokestatic; }
    1.95 -  bool is_invokespecial() const                  { return adjusted_invoke_code() == Bytecodes::_invokespecial; }
    1.96 -  bool is_invokedynamic() const                  { return adjusted_invoke_code() == Bytecodes::_invokedynamic; }
    1.97 +  bool is_invokeinterface() const                { return java_code() == Bytecodes::_invokeinterface; }
    1.98 +  bool is_invokevirtual() const                  { return java_code() == Bytecodes::_invokevirtual; }
    1.99 +  bool is_invokestatic() const                   { return java_code() == Bytecodes::_invokestatic; }
   1.100 +  bool is_invokespecial() const                  { return java_code() == Bytecodes::_invokespecial; }
   1.101 +  bool is_invokedynamic() const                  { return java_code() == Bytecodes::_invokedynamic; }
   1.102  
   1.103    bool has_receiver() const                      { return !is_invokestatic() && !is_invokedynamic(); }
   1.104  
   1.105 @@ -230,7 +246,7 @@
   1.106  
   1.107  inline Bytecode_invoke* Bytecode_invoke_at(methodHandle method, int bci) {
   1.108    Bytecode_invoke* b = new Bytecode_invoke(method, bci);
   1.109 -  debug_only(b->verify());
   1.110 +  DEBUG_ONLY(b->verify());
   1.111    return b;
   1.112  }
   1.113  
   1.114 @@ -240,21 +256,34 @@
   1.115  }
   1.116  
   1.117  
   1.118 -// Abstraction for all field accesses (put/get field/static_
   1.119 -class Bytecode_field: public Bytecode {
   1.120 -public:
   1.121 +// Abstraction for all field accesses (put/get field/static)
   1.122 +class Bytecode_field: public Bytecode_member_ref {
   1.123 + protected:
   1.124 +  Bytecode_field(methodHandle method, int bci)  : Bytecode_member_ref(method, bci) {}
   1.125 +
   1.126 + public:
   1.127 +  // Testers
   1.128 +  bool is_getfield() const                       { return java_code() == Bytecodes::_getfield; }
   1.129 +  bool is_putfield() const                       { return java_code() == Bytecodes::_putfield; }
   1.130 +  bool is_getstatic() const                      { return java_code() == Bytecodes::_getstatic; }
   1.131 +  bool is_putstatic() const                      { return java_code() == Bytecodes::_putstatic; }
   1.132 +
   1.133 +  bool is_getter() const                         { return is_getfield()  || is_getstatic(); }
   1.134 +  bool is_static() const                         { return is_getstatic() || is_putstatic(); }
   1.135 +
   1.136 +  bool is_valid() const                          { return is_getfield()   ||
   1.137 +                                                          is_putfield()   ||
   1.138 +                                                          is_getstatic()  ||
   1.139 +                                                          is_putstatic(); }
   1.140    void verify() const;
   1.141  
   1.142 -  int  index() const;
   1.143 -  bool is_static() const;
   1.144 -
   1.145    // Creation
   1.146 -  inline friend Bytecode_field* Bytecode_field_at(const methodOop method, address bcp);
   1.147 +  inline friend Bytecode_field* Bytecode_field_at(methodHandle method, int bci);
   1.148  };
   1.149  
   1.150 -inline Bytecode_field* Bytecode_field_at(const methodOop method, address bcp) {
   1.151 -  Bytecode_field* b = (Bytecode_field*)bcp;
   1.152 -  debug_only(b->verify());
   1.153 +inline Bytecode_field* Bytecode_field_at(methodHandle method, int bci) {
   1.154 +  Bytecode_field* b = new Bytecode_field(method, bci);
   1.155 +  DEBUG_ONLY(b->verify());
   1.156    return b;
   1.157  }
   1.158  
   1.159 @@ -274,7 +303,7 @@
   1.160  
   1.161  inline Bytecode_checkcast* Bytecode_checkcast_at(address bcp) {
   1.162    Bytecode_checkcast* b = (Bytecode_checkcast*)bcp;
   1.163 -  debug_only(b->verify());
   1.164 +  DEBUG_ONLY(b->verify());
   1.165    return b;
   1.166  }
   1.167  
   1.168 @@ -294,7 +323,7 @@
   1.169  
   1.170  inline Bytecode_instanceof* Bytecode_instanceof_at(address bcp) {
   1.171    Bytecode_instanceof* b = (Bytecode_instanceof*)bcp;
   1.172 -  debug_only(b->verify());
   1.173 +  DEBUG_ONLY(b->verify());
   1.174    return b;
   1.175  }
   1.176  
   1.177 @@ -312,7 +341,7 @@
   1.178  
   1.179  inline Bytecode_new* Bytecode_new_at(address bcp) {
   1.180    Bytecode_new* b = (Bytecode_new*)bcp;
   1.181 -  debug_only(b->verify());
   1.182 +  DEBUG_ONLY(b->verify());
   1.183    return b;
   1.184  }
   1.185  
   1.186 @@ -330,7 +359,7 @@
   1.187  
   1.188  inline Bytecode_multianewarray* Bytecode_multianewarray_at(address bcp) {
   1.189    Bytecode_multianewarray* b = (Bytecode_multianewarray*)bcp;
   1.190 -  debug_only(b->verify());
   1.191 +  DEBUG_ONLY(b->verify());
   1.192    return b;
   1.193  }
   1.194  
   1.195 @@ -348,29 +377,57 @@
   1.196  
   1.197  inline Bytecode_anewarray* Bytecode_anewarray_at(address bcp) {
   1.198    Bytecode_anewarray* b = (Bytecode_anewarray*)bcp;
   1.199 -  debug_only(b->verify());
   1.200 +  DEBUG_ONLY(b->verify());
   1.201    return b;
   1.202  }
   1.203  
   1.204  
   1.205  // Abstraction for ldc, ldc_w and ldc2_w
   1.206  
   1.207 -class Bytecode_loadconstant: public Bytecode {
   1.208 +class Bytecode_loadconstant: public ResourceObj {
   1.209 + private:
   1.210 +  int          _bci;
   1.211 +  methodHandle _method;
   1.212 +
   1.213 +  Bytecodes::Code code() const                   { return bytecode()->code(); }
   1.214 +
   1.215 +  int raw_index() const;
   1.216 +
   1.217 +  Bytecode_loadconstant(methodHandle method, int bci) : _method(method), _bci(bci) {}
   1.218 +
   1.219   public:
   1.220 +  // Attributes
   1.221 +  methodHandle method() const                    { return _method; }
   1.222 +  int          bci() const                       { return _bci; }
   1.223 +  address      bcp() const                       { return _method->bcp_from(bci()); }
   1.224 +  Bytecode*    bytecode() const                  { return Bytecode_at(bcp()); }
   1.225 +
   1.226    void verify() const {
   1.227 +    assert(_method.not_null(), "must supply method");
   1.228      Bytecodes::Code stdc = Bytecodes::java_code(code());
   1.229      assert(stdc == Bytecodes::_ldc ||
   1.230             stdc == Bytecodes::_ldc_w ||
   1.231             stdc == Bytecodes::_ldc2_w, "load constant");
   1.232    }
   1.233  
   1.234 -  int index() const;
   1.235 +  // Only non-standard bytecodes (fast_aldc) have CP cache indexes.
   1.236 +  bool has_cache_index() const { return code() >= Bytecodes::number_of_java_codes; }
   1.237  
   1.238 -  inline friend Bytecode_loadconstant* Bytecode_loadconstant_at(const methodOop method, address bcp);
   1.239 +  int pool_index() const;               // index into constant pool
   1.240 +  int cache_index() const {             // index into CP cache (or -1 if none)
   1.241 +    return has_cache_index() ? raw_index() : -1;
   1.242 +  }
   1.243 +
   1.244 +  BasicType result_type() const;        // returns the result type of the ldc
   1.245 +
   1.246 +  oop resolve_constant(TRAPS) const;
   1.247 +
   1.248 +  // Creation
   1.249 +  inline friend Bytecode_loadconstant* Bytecode_loadconstant_at(methodHandle method, int bci);
   1.250  };
   1.251  
   1.252 -inline Bytecode_loadconstant* Bytecode_loadconstant_at(const methodOop method, address bcp) {
   1.253 -  Bytecode_loadconstant* b = (Bytecode_loadconstant*)bcp;
   1.254 -  debug_only(b->verify());
   1.255 +inline Bytecode_loadconstant* Bytecode_loadconstant_at(methodHandle method, int bci) {
   1.256 +  Bytecode_loadconstant* b = new Bytecode_loadconstant(method, bci);
   1.257 +  DEBUG_ONLY(b->verify());
   1.258    return b;
   1.259  }

mercurial