120 } |
117 } |
121 |
118 |
122 |
119 |
123 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) { |
120 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) { |
124 assert(wide_format == NULL || format != NULL, "short form must exist if there's a wide form"); |
121 assert(wide_format == NULL || format != NULL, "short form must exist if there's a wide form"); |
|
122 int len = (format != NULL ? (int) strlen(format) : 0); |
|
123 int wlen = (wide_format != NULL ? (int) strlen(wide_format) : 0); |
125 _name [code] = name; |
124 _name [code] = name; |
126 _format [code] = format; |
|
127 _wide_format [code] = wide_format; |
|
128 _result_type [code] = result_type; |
125 _result_type [code] = result_type; |
129 _depth [code] = depth; |
126 _depth [code] = depth; |
130 _can_trap [code] = can_trap; |
127 _lengths [code] = (wlen << 4) | (len & 0xF); |
131 _length [code] = format != NULL ? (u_char)strlen(format) : 0; |
|
132 _java_code [code] = java_code; |
128 _java_code [code] = java_code; |
133 if (java_code != code) _can_rewrite[java_code] = true; |
129 int bc_flags = 0; |
|
130 if (can_trap) bc_flags |= _bc_can_trap; |
|
131 if (java_code != code) bc_flags |= _bc_can_rewrite; |
|
132 _flags[(u1)code+0*(1<<BitsPerByte)] = compute_flags(format, bc_flags); |
|
133 _flags[(u1)code+1*(1<<BitsPerByte)] = compute_flags(wide_format, bc_flags); |
|
134 assert(is_defined(code) == (format != NULL), ""); |
|
135 assert(wide_is_defined(code) == (wide_format != NULL), ""); |
|
136 assert(length_for(code) == len, ""); |
|
137 assert(wide_length_for(code) == wlen, ""); |
134 } |
138 } |
135 |
139 |
136 |
140 |
137 // Format strings interpretation: |
141 // Format strings interpretation: |
138 // |
142 // |
139 // b: bytecode |
143 // b: bytecode |
140 // c: signed constant, Java byte-ordering |
144 // c: signed constant, Java byte-ordering |
141 // i: unsigned index , Java byte-ordering |
145 // i: unsigned local index, Java byte-ordering (I = native byte ordering) |
142 // j: unsigned index , native byte-ordering |
146 // j: unsigned CP cache index, Java byte-ordering (J = native byte ordering) |
143 // o: branch offset , Java byte-ordering |
147 // k: unsigned CP index, Java byte-ordering |
|
148 // o: branch offset, Java byte-ordering |
144 // _: unused/ignored |
149 // _: unused/ignored |
145 // w: wide bytecode |
150 // w: wide bytecode |
146 // |
151 // |
147 // Note: Right now the format strings are used for 2 purposes: |
152 // Note: The format strings are used for 2 purposes: |
148 // 1. to specify the length of the bytecode |
153 // 1. to specify the length of the bytecode |
149 // (= number of characters in format string) |
154 // (= number of characters in format string) |
150 // 2. to specify the bytecode attributes |
155 // 2. to derive bytecode format flags (_fmt_has_k, etc.) |
151 // |
|
152 // The bytecode attributes are currently used only for bytecode tracing |
|
153 // (see BytecodeTracer); thus if more specific format information is |
|
154 // used, one would also have to adjust the bytecode tracer. |
|
155 // |
156 // |
156 // Note: For bytecodes with variable length, the format string is the empty string. |
157 // Note: For bytecodes with variable length, the format string is the empty string. |
|
158 |
|
159 int Bytecodes::compute_flags(const char* format, int more_flags) { |
|
160 if (format == NULL) return 0; // not even more_flags |
|
161 int flags = more_flags; |
|
162 const char* fp = format; |
|
163 switch (*fp) { |
|
164 case '\0': |
|
165 flags |= _fmt_not_simple; // but variable |
|
166 break; |
|
167 case 'b': |
|
168 flags |= _fmt_not_variable; // but simple |
|
169 ++fp; // skip 'b' |
|
170 break; |
|
171 case 'w': |
|
172 flags |= _fmt_not_variable | _fmt_not_simple; |
|
173 ++fp; // skip 'w' |
|
174 guarantee(*fp == 'b', "wide format must start with 'wb'"); |
|
175 ++fp; // skip 'b' |
|
176 break; |
|
177 } |
|
178 |
|
179 int has_nbo = 0, has_jbo = 0, has_size = 0; |
|
180 for (;;) { |
|
181 int this_flag = 0; |
|
182 char fc = *fp++; |
|
183 switch (fc) { |
|
184 case '\0': // end of string |
|
185 assert(flags == (jchar)flags, "change _format_flags"); |
|
186 return flags; |
|
187 |
|
188 case '_': continue; // ignore these |
|
189 |
|
190 case 'j': this_flag = _fmt_has_j; has_jbo = 1; break; |
|
191 case 'k': this_flag = _fmt_has_k; has_jbo = 1; break; |
|
192 case 'i': this_flag = _fmt_has_i; has_jbo = 1; break; |
|
193 case 'c': this_flag = _fmt_has_c; has_jbo = 1; break; |
|
194 case 'o': this_flag = _fmt_has_o; has_jbo = 1; break; |
|
195 |
|
196 // uppercase versions mark native byte order (from Rewriter) |
|
197 // actually, only the 'J' case happens currently |
|
198 case 'J': this_flag = _fmt_has_j; has_nbo = 1; break; |
|
199 case 'K': this_flag = _fmt_has_k; has_nbo = 1; break; |
|
200 case 'I': this_flag = _fmt_has_i; has_nbo = 1; break; |
|
201 case 'C': this_flag = _fmt_has_c; has_nbo = 1; break; |
|
202 case 'O': this_flag = _fmt_has_o; has_nbo = 1; break; |
|
203 default: guarantee(false, "bad char in format"); |
|
204 } |
|
205 |
|
206 flags |= this_flag; |
|
207 |
|
208 guarantee(!(has_jbo && has_nbo), "mixed byte orders in format"); |
|
209 if (has_nbo) |
|
210 flags |= _fmt_has_nbo; |
|
211 |
|
212 int this_size = 1; |
|
213 if (*fp == fc) { |
|
214 // advance beyond run of the same characters |
|
215 this_size = 2; |
|
216 while (*++fp == fc) this_size++; |
|
217 switch (this_size) { |
|
218 case 2: flags |= _fmt_has_u2; break; |
|
219 case 4: flags |= _fmt_has_u4; break; |
|
220 default: guarantee(false, "bad rep count in format"); |
|
221 } |
|
222 } |
|
223 guarantee(has_size == 0 || // no field yet |
|
224 this_size == has_size || // same size |
|
225 this_size < has_size && *fp == '\0', // last field can be short |
|
226 "mixed field sizes in format"); |
|
227 has_size = this_size; |
|
228 } |
|
229 } |
157 |
230 |
158 void Bytecodes::initialize() { |
231 void Bytecodes::initialize() { |
159 if (_is_initialized) return; |
232 if (_is_initialized) return; |
160 assert(number_of_codes <= 256, "too many bytecodes"); |
233 assert(number_of_codes <= 256, "too many bytecodes"); |
161 |
234 |
187 def(_fconst_2 , "fconst_2" , "b" , NULL , T_FLOAT , 1, false); |
260 def(_fconst_2 , "fconst_2" , "b" , NULL , T_FLOAT , 1, false); |
188 def(_dconst_0 , "dconst_0" , "b" , NULL , T_DOUBLE , 2, false); |
261 def(_dconst_0 , "dconst_0" , "b" , NULL , T_DOUBLE , 2, false); |
189 def(_dconst_1 , "dconst_1" , "b" , NULL , T_DOUBLE , 2, false); |
262 def(_dconst_1 , "dconst_1" , "b" , NULL , T_DOUBLE , 2, false); |
190 def(_bipush , "bipush" , "bc" , NULL , T_INT , 1, false); |
263 def(_bipush , "bipush" , "bc" , NULL , T_INT , 1, false); |
191 def(_sipush , "sipush" , "bcc" , NULL , T_INT , 1, false); |
264 def(_sipush , "sipush" , "bcc" , NULL , T_INT , 1, false); |
192 def(_ldc , "ldc" , "bi" , NULL , T_ILLEGAL, 1, true ); |
265 def(_ldc , "ldc" , "bk" , NULL , T_ILLEGAL, 1, true ); |
193 def(_ldc_w , "ldc_w" , "bii" , NULL , T_ILLEGAL, 1, true ); |
266 def(_ldc_w , "ldc_w" , "bkk" , NULL , T_ILLEGAL, 1, true ); |
194 def(_ldc2_w , "ldc2_w" , "bii" , NULL , T_ILLEGAL, 2, true ); |
267 def(_ldc2_w , "ldc2_w" , "bkk" , NULL , T_ILLEGAL, 2, true ); |
195 def(_iload , "iload" , "bi" , "wbii" , T_INT , 1, false); |
268 def(_iload , "iload" , "bi" , "wbii" , T_INT , 1, false); |
196 def(_lload , "lload" , "bi" , "wbii" , T_LONG , 2, false); |
269 def(_lload , "lload" , "bi" , "wbii" , T_LONG , 2, false); |
197 def(_fload , "fload" , "bi" , "wbii" , T_FLOAT , 1, false); |
270 def(_fload , "fload" , "bi" , "wbii" , T_FLOAT , 1, false); |
198 def(_dload , "dload" , "bi" , "wbii" , T_DOUBLE , 2, false); |
271 def(_dload , "dload" , "bi" , "wbii" , T_DOUBLE , 2, false); |
199 def(_aload , "aload" , "bi" , "wbii" , T_OBJECT , 1, false); |
272 def(_aload , "aload" , "bi" , "wbii" , T_OBJECT , 1, false); |
347 def(_lreturn , "lreturn" , "b" , NULL , T_LONG , -2, true); |
420 def(_lreturn , "lreturn" , "b" , NULL , T_LONG , -2, true); |
348 def(_freturn , "freturn" , "b" , NULL , T_FLOAT , -1, true); |
421 def(_freturn , "freturn" , "b" , NULL , T_FLOAT , -1, true); |
349 def(_dreturn , "dreturn" , "b" , NULL , T_DOUBLE , -2, true); |
422 def(_dreturn , "dreturn" , "b" , NULL , T_DOUBLE , -2, true); |
350 def(_areturn , "areturn" , "b" , NULL , T_OBJECT , -1, true); |
423 def(_areturn , "areturn" , "b" , NULL , T_OBJECT , -1, true); |
351 def(_return , "return" , "b" , NULL , T_VOID , 0, true); |
424 def(_return , "return" , "b" , NULL , T_VOID , 0, true); |
352 def(_getstatic , "getstatic" , "bjj" , NULL , T_ILLEGAL, 1, true ); |
425 def(_getstatic , "getstatic" , "bJJ" , NULL , T_ILLEGAL, 1, true ); |
353 def(_putstatic , "putstatic" , "bjj" , NULL , T_ILLEGAL, -1, true ); |
426 def(_putstatic , "putstatic" , "bJJ" , NULL , T_ILLEGAL, -1, true ); |
354 def(_getfield , "getfield" , "bjj" , NULL , T_ILLEGAL, 0, true ); |
427 def(_getfield , "getfield" , "bJJ" , NULL , T_ILLEGAL, 0, true ); |
355 def(_putfield , "putfield" , "bjj" , NULL , T_ILLEGAL, -2, true ); |
428 def(_putfield , "putfield" , "bJJ" , NULL , T_ILLEGAL, -2, true ); |
356 def(_invokevirtual , "invokevirtual" , "bjj" , NULL , T_ILLEGAL, -1, true); |
429 def(_invokevirtual , "invokevirtual" , "bJJ" , NULL , T_ILLEGAL, -1, true); |
357 def(_invokespecial , "invokespecial" , "bjj" , NULL , T_ILLEGAL, -1, true); |
430 def(_invokespecial , "invokespecial" , "bJJ" , NULL , T_ILLEGAL, -1, true); |
358 def(_invokestatic , "invokestatic" , "bjj" , NULL , T_ILLEGAL, 0, true); |
431 def(_invokestatic , "invokestatic" , "bJJ" , NULL , T_ILLEGAL, 0, true); |
359 def(_invokeinterface , "invokeinterface" , "bjj__", NULL , T_ILLEGAL, -1, true); |
432 def(_invokeinterface , "invokeinterface" , "bJJ__", NULL , T_ILLEGAL, -1, true); |
360 def(_invokedynamic , "invokedynamic" , "bjjjj", NULL , T_ILLEGAL, 0, true ); |
433 def(_invokedynamic , "invokedynamic" , "bJJJJ", NULL , T_ILLEGAL, 0, true ); |
361 def(_new , "new" , "bii" , NULL , T_OBJECT , 1, true ); |
434 def(_new , "new" , "bkk" , NULL , T_OBJECT , 1, true ); |
362 def(_newarray , "newarray" , "bc" , NULL , T_OBJECT , 0, true ); |
435 def(_newarray , "newarray" , "bc" , NULL , T_OBJECT , 0, true ); |
363 def(_anewarray , "anewarray" , "bii" , NULL , T_OBJECT , 0, true ); |
436 def(_anewarray , "anewarray" , "bkk" , NULL , T_OBJECT , 0, true ); |
364 def(_arraylength , "arraylength" , "b" , NULL , T_VOID , 0, true ); |
437 def(_arraylength , "arraylength" , "b" , NULL , T_VOID , 0, true ); |
365 def(_athrow , "athrow" , "b" , NULL , T_VOID , -1, true ); |
438 def(_athrow , "athrow" , "b" , NULL , T_VOID , -1, true ); |
366 def(_checkcast , "checkcast" , "bii" , NULL , T_OBJECT , 0, true ); |
439 def(_checkcast , "checkcast" , "bkk" , NULL , T_OBJECT , 0, true ); |
367 def(_instanceof , "instanceof" , "bii" , NULL , T_INT , 0, true ); |
440 def(_instanceof , "instanceof" , "bkk" , NULL , T_INT , 0, true ); |
368 def(_monitorenter , "monitorenter" , "b" , NULL , T_VOID , -1, true ); |
441 def(_monitorenter , "monitorenter" , "b" , NULL , T_VOID , -1, true ); |
369 def(_monitorexit , "monitorexit" , "b" , NULL , T_VOID , -1, true ); |
442 def(_monitorexit , "monitorexit" , "b" , NULL , T_VOID , -1, true ); |
370 def(_wide , "wide" , "" , NULL , T_VOID , 0, false); |
443 def(_wide , "wide" , "" , NULL , T_VOID , 0, false); |
371 def(_multianewarray , "multianewarray" , "biic" , NULL , T_OBJECT , 1, true ); |
444 def(_multianewarray , "multianewarray" , "bkkc" , NULL , T_OBJECT , 1, true ); |
372 def(_ifnull , "ifnull" , "boo" , NULL , T_VOID , -1, false); |
445 def(_ifnull , "ifnull" , "boo" , NULL , T_VOID , -1, false); |
373 def(_ifnonnull , "ifnonnull" , "boo" , NULL , T_VOID , -1, false); |
446 def(_ifnonnull , "ifnonnull" , "boo" , NULL , T_VOID , -1, false); |
374 def(_goto_w , "goto_w" , "boooo", NULL , T_VOID , 0, false); |
447 def(_goto_w , "goto_w" , "boooo", NULL , T_VOID , 0, false); |
375 def(_jsr_w , "jsr_w" , "boooo", NULL , T_INT , 0, false); |
448 def(_jsr_w , "jsr_w" , "boooo", NULL , T_INT , 0, false); |
376 def(_breakpoint , "breakpoint" , "" , NULL , T_VOID , 0, true); |
449 def(_breakpoint , "breakpoint" , "" , NULL , T_VOID , 0, true); |
377 |
450 |
378 // JVM bytecodes |
451 // JVM bytecodes |
379 // bytecode bytecode name format wide f. result tp stk traps std code |
452 // bytecode bytecode name format wide f. result tp stk traps std code |
380 |
453 |
381 def(_fast_agetfield , "fast_agetfield" , "bjj" , NULL , T_OBJECT , 0, true , _getfield ); |
454 def(_fast_agetfield , "fast_agetfield" , "bJJ" , NULL , T_OBJECT , 0, true , _getfield ); |
382 def(_fast_bgetfield , "fast_bgetfield" , "bjj" , NULL , T_INT , 0, true , _getfield ); |
455 def(_fast_bgetfield , "fast_bgetfield" , "bJJ" , NULL , T_INT , 0, true , _getfield ); |
383 def(_fast_cgetfield , "fast_cgetfield" , "bjj" , NULL , T_CHAR , 0, true , _getfield ); |
456 def(_fast_cgetfield , "fast_cgetfield" , "bJJ" , NULL , T_CHAR , 0, true , _getfield ); |
384 def(_fast_dgetfield , "fast_dgetfield" , "bjj" , NULL , T_DOUBLE , 0, true , _getfield ); |
457 def(_fast_dgetfield , "fast_dgetfield" , "bJJ" , NULL , T_DOUBLE , 0, true , _getfield ); |
385 def(_fast_fgetfield , "fast_fgetfield" , "bjj" , NULL , T_FLOAT , 0, true , _getfield ); |
458 def(_fast_fgetfield , "fast_fgetfield" , "bJJ" , NULL , T_FLOAT , 0, true , _getfield ); |
386 def(_fast_igetfield , "fast_igetfield" , "bjj" , NULL , T_INT , 0, true , _getfield ); |
459 def(_fast_igetfield , "fast_igetfield" , "bJJ" , NULL , T_INT , 0, true , _getfield ); |
387 def(_fast_lgetfield , "fast_lgetfield" , "bjj" , NULL , T_LONG , 0, true , _getfield ); |
460 def(_fast_lgetfield , "fast_lgetfield" , "bJJ" , NULL , T_LONG , 0, true , _getfield ); |
388 def(_fast_sgetfield , "fast_sgetfield" , "bjj" , NULL , T_SHORT , 0, true , _getfield ); |
461 def(_fast_sgetfield , "fast_sgetfield" , "bJJ" , NULL , T_SHORT , 0, true , _getfield ); |
389 |
462 |
390 def(_fast_aputfield , "fast_aputfield" , "bjj" , NULL , T_OBJECT , 0, true , _putfield ); |
463 def(_fast_aputfield , "fast_aputfield" , "bJJ" , NULL , T_OBJECT , 0, true , _putfield ); |
391 def(_fast_bputfield , "fast_bputfield" , "bjj" , NULL , T_INT , 0, true , _putfield ); |
464 def(_fast_bputfield , "fast_bputfield" , "bJJ" , NULL , T_INT , 0, true , _putfield ); |
392 def(_fast_cputfield , "fast_cputfield" , "bjj" , NULL , T_CHAR , 0, true , _putfield ); |
465 def(_fast_cputfield , "fast_cputfield" , "bJJ" , NULL , T_CHAR , 0, true , _putfield ); |
393 def(_fast_dputfield , "fast_dputfield" , "bjj" , NULL , T_DOUBLE , 0, true , _putfield ); |
466 def(_fast_dputfield , "fast_dputfield" , "bJJ" , NULL , T_DOUBLE , 0, true , _putfield ); |
394 def(_fast_fputfield , "fast_fputfield" , "bjj" , NULL , T_FLOAT , 0, true , _putfield ); |
467 def(_fast_fputfield , "fast_fputfield" , "bJJ" , NULL , T_FLOAT , 0, true , _putfield ); |
395 def(_fast_iputfield , "fast_iputfield" , "bjj" , NULL , T_INT , 0, true , _putfield ); |
468 def(_fast_iputfield , "fast_iputfield" , "bJJ" , NULL , T_INT , 0, true , _putfield ); |
396 def(_fast_lputfield , "fast_lputfield" , "bjj" , NULL , T_LONG , 0, true , _putfield ); |
469 def(_fast_lputfield , "fast_lputfield" , "bJJ" , NULL , T_LONG , 0, true , _putfield ); |
397 def(_fast_sputfield , "fast_sputfield" , "bjj" , NULL , T_SHORT , 0, true , _putfield ); |
470 def(_fast_sputfield , "fast_sputfield" , "bJJ" , NULL , T_SHORT , 0, true , _putfield ); |
398 |
471 |
399 def(_fast_aload_0 , "fast_aload_0" , "b" , NULL , T_OBJECT , 1, true , _aload_0 ); |
472 def(_fast_aload_0 , "fast_aload_0" , "b" , NULL , T_OBJECT , 1, true , _aload_0 ); |
400 def(_fast_iaccess_0 , "fast_iaccess_0" , "b_jj" , NULL , T_INT , 1, true , _aload_0 ); |
473 def(_fast_iaccess_0 , "fast_iaccess_0" , "b_JJ" , NULL , T_INT , 1, true , _aload_0 ); |
401 def(_fast_aaccess_0 , "fast_aaccess_0" , "b_jj" , NULL , T_OBJECT , 1, true , _aload_0 ); |
474 def(_fast_aaccess_0 , "fast_aaccess_0" , "b_JJ" , NULL , T_OBJECT , 1, true , _aload_0 ); |
402 def(_fast_faccess_0 , "fast_faccess_0" , "b_jj" , NULL , T_OBJECT , 1, true , _aload_0 ); |
475 def(_fast_faccess_0 , "fast_faccess_0" , "b_JJ" , NULL , T_OBJECT , 1, true , _aload_0 ); |
403 |
476 |
404 def(_fast_iload , "fast_iload" , "bi" , NULL , T_INT , 1, false, _iload); |
477 def(_fast_iload , "fast_iload" , "bi" , NULL , T_INT , 1, false, _iload); |
405 def(_fast_iload2 , "fast_iload2" , "bi_i" , NULL , T_INT , 2, false, _iload); |
478 def(_fast_iload2 , "fast_iload2" , "bi_i" , NULL , T_INT , 2, false, _iload); |
406 def(_fast_icaload , "fast_icaload" , "bi_" , NULL , T_INT , 0, false, _iload); |
479 def(_fast_icaload , "fast_icaload" , "bi_" , NULL , T_INT , 0, false, _iload); |
407 |
480 |
408 // Faster method invocation. |
481 // Faster method invocation. |
409 def(_fast_invokevfinal , "fast_invokevfinal" , "bjj" , NULL , T_ILLEGAL, -1, true, _invokevirtual ); |
482 def(_fast_invokevfinal , "fast_invokevfinal" , "bJJ" , NULL , T_ILLEGAL, -1, true, _invokevirtual ); |
410 |
483 |
411 def(_fast_linearswitch , "fast_linearswitch" , "" , NULL , T_VOID , -1, false, _lookupswitch ); |
484 def(_fast_linearswitch , "fast_linearswitch" , "" , NULL , T_VOID , -1, false, _lookupswitch ); |
412 def(_fast_binaryswitch , "fast_binaryswitch" , "" , NULL , T_VOID , -1, false, _lookupswitch ); |
485 def(_fast_binaryswitch , "fast_binaryswitch" , "" , NULL , T_VOID , -1, false, _lookupswitch ); |
413 |
486 |
414 def(_return_register_finalizer , "return_register_finalizer" , "b" , NULL , T_VOID , 0, true, _return); |
487 def(_return_register_finalizer , "return_register_finalizer" , "b" , NULL , T_VOID , 0, true, _return); |