1.1 --- a/src/share/vm/interpreter/bytecode.hpp Tue Jun 01 11:48:33 2010 -0700 1.2 +++ b/src/share/vm/interpreter/bytecode.hpp Wed Jun 02 22:45:42 2010 -0700 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. 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 @@ -26,92 +26,100 @@ 1.11 // relative to an objects 'this' pointer. 1.12 1.13 class ThisRelativeObj VALUE_OBJ_CLASS_SPEC { 1.14 - private: 1.15 - int sign_extend (int x, int size) const { const int s = (BytesPerInt - size)*BitsPerByte; return (x << s) >> s; } 1.16 - 1.17 public: 1.18 // Address computation 1.19 address addr_at (int offset) const { return (address)this + offset; } 1.20 + int byte_at (int offset) const { return *(addr_at(offset)); } 1.21 address aligned_addr_at (int offset) const { return (address)round_to((intptr_t)addr_at(offset), jintSize); } 1.22 int aligned_offset (int offset) const { return aligned_addr_at(offset) - addr_at(0); } 1.23 1.24 - // Java unsigned accessors (using Java spec byte ordering) 1.25 - int java_byte_at (int offset) const { return *(jubyte*)addr_at(offset); } 1.26 - int java_hwrd_at (int offset) const { return java_byte_at(offset) << (1 * BitsPerByte) | java_byte_at(offset + 1); } 1.27 - int java_word_at (int offset) const { return java_hwrd_at(offset) << (2 * BitsPerByte) | java_hwrd_at(offset + 2); } 1.28 - 1.29 - // Java signed accessors (using Java spec byte ordering) 1.30 - int java_signed_byte_at(int offset) const { return sign_extend(java_byte_at(offset), 1); } 1.31 - int java_signed_hwrd_at(int offset) const { return sign_extend(java_hwrd_at(offset), 2); } 1.32 - int java_signed_word_at(int offset) const { return java_word_at(offset) ; } 1.33 - 1.34 - // Fast accessors (using the machine's natural byte ordering) 1.35 - int fast_byte_at (int offset) const { return *(jubyte *)addr_at(offset); } 1.36 - int fast_hwrd_at (int offset) const { return *(jushort*)addr_at(offset); } 1.37 - int fast_word_at (int offset) const { return *(juint *)addr_at(offset); } 1.38 - 1.39 - // Fast signed accessors (using the machine's natural byte ordering) 1.40 - int fast_signed_byte_at(int offset) const { return *(jbyte *)addr_at(offset); } 1.41 - int fast_signed_hwrd_at(int offset) const { return *(jshort*)addr_at(offset); } 1.42 - int fast_signed_word_at(int offset) const { return *(jint *)addr_at(offset); } 1.43 - 1.44 - // Fast manipulators (using the machine's natural byte ordering) 1.45 - void set_fast_byte_at (int offset, int x) const { *(jbyte *)addr_at(offset) = (jbyte )x; } 1.46 - void set_fast_hwrd_at (int offset, int x) const { *(jshort*)addr_at(offset) = (jshort)x; } 1.47 - void set_fast_word_at (int offset, int x) const { *(jint *)addr_at(offset) = (jint )x; } 1.48 + // Word access: 1.49 + int get_Java_u2_at (int offset) const { return Bytes::get_Java_u2(addr_at(offset)); } 1.50 + int get_Java_u4_at (int offset) const { return Bytes::get_Java_u4(addr_at(offset)); } 1.51 + int get_native_u2_at (int offset) const { return Bytes::get_native_u2(addr_at(offset)); } 1.52 + int get_native_u4_at (int offset) const { return Bytes::get_native_u4(addr_at(offset)); } 1.53 }; 1.54 1.55 1.56 // The base class for different kinds of bytecode abstractions. 1.57 // Provides the primitive operations to manipulate code relative 1.58 // to an objects 'this' pointer. 1.59 +// FIXME: Make this a ResourceObj, include the enclosing methodOop, and cache the opcode. 1.60 1.61 class Bytecode: public ThisRelativeObj { 1.62 protected: 1.63 u_char byte_at(int offset) const { return *addr_at(offset); } 1.64 - bool check_must_rewrite() const; 1.65 + bool check_must_rewrite(Bytecodes::Code bc) const; 1.66 1.67 public: 1.68 // Attributes 1.69 address bcp() const { return addr_at(0); } 1.70 - address next_bcp() const { return addr_at(0) + Bytecodes::length_at(bcp()); } 1.71 int instruction_size() const { return Bytecodes::length_at(bcp()); } 1.72 1.73 + // Warning: Use code() with caution on live bytecode streams. 4926272 1.74 Bytecodes::Code code() const { return Bytecodes::code_at(addr_at(0)); } 1.75 Bytecodes::Code java_code() const { return Bytecodes::java_code(code()); } 1.76 - bool must_rewrite() const { return Bytecodes::can_rewrite(code()) && check_must_rewrite(); } 1.77 - bool is_active_breakpoint() const { return Bytecodes::is_active_breakpoint_at(bcp()); } 1.78 - 1.79 - int one_byte_index() const { assert_index_size(1); return byte_at(1); } 1.80 - int two_byte_index() const { assert_index_size(2); return (byte_at(1) << 8) + byte_at(2); } 1.81 - 1.82 - int offset() const { return (two_byte_index() << 16) >> 16; } 1.83 - address destination() const { return bcp() + offset(); } 1.84 - 1.85 - // Attribute modification 1.86 - void set_code(Bytecodes::Code code); 1.87 + bool must_rewrite(Bytecodes::Code code) const { return Bytecodes::can_rewrite(code) && check_must_rewrite(code); } 1.88 1.89 // Creation 1.90 inline friend Bytecode* Bytecode_at(address bcp); 1.91 1.92 - private: 1.93 - void assert_index_size(int required_size) const { 1.94 -#ifdef ASSERT 1.95 - int isize = instruction_size() - 1; 1.96 - if (isize == 2 && code() == Bytecodes::_iinc) 1.97 - isize = 1; 1.98 - else if (isize <= 2) 1.99 - ; // no change 1.100 - else if (code() == Bytecodes::_invokedynamic) 1.101 - isize = 4; 1.102 - else 1.103 - isize = 2; 1.104 - assert(isize = required_size, "wrong index size"); 1.105 -#endif 1.106 + // Static functions for parsing bytecodes in place. 1.107 + int get_index_u1(Bytecodes::Code bc) const { 1.108 + assert_same_format_as(bc); assert_index_size(1, bc); 1.109 + return *(jubyte*)addr_at(1); 1.110 + } 1.111 + int get_index_u2(Bytecodes::Code bc, bool is_wide = false) const { 1.112 + assert_same_format_as(bc, is_wide); assert_index_size(2, bc, is_wide); 1.113 + address p = addr_at(is_wide ? 2 : 1); 1.114 + if (can_use_native_byte_order(bc, is_wide)) 1.115 + return Bytes::get_native_u2(p); 1.116 + else return Bytes::get_Java_u2(p); 1.117 + } 1.118 + int get_index_u2_cpcache(Bytecodes::Code bc) const { 1.119 + assert_same_format_as(bc); assert_index_size(2, bc); assert_native_index(bc); 1.120 + return Bytes::get_native_u2(addr_at(1)) DEBUG_ONLY(+ constantPoolOopDesc::CPCACHE_INDEX_TAG); 1.121 + } 1.122 + int get_index_u4(Bytecodes::Code bc) const { 1.123 + assert_same_format_as(bc); assert_index_size(4, bc); 1.124 + assert(can_use_native_byte_order(bc), ""); 1.125 + return Bytes::get_native_u4(addr_at(1)); 1.126 + } 1.127 + bool has_index_u4(Bytecodes::Code bc) const { 1.128 + return bc == Bytecodes::_invokedynamic; 1.129 + } 1.130 + 1.131 + int get_offset_s2(Bytecodes::Code bc) const { 1.132 + assert_same_format_as(bc); assert_offset_size(2, bc); 1.133 + return (jshort) Bytes::get_Java_u2(addr_at(1)); 1.134 + } 1.135 + int get_offset_s4(Bytecodes::Code bc) const { 1.136 + assert_same_format_as(bc); assert_offset_size(4, bc); 1.137 + return (jint) Bytes::get_Java_u4(addr_at(1)); 1.138 + } 1.139 + 1.140 + int get_constant_u1(int offset, Bytecodes::Code bc) const { 1.141 + assert_same_format_as(bc); assert_constant_size(1, offset, bc); 1.142 + return *(jbyte*)addr_at(offset); 1.143 + } 1.144 + int get_constant_u2(int offset, Bytecodes::Code bc, bool is_wide = false) const { 1.145 + assert_same_format_as(bc, is_wide); assert_constant_size(2, offset, bc, is_wide); 1.146 + return (jshort) Bytes::get_Java_u2(addr_at(offset)); 1.147 + } 1.148 + 1.149 + // These are used locally and also from bytecode streams. 1.150 + void assert_same_format_as(Bytecodes::Code testbc, bool is_wide = false) const NOT_DEBUG_RETURN; 1.151 + static void assert_index_size(int required_size, Bytecodes::Code bc, bool is_wide = false) NOT_DEBUG_RETURN; 1.152 + static void assert_offset_size(int required_size, Bytecodes::Code bc, bool is_wide = false) NOT_DEBUG_RETURN; 1.153 + static void assert_constant_size(int required_size, int where, Bytecodes::Code bc, bool is_wide = false) NOT_DEBUG_RETURN; 1.154 + static void assert_native_index(Bytecodes::Code bc, bool is_wide = false) NOT_DEBUG_RETURN; 1.155 + static bool can_use_native_byte_order(Bytecodes::Code bc, bool is_wide = false) { 1.156 + return (!Bytes::is_Java_byte_ordering_different() || Bytecodes::native_byte_order(bc /*, is_wide*/)); 1.157 } 1.158 }; 1.159 1.160 inline Bytecode* Bytecode_at(address bcp) { 1.161 + // Warning: Use with caution on live bytecode streams. 4926272 1.162 return (Bytecode*)bcp; 1.163 } 1.164 1.165 @@ -124,8 +132,8 @@ 1.166 int _offset; 1.167 1.168 public: 1.169 - int match() const { return java_signed_word_at(0 * jintSize); } 1.170 - int offset() const { return java_signed_word_at(1 * jintSize); } 1.171 + int match() const { return get_Java_u4_at(0 * jintSize); } 1.172 + int offset() const { return get_Java_u4_at(1 * jintSize); } 1.173 }; 1.174 1.175 1.176 @@ -134,8 +142,8 @@ 1.177 void verify() const PRODUCT_RETURN; 1.178 1.179 // Attributes 1.180 - int default_offset() const { return java_signed_word_at(aligned_offset(1 + 0*jintSize)); } 1.181 - int number_of_pairs() const { return java_signed_word_at(aligned_offset(1 + 1*jintSize)); } 1.182 + int default_offset() const { return get_Java_u4_at(aligned_offset(1 + 0*jintSize)); } 1.183 + int number_of_pairs() const { return get_Java_u4_at(aligned_offset(1 + 1*jintSize)); } 1.184 LookupswitchPair* pair_at(int i) const { assert(0 <= i && i < number_of_pairs(), "pair index out of bounds"); 1.185 return (LookupswitchPair*)aligned_addr_at(1 + (1 + i)*2*jintSize); } 1.186 // Creation 1.187 @@ -154,9 +162,9 @@ 1.188 void verify() const PRODUCT_RETURN; 1.189 1.190 // Attributes 1.191 - int default_offset() const { return java_signed_word_at(aligned_offset(1 + 0*jintSize)); } 1.192 - int low_key() const { return java_signed_word_at(aligned_offset(1 + 1*jintSize)); } 1.193 - int high_key() const { return java_signed_word_at(aligned_offset(1 + 2*jintSize)); } 1.194 + int default_offset() const { return get_Java_u4_at(aligned_offset(1 + 0*jintSize)); } 1.195 + int low_key() const { return get_Java_u4_at(aligned_offset(1 + 1*jintSize)); } 1.196 + int high_key() const { return get_Java_u4_at(aligned_offset(1 + 2*jintSize)); } 1.197 int dest_offset_at(int i) const; 1.198 int length() { return high_key()-low_key()+1; } 1.199 1.200 @@ -206,7 +214,6 @@ 1.201 bool is_invokedynamic() const { return adjusted_invoke_code() == Bytecodes::_invokedynamic; } 1.202 1.203 bool has_receiver() const { return !is_invokestatic() && !is_invokedynamic(); } 1.204 - bool has_giant_index() const { return is_invokedynamic(); } 1.205 1.206 bool is_valid() const { return is_invokeinterface() || 1.207 is_invokevirtual() || 1.208 @@ -252,26 +259,6 @@ 1.209 } 1.210 1.211 1.212 -// Abstraction for {get,put}static 1.213 - 1.214 -class Bytecode_static: public Bytecode { 1.215 - public: 1.216 - void verify() const; 1.217 - 1.218 - // Returns the result type of the send by inspecting the field ref 1.219 - BasicType result_type(methodOop method) const; 1.220 - 1.221 - // Creation 1.222 - inline friend Bytecode_static* Bytecode_static_at(const methodOop method, address bcp); 1.223 -}; 1.224 - 1.225 -inline Bytecode_static* Bytecode_static_at(const methodOop method, address bcp) { 1.226 - Bytecode_static* b = (Bytecode_static*)bcp; 1.227 - debug_only(b->verify()); 1.228 - return b; 1.229 -} 1.230 - 1.231 - 1.232 // Abstraction for checkcast 1.233 1.234 class Bytecode_checkcast: public Bytecode { 1.235 @@ -279,7 +266,7 @@ 1.236 void verify() const { assert(Bytecodes::java_code(code()) == Bytecodes::_checkcast, "check checkcast"); } 1.237 1.238 // Returns index 1.239 - long index() const { return java_hwrd_at(1); }; 1.240 + long index() const { return get_index_u2(Bytecodes::_checkcast); }; 1.241 1.242 // Creation 1.243 inline friend Bytecode_checkcast* Bytecode_checkcast_at(address bcp); 1.244 @@ -299,7 +286,7 @@ 1.245 void verify() const { assert(code() == Bytecodes::_instanceof, "check instanceof"); } 1.246 1.247 // Returns index 1.248 - long index() const { return java_hwrd_at(1); }; 1.249 + long index() const { return get_index_u2(Bytecodes::_instanceof); }; 1.250 1.251 // Creation 1.252 inline friend Bytecode_instanceof* Bytecode_instanceof_at(address bcp); 1.253 @@ -317,7 +304,7 @@ 1.254 void verify() const { assert(java_code() == Bytecodes::_new, "check new"); } 1.255 1.256 // Returns index 1.257 - long index() const { return java_hwrd_at(1); }; 1.258 + long index() const { return get_index_u2(Bytecodes::_new); }; 1.259 1.260 // Creation 1.261 inline friend Bytecode_new* Bytecode_new_at(address bcp); 1.262 @@ -335,7 +322,7 @@ 1.263 void verify() const { assert(java_code() == Bytecodes::_multianewarray, "check new"); } 1.264 1.265 // Returns index 1.266 - long index() const { return java_hwrd_at(1); }; 1.267 + long index() const { return get_index_u2(Bytecodes::_multianewarray); }; 1.268 1.269 // Creation 1.270 inline friend Bytecode_multianewarray* Bytecode_multianewarray_at(address bcp); 1.271 @@ -353,7 +340,7 @@ 1.272 void verify() const { assert(java_code() == Bytecodes::_anewarray, "check anewarray"); } 1.273 1.274 // Returns index 1.275 - long index() const { return java_hwrd_at(1); }; 1.276 + long index() const { return get_index_u2(Bytecodes::_anewarray); }; 1.277 1.278 // Creation 1.279 inline friend Bytecode_anewarray* Bytecode_anewarray_at(address bcp);