1.1 --- a/src/share/vm/interpreter/bytecodes.cpp Tue Jun 01 11:48:33 2010 -0700 1.2 +++ b/src/share/vm/interpreter/bytecodes.cpp 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 @@ -37,14 +37,11 @@ 1.11 1.12 bool Bytecodes::_is_initialized = false; 1.13 const char* Bytecodes::_name [Bytecodes::number_of_codes]; 1.14 -const char* Bytecodes::_format [Bytecodes::number_of_codes]; 1.15 -const char* Bytecodes::_wide_format [Bytecodes::number_of_codes]; 1.16 BasicType Bytecodes::_result_type [Bytecodes::number_of_codes]; 1.17 s_char Bytecodes::_depth [Bytecodes::number_of_codes]; 1.18 -u_char Bytecodes::_length [Bytecodes::number_of_codes]; 1.19 -bool Bytecodes::_can_trap [Bytecodes::number_of_codes]; 1.20 +u_char Bytecodes::_lengths [Bytecodes::number_of_codes]; 1.21 Bytecodes::Code Bytecodes::_java_code [Bytecodes::number_of_codes]; 1.22 -bool Bytecodes::_can_rewrite [Bytecodes::number_of_codes]; 1.23 +u_short Bytecodes::_flags [(1<<BitsPerByte)*2]; 1.24 1.25 1.26 Bytecodes::Code Bytecodes::code_at(methodOop method, int bci) { 1.27 @@ -91,6 +88,7 @@ 1.28 return (len > 0 && len == (int)len) ? len : -1; 1.29 } 1.30 } 1.31 + // Note: Length functions must return <=0 for invalid bytecodes. 1.32 return 0; 1.33 } 1.34 1.35 @@ -124,15 +122,22 @@ 1.36 1.37 void Bytecodes::def(Code code, const char* name, const char* format, const char* wide_format, BasicType result_type, int depth, bool can_trap, Code java_code) { 1.38 assert(wide_format == NULL || format != NULL, "short form must exist if there's a wide form"); 1.39 + int len = (format != NULL ? (int) strlen(format) : 0); 1.40 + int wlen = (wide_format != NULL ? (int) strlen(wide_format) : 0); 1.41 _name [code] = name; 1.42 - _format [code] = format; 1.43 - _wide_format [code] = wide_format; 1.44 _result_type [code] = result_type; 1.45 _depth [code] = depth; 1.46 - _can_trap [code] = can_trap; 1.47 - _length [code] = format != NULL ? (u_char)strlen(format) : 0; 1.48 + _lengths [code] = (wlen << 4) | (len & 0xF); 1.49 _java_code [code] = java_code; 1.50 - if (java_code != code) _can_rewrite[java_code] = true; 1.51 + int bc_flags = 0; 1.52 + if (can_trap) bc_flags |= _bc_can_trap; 1.53 + if (java_code != code) bc_flags |= _bc_can_rewrite; 1.54 + _flags[(u1)code+0*(1<<BitsPerByte)] = compute_flags(format, bc_flags); 1.55 + _flags[(u1)code+1*(1<<BitsPerByte)] = compute_flags(wide_format, bc_flags); 1.56 + assert(is_defined(code) == (format != NULL), ""); 1.57 + assert(wide_is_defined(code) == (wide_format != NULL), ""); 1.58 + assert(length_for(code) == len, ""); 1.59 + assert(wide_length_for(code) == wlen, ""); 1.60 } 1.61 1.62 1.63 @@ -140,23 +145,92 @@ 1.64 // 1.65 // b: bytecode 1.66 // c: signed constant, Java byte-ordering 1.67 -// i: unsigned index , Java byte-ordering 1.68 -// j: unsigned index , native byte-ordering 1.69 -// o: branch offset , Java byte-ordering 1.70 +// i: unsigned local index, Java byte-ordering (I = native byte ordering) 1.71 +// j: unsigned CP cache index, Java byte-ordering (J = native byte ordering) 1.72 +// k: unsigned CP index, Java byte-ordering 1.73 +// o: branch offset, Java byte-ordering 1.74 // _: unused/ignored 1.75 // w: wide bytecode 1.76 // 1.77 -// Note: Right now the format strings are used for 2 purposes: 1.78 +// Note: The format strings are used for 2 purposes: 1.79 // 1. to specify the length of the bytecode 1.80 // (= number of characters in format string) 1.81 -// 2. to specify the bytecode attributes 1.82 -// 1.83 -// The bytecode attributes are currently used only for bytecode tracing 1.84 -// (see BytecodeTracer); thus if more specific format information is 1.85 -// used, one would also have to adjust the bytecode tracer. 1.86 +// 2. to derive bytecode format flags (_fmt_has_k, etc.) 1.87 // 1.88 // Note: For bytecodes with variable length, the format string is the empty string. 1.89 1.90 +int Bytecodes::compute_flags(const char* format, int more_flags) { 1.91 + if (format == NULL) return 0; // not even more_flags 1.92 + int flags = more_flags; 1.93 + const char* fp = format; 1.94 + switch (*fp) { 1.95 + case '\0': 1.96 + flags |= _fmt_not_simple; // but variable 1.97 + break; 1.98 + case 'b': 1.99 + flags |= _fmt_not_variable; // but simple 1.100 + ++fp; // skip 'b' 1.101 + break; 1.102 + case 'w': 1.103 + flags |= _fmt_not_variable | _fmt_not_simple; 1.104 + ++fp; // skip 'w' 1.105 + guarantee(*fp == 'b', "wide format must start with 'wb'"); 1.106 + ++fp; // skip 'b' 1.107 + break; 1.108 + } 1.109 + 1.110 + int has_nbo = 0, has_jbo = 0, has_size = 0; 1.111 + for (;;) { 1.112 + int this_flag = 0; 1.113 + char fc = *fp++; 1.114 + switch (fc) { 1.115 + case '\0': // end of string 1.116 + assert(flags == (jchar)flags, "change _format_flags"); 1.117 + return flags; 1.118 + 1.119 + case '_': continue; // ignore these 1.120 + 1.121 + case 'j': this_flag = _fmt_has_j; has_jbo = 1; break; 1.122 + case 'k': this_flag = _fmt_has_k; has_jbo = 1; break; 1.123 + case 'i': this_flag = _fmt_has_i; has_jbo = 1; break; 1.124 + case 'c': this_flag = _fmt_has_c; has_jbo = 1; break; 1.125 + case 'o': this_flag = _fmt_has_o; has_jbo = 1; break; 1.126 + 1.127 + // uppercase versions mark native byte order (from Rewriter) 1.128 + // actually, only the 'J' case happens currently 1.129 + case 'J': this_flag = _fmt_has_j; has_nbo = 1; break; 1.130 + case 'K': this_flag = _fmt_has_k; has_nbo = 1; break; 1.131 + case 'I': this_flag = _fmt_has_i; has_nbo = 1; break; 1.132 + case 'C': this_flag = _fmt_has_c; has_nbo = 1; break; 1.133 + case 'O': this_flag = _fmt_has_o; has_nbo = 1; break; 1.134 + default: guarantee(false, "bad char in format"); 1.135 + } 1.136 + 1.137 + flags |= this_flag; 1.138 + 1.139 + guarantee(!(has_jbo && has_nbo), "mixed byte orders in format"); 1.140 + if (has_nbo) 1.141 + flags |= _fmt_has_nbo; 1.142 + 1.143 + int this_size = 1; 1.144 + if (*fp == fc) { 1.145 + // advance beyond run of the same characters 1.146 + this_size = 2; 1.147 + while (*++fp == fc) this_size++; 1.148 + switch (this_size) { 1.149 + case 2: flags |= _fmt_has_u2; break; 1.150 + case 4: flags |= _fmt_has_u4; break; 1.151 + default: guarantee(false, "bad rep count in format"); 1.152 + } 1.153 + } 1.154 + guarantee(has_size == 0 || // no field yet 1.155 + this_size == has_size || // same size 1.156 + this_size < has_size && *fp == '\0', // last field can be short 1.157 + "mixed field sizes in format"); 1.158 + has_size = this_size; 1.159 + } 1.160 +} 1.161 + 1.162 void Bytecodes::initialize() { 1.163 if (_is_initialized) return; 1.164 assert(number_of_codes <= 256, "too many bytecodes"); 1.165 @@ -191,9 +265,9 @@ 1.166 def(_dconst_1 , "dconst_1" , "b" , NULL , T_DOUBLE , 2, false); 1.167 def(_bipush , "bipush" , "bc" , NULL , T_INT , 1, false); 1.168 def(_sipush , "sipush" , "bcc" , NULL , T_INT , 1, false); 1.169 - def(_ldc , "ldc" , "bi" , NULL , T_ILLEGAL, 1, true ); 1.170 - def(_ldc_w , "ldc_w" , "bii" , NULL , T_ILLEGAL, 1, true ); 1.171 - def(_ldc2_w , "ldc2_w" , "bii" , NULL , T_ILLEGAL, 2, true ); 1.172 + def(_ldc , "ldc" , "bk" , NULL , T_ILLEGAL, 1, true ); 1.173 + def(_ldc_w , "ldc_w" , "bkk" , NULL , T_ILLEGAL, 1, true ); 1.174 + def(_ldc2_w , "ldc2_w" , "bkk" , NULL , T_ILLEGAL, 2, true ); 1.175 def(_iload , "iload" , "bi" , "wbii" , T_INT , 1, false); 1.176 def(_lload , "lload" , "bi" , "wbii" , T_LONG , 2, false); 1.177 def(_fload , "fload" , "bi" , "wbii" , T_FLOAT , 1, false); 1.178 @@ -351,26 +425,26 @@ 1.179 def(_dreturn , "dreturn" , "b" , NULL , T_DOUBLE , -2, true); 1.180 def(_areturn , "areturn" , "b" , NULL , T_OBJECT , -1, true); 1.181 def(_return , "return" , "b" , NULL , T_VOID , 0, true); 1.182 - def(_getstatic , "getstatic" , "bjj" , NULL , T_ILLEGAL, 1, true ); 1.183 - def(_putstatic , "putstatic" , "bjj" , NULL , T_ILLEGAL, -1, true ); 1.184 - def(_getfield , "getfield" , "bjj" , NULL , T_ILLEGAL, 0, true ); 1.185 - def(_putfield , "putfield" , "bjj" , NULL , T_ILLEGAL, -2, true ); 1.186 - def(_invokevirtual , "invokevirtual" , "bjj" , NULL , T_ILLEGAL, -1, true); 1.187 - def(_invokespecial , "invokespecial" , "bjj" , NULL , T_ILLEGAL, -1, true); 1.188 - def(_invokestatic , "invokestatic" , "bjj" , NULL , T_ILLEGAL, 0, true); 1.189 - def(_invokeinterface , "invokeinterface" , "bjj__", NULL , T_ILLEGAL, -1, true); 1.190 - def(_invokedynamic , "invokedynamic" , "bjjjj", NULL , T_ILLEGAL, 0, true ); 1.191 - def(_new , "new" , "bii" , NULL , T_OBJECT , 1, true ); 1.192 + def(_getstatic , "getstatic" , "bJJ" , NULL , T_ILLEGAL, 1, true ); 1.193 + def(_putstatic , "putstatic" , "bJJ" , NULL , T_ILLEGAL, -1, true ); 1.194 + def(_getfield , "getfield" , "bJJ" , NULL , T_ILLEGAL, 0, true ); 1.195 + def(_putfield , "putfield" , "bJJ" , NULL , T_ILLEGAL, -2, true ); 1.196 + def(_invokevirtual , "invokevirtual" , "bJJ" , NULL , T_ILLEGAL, -1, true); 1.197 + def(_invokespecial , "invokespecial" , "bJJ" , NULL , T_ILLEGAL, -1, true); 1.198 + def(_invokestatic , "invokestatic" , "bJJ" , NULL , T_ILLEGAL, 0, true); 1.199 + def(_invokeinterface , "invokeinterface" , "bJJ__", NULL , T_ILLEGAL, -1, true); 1.200 + def(_invokedynamic , "invokedynamic" , "bJJJJ", NULL , T_ILLEGAL, 0, true ); 1.201 + def(_new , "new" , "bkk" , NULL , T_OBJECT , 1, true ); 1.202 def(_newarray , "newarray" , "bc" , NULL , T_OBJECT , 0, true ); 1.203 - def(_anewarray , "anewarray" , "bii" , NULL , T_OBJECT , 0, true ); 1.204 + def(_anewarray , "anewarray" , "bkk" , NULL , T_OBJECT , 0, true ); 1.205 def(_arraylength , "arraylength" , "b" , NULL , T_VOID , 0, true ); 1.206 def(_athrow , "athrow" , "b" , NULL , T_VOID , -1, true ); 1.207 - def(_checkcast , "checkcast" , "bii" , NULL , T_OBJECT , 0, true ); 1.208 - def(_instanceof , "instanceof" , "bii" , NULL , T_INT , 0, true ); 1.209 + def(_checkcast , "checkcast" , "bkk" , NULL , T_OBJECT , 0, true ); 1.210 + def(_instanceof , "instanceof" , "bkk" , NULL , T_INT , 0, true ); 1.211 def(_monitorenter , "monitorenter" , "b" , NULL , T_VOID , -1, true ); 1.212 def(_monitorexit , "monitorexit" , "b" , NULL , T_VOID , -1, true ); 1.213 def(_wide , "wide" , "" , NULL , T_VOID , 0, false); 1.214 - def(_multianewarray , "multianewarray" , "biic" , NULL , T_OBJECT , 1, true ); 1.215 + def(_multianewarray , "multianewarray" , "bkkc" , NULL , T_OBJECT , 1, true ); 1.216 def(_ifnull , "ifnull" , "boo" , NULL , T_VOID , -1, false); 1.217 def(_ifnonnull , "ifnonnull" , "boo" , NULL , T_VOID , -1, false); 1.218 def(_goto_w , "goto_w" , "boooo", NULL , T_VOID , 0, false); 1.219 @@ -380,35 +454,35 @@ 1.220 // JVM bytecodes 1.221 // bytecode bytecode name format wide f. result tp stk traps std code 1.222 1.223 - def(_fast_agetfield , "fast_agetfield" , "bjj" , NULL , T_OBJECT , 0, true , _getfield ); 1.224 - def(_fast_bgetfield , "fast_bgetfield" , "bjj" , NULL , T_INT , 0, true , _getfield ); 1.225 - def(_fast_cgetfield , "fast_cgetfield" , "bjj" , NULL , T_CHAR , 0, true , _getfield ); 1.226 - def(_fast_dgetfield , "fast_dgetfield" , "bjj" , NULL , T_DOUBLE , 0, true , _getfield ); 1.227 - def(_fast_fgetfield , "fast_fgetfield" , "bjj" , NULL , T_FLOAT , 0, true , _getfield ); 1.228 - def(_fast_igetfield , "fast_igetfield" , "bjj" , NULL , T_INT , 0, true , _getfield ); 1.229 - def(_fast_lgetfield , "fast_lgetfield" , "bjj" , NULL , T_LONG , 0, true , _getfield ); 1.230 - def(_fast_sgetfield , "fast_sgetfield" , "bjj" , NULL , T_SHORT , 0, true , _getfield ); 1.231 + def(_fast_agetfield , "fast_agetfield" , "bJJ" , NULL , T_OBJECT , 0, true , _getfield ); 1.232 + def(_fast_bgetfield , "fast_bgetfield" , "bJJ" , NULL , T_INT , 0, true , _getfield ); 1.233 + def(_fast_cgetfield , "fast_cgetfield" , "bJJ" , NULL , T_CHAR , 0, true , _getfield ); 1.234 + def(_fast_dgetfield , "fast_dgetfield" , "bJJ" , NULL , T_DOUBLE , 0, true , _getfield ); 1.235 + def(_fast_fgetfield , "fast_fgetfield" , "bJJ" , NULL , T_FLOAT , 0, true , _getfield ); 1.236 + def(_fast_igetfield , "fast_igetfield" , "bJJ" , NULL , T_INT , 0, true , _getfield ); 1.237 + def(_fast_lgetfield , "fast_lgetfield" , "bJJ" , NULL , T_LONG , 0, true , _getfield ); 1.238 + def(_fast_sgetfield , "fast_sgetfield" , "bJJ" , NULL , T_SHORT , 0, true , _getfield ); 1.239 1.240 - def(_fast_aputfield , "fast_aputfield" , "bjj" , NULL , T_OBJECT , 0, true , _putfield ); 1.241 - def(_fast_bputfield , "fast_bputfield" , "bjj" , NULL , T_INT , 0, true , _putfield ); 1.242 - def(_fast_cputfield , "fast_cputfield" , "bjj" , NULL , T_CHAR , 0, true , _putfield ); 1.243 - def(_fast_dputfield , "fast_dputfield" , "bjj" , NULL , T_DOUBLE , 0, true , _putfield ); 1.244 - def(_fast_fputfield , "fast_fputfield" , "bjj" , NULL , T_FLOAT , 0, true , _putfield ); 1.245 - def(_fast_iputfield , "fast_iputfield" , "bjj" , NULL , T_INT , 0, true , _putfield ); 1.246 - def(_fast_lputfield , "fast_lputfield" , "bjj" , NULL , T_LONG , 0, true , _putfield ); 1.247 - def(_fast_sputfield , "fast_sputfield" , "bjj" , NULL , T_SHORT , 0, true , _putfield ); 1.248 + def(_fast_aputfield , "fast_aputfield" , "bJJ" , NULL , T_OBJECT , 0, true , _putfield ); 1.249 + def(_fast_bputfield , "fast_bputfield" , "bJJ" , NULL , T_INT , 0, true , _putfield ); 1.250 + def(_fast_cputfield , "fast_cputfield" , "bJJ" , NULL , T_CHAR , 0, true , _putfield ); 1.251 + def(_fast_dputfield , "fast_dputfield" , "bJJ" , NULL , T_DOUBLE , 0, true , _putfield ); 1.252 + def(_fast_fputfield , "fast_fputfield" , "bJJ" , NULL , T_FLOAT , 0, true , _putfield ); 1.253 + def(_fast_iputfield , "fast_iputfield" , "bJJ" , NULL , T_INT , 0, true , _putfield ); 1.254 + def(_fast_lputfield , "fast_lputfield" , "bJJ" , NULL , T_LONG , 0, true , _putfield ); 1.255 + def(_fast_sputfield , "fast_sputfield" , "bJJ" , NULL , T_SHORT , 0, true , _putfield ); 1.256 1.257 def(_fast_aload_0 , "fast_aload_0" , "b" , NULL , T_OBJECT , 1, true , _aload_0 ); 1.258 - def(_fast_iaccess_0 , "fast_iaccess_0" , "b_jj" , NULL , T_INT , 1, true , _aload_0 ); 1.259 - def(_fast_aaccess_0 , "fast_aaccess_0" , "b_jj" , NULL , T_OBJECT , 1, true , _aload_0 ); 1.260 - def(_fast_faccess_0 , "fast_faccess_0" , "b_jj" , NULL , T_OBJECT , 1, true , _aload_0 ); 1.261 + def(_fast_iaccess_0 , "fast_iaccess_0" , "b_JJ" , NULL , T_INT , 1, true , _aload_0 ); 1.262 + def(_fast_aaccess_0 , "fast_aaccess_0" , "b_JJ" , NULL , T_OBJECT , 1, true , _aload_0 ); 1.263 + def(_fast_faccess_0 , "fast_faccess_0" , "b_JJ" , NULL , T_OBJECT , 1, true , _aload_0 ); 1.264 1.265 def(_fast_iload , "fast_iload" , "bi" , NULL , T_INT , 1, false, _iload); 1.266 def(_fast_iload2 , "fast_iload2" , "bi_i" , NULL , T_INT , 2, false, _iload); 1.267 def(_fast_icaload , "fast_icaload" , "bi_" , NULL , T_INT , 0, false, _iload); 1.268 1.269 // Faster method invocation. 1.270 - def(_fast_invokevfinal , "fast_invokevfinal" , "bjj" , NULL , T_ILLEGAL, -1, true, _invokevirtual ); 1.271 + def(_fast_invokevfinal , "fast_invokevfinal" , "bJJ" , NULL , T_ILLEGAL, -1, true, _invokevirtual ); 1.272 1.273 def(_fast_linearswitch , "fast_linearswitch" , "" , NULL , T_VOID , -1, false, _lookupswitch ); 1.274 def(_fast_binaryswitch , "fast_binaryswitch" , "" , NULL , T_VOID , -1, false, _lookupswitch );