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