1 /*
   2  * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "asm/macroAssembler.hpp"
  27 #include "compiler/disassembler.hpp"
  28 #include "gc/shared/collectedHeap.hpp"
  29 #include "gc/shared/gc_globals.hpp"
  30 #include "gc/shared/tlab_globals.hpp"
  31 #include "interpreter/interpreter.hpp"
  32 #include "interpreter/interpreterRuntime.hpp"
  33 #include "interpreter/interp_masm.hpp"
  34 #include "interpreter/templateTable.hpp"
  35 #include "memory/universe.hpp"
  36 #include "oops/methodCounters.hpp"
  37 #include "oops/methodData.hpp"
  38 #include "oops/objArrayKlass.hpp"
  39 #include "oops/oop.inline.hpp"
  40 #include "oops/inlineKlass.hpp"
  41 #include "oops/resolvedFieldEntry.hpp"
  42 #include "oops/resolvedIndyEntry.hpp"
  43 #include "oops/resolvedMethodEntry.hpp"
  44 #include "prims/jvmtiExport.hpp"
  45 #include "prims/methodHandles.hpp"
  46 #include "runtime/frame.inline.hpp"
  47 #include "runtime/safepointMechanism.hpp"
  48 #include "runtime/sharedRuntime.hpp"
  49 #include "runtime/stubRoutines.hpp"
  50 #include "runtime/synchronizer.hpp"
  51 #include "utilities/macros.hpp"
  52 
  53 #define __ Disassembler::hook<InterpreterMacroAssembler>(__FILE__, __LINE__, _masm)->
  54 
  55 // Global Register Names
  56 static const Register rbcp     = LP64_ONLY(r13) NOT_LP64(rsi);
  57 static const Register rlocals  = LP64_ONLY(r14) NOT_LP64(rdi);
  58 
  59 // Address Computation: local variables
  60 static inline Address iaddress(int n) {
  61   return Address(rlocals, Interpreter::local_offset_in_bytes(n));
  62 }
  63 
  64 static inline Address laddress(int n) {
  65   return iaddress(n + 1);
  66 }
  67 
  68 #ifndef _LP64
  69 static inline Address haddress(int n) {
  70   return iaddress(n + 0);
  71 }
  72 #endif
  73 
  74 static inline Address faddress(int n) {
  75   return iaddress(n);
  76 }
  77 
  78 static inline Address daddress(int n) {
  79   return laddress(n);
  80 }
  81 
  82 static inline Address aaddress(int n) {
  83   return iaddress(n);
  84 }
  85 
  86 static inline Address iaddress(Register r) {
  87   return Address(rlocals, r, Address::times_ptr);
  88 }
  89 
  90 static inline Address laddress(Register r) {
  91   return Address(rlocals, r, Address::times_ptr, Interpreter::local_offset_in_bytes(1));
  92 }
  93 
  94 #ifndef _LP64
  95 static inline Address haddress(Register r)       {
  96   return Address(rlocals, r, Interpreter::stackElementScale(), Interpreter::local_offset_in_bytes(0));
  97 }
  98 #endif
  99 
 100 static inline Address faddress(Register r) {
 101   return iaddress(r);
 102 }
 103 
 104 static inline Address daddress(Register r) {
 105   return laddress(r);
 106 }
 107 
 108 static inline Address aaddress(Register r) {
 109   return iaddress(r);
 110 }
 111 
 112 
 113 // expression stack
 114 // (Note: Must not use symmetric equivalents at_rsp_m1/2 since they store
 115 // data beyond the rsp which is potentially unsafe in an MT environment;
 116 // an interrupt may overwrite that data.)
 117 static inline Address at_rsp   () {
 118   return Address(rsp, 0);
 119 }
 120 
 121 // At top of Java expression stack which may be different than esp().  It
 122 // isn't for category 1 objects.
 123 static inline Address at_tos   () {
 124   return Address(rsp,  Interpreter::expr_offset_in_bytes(0));
 125 }
 126 
 127 static inline Address at_tos_p1() {
 128   return Address(rsp,  Interpreter::expr_offset_in_bytes(1));
 129 }
 130 
 131 static inline Address at_tos_p2() {
 132   return Address(rsp,  Interpreter::expr_offset_in_bytes(2));
 133 }
 134 
 135 // Condition conversion
 136 static Assembler::Condition j_not(TemplateTable::Condition cc) {
 137   switch (cc) {
 138   case TemplateTable::equal        : return Assembler::notEqual;
 139   case TemplateTable::not_equal    : return Assembler::equal;
 140   case TemplateTable::less         : return Assembler::greaterEqual;
 141   case TemplateTable::less_equal   : return Assembler::greater;
 142   case TemplateTable::greater      : return Assembler::lessEqual;
 143   case TemplateTable::greater_equal: return Assembler::less;
 144   }
 145   ShouldNotReachHere();
 146   return Assembler::zero;
 147 }
 148 
 149 
 150 
 151 // Miscellaneous helper routines
 152 // Store an oop (or null) at the address described by obj.
 153 // If val == noreg this means store a null
 154 
 155 
 156 static void do_oop_store(InterpreterMacroAssembler* _masm,
 157                          Address dst,
 158                          Register val,
 159                          DecoratorSet decorators = 0) {
 160   assert(val == noreg || val == rax, "parameter is just for looks");
 161   __ store_heap_oop(dst, val,
 162                     NOT_LP64(rdx) LP64_ONLY(rscratch2),
 163                     NOT_LP64(rbx) LP64_ONLY(r9),
 164                     NOT_LP64(rsi) LP64_ONLY(r8), decorators);
 165 }
 166 
 167 static void do_oop_load(InterpreterMacroAssembler* _masm,
 168                         Address src,
 169                         Register dst,
 170                         DecoratorSet decorators = 0) {
 171   __ load_heap_oop(dst, src, rdx, rbx, decorators);
 172 }
 173 
 174 Address TemplateTable::at_bcp(int offset) {
 175   assert(_desc->uses_bcp(), "inconsistent uses_bcp information");
 176   return Address(rbcp, offset);
 177 }
 178 
 179 
 180 void TemplateTable::patch_bytecode(Bytecodes::Code bc, Register bc_reg,
 181                                    Register temp_reg, bool load_bc_into_bc_reg/*=true*/,
 182                                    int byte_no) {
 183   if (!RewriteBytecodes)  return;
 184   Label L_patch_done;
 185 
 186   switch (bc) {
 187   case Bytecodes::_fast_qputfield:
 188   case Bytecodes::_fast_aputfield:
 189   case Bytecodes::_fast_bputfield:
 190   case Bytecodes::_fast_zputfield:
 191   case Bytecodes::_fast_cputfield:
 192   case Bytecodes::_fast_dputfield:
 193   case Bytecodes::_fast_fputfield:
 194   case Bytecodes::_fast_iputfield:
 195   case Bytecodes::_fast_lputfield:
 196   case Bytecodes::_fast_sputfield:
 197     {
 198       // We skip bytecode quickening for putfield instructions when
 199       // the put_code written to the constant pool cache is zero.
 200       // This is required so that every execution of this instruction
 201       // calls out to InterpreterRuntime::resolve_get_put to do
 202       // additional, required work.
 203       assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
 204       assert(load_bc_into_bc_reg, "we use bc_reg as temp");
 205       __ load_field_entry(temp_reg, bc_reg);
 206       if (byte_no == f1_byte) {
 207         __ load_unsigned_byte(temp_reg, Address(temp_reg, in_bytes(ResolvedFieldEntry::get_code_offset())));
 208       } else {
 209         __ load_unsigned_byte(temp_reg, Address(temp_reg, in_bytes(ResolvedFieldEntry::put_code_offset())));
 210       }
 211 
 212       __ movl(bc_reg, bc);
 213       __ cmpl(temp_reg, (int) 0);
 214       __ jcc(Assembler::zero, L_patch_done);  // don't patch
 215     }
 216     break;
 217   default:
 218     assert(byte_no == -1, "sanity");
 219     // the pair bytecodes have already done the load.
 220     if (load_bc_into_bc_reg) {
 221       __ movl(bc_reg, bc);
 222     }
 223   }
 224 
 225   if (JvmtiExport::can_post_breakpoint()) {
 226     Label L_fast_patch;
 227     // if a breakpoint is present we can't rewrite the stream directly
 228     __ movzbl(temp_reg, at_bcp(0));
 229     __ cmpl(temp_reg, Bytecodes::_breakpoint);
 230     __ jcc(Assembler::notEqual, L_fast_patch);
 231     __ get_method(temp_reg);
 232     // Let breakpoint table handling rewrite to quicker bytecode
 233     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::set_original_bytecode_at), temp_reg, rbcp, bc_reg);
 234 #ifndef ASSERT
 235     __ jmpb(L_patch_done);
 236 #else
 237     __ jmp(L_patch_done);
 238 #endif
 239     __ bind(L_fast_patch);
 240   }
 241 
 242 #ifdef ASSERT
 243   Label L_okay;
 244   __ load_unsigned_byte(temp_reg, at_bcp(0));
 245   __ cmpl(temp_reg, (int) Bytecodes::java_code(bc));
 246   __ jcc(Assembler::equal, L_okay);
 247   __ cmpl(temp_reg, bc_reg);
 248   __ jcc(Assembler::equal, L_okay);
 249   __ stop("patching the wrong bytecode");
 250   __ bind(L_okay);
 251 #endif
 252 
 253   // patch bytecode
 254   __ movb(at_bcp(0), bc_reg);
 255   __ bind(L_patch_done);
 256 }
 257 // Individual instructions
 258 
 259 
 260 void TemplateTable::nop() {
 261   transition(vtos, vtos);
 262   // nothing to do
 263 }
 264 
 265 void TemplateTable::shouldnotreachhere() {
 266   transition(vtos, vtos);
 267   __ stop("shouldnotreachhere bytecode");
 268 }
 269 
 270 void TemplateTable::aconst_null() {
 271   transition(vtos, atos);
 272   __ xorl(rax, rax);
 273 }
 274 
 275 void TemplateTable::iconst(int value) {
 276   transition(vtos, itos);
 277   if (value == 0) {
 278     __ xorl(rax, rax);
 279   } else {
 280     __ movl(rax, value);
 281   }
 282 }
 283 
 284 void TemplateTable::lconst(int value) {
 285   transition(vtos, ltos);
 286   if (value == 0) {
 287     __ xorl(rax, rax);
 288   } else {
 289     __ movl(rax, value);
 290   }
 291 #ifndef _LP64
 292   assert(value >= 0, "check this code");
 293   __ xorptr(rdx, rdx);
 294 #endif
 295 }
 296 
 297 
 298 
 299 void TemplateTable::fconst(int value) {
 300   transition(vtos, ftos);
 301   if (UseSSE >= 1) {
 302     static float one = 1.0f, two = 2.0f;
 303     switch (value) {
 304     case 0:
 305       __ xorps(xmm0, xmm0);
 306       break;
 307     case 1:
 308       __ movflt(xmm0, ExternalAddress((address) &one), rscratch1);
 309       break;
 310     case 2:
 311       __ movflt(xmm0, ExternalAddress((address) &two), rscratch1);
 312       break;
 313     default:
 314       ShouldNotReachHere();
 315       break;
 316     }
 317   } else {
 318 #ifdef _LP64
 319     ShouldNotReachHere();
 320 #else
 321            if (value == 0) { __ fldz();
 322     } else if (value == 1) { __ fld1();
 323     } else if (value == 2) { __ fld1(); __ fld1(); __ faddp(); // should do a better solution here
 324     } else                 { ShouldNotReachHere();
 325     }
 326 #endif // _LP64
 327   }
 328 }
 329 
 330 void TemplateTable::dconst(int value) {
 331   transition(vtos, dtos);
 332   if (UseSSE >= 2) {
 333     static double one = 1.0;
 334     switch (value) {
 335     case 0:
 336       __ xorpd(xmm0, xmm0);
 337       break;
 338     case 1:
 339       __ movdbl(xmm0, ExternalAddress((address) &one), rscratch1);
 340       break;
 341     default:
 342       ShouldNotReachHere();
 343       break;
 344     }
 345   } else {
 346 #ifdef _LP64
 347     ShouldNotReachHere();
 348 #else
 349            if (value == 0) { __ fldz();
 350     } else if (value == 1) { __ fld1();
 351     } else                 { ShouldNotReachHere();
 352     }
 353 #endif
 354   }
 355 }
 356 
 357 void TemplateTable::bipush() {
 358   transition(vtos, itos);
 359   __ load_signed_byte(rax, at_bcp(1));
 360 }
 361 
 362 void TemplateTable::sipush() {
 363   transition(vtos, itos);
 364   __ load_unsigned_short(rax, at_bcp(1));
 365   __ bswapl(rax);
 366   __ sarl(rax, 16);
 367 }
 368 
 369 void TemplateTable::ldc(LdcType type) {
 370   transition(vtos, vtos);
 371   Register rarg = NOT_LP64(rcx) LP64_ONLY(c_rarg1);
 372   Label call_ldc, notFloat, notClass, notInt, Done;
 373 
 374   if (is_ldc_wide(type)) {
 375     __ get_unsigned_2_byte_index_at_bcp(rbx, 1);
 376   } else {
 377     __ load_unsigned_byte(rbx, at_bcp(1));
 378   }
 379 
 380   __ get_cpool_and_tags(rcx, rax);
 381   const int base_offset = ConstantPool::header_size() * wordSize;
 382   const int tags_offset = Array<u1>::base_offset_in_bytes();
 383 
 384   // get type
 385   __ movzbl(rdx, Address(rax, rbx, Address::times_1, tags_offset));
 386 
 387   // unresolved class - get the resolved class
 388   __ cmpl(rdx, JVM_CONSTANT_UnresolvedClass);
 389   __ jccb(Assembler::equal, call_ldc);
 390 
 391   // unresolved class in error state - call into runtime to throw the error
 392   // from the first resolution attempt
 393   __ cmpl(rdx, JVM_CONSTANT_UnresolvedClassInError);
 394   __ jccb(Assembler::equal, call_ldc);
 395 
 396   // resolved class - need to call vm to get java mirror of the class
 397   __ cmpl(rdx, JVM_CONSTANT_Class);
 398   __ jcc(Assembler::notEqual, notClass);
 399 
 400   __ bind(call_ldc);
 401 
 402   __ movl(rarg, is_ldc_wide(type) ? 1 : 0);
 403   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::ldc), rarg);
 404 
 405   __ push(atos);
 406   __ jmp(Done);
 407 
 408   __ bind(notClass);
 409   __ cmpl(rdx, JVM_CONSTANT_Float);
 410   __ jccb(Assembler::notEqual, notFloat);
 411 
 412   // ftos
 413   __ load_float(Address(rcx, rbx, Address::times_ptr, base_offset));
 414   __ push(ftos);
 415   __ jmp(Done);
 416 
 417   __ bind(notFloat);
 418   __ cmpl(rdx, JVM_CONSTANT_Integer);
 419   __ jccb(Assembler::notEqual, notInt);
 420 
 421   // itos
 422   __ movl(rax, Address(rcx, rbx, Address::times_ptr, base_offset));
 423   __ push(itos);
 424   __ jmp(Done);
 425 
 426   // assume the tag is for condy; if not, the VM runtime will tell us
 427   __ bind(notInt);
 428   condy_helper(Done);
 429 
 430   __ bind(Done);
 431 }
 432 
 433 // Fast path for caching oop constants.
 434 void TemplateTable::fast_aldc(LdcType type) {
 435   transition(vtos, atos);
 436 
 437   Register result = rax;
 438   Register tmp = rdx;
 439   Register rarg = NOT_LP64(rcx) LP64_ONLY(c_rarg1);
 440   int index_size = is_ldc_wide(type) ? sizeof(u2) : sizeof(u1);
 441 
 442   Label resolved;
 443 
 444   // We are resolved if the resolved reference cache entry contains a
 445   // non-null object (String, MethodType, etc.)
 446   assert_different_registers(result, tmp);
 447   __ get_cache_index_at_bcp(tmp, 1, index_size);
 448   __ load_resolved_reference_at_index(result, tmp);
 449   __ testptr(result, result);
 450   __ jcc(Assembler::notZero, resolved);
 451 
 452   address entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_ldc);
 453 
 454   // first time invocation - must resolve first
 455   __ movl(rarg, (int)bytecode());
 456   __ call_VM(result, entry, rarg);
 457   __ bind(resolved);
 458 
 459   { // Check for the null sentinel.
 460     // If we just called the VM, it already did the mapping for us,
 461     // but it's harmless to retry.
 462     Label notNull;
 463     ExternalAddress null_sentinel((address)Universe::the_null_sentinel_addr());
 464     __ movptr(tmp, null_sentinel);
 465     __ resolve_oop_handle(tmp, rscratch2);
 466     __ cmpoop(tmp, result);
 467     __ jccb(Assembler::notEqual, notNull);
 468     __ xorptr(result, result);  // null object reference
 469     __ bind(notNull);
 470   }
 471 
 472   if (VerifyOops) {
 473     __ verify_oop(result);
 474   }
 475 }
 476 
 477 void TemplateTable::ldc2_w() {
 478   transition(vtos, vtos);
 479   Label notDouble, notLong, Done;
 480   __ get_unsigned_2_byte_index_at_bcp(rbx, 1);
 481 
 482   __ get_cpool_and_tags(rcx, rax);
 483   const int base_offset = ConstantPool::header_size() * wordSize;
 484   const int tags_offset = Array<u1>::base_offset_in_bytes();
 485 
 486   // get type
 487   __ movzbl(rdx, Address(rax, rbx, Address::times_1, tags_offset));
 488   __ cmpl(rdx, JVM_CONSTANT_Double);
 489   __ jccb(Assembler::notEqual, notDouble);
 490 
 491   // dtos
 492   __ load_double(Address(rcx, rbx, Address::times_ptr, base_offset));
 493   __ push(dtos);
 494 
 495   __ jmp(Done);
 496   __ bind(notDouble);
 497   __ cmpl(rdx, JVM_CONSTANT_Long);
 498   __ jccb(Assembler::notEqual, notLong);
 499 
 500   // ltos
 501   __ movptr(rax, Address(rcx, rbx, Address::times_ptr, base_offset + 0 * wordSize));
 502   NOT_LP64(__ movptr(rdx, Address(rcx, rbx, Address::times_ptr, base_offset + 1 * wordSize)));
 503   __ push(ltos);
 504   __ jmp(Done);
 505 
 506   __ bind(notLong);
 507   condy_helper(Done);
 508 
 509   __ bind(Done);
 510 }
 511 
 512 void TemplateTable::condy_helper(Label& Done) {
 513   const Register obj = rax;
 514   const Register off = rbx;
 515   const Register flags = rcx;
 516   const Register rarg = NOT_LP64(rcx) LP64_ONLY(c_rarg1);
 517   __ movl(rarg, (int)bytecode());
 518   call_VM(obj, CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_ldc), rarg);
 519 #ifndef _LP64
 520   // borrow rdi from locals
 521   __ get_thread(rdi);
 522   __ get_vm_result_2(flags, rdi);
 523   __ restore_locals();
 524 #else
 525   __ get_vm_result_2(flags, r15_thread);
 526 #endif
 527   // VMr = obj = base address to find primitive value to push
 528   // VMr2 = flags = (tos, off) using format of CPCE::_flags
 529   __ movl(off, flags);
 530   __ andl(off, ConstantPoolCache::field_index_mask);
 531   const Address field(obj, off, Address::times_1, 0*wordSize);
 532 
 533   // What sort of thing are we loading?
 534   __ shrl(flags, ConstantPoolCache::tos_state_shift);
 535   __ andl(flags, ConstantPoolCache::tos_state_mask);
 536 
 537   switch (bytecode()) {
 538   case Bytecodes::_ldc:
 539   case Bytecodes::_ldc_w:
 540     {
 541       // tos in (itos, ftos, stos, btos, ctos, ztos)
 542       Label notInt, notFloat, notShort, notByte, notChar, notBool;
 543       __ cmpl(flags, itos);
 544       __ jccb(Assembler::notEqual, notInt);
 545       // itos
 546       __ movl(rax, field);
 547       __ push(itos);
 548       __ jmp(Done);
 549 
 550       __ bind(notInt);
 551       __ cmpl(flags, ftos);
 552       __ jccb(Assembler::notEqual, notFloat);
 553       // ftos
 554       __ load_float(field);
 555       __ push(ftos);
 556       __ jmp(Done);
 557 
 558       __ bind(notFloat);
 559       __ cmpl(flags, stos);
 560       __ jccb(Assembler::notEqual, notShort);
 561       // stos
 562       __ load_signed_short(rax, field);
 563       __ push(stos);
 564       __ jmp(Done);
 565 
 566       __ bind(notShort);
 567       __ cmpl(flags, btos);
 568       __ jccb(Assembler::notEqual, notByte);
 569       // btos
 570       __ load_signed_byte(rax, field);
 571       __ push(btos);
 572       __ jmp(Done);
 573 
 574       __ bind(notByte);
 575       __ cmpl(flags, ctos);
 576       __ jccb(Assembler::notEqual, notChar);
 577       // ctos
 578       __ load_unsigned_short(rax, field);
 579       __ push(ctos);
 580       __ jmp(Done);
 581 
 582       __ bind(notChar);
 583       __ cmpl(flags, ztos);
 584       __ jccb(Assembler::notEqual, notBool);
 585       // ztos
 586       __ load_signed_byte(rax, field);
 587       __ push(ztos);
 588       __ jmp(Done);
 589 
 590       __ bind(notBool);
 591       break;
 592     }
 593 
 594   case Bytecodes::_ldc2_w:
 595     {
 596       Label notLong, notDouble;
 597       __ cmpl(flags, ltos);
 598       __ jccb(Assembler::notEqual, notLong);
 599       // ltos
 600       // Loading high word first because movptr clobbers rax
 601       NOT_LP64(__ movptr(rdx, field.plus_disp(4)));
 602       __ movptr(rax, field);
 603       __ push(ltos);
 604       __ jmp(Done);
 605 
 606       __ bind(notLong);
 607       __ cmpl(flags, dtos);
 608       __ jccb(Assembler::notEqual, notDouble);
 609       // dtos
 610       __ load_double(field);
 611       __ push(dtos);
 612       __ jmp(Done);
 613 
 614       __ bind(notDouble);
 615       break;
 616     }
 617 
 618   default:
 619     ShouldNotReachHere();
 620   }
 621 
 622   __ stop("bad ldc/condy");
 623 }
 624 
 625 void TemplateTable::locals_index(Register reg, int offset) {
 626   __ load_unsigned_byte(reg, at_bcp(offset));
 627   __ negptr(reg);
 628 }
 629 
 630 void TemplateTable::iload() {
 631   iload_internal();
 632 }
 633 
 634 void TemplateTable::nofast_iload() {
 635   iload_internal(may_not_rewrite);
 636 }
 637 
 638 void TemplateTable::iload_internal(RewriteControl rc) {
 639   transition(vtos, itos);
 640   if (RewriteFrequentPairs && rc == may_rewrite) {
 641     Label rewrite, done;
 642     const Register bc = LP64_ONLY(c_rarg3) NOT_LP64(rcx);
 643     LP64_ONLY(assert(rbx != bc, "register damaged"));
 644 
 645     // get next byte
 646     __ load_unsigned_byte(rbx,
 647                           at_bcp(Bytecodes::length_for(Bytecodes::_iload)));
 648     // if _iload, wait to rewrite to iload2.  We only want to rewrite the
 649     // last two iloads in a pair.  Comparing against fast_iload means that
 650     // the next bytecode is neither an iload or a caload, and therefore
 651     // an iload pair.
 652     __ cmpl(rbx, Bytecodes::_iload);
 653     __ jcc(Assembler::equal, done);
 654 
 655     __ cmpl(rbx, Bytecodes::_fast_iload);
 656     __ movl(bc, Bytecodes::_fast_iload2);
 657 
 658     __ jccb(Assembler::equal, rewrite);
 659 
 660     // if _caload, rewrite to fast_icaload
 661     __ cmpl(rbx, Bytecodes::_caload);
 662     __ movl(bc, Bytecodes::_fast_icaload);
 663     __ jccb(Assembler::equal, rewrite);
 664 
 665     // rewrite so iload doesn't check again.
 666     __ movl(bc, Bytecodes::_fast_iload);
 667 
 668     // rewrite
 669     // bc: fast bytecode
 670     __ bind(rewrite);
 671     patch_bytecode(Bytecodes::_iload, bc, rbx, false);
 672     __ bind(done);
 673   }
 674 
 675   // Get the local value into tos
 676   locals_index(rbx);
 677   __ movl(rax, iaddress(rbx));
 678 }
 679 
 680 void TemplateTable::fast_iload2() {
 681   transition(vtos, itos);
 682   locals_index(rbx);
 683   __ movl(rax, iaddress(rbx));
 684   __ push(itos);
 685   locals_index(rbx, 3);
 686   __ movl(rax, iaddress(rbx));
 687 }
 688 
 689 void TemplateTable::fast_iload() {
 690   transition(vtos, itos);
 691   locals_index(rbx);
 692   __ movl(rax, iaddress(rbx));
 693 }
 694 
 695 void TemplateTable::lload() {
 696   transition(vtos, ltos);
 697   locals_index(rbx);
 698   __ movptr(rax, laddress(rbx));
 699   NOT_LP64(__ movl(rdx, haddress(rbx)));
 700 }
 701 
 702 void TemplateTable::fload() {
 703   transition(vtos, ftos);
 704   locals_index(rbx);
 705   __ load_float(faddress(rbx));
 706 }
 707 
 708 void TemplateTable::dload() {
 709   transition(vtos, dtos);
 710   locals_index(rbx);
 711   __ load_double(daddress(rbx));
 712 }
 713 
 714 void TemplateTable::aload() {
 715   transition(vtos, atos);
 716   locals_index(rbx);
 717   __ movptr(rax, aaddress(rbx));
 718 }
 719 
 720 void TemplateTable::locals_index_wide(Register reg) {
 721   __ load_unsigned_short(reg, at_bcp(2));
 722   __ bswapl(reg);
 723   __ shrl(reg, 16);
 724   __ negptr(reg);
 725 }
 726 
 727 void TemplateTable::wide_iload() {
 728   transition(vtos, itos);
 729   locals_index_wide(rbx);
 730   __ movl(rax, iaddress(rbx));
 731 }
 732 
 733 void TemplateTable::wide_lload() {
 734   transition(vtos, ltos);
 735   locals_index_wide(rbx);
 736   __ movptr(rax, laddress(rbx));
 737   NOT_LP64(__ movl(rdx, haddress(rbx)));
 738 }
 739 
 740 void TemplateTable::wide_fload() {
 741   transition(vtos, ftos);
 742   locals_index_wide(rbx);
 743   __ load_float(faddress(rbx));
 744 }
 745 
 746 void TemplateTable::wide_dload() {
 747   transition(vtos, dtos);
 748   locals_index_wide(rbx);
 749   __ load_double(daddress(rbx));
 750 }
 751 
 752 void TemplateTable::wide_aload() {
 753   transition(vtos, atos);
 754   locals_index_wide(rbx);
 755   __ movptr(rax, aaddress(rbx));
 756 }
 757 
 758 void TemplateTable::index_check(Register array, Register index) {
 759   // Pop ptr into array
 760   __ pop_ptr(array);
 761   index_check_without_pop(array, index);
 762 }
 763 
 764 void TemplateTable::index_check_without_pop(Register array, Register index) {
 765   // destroys rbx
 766   // sign extend index for use by indexed load
 767   __ movl2ptr(index, index);
 768   // check index
 769   __ cmpl(index, Address(array, arrayOopDesc::length_offset_in_bytes()));
 770   if (index != rbx) {
 771     // ??? convention: move aberrant index into rbx for exception message
 772     assert(rbx != array, "different registers");
 773     __ movl(rbx, index);
 774   }
 775   Label skip;
 776   __ jccb(Assembler::below, skip);
 777   // Pass array to create more detailed exceptions.
 778   __ mov(NOT_LP64(rax) LP64_ONLY(c_rarg1), array);
 779   __ jump(ExternalAddress(Interpreter::_throw_ArrayIndexOutOfBoundsException_entry));
 780   __ bind(skip);
 781 }
 782 
 783 void TemplateTable::iaload() {
 784   transition(itos, itos);
 785   // rax: index
 786   // rdx: array
 787   index_check(rdx, rax); // kills rbx
 788   __ access_load_at(T_INT, IN_HEAP | IS_ARRAY, rax,
 789                     Address(rdx, rax, Address::times_4,
 790                             arrayOopDesc::base_offset_in_bytes(T_INT)),
 791                     noreg, noreg);
 792 }
 793 
 794 void TemplateTable::laload() {
 795   transition(itos, ltos);
 796   // rax: index
 797   // rdx: array
 798   index_check(rdx, rax); // kills rbx
 799   NOT_LP64(__ mov(rbx, rax));
 800   // rbx,: index
 801   __ access_load_at(T_LONG, IN_HEAP | IS_ARRAY, noreg /* ltos */,
 802                     Address(rdx, rbx, Address::times_8,
 803                             arrayOopDesc::base_offset_in_bytes(T_LONG)),
 804                     noreg, noreg);
 805 }
 806 
 807 
 808 
 809 void TemplateTable::faload() {
 810   transition(itos, ftos);
 811   // rax: index
 812   // rdx: array
 813   index_check(rdx, rax); // kills rbx
 814   __ access_load_at(T_FLOAT, IN_HEAP | IS_ARRAY, noreg /* ftos */,
 815                     Address(rdx, rax,
 816                             Address::times_4,
 817                             arrayOopDesc::base_offset_in_bytes(T_FLOAT)),
 818                     noreg, noreg);
 819 }
 820 
 821 void TemplateTable::daload() {
 822   transition(itos, dtos);
 823   // rax: index
 824   // rdx: array
 825   index_check(rdx, rax); // kills rbx
 826   __ access_load_at(T_DOUBLE, IN_HEAP | IS_ARRAY, noreg /* dtos */,
 827                     Address(rdx, rax,
 828                             Address::times_8,
 829                             arrayOopDesc::base_offset_in_bytes(T_DOUBLE)),
 830                     noreg, noreg);
 831 }
 832 
 833 void TemplateTable::aaload() {
 834   transition(itos, atos);
 835   Register array = rdx;
 836   Register index = rax;
 837 
 838   index_check(array, index); // kills rbx
 839   __ profile_array_type<ArrayLoadData>(rbx, array, rcx);
 840   if (UseFlatArray) {
 841     Label is_flat_array, done;
 842     __ test_flat_array_oop(array, rbx, is_flat_array);
 843     do_oop_load(_masm,
 844                 Address(array, index,
 845                         UseCompressedOops ? Address::times_4 : Address::times_ptr,
 846                         arrayOopDesc::base_offset_in_bytes(T_OBJECT)),
 847                 rax,
 848                 IS_ARRAY);
 849     __ jmp(done);
 850     __ bind(is_flat_array);
 851     __ read_flat_element(array, index, rbx, rcx, rax);
 852     __ bind(done);
 853   } else {
 854     do_oop_load(_masm,
 855                 Address(array, index,
 856                         UseCompressedOops ? Address::times_4 : Address::times_ptr,
 857                         arrayOopDesc::base_offset_in_bytes(T_OBJECT)),
 858                 rax,
 859                 IS_ARRAY);
 860   }
 861   __ profile_element_type(rbx, rax, rcx);
 862 }
 863 
 864 void TemplateTable::baload() {
 865   transition(itos, itos);
 866   // rax: index
 867   // rdx: array
 868   index_check(rdx, rax); // kills rbx
 869   __ access_load_at(T_BYTE, IN_HEAP | IS_ARRAY, rax,
 870                     Address(rdx, rax, Address::times_1, arrayOopDesc::base_offset_in_bytes(T_BYTE)),
 871                     noreg, noreg);
 872 }
 873 
 874 void TemplateTable::caload() {
 875   transition(itos, itos);
 876   // rax: index
 877   // rdx: array
 878   index_check(rdx, rax); // kills rbx
 879   __ access_load_at(T_CHAR, IN_HEAP | IS_ARRAY, rax,
 880                     Address(rdx, rax, Address::times_2, arrayOopDesc::base_offset_in_bytes(T_CHAR)),
 881                     noreg, noreg);
 882 }
 883 
 884 // iload followed by caload frequent pair
 885 void TemplateTable::fast_icaload() {
 886   transition(vtos, itos);
 887   // load index out of locals
 888   locals_index(rbx);
 889   __ movl(rax, iaddress(rbx));
 890 
 891   // rax: index
 892   // rdx: array
 893   index_check(rdx, rax); // kills rbx
 894   __ access_load_at(T_CHAR, IN_HEAP | IS_ARRAY, rax,
 895                     Address(rdx, rax, Address::times_2, arrayOopDesc::base_offset_in_bytes(T_CHAR)),
 896                     noreg, noreg);
 897 }
 898 
 899 
 900 void TemplateTable::saload() {
 901   transition(itos, itos);
 902   // rax: index
 903   // rdx: array
 904   index_check(rdx, rax); // kills rbx
 905   __ access_load_at(T_SHORT, IN_HEAP | IS_ARRAY, rax,
 906                     Address(rdx, rax, Address::times_2, arrayOopDesc::base_offset_in_bytes(T_SHORT)),
 907                     noreg, noreg);
 908 }
 909 
 910 void TemplateTable::iload(int n) {
 911   transition(vtos, itos);
 912   __ movl(rax, iaddress(n));
 913 }
 914 
 915 void TemplateTable::lload(int n) {
 916   transition(vtos, ltos);
 917   __ movptr(rax, laddress(n));
 918   NOT_LP64(__ movptr(rdx, haddress(n)));
 919 }
 920 
 921 void TemplateTable::fload(int n) {
 922   transition(vtos, ftos);
 923   __ load_float(faddress(n));
 924 }
 925 
 926 void TemplateTable::dload(int n) {
 927   transition(vtos, dtos);
 928   __ load_double(daddress(n));
 929 }
 930 
 931 void TemplateTable::aload(int n) {
 932   transition(vtos, atos);
 933   __ movptr(rax, aaddress(n));
 934 }
 935 
 936 void TemplateTable::aload_0() {
 937   aload_0_internal();
 938 }
 939 
 940 void TemplateTable::nofast_aload_0() {
 941   aload_0_internal(may_not_rewrite);
 942 }
 943 
 944 void TemplateTable::aload_0_internal(RewriteControl rc) {
 945   transition(vtos, atos);
 946   // According to bytecode histograms, the pairs:
 947   //
 948   // _aload_0, _fast_igetfield
 949   // _aload_0, _fast_agetfield
 950   // _aload_0, _fast_fgetfield
 951   //
 952   // occur frequently. If RewriteFrequentPairs is set, the (slow)
 953   // _aload_0 bytecode checks if the next bytecode is either
 954   // _fast_igetfield, _fast_agetfield or _fast_fgetfield and then
 955   // rewrites the current bytecode into a pair bytecode; otherwise it
 956   // rewrites the current bytecode into _fast_aload_0 that doesn't do
 957   // the pair check anymore.
 958   //
 959   // Note: If the next bytecode is _getfield, the rewrite must be
 960   //       delayed, otherwise we may miss an opportunity for a pair.
 961   //
 962   // Also rewrite frequent pairs
 963   //   aload_0, aload_1
 964   //   aload_0, iload_1
 965   // These bytecodes with a small amount of code are most profitable
 966   // to rewrite
 967   if (RewriteFrequentPairs && rc == may_rewrite) {
 968     Label rewrite, done;
 969 
 970     const Register bc = LP64_ONLY(c_rarg3) NOT_LP64(rcx);
 971     LP64_ONLY(assert(rbx != bc, "register damaged"));
 972 
 973     // get next byte
 974     __ load_unsigned_byte(rbx, at_bcp(Bytecodes::length_for(Bytecodes::_aload_0)));
 975 
 976     // if _getfield then wait with rewrite
 977     __ cmpl(rbx, Bytecodes::_getfield);
 978     __ jcc(Assembler::equal, done);
 979 
 980     // if _igetfield then rewrite to _fast_iaccess_0
 981     assert(Bytecodes::java_code(Bytecodes::_fast_iaccess_0) == Bytecodes::_aload_0, "fix bytecode definition");
 982     __ cmpl(rbx, Bytecodes::_fast_igetfield);
 983     __ movl(bc, Bytecodes::_fast_iaccess_0);
 984     __ jccb(Assembler::equal, rewrite);
 985 
 986     // if _agetfield then rewrite to _fast_aaccess_0
 987     assert(Bytecodes::java_code(Bytecodes::_fast_aaccess_0) == Bytecodes::_aload_0, "fix bytecode definition");
 988     __ cmpl(rbx, Bytecodes::_fast_agetfield);
 989     __ movl(bc, Bytecodes::_fast_aaccess_0);
 990     __ jccb(Assembler::equal, rewrite);
 991 
 992     // if _fgetfield then rewrite to _fast_faccess_0
 993     assert(Bytecodes::java_code(Bytecodes::_fast_faccess_0) == Bytecodes::_aload_0, "fix bytecode definition");
 994     __ cmpl(rbx, Bytecodes::_fast_fgetfield);
 995     __ movl(bc, Bytecodes::_fast_faccess_0);
 996     __ jccb(Assembler::equal, rewrite);
 997 
 998     // else rewrite to _fast_aload0
 999     assert(Bytecodes::java_code(Bytecodes::_fast_aload_0) == Bytecodes::_aload_0, "fix bytecode definition");
1000     __ movl(bc, Bytecodes::_fast_aload_0);
1001 
1002     // rewrite
1003     // bc: fast bytecode
1004     __ bind(rewrite);
1005     patch_bytecode(Bytecodes::_aload_0, bc, rbx, false);
1006 
1007     __ bind(done);
1008   }
1009 
1010   // Do actual aload_0 (must do this after patch_bytecode which might call VM and GC might change oop).
1011   aload(0);
1012 }
1013 
1014 void TemplateTable::istore() {
1015   transition(itos, vtos);
1016   locals_index(rbx);
1017   __ movl(iaddress(rbx), rax);
1018 }
1019 
1020 
1021 void TemplateTable::lstore() {
1022   transition(ltos, vtos);
1023   locals_index(rbx);
1024   __ movptr(laddress(rbx), rax);
1025   NOT_LP64(__ movptr(haddress(rbx), rdx));
1026 }
1027 
1028 void TemplateTable::fstore() {
1029   transition(ftos, vtos);
1030   locals_index(rbx);
1031   __ store_float(faddress(rbx));
1032 }
1033 
1034 void TemplateTable::dstore() {
1035   transition(dtos, vtos);
1036   locals_index(rbx);
1037   __ store_double(daddress(rbx));
1038 }
1039 
1040 void TemplateTable::astore() {
1041   transition(vtos, vtos);
1042   __ pop_ptr(rax);
1043   locals_index(rbx);
1044   __ movptr(aaddress(rbx), rax);
1045 }
1046 
1047 void TemplateTable::wide_istore() {
1048   transition(vtos, vtos);
1049   __ pop_i();
1050   locals_index_wide(rbx);
1051   __ movl(iaddress(rbx), rax);
1052 }
1053 
1054 void TemplateTable::wide_lstore() {
1055   transition(vtos, vtos);
1056   NOT_LP64(__ pop_l(rax, rdx));
1057   LP64_ONLY(__ pop_l());
1058   locals_index_wide(rbx);
1059   __ movptr(laddress(rbx), rax);
1060   NOT_LP64(__ movl(haddress(rbx), rdx));
1061 }
1062 
1063 void TemplateTable::wide_fstore() {
1064 #ifdef _LP64
1065   transition(vtos, vtos);
1066   __ pop_f(xmm0);
1067   locals_index_wide(rbx);
1068   __ movflt(faddress(rbx), xmm0);
1069 #else
1070   wide_istore();
1071 #endif
1072 }
1073 
1074 void TemplateTable::wide_dstore() {
1075 #ifdef _LP64
1076   transition(vtos, vtos);
1077   __ pop_d(xmm0);
1078   locals_index_wide(rbx);
1079   __ movdbl(daddress(rbx), xmm0);
1080 #else
1081   wide_lstore();
1082 #endif
1083 }
1084 
1085 void TemplateTable::wide_astore() {
1086   transition(vtos, vtos);
1087   __ pop_ptr(rax);
1088   locals_index_wide(rbx);
1089   __ movptr(aaddress(rbx), rax);
1090 }
1091 
1092 void TemplateTable::iastore() {
1093   transition(itos, vtos);
1094   __ pop_i(rbx);
1095   // rax: value
1096   // rbx: index
1097   // rdx: array
1098   index_check(rdx, rbx); // prefer index in rbx
1099   __ access_store_at(T_INT, IN_HEAP | IS_ARRAY,
1100                      Address(rdx, rbx, Address::times_4,
1101                              arrayOopDesc::base_offset_in_bytes(T_INT)),
1102                      rax, noreg, noreg, noreg);
1103 }
1104 
1105 void TemplateTable::lastore() {
1106   transition(ltos, vtos);
1107   __ pop_i(rbx);
1108   // rax,: low(value)
1109   // rcx: array
1110   // rdx: high(value)
1111   index_check(rcx, rbx);  // prefer index in rbx,
1112   // rbx,: index
1113   __ access_store_at(T_LONG, IN_HEAP | IS_ARRAY,
1114                      Address(rcx, rbx, Address::times_8,
1115                              arrayOopDesc::base_offset_in_bytes(T_LONG)),
1116                      noreg /* ltos */, noreg, noreg, noreg);
1117 }
1118 
1119 
1120 void TemplateTable::fastore() {
1121   transition(ftos, vtos);
1122   __ pop_i(rbx);
1123   // value is in UseSSE >= 1 ? xmm0 : ST(0)
1124   // rbx:  index
1125   // rdx:  array
1126   index_check(rdx, rbx); // prefer index in rbx
1127   __ access_store_at(T_FLOAT, IN_HEAP | IS_ARRAY,
1128                      Address(rdx, rbx, Address::times_4,
1129                              arrayOopDesc::base_offset_in_bytes(T_FLOAT)),
1130                      noreg /* ftos */, noreg, noreg, noreg);
1131 }
1132 
1133 void TemplateTable::dastore() {
1134   transition(dtos, vtos);
1135   __ pop_i(rbx);
1136   // value is in UseSSE >= 2 ? xmm0 : ST(0)
1137   // rbx:  index
1138   // rdx:  array
1139   index_check(rdx, rbx); // prefer index in rbx
1140   __ access_store_at(T_DOUBLE, IN_HEAP | IS_ARRAY,
1141                      Address(rdx, rbx, Address::times_8,
1142                              arrayOopDesc::base_offset_in_bytes(T_DOUBLE)),
1143                      noreg /* dtos */, noreg, noreg, noreg);
1144 }
1145 
1146 void TemplateTable::aastore() {
1147   Label is_null, is_flat_array, ok_is_subtype, done;
1148   transition(vtos, vtos);
1149   // stack: ..., array, index, value
1150   __ movptr(rax, at_tos());    // value
1151   __ movl(rcx, at_tos_p1()); // index
1152   __ movptr(rdx, at_tos_p2()); // array
1153 
1154   Address element_address(rdx, rcx,
1155                           UseCompressedOops? Address::times_4 : Address::times_ptr,
1156                           arrayOopDesc::base_offset_in_bytes(T_OBJECT));
1157 
1158   index_check_without_pop(rdx, rcx);     // kills rbx
1159 
1160   __ profile_array_type<ArrayStoreData>(rdi, rdx, rbx);
1161   __ profile_multiple_element_types(rdi, rax, rbx, rcx);
1162 
1163   __ testptr(rax, rax);
1164   __ jcc(Assembler::zero, is_null);
1165 
1166   // Move array class to rdi
1167   __ load_klass(rdi, rdx, rscratch1);
1168   if (UseFlatArray) {
1169     __ movl(rbx, Address(rdi, Klass::layout_helper_offset()));
1170     __ test_flat_array_layout(rbx, is_flat_array);
1171   }
1172 
1173   // Move subklass into rbx
1174   __ load_klass(rbx, rax, rscratch1);
1175   // Move array element superklass into rax
1176   __ movptr(rax, Address(rdi,
1177                          ObjArrayKlass::element_klass_offset()));
1178 
1179   // Generate subtype check.  Blows rcx, rdi
1180   // Superklass in rax.  Subklass in rbx.
1181   // is "rbx <: rax" ? (value subclass <: array element superclass)
1182   __ gen_subtype_check(rbx, ok_is_subtype, false);
1183 
1184   // Come here on failure
1185   // object is at TOS
1186   __ jump(ExternalAddress(Interpreter::_throw_ArrayStoreException_entry));
1187 
1188   // Come here on success
1189   __ bind(ok_is_subtype);
1190 
1191   // Get the value we will store
1192   __ movptr(rax, at_tos());
1193   __ movl(rcx, at_tos_p1()); // index
1194   // Now store using the appropriate barrier
1195   do_oop_store(_masm, element_address, rax, IS_ARRAY);
1196   __ jmp(done);
1197 
1198   // Have a null in rax, rdx=array, ecx=index.  Store null at ary[idx]
1199   __ bind(is_null);
1200   if (EnableValhalla) {
1201     Label is_null_into_value_array_npe, store_null;
1202 
1203     // No way to store null in null-free array
1204     __ test_null_free_array_oop(rdx, rbx, is_null_into_value_array_npe);
1205     __ jmp(store_null);
1206 
1207     __ bind(is_null_into_value_array_npe);
1208     __ jump(ExternalAddress(Interpreter::_throw_NullPointerException_entry));
1209 
1210     __ bind(store_null);
1211   }
1212   // Store a null
1213   do_oop_store(_masm, element_address, noreg, IS_ARRAY);
1214   __ jmp(done);
1215 
1216   if (UseFlatArray) {
1217     Label is_type_ok;
1218     __ bind(is_flat_array); // Store non-null value to flat
1219 
1220     // Simplistic type check...
1221 
1222     // Profile the not-null value's klass.
1223     __ load_klass(rbx, rax, rscratch1);
1224     // Move element klass into rax
1225     __ movptr(rax, Address(rdi, ArrayKlass::element_klass_offset()));
1226     // flat value array needs exact type match
1227     // is "rax == rbx" (value subclass == array element superclass)
1228     __ cmpptr(rax, rbx);
1229     __ jccb(Assembler::equal, is_type_ok);
1230 
1231     __ jump(ExternalAddress(Interpreter::_throw_ArrayStoreException_entry));
1232 
1233     __ bind(is_type_ok);
1234     // rbx: value's klass
1235     // rdx: array
1236     // rdi: array klass
1237     __ test_klass_is_empty_inline_type(rbx, rax, done);
1238 
1239     // calc dst for copy
1240     __ movl(rax, at_tos_p1()); // index
1241     __ data_for_value_array_index(rdx, rdi, rax, rax);
1242 
1243     // ...and src for copy
1244     __ movptr(rcx, at_tos());  // value
1245     __ data_for_oop(rcx, rcx, rbx);
1246 
1247     __ access_value_copy(IN_HEAP, rcx, rax, rbx);
1248   }
1249   // Pop stack arguments
1250   __ bind(done);
1251   __ addptr(rsp, 3 * Interpreter::stackElementSize);
1252 }
1253 
1254 void TemplateTable::bastore() {
1255   transition(itos, vtos);
1256   __ pop_i(rbx);
1257   // rax: value
1258   // rbx: index
1259   // rdx: array
1260   index_check(rdx, rbx); // prefer index in rbx
1261   // Need to check whether array is boolean or byte
1262   // since both types share the bastore bytecode.
1263   __ load_klass(rcx, rdx, rscratch1);
1264   __ movl(rcx, Address(rcx, Klass::layout_helper_offset()));
1265   int diffbit = Klass::layout_helper_boolean_diffbit();
1266   __ testl(rcx, diffbit);
1267   Label L_skip;
1268   __ jccb(Assembler::zero, L_skip);
1269   __ andl(rax, 1);  // if it is a T_BOOLEAN array, mask the stored value to 0/1
1270   __ bind(L_skip);
1271   __ access_store_at(T_BYTE, IN_HEAP | IS_ARRAY,
1272                      Address(rdx, rbx,Address::times_1,
1273                              arrayOopDesc::base_offset_in_bytes(T_BYTE)),
1274                      rax, noreg, noreg, noreg);
1275 }
1276 
1277 void TemplateTable::castore() {
1278   transition(itos, vtos);
1279   __ pop_i(rbx);
1280   // rax: value
1281   // rbx: index
1282   // rdx: array
1283   index_check(rdx, rbx);  // prefer index in rbx
1284   __ access_store_at(T_CHAR, IN_HEAP | IS_ARRAY,
1285                      Address(rdx, rbx, Address::times_2,
1286                              arrayOopDesc::base_offset_in_bytes(T_CHAR)),
1287                      rax, noreg, noreg, noreg);
1288 }
1289 
1290 
1291 void TemplateTable::sastore() {
1292   castore();
1293 }
1294 
1295 void TemplateTable::istore(int n) {
1296   transition(itos, vtos);
1297   __ movl(iaddress(n), rax);
1298 }
1299 
1300 void TemplateTable::lstore(int n) {
1301   transition(ltos, vtos);
1302   __ movptr(laddress(n), rax);
1303   NOT_LP64(__ movptr(haddress(n), rdx));
1304 }
1305 
1306 void TemplateTable::fstore(int n) {
1307   transition(ftos, vtos);
1308   __ store_float(faddress(n));
1309 }
1310 
1311 void TemplateTable::dstore(int n) {
1312   transition(dtos, vtos);
1313   __ store_double(daddress(n));
1314 }
1315 
1316 
1317 void TemplateTable::astore(int n) {
1318   transition(vtos, vtos);
1319   __ pop_ptr(rax);
1320   __ movptr(aaddress(n), rax);
1321 }
1322 
1323 void TemplateTable::pop() {
1324   transition(vtos, vtos);
1325   __ addptr(rsp, Interpreter::stackElementSize);
1326 }
1327 
1328 void TemplateTable::pop2() {
1329   transition(vtos, vtos);
1330   __ addptr(rsp, 2 * Interpreter::stackElementSize);
1331 }
1332 
1333 
1334 void TemplateTable::dup() {
1335   transition(vtos, vtos);
1336   __ load_ptr(0, rax);
1337   __ push_ptr(rax);
1338   // stack: ..., a, a
1339 }
1340 
1341 void TemplateTable::dup_x1() {
1342   transition(vtos, vtos);
1343   // stack: ..., a, b
1344   __ load_ptr( 0, rax);  // load b
1345   __ load_ptr( 1, rcx);  // load a
1346   __ store_ptr(1, rax);  // store b
1347   __ store_ptr(0, rcx);  // store a
1348   __ push_ptr(rax);      // push b
1349   // stack: ..., b, a, b
1350 }
1351 
1352 void TemplateTable::dup_x2() {
1353   transition(vtos, vtos);
1354   // stack: ..., a, b, c
1355   __ load_ptr( 0, rax);  // load c
1356   __ load_ptr( 2, rcx);  // load a
1357   __ store_ptr(2, rax);  // store c in a
1358   __ push_ptr(rax);      // push c
1359   // stack: ..., c, b, c, c
1360   __ load_ptr( 2, rax);  // load b
1361   __ store_ptr(2, rcx);  // store a in b
1362   // stack: ..., c, a, c, c
1363   __ store_ptr(1, rax);  // store b in c
1364   // stack: ..., c, a, b, c
1365 }
1366 
1367 void TemplateTable::dup2() {
1368   transition(vtos, vtos);
1369   // stack: ..., a, b
1370   __ load_ptr(1, rax);  // load a
1371   __ push_ptr(rax);     // push a
1372   __ load_ptr(1, rax);  // load b
1373   __ push_ptr(rax);     // push b
1374   // stack: ..., a, b, a, b
1375 }
1376 
1377 
1378 void TemplateTable::dup2_x1() {
1379   transition(vtos, vtos);
1380   // stack: ..., a, b, c
1381   __ load_ptr( 0, rcx);  // load c
1382   __ load_ptr( 1, rax);  // load b
1383   __ push_ptr(rax);      // push b
1384   __ push_ptr(rcx);      // push c
1385   // stack: ..., a, b, c, b, c
1386   __ store_ptr(3, rcx);  // store c in b
1387   // stack: ..., a, c, c, b, c
1388   __ load_ptr( 4, rcx);  // load a
1389   __ store_ptr(2, rcx);  // store a in 2nd c
1390   // stack: ..., a, c, a, b, c
1391   __ store_ptr(4, rax);  // store b in a
1392   // stack: ..., b, c, a, b, c
1393 }
1394 
1395 void TemplateTable::dup2_x2() {
1396   transition(vtos, vtos);
1397   // stack: ..., a, b, c, d
1398   __ load_ptr( 0, rcx);  // load d
1399   __ load_ptr( 1, rax);  // load c
1400   __ push_ptr(rax);      // push c
1401   __ push_ptr(rcx);      // push d
1402   // stack: ..., a, b, c, d, c, d
1403   __ load_ptr( 4, rax);  // load b
1404   __ store_ptr(2, rax);  // store b in d
1405   __ store_ptr(4, rcx);  // store d in b
1406   // stack: ..., a, d, c, b, c, d
1407   __ load_ptr( 5, rcx);  // load a
1408   __ load_ptr( 3, rax);  // load c
1409   __ store_ptr(3, rcx);  // store a in c
1410   __ store_ptr(5, rax);  // store c in a
1411   // stack: ..., c, d, a, b, c, d
1412 }
1413 
1414 void TemplateTable::swap() {
1415   transition(vtos, vtos);
1416   // stack: ..., a, b
1417   __ load_ptr( 1, rcx);  // load a
1418   __ load_ptr( 0, rax);  // load b
1419   __ store_ptr(0, rcx);  // store a in b
1420   __ store_ptr(1, rax);  // store b in a
1421   // stack: ..., b, a
1422 }
1423 
1424 void TemplateTable::iop2(Operation op) {
1425   transition(itos, itos);
1426   switch (op) {
1427   case add  :                    __ pop_i(rdx); __ addl (rax, rdx); break;
1428   case sub  : __ movl(rdx, rax); __ pop_i(rax); __ subl (rax, rdx); break;
1429   case mul  :                    __ pop_i(rdx); __ imull(rax, rdx); break;
1430   case _and :                    __ pop_i(rdx); __ andl (rax, rdx); break;
1431   case _or  :                    __ pop_i(rdx); __ orl  (rax, rdx); break;
1432   case _xor :                    __ pop_i(rdx); __ xorl (rax, rdx); break;
1433   case shl  : __ movl(rcx, rax); __ pop_i(rax); __ shll (rax);      break;
1434   case shr  : __ movl(rcx, rax); __ pop_i(rax); __ sarl (rax);      break;
1435   case ushr : __ movl(rcx, rax); __ pop_i(rax); __ shrl (rax);      break;
1436   default   : ShouldNotReachHere();
1437   }
1438 }
1439 
1440 void TemplateTable::lop2(Operation op) {
1441   transition(ltos, ltos);
1442 #ifdef _LP64
1443   switch (op) {
1444   case add  :                    __ pop_l(rdx); __ addptr(rax, rdx); break;
1445   case sub  : __ mov(rdx, rax);  __ pop_l(rax); __ subptr(rax, rdx); break;
1446   case _and :                    __ pop_l(rdx); __ andptr(rax, rdx); break;
1447   case _or  :                    __ pop_l(rdx); __ orptr (rax, rdx); break;
1448   case _xor :                    __ pop_l(rdx); __ xorptr(rax, rdx); break;
1449   default   : ShouldNotReachHere();
1450   }
1451 #else
1452   __ pop_l(rbx, rcx);
1453   switch (op) {
1454     case add  : __ addl(rax, rbx); __ adcl(rdx, rcx); break;
1455     case sub  : __ subl(rbx, rax); __ sbbl(rcx, rdx);
1456                 __ mov (rax, rbx); __ mov (rdx, rcx); break;
1457     case _and : __ andl(rax, rbx); __ andl(rdx, rcx); break;
1458     case _or  : __ orl (rax, rbx); __ orl (rdx, rcx); break;
1459     case _xor : __ xorl(rax, rbx); __ xorl(rdx, rcx); break;
1460     default   : ShouldNotReachHere();
1461   }
1462 #endif
1463 }
1464 
1465 void TemplateTable::idiv() {
1466   transition(itos, itos);
1467   __ movl(rcx, rax);
1468   __ pop_i(rax);
1469   // Note: could xor rax and ecx and compare with (-1 ^ min_int). If
1470   //       they are not equal, one could do a normal division (no correction
1471   //       needed), which may speed up this implementation for the common case.
1472   //       (see also JVM spec., p.243 & p.271)
1473   __ corrected_idivl(rcx);
1474 }
1475 
1476 void TemplateTable::irem() {
1477   transition(itos, itos);
1478   __ movl(rcx, rax);
1479   __ pop_i(rax);
1480   // Note: could xor rax and ecx and compare with (-1 ^ min_int). If
1481   //       they are not equal, one could do a normal division (no correction
1482   //       needed), which may speed up this implementation for the common case.
1483   //       (see also JVM spec., p.243 & p.271)
1484   __ corrected_idivl(rcx);
1485   __ movl(rax, rdx);
1486 }
1487 
1488 void TemplateTable::lmul() {
1489   transition(ltos, ltos);
1490 #ifdef _LP64
1491   __ pop_l(rdx);
1492   __ imulq(rax, rdx);
1493 #else
1494   __ pop_l(rbx, rcx);
1495   __ push(rcx); __ push(rbx);
1496   __ push(rdx); __ push(rax);
1497   __ lmul(2 * wordSize, 0);
1498   __ addptr(rsp, 4 * wordSize);  // take off temporaries
1499 #endif
1500 }
1501 
1502 void TemplateTable::ldiv() {
1503   transition(ltos, ltos);
1504 #ifdef _LP64
1505   __ mov(rcx, rax);
1506   __ pop_l(rax);
1507   // generate explicit div0 check
1508   __ testq(rcx, rcx);
1509   __ jump_cc(Assembler::zero,
1510              ExternalAddress(Interpreter::_throw_ArithmeticException_entry));
1511   // Note: could xor rax and rcx and compare with (-1 ^ min_int). If
1512   //       they are not equal, one could do a normal division (no correction
1513   //       needed), which may speed up this implementation for the common case.
1514   //       (see also JVM spec., p.243 & p.271)
1515   __ corrected_idivq(rcx); // kills rbx
1516 #else
1517   __ pop_l(rbx, rcx);
1518   __ push(rcx); __ push(rbx);
1519   __ push(rdx); __ push(rax);
1520   // check if y = 0
1521   __ orl(rax, rdx);
1522   __ jump_cc(Assembler::zero,
1523              ExternalAddress(Interpreter::_throw_ArithmeticException_entry));
1524   __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::ldiv));
1525   __ addptr(rsp, 4 * wordSize);  // take off temporaries
1526 #endif
1527 }
1528 
1529 void TemplateTable::lrem() {
1530   transition(ltos, ltos);
1531 #ifdef _LP64
1532   __ mov(rcx, rax);
1533   __ pop_l(rax);
1534   __ testq(rcx, rcx);
1535   __ jump_cc(Assembler::zero,
1536              ExternalAddress(Interpreter::_throw_ArithmeticException_entry));
1537   // Note: could xor rax and rcx and compare with (-1 ^ min_int). If
1538   //       they are not equal, one could do a normal division (no correction
1539   //       needed), which may speed up this implementation for the common case.
1540   //       (see also JVM spec., p.243 & p.271)
1541   __ corrected_idivq(rcx); // kills rbx
1542   __ mov(rax, rdx);
1543 #else
1544   __ pop_l(rbx, rcx);
1545   __ push(rcx); __ push(rbx);
1546   __ push(rdx); __ push(rax);
1547   // check if y = 0
1548   __ orl(rax, rdx);
1549   __ jump_cc(Assembler::zero,
1550              ExternalAddress(Interpreter::_throw_ArithmeticException_entry));
1551   __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::lrem));
1552   __ addptr(rsp, 4 * wordSize);
1553 #endif
1554 }
1555 
1556 void TemplateTable::lshl() {
1557   transition(itos, ltos);
1558   __ movl(rcx, rax);                             // get shift count
1559   #ifdef _LP64
1560   __ pop_l(rax);                                 // get shift value
1561   __ shlq(rax);
1562 #else
1563   __ pop_l(rax, rdx);                            // get shift value
1564   __ lshl(rdx, rax);
1565 #endif
1566 }
1567 
1568 void TemplateTable::lshr() {
1569 #ifdef _LP64
1570   transition(itos, ltos);
1571   __ movl(rcx, rax);                             // get shift count
1572   __ pop_l(rax);                                 // get shift value
1573   __ sarq(rax);
1574 #else
1575   transition(itos, ltos);
1576   __ mov(rcx, rax);                              // get shift count
1577   __ pop_l(rax, rdx);                            // get shift value
1578   __ lshr(rdx, rax, true);
1579 #endif
1580 }
1581 
1582 void TemplateTable::lushr() {
1583   transition(itos, ltos);
1584 #ifdef _LP64
1585   __ movl(rcx, rax);                             // get shift count
1586   __ pop_l(rax);                                 // get shift value
1587   __ shrq(rax);
1588 #else
1589   __ mov(rcx, rax);                              // get shift count
1590   __ pop_l(rax, rdx);                            // get shift value
1591   __ lshr(rdx, rax);
1592 #endif
1593 }
1594 
1595 void TemplateTable::fop2(Operation op) {
1596   transition(ftos, ftos);
1597 
1598   if (UseSSE >= 1) {
1599     switch (op) {
1600     case add:
1601       __ addss(xmm0, at_rsp());
1602       __ addptr(rsp, Interpreter::stackElementSize);
1603       break;
1604     case sub:
1605       __ movflt(xmm1, xmm0);
1606       __ pop_f(xmm0);
1607       __ subss(xmm0, xmm1);
1608       break;
1609     case mul:
1610       __ mulss(xmm0, at_rsp());
1611       __ addptr(rsp, Interpreter::stackElementSize);
1612       break;
1613     case div:
1614       __ movflt(xmm1, xmm0);
1615       __ pop_f(xmm0);
1616       __ divss(xmm0, xmm1);
1617       break;
1618     case rem:
1619       // On x86_64 platforms the SharedRuntime::frem method is called to perform the
1620       // modulo operation. The frem method calls the function
1621       // double fmod(double x, double y) in math.h. The documentation of fmod states:
1622       // "If x or y is a NaN, a NaN is returned." without specifying what type of NaN
1623       // (signalling or quiet) is returned.
1624       //
1625       // On x86_32 platforms the FPU is used to perform the modulo operation. The
1626       // reason is that on 32-bit Windows the sign of modulo operations diverges from
1627       // what is considered the standard (e.g., -0.0f % -3.14f is 0.0f (and not -0.0f).
1628       // The fprem instruction used on x86_32 is functionally equivalent to
1629       // SharedRuntime::frem in that it returns a NaN.
1630 #ifdef _LP64
1631       __ movflt(xmm1, xmm0);
1632       __ pop_f(xmm0);
1633       __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::frem), 2);
1634 #else // !_LP64
1635       __ push_f(xmm0);
1636       __ pop_f();
1637       __ fld_s(at_rsp());
1638       __ fremr(rax);
1639       __ f2ieee();
1640       __ pop(rax);  // pop second operand off the stack
1641       __ push_f();
1642       __ pop_f(xmm0);
1643 #endif // _LP64
1644       break;
1645     default:
1646       ShouldNotReachHere();
1647       break;
1648     }
1649   } else {
1650 #ifdef _LP64
1651     ShouldNotReachHere();
1652 #else // !_LP64
1653     switch (op) {
1654     case add: __ fadd_s (at_rsp());                break;
1655     case sub: __ fsubr_s(at_rsp());                break;
1656     case mul: __ fmul_s (at_rsp());                break;
1657     case div: __ fdivr_s(at_rsp());                break;
1658     case rem: __ fld_s  (at_rsp()); __ fremr(rax); break;
1659     default : ShouldNotReachHere();
1660     }
1661     __ f2ieee();
1662     __ pop(rax);  // pop second operand off the stack
1663 #endif // _LP64
1664   }
1665 }
1666 
1667 void TemplateTable::dop2(Operation op) {
1668   transition(dtos, dtos);
1669   if (UseSSE >= 2) {
1670     switch (op) {
1671     case add:
1672       __ addsd(xmm0, at_rsp());
1673       __ addptr(rsp, 2 * Interpreter::stackElementSize);
1674       break;
1675     case sub:
1676       __ movdbl(xmm1, xmm0);
1677       __ pop_d(xmm0);
1678       __ subsd(xmm0, xmm1);
1679       break;
1680     case mul:
1681       __ mulsd(xmm0, at_rsp());
1682       __ addptr(rsp, 2 * Interpreter::stackElementSize);
1683       break;
1684     case div:
1685       __ movdbl(xmm1, xmm0);
1686       __ pop_d(xmm0);
1687       __ divsd(xmm0, xmm1);
1688       break;
1689     case rem:
1690       // Similar to fop2(), the modulo operation is performed using the
1691       // SharedRuntime::drem method (on x86_64 platforms) or using the
1692       // FPU (on x86_32 platforms) for the same reasons as mentioned in fop2().
1693 #ifdef _LP64
1694       __ movdbl(xmm1, xmm0);
1695       __ pop_d(xmm0);
1696       __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::drem), 2);
1697 #else // !_LP64
1698       __ push_d(xmm0);
1699       __ pop_d();
1700       __ fld_d(at_rsp());
1701       __ fremr(rax);
1702       __ d2ieee();
1703       __ pop(rax);
1704       __ pop(rdx);
1705       __ push_d();
1706       __ pop_d(xmm0);
1707 #endif // _LP64
1708       break;
1709     default:
1710       ShouldNotReachHere();
1711       break;
1712     }
1713   } else {
1714 #ifdef _LP64
1715     ShouldNotReachHere();
1716 #else // !_LP64
1717     switch (op) {
1718     case add: __ fadd_d (at_rsp());                break;
1719     case sub: __ fsubr_d(at_rsp());                break;
1720     case mul: {
1721       // strict semantics
1722       __ fld_x(ExternalAddress(StubRoutines::x86::addr_fpu_subnormal_bias1()));
1723       __ fmulp();
1724       __ fmul_d (at_rsp());
1725       __ fld_x(ExternalAddress(StubRoutines::x86::addr_fpu_subnormal_bias2()));
1726       __ fmulp();
1727       break;
1728     }
1729     case div: {
1730       // strict semantics
1731       __ fld_x(ExternalAddress(StubRoutines::x86::addr_fpu_subnormal_bias1()));
1732       __ fmul_d (at_rsp());
1733       __ fdivrp();
1734       __ fld_x(ExternalAddress(StubRoutines::x86::addr_fpu_subnormal_bias2()));
1735       __ fmulp();
1736       break;
1737     }
1738     case rem: __ fld_d  (at_rsp()); __ fremr(rax); break;
1739     default : ShouldNotReachHere();
1740     }
1741     __ d2ieee();
1742     // Pop double precision number from rsp.
1743     __ pop(rax);
1744     __ pop(rdx);
1745 #endif // _LP64
1746   }
1747 }
1748 
1749 void TemplateTable::ineg() {
1750   transition(itos, itos);
1751   __ negl(rax);
1752 }
1753 
1754 void TemplateTable::lneg() {
1755   transition(ltos, ltos);
1756   LP64_ONLY(__ negq(rax));
1757   NOT_LP64(__ lneg(rdx, rax));
1758 }
1759 
1760 // Note: 'double' and 'long long' have 32-bits alignment on x86.
1761 static jlong* double_quadword(jlong *adr, jlong lo, jlong hi) {
1762   // Use the expression (adr)&(~0xF) to provide 128-bits aligned address
1763   // of 128-bits operands for SSE instructions.
1764   jlong *operand = (jlong*)(((intptr_t)adr)&((intptr_t)(~0xF)));
1765   // Store the value to a 128-bits operand.
1766   operand[0] = lo;
1767   operand[1] = hi;
1768   return operand;
1769 }
1770 
1771 // Buffer for 128-bits masks used by SSE instructions.
1772 static jlong float_signflip_pool[2*2];
1773 static jlong double_signflip_pool[2*2];
1774 
1775 void TemplateTable::fneg() {
1776   transition(ftos, ftos);
1777   if (UseSSE >= 1) {
1778     static jlong *float_signflip  = double_quadword(&float_signflip_pool[1],  CONST64(0x8000000080000000),  CONST64(0x8000000080000000));
1779     __ xorps(xmm0, ExternalAddress((address) float_signflip), rscratch1);
1780   } else {
1781     LP64_ONLY(ShouldNotReachHere());
1782     NOT_LP64(__ fchs());
1783   }
1784 }
1785 
1786 void TemplateTable::dneg() {
1787   transition(dtos, dtos);
1788   if (UseSSE >= 2) {
1789     static jlong *double_signflip =
1790       double_quadword(&double_signflip_pool[1], CONST64(0x8000000000000000), CONST64(0x8000000000000000));
1791     __ xorpd(xmm0, ExternalAddress((address) double_signflip), rscratch1);
1792   } else {
1793 #ifdef _LP64
1794     ShouldNotReachHere();
1795 #else
1796     __ fchs();
1797 #endif
1798   }
1799 }
1800 
1801 void TemplateTable::iinc() {
1802   transition(vtos, vtos);
1803   __ load_signed_byte(rdx, at_bcp(2)); // get constant
1804   locals_index(rbx);
1805   __ addl(iaddress(rbx), rdx);
1806 }
1807 
1808 void TemplateTable::wide_iinc() {
1809   transition(vtos, vtos);
1810   __ movl(rdx, at_bcp(4)); // get constant
1811   locals_index_wide(rbx);
1812   __ bswapl(rdx); // swap bytes & sign-extend constant
1813   __ sarl(rdx, 16);
1814   __ addl(iaddress(rbx), rdx);
1815   // Note: should probably use only one movl to get both
1816   //       the index and the constant -> fix this
1817 }
1818 
1819 void TemplateTable::convert() {
1820 #ifdef _LP64
1821   // Checking
1822 #ifdef ASSERT
1823   {
1824     TosState tos_in  = ilgl;
1825     TosState tos_out = ilgl;
1826     switch (bytecode()) {
1827     case Bytecodes::_i2l: // fall through
1828     case Bytecodes::_i2f: // fall through
1829     case Bytecodes::_i2d: // fall through
1830     case Bytecodes::_i2b: // fall through
1831     case Bytecodes::_i2c: // fall through
1832     case Bytecodes::_i2s: tos_in = itos; break;
1833     case Bytecodes::_l2i: // fall through
1834     case Bytecodes::_l2f: // fall through
1835     case Bytecodes::_l2d: tos_in = ltos; break;
1836     case Bytecodes::_f2i: // fall through
1837     case Bytecodes::_f2l: // fall through
1838     case Bytecodes::_f2d: tos_in = ftos; break;
1839     case Bytecodes::_d2i: // fall through
1840     case Bytecodes::_d2l: // fall through
1841     case Bytecodes::_d2f: tos_in = dtos; break;
1842     default             : ShouldNotReachHere();
1843     }
1844     switch (bytecode()) {
1845     case Bytecodes::_l2i: // fall through
1846     case Bytecodes::_f2i: // fall through
1847     case Bytecodes::_d2i: // fall through
1848     case Bytecodes::_i2b: // fall through
1849     case Bytecodes::_i2c: // fall through
1850     case Bytecodes::_i2s: tos_out = itos; break;
1851     case Bytecodes::_i2l: // fall through
1852     case Bytecodes::_f2l: // fall through
1853     case Bytecodes::_d2l: tos_out = ltos; break;
1854     case Bytecodes::_i2f: // fall through
1855     case Bytecodes::_l2f: // fall through
1856     case Bytecodes::_d2f: tos_out = ftos; break;
1857     case Bytecodes::_i2d: // fall through
1858     case Bytecodes::_l2d: // fall through
1859     case Bytecodes::_f2d: tos_out = dtos; break;
1860     default             : ShouldNotReachHere();
1861     }
1862     transition(tos_in, tos_out);
1863   }
1864 #endif // ASSERT
1865 
1866   static const int64_t is_nan = 0x8000000000000000L;
1867 
1868   // Conversion
1869   switch (bytecode()) {
1870   case Bytecodes::_i2l:
1871     __ movslq(rax, rax);
1872     break;
1873   case Bytecodes::_i2f:
1874     __ cvtsi2ssl(xmm0, rax);
1875     break;
1876   case Bytecodes::_i2d:
1877     __ cvtsi2sdl(xmm0, rax);
1878     break;
1879   case Bytecodes::_i2b:
1880     __ movsbl(rax, rax);
1881     break;
1882   case Bytecodes::_i2c:
1883     __ movzwl(rax, rax);
1884     break;
1885   case Bytecodes::_i2s:
1886     __ movswl(rax, rax);
1887     break;
1888   case Bytecodes::_l2i:
1889     __ movl(rax, rax);
1890     break;
1891   case Bytecodes::_l2f:
1892     __ cvtsi2ssq(xmm0, rax);
1893     break;
1894   case Bytecodes::_l2d:
1895     __ cvtsi2sdq(xmm0, rax);
1896     break;
1897   case Bytecodes::_f2i:
1898   {
1899     Label L;
1900     __ cvttss2sil(rax, xmm0);
1901     __ cmpl(rax, 0x80000000); // NaN or overflow/underflow?
1902     __ jcc(Assembler::notEqual, L);
1903     __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::f2i), 1);
1904     __ bind(L);
1905   }
1906     break;
1907   case Bytecodes::_f2l:
1908   {
1909     Label L;
1910     __ cvttss2siq(rax, xmm0);
1911     // NaN or overflow/underflow?
1912     __ cmp64(rax, ExternalAddress((address) &is_nan), rscratch1);
1913     __ jcc(Assembler::notEqual, L);
1914     __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::f2l), 1);
1915     __ bind(L);
1916   }
1917     break;
1918   case Bytecodes::_f2d:
1919     __ cvtss2sd(xmm0, xmm0);
1920     break;
1921   case Bytecodes::_d2i:
1922   {
1923     Label L;
1924     __ cvttsd2sil(rax, xmm0);
1925     __ cmpl(rax, 0x80000000); // NaN or overflow/underflow?
1926     __ jcc(Assembler::notEqual, L);
1927     __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::d2i), 1);
1928     __ bind(L);
1929   }
1930     break;
1931   case Bytecodes::_d2l:
1932   {
1933     Label L;
1934     __ cvttsd2siq(rax, xmm0);
1935     // NaN or overflow/underflow?
1936     __ cmp64(rax, ExternalAddress((address) &is_nan), rscratch1);
1937     __ jcc(Assembler::notEqual, L);
1938     __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::d2l), 1);
1939     __ bind(L);
1940   }
1941     break;
1942   case Bytecodes::_d2f:
1943     __ cvtsd2ss(xmm0, xmm0);
1944     break;
1945   default:
1946     ShouldNotReachHere();
1947   }
1948 #else // !_LP64
1949   // Checking
1950 #ifdef ASSERT
1951   { TosState tos_in  = ilgl;
1952     TosState tos_out = ilgl;
1953     switch (bytecode()) {
1954       case Bytecodes::_i2l: // fall through
1955       case Bytecodes::_i2f: // fall through
1956       case Bytecodes::_i2d: // fall through
1957       case Bytecodes::_i2b: // fall through
1958       case Bytecodes::_i2c: // fall through
1959       case Bytecodes::_i2s: tos_in = itos; break;
1960       case Bytecodes::_l2i: // fall through
1961       case Bytecodes::_l2f: // fall through
1962       case Bytecodes::_l2d: tos_in = ltos; break;
1963       case Bytecodes::_f2i: // fall through
1964       case Bytecodes::_f2l: // fall through
1965       case Bytecodes::_f2d: tos_in = ftos; break;
1966       case Bytecodes::_d2i: // fall through
1967       case Bytecodes::_d2l: // fall through
1968       case Bytecodes::_d2f: tos_in = dtos; break;
1969       default             : ShouldNotReachHere();
1970     }
1971     switch (bytecode()) {
1972       case Bytecodes::_l2i: // fall through
1973       case Bytecodes::_f2i: // fall through
1974       case Bytecodes::_d2i: // fall through
1975       case Bytecodes::_i2b: // fall through
1976       case Bytecodes::_i2c: // fall through
1977       case Bytecodes::_i2s: tos_out = itos; break;
1978       case Bytecodes::_i2l: // fall through
1979       case Bytecodes::_f2l: // fall through
1980       case Bytecodes::_d2l: tos_out = ltos; break;
1981       case Bytecodes::_i2f: // fall through
1982       case Bytecodes::_l2f: // fall through
1983       case Bytecodes::_d2f: tos_out = ftos; break;
1984       case Bytecodes::_i2d: // fall through
1985       case Bytecodes::_l2d: // fall through
1986       case Bytecodes::_f2d: tos_out = dtos; break;
1987       default             : ShouldNotReachHere();
1988     }
1989     transition(tos_in, tos_out);
1990   }
1991 #endif // ASSERT
1992 
1993   // Conversion
1994   // (Note: use push(rcx)/pop(rcx) for 1/2-word stack-ptr manipulation)
1995   switch (bytecode()) {
1996     case Bytecodes::_i2l:
1997       __ extend_sign(rdx, rax);
1998       break;
1999     case Bytecodes::_i2f:
2000       if (UseSSE >= 1) {
2001         __ cvtsi2ssl(xmm0, rax);
2002       } else {
2003         __ push(rax);          // store int on tos
2004         __ fild_s(at_rsp());   // load int to ST0
2005         __ f2ieee();           // truncate to float size
2006         __ pop(rcx);           // adjust rsp
2007       }
2008       break;
2009     case Bytecodes::_i2d:
2010       if (UseSSE >= 2) {
2011         __ cvtsi2sdl(xmm0, rax);
2012       } else {
2013       __ push(rax);          // add one slot for d2ieee()
2014       __ push(rax);          // store int on tos
2015       __ fild_s(at_rsp());   // load int to ST0
2016       __ d2ieee();           // truncate to double size
2017       __ pop(rcx);           // adjust rsp
2018       __ pop(rcx);
2019       }
2020       break;
2021     case Bytecodes::_i2b:
2022       __ shll(rax, 24);      // truncate upper 24 bits
2023       __ sarl(rax, 24);      // and sign-extend byte
2024       LP64_ONLY(__ movsbl(rax, rax));
2025       break;
2026     case Bytecodes::_i2c:
2027       __ andl(rax, 0xFFFF);  // truncate upper 16 bits
2028       LP64_ONLY(__ movzwl(rax, rax));
2029       break;
2030     case Bytecodes::_i2s:
2031       __ shll(rax, 16);      // truncate upper 16 bits
2032       __ sarl(rax, 16);      // and sign-extend short
2033       LP64_ONLY(__ movswl(rax, rax));
2034       break;
2035     case Bytecodes::_l2i:
2036       /* nothing to do */
2037       break;
2038     case Bytecodes::_l2f:
2039       // On 64-bit platforms, the cvtsi2ssq instruction is used to convert
2040       // 64-bit long values to floats. On 32-bit platforms it is not possible
2041       // to use that instruction with 64-bit operands, therefore the FPU is
2042       // used to perform the conversion.
2043       __ push(rdx);          // store long on tos
2044       __ push(rax);
2045       __ fild_d(at_rsp());   // load long to ST0
2046       __ f2ieee();           // truncate to float size
2047       __ pop(rcx);           // adjust rsp
2048       __ pop(rcx);
2049       if (UseSSE >= 1) {
2050         __ push_f();
2051         __ pop_f(xmm0);
2052       }
2053       break;
2054     case Bytecodes::_l2d:
2055       // On 32-bit platforms the FPU is used for conversion because on
2056       // 32-bit platforms it is not not possible to use the cvtsi2sdq
2057       // instruction with 64-bit operands.
2058       __ push(rdx);          // store long on tos
2059       __ push(rax);
2060       __ fild_d(at_rsp());   // load long to ST0
2061       __ d2ieee();           // truncate to double size
2062       __ pop(rcx);           // adjust rsp
2063       __ pop(rcx);
2064       if (UseSSE >= 2) {
2065         __ push_d();
2066         __ pop_d(xmm0);
2067       }
2068       break;
2069     case Bytecodes::_f2i:
2070       // SharedRuntime::f2i does not differentiate between sNaNs and qNaNs
2071       // as it returns 0 for any NaN.
2072       if (UseSSE >= 1) {
2073         __ push_f(xmm0);
2074       } else {
2075         __ push(rcx);          // reserve space for argument
2076         __ fstp_s(at_rsp());   // pass float argument on stack
2077       }
2078       __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::f2i), 1);
2079       break;
2080     case Bytecodes::_f2l:
2081       // SharedRuntime::f2l does not differentiate between sNaNs and qNaNs
2082       // as it returns 0 for any NaN.
2083       if (UseSSE >= 1) {
2084        __ push_f(xmm0);
2085       } else {
2086         __ push(rcx);          // reserve space for argument
2087         __ fstp_s(at_rsp());   // pass float argument on stack
2088       }
2089       __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::f2l), 1);
2090       break;
2091     case Bytecodes::_f2d:
2092       if (UseSSE < 1) {
2093         /* nothing to do */
2094       } else if (UseSSE == 1) {
2095         __ push_f(xmm0);
2096         __ pop_f();
2097       } else { // UseSSE >= 2
2098         __ cvtss2sd(xmm0, xmm0);
2099       }
2100       break;
2101     case Bytecodes::_d2i:
2102       if (UseSSE >= 2) {
2103         __ push_d(xmm0);
2104       } else {
2105         __ push(rcx);          // reserve space for argument
2106         __ push(rcx);
2107         __ fstp_d(at_rsp());   // pass double argument on stack
2108       }
2109       __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::d2i), 2);
2110       break;
2111     case Bytecodes::_d2l:
2112       if (UseSSE >= 2) {
2113         __ push_d(xmm0);
2114       } else {
2115         __ push(rcx);          // reserve space for argument
2116         __ push(rcx);
2117         __ fstp_d(at_rsp());   // pass double argument on stack
2118       }
2119       __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::d2l), 2);
2120       break;
2121     case Bytecodes::_d2f:
2122       if (UseSSE <= 1) {
2123         __ push(rcx);          // reserve space for f2ieee()
2124         __ f2ieee();           // truncate to float size
2125         __ pop(rcx);           // adjust rsp
2126         if (UseSSE == 1) {
2127           // The cvtsd2ss instruction is not available if UseSSE==1, therefore
2128           // the conversion is performed using the FPU in this case.
2129           __ push_f();
2130           __ pop_f(xmm0);
2131         }
2132       } else { // UseSSE >= 2
2133         __ cvtsd2ss(xmm0, xmm0);
2134       }
2135       break;
2136     default             :
2137       ShouldNotReachHere();
2138   }
2139 #endif // _LP64
2140 }
2141 
2142 void TemplateTable::lcmp() {
2143   transition(ltos, itos);
2144 #ifdef _LP64
2145   Label done;
2146   __ pop_l(rdx);
2147   __ cmpq(rdx, rax);
2148   __ movl(rax, -1);
2149   __ jccb(Assembler::less, done);
2150   __ setb(Assembler::notEqual, rax);
2151   __ movzbl(rax, rax);
2152   __ bind(done);
2153 #else
2154 
2155   // y = rdx:rax
2156   __ pop_l(rbx, rcx);             // get x = rcx:rbx
2157   __ lcmp2int(rcx, rbx, rdx, rax);// rcx := cmp(x, y)
2158   __ mov(rax, rcx);
2159 #endif
2160 }
2161 
2162 void TemplateTable::float_cmp(bool is_float, int unordered_result) {
2163   if ((is_float && UseSSE >= 1) ||
2164       (!is_float && UseSSE >= 2)) {
2165     Label done;
2166     if (is_float) {
2167       // XXX get rid of pop here, use ... reg, mem32
2168       __ pop_f(xmm1);
2169       __ ucomiss(xmm1, xmm0);
2170     } else {
2171       // XXX get rid of pop here, use ... reg, mem64
2172       __ pop_d(xmm1);
2173       __ ucomisd(xmm1, xmm0);
2174     }
2175     if (unordered_result < 0) {
2176       __ movl(rax, -1);
2177       __ jccb(Assembler::parity, done);
2178       __ jccb(Assembler::below, done);
2179       __ setb(Assembler::notEqual, rdx);
2180       __ movzbl(rax, rdx);
2181     } else {
2182       __ movl(rax, 1);
2183       __ jccb(Assembler::parity, done);
2184       __ jccb(Assembler::above, done);
2185       __ movl(rax, 0);
2186       __ jccb(Assembler::equal, done);
2187       __ decrementl(rax);
2188     }
2189     __ bind(done);
2190   } else {
2191 #ifdef _LP64
2192     ShouldNotReachHere();
2193 #else // !_LP64
2194     if (is_float) {
2195       __ fld_s(at_rsp());
2196     } else {
2197       __ fld_d(at_rsp());
2198       __ pop(rdx);
2199     }
2200     __ pop(rcx);
2201     __ fcmp2int(rax, unordered_result < 0);
2202 #endif // _LP64
2203   }
2204 }
2205 
2206 void TemplateTable::branch(bool is_jsr, bool is_wide) {
2207   __ get_method(rcx); // rcx holds method
2208   __ profile_taken_branch(rax, rbx); // rax holds updated MDP, rbx
2209                                      // holds bumped taken count
2210 
2211   const ByteSize be_offset = MethodCounters::backedge_counter_offset() +
2212                              InvocationCounter::counter_offset();
2213   const ByteSize inv_offset = MethodCounters::invocation_counter_offset() +
2214                               InvocationCounter::counter_offset();
2215 
2216   // Load up edx with the branch displacement
2217   if (is_wide) {
2218     __ movl(rdx, at_bcp(1));
2219   } else {
2220     __ load_signed_short(rdx, at_bcp(1));
2221   }
2222   __ bswapl(rdx);
2223 
2224   if (!is_wide) {
2225     __ sarl(rdx, 16);
2226   }
2227   LP64_ONLY(__ movl2ptr(rdx, rdx));
2228 
2229   // Handle all the JSR stuff here, then exit.
2230   // It's much shorter and cleaner than intermingling with the non-JSR
2231   // normal-branch stuff occurring below.
2232   if (is_jsr) {
2233     // Pre-load the next target bytecode into rbx
2234     __ load_unsigned_byte(rbx, Address(rbcp, rdx, Address::times_1, 0));
2235 
2236     // compute return address as bci in rax
2237     __ lea(rax, at_bcp((is_wide ? 5 : 3) -
2238                         in_bytes(ConstMethod::codes_offset())));
2239     __ subptr(rax, Address(rcx, Method::const_offset()));
2240     // Adjust the bcp in r13 by the displacement in rdx
2241     __ addptr(rbcp, rdx);
2242     // jsr returns atos that is not an oop
2243     __ push_i(rax);
2244     __ dispatch_only(vtos, true);
2245     return;
2246   }
2247 
2248   // Normal (non-jsr) branch handling
2249 
2250   // Adjust the bcp in r13 by the displacement in rdx
2251   __ addptr(rbcp, rdx);
2252 
2253   assert(UseLoopCounter || !UseOnStackReplacement,
2254          "on-stack-replacement requires loop counters");
2255   Label backedge_counter_overflow;
2256   Label dispatch;
2257   if (UseLoopCounter) {
2258     // increment backedge counter for backward branches
2259     // rax: MDO
2260     // rbx: MDO bumped taken-count
2261     // rcx: method
2262     // rdx: target offset
2263     // r13: target bcp
2264     // r14: locals pointer
2265     __ testl(rdx, rdx);             // check if forward or backward branch
2266     __ jcc(Assembler::positive, dispatch); // count only if backward branch
2267 
2268     // check if MethodCounters exists
2269     Label has_counters;
2270     __ movptr(rax, Address(rcx, Method::method_counters_offset()));
2271     __ testptr(rax, rax);
2272     __ jcc(Assembler::notZero, has_counters);
2273     __ push(rdx);
2274     __ push(rcx);
2275     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::build_method_counters),
2276                rcx);
2277     __ pop(rcx);
2278     __ pop(rdx);
2279     __ movptr(rax, Address(rcx, Method::method_counters_offset()));
2280     __ testptr(rax, rax);
2281     __ jcc(Assembler::zero, dispatch);
2282     __ bind(has_counters);
2283 
2284     Label no_mdo;
2285     if (ProfileInterpreter) {
2286       // Are we profiling?
2287       __ movptr(rbx, Address(rcx, in_bytes(Method::method_data_offset())));
2288       __ testptr(rbx, rbx);
2289       __ jccb(Assembler::zero, no_mdo);
2290       // Increment the MDO backedge counter
2291       const Address mdo_backedge_counter(rbx, in_bytes(MethodData::backedge_counter_offset()) +
2292           in_bytes(InvocationCounter::counter_offset()));
2293       const Address mask(rbx, in_bytes(MethodData::backedge_mask_offset()));
2294       __ increment_mask_and_jump(mdo_backedge_counter, mask, rax,
2295           UseOnStackReplacement ? &backedge_counter_overflow : nullptr);
2296       __ jmp(dispatch);
2297     }
2298     __ bind(no_mdo);
2299     // Increment backedge counter in MethodCounters*
2300     __ movptr(rcx, Address(rcx, Method::method_counters_offset()));
2301     const Address mask(rcx, in_bytes(MethodCounters::backedge_mask_offset()));
2302     __ increment_mask_and_jump(Address(rcx, be_offset), mask, rax,
2303         UseOnStackReplacement ? &backedge_counter_overflow : nullptr);
2304     __ bind(dispatch);
2305   }
2306 
2307   // Pre-load the next target bytecode into rbx
2308   __ load_unsigned_byte(rbx, Address(rbcp, 0));
2309 
2310   // continue with the bytecode @ target
2311   // rax: return bci for jsr's, unused otherwise
2312   // rbx: target bytecode
2313   // r13: target bcp
2314   __ dispatch_only(vtos, true);
2315 
2316   if (UseLoopCounter) {
2317     if (UseOnStackReplacement) {
2318       Label set_mdp;
2319       // invocation counter overflow
2320       __ bind(backedge_counter_overflow);
2321       __ negptr(rdx);
2322       __ addptr(rdx, rbcp); // branch bcp
2323       // IcoResult frequency_counter_overflow([JavaThread*], address branch_bcp)
2324       __ call_VM(noreg,
2325                  CAST_FROM_FN_PTR(address,
2326                                   InterpreterRuntime::frequency_counter_overflow),
2327                  rdx);
2328 
2329       // rax: osr nmethod (osr ok) or null (osr not possible)
2330       // rdx: scratch
2331       // r14: locals pointer
2332       // r13: bcp
2333       __ testptr(rax, rax);                        // test result
2334       __ jcc(Assembler::zero, dispatch);         // no osr if null
2335       // nmethod may have been invalidated (VM may block upon call_VM return)
2336       __ cmpb(Address(rax, nmethod::state_offset()), nmethod::in_use);
2337       __ jcc(Assembler::notEqual, dispatch);
2338 
2339       // We have the address of an on stack replacement routine in rax.
2340       // In preparation of invoking it, first we must migrate the locals
2341       // and monitors from off the interpreter frame on the stack.
2342       // Ensure to save the osr nmethod over the migration call,
2343       // it will be preserved in rbx.
2344       __ mov(rbx, rax);
2345 
2346       NOT_LP64(__ get_thread(rcx));
2347 
2348       call_VM(noreg, CAST_FROM_FN_PTR(address, SharedRuntime::OSR_migration_begin));
2349 
2350       // rax is OSR buffer, move it to expected parameter location
2351       LP64_ONLY(__ mov(j_rarg0, rax));
2352       NOT_LP64(__ mov(rcx, rax));
2353       // We use j_rarg definitions here so that registers don't conflict as parameter
2354       // registers change across platforms as we are in the midst of a calling
2355       // sequence to the OSR nmethod and we don't want collision. These are NOT parameters.
2356 
2357       const Register retaddr   = LP64_ONLY(j_rarg2) NOT_LP64(rdi);
2358       const Register sender_sp = LP64_ONLY(j_rarg1) NOT_LP64(rdx);
2359 
2360       // pop the interpreter frame
2361       __ movptr(sender_sp, Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize)); // get sender sp
2362       __ leave();                                // remove frame anchor
2363       __ pop(retaddr);                           // get return address
2364       __ mov(rsp, sender_sp);                   // set sp to sender sp
2365       // Ensure compiled code always sees stack at proper alignment
2366       __ andptr(rsp, -(StackAlignmentInBytes));
2367 
2368       // unlike x86 we need no specialized return from compiled code
2369       // to the interpreter or the call stub.
2370 
2371       // push the return address
2372       __ push(retaddr);
2373 
2374       // and begin the OSR nmethod
2375       __ jmp(Address(rbx, nmethod::osr_entry_point_offset()));
2376     }
2377   }
2378 }
2379 
2380 void TemplateTable::if_0cmp(Condition cc) {
2381   transition(itos, vtos);
2382   // assume branch is more often taken than not (loops use backward branches)
2383   Label not_taken;
2384   __ testl(rax, rax);
2385   __ jcc(j_not(cc), not_taken);
2386   branch(false, false);
2387   __ bind(not_taken);
2388   __ profile_not_taken_branch(rax);
2389 }
2390 
2391 void TemplateTable::if_icmp(Condition cc) {
2392   transition(itos, vtos);
2393   // assume branch is more often taken than not (loops use backward branches)
2394   Label not_taken;
2395   __ pop_i(rdx);
2396   __ cmpl(rdx, rax);
2397   __ jcc(j_not(cc), not_taken);
2398   branch(false, false);
2399   __ bind(not_taken);
2400   __ profile_not_taken_branch(rax);
2401 }
2402 
2403 void TemplateTable::if_nullcmp(Condition cc) {
2404   transition(atos, vtos);
2405   // assume branch is more often taken than not (loops use backward branches)
2406   Label not_taken;
2407   __ testptr(rax, rax);
2408   __ jcc(j_not(cc), not_taken);
2409   branch(false, false);
2410   __ bind(not_taken);
2411   __ profile_not_taken_branch(rax);
2412 }
2413 
2414 void TemplateTable::if_acmp(Condition cc) {
2415   transition(atos, vtos);
2416   // assume branch is more often taken than not (loops use backward branches)
2417   Label taken, not_taken;
2418   __ pop_ptr(rdx);
2419 
2420   __ profile_acmp(rbx, rdx, rax, rcx);
2421 
2422   const int is_inline_type_mask = markWord::inline_type_pattern;
2423   if (EnableValhalla) {
2424     __ cmpoop(rdx, rax);
2425     __ jcc(Assembler::equal, (cc == equal) ? taken : not_taken);
2426 
2427     // might be substitutable, test if either rax or rdx is null
2428     __ testptr(rax, rax);
2429     __ jcc(Assembler::zero, (cc == equal) ? not_taken : taken);
2430     __ testptr(rdx, rdx);
2431     __ jcc(Assembler::zero, (cc == equal) ? not_taken : taken);
2432 
2433     // and both are values ?
2434     __ movptr(rbx, Address(rdx, oopDesc::mark_offset_in_bytes()));
2435     __ andptr(rbx, Address(rax, oopDesc::mark_offset_in_bytes()));
2436     __ andptr(rbx, is_inline_type_mask);
2437     __ cmpptr(rbx, is_inline_type_mask);
2438     __ jcc(Assembler::notEqual, (cc == equal) ? not_taken : taken);
2439 
2440     // same value klass ?
2441     __ load_metadata(rbx, rdx);
2442     __ load_metadata(rcx, rax);
2443     __ cmpptr(rbx, rcx);
2444     __ jcc(Assembler::notEqual, (cc == equal) ? not_taken : taken);
2445 
2446     // Know both are the same type, let's test for substitutability...
2447     if (cc == equal) {
2448       invoke_is_substitutable(rax, rdx, taken, not_taken);
2449     } else {
2450       invoke_is_substitutable(rax, rdx, not_taken, taken);
2451     }
2452     __ stop("Not reachable");
2453   }
2454 
2455   __ cmpoop(rdx, rax);
2456   __ jcc(j_not(cc), not_taken);
2457   __ bind(taken);
2458   branch(false, false);
2459   __ bind(not_taken);
2460   __ profile_not_taken_branch(rax, true);
2461 }
2462 
2463 void TemplateTable::invoke_is_substitutable(Register aobj, Register bobj,
2464                                             Label& is_subst, Label& not_subst) {
2465   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::is_substitutable), aobj, bobj);
2466   // Restored...rax answer, jmp to outcome...
2467   __ testl(rax, rax);
2468   __ jcc(Assembler::zero, not_subst);
2469   __ jmp(is_subst);
2470 }
2471 
2472 void TemplateTable::ret() {
2473   transition(vtos, vtos);
2474   locals_index(rbx);
2475   LP64_ONLY(__ movslq(rbx, iaddress(rbx))); // get return bci, compute return bcp
2476   NOT_LP64(__ movptr(rbx, iaddress(rbx)));
2477   __ profile_ret(rbx, rcx);
2478   __ get_method(rax);
2479   __ movptr(rbcp, Address(rax, Method::const_offset()));
2480   __ lea(rbcp, Address(rbcp, rbx, Address::times_1,
2481                       ConstMethod::codes_offset()));
2482   __ dispatch_next(vtos, 0, true);
2483 }
2484 
2485 void TemplateTable::wide_ret() {
2486   transition(vtos, vtos);
2487   locals_index_wide(rbx);
2488   __ movptr(rbx, aaddress(rbx)); // get return bci, compute return bcp
2489   __ profile_ret(rbx, rcx);
2490   __ get_method(rax);
2491   __ movptr(rbcp, Address(rax, Method::const_offset()));
2492   __ lea(rbcp, Address(rbcp, rbx, Address::times_1, ConstMethod::codes_offset()));
2493   __ dispatch_next(vtos, 0, true);
2494 }
2495 
2496 void TemplateTable::tableswitch() {
2497   Label default_case, continue_execution;
2498   transition(itos, vtos);
2499 
2500   // align r13/rsi
2501   __ lea(rbx, at_bcp(BytesPerInt));
2502   __ andptr(rbx, -BytesPerInt);
2503   // load lo & hi
2504   __ movl(rcx, Address(rbx, BytesPerInt));
2505   __ movl(rdx, Address(rbx, 2 * BytesPerInt));
2506   __ bswapl(rcx);
2507   __ bswapl(rdx);
2508   // check against lo & hi
2509   __ cmpl(rax, rcx);
2510   __ jcc(Assembler::less, default_case);
2511   __ cmpl(rax, rdx);
2512   __ jcc(Assembler::greater, default_case);
2513   // lookup dispatch offset
2514   __ subl(rax, rcx);
2515   __ movl(rdx, Address(rbx, rax, Address::times_4, 3 * BytesPerInt));
2516   __ profile_switch_case(rax, rbx, rcx);
2517   // continue execution
2518   __ bind(continue_execution);
2519   __ bswapl(rdx);
2520   LP64_ONLY(__ movl2ptr(rdx, rdx));
2521   __ load_unsigned_byte(rbx, Address(rbcp, rdx, Address::times_1));
2522   __ addptr(rbcp, rdx);
2523   __ dispatch_only(vtos, true);
2524   // handle default
2525   __ bind(default_case);
2526   __ profile_switch_default(rax);
2527   __ movl(rdx, Address(rbx, 0));
2528   __ jmp(continue_execution);
2529 }
2530 
2531 void TemplateTable::lookupswitch() {
2532   transition(itos, itos);
2533   __ stop("lookupswitch bytecode should have been rewritten");
2534 }
2535 
2536 void TemplateTable::fast_linearswitch() {
2537   transition(itos, vtos);
2538   Label loop_entry, loop, found, continue_execution;
2539   // bswap rax so we can avoid bswapping the table entries
2540   __ bswapl(rax);
2541   // align r13
2542   __ lea(rbx, at_bcp(BytesPerInt)); // btw: should be able to get rid of
2543                                     // this instruction (change offsets
2544                                     // below)
2545   __ andptr(rbx, -BytesPerInt);
2546   // set counter
2547   __ movl(rcx, Address(rbx, BytesPerInt));
2548   __ bswapl(rcx);
2549   __ jmpb(loop_entry);
2550   // table search
2551   __ bind(loop);
2552   __ cmpl(rax, Address(rbx, rcx, Address::times_8, 2 * BytesPerInt));
2553   __ jcc(Assembler::equal, found);
2554   __ bind(loop_entry);
2555   __ decrementl(rcx);
2556   __ jcc(Assembler::greaterEqual, loop);
2557   // default case
2558   __ profile_switch_default(rax);
2559   __ movl(rdx, Address(rbx, 0));
2560   __ jmp(continue_execution);
2561   // entry found -> get offset
2562   __ bind(found);
2563   __ movl(rdx, Address(rbx, rcx, Address::times_8, 3 * BytesPerInt));
2564   __ profile_switch_case(rcx, rax, rbx);
2565   // continue execution
2566   __ bind(continue_execution);
2567   __ bswapl(rdx);
2568   __ movl2ptr(rdx, rdx);
2569   __ load_unsigned_byte(rbx, Address(rbcp, rdx, Address::times_1));
2570   __ addptr(rbcp, rdx);
2571   __ dispatch_only(vtos, true);
2572 }
2573 
2574 void TemplateTable::fast_binaryswitch() {
2575   transition(itos, vtos);
2576   // Implementation using the following core algorithm:
2577   //
2578   // int binary_search(int key, LookupswitchPair* array, int n) {
2579   //   // Binary search according to "Methodik des Programmierens" by
2580   //   // Edsger W. Dijkstra and W.H.J. Feijen, Addison Wesley Germany 1985.
2581   //   int i = 0;
2582   //   int j = n;
2583   //   while (i+1 < j) {
2584   //     // invariant P: 0 <= i < j <= n and (a[i] <= key < a[j] or Q)
2585   //     // with      Q: for all i: 0 <= i < n: key < a[i]
2586   //     // where a stands for the array and assuming that the (inexisting)
2587   //     // element a[n] is infinitely big.
2588   //     int h = (i + j) >> 1;
2589   //     // i < h < j
2590   //     if (key < array[h].fast_match()) {
2591   //       j = h;
2592   //     } else {
2593   //       i = h;
2594   //     }
2595   //   }
2596   //   // R: a[i] <= key < a[i+1] or Q
2597   //   // (i.e., if key is within array, i is the correct index)
2598   //   return i;
2599   // }
2600 
2601   // Register allocation
2602   const Register key   = rax; // already set (tosca)
2603   const Register array = rbx;
2604   const Register i     = rcx;
2605   const Register j     = rdx;
2606   const Register h     = rdi;
2607   const Register temp  = rsi;
2608 
2609   // Find array start
2610   NOT_LP64(__ save_bcp());
2611 
2612   __ lea(array, at_bcp(3 * BytesPerInt)); // btw: should be able to
2613                                           // get rid of this
2614                                           // instruction (change
2615                                           // offsets below)
2616   __ andptr(array, -BytesPerInt);
2617 
2618   // Initialize i & j
2619   __ xorl(i, i);                            // i = 0;
2620   __ movl(j, Address(array, -BytesPerInt)); // j = length(array);
2621 
2622   // Convert j into native byteordering
2623   __ bswapl(j);
2624 
2625   // And start
2626   Label entry;
2627   __ jmp(entry);
2628 
2629   // binary search loop
2630   {
2631     Label loop;
2632     __ bind(loop);
2633     // int h = (i + j) >> 1;
2634     __ leal(h, Address(i, j, Address::times_1)); // h = i + j;
2635     __ sarl(h, 1);                               // h = (i + j) >> 1;
2636     // if (key < array[h].fast_match()) {
2637     //   j = h;
2638     // } else {
2639     //   i = h;
2640     // }
2641     // Convert array[h].match to native byte-ordering before compare
2642     __ movl(temp, Address(array, h, Address::times_8));
2643     __ bswapl(temp);
2644     __ cmpl(key, temp);
2645     // j = h if (key <  array[h].fast_match())
2646     __ cmov32(Assembler::less, j, h);
2647     // i = h if (key >= array[h].fast_match())
2648     __ cmov32(Assembler::greaterEqual, i, h);
2649     // while (i+1 < j)
2650     __ bind(entry);
2651     __ leal(h, Address(i, 1)); // i+1
2652     __ cmpl(h, j);             // i+1 < j
2653     __ jcc(Assembler::less, loop);
2654   }
2655 
2656   // end of binary search, result index is i (must check again!)
2657   Label default_case;
2658   // Convert array[i].match to native byte-ordering before compare
2659   __ movl(temp, Address(array, i, Address::times_8));
2660   __ bswapl(temp);
2661   __ cmpl(key, temp);
2662   __ jcc(Assembler::notEqual, default_case);
2663 
2664   // entry found -> j = offset
2665   __ movl(j , Address(array, i, Address::times_8, BytesPerInt));
2666   __ profile_switch_case(i, key, array);
2667   __ bswapl(j);
2668   LP64_ONLY(__ movslq(j, j));
2669 
2670   NOT_LP64(__ restore_bcp());
2671   NOT_LP64(__ restore_locals());                           // restore rdi
2672 
2673   __ load_unsigned_byte(rbx, Address(rbcp, j, Address::times_1));
2674   __ addptr(rbcp, j);
2675   __ dispatch_only(vtos, true);
2676 
2677   // default case -> j = default offset
2678   __ bind(default_case);
2679   __ profile_switch_default(i);
2680   __ movl(j, Address(array, -2 * BytesPerInt));
2681   __ bswapl(j);
2682   LP64_ONLY(__ movslq(j, j));
2683 
2684   NOT_LP64(__ restore_bcp());
2685   NOT_LP64(__ restore_locals());
2686 
2687   __ load_unsigned_byte(rbx, Address(rbcp, j, Address::times_1));
2688   __ addptr(rbcp, j);
2689   __ dispatch_only(vtos, true);
2690 }
2691 
2692 void TemplateTable::_return(TosState state) {
2693   transition(state, state);
2694 
2695   assert(_desc->calls_vm(),
2696          "inconsistent calls_vm information"); // call in remove_activation
2697 
2698   if (_desc->bytecode() == Bytecodes::_return_register_finalizer) {
2699     assert(state == vtos, "only valid state");
2700     Register robj = LP64_ONLY(c_rarg1) NOT_LP64(rax);
2701     __ movptr(robj, aaddress(0));
2702     __ load_klass(rdi, robj, rscratch1);
2703     __ movl(rdi, Address(rdi, Klass::access_flags_offset()));
2704     __ testl(rdi, JVM_ACC_HAS_FINALIZER);
2705     Label skip_register_finalizer;
2706     __ jcc(Assembler::zero, skip_register_finalizer);
2707 
2708     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::register_finalizer), robj);
2709 
2710     __ bind(skip_register_finalizer);
2711   }
2712 
2713   if (_desc->bytecode() != Bytecodes::_return_register_finalizer) {
2714     Label no_safepoint;
2715     NOT_PRODUCT(__ block_comment("Thread-local Safepoint poll"));
2716 #ifdef _LP64
2717     __ testb(Address(r15_thread, JavaThread::polling_word_offset()), SafepointMechanism::poll_bit());
2718 #else
2719     const Register thread = rdi;
2720     __ get_thread(thread);
2721     __ testb(Address(thread, JavaThread::polling_word_offset()), SafepointMechanism::poll_bit());
2722 #endif
2723     __ jcc(Assembler::zero, no_safepoint);
2724     __ push(state);
2725     __ push_cont_fastpath();
2726     __ call_VM(noreg, CAST_FROM_FN_PTR(address,
2727                                        InterpreterRuntime::at_safepoint));
2728     __ pop_cont_fastpath();
2729     __ pop(state);
2730     __ bind(no_safepoint);
2731   }
2732 
2733   // Narrow result if state is itos but result type is smaller.
2734   // Need to narrow in the return bytecode rather than in generate_return_entry
2735   // since compiled code callers expect the result to already be narrowed.
2736   if (state == itos) {
2737     __ narrow(rax);
2738   }
2739 
2740   __ remove_activation(state, rbcp, true, true, true);
2741 
2742   __ jmp(rbcp);
2743 }
2744 
2745 // ----------------------------------------------------------------------------
2746 // Volatile variables demand their effects be made known to all CPU's
2747 // in order.  Store buffers on most chips allow reads & writes to
2748 // reorder; the JMM's ReadAfterWrite.java test fails in -Xint mode
2749 // without some kind of memory barrier (i.e., it's not sufficient that
2750 // the interpreter does not reorder volatile references, the hardware
2751 // also must not reorder them).
2752 //
2753 // According to the new Java Memory Model (JMM):
2754 // (1) All volatiles are serialized wrt to each other.  ALSO reads &
2755 //     writes act as acquire & release, so:
2756 // (2) A read cannot let unrelated NON-volatile memory refs that
2757 //     happen after the read float up to before the read.  It's OK for
2758 //     non-volatile memory refs that happen before the volatile read to
2759 //     float down below it.
2760 // (3) Similar a volatile write cannot let unrelated NON-volatile
2761 //     memory refs that happen BEFORE the write float down to after the
2762 //     write.  It's OK for non-volatile memory refs that happen after the
2763 //     volatile write to float up before it.
2764 //
2765 // We only put in barriers around volatile refs (they are expensive),
2766 // not _between_ memory refs (that would require us to track the
2767 // flavor of the previous memory refs).  Requirements (2) and (3)
2768 // require some barriers before volatile stores and after volatile
2769 // loads.  These nearly cover requirement (1) but miss the
2770 // volatile-store-volatile-load case.  This final case is placed after
2771 // volatile-stores although it could just as well go before
2772 // volatile-loads.
2773 
2774 void TemplateTable::volatile_barrier(Assembler::Membar_mask_bits order_constraint ) {
2775   // Helper function to insert a is-volatile test and memory barrier
2776   __ membar(order_constraint);
2777 }
2778 
2779 void TemplateTable::resolve_cache_and_index_for_method(int byte_no,
2780                                                        Register cache,
2781                                                        Register index) {
2782   const Register temp = rbx;
2783   assert_different_registers(cache, index, temp);
2784 
2785   Label L_clinit_barrier_slow;
2786   Label resolved;
2787 
2788   Bytecodes::Code code = bytecode();
2789 
2790   assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
2791 
2792   __ load_method_entry(cache, index);
2793   switch(byte_no) {
2794     case f1_byte:
2795       __ load_unsigned_byte(temp, Address(cache, in_bytes(ResolvedMethodEntry::bytecode1_offset())));
2796       break;
2797     case f2_byte:
2798       __ load_unsigned_byte(temp, Address(cache, in_bytes(ResolvedMethodEntry::bytecode2_offset())));
2799       break;
2800     default:
2801       ShouldNotReachHere();
2802   }
2803   __ cmpl(temp, code);  // have we resolved this bytecode?
2804   __ jcc(Assembler::equal, resolved);
2805 
2806   // resolve first time through
2807   // Class initialization barrier slow path lands here as well.
2808   __ bind(L_clinit_barrier_slow);
2809   address entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_from_cache);
2810   __ movl(temp, code);
2811   __ call_VM(noreg, entry, temp);
2812   // Update registers with resolved info
2813   __ load_method_entry(cache, index);
2814 
2815   __ bind(resolved);
2816 
2817   // Class initialization barrier for static methods
2818   if (VM_Version::supports_fast_class_init_checks() && bytecode() == Bytecodes::_invokestatic) {
2819     const Register method = temp;
2820     const Register klass  = temp;
2821     const Register thread = LP64_ONLY(r15_thread) NOT_LP64(noreg);
2822     assert(thread != noreg, "x86_32 not supported");
2823 
2824     __ movptr(method, Address(cache, in_bytes(ResolvedMethodEntry::method_offset())));
2825     __ load_method_holder(klass, method);
2826     __ clinit_barrier(klass, thread, nullptr /*L_fast_path*/, &L_clinit_barrier_slow);
2827   }
2828 }
2829 
2830 void TemplateTable::resolve_cache_and_index_for_field(int byte_no,
2831                                             Register cache,
2832                                             Register index) {
2833   const Register temp = rbx;
2834   assert_different_registers(cache, index, temp);
2835 
2836   Label resolved;
2837 
2838   Bytecodes::Code code = bytecode();
2839   switch (code) {
2840     case Bytecodes::_nofast_getfield: code = Bytecodes::_getfield; break;
2841     case Bytecodes::_nofast_putfield: code = Bytecodes::_putfield; break;
2842     default: break;
2843   }
2844 
2845   assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
2846   __ load_field_entry(cache, index);
2847   if (byte_no == f1_byte) {
2848     __ load_unsigned_byte(temp, Address(cache, in_bytes(ResolvedFieldEntry::get_code_offset())));
2849   } else {
2850     __ load_unsigned_byte(temp, Address(cache, in_bytes(ResolvedFieldEntry::put_code_offset())));
2851   }
2852   __ cmpl(temp, code);  // have we resolved this bytecode?
2853   __ jcc(Assembler::equal, resolved);
2854 
2855   // resolve first time through
2856   address entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_from_cache);
2857   __ movl(temp, code);
2858   __ call_VM(noreg, entry, temp);
2859   // Update registers with resolved info
2860   __ load_field_entry(cache, index);
2861 
2862   __ bind(resolved);
2863 }
2864 
2865 void TemplateTable::load_resolved_field_entry(Register obj,
2866                                               Register cache,
2867                                               Register tos_state,
2868                                               Register offset,
2869                                               Register flags,
2870                                               bool is_static = false) {
2871   assert_different_registers(cache, tos_state, flags, offset);
2872 
2873   // Field offset
2874   __ load_sized_value(offset, Address(cache, in_bytes(ResolvedFieldEntry::field_offset_offset())), sizeof(int), true /*is_signed*/);
2875 
2876   // Flags
2877   __ load_unsigned_byte(flags, Address(cache, in_bytes(ResolvedFieldEntry::flags_offset())));
2878 
2879   // TOS state
2880   __ load_unsigned_byte(tos_state, Address(cache, in_bytes(ResolvedFieldEntry::type_offset())));
2881 
2882   // Klass overwrite register
2883   if (is_static) {
2884     __ movptr(obj, Address(cache, ResolvedFieldEntry::field_holder_offset()));
2885     const int mirror_offset = in_bytes(Klass::java_mirror_offset());
2886     __ movptr(obj, Address(obj, mirror_offset));
2887     __ resolve_oop_handle(obj, rscratch2);
2888   }
2889 
2890 }
2891 
2892 void TemplateTable::load_invokedynamic_entry(Register method) {
2893   // setup registers
2894   const Register appendix = rax;
2895   const Register cache = rcx;
2896   const Register index = rdx;
2897   assert_different_registers(method, appendix, cache, index);
2898 
2899   __ save_bcp();
2900 
2901   Label resolved;
2902 
2903   __ load_resolved_indy_entry(cache, index);
2904   __ movptr(method, Address(cache, in_bytes(ResolvedIndyEntry::method_offset())));
2905 
2906   // Compare the method to zero
2907   __ testptr(method, method);
2908   __ jcc(Assembler::notZero, resolved);
2909 
2910   Bytecodes::Code code = bytecode();
2911 
2912   // Call to the interpreter runtime to resolve invokedynamic
2913   address entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_from_cache);
2914   __ movl(method, code); // this is essentially Bytecodes::_invokedynamic
2915   __ call_VM(noreg, entry, method);
2916   // Update registers with resolved info
2917   __ load_resolved_indy_entry(cache, index);
2918   __ movptr(method, Address(cache, in_bytes(ResolvedIndyEntry::method_offset())));
2919 
2920 #ifdef ASSERT
2921   __ testptr(method, method);
2922   __ jcc(Assembler::notZero, resolved);
2923   __ stop("Should be resolved by now");
2924 #endif // ASSERT
2925   __ bind(resolved);
2926 
2927   Label L_no_push;
2928   // Check if there is an appendix
2929   __ load_unsigned_byte(index, Address(cache, in_bytes(ResolvedIndyEntry::flags_offset())));
2930   __ testl(index, (1 << ResolvedIndyEntry::has_appendix_shift));
2931   __ jcc(Assembler::zero, L_no_push);
2932 
2933   // Get appendix
2934   __ load_unsigned_short(index, Address(cache, in_bytes(ResolvedIndyEntry::resolved_references_index_offset())));
2935   // Push the appendix as a trailing parameter
2936   // since the parameter_size includes it.
2937   __ load_resolved_reference_at_index(appendix, index);
2938   __ verify_oop(appendix);
2939   __ push(appendix);  // push appendix (MethodType, CallSite, etc.)
2940   __ bind(L_no_push);
2941 
2942   // compute return type
2943   __ load_unsigned_byte(index, Address(cache, in_bytes(ResolvedIndyEntry::result_type_offset())));
2944   // load return address
2945   {
2946     const address table_addr = (address) Interpreter::invoke_return_entry_table_for(code);
2947     ExternalAddress table(table_addr);
2948 #ifdef _LP64
2949     __ lea(rscratch1, table);
2950     __ movptr(index, Address(rscratch1, index, Address::times_ptr));
2951 #else
2952     __ movptr(index, ArrayAddress(table, Address(noreg, index, Address::times_ptr)));
2953 #endif // _LP64
2954   }
2955 
2956   // push return address
2957   __ push(index);
2958 }
2959 
2960 void TemplateTable::load_resolved_method_entry_special_or_static(Register cache,
2961                                                                  Register method,
2962                                                                  Register flags) {
2963   // setup registers
2964   const Register index = rdx;
2965   assert_different_registers(cache, index);
2966   assert_different_registers(method, cache, flags);
2967 
2968   // determine constant pool cache field offsets
2969   resolve_cache_and_index_for_method(f1_byte, cache, index);
2970   __ load_unsigned_byte(flags, Address(cache, in_bytes(ResolvedMethodEntry::flags_offset())));
2971   __ movptr(method, Address(cache, in_bytes(ResolvedMethodEntry::method_offset())));
2972 }
2973 
2974 void TemplateTable::load_resolved_method_entry_handle(Register cache,
2975                                                Register method,
2976                                                Register ref_index,
2977                                                Register flags) {
2978   // setup registers
2979   const Register index = rdx;
2980   assert_different_registers(cache, index);
2981   assert_different_registers(cache, method, ref_index, flags);
2982 
2983   // determine constant pool cache field offsets
2984   resolve_cache_and_index_for_method(f1_byte, cache, index);
2985   __ load_unsigned_byte(flags, Address(cache, in_bytes(ResolvedMethodEntry::flags_offset())));
2986 
2987   // Maybe push appendix
2988   Label L_no_push;
2989   __ testl(flags, (1 << ResolvedMethodEntry::has_appendix_shift));
2990   __ jcc(Assembler::zero, L_no_push);
2991   // invokehandle uses an index into the resolved references array
2992   __ load_unsigned_short(ref_index, Address(cache, in_bytes(ResolvedMethodEntry::resolved_references_index_offset())));
2993   // Push the appendix as a trailing parameter.
2994   // This must be done before we get the receiver,
2995   // since the parameter_size includes it.
2996   Register appendix = method;
2997   __ load_resolved_reference_at_index(appendix, ref_index);
2998   __ push(appendix);  // push appendix (MethodType, CallSite, etc.)
2999   __ bind(L_no_push);
3000 
3001   __ movptr(method, Address(cache, in_bytes(ResolvedMethodEntry::method_offset())));
3002 }
3003 
3004 void TemplateTable::load_resolved_method_entry_interface(Register cache,
3005                                                          Register klass,
3006                                                          Register method_or_table_index,
3007                                                          Register flags) {
3008   // setup registers
3009   const Register index = rdx;
3010   assert_different_registers(cache, klass, method_or_table_index, flags);
3011 
3012   // determine constant pool cache field offsets
3013   resolve_cache_and_index_for_method(f1_byte, cache, index);
3014   __ load_unsigned_byte(flags, Address(cache, in_bytes(ResolvedMethodEntry::flags_offset())));
3015 
3016   // Invokeinterface can behave in different ways:
3017   // If calling a method from java.lang.Object, the forced virtual flag is true so the invocation will
3018   // behave like an invokevirtual call. The state of the virtual final flag will determine whether a method or
3019   // vtable index is placed in the register.
3020   // Otherwise, the registers will be populated with the klass and method.
3021 
3022   Label NotVirtual; Label NotVFinal; Label Done;
3023   __ testl(flags, 1 << ResolvedMethodEntry::is_forced_virtual_shift);
3024   __ jcc(Assembler::zero, NotVirtual);
3025   __ testl(flags, (1 << ResolvedMethodEntry::is_vfinal_shift));
3026   __ jcc(Assembler::zero, NotVFinal);
3027   __ movptr(method_or_table_index, Address(cache, in_bytes(ResolvedMethodEntry::method_offset())));
3028   __ jmp(Done);
3029 
3030   __ bind(NotVFinal);
3031   __ load_unsigned_short(method_or_table_index, Address(cache, in_bytes(ResolvedMethodEntry::table_index_offset())));
3032   __ jmp(Done);
3033 
3034   __ bind(NotVirtual);
3035   __ movptr(method_or_table_index, Address(cache, in_bytes(ResolvedMethodEntry::method_offset())));
3036   __ movptr(klass, Address(cache, in_bytes(ResolvedMethodEntry::klass_offset())));
3037   __ bind(Done);
3038 }
3039 
3040 void TemplateTable::load_resolved_method_entry_virtual(Register cache,
3041                                                        Register method_or_table_index,
3042                                                        Register flags) {
3043   // setup registers
3044   const Register index = rdx;
3045   assert_different_registers(index, cache);
3046   assert_different_registers(method_or_table_index, cache, flags);
3047 
3048   // determine constant pool cache field offsets
3049   resolve_cache_and_index_for_method(f2_byte, cache, index);
3050   __ load_unsigned_byte(flags, Address(cache, in_bytes(ResolvedMethodEntry::flags_offset())));
3051 
3052   // method_or_table_index can either be an itable index or a method depending on the virtual final flag
3053   Label isVFinal; Label Done;
3054   __ testl(flags, (1 << ResolvedMethodEntry::is_vfinal_shift));
3055   __ jcc(Assembler::notZero, isVFinal);
3056   __ load_unsigned_short(method_or_table_index, Address(cache, in_bytes(ResolvedMethodEntry::table_index_offset())));
3057   __ jmp(Done);
3058   __ bind(isVFinal);
3059   __ movptr(method_or_table_index, Address(cache, in_bytes(ResolvedMethodEntry::method_offset())));
3060   __ bind(Done);
3061 }
3062 
3063 // The registers cache and index expected to be set before call.
3064 // Correct values of the cache and index registers are preserved.
3065 void TemplateTable::jvmti_post_field_access(Register cache,
3066                                             Register index,
3067                                             bool is_static,
3068                                             bool has_tos) {
3069   if (JvmtiExport::can_post_field_access()) {
3070     // Check to see if a field access watch has been set before we take
3071     // the time to call into the VM.
3072     Label L1;
3073     assert_different_registers(cache, index, rax);
3074     __ mov32(rax, ExternalAddress((address) JvmtiExport::get_field_access_count_addr()));
3075     __ testl(rax,rax);
3076     __ jcc(Assembler::zero, L1);
3077 
3078     // cache entry pointer
3079     __ load_field_entry(cache, index);
3080     if (is_static) {
3081       __ xorptr(rax, rax);      // null object reference
3082     } else {
3083       __ pop(atos);         // Get the object
3084       __ verify_oop(rax);
3085       __ push(atos);        // Restore stack state
3086     }
3087     // rax,:   object pointer or null
3088     // cache: cache entry pointer
3089     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access),
3090               rax, cache);
3091 
3092     __ load_field_entry(cache, index);
3093     __ bind(L1);
3094   }
3095 }
3096 
3097 void TemplateTable::pop_and_check_object(Register r) {
3098   __ pop_ptr(r);
3099   __ null_check(r);  // for field access must check obj.
3100   __ verify_oop(r);
3101 }
3102 
3103 void TemplateTable::getfield_or_static(int byte_no, bool is_static, RewriteControl rc) {
3104   transition(vtos, vtos);
3105 
3106   const Register obj   = LP64_ONLY(r9) NOT_LP64(rcx);
3107   const Register cache = rcx;
3108   const Register index = rdx;
3109   const Register off   = rbx;
3110   const Register tos_state   = rax;
3111   const Register flags = rdx;
3112   const Register bc    = LP64_ONLY(c_rarg3) NOT_LP64(rcx); // uses same reg as obj, so don't mix them
3113 
3114   resolve_cache_and_index_for_field(byte_no, cache, index);
3115   jvmti_post_field_access(cache, index, is_static, false);
3116   load_resolved_field_entry(obj, cache, tos_state, off, flags, is_static);
3117 
3118   const Address field(obj, off, Address::times_1, 0*wordSize);
3119 
3120   Label Done, notByte, notBool, notInt, notShort, notChar, notLong, notFloat, notObj, notInlineType;
3121 
3122   // Make sure we don't need to mask edx after the above shift
3123   assert(btos == 0, "change code, btos != 0");
3124   __ testl(tos_state, tos_state);
3125   __ jcc(Assembler::notZero, notByte);
3126 
3127   // btos
3128   if (!is_static) pop_and_check_object(obj);
3129   __ access_load_at(T_BYTE, IN_HEAP, rax, field, noreg, noreg);
3130   __ push(btos);
3131   // Rewrite bytecode to be faster
3132   if (!is_static && rc == may_rewrite) {
3133     patch_bytecode(Bytecodes::_fast_bgetfield, bc, rbx);
3134   }
3135   __ jmp(Done);
3136 
3137   __ bind(notByte);
3138   __ cmpl(tos_state, ztos);
3139   __ jcc(Assembler::notEqual, notBool);
3140    if (!is_static) pop_and_check_object(obj);
3141   // ztos (same code as btos)
3142   __ access_load_at(T_BOOLEAN, IN_HEAP, rax, field, noreg, noreg);
3143   __ push(ztos);
3144   // Rewrite bytecode to be faster
3145   if (!is_static && rc == may_rewrite) {
3146     // use btos rewriting, no truncating to t/f bit is needed for getfield.
3147     patch_bytecode(Bytecodes::_fast_bgetfield, bc, rbx);
3148   }
3149   __ jmp(Done);
3150 
3151   __ bind(notBool);
3152   __ cmpl(tos_state, atos);
3153   __ jcc(Assembler::notEqual, notObj);
3154   // atos
3155   if (!EnableValhalla) {
3156     if (!is_static) pop_and_check_object(obj);
3157     do_oop_load(_masm, field, rax);
3158     __ push(atos);
3159     if (!is_static && rc == may_rewrite) {
3160       patch_bytecode(Bytecodes::_fast_agetfield, bc, rbx);
3161     }
3162     __ jmp(Done);
3163   } else {
3164     if (is_static) {
3165       __ load_heap_oop(rax, field);
3166       Label is_null_free_inline_type, uninitialized;
3167       // Issue below if the static field has not been initialized yet
3168       __ test_field_is_null_free_inline_type(flags, rscratch1, is_null_free_inline_type);
3169         // field is not a null free inline type
3170         __ push(atos);
3171         __ jmp(Done);
3172       // field is a null free inline type, must not return null even if uninitialized
3173       __ bind(is_null_free_inline_type);
3174           __ testptr(rax, rax);
3175         __ jcc(Assembler::zero, uninitialized);
3176           __ push(atos);
3177           __ jmp(Done);
3178         __ bind(uninitialized);
3179 #ifdef _LP64
3180           Label slow_case, finish;
3181           __ movptr(rbx, Address(obj, java_lang_Class::klass_offset()));
3182           __ cmpb(Address(rbx, InstanceKlass::init_state_offset()), InstanceKlass::fully_initialized);
3183           __ jcc(Assembler::notEqual, slow_case);
3184         __ get_default_value_oop(rbx, rscratch1, rax);
3185         __ jmp(finish);
3186         __ bind(slow_case);
3187 #endif // LP64
3188           __ call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::uninitialized_static_inline_type_field),
3189                 obj, cache);
3190 #ifdef _LP64
3191           __ bind(finish);
3192   #endif // _LP64
3193         __ verify_oop(rax);
3194         __ push(atos);
3195         __ jmp(Done);
3196     } else {
3197       Label is_flat, nonnull, is_inline_type, rewrite_inline;
3198       __ test_field_is_null_free_inline_type(flags, rscratch1, is_inline_type);
3199       // field is not a null free inline type
3200       pop_and_check_object(obj);
3201       __ load_heap_oop(rax, field);
3202       __ push(atos);
3203       if (rc == may_rewrite) {
3204         patch_bytecode(Bytecodes::_fast_agetfield, bc, rbx);
3205       }
3206       __ jmp(Done);
3207       __ bind(is_inline_type);
3208       __ test_field_is_flat(flags, rscratch1, is_flat);
3209           // field is not flat
3210           pop_and_check_object(obj);
3211           __ load_heap_oop(rax, field);
3212           __ testptr(rax, rax);
3213           __ jcc(Assembler::notZero, nonnull);
3214             __ load_unsigned_short(flags, Address(cache, in_bytes(ResolvedFieldEntry::field_index_offset())));
3215             __ movptr(rcx, Address(cache, ResolvedFieldEntry::field_holder_offset()));
3216             __ get_inline_type_field_klass(rcx, flags, rbx);
3217             __ get_default_value_oop(rbx, rcx, rax);
3218           __ bind(nonnull);
3219           __ verify_oop(rax);
3220           __ push(atos);
3221           __ jmp(rewrite_inline);
3222         __ bind(is_flat);
3223           pop_and_check_object(rax);
3224           __ load_unsigned_short(flags, Address(cache, in_bytes(ResolvedFieldEntry::field_index_offset())));
3225           __ movptr(rcx, Address(cache, ResolvedFieldEntry::field_holder_offset()));
3226           __ read_flat_field(rcx, flags, rbx, rax);
3227           __ verify_oop(rax);
3228           __ push(atos);
3229       __ bind(rewrite_inline);
3230       if (rc == may_rewrite) {
3231         patch_bytecode(Bytecodes::_fast_qgetfield, bc, rbx);
3232       }
3233         __ jmp(Done);
3234     }
3235   }
3236 
3237   __ bind(notObj);
3238 
3239   if (!is_static) pop_and_check_object(obj);
3240 
3241   __ cmpl(tos_state, itos);
3242   __ jcc(Assembler::notEqual, notInt);
3243   // itos
3244   __ access_load_at(T_INT, IN_HEAP, rax, field, noreg, noreg);
3245   __ push(itos);
3246   // Rewrite bytecode to be faster
3247   if (!is_static && rc == may_rewrite) {
3248     patch_bytecode(Bytecodes::_fast_igetfield, bc, rbx);
3249   }
3250   __ jmp(Done);
3251 
3252   __ bind(notInt);
3253   __ cmpl(tos_state, ctos);
3254   __ jcc(Assembler::notEqual, notChar);
3255   // ctos
3256   __ access_load_at(T_CHAR, IN_HEAP, rax, field, noreg, noreg);
3257   __ push(ctos);
3258   // Rewrite bytecode to be faster
3259   if (!is_static && rc == may_rewrite) {
3260     patch_bytecode(Bytecodes::_fast_cgetfield, bc, rbx);
3261   }
3262   __ jmp(Done);
3263 
3264   __ bind(notChar);
3265   __ cmpl(tos_state, stos);
3266   __ jcc(Assembler::notEqual, notShort);
3267   // stos
3268   __ access_load_at(T_SHORT, IN_HEAP, rax, field, noreg, noreg);
3269   __ push(stos);
3270   // Rewrite bytecode to be faster
3271   if (!is_static && rc == may_rewrite) {
3272     patch_bytecode(Bytecodes::_fast_sgetfield, bc, rbx);
3273   }
3274   __ jmp(Done);
3275 
3276   __ bind(notShort);
3277   __ cmpl(tos_state, ltos);
3278   __ jcc(Assembler::notEqual, notLong);
3279   // ltos
3280     // Generate code as if volatile (x86_32).  There just aren't enough registers to
3281     // save that information and this code is faster than the test.
3282   __ access_load_at(T_LONG, IN_HEAP | MO_RELAXED, noreg /* ltos */, field, noreg, noreg);
3283   __ push(ltos);
3284   // Rewrite bytecode to be faster
3285   LP64_ONLY(if (!is_static && rc == may_rewrite) patch_bytecode(Bytecodes::_fast_lgetfield, bc, rbx));
3286   __ jmp(Done);
3287 
3288   __ bind(notLong);
3289   __ cmpl(tos_state, ftos);
3290   __ jcc(Assembler::notEqual, notFloat);
3291   // ftos
3292 
3293   __ access_load_at(T_FLOAT, IN_HEAP, noreg /* ftos */, field, noreg, noreg);
3294   __ push(ftos);
3295   // Rewrite bytecode to be faster
3296   if (!is_static && rc == may_rewrite) {
3297     patch_bytecode(Bytecodes::_fast_fgetfield, bc, rbx);
3298   }
3299   __ jmp(Done);
3300 
3301   __ bind(notFloat);
3302 #ifdef ASSERT
3303   Label notDouble;
3304   __ cmpl(tos_state, dtos);
3305   __ jcc(Assembler::notEqual, notDouble);
3306 #endif
3307   // dtos
3308   // MO_RELAXED: for the case of volatile field, in fact it adds no extra work for the underlying implementation
3309   __ access_load_at(T_DOUBLE, IN_HEAP | MO_RELAXED, noreg /* dtos */, field, noreg, noreg);
3310   __ push(dtos);
3311   // Rewrite bytecode to be faster
3312   if (!is_static && rc == may_rewrite) {
3313     patch_bytecode(Bytecodes::_fast_dgetfield, bc, rbx);
3314   }
3315 #ifdef ASSERT
3316   __ jmp(Done);
3317 
3318   __ bind(notDouble);
3319   __ stop("Bad state");
3320 #endif
3321 
3322   __ bind(Done);
3323   // [jk] not needed currently
3324   // volatile_barrier(Assembler::Membar_mask_bits(Assembler::LoadLoad |
3325   //                                              Assembler::LoadStore));
3326 }
3327 
3328 void TemplateTable::getfield(int byte_no) {
3329   getfield_or_static(byte_no, false);
3330 }
3331 
3332 void TemplateTable::nofast_getfield(int byte_no) {
3333   getfield_or_static(byte_no, false, may_not_rewrite);
3334 }
3335 
3336 void TemplateTable::getstatic(int byte_no) {
3337   getfield_or_static(byte_no, true);
3338 }
3339 
3340 // The registers cache and index expected to be set before call.
3341 // The function may destroy various registers, just not the cache and index registers.
3342 void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
3343   // Cache is rcx and index is rdx
3344   const Register entry = LP64_ONLY(c_rarg2) NOT_LP64(rax); // ResolvedFieldEntry
3345   const Register obj = LP64_ONLY(c_rarg1) NOT_LP64(rbx);   // Object pointer
3346   const Register value = LP64_ONLY(c_rarg3) NOT_LP64(rcx); // JValue object
3347 
3348   if (JvmtiExport::can_post_field_modification()) {
3349     // Check to see if a field modification watch has been set before
3350     // we take the time to call into the VM.
3351     Label L1;
3352     assert_different_registers(cache, obj, rax);
3353     __ mov32(rax, ExternalAddress((address)JvmtiExport::get_field_modification_count_addr()));
3354     __ testl(rax, rax);
3355     __ jcc(Assembler::zero, L1);
3356 
3357     __ mov(entry, cache);
3358 
3359     if (is_static) {
3360       // Life is simple.  Null out the object pointer.
3361       __ xorl(obj, obj);
3362 
3363     } else {
3364       // Life is harder. The stack holds the value on top, followed by
3365       // the object.  We don't know the size of the value, though; it
3366       // could be one or two words depending on its type. As a result,
3367       // we must find the type to determine where the object is.
3368 #ifndef _LP64
3369       Label two_word, valsize_known;
3370 #endif
3371       __ load_unsigned_byte(value, Address(entry, in_bytes(ResolvedFieldEntry::type_offset())));
3372 #ifdef _LP64
3373       __ movptr(obj, at_tos_p1());  // initially assume a one word jvalue
3374       __ cmpl(value, ltos);
3375       __ cmovptr(Assembler::equal,
3376                  obj, at_tos_p2()); // ltos (two word jvalue)
3377       __ cmpl(value, dtos);
3378       __ cmovptr(Assembler::equal,
3379                  obj, at_tos_p2()); // dtos (two word jvalue)
3380 #else
3381       __ mov(obj, rsp);
3382       __ cmpl(value, ltos);
3383       __ jccb(Assembler::equal, two_word);
3384       __ cmpl(value, dtos);
3385       __ jccb(Assembler::equal, two_word);
3386       __ addptr(obj, Interpreter::expr_offset_in_bytes(1)); // one word jvalue (not ltos, dtos)
3387       __ jmpb(valsize_known);
3388 
3389       __ bind(two_word);
3390       __ addptr(obj, Interpreter::expr_offset_in_bytes(2)); // two words jvalue
3391 
3392       __ bind(valsize_known);
3393       // setup object pointer
3394       __ movptr(obj, Address(obj, 0));
3395 #endif
3396     }
3397 
3398     // object (tos)
3399     __ mov(value, rsp);
3400     // obj: object pointer set up above (null if static)
3401     // cache: field entry pointer
3402     // value: jvalue object on the stack
3403     __ call_VM(noreg,
3404               CAST_FROM_FN_PTR(address,
3405                               InterpreterRuntime::post_field_modification),
3406               obj, entry, value);
3407     // Reload field entry
3408     __ load_field_entry(cache, index);
3409     __ bind(L1);
3410   }
3411 }
3412 
3413 void TemplateTable::putfield_or_static(int byte_no, bool is_static, RewriteControl rc) {
3414   transition(vtos, vtos);
3415 
3416   const Register obj = rcx;
3417   const Register cache = rcx;
3418   const Register index = rdx;
3419   const Register tos_state   = rdx;
3420   const Register off   = rbx;
3421   const Register flags = r9;
3422 
3423   resolve_cache_and_index_for_field(byte_no, cache, index);
3424   jvmti_post_field_mod(cache, index, is_static);
3425   load_resolved_field_entry(obj, cache, tos_state, off, flags, is_static);
3426 
3427   // [jk] not needed currently
3428   // volatile_barrier(Assembler::Membar_mask_bits(Assembler::LoadStore |
3429   //                                              Assembler::StoreStore));
3430 
3431   Label notVolatile, Done;
3432 
3433   // Check for volatile store
3434   __ movl(rscratch1, flags);
3435   __ andl(rscratch1, (1 << ResolvedFieldEntry::is_volatile_shift));
3436   __ testl(rscratch1, rscratch1);
3437   __ jcc(Assembler::zero, notVolatile);
3438 
3439   putfield_or_static_helper(byte_no, is_static, rc, obj, off, tos_state, flags);
3440   volatile_barrier(Assembler::Membar_mask_bits(Assembler::StoreLoad |
3441                                                Assembler::StoreStore));
3442   __ jmp(Done);
3443   __ bind(notVolatile);
3444 
3445   putfield_or_static_helper(byte_no, is_static, rc, obj, off, tos_state, flags);
3446 
3447   __ bind(Done);
3448 }
3449 
3450 void TemplateTable::putfield_or_static_helper(int byte_no, bool is_static, RewriteControl rc,
3451                                               Register obj, Register off, Register tos_state, Register flags) {
3452 
3453   // field addresses
3454   const Address field(obj, off, Address::times_1, 0*wordSize);
3455   NOT_LP64( const Address hi(obj, off, Address::times_1, 1*wordSize);)
3456 
3457   Label notByte, notBool, notInt, notShort, notChar,
3458         notLong, notFloat, notObj, notInlineType;
3459   Label Done;
3460 
3461   const Register bc    = LP64_ONLY(c_rarg3) NOT_LP64(rcx);
3462 
3463   // Test TOS state
3464   __ testl(tos_state, tos_state);
3465   __ jcc(Assembler::notZero, notByte);
3466 
3467   // btos
3468   {
3469     __ pop(btos);
3470     if (!is_static) pop_and_check_object(obj);
3471     __ access_store_at(T_BYTE, IN_HEAP, field, rax, noreg, noreg, noreg);
3472     if (!is_static && rc == may_rewrite) {
3473       patch_bytecode(Bytecodes::_fast_bputfield, bc, rbx, true, byte_no);
3474     }
3475     __ jmp(Done);
3476   }
3477 
3478   __ bind(notByte);
3479   __ cmpl(tos_state, ztos);
3480   __ jcc(Assembler::notEqual, notBool);
3481 
3482   // ztos
3483   {
3484     __ pop(ztos);
3485     if (!is_static) pop_and_check_object(obj);
3486     __ access_store_at(T_BOOLEAN, IN_HEAP, field, rax, noreg, noreg, noreg);
3487     if (!is_static && rc == may_rewrite) {
3488       patch_bytecode(Bytecodes::_fast_zputfield, bc, rbx, true, byte_no);
3489     }
3490     __ jmp(Done);
3491   }
3492 
3493   __ bind(notBool);
3494   __ cmpl(tos_state, atos);
3495   __ jcc(Assembler::notEqual, notObj);
3496 
3497   // atos
3498   {
3499     if (!EnableValhalla) {
3500       __ pop(atos);
3501       if (!is_static) pop_and_check_object(obj);
3502       // Store into the field
3503       do_oop_store(_masm, field, rax);
3504       if (!is_static && rc == may_rewrite) {
3505         patch_bytecode(Bytecodes::_fast_aputfield, bc, rbx, true, byte_no);
3506       }
3507       __ jmp(Done);
3508     } else {
3509       __ pop(atos);
3510       if (is_static) {
3511         Label is_inline_type;
3512         __ test_field_is_not_null_free_inline_type(flags, rscratch1, is_inline_type);
3513         __ null_check(rax);
3514         __ bind(is_inline_type);
3515         do_oop_store(_masm, field, rax);
3516         __ jmp(Done);
3517       } else {
3518         Label is_inline_type, is_flat, rewrite_not_inline, rewrite_inline;
3519         __ test_field_is_null_free_inline_type(flags, rscratch1, is_inline_type);
3520         // Not an inline type
3521         pop_and_check_object(obj);
3522         // Store into the field
3523         do_oop_store(_masm, field, rax);
3524         __ bind(rewrite_not_inline);
3525         if (rc == may_rewrite) {
3526           patch_bytecode(Bytecodes::_fast_aputfield, bc, rbx, true, byte_no);
3527         }
3528         __ jmp(Done);
3529         // Implementation of the inline type semantic
3530         __ bind(is_inline_type);
3531         __ null_check(rax);
3532         __ test_field_is_flat(flags, rscratch1, is_flat);
3533         // field is not flat
3534         pop_and_check_object(obj);
3535         // Store into the field
3536         do_oop_store(_masm, field, rax);
3537         __ jmp(rewrite_inline);
3538         __ bind(is_flat);
3539         // field is flat
3540         pop_and_check_object(obj);
3541         assert_different_registers(rax, rdx, obj, off);
3542         __ load_klass(rdx, rax, rscratch1);
3543         __ data_for_oop(rax, rax, rdx);
3544         __ addptr(obj, off);
3545         __ access_value_copy(IN_HEAP, rax, obj, rdx);
3546         __ bind(rewrite_inline);
3547         if (rc == may_rewrite) {
3548           patch_bytecode(Bytecodes::_fast_qputfield, bc, rbx, true, byte_no);
3549         }
3550         __ jmp(Done);
3551       }
3552     }
3553   }
3554 
3555   __ bind(notObj);
3556   __ cmpl(tos_state, itos);
3557   __ jcc(Assembler::notEqual, notInt);
3558 
3559   // itos
3560   {
3561     __ pop(itos);
3562     if (!is_static) pop_and_check_object(obj);
3563     __ access_store_at(T_INT, IN_HEAP, field, rax, noreg, noreg, noreg);
3564     if (!is_static && rc == may_rewrite) {
3565       patch_bytecode(Bytecodes::_fast_iputfield, bc, rbx, true, byte_no);
3566     }
3567     __ jmp(Done);
3568   }
3569 
3570   __ bind(notInt);
3571   __ cmpl(tos_state, ctos);
3572   __ jcc(Assembler::notEqual, notChar);
3573 
3574   // ctos
3575   {
3576     __ pop(ctos);
3577     if (!is_static) pop_and_check_object(obj);
3578     __ access_store_at(T_CHAR, IN_HEAP, field, rax, noreg, noreg, noreg);
3579     if (!is_static && rc == may_rewrite) {
3580       patch_bytecode(Bytecodes::_fast_cputfield, bc, rbx, true, byte_no);
3581     }
3582     __ jmp(Done);
3583   }
3584 
3585   __ bind(notChar);
3586   __ cmpl(tos_state, stos);
3587   __ jcc(Assembler::notEqual, notShort);
3588 
3589   // stos
3590   {
3591     __ pop(stos);
3592     if (!is_static) pop_and_check_object(obj);
3593     __ access_store_at(T_SHORT, IN_HEAP, field, rax, noreg, noreg, noreg);
3594     if (!is_static && rc == may_rewrite) {
3595       patch_bytecode(Bytecodes::_fast_sputfield, bc, rbx, true, byte_no);
3596     }
3597     __ jmp(Done);
3598   }
3599 
3600   __ bind(notShort);
3601   __ cmpl(tos_state, ltos);
3602   __ jcc(Assembler::notEqual, notLong);
3603 
3604   // ltos
3605   {
3606     __ pop(ltos);
3607     if (!is_static) pop_and_check_object(obj);
3608     // MO_RELAXED: generate atomic store for the case of volatile field (important for x86_32)
3609     __ access_store_at(T_LONG, IN_HEAP | MO_RELAXED, field, noreg /* ltos*/, noreg, noreg, noreg);
3610 #ifdef _LP64
3611     if (!is_static && rc == may_rewrite) {
3612       patch_bytecode(Bytecodes::_fast_lputfield, bc, rbx, true, byte_no);
3613     }
3614 #endif // _LP64
3615     __ jmp(Done);
3616   }
3617 
3618   __ bind(notLong);
3619   __ cmpl(tos_state, ftos);
3620   __ jcc(Assembler::notEqual, notFloat);
3621 
3622   // ftos
3623   {
3624     __ pop(ftos);
3625     if (!is_static) pop_and_check_object(obj);
3626     __ access_store_at(T_FLOAT, IN_HEAP, field, noreg /* ftos */, noreg, noreg, noreg);
3627     if (!is_static && rc == may_rewrite) {
3628       patch_bytecode(Bytecodes::_fast_fputfield, bc, rbx, true, byte_no);
3629     }
3630     __ jmp(Done);
3631   }
3632 
3633   __ bind(notFloat);
3634 #ifdef ASSERT
3635   Label notDouble;
3636   __ cmpl(tos_state, dtos);
3637   __ jcc(Assembler::notEqual, notDouble);
3638 #endif
3639 
3640   // dtos
3641   {
3642     __ pop(dtos);
3643     if (!is_static) pop_and_check_object(obj);
3644     // MO_RELAXED: for the case of volatile field, in fact it adds no extra work for the underlying implementation
3645     __ access_store_at(T_DOUBLE, IN_HEAP | MO_RELAXED, field, noreg /* dtos */, noreg, noreg, noreg);
3646     if (!is_static && rc == may_rewrite) {
3647       patch_bytecode(Bytecodes::_fast_dputfield, bc, rbx, true, byte_no);
3648     }
3649   }
3650 
3651 #ifdef ASSERT
3652   __ jmp(Done);
3653 
3654   __ bind(notDouble);
3655   __ stop("Bad state");
3656 #endif
3657 
3658   __ bind(Done);
3659 }
3660 
3661 void TemplateTable::putfield(int byte_no) {
3662   putfield_or_static(byte_no, false);
3663 }
3664 
3665 void TemplateTable::nofast_putfield(int byte_no) {
3666   putfield_or_static(byte_no, false, may_not_rewrite);
3667 }
3668 
3669 void TemplateTable::putstatic(int byte_no) {
3670   putfield_or_static(byte_no, true);
3671 }
3672 
3673 void TemplateTable::jvmti_post_fast_field_mod() {
3674 
3675   const Register scratch = LP64_ONLY(c_rarg3) NOT_LP64(rcx);
3676 
3677   if (JvmtiExport::can_post_field_modification()) {
3678     // Check to see if a field modification watch has been set before
3679     // we take the time to call into the VM.
3680     Label L2;
3681     __ mov32(scratch, ExternalAddress((address)JvmtiExport::get_field_modification_count_addr()));
3682     __ testl(scratch, scratch);
3683     __ jcc(Assembler::zero, L2);
3684     __ pop_ptr(rbx);                  // copy the object pointer from tos
3685     __ verify_oop(rbx);
3686     __ push_ptr(rbx);                 // put the object pointer back on tos
3687     // Save tos values before call_VM() clobbers them. Since we have
3688     // to do it for every data type, we use the saved values as the
3689     // jvalue object.
3690     switch (bytecode()) {          // load values into the jvalue object
3691     case Bytecodes::_fast_qputfield: //fall through
3692     case Bytecodes::_fast_aputfield: __ push_ptr(rax); break;
3693     case Bytecodes::_fast_bputfield: // fall through
3694     case Bytecodes::_fast_zputfield: // fall through
3695     case Bytecodes::_fast_sputfield: // fall through
3696     case Bytecodes::_fast_cputfield: // fall through
3697     case Bytecodes::_fast_iputfield: __ push_i(rax); break;
3698     case Bytecodes::_fast_dputfield: __ push(dtos); break;
3699     case Bytecodes::_fast_fputfield: __ push(ftos); break;
3700     case Bytecodes::_fast_lputfield: __ push_l(rax); break;
3701 
3702     default:
3703       ShouldNotReachHere();
3704     }
3705     __ mov(scratch, rsp);             // points to jvalue on the stack
3706     // access constant pool cache entry
3707     LP64_ONLY(__ load_field_entry(c_rarg2, rax));
3708     NOT_LP64(__ load_field_entry(rax, rdx));
3709     __ verify_oop(rbx);
3710     // rbx: object pointer copied above
3711     // c_rarg2: cache entry pointer
3712     // c_rarg3: jvalue object on the stack
3713     LP64_ONLY(__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification), rbx, c_rarg2, c_rarg3));
3714     NOT_LP64(__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification), rbx, rax, rcx));
3715 
3716     switch (bytecode()) {             // restore tos values
3717     case Bytecodes::_fast_qputfield: // fall through
3718     case Bytecodes::_fast_aputfield: __ pop_ptr(rax); break;
3719     case Bytecodes::_fast_bputfield: // fall through
3720     case Bytecodes::_fast_zputfield: // fall through
3721     case Bytecodes::_fast_sputfield: // fall through
3722     case Bytecodes::_fast_cputfield: // fall through
3723     case Bytecodes::_fast_iputfield: __ pop_i(rax); break;
3724     case Bytecodes::_fast_dputfield: __ pop(dtos); break;
3725     case Bytecodes::_fast_fputfield: __ pop(ftos); break;
3726     case Bytecodes::_fast_lputfield: __ pop_l(rax); break;
3727     default: break;
3728     }
3729     __ bind(L2);
3730   }
3731 }
3732 
3733 void TemplateTable::fast_storefield(TosState state) {
3734   transition(state, vtos);
3735 
3736   Register cache = rcx;
3737 
3738   Label notVolatile, Done;
3739 
3740   jvmti_post_fast_field_mod();
3741 
3742   __ push(rax);
3743   __ load_field_entry(rcx, rax);
3744   load_resolved_field_entry(noreg, cache, rax, rbx, rdx);
3745   __ pop(rax);
3746   // RBX: field offset, RCX: RAX: TOS, RDX: flags
3747 
3748   // Get object from stack
3749   pop_and_check_object(rcx);
3750 
3751   // field address
3752   const Address field(rcx, rbx, Address::times_1);
3753 
3754   // Check for volatile store
3755   __ movl(rscratch2, rdx);  // saving flags for is_flat test
3756   __ andl(rscratch2, (1 << ResolvedFieldEntry::is_volatile_shift));
3757   __ testl(rscratch2, rscratch2);
3758   __ jcc(Assembler::zero, notVolatile);
3759 
3760   fast_storefield_helper(field, rax, rdx);
3761   volatile_barrier(Assembler::Membar_mask_bits(Assembler::StoreLoad |
3762                                                Assembler::StoreStore));
3763   __ jmp(Done);
3764   __ bind(notVolatile);
3765 
3766   fast_storefield_helper(field, rax, rdx);
3767 
3768   __ bind(Done);
3769 }
3770 
3771 void TemplateTable::fast_storefield_helper(Address field, Register rax, Register flags) {
3772 
3773   // access field
3774   switch (bytecode()) {
3775   case Bytecodes::_fast_qputfield:
3776     {
3777       Label is_flat, done;
3778       __ null_check(rax);
3779       __ test_field_is_flat(flags, rscratch1, is_flat);
3780       // field is not flat
3781       do_oop_store(_masm, field, rax);
3782       __ jmp(done);
3783       __ bind(is_flat);
3784       // field is flat
3785       __ load_klass(rdx, rax, rscratch1);
3786       __ data_for_oop(rax, rax, rdx);
3787       __ lea(rcx, field);
3788       __ access_value_copy(IN_HEAP, rax, rcx, rdx);
3789       __ bind(done);
3790     }
3791     break;
3792   case Bytecodes::_fast_aputfield:
3793     {
3794       do_oop_store(_masm, field, rax);
3795     }
3796     break;
3797   case Bytecodes::_fast_lputfield:
3798 #ifdef _LP64
3799     __ access_store_at(T_LONG, IN_HEAP, field, noreg /* ltos */, noreg, noreg, noreg);
3800 #else
3801   __ stop("should not be rewritten");
3802 #endif
3803     break;
3804   case Bytecodes::_fast_iputfield:
3805     __ access_store_at(T_INT, IN_HEAP, field, rax, noreg, noreg, noreg);
3806     break;
3807   case Bytecodes::_fast_zputfield:
3808     __ access_store_at(T_BOOLEAN, IN_HEAP, field, rax, noreg, noreg, noreg);
3809     break;
3810   case Bytecodes::_fast_bputfield:
3811     __ access_store_at(T_BYTE, IN_HEAP, field, rax, noreg, noreg, noreg);
3812     break;
3813   case Bytecodes::_fast_sputfield:
3814     __ access_store_at(T_SHORT, IN_HEAP, field, rax, noreg, noreg, noreg);
3815     break;
3816   case Bytecodes::_fast_cputfield:
3817     __ access_store_at(T_CHAR, IN_HEAP, field, rax, noreg, noreg, noreg);
3818     break;
3819   case Bytecodes::_fast_fputfield:
3820     __ access_store_at(T_FLOAT, IN_HEAP, field, noreg /* ftos*/, noreg, noreg, noreg);
3821     break;
3822   case Bytecodes::_fast_dputfield:
3823     __ access_store_at(T_DOUBLE, IN_HEAP, field, noreg /* dtos*/, noreg, noreg, noreg);
3824     break;
3825   default:
3826     ShouldNotReachHere();
3827   }
3828 }
3829 
3830 void TemplateTable::fast_accessfield(TosState state) {
3831   transition(atos, state);
3832 
3833   // Do the JVMTI work here to avoid disturbing the register state below
3834   if (JvmtiExport::can_post_field_access()) {
3835     // Check to see if a field access watch has been set before we
3836     // take the time to call into the VM.
3837     Label L1;
3838     __ mov32(rcx, ExternalAddress((address) JvmtiExport::get_field_access_count_addr()));
3839     __ testl(rcx, rcx);
3840     __ jcc(Assembler::zero, L1);
3841     // access constant pool cache entry
3842     LP64_ONLY(__ load_field_entry(c_rarg2, rcx));
3843     NOT_LP64(__ load_field_entry(rcx, rdx));
3844     __ verify_oop(rax);
3845     __ push_ptr(rax);  // save object pointer before call_VM() clobbers it
3846     LP64_ONLY(__ mov(c_rarg1, rax));
3847     // c_rarg1: object pointer copied above
3848     // c_rarg2: cache entry pointer
3849     LP64_ONLY(__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access), c_rarg1, c_rarg2));
3850     NOT_LP64(__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access), rax, rcx));
3851     __ pop_ptr(rax); // restore object pointer
3852     __ bind(L1);
3853   }
3854 
3855   // access constant pool cache
3856   __ load_field_entry(rcx, rbx);
3857   __ load_sized_value(rdx, Address(rcx, in_bytes(ResolvedFieldEntry::field_offset_offset())), sizeof(int), true /*is_signed*/);
3858 
3859   // rax: object
3860   __ verify_oop(rax);
3861   __ null_check(rax);
3862   Address field(rax, rdx, Address::times_1);
3863 
3864   // access field
3865   switch (bytecode()) {
3866   case Bytecodes::_fast_qgetfield:
3867     {
3868       Label is_flat, nonnull, Done;
3869       __ load_unsigned_byte(rscratch1, Address(rcx, in_bytes(ResolvedFieldEntry::flags_offset())));
3870       __ test_field_is_flat(rscratch1, rscratch2, is_flat);
3871         // field is not flat
3872         __ load_heap_oop(rax, field);
3873         __ testptr(rax, rax);
3874         __ jcc(Assembler::notZero, nonnull);
3875           __ load_unsigned_short(rdx, Address(rcx, in_bytes(ResolvedFieldEntry::field_index_offset())));
3876           __ movptr(rcx, Address(rcx, ResolvedFieldEntry::field_holder_offset()));
3877           __ get_inline_type_field_klass(rcx, rdx, rbx);
3878           __ get_default_value_oop(rbx, rcx, rax);
3879         __ bind(nonnull);
3880         __ verify_oop(rax);
3881         __ jmp(Done);
3882       __ bind(is_flat);
3883       // field is flat
3884         __ push(rdx); // save offset
3885         __ load_unsigned_short(rdx, Address(rcx, in_bytes(ResolvedFieldEntry::field_index_offset())));
3886         __ movptr(rcx, Address(rcx, ResolvedFieldEntry::field_holder_offset()));
3887         __ pop(rbx); // restore offset
3888         __ read_flat_field(rcx, rdx, rbx, rax);
3889       __ bind(Done);
3890       __ verify_oop(rax);
3891     }
3892     break;
3893   case Bytecodes::_fast_agetfield:
3894     do_oop_load(_masm, field, rax);
3895     __ verify_oop(rax);
3896     break;
3897   case Bytecodes::_fast_lgetfield:
3898 #ifdef _LP64
3899     __ access_load_at(T_LONG, IN_HEAP, noreg /* ltos */, field, noreg, noreg);
3900 #else
3901   __ stop("should not be rewritten");
3902 #endif
3903     break;
3904   case Bytecodes::_fast_igetfield:
3905     __ access_load_at(T_INT, IN_HEAP, rax, field, noreg, noreg);
3906     break;
3907   case Bytecodes::_fast_bgetfield:
3908     __ access_load_at(T_BYTE, IN_HEAP, rax, field, noreg, noreg);
3909     break;
3910   case Bytecodes::_fast_sgetfield:
3911     __ access_load_at(T_SHORT, IN_HEAP, rax, field, noreg, noreg);
3912     break;
3913   case Bytecodes::_fast_cgetfield:
3914     __ access_load_at(T_CHAR, IN_HEAP, rax, field, noreg, noreg);
3915     break;
3916   case Bytecodes::_fast_fgetfield:
3917     __ access_load_at(T_FLOAT, IN_HEAP, noreg /* ftos */, field, noreg, noreg);
3918     break;
3919   case Bytecodes::_fast_dgetfield:
3920     __ access_load_at(T_DOUBLE, IN_HEAP, noreg /* dtos */, field, noreg, noreg);
3921     break;
3922   default:
3923     ShouldNotReachHere();
3924   }
3925   // [jk] not needed currently
3926   //   Label notVolatile;
3927   //   __ testl(rdx, rdx);
3928   //   __ jcc(Assembler::zero, notVolatile);
3929   //   __ membar(Assembler::LoadLoad);
3930   //   __ bind(notVolatile);
3931 }
3932 
3933 void TemplateTable::fast_xaccess(TosState state) {
3934   transition(vtos, state);
3935 
3936   // get receiver
3937   __ movptr(rax, aaddress(0));
3938   // access constant pool cache
3939   __ load_field_entry(rcx, rdx, 2);
3940   __ load_sized_value(rbx, Address(rcx, in_bytes(ResolvedFieldEntry::field_offset_offset())), sizeof(int), true /*is_signed*/);
3941 
3942   // make sure exception is reported in correct bcp range (getfield is
3943   // next instruction)
3944   __ increment(rbcp);
3945   __ null_check(rax);
3946   const Address field = Address(rax, rbx, Address::times_1, 0*wordSize);
3947   switch (state) {
3948   case itos:
3949     __ access_load_at(T_INT, IN_HEAP, rax, field, noreg, noreg);
3950     break;
3951   case atos:
3952     do_oop_load(_masm, field, rax);
3953     __ verify_oop(rax);
3954     break;
3955   case ftos:
3956     __ access_load_at(T_FLOAT, IN_HEAP, noreg /* ftos */, field, noreg, noreg);
3957     break;
3958   default:
3959     ShouldNotReachHere();
3960   }
3961 
3962   // [jk] not needed currently
3963   // Label notVolatile;
3964   // __ movl(rdx, Address(rcx, rdx, Address::times_8,
3965   //                      in_bytes(ConstantPoolCache::base_offset() +
3966   //                               ConstantPoolCacheEntry::flags_offset())));
3967   // __ shrl(rdx, ConstantPoolCacheEntry::is_volatile_shift);
3968   // __ testl(rdx, 0x1);
3969   // __ jcc(Assembler::zero, notVolatile);
3970   // __ membar(Assembler::LoadLoad);
3971   // __ bind(notVolatile);
3972 
3973   __ decrement(rbcp);
3974 }
3975 
3976 //-----------------------------------------------------------------------------
3977 // Calls
3978 
3979 void TemplateTable::prepare_invoke(Register cache, Register recv, Register flags) {
3980   // determine flags
3981   const Bytecodes::Code code = bytecode();
3982   const bool load_receiver       = (code != Bytecodes::_invokestatic) && (code != Bytecodes::_invokedynamic);
3983   assert_different_registers(recv, flags);
3984 
3985   // save 'interpreter return address'
3986   __ save_bcp();
3987 
3988   // Save flags and load TOS
3989   __ movl(rbcp, flags);
3990   __ load_unsigned_byte(flags, Address(cache, in_bytes(ResolvedMethodEntry::type_offset())));
3991 
3992   // load receiver if needed (after appendix is pushed so parameter size is correct)
3993   // Note: no return address pushed yet
3994   if (load_receiver) {
3995     __ load_unsigned_short(recv, Address(cache, in_bytes(ResolvedMethodEntry::num_parameters_offset())));
3996     const int no_return_pc_pushed_yet = -1;  // argument slot correction before we push return address
3997     const int receiver_is_at_end      = -1;  // back off one slot to get receiver
3998     Address recv_addr = __ argument_address(recv, no_return_pc_pushed_yet + receiver_is_at_end);
3999     __ movptr(recv, recv_addr);
4000     __ verify_oop(recv);
4001   }
4002 
4003   // load return address
4004   {
4005     const address table_addr = (address) Interpreter::invoke_return_entry_table_for(code);
4006     ExternalAddress table(table_addr);
4007 #ifdef _LP64
4008     __ lea(rscratch1, table);
4009     __ movptr(flags, Address(rscratch1, flags, Address::times_ptr));
4010 #else
4011     __ movptr(flags, ArrayAddress(table, Address(noreg, flags, Address::times_ptr)));
4012 #endif // _LP64
4013   }
4014 
4015   // push return address
4016   __ push(flags);
4017 
4018   // Restore flags value from the constant pool cache entry, and restore rsi
4019   // for later null checks.  r13 is the bytecode pointer
4020   __ movl(flags, rbcp);
4021   __ restore_bcp();
4022 }
4023 
4024 void TemplateTable::invokevirtual_helper(Register index,
4025                                          Register recv,
4026                                          Register flags) {
4027   // Uses temporary registers rax, rdx
4028   assert_different_registers(index, recv, rax, rdx);
4029   assert(index == rbx, "");
4030   assert(recv  == rcx, "");
4031 
4032   // Test for an invoke of a final method
4033   Label notFinal;
4034   __ movl(rax, flags);
4035   __ andl(rax, (1 << ResolvedMethodEntry::is_vfinal_shift));
4036   __ jcc(Assembler::zero, notFinal);
4037 
4038   const Register method = index;  // method must be rbx
4039   assert(method == rbx,
4040          "Method* must be rbx for interpreter calling convention");
4041 
4042   // do the call - the index is actually the method to call
4043   // that is, f2 is a vtable index if !is_vfinal, else f2 is a Method*
4044 
4045   // It's final, need a null check here!
4046   __ null_check(recv);
4047 
4048   // profile this call
4049   __ profile_final_call(rax);
4050   __ profile_arguments_type(rax, method, rbcp, true);
4051 
4052   __ jump_from_interpreted(method, rax);
4053 
4054   __ bind(notFinal);
4055 
4056   // get receiver klass
4057   __ load_klass(rax, recv, rscratch1);
4058 
4059   // profile this call
4060   __ profile_virtual_call(rax, rlocals, rdx);
4061   // get target Method* & entry point
4062   __ lookup_virtual_method(rax, index, method);
4063 
4064   __ profile_arguments_type(rdx, method, rbcp, true);
4065   __ jump_from_interpreted(method, rdx);
4066 }
4067 
4068 void TemplateTable::invokevirtual(int byte_no) {
4069   transition(vtos, vtos);
4070   assert(byte_no == f2_byte, "use this argument");
4071 
4072   load_resolved_method_entry_virtual(rcx,  // ResolvedMethodEntry*
4073                                      rbx,  // Method or itable index
4074                                      rdx); // Flags
4075   prepare_invoke(rcx,  // ResolvedMethodEntry*
4076                  rcx,  // Receiver
4077                  rdx); // flags
4078 
4079   // rbx: index
4080   // rcx: receiver
4081   // rdx: flags
4082   invokevirtual_helper(rbx, rcx, rdx);
4083 }
4084 
4085 void TemplateTable::invokespecial(int byte_no) {
4086   transition(vtos, vtos);
4087   assert(byte_no == f1_byte, "use this argument");
4088 
4089   load_resolved_method_entry_special_or_static(rcx,  // ResolvedMethodEntry*
4090                                                rbx,  // Method*
4091                                                rdx); // flags
4092   prepare_invoke(rcx,
4093                  rcx,  // get receiver also for null check
4094                  rdx); // flags
4095 
4096   __ verify_oop(rcx);
4097   __ null_check(rcx);
4098   // do the call
4099   __ profile_call(rax);
4100   __ profile_arguments_type(rax, rbx, rbcp, false);
4101   __ jump_from_interpreted(rbx, rax);
4102 }
4103 
4104 void TemplateTable::invokestatic(int byte_no) {
4105   transition(vtos, vtos);
4106   assert(byte_no == f1_byte, "use this argument");
4107 
4108   load_resolved_method_entry_special_or_static(rcx, // ResolvedMethodEntry*
4109                                                rbx, // Method*
4110                                                rdx  // flags
4111                                                );
4112   prepare_invoke(rcx, rcx, rdx);  // cache and flags
4113 
4114   // do the call
4115   __ profile_call(rax);
4116   __ profile_arguments_type(rax, rbx, rbcp, false);
4117   __ jump_from_interpreted(rbx, rax);
4118 }
4119 
4120 
4121 void TemplateTable::fast_invokevfinal(int byte_no) {
4122   transition(vtos, vtos);
4123   assert(byte_no == f2_byte, "use this argument");
4124   __ stop("fast_invokevfinal not used on x86");
4125 }
4126 
4127 
4128 void TemplateTable::invokeinterface(int byte_no) {
4129   transition(vtos, vtos);
4130   assert(byte_no == f1_byte, "use this argument");
4131 
4132   load_resolved_method_entry_interface(rcx,  // ResolvedMethodEntry*
4133                                        rax,  // Klass*
4134                                        rbx,  // Method* or itable/vtable index
4135                                        rdx); // flags
4136   prepare_invoke(rcx, rcx, rdx); // receiver, flags
4137 
4138   // First check for Object case, then private interface method,
4139   // then regular interface method.
4140 
4141   // Special case of invokeinterface called for virtual method of
4142   // java.lang.Object.  See cpCache.cpp for details.
4143   Label notObjectMethod;
4144   __ movl(rlocals, rdx);
4145   __ andl(rlocals, (1 << ResolvedMethodEntry::is_forced_virtual_shift));
4146   __ jcc(Assembler::zero, notObjectMethod);
4147 
4148   invokevirtual_helper(rbx, rcx, rdx);
4149   // no return from above
4150   __ bind(notObjectMethod);
4151 
4152   Label no_such_interface; // for receiver subtype check
4153   Register recvKlass; // used for exception processing
4154 
4155   // Check for private method invocation - indicated by vfinal
4156   Label notVFinal;
4157   __ movl(rlocals, rdx);
4158   __ andl(rlocals, (1 << ResolvedMethodEntry::is_vfinal_shift));
4159   __ jcc(Assembler::zero, notVFinal);
4160 
4161   // Get receiver klass into rlocals - also a null check
4162   __ load_klass(rlocals, rcx, rscratch1);
4163 
4164   Label subtype;
4165   __ check_klass_subtype(rlocals, rax, rbcp, subtype);
4166   // If we get here the typecheck failed
4167   recvKlass = rdx;
4168   __ mov(recvKlass, rlocals); // shuffle receiver class for exception use
4169   __ jmp(no_such_interface);
4170 
4171   __ bind(subtype);
4172 
4173   // do the call - rbx is actually the method to call
4174 
4175   __ profile_final_call(rdx);
4176   __ profile_arguments_type(rdx, rbx, rbcp, true);
4177 
4178   __ jump_from_interpreted(rbx, rdx);
4179   // no return from above
4180   __ bind(notVFinal);
4181 
4182   // Get receiver klass into rdx - also a null check
4183   __ restore_locals();  // restore r14
4184   __ load_klass(rdx, rcx, rscratch1);
4185 
4186   Label no_such_method;
4187 
4188   // Preserve method for throw_AbstractMethodErrorVerbose.
4189   __ mov(rcx, rbx);
4190   // Receiver subtype check against REFC.
4191   // Superklass in rax. Subklass in rdx. Blows rcx, rdi.
4192   __ lookup_interface_method(// inputs: rec. class, interface, itable index
4193                              rdx, rax, noreg,
4194                              // outputs: scan temp. reg, scan temp. reg
4195                              rbcp, rlocals,
4196                              no_such_interface,
4197                              /*return_method=*/false);
4198 
4199   // profile this call
4200   __ restore_bcp(); // rbcp was destroyed by receiver type check
4201   __ profile_virtual_call(rdx, rbcp, rlocals);
4202 
4203   // Get declaring interface class from method, and itable index
4204   __ load_method_holder(rax, rbx);
4205   __ movl(rbx, Address(rbx, Method::itable_index_offset()));
4206   __ subl(rbx, Method::itable_index_max);
4207   __ negl(rbx);
4208 
4209   // Preserve recvKlass for throw_AbstractMethodErrorVerbose.
4210   __ mov(rlocals, rdx);
4211   __ lookup_interface_method(// inputs: rec. class, interface, itable index
4212                              rlocals, rax, rbx,
4213                              // outputs: method, scan temp. reg
4214                              rbx, rbcp,
4215                              no_such_interface);
4216 
4217   // rbx: Method* to call
4218   // rcx: receiver
4219   // Check for abstract method error
4220   // Note: This should be done more efficiently via a throw_abstract_method_error
4221   //       interpreter entry point and a conditional jump to it in case of a null
4222   //       method.
4223   __ testptr(rbx, rbx);
4224   __ jcc(Assembler::zero, no_such_method);
4225 
4226   __ profile_arguments_type(rdx, rbx, rbcp, true);
4227 
4228   // do the call
4229   // rcx: receiver
4230   // rbx,: Method*
4231   __ jump_from_interpreted(rbx, rdx);
4232   __ should_not_reach_here();
4233 
4234   // exception handling code follows...
4235   // note: must restore interpreter registers to canonical
4236   //       state for exception handling to work correctly!
4237 
4238   __ bind(no_such_method);
4239   // throw exception
4240   __ pop(rbx);           // pop return address (pushed by prepare_invoke)
4241   __ restore_bcp();      // rbcp must be correct for exception handler   (was destroyed)
4242   __ restore_locals();   // make sure locals pointer is correct as well (was destroyed)
4243   // Pass arguments for generating a verbose error message.
4244 #ifdef _LP64
4245   recvKlass = c_rarg1;
4246   Register method    = c_rarg2;
4247   if (recvKlass != rdx) { __ movq(recvKlass, rdx); }
4248   if (method != rcx)    { __ movq(method, rcx);    }
4249 #else
4250   recvKlass = rdx;
4251   Register method    = rcx;
4252 #endif
4253   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodErrorVerbose),
4254              recvKlass, method);
4255   // The call_VM checks for exception, so we should never return here.
4256   __ should_not_reach_here();
4257 
4258   __ bind(no_such_interface);
4259   // throw exception
4260   __ pop(rbx);           // pop return address (pushed by prepare_invoke)
4261   __ restore_bcp();      // rbcp must be correct for exception handler   (was destroyed)
4262   __ restore_locals();   // make sure locals pointer is correct as well (was destroyed)
4263   // Pass arguments for generating a verbose error message.
4264   LP64_ONLY( if (recvKlass != rdx) { __ movq(recvKlass, rdx); } )
4265   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_IncompatibleClassChangeErrorVerbose),
4266              recvKlass, rax);
4267   // the call_VM checks for exception, so we should never return here.
4268   __ should_not_reach_here();
4269 }
4270 
4271 void TemplateTable::invokehandle(int byte_no) {
4272   transition(vtos, vtos);
4273   assert(byte_no == f1_byte, "use this argument");
4274   const Register rbx_method = rbx;
4275   const Register rax_mtype  = rax;
4276   const Register rcx_recv   = rcx;
4277   const Register rdx_flags  = rdx;
4278 
4279   load_resolved_method_entry_handle(rcx, rbx_method, rax_mtype, rdx_flags);
4280   prepare_invoke(rcx, rcx_recv, rdx_flags);
4281 
4282   __ verify_method_ptr(rbx_method);
4283   __ verify_oop(rcx_recv);
4284   __ null_check(rcx_recv);
4285 
4286   // rax: MethodType object (from cpool->resolved_references[f1], if necessary)
4287   // rbx: MH.invokeExact_MT method
4288 
4289   // Note:  rax_mtype is already pushed (if necessary)
4290 
4291   // FIXME: profile the LambdaForm also
4292   __ profile_final_call(rax);
4293   __ profile_arguments_type(rdx, rbx_method, rbcp, true);
4294 
4295   __ jump_from_interpreted(rbx_method, rdx);
4296 }
4297 
4298 void TemplateTable::invokedynamic(int byte_no) {
4299   transition(vtos, vtos);
4300   assert(byte_no == f1_byte, "use this argument");
4301 
4302   const Register rbx_method   = rbx;
4303   const Register rax_callsite = rax;
4304 
4305   load_invokedynamic_entry(rbx_method);
4306   // rax: CallSite object (from cpool->resolved_references[])
4307   // rbx: MH.linkToCallSite method
4308 
4309   // Note:  rax_callsite is already pushed
4310 
4311   // %%% should make a type profile for any invokedynamic that takes a ref argument
4312   // profile this call
4313   __ profile_call(rbcp);
4314   __ profile_arguments_type(rdx, rbx_method, rbcp, false);
4315 
4316   __ verify_oop(rax_callsite);
4317 
4318   __ jump_from_interpreted(rbx_method, rdx);
4319 }
4320 
4321 //-----------------------------------------------------------------------------
4322 // Allocation
4323 
4324 void TemplateTable::_new() {
4325   transition(vtos, atos);
4326   __ get_unsigned_2_byte_index_at_bcp(rdx, 1);
4327   Label slow_case;
4328   Label done;
4329 
4330   __ get_cpool_and_tags(rcx, rax);
4331 
4332   // Make sure the class we're about to instantiate has been resolved.
4333   // This is done before loading InstanceKlass to be consistent with the order
4334   // how Constant Pool is updated (see ConstantPool::klass_at_put)
4335   const int tags_offset = Array<u1>::base_offset_in_bytes();
4336   __ cmpb(Address(rax, rdx, Address::times_1, tags_offset), JVM_CONSTANT_Class);
4337   __ jcc(Assembler::notEqual, slow_case);
4338 
4339   // get InstanceKlass
4340   __ load_resolved_klass_at_index(rcx, rcx, rdx);
4341 
4342   // make sure klass is initialized & doesn't have finalizer
4343   __ cmpb(Address(rcx, InstanceKlass::init_state_offset()), InstanceKlass::fully_initialized);
4344   __ jcc(Assembler::notEqual, slow_case);
4345 
4346   __ allocate_instance(rcx, rax, rdx, rbx, true, slow_case);
4347   __ jmp(done);
4348 
4349   // slow case
4350   __ bind(slow_case);
4351 
4352   Register rarg1 = LP64_ONLY(c_rarg1) NOT_LP64(rax);
4353   Register rarg2 = LP64_ONLY(c_rarg2) NOT_LP64(rdx);
4354 
4355   __ get_constant_pool(rarg1);
4356   __ get_unsigned_2_byte_index_at_bcp(rarg2, 1);
4357   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), rarg1, rarg2);
4358    __ verify_oop(rax);
4359 
4360   // continue
4361   __ bind(done);
4362 }
4363 
4364 void TemplateTable::newarray() {
4365   transition(itos, atos);
4366   Register rarg1 = LP64_ONLY(c_rarg1) NOT_LP64(rdx);
4367   __ load_unsigned_byte(rarg1, at_bcp(1));
4368   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::newarray),
4369           rarg1, rax);
4370 }
4371 
4372 void TemplateTable::anewarray() {
4373   transition(itos, atos);
4374 
4375   Register rarg1 = LP64_ONLY(c_rarg1) NOT_LP64(rcx);
4376   Register rarg2 = LP64_ONLY(c_rarg2) NOT_LP64(rdx);
4377 
4378   __ get_unsigned_2_byte_index_at_bcp(rarg2, 1);
4379   __ get_constant_pool(rarg1);
4380   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::anewarray),
4381           rarg1, rarg2, rax);
4382 }
4383 
4384 void TemplateTable::arraylength() {
4385   transition(atos, itos);
4386   __ movl(rax, Address(rax, arrayOopDesc::length_offset_in_bytes()));
4387 }
4388 
4389 void TemplateTable::checkcast() {
4390   transition(atos, atos);
4391   Label done, is_null, ok_is_subtype, quicked, resolved;
4392   __ testptr(rax, rax); // object is in rax
4393   __ jcc(Assembler::zero, is_null);
4394 
4395   // Get cpool & tags index
4396   __ get_cpool_and_tags(rcx, rdx); // rcx=cpool, rdx=tags array
4397   __ get_unsigned_2_byte_index_at_bcp(rbx, 1); // rbx=index
4398   // See if bytecode has already been quicked
4399   __ movzbl(rdx, Address(rdx, rbx,
4400       Address::times_1,
4401       Array<u1>::base_offset_in_bytes()));
4402   __ cmpl(rdx, JVM_CONSTANT_Class);
4403   __ jcc(Assembler::equal, quicked);
4404   __ push(atos); // save receiver for result, and for GC
4405   call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc));
4406 
4407   // vm_result_2 has metadata result
4408 #ifndef _LP64
4409   // borrow rdi from locals
4410   __ get_thread(rdi);
4411   __ get_vm_result_2(rax, rdi);
4412   __ restore_locals();
4413 #else
4414   __ get_vm_result_2(rax, r15_thread);
4415 #endif
4416 
4417   __ pop_ptr(rdx); // restore receiver
4418   __ jmpb(resolved);
4419 
4420   // Get superklass in rax and subklass in rbx
4421   __ bind(quicked);
4422   __ mov(rdx, rax); // Save object in rdx; rax needed for subtype check
4423   __ load_resolved_klass_at_index(rax, rcx, rbx);
4424 
4425   __ bind(resolved);
4426   __ load_klass(rbx, rdx, rscratch1);
4427 
4428   // Generate subtype check.  Blows rcx, rdi.  Object in rdx.
4429   // Superklass in rax.  Subklass in rbx.
4430   __ gen_subtype_check(rbx, ok_is_subtype);
4431 
4432   // Come here on failure
4433   __ push_ptr(rdx);
4434   // object is at TOS
4435   __ jump(ExternalAddress(Interpreter::_throw_ClassCastException_entry));
4436 
4437   // Come here on success
4438   __ bind(ok_is_subtype);
4439   __ mov(rax, rdx); // Restore object in rdx
4440   __ jmp(done);
4441 
4442   __ bind(is_null);
4443 
4444   // Collect counts on whether this check-cast sees nulls a lot or not.
4445   if (ProfileInterpreter) {
4446     __ profile_null_seen(rcx);
4447   }
4448 
4449   __ bind(done);
4450 }
4451 
4452 void TemplateTable::instanceof() {
4453   transition(atos, itos);
4454   Label done, is_null, ok_is_subtype, quicked, resolved;
4455   __ testptr(rax, rax);
4456   __ jcc(Assembler::zero, is_null);
4457 
4458   // Get cpool & tags index
4459   __ get_cpool_and_tags(rcx, rdx); // rcx=cpool, rdx=tags array
4460   __ get_unsigned_2_byte_index_at_bcp(rbx, 1); // rbx=index
4461   // See if bytecode has already been quicked
4462   __ movzbl(rdx, Address(rdx, rbx,
4463         Address::times_1,
4464         Array<u1>::base_offset_in_bytes()));
4465   __ cmpl(rdx, JVM_CONSTANT_Class);
4466   __ jcc(Assembler::equal, quicked);
4467 
4468   __ push(atos); // save receiver for result, and for GC
4469   call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc));
4470   // vm_result_2 has metadata result
4471 
4472 #ifndef _LP64
4473   // borrow rdi from locals
4474   __ get_thread(rdi);
4475   __ get_vm_result_2(rax, rdi);
4476   __ restore_locals();
4477 #else
4478   __ get_vm_result_2(rax, r15_thread);
4479 #endif
4480 
4481   __ pop_ptr(rdx); // restore receiver
4482   __ verify_oop(rdx);
4483   __ load_klass(rdx, rdx, rscratch1);
4484   __ jmpb(resolved);
4485 
4486   // Get superklass in rax and subklass in rdx
4487   __ bind(quicked);
4488   __ load_klass(rdx, rax, rscratch1);
4489   __ load_resolved_klass_at_index(rax, rcx, rbx);
4490 
4491   __ bind(resolved);
4492 
4493   // Generate subtype check.  Blows rcx, rdi
4494   // Superklass in rax.  Subklass in rdx.
4495   __ gen_subtype_check(rdx, ok_is_subtype);
4496 
4497   // Come here on failure
4498   __ xorl(rax, rax);
4499   __ jmpb(done);
4500   // Come here on success
4501   __ bind(ok_is_subtype);
4502   __ movl(rax, 1);
4503 
4504   // Collect counts on whether this test sees nulls a lot or not.
4505   if (ProfileInterpreter) {
4506     __ jmp(done);
4507     __ bind(is_null);
4508     __ profile_null_seen(rcx);
4509   } else {
4510     __ bind(is_null);   // same as 'done'
4511   }
4512   __ bind(done);
4513   // rax = 0: obj == nullptr or  obj is not an instanceof the specified klass
4514   // rax = 1: obj != nullptr and obj is     an instanceof the specified klass
4515 }
4516 
4517 //----------------------------------------------------------------------------------------------------
4518 // Breakpoints
4519 void TemplateTable::_breakpoint() {
4520   // Note: We get here even if we are single stepping..
4521   // jbug insists on setting breakpoints at every bytecode
4522   // even if we are in single step mode.
4523 
4524   transition(vtos, vtos);
4525 
4526   Register rarg = LP64_ONLY(c_rarg1) NOT_LP64(rcx);
4527 
4528   // get the unpatched byte code
4529   __ get_method(rarg);
4530   __ call_VM(noreg,
4531              CAST_FROM_FN_PTR(address,
4532                               InterpreterRuntime::get_original_bytecode_at),
4533              rarg, rbcp);
4534   __ mov(rbx, rax);  // why?
4535 
4536   // post the breakpoint event
4537   __ get_method(rarg);
4538   __ call_VM(noreg,
4539              CAST_FROM_FN_PTR(address, InterpreterRuntime::_breakpoint),
4540              rarg, rbcp);
4541 
4542   // complete the execution of original bytecode
4543   __ dispatch_only_normal(vtos);
4544 }
4545 
4546 //-----------------------------------------------------------------------------
4547 // Exceptions
4548 
4549 void TemplateTable::athrow() {
4550   transition(atos, vtos);
4551   __ null_check(rax);
4552   __ jump(ExternalAddress(Interpreter::throw_exception_entry()));
4553 }
4554 
4555 //-----------------------------------------------------------------------------
4556 // Synchronization
4557 //
4558 // Note: monitorenter & exit are symmetric routines; which is reflected
4559 //       in the assembly code structure as well
4560 //
4561 // Stack layout:
4562 //
4563 // [expressions  ] <--- rsp               = expression stack top
4564 // ..
4565 // [expressions  ]
4566 // [monitor entry] <--- monitor block top = expression stack bot
4567 // ..
4568 // [monitor entry]
4569 // [frame data   ] <--- monitor block bot
4570 // ...
4571 // [saved rbp    ] <--- rbp
4572 void TemplateTable::monitorenter() {
4573   transition(atos, vtos);
4574 
4575   // check for null object
4576   __ null_check(rax);
4577 
4578   Label is_inline_type;
4579   __ movptr(rbx, Address(rax, oopDesc::mark_offset_in_bytes()));
4580   __ test_markword_is_inline_type(rbx, is_inline_type);
4581 
4582   const Address monitor_block_top(
4583         rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
4584   const Address monitor_block_bot(
4585         rbp, frame::interpreter_frame_initial_sp_offset * wordSize);
4586   const int entry_size = frame::interpreter_frame_monitor_size_in_bytes();
4587 
4588   Label allocated;
4589 
4590   Register rtop = LP64_ONLY(c_rarg3) NOT_LP64(rcx);
4591   Register rbot = LP64_ONLY(c_rarg2) NOT_LP64(rbx);
4592   Register rmon = LP64_ONLY(c_rarg1) NOT_LP64(rdx);
4593 
4594   // initialize entry pointer
4595   __ xorl(rmon, rmon); // points to free slot or null
4596 
4597   // find a free slot in the monitor block (result in rmon)
4598   {
4599     Label entry, loop, exit;
4600     __ movptr(rtop, monitor_block_top); // derelativize pointer
4601     __ lea(rtop, Address(rbp, rtop, Address::times_ptr));
4602     // rtop points to current entry, starting with top-most entry
4603 
4604     __ lea(rbot, monitor_block_bot);    // points to word before bottom
4605                                         // of monitor block
4606     __ jmpb(entry);
4607 
4608     __ bind(loop);
4609     // check if current entry is used
4610     __ cmpptr(Address(rtop, BasicObjectLock::obj_offset()), NULL_WORD);
4611     // if not used then remember entry in rmon
4612     __ cmovptr(Assembler::equal, rmon, rtop);   // cmov => cmovptr
4613     // check if current entry is for same object
4614     __ cmpptr(rax, Address(rtop, BasicObjectLock::obj_offset()));
4615     // if same object then stop searching
4616     __ jccb(Assembler::equal, exit);
4617     // otherwise advance to next entry
4618     __ addptr(rtop, entry_size);
4619     __ bind(entry);
4620     // check if bottom reached
4621     __ cmpptr(rtop, rbot);
4622     // if not at bottom then check this entry
4623     __ jcc(Assembler::notEqual, loop);
4624     __ bind(exit);
4625   }
4626 
4627   __ testptr(rmon, rmon); // check if a slot has been found
4628   __ jcc(Assembler::notZero, allocated); // if found, continue with that one
4629 
4630   // allocate one if there's no free slot
4631   {
4632     Label entry, loop;
4633     // 1. compute new pointers          // rsp: old expression stack top
4634     __ movptr(rmon, monitor_block_bot); // rmon: old expression stack bottom
4635     __ lea(rmon, Address(rbp, rmon, Address::times_ptr));
4636     __ subptr(rsp, entry_size);         // move expression stack top
4637     __ subptr(rmon, entry_size);        // move expression stack bottom
4638     __ mov(rtop, rsp);                  // set start value for copy loop
4639     __ subptr(monitor_block_bot, entry_size / wordSize); // set new monitor block bottom
4640     __ jmp(entry);
4641     // 2. move expression stack contents
4642     __ bind(loop);
4643     __ movptr(rbot, Address(rtop, entry_size)); // load expression stack
4644                                                 // word from old location
4645     __ movptr(Address(rtop, 0), rbot);          // and store it at new location
4646     __ addptr(rtop, wordSize);                  // advance to next word
4647     __ bind(entry);
4648     __ cmpptr(rtop, rmon);                      // check if bottom reached
4649     __ jcc(Assembler::notEqual, loop);          // if not at bottom then
4650                                                 // copy next word
4651   }
4652 
4653   // call run-time routine
4654   // rmon: points to monitor entry
4655   __ bind(allocated);
4656 
4657   // Increment bcp to point to the next bytecode, so exception
4658   // handling for async. exceptions work correctly.
4659   // The object has already been popped from the stack, so the
4660   // expression stack looks correct.
4661   __ increment(rbcp);
4662 
4663   // store object
4664   __ movptr(Address(rmon, BasicObjectLock::obj_offset()), rax);
4665   __ lock_object(rmon);
4666 
4667   // check to make sure this monitor doesn't cause stack overflow after locking
4668   __ save_bcp();  // in case of exception
4669   __ generate_stack_overflow_check(0);
4670 
4671   // The bcp has already been incremented. Just need to dispatch to
4672   // next instruction.
4673   __ dispatch_next(vtos);
4674 
4675   __ bind(is_inline_type);
4676   __ call_VM(noreg, CAST_FROM_FN_PTR(address,
4677                     InterpreterRuntime::throw_illegal_monitor_state_exception));
4678   __ should_not_reach_here();
4679 }
4680 
4681 void TemplateTable::monitorexit() {
4682   transition(atos, vtos);
4683 
4684   // check for null object
4685   __ null_check(rax);
4686 
4687   const int is_inline_type_mask = markWord::inline_type_pattern;
4688   Label has_identity;
4689   __ movptr(rbx, Address(rax, oopDesc::mark_offset_in_bytes()));
4690   __ andptr(rbx, is_inline_type_mask);
4691   __ cmpl(rbx, is_inline_type_mask);
4692   __ jcc(Assembler::notEqual, has_identity);
4693   __ call_VM(noreg, CAST_FROM_FN_PTR(address,
4694                      InterpreterRuntime::throw_illegal_monitor_state_exception));
4695   __ should_not_reach_here();
4696   __ bind(has_identity);
4697 
4698   const Address monitor_block_top(
4699         rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
4700   const Address monitor_block_bot(
4701         rbp, frame::interpreter_frame_initial_sp_offset * wordSize);
4702   const int entry_size = frame::interpreter_frame_monitor_size_in_bytes();
4703 
4704   Register rtop = LP64_ONLY(c_rarg1) NOT_LP64(rdx);
4705   Register rbot = LP64_ONLY(c_rarg2) NOT_LP64(rbx);
4706 
4707   Label found;
4708 
4709   // find matching slot
4710   {
4711     Label entry, loop;
4712     __ movptr(rtop, monitor_block_top); // derelativize pointer
4713     __ lea(rtop, Address(rbp, rtop, Address::times_ptr));
4714     // rtop points to current entry, starting with top-most entry
4715 
4716     __ lea(rbot, monitor_block_bot);    // points to word before bottom
4717                                         // of monitor block
4718     __ jmpb(entry);
4719 
4720     __ bind(loop);
4721     // check if current entry is for same object
4722     __ cmpptr(rax, Address(rtop, BasicObjectLock::obj_offset()));
4723     // if same object then stop searching
4724     __ jcc(Assembler::equal, found);
4725     // otherwise advance to next entry
4726     __ addptr(rtop, entry_size);
4727     __ bind(entry);
4728     // check if bottom reached
4729     __ cmpptr(rtop, rbot);
4730     // if not at bottom then check this entry
4731     __ jcc(Assembler::notEqual, loop);
4732   }
4733 
4734   // error handling. Unlocking was not block-structured
4735   __ call_VM(noreg, CAST_FROM_FN_PTR(address,
4736                    InterpreterRuntime::throw_illegal_monitor_state_exception));
4737   __ should_not_reach_here();
4738 
4739   // call run-time routine
4740   __ bind(found);
4741   __ push_ptr(rax); // make sure object is on stack (contract with oopMaps)
4742   __ unlock_object(rtop);
4743   __ pop_ptr(rax); // discard object
4744 }
4745 
4746 // Wide instructions
4747 void TemplateTable::wide() {
4748   transition(vtos, vtos);
4749   __ load_unsigned_byte(rbx, at_bcp(1));
4750   ExternalAddress wtable((address)Interpreter::_wentry_point);
4751   __ jump(ArrayAddress(wtable, Address(noreg, rbx, Address::times_ptr)), rscratch1);
4752   // Note: the rbcp increment step is part of the individual wide bytecode implementations
4753 }
4754 
4755 // Multi arrays
4756 void TemplateTable::multianewarray() {
4757   transition(vtos, atos);
4758 
4759   Register rarg = LP64_ONLY(c_rarg1) NOT_LP64(rax);
4760   __ load_unsigned_byte(rax, at_bcp(3)); // get number of dimensions
4761   // last dim is on top of stack; we want address of first one:
4762   // first_addr = last_addr + (ndims - 1) * stackElementSize - 1*wordsize
4763   // the latter wordSize to point to the beginning of the array.
4764   __ lea(rarg, Address(rsp, rax, Interpreter::stackElementScale(), -wordSize));
4765   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::multianewarray), rarg);
4766   __ load_unsigned_byte(rbx, at_bcp(3));
4767   __ lea(rsp, Address(rsp, rbx, Interpreter::stackElementScale()));  // get rid of counts
4768 }