1 /*
   2  * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2014, Red Hat Inc. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 #include "precompiled.hpp"
  27 #include "asm/macroAssembler.hpp"
  28 #include "interpreter/interpreter.hpp"
  29 #include "interpreter/interpreterRuntime.hpp"
  30 #include "interpreter/interp_masm.hpp"
  31 #include "interpreter/templateTable.hpp"
  32 #include "memory/universe.inline.hpp"
  33 #include "oops/methodData.hpp"
  34 #include "oops/method.hpp"
  35 #include "oops/objArrayKlass.hpp"
  36 #include "oops/oop.inline.hpp"
  37 #include "prims/methodHandles.hpp"
  38 #include "runtime/sharedRuntime.hpp"
  39 #include "runtime/stubRoutines.hpp"
  40 #include "runtime/synchronizer.hpp"
  41 
  42 #ifndef CC_INTERP
  43 
  44 #define __ _masm->
  45 
  46 // Platform-dependent initialization
  47 
  48 void TemplateTable::pd_initialize() {
  49   // No aarch64 specific initialization
  50 }
  51 
  52 // Address computation: local variables
  53 
  54 static inline Address iaddress(int n) {
  55   return Address(rlocals, Interpreter::local_offset_in_bytes(n));
  56 }
  57 
  58 static inline Address laddress(int n) {
  59   return iaddress(n + 1);
  60 }
  61 
  62 static inline Address faddress(int n) {
  63   return iaddress(n);
  64 }
  65 
  66 static inline Address daddress(int n) {
  67   return laddress(n);
  68 }
  69 
  70 static inline Address aaddress(int n) {
  71   return iaddress(n);
  72 }
  73 
  74 static inline Address iaddress(Register r) {
  75   return Address(rlocals, r, Address::lsl(3));
  76 }
  77 
  78 static inline Address laddress(Register r, Register scratch,
  79                                InterpreterMacroAssembler* _masm) {
  80   __ lea(scratch, Address(rlocals, r, Address::lsl(3)));
  81   return Address(scratch, Interpreter::local_offset_in_bytes(1));
  82 }
  83 
  84 static inline Address faddress(Register r) {
  85   return iaddress(r);
  86 }
  87 
  88 static inline Address daddress(Register r, Register scratch,
  89                                InterpreterMacroAssembler* _masm) {
  90   return laddress(r, scratch, _masm);
  91 }
  92 
  93 static inline Address aaddress(Register r) {
  94   return iaddress(r);
  95 }
  96 
  97 static inline Address at_rsp() {
  98   return Address(esp, 0);
  99 }
 100 
 101 // At top of Java expression stack which may be different than esp().  It
 102 // isn't for category 1 objects.
 103 static inline Address at_tos   () {
 104   return Address(esp,  Interpreter::expr_offset_in_bytes(0));
 105 }
 106 
 107 static inline Address at_tos_p1() {
 108   return Address(esp,  Interpreter::expr_offset_in_bytes(1));
 109 }
 110 
 111 static inline Address at_tos_p2() {
 112   return Address(esp,  Interpreter::expr_offset_in_bytes(2));
 113 }
 114 
 115 static inline Address at_tos_p3() {
 116   return Address(esp,  Interpreter::expr_offset_in_bytes(3));
 117 }
 118 
 119 static inline Address at_tos_p4() {
 120   return Address(esp,  Interpreter::expr_offset_in_bytes(4));
 121 }
 122 
 123 static inline Address at_tos_p5() {
 124   return Address(esp,  Interpreter::expr_offset_in_bytes(5));
 125 }
 126 
 127 // Condition conversion
 128 static Assembler::Condition j_not(TemplateTable::Condition cc) {
 129   switch (cc) {
 130   case TemplateTable::equal        : return Assembler::NE;
 131   case TemplateTable::not_equal    : return Assembler::EQ;
 132   case TemplateTable::less         : return Assembler::GE;
 133   case TemplateTable::less_equal   : return Assembler::GT;
 134   case TemplateTable::greater      : return Assembler::LE;
 135   case TemplateTable::greater_equal: return Assembler::LT;
 136   }
 137   ShouldNotReachHere();
 138   return Assembler::EQ;
 139 }
 140 
 141 
 142 // Miscelaneous helper routines
 143 // Store an oop (or NULL) at the Address described by obj.
 144 // If val == noreg this means store a NULL
 145 static void do_oop_store(InterpreterMacroAssembler* _masm,
 146                          Address obj,
 147                          Register val,
 148                          BarrierSet::Name barrier,
 149                          bool precise) {
 150   assert(val == noreg || val == r0, "parameter is just for looks");
 151   switch (barrier) {
 152 #if INCLUDE_ALL_GCS
 153     case BarrierSet::G1SATBCTLogging:
 154       {
 155         // flatten object address if needed
 156         if (obj.index() == noreg && obj.offset() == 0) {
 157           if (obj.base() != r3) {
 158             __ mov(r3, obj.base());
 159           }
 160         } else {
 161           __ lea(r3, obj);
 162         }
 163         __ g1_write_barrier_pre(r3 /* obj */,
 164                                 r1 /* pre_val */,
 165                                 rthread /* thread */,
 166                                 r10  /* tmp */,
 167                                 val != noreg /* tosca_live */,
 168                                 false /* expand_call */);
 169         if (val == noreg) {
 170           __ store_heap_oop_null(Address(r3, 0));
 171         } else {
 172           // G1 barrier needs uncompressed oop for region cross check.
 173           Register new_val = val;
 174           if (UseCompressedOops) {
 175             new_val = rscratch1;
 176             __ mov(new_val, val);
 177           }
 178           __ store_heap_oop(Address(r3, 0), val);
 179           __ g1_write_barrier_post(r3 /* store_adr */,
 180                                    new_val /* new_val */,
 181                                    rthread /* thread */,
 182                                    r10 /* tmp */,
 183                                    r1 /* tmp2 */);
 184         }
 185 
 186       }
 187       break;
 188 #endif // INCLUDE_ALL_GCS
 189     case BarrierSet::CardTableForRS:
 190     case BarrierSet::CardTableExtension:
 191       {
 192         if (val == noreg) {
 193           __ store_heap_oop_null(obj);
 194         } else {
 195           __ store_heap_oop(obj, val);
 196           // flatten object address if needed
 197           if (!precise || (obj.index() == noreg && obj.offset() == 0)) {
 198             __ store_check(obj.base());
 199           } else {
 200             __ lea(r3, obj);
 201             __ store_check(r3);
 202           }
 203         }
 204       }
 205       break;
 206     case BarrierSet::ModRef:
 207       if (val == noreg) {
 208         __ store_heap_oop_null(obj);
 209       } else {
 210         __ store_heap_oop(obj, val);
 211       }
 212       break;
 213     default      :
 214       ShouldNotReachHere();
 215 
 216   }
 217 }
 218 
 219 Address TemplateTable::at_bcp(int offset) {
 220   assert(_desc->uses_bcp(), "inconsistent uses_bcp information");
 221   return Address(rbcp, offset);
 222 }
 223 
 224 void TemplateTable::patch_bytecode(Bytecodes::Code bc, Register bc_reg,
 225                                    Register temp_reg, bool load_bc_into_bc_reg/*=true*/,
 226                                    int byte_no)
 227 {
 228   if (!RewriteBytecodes)  return;
 229   Label L_patch_done;
 230 
 231   switch (bc) {
 232   case Bytecodes::_fast_aputfield:
 233   case Bytecodes::_fast_bputfield:
 234   case Bytecodes::_fast_cputfield:
 235   case Bytecodes::_fast_dputfield:
 236   case Bytecodes::_fast_fputfield:
 237   case Bytecodes::_fast_iputfield:
 238   case Bytecodes::_fast_lputfield:
 239   case Bytecodes::_fast_sputfield:
 240     {
 241       // We skip bytecode quickening for putfield instructions when
 242       // the put_code written to the constant pool cache is zero.
 243       // This is required so that every execution of this instruction
 244       // calls out to InterpreterRuntime::resolve_get_put to do
 245       // additional, required work.
 246       assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
 247       assert(load_bc_into_bc_reg, "we use bc_reg as temp");
 248       __ get_cache_and_index_and_bytecode_at_bcp(temp_reg, bc_reg, temp_reg, byte_no, 1);
 249       __ movw(bc_reg, bc);
 250       __ cmpw(temp_reg, (unsigned) 0);
 251       __ br(Assembler::EQ, L_patch_done);  // don't patch
 252     }
 253     break;
 254   default:
 255     assert(byte_no == -1, "sanity");
 256     // the pair bytecodes have already done the load.
 257     if (load_bc_into_bc_reg) {
 258       __ movw(bc_reg, bc);
 259     }
 260   }
 261 
 262   if (JvmtiExport::can_post_breakpoint()) {
 263     Label L_fast_patch;
 264     // if a breakpoint is present we can't rewrite the stream directly
 265     __ load_unsigned_byte(temp_reg, at_bcp(0));
 266     __ cmpw(temp_reg, Bytecodes::_breakpoint);
 267     __ br(Assembler::NE, L_fast_patch);
 268     // Let breakpoint table handling rewrite to quicker bytecode
 269     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::set_original_bytecode_at), rmethod, rbcp, bc_reg);
 270     __ b(L_patch_done);
 271     __ bind(L_fast_patch);
 272   }
 273 
 274 #ifdef ASSERT
 275   Label L_okay;
 276   __ load_unsigned_byte(temp_reg, at_bcp(0));
 277   __ cmpw(temp_reg, (int) Bytecodes::java_code(bc));
 278   __ br(Assembler::EQ, L_okay);
 279   __ cmpw(temp_reg, bc_reg);
 280   __ br(Assembler::EQ, L_okay);
 281   __ stop("patching the wrong bytecode");
 282   __ bind(L_okay);
 283 #endif
 284 
 285   // patch bytecode
 286   __ strb(bc_reg, at_bcp(0));
 287   __ bind(L_patch_done);
 288 }
 289 
 290 
 291 // Individual instructions
 292 
 293 void TemplateTable::nop() {
 294   transition(vtos, vtos);
 295   // nothing to do
 296 }
 297 
 298 void TemplateTable::shouldnotreachhere() {
 299   transition(vtos, vtos);
 300   __ stop("shouldnotreachhere bytecode");
 301 }
 302 
 303 void TemplateTable::aconst_null()
 304 {
 305   transition(vtos, atos);
 306   __ mov(r0, 0);
 307 }
 308 
 309 void TemplateTable::iconst(int value)
 310 {
 311   transition(vtos, itos);
 312   __ mov(r0, value);
 313 }
 314 
 315 void TemplateTable::lconst(int value)
 316 {
 317   __ mov(r0, value);
 318 }
 319 
 320 void TemplateTable::fconst(int value)
 321 {
 322   transition(vtos, ftos);
 323   switch (value) {
 324   case 0:
 325     __ fmovs(v0, zr);
 326     break;
 327   case 1:
 328     __ fmovs(v0, 1.0);
 329     break;
 330   case 2:
 331     __ fmovs(v0, 2.0);
 332     break;
 333   default:
 334     ShouldNotReachHere();
 335     break;
 336   }
 337 }
 338 
 339 void TemplateTable::dconst(int value)
 340 {
 341   transition(vtos, dtos);
 342   switch (value) {
 343   case 0:
 344     __ fmovd(v0, zr);
 345     break;
 346   case 1:
 347     __ fmovd(v0, 1.0);
 348     break;
 349   case 2:
 350     __ fmovd(v0, 2.0);
 351     break;
 352   default:
 353     ShouldNotReachHere();
 354     break;
 355   }
 356 }
 357 
 358 void TemplateTable::bipush()
 359 {
 360   transition(vtos, itos);
 361   __ load_signed_byte32(r0, at_bcp(1));
 362 }
 363 
 364 void TemplateTable::sipush()
 365 {
 366   transition(vtos, itos);
 367   __ load_unsigned_short(r0, at_bcp(1));
 368   __ revw(r0, r0);
 369   __ asrw(r0, r0, 16);
 370 }
 371 
 372 void TemplateTable::ldc(bool wide)
 373 {
 374   transition(vtos, vtos);
 375   Label call_ldc, notFloat, notClass, Done;
 376 
 377   if (wide) {
 378     __ get_unsigned_2_byte_index_at_bcp(r1, 1);
 379   } else {
 380     __ load_unsigned_byte(r1, at_bcp(1));
 381   }
 382   __ get_cpool_and_tags(r2, r0);
 383 
 384   const int base_offset = ConstantPool::header_size() * wordSize;
 385   const int tags_offset = Array<u1>::base_offset_in_bytes();
 386 
 387   // get type
 388   __ add(r3, r1, tags_offset);
 389   __ lea(r3, Address(r0, r3));
 390   __ ldarb(r3, r3);
 391 
 392   // unresolved class - get the resolved class
 393   __ cmp(r3, JVM_CONSTANT_UnresolvedClass);
 394   __ br(Assembler::EQ, call_ldc);
 395 
 396   // unresolved class in error state - call into runtime to throw the error
 397   // from the first resolution attempt
 398   __ cmp(r3, JVM_CONSTANT_UnresolvedClassInError);
 399   __ br(Assembler::EQ, call_ldc);
 400 
 401   // resolved class - need to call vm to get java mirror of the class
 402   __ cmp(r3, JVM_CONSTANT_Class);
 403   __ br(Assembler::NE, notClass);
 404 
 405   __ bind(call_ldc);
 406   __ mov(c_rarg1, wide);
 407   call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::ldc), c_rarg1);
 408   __ push_ptr(r0);
 409   __ verify_oop(r0);
 410   __ b(Done);
 411 
 412   __ bind(notClass);
 413   __ cmp(r3, JVM_CONSTANT_Float);
 414   __ br(Assembler::NE, notFloat);
 415   // ftos
 416   __ adds(r1, r2, r1, Assembler::LSL, 3);
 417   __ ldrs(v0, Address(r1, base_offset));
 418   __ push_f();
 419   __ b(Done);
 420 
 421   __ bind(notFloat);
 422 #ifdef ASSERT
 423   {
 424     Label L;
 425     __ cmp(r3, JVM_CONSTANT_Integer);
 426     __ br(Assembler::EQ, L);
 427     // String and Object are rewritten to fast_aldc
 428     __ stop("unexpected tag type in ldc");
 429     __ bind(L);
 430   }
 431 #endif
 432   // itos JVM_CONSTANT_Integer only
 433   __ adds(r1, r2, r1, Assembler::LSL, 3);
 434   __ ldrw(r0, Address(r1, base_offset));
 435   __ push_i(r0);
 436   __ bind(Done);
 437 }
 438 
 439 // Fast path for caching oop constants.
 440 void TemplateTable::fast_aldc(bool wide)
 441 {
 442   transition(vtos, atos);
 443 
 444   Register result = r0;
 445   Register tmp = r1;
 446   int index_size = wide ? sizeof(u2) : sizeof(u1);
 447 
 448   Label resolved;
 449 
 450   // We are resolved if the resolved reference cache entry contains a
 451   // non-null object (String, MethodType, etc.)
 452   assert_different_registers(result, tmp);
 453   __ get_cache_index_at_bcp(tmp, 1, index_size);
 454   __ load_resolved_reference_at_index(result, tmp);
 455   __ cbnz(result, resolved);
 456 
 457   address entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_ldc);
 458 
 459   // first time invocation - must resolve first
 460   __ mov(tmp, (int)bytecode());
 461   __ call_VM(result, entry, tmp);
 462 
 463   __ bind(resolved);
 464 
 465   if (VerifyOops) {
 466     __ verify_oop(result);
 467   }
 468 }
 469 
 470 void TemplateTable::ldc2_w()
 471 {
 472   transition(vtos, vtos);
 473   Label Long, Done;
 474   __ get_unsigned_2_byte_index_at_bcp(r0, 1);
 475 
 476   __ get_cpool_and_tags(r1, r2);
 477   const int base_offset = ConstantPool::header_size() * wordSize;
 478   const int tags_offset = Array<u1>::base_offset_in_bytes();
 479 
 480   // get type
 481   __ lea(r2, Address(r2, r0, Address::lsl(0)));
 482   __ load_unsigned_byte(r2, Address(r2, tags_offset));
 483   __ cmpw(r2, (int)JVM_CONSTANT_Double);
 484   __ br(Assembler::NE, Long);
 485   // dtos
 486   __ lea (r2, Address(r1, r0, Address::lsl(3)));
 487   __ ldrd(v0, Address(r2, base_offset));
 488   __ push_d();
 489   __ b(Done);
 490 
 491   __ bind(Long);
 492   // ltos
 493   __ lea(r0, Address(r1, r0, Address::lsl(3)));
 494   __ ldr(r0, Address(r0, base_offset));
 495   __ push_l();
 496 
 497   __ bind(Done);
 498 }
 499 
 500 void TemplateTable::locals_index(Register reg, int offset)
 501 {
 502   __ ldrb(reg, at_bcp(offset));
 503   __ neg(reg, reg);
 504 }
 505 
 506 void TemplateTable::iload() {
 507   iload_internal();
 508 }
 509 
 510 void TemplateTable::nofast_iload() {
 511   iload_internal(may_not_rewrite);
 512 }
 513 
 514 void TemplateTable::iload_internal(RewriteControl rc) {
 515   transition(vtos, itos);
 516   if (RewriteFrequentPairs && rc == may_rewrite) {
 517     Label rewrite, done;
 518     Register bc = r4;
 519 
 520     // get next bytecode
 521     __ load_unsigned_byte(r1, at_bcp(Bytecodes::length_for(Bytecodes::_iload)));
 522 
 523     // if _iload, wait to rewrite to iload2.  We only want to rewrite the
 524     // last two iloads in a pair.  Comparing against fast_iload means that
 525     // the next bytecode is neither an iload or a caload, and therefore
 526     // an iload pair.
 527     __ cmpw(r1, Bytecodes::_iload);
 528     __ br(Assembler::EQ, done);
 529 
 530     // if _fast_iload rewrite to _fast_iload2
 531     __ cmpw(r1, Bytecodes::_fast_iload);
 532     __ movw(bc, Bytecodes::_fast_iload2);
 533     __ br(Assembler::EQ, rewrite);
 534 
 535     // if _caload rewrite to _fast_icaload
 536     __ cmpw(r1, Bytecodes::_caload);
 537     __ movw(bc, Bytecodes::_fast_icaload);
 538     __ br(Assembler::EQ, rewrite);
 539 
 540     // else rewrite to _fast_iload
 541     __ movw(bc, Bytecodes::_fast_iload);
 542 
 543     // rewrite
 544     // bc: new bytecode
 545     __ bind(rewrite);
 546     patch_bytecode(Bytecodes::_iload, bc, r1, false);
 547     __ bind(done);
 548 
 549   }
 550 
 551   // do iload, get the local value into tos
 552   locals_index(r1);
 553   __ ldr(r0, iaddress(r1));
 554 
 555 }
 556 
 557 void TemplateTable::fast_iload2()
 558 {
 559   transition(vtos, itos);
 560   locals_index(r1);
 561   __ ldr(r0, iaddress(r1));
 562   __ push(itos);
 563   locals_index(r1, 3);
 564   __ ldr(r0, iaddress(r1));
 565 }
 566 
 567 void TemplateTable::fast_iload()
 568 {
 569   transition(vtos, itos);
 570   locals_index(r1);
 571   __ ldr(r0, iaddress(r1));
 572 }
 573 
 574 void TemplateTable::lload()
 575 {
 576   transition(vtos, ltos);
 577   __ ldrb(r1, at_bcp(1));
 578   __ sub(r1, rlocals, r1, ext::uxtw, LogBytesPerWord);
 579   __ ldr(r0, Address(r1, Interpreter::local_offset_in_bytes(1)));
 580 }
 581 
 582 void TemplateTable::fload()
 583 {
 584   transition(vtos, ftos);
 585   locals_index(r1);
 586   // n.b. we use ldrd here because this is a 64 bit slot
 587   // this is comparable to the iload case
 588   __ ldrd(v0, faddress(r1));
 589 }
 590 
 591 void TemplateTable::dload()
 592 {
 593   transition(vtos, dtos);
 594   __ ldrb(r1, at_bcp(1));
 595   __ sub(r1, rlocals, r1, ext::uxtw, LogBytesPerWord);
 596   __ ldrd(v0, Address(r1, Interpreter::local_offset_in_bytes(1)));
 597 }
 598 
 599 void TemplateTable::aload()
 600 {
 601   transition(vtos, atos);
 602   locals_index(r1);
 603   __ ldr(r0, iaddress(r1));
 604 }
 605 
 606 void TemplateTable::locals_index_wide(Register reg) {
 607   __ ldrh(reg, at_bcp(2));
 608   __ rev16w(reg, reg);
 609   __ neg(reg, reg);
 610 }
 611 
 612 void TemplateTable::wide_iload() {
 613   transition(vtos, itos);
 614   locals_index_wide(r1);
 615   __ ldr(r0, iaddress(r1));
 616 }
 617 
 618 void TemplateTable::wide_lload()
 619 {
 620   transition(vtos, ltos);
 621   __ ldrh(r1, at_bcp(2));
 622   __ rev16w(r1, r1);
 623   __ sub(r1, rlocals, r1, ext::uxtw, LogBytesPerWord);
 624   __ ldr(r0, Address(r1, Interpreter::local_offset_in_bytes(1)));
 625 }
 626 
 627 void TemplateTable::wide_fload()
 628 {
 629   transition(vtos, ftos);
 630   locals_index_wide(r1);
 631   // n.b. we use ldrd here because this is a 64 bit slot
 632   // this is comparable to the iload case
 633   __ ldrd(v0, faddress(r1));
 634 }
 635 
 636 void TemplateTable::wide_dload()
 637 {
 638   transition(vtos, dtos);
 639   __ ldrh(r1, at_bcp(2));
 640   __ rev16w(r1, r1);
 641   __ sub(r1, rlocals, r1, ext::uxtw, LogBytesPerWord);
 642   __ ldrd(v0, Address(r1, Interpreter::local_offset_in_bytes(1)));
 643 }
 644 
 645 void TemplateTable::wide_aload()
 646 {
 647   transition(vtos, atos);
 648   locals_index_wide(r1);
 649   __ ldr(r0, aaddress(r1));
 650 }
 651 
 652 void TemplateTable::index_check(Register array, Register index)
 653 {
 654   // destroys r1, rscratch1
 655   // check array
 656   __ null_check(array, arrayOopDesc::length_offset_in_bytes());
 657   // sign extend index for use by indexed load
 658   // __ movl2ptr(index, index);
 659   // check index
 660   Register length = rscratch1;
 661   __ ldrw(length, Address(array, arrayOopDesc::length_offset_in_bytes()));
 662   __ cmpw(index, length);
 663   if (index != r1) {
 664     // ??? convention: move aberrant index into r1 for exception message
 665     assert(r1 != array, "different registers");
 666     __ mov(r1, index);
 667   }
 668   Label ok;
 669   __ br(Assembler::LO, ok);
 670   __ mov(rscratch1, Interpreter::_throw_ArrayIndexOutOfBoundsException_entry);
 671   __ br(rscratch1);
 672   __ bind(ok);
 673 }
 674 
 675 void TemplateTable::iaload()
 676 {
 677   transition(itos, itos);
 678   __ mov(r1, r0);
 679   __ pop_ptr(r0);
 680   // r0: array
 681   // r1: index
 682   index_check(r0, r1); // leaves index in r1, kills rscratch1
 683   __ lea(r1, Address(r0, r1, Address::uxtw(2)));
 684   __ ldrw(r0, Address(r1, arrayOopDesc::base_offset_in_bytes(T_INT)));
 685 }
 686 
 687 void TemplateTable::laload()
 688 {
 689   transition(itos, ltos);
 690   __ mov(r1, r0);
 691   __ pop_ptr(r0);
 692   // r0: array
 693   // r1: index
 694   index_check(r0, r1); // leaves index in r1, kills rscratch1
 695   __ lea(r1, Address(r0, r1, Address::uxtw(3)));
 696   __ ldr(r0, Address(r1,  arrayOopDesc::base_offset_in_bytes(T_LONG)));
 697 }
 698 
 699 void TemplateTable::faload()
 700 {
 701   transition(itos, ftos);
 702   __ mov(r1, r0);
 703   __ pop_ptr(r0);
 704   // r0: array
 705   // r1: index
 706   index_check(r0, r1); // leaves index in r1, kills rscratch1
 707   __ lea(r1,  Address(r0, r1, Address::uxtw(2)));
 708   __ ldrs(v0, Address(r1,  arrayOopDesc::base_offset_in_bytes(T_FLOAT)));
 709 }
 710 
 711 void TemplateTable::daload()
 712 {
 713   transition(itos, dtos);
 714   __ mov(r1, r0);
 715   __ pop_ptr(r0);
 716   // r0: array
 717   // r1: index
 718   index_check(r0, r1); // leaves index in r1, kills rscratch1
 719   __ lea(r1,  Address(r0, r1, Address::uxtw(3)));
 720   __ ldrd(v0, Address(r1,  arrayOopDesc::base_offset_in_bytes(T_DOUBLE)));
 721 }
 722 
 723 void TemplateTable::aaload()
 724 {
 725   transition(itos, atos);
 726   __ mov(r1, r0);
 727   __ pop_ptr(r0);
 728   // r0: array
 729   // r1: index
 730   index_check(r0, r1); // leaves index in r1, kills rscratch1
 731   int s = (UseCompressedOops ? 2 : 3);
 732   __ lea(r1, Address(r0, r1, Address::uxtw(s)));
 733   __ load_heap_oop(r0, Address(r1, arrayOopDesc::base_offset_in_bytes(T_OBJECT)));
 734 }
 735 
 736 void TemplateTable::baload()
 737 {
 738   transition(itos, itos);
 739   __ mov(r1, r0);
 740   __ pop_ptr(r0);
 741   // r0: array
 742   // r1: index
 743   index_check(r0, r1); // leaves index in r1, kills rscratch1
 744   __ lea(r1,  Address(r0, r1, Address::uxtw(0)));
 745   __ load_signed_byte(r0, Address(r1,  arrayOopDesc::base_offset_in_bytes(T_BYTE)));
 746 }
 747 
 748 void TemplateTable::caload()
 749 {
 750   transition(itos, itos);
 751   __ mov(r1, r0);
 752   __ pop_ptr(r0);
 753   // r0: array
 754   // r1: index
 755   index_check(r0, r1); // leaves index in r1, kills rscratch1
 756   __ lea(r1,  Address(r0, r1, Address::uxtw(1)));
 757   __ load_unsigned_short(r0, Address(r1,  arrayOopDesc::base_offset_in_bytes(T_CHAR)));
 758 }
 759 
 760 // iload followed by caload frequent pair
 761 void TemplateTable::fast_icaload()
 762 {
 763   transition(vtos, itos);
 764   // load index out of locals
 765   locals_index(r2);
 766   __ ldr(r1, iaddress(r2));
 767 
 768   __ pop_ptr(r0);
 769 
 770   // r0: array
 771   // r1: index
 772   index_check(r0, r1); // leaves index in r1, kills rscratch1
 773   __ lea(r1,  Address(r0, r1, Address::uxtw(1)));
 774   __ load_unsigned_short(r0, Address(r1,  arrayOopDesc::base_offset_in_bytes(T_CHAR)));
 775 }
 776 
 777 void TemplateTable::saload()
 778 {
 779   transition(itos, itos);
 780   __ mov(r1, r0);
 781   __ pop_ptr(r0);
 782   // r0: array
 783   // r1: index
 784   index_check(r0, r1); // leaves index in r1, kills rscratch1
 785   __ lea(r1,  Address(r0, r1, Address::uxtw(1)));
 786   __ load_signed_short(r0, Address(r1,  arrayOopDesc::base_offset_in_bytes(T_SHORT)));
 787 }
 788 
 789 void TemplateTable::iload(int n)
 790 {
 791   transition(vtos, itos);
 792   __ ldr(r0, iaddress(n));
 793 }
 794 
 795 void TemplateTable::lload(int n)
 796 {
 797   transition(vtos, ltos);
 798   __ ldr(r0, laddress(n));
 799 }
 800 
 801 void TemplateTable::fload(int n)
 802 {
 803   transition(vtos, ftos);
 804   __ ldrs(v0, faddress(n));
 805 }
 806 
 807 void TemplateTable::dload(int n)
 808 {
 809   transition(vtos, dtos);
 810   __ ldrd(v0, daddress(n));
 811 }
 812 
 813 void TemplateTable::aload(int n)
 814 {
 815   transition(vtos, atos);
 816   __ ldr(r0, iaddress(n));
 817 }
 818 
 819 void TemplateTable::aload_0() {
 820   aload_0_internal();
 821 }
 822 
 823 void TemplateTable::nofast_aload_0() {
 824   aload_0_internal(may_not_rewrite);
 825 }
 826 
 827 void TemplateTable::aload_0_internal(RewriteControl rc) {
 828   // According to bytecode histograms, the pairs:
 829   //
 830   // _aload_0, _fast_igetfield
 831   // _aload_0, _fast_agetfield
 832   // _aload_0, _fast_fgetfield
 833   //
 834   // occur frequently. If RewriteFrequentPairs is set, the (slow)
 835   // _aload_0 bytecode checks if the next bytecode is either
 836   // _fast_igetfield, _fast_agetfield or _fast_fgetfield and then
 837   // rewrites the current bytecode into a pair bytecode; otherwise it
 838   // rewrites the current bytecode into _fast_aload_0 that doesn't do
 839   // the pair check anymore.
 840   //
 841   // Note: If the next bytecode is _getfield, the rewrite must be
 842   //       delayed, otherwise we may miss an opportunity for a pair.
 843   //
 844   // Also rewrite frequent pairs
 845   //   aload_0, aload_1
 846   //   aload_0, iload_1
 847   // These bytecodes with a small amount of code are most profitable
 848   // to rewrite
 849   if (RewriteFrequentPairs && rc == may_rewrite) {
 850     Label rewrite, done;
 851     const Register bc = r4;
 852 
 853     // get next bytecode
 854     __ load_unsigned_byte(r1, at_bcp(Bytecodes::length_for(Bytecodes::_aload_0)));
 855 
 856     // do actual aload_0
 857     aload(0);
 858 
 859     // if _getfield then wait with rewrite
 860     __ cmpw(r1, Bytecodes::Bytecodes::_getfield);
 861     __ br(Assembler::EQ, done);
 862 
 863     // if _igetfield then reqrite to _fast_iaccess_0
 864     assert(Bytecodes::java_code(Bytecodes::_fast_iaccess_0) == Bytecodes::_aload_0, "fix bytecode definition");
 865     __ cmpw(r1, Bytecodes::_fast_igetfield);
 866     __ movw(bc, Bytecodes::_fast_iaccess_0);
 867     __ br(Assembler::EQ, rewrite);
 868 
 869     // if _agetfield then reqrite to _fast_aaccess_0
 870     assert(Bytecodes::java_code(Bytecodes::_fast_aaccess_0) == Bytecodes::_aload_0, "fix bytecode definition");
 871     __ cmpw(r1, Bytecodes::_fast_agetfield);
 872     __ movw(bc, Bytecodes::_fast_aaccess_0);
 873     __ br(Assembler::EQ, rewrite);
 874 
 875     // if _fgetfield then reqrite to _fast_faccess_0
 876     assert(Bytecodes::java_code(Bytecodes::_fast_faccess_0) == Bytecodes::_aload_0, "fix bytecode definition");
 877     __ cmpw(r1, Bytecodes::_fast_fgetfield);
 878     __ movw(bc, Bytecodes::_fast_faccess_0);
 879     __ br(Assembler::EQ, rewrite);
 880 
 881     // else rewrite to _fast_aload0
 882     assert(Bytecodes::java_code(Bytecodes::_fast_aload_0) == Bytecodes::_aload_0, "fix bytecode definition");
 883     __ movw(bc, Bytecodes::Bytecodes::_fast_aload_0);
 884 
 885     // rewrite
 886     // bc: new bytecode
 887     __ bind(rewrite);
 888     patch_bytecode(Bytecodes::_aload_0, bc, r1, false);
 889 
 890     __ bind(done);
 891   } else {
 892     aload(0);
 893   }
 894 }
 895 
 896 void TemplateTable::istore()
 897 {
 898   transition(itos, vtos);
 899   locals_index(r1);
 900   // FIXME: We're being very pernickerty here storing a jint in a
 901   // local with strw, which costs an extra instruction over what we'd
 902   // be able to do with a simple str.  We should just store the whole
 903   // word.
 904   __ lea(rscratch1, iaddress(r1));
 905   __ strw(r0, Address(rscratch1));
 906 }
 907 
 908 void TemplateTable::lstore()
 909 {
 910   transition(ltos, vtos);
 911   locals_index(r1);
 912   __ str(r0, laddress(r1, rscratch1, _masm));
 913 }
 914 
 915 void TemplateTable::fstore() {
 916   transition(ftos, vtos);
 917   locals_index(r1);
 918   __ lea(rscratch1, iaddress(r1));
 919   __ strs(v0, Address(rscratch1));
 920 }
 921 
 922 void TemplateTable::dstore() {
 923   transition(dtos, vtos);
 924   locals_index(r1);
 925   __ strd(v0, daddress(r1, rscratch1, _masm));
 926 }
 927 
 928 void TemplateTable::astore()
 929 {
 930   transition(vtos, vtos);
 931   __ pop_ptr(r0);
 932   locals_index(r1);
 933   __ str(r0, aaddress(r1));
 934 }
 935 
 936 void TemplateTable::wide_istore() {
 937   transition(vtos, vtos);
 938   __ pop_i();
 939   locals_index_wide(r1);
 940   __ lea(rscratch1, iaddress(r1));
 941   __ strw(r0, Address(rscratch1));
 942 }
 943 
 944 void TemplateTable::wide_lstore() {
 945   transition(vtos, vtos);
 946   __ pop_l();
 947   locals_index_wide(r1);
 948   __ str(r0, laddress(r1, rscratch1, _masm));
 949 }
 950 
 951 void TemplateTable::wide_fstore() {
 952   transition(vtos, vtos);
 953   __ pop_f();
 954   locals_index_wide(r1);
 955   __ lea(rscratch1, faddress(r1));
 956   __ strs(v0, rscratch1);
 957 }
 958 
 959 void TemplateTable::wide_dstore() {
 960   transition(vtos, vtos);
 961   __ pop_d();
 962   locals_index_wide(r1);
 963   __ strd(v0, daddress(r1, rscratch1, _masm));
 964 }
 965 
 966 void TemplateTable::wide_astore() {
 967   transition(vtos, vtos);
 968   __ pop_ptr(r0);
 969   locals_index_wide(r1);
 970   __ str(r0, aaddress(r1));
 971 }
 972 
 973 void TemplateTable::iastore() {
 974   transition(itos, vtos);
 975   __ pop_i(r1);
 976   __ pop_ptr(r3);
 977   // r0: value
 978   // r1: index
 979   // r3: array
 980   index_check(r3, r1); // prefer index in r1
 981   __ lea(rscratch1, Address(r3, r1, Address::uxtw(2)));
 982   __ strw(r0, Address(rscratch1,
 983                       arrayOopDesc::base_offset_in_bytes(T_INT)));
 984 }
 985 
 986 void TemplateTable::lastore() {
 987   transition(ltos, vtos);
 988   __ pop_i(r1);
 989   __ pop_ptr(r3);
 990   // r0: value
 991   // r1: index
 992   // r3: array
 993   index_check(r3, r1); // prefer index in r1
 994   __ lea(rscratch1, Address(r3, r1, Address::uxtw(3)));
 995   __ str(r0, Address(rscratch1,
 996                       arrayOopDesc::base_offset_in_bytes(T_LONG)));
 997 }
 998 
 999 void TemplateTable::fastore() {
1000   transition(ftos, vtos);
1001   __ pop_i(r1);
1002   __ pop_ptr(r3);
1003   // v0: value
1004   // r1:  index
1005   // r3:  array
1006   index_check(r3, r1); // prefer index in r1
1007   __ lea(rscratch1, Address(r3, r1, Address::uxtw(2)));
1008   __ strs(v0, Address(rscratch1,
1009                       arrayOopDesc::base_offset_in_bytes(T_FLOAT)));
1010 }
1011 
1012 void TemplateTable::dastore() {
1013   transition(dtos, vtos);
1014   __ pop_i(r1);
1015   __ pop_ptr(r3);
1016   // v0: value
1017   // r1:  index
1018   // r3:  array
1019   index_check(r3, r1); // prefer index in r1
1020   __ lea(rscratch1, Address(r3, r1, Address::uxtw(3)));
1021   __ strd(v0, Address(rscratch1,
1022                       arrayOopDesc::base_offset_in_bytes(T_DOUBLE)));
1023 }
1024 
1025 void TemplateTable::aastore() {
1026   Label is_null, ok_is_subtype, done;
1027   transition(vtos, vtos);
1028   // stack: ..., array, index, value
1029   __ ldr(r0, at_tos());    // value
1030   __ ldr(r2, at_tos_p1()); // index
1031   __ ldr(r3, at_tos_p2()); // array
1032 
1033   Address element_address(r4, arrayOopDesc::base_offset_in_bytes(T_OBJECT));
1034 
1035   index_check(r3, r2);     // kills r1
1036   __ lea(r4, Address(r3, r2, Address::uxtw(UseCompressedOops? 2 : 3)));
1037 
1038   // do array store check - check for NULL value first
1039   __ cbz(r0, is_null);
1040 
1041   // Move subklass into r1
1042   __ load_klass(r1, r0);
1043   // Move superklass into r0
1044   __ load_klass(r0, r3);
1045   __ ldr(r0, Address(r0,
1046                      ObjArrayKlass::element_klass_offset()));
1047   // Compress array + index*oopSize + 12 into a single register.  Frees r2.
1048 
1049   // Generate subtype check.  Blows r2, r5
1050   // Superklass in r0.  Subklass in r1.
1051   __ gen_subtype_check(r1, ok_is_subtype);
1052 
1053   // Come here on failure
1054   // object is at TOS
1055   __ b(Interpreter::_throw_ArrayStoreException_entry);
1056 
1057   // Come here on success
1058   __ bind(ok_is_subtype);
1059 
1060   // Get the value we will store
1061   __ ldr(r0, at_tos());
1062   // Now store using the appropriate barrier
1063   do_oop_store(_masm, element_address, r0, _bs->kind(), true);
1064   __ b(done);
1065 
1066   // Have a NULL in r0, r3=array, r2=index.  Store NULL at ary[idx]
1067   __ bind(is_null);
1068   __ profile_null_seen(r2);
1069 
1070   // Store a NULL
1071   do_oop_store(_masm, element_address, noreg, _bs->kind(), true);
1072 
1073   // Pop stack arguments
1074   __ bind(done);
1075   __ add(esp, esp, 3 * Interpreter::stackElementSize);
1076 }
1077 
1078 void TemplateTable::bastore()
1079 {
1080   transition(itos, vtos);
1081   __ pop_i(r1);
1082   __ pop_ptr(r3);
1083   // r0: value
1084   // r1: index
1085   // r3: array
1086   index_check(r3, r1); // prefer index in r1
1087   __ lea(rscratch1, Address(r3, r1, Address::uxtw(0)));
1088   __ strb(r0, Address(rscratch1,
1089                       arrayOopDesc::base_offset_in_bytes(T_BYTE)));
1090 }
1091 
1092 void TemplateTable::castore()
1093 {
1094   transition(itos, vtos);
1095   __ pop_i(r1);
1096   __ pop_ptr(r3);
1097   // r0: value
1098   // r1: index
1099   // r3: array
1100   index_check(r3, r1); // prefer index in r1
1101   __ lea(rscratch1, Address(r3, r1, Address::uxtw(1)));
1102   __ strh(r0, Address(rscratch1,
1103                       arrayOopDesc::base_offset_in_bytes(T_CHAR)));
1104 }
1105 
1106 void TemplateTable::sastore()
1107 {
1108   castore();
1109 }
1110 
1111 void TemplateTable::istore(int n)
1112 {
1113   transition(itos, vtos);
1114   __ str(r0, iaddress(n));
1115 }
1116 
1117 void TemplateTable::lstore(int n)
1118 {
1119   transition(ltos, vtos);
1120   __ str(r0, laddress(n));
1121 }
1122 
1123 void TemplateTable::fstore(int n)
1124 {
1125   transition(ftos, vtos);
1126   __ strs(v0, faddress(n));
1127 }
1128 
1129 void TemplateTable::dstore(int n)
1130 {
1131   transition(dtos, vtos);
1132   __ strd(v0, daddress(n));
1133 }
1134 
1135 void TemplateTable::astore(int n)
1136 {
1137   transition(vtos, vtos);
1138   __ pop_ptr(r0);
1139   __ str(r0, iaddress(n));
1140 }
1141 
1142 void TemplateTable::pop()
1143 {
1144   transition(vtos, vtos);
1145   __ add(esp, esp, Interpreter::stackElementSize);
1146 }
1147 
1148 void TemplateTable::pop2()
1149 {
1150   transition(vtos, vtos);
1151   __ add(esp, esp, 2 * Interpreter::stackElementSize);
1152 }
1153 
1154 void TemplateTable::dup()
1155 {
1156   transition(vtos, vtos);
1157   __ ldr(r0, Address(esp, 0));
1158   __ push(r0);
1159   // stack: ..., a, a
1160 }
1161 
1162 void TemplateTable::dup_x1()
1163 {
1164   transition(vtos, vtos);
1165   // stack: ..., a, b
1166   __ ldr(r0, at_tos());  // load b
1167   __ ldr(r2, at_tos_p1());  // load a
1168   __ str(r0, at_tos_p1());  // store b
1169   __ str(r2, at_tos());  // store a
1170   __ push(r0);                  // push b
1171   // stack: ..., b, a, b
1172 }
1173 
1174 void TemplateTable::dup_x2()
1175 {
1176   transition(vtos, vtos);
1177   // stack: ..., a, b, c
1178   __ ldr(r0, at_tos());  // load c
1179   __ ldr(r2, at_tos_p2());  // load a
1180   __ str(r0, at_tos_p2());  // store c in a
1181   __ push(r0);      // push c
1182   // stack: ..., c, b, c, c
1183   __ ldr(r0, at_tos_p2());  // load b
1184   __ str(r2, at_tos_p2());  // store a in b
1185   // stack: ..., c, a, c, c
1186   __ str(r0, at_tos_p1());  // store b in c
1187   // stack: ..., c, a, b, c
1188 }
1189 
1190 void TemplateTable::dup2()
1191 {
1192   transition(vtos, vtos);
1193   // stack: ..., a, b
1194   __ ldr(r0, at_tos_p1());  // load a
1195   __ push(r0);                  // push a
1196   __ ldr(r0, at_tos_p1());  // load b
1197   __ push(r0);                  // push b
1198   // stack: ..., a, b, a, b
1199 }
1200 
1201 void TemplateTable::dup2_x1()
1202 {
1203   transition(vtos, vtos);
1204   // stack: ..., a, b, c
1205   __ ldr(r2, at_tos());  // load c
1206   __ ldr(r0, at_tos_p1());  // load b
1207   __ push(r0);                  // push b
1208   __ push(r2);                  // push c
1209   // stack: ..., a, b, c, b, c
1210   __ str(r2, at_tos_p3());  // store c in b
1211   // stack: ..., a, c, c, b, c
1212   __ ldr(r2, at_tos_p4());  // load a
1213   __ str(r2, at_tos_p2());  // store a in 2nd c
1214   // stack: ..., a, c, a, b, c
1215   __ str(r0, at_tos_p4());  // store b in a
1216   // stack: ..., b, c, a, b, c
1217 }
1218 
1219 void TemplateTable::dup2_x2()
1220 {
1221   transition(vtos, vtos);
1222   // stack: ..., a, b, c, d
1223   __ ldr(r2, at_tos());  // load d
1224   __ ldr(r0, at_tos_p1());  // load c
1225   __ push(r0)            ;      // push c
1226   __ push(r2);                  // push d
1227   // stack: ..., a, b, c, d, c, d
1228   __ ldr(r0, at_tos_p4());  // load b
1229   __ str(r0, at_tos_p2());  // store b in d
1230   __ str(r2, at_tos_p4());  // store d in b
1231   // stack: ..., a, d, c, b, c, d
1232   __ ldr(r2, at_tos_p5());  // load a
1233   __ ldr(r0, at_tos_p3());  // load c
1234   __ str(r2, at_tos_p3());  // store a in c
1235   __ str(r0, at_tos_p5());  // store c in a
1236   // stack: ..., c, d, a, b, c, d
1237 }
1238 
1239 void TemplateTable::swap()
1240 {
1241   transition(vtos, vtos);
1242   // stack: ..., a, b
1243   __ ldr(r2, at_tos_p1());  // load a
1244   __ ldr(r0, at_tos());  // load b
1245   __ str(r2, at_tos());  // store a in b
1246   __ str(r0, at_tos_p1());  // store b in a
1247   // stack: ..., b, a
1248 }
1249 
1250 void TemplateTable::iop2(Operation op)
1251 {
1252   transition(itos, itos);
1253   // r0 <== r1 op r0
1254   __ pop_i(r1);
1255   switch (op) {
1256   case add  : __ addw(r0, r1, r0); break;
1257   case sub  : __ subw(r0, r1, r0); break;
1258   case mul  : __ mulw(r0, r1, r0); break;
1259   case _and : __ andw(r0, r1, r0); break;
1260   case _or  : __ orrw(r0, r1, r0); break;
1261   case _xor : __ eorw(r0, r1, r0); break;
1262   case shl  : __ lslvw(r0, r1, r0); break;
1263   case shr  : __ asrvw(r0, r1, r0); break;
1264   case ushr : __ lsrvw(r0, r1, r0);break;
1265   default   : ShouldNotReachHere();
1266   }
1267 }
1268 
1269 void TemplateTable::lop2(Operation op)
1270 {
1271   transition(ltos, ltos);
1272   // r0 <== r1 op r0
1273   __ pop_l(r1);
1274   switch (op) {
1275   case add  : __ add(r0, r1, r0); break;
1276   case sub  : __ sub(r0, r1, r0); break;
1277   case mul  : __ mul(r0, r1, r0); break;
1278   case _and : __ andr(r0, r1, r0); break;
1279   case _or  : __ orr(r0, r1, r0); break;
1280   case _xor : __ eor(r0, r1, r0); break;
1281   default   : ShouldNotReachHere();
1282   }
1283 }
1284 
1285 void TemplateTable::idiv()
1286 {
1287   transition(itos, itos);
1288   // explicitly check for div0
1289   Label no_div0;
1290   __ cbnzw(r0, no_div0);
1291   __ mov(rscratch1, Interpreter::_throw_ArithmeticException_entry);
1292   __ br(rscratch1);
1293   __ bind(no_div0);
1294   __ pop_i(r1);
1295   // r0 <== r1 idiv r0
1296   __ corrected_idivl(r0, r1, r0, /* want_remainder */ false);
1297 }
1298 
1299 void TemplateTable::irem()
1300 {
1301   transition(itos, itos);
1302   // explicitly check for div0
1303   Label no_div0;
1304   __ cbnzw(r0, no_div0);
1305   __ mov(rscratch1, Interpreter::_throw_ArithmeticException_entry);
1306   __ br(rscratch1);
1307   __ bind(no_div0);
1308   __ pop_i(r1);
1309   // r0 <== r1 irem r0
1310   __ corrected_idivl(r0, r1, r0, /* want_remainder */ true);
1311 }
1312 
1313 void TemplateTable::lmul()
1314 {
1315   transition(ltos, ltos);
1316   __ pop_l(r1);
1317   __ mul(r0, r0, r1);
1318 }
1319 
1320 void TemplateTable::ldiv()
1321 {
1322   transition(ltos, ltos);
1323   // explicitly check for div0
1324   Label no_div0;
1325   __ cbnz(r0, no_div0);
1326   __ mov(rscratch1, Interpreter::_throw_ArithmeticException_entry);
1327   __ br(rscratch1);
1328   __ bind(no_div0);
1329   __ pop_l(r1);
1330   // r0 <== r1 ldiv r0
1331   __ corrected_idivq(r0, r1, r0, /* want_remainder */ false);
1332 }
1333 
1334 void TemplateTable::lrem()
1335 {
1336   transition(ltos, ltos);
1337   // explicitly check for div0
1338   Label no_div0;
1339   __ cbnz(r0, no_div0);
1340   __ mov(rscratch1, Interpreter::_throw_ArithmeticException_entry);
1341   __ br(rscratch1);
1342   __ bind(no_div0);
1343   __ pop_l(r1);
1344   // r0 <== r1 lrem r0
1345   __ corrected_idivq(r0, r1, r0, /* want_remainder */ true);
1346 }
1347 
1348 void TemplateTable::lshl()
1349 {
1350   transition(itos, ltos);
1351   // shift count is in r0
1352   __ pop_l(r1);
1353   __ lslv(r0, r1, r0);
1354 }
1355 
1356 void TemplateTable::lshr()
1357 {
1358   transition(itos, ltos);
1359   // shift count is in r0
1360   __ pop_l(r1);
1361   __ asrv(r0, r1, r0);
1362 }
1363 
1364 void TemplateTable::lushr()
1365 {
1366   transition(itos, ltos);
1367   // shift count is in r0
1368   __ pop_l(r1);
1369   __ lsrv(r0, r1, r0);
1370 }
1371 
1372 void TemplateTable::fop2(Operation op)
1373 {
1374   transition(ftos, ftos);
1375   switch (op) {
1376   case add:
1377     // n.b. use ldrd because this is a 64 bit slot
1378     __ pop_f(v1);
1379     __ fadds(v0, v1, v0);
1380     break;
1381   case sub:
1382     __ pop_f(v1);
1383     __ fsubs(v0, v1, v0);
1384     break;
1385   case mul:
1386     __ pop_f(v1);
1387     __ fmuls(v0, v1, v0);
1388     break;
1389   case div:
1390     __ pop_f(v1);
1391     __ fdivs(v0, v1, v0);
1392     break;
1393   case rem:
1394     __ fmovs(v1, v0);
1395     __ pop_f(v0);
1396     __ call_VM_leaf_base1(CAST_FROM_FN_PTR(address, SharedRuntime::frem),
1397                          0, 2, MacroAssembler::ret_type_float);
1398     break;
1399   default:
1400     ShouldNotReachHere();
1401     break;
1402   }
1403 }
1404 
1405 void TemplateTable::dop2(Operation op)
1406 {
1407   transition(dtos, dtos);
1408   switch (op) {
1409   case add:
1410     // n.b. use ldrd because this is a 64 bit slot
1411     __ pop_d(v1);
1412     __ faddd(v0, v1, v0);
1413     break;
1414   case sub:
1415     __ pop_d(v1);
1416     __ fsubd(v0, v1, v0);
1417     break;
1418   case mul:
1419     __ pop_d(v1);
1420     __ fmuld(v0, v1, v0);
1421     break;
1422   case div:
1423     __ pop_d(v1);
1424     __ fdivd(v0, v1, v0);
1425     break;
1426   case rem:
1427     __ fmovd(v1, v0);
1428     __ pop_d(v0);
1429     __ call_VM_leaf_base1(CAST_FROM_FN_PTR(address, SharedRuntime::drem),
1430                          0, 2, MacroAssembler::ret_type_double);
1431     break;
1432   default:
1433     ShouldNotReachHere();
1434     break;
1435   }
1436 }
1437 
1438 void TemplateTable::ineg()
1439 {
1440   transition(itos, itos);
1441   __ negw(r0, r0);
1442 
1443 }
1444 
1445 void TemplateTable::lneg()
1446 {
1447   transition(ltos, ltos);
1448   __ neg(r0, r0);
1449 }
1450 
1451 void TemplateTable::fneg()
1452 {
1453   transition(ftos, ftos);
1454   __ fnegs(v0, v0);
1455 }
1456 
1457 void TemplateTable::dneg()
1458 {
1459   transition(dtos, dtos);
1460   __ fnegd(v0, v0);
1461 }
1462 
1463 void TemplateTable::iinc()
1464 {
1465   transition(vtos, vtos);
1466   __ load_signed_byte(r1, at_bcp(2)); // get constant
1467   locals_index(r2);
1468   __ ldr(r0, iaddress(r2));
1469   __ addw(r0, r0, r1);
1470   __ str(r0, iaddress(r2));
1471 }
1472 
1473 void TemplateTable::wide_iinc()
1474 {
1475   transition(vtos, vtos);
1476   // __ mov(r1, zr);
1477   __ ldrw(r1, at_bcp(2)); // get constant and index
1478   __ rev16(r1, r1);
1479   __ ubfx(r2, r1, 0, 16);
1480   __ neg(r2, r2);
1481   __ sbfx(r1, r1, 16, 16);
1482   __ ldr(r0, iaddress(r2));
1483   __ addw(r0, r0, r1);
1484   __ str(r0, iaddress(r2));
1485 }
1486 
1487 void TemplateTable::convert()
1488 {
1489   // Checking
1490 #ifdef ASSERT
1491   {
1492     TosState tos_in  = ilgl;
1493     TosState tos_out = ilgl;
1494     switch (bytecode()) {
1495     case Bytecodes::_i2l: // fall through
1496     case Bytecodes::_i2f: // fall through
1497     case Bytecodes::_i2d: // fall through
1498     case Bytecodes::_i2b: // fall through
1499     case Bytecodes::_i2c: // fall through
1500     case Bytecodes::_i2s: tos_in = itos; break;
1501     case Bytecodes::_l2i: // fall through
1502     case Bytecodes::_l2f: // fall through
1503     case Bytecodes::_l2d: tos_in = ltos; break;
1504     case Bytecodes::_f2i: // fall through
1505     case Bytecodes::_f2l: // fall through
1506     case Bytecodes::_f2d: tos_in = ftos; break;
1507     case Bytecodes::_d2i: // fall through
1508     case Bytecodes::_d2l: // fall through
1509     case Bytecodes::_d2f: tos_in = dtos; break;
1510     default             : ShouldNotReachHere();
1511     }
1512     switch (bytecode()) {
1513     case Bytecodes::_l2i: // fall through
1514     case Bytecodes::_f2i: // fall through
1515     case Bytecodes::_d2i: // fall through
1516     case Bytecodes::_i2b: // fall through
1517     case Bytecodes::_i2c: // fall through
1518     case Bytecodes::_i2s: tos_out = itos; break;
1519     case Bytecodes::_i2l: // fall through
1520     case Bytecodes::_f2l: // fall through
1521     case Bytecodes::_d2l: tos_out = ltos; break;
1522     case Bytecodes::_i2f: // fall through
1523     case Bytecodes::_l2f: // fall through
1524     case Bytecodes::_d2f: tos_out = ftos; break;
1525     case Bytecodes::_i2d: // fall through
1526     case Bytecodes::_l2d: // fall through
1527     case Bytecodes::_f2d: tos_out = dtos; break;
1528     default             : ShouldNotReachHere();
1529     }
1530     transition(tos_in, tos_out);
1531   }
1532 #endif // ASSERT
1533   // static const int64_t is_nan = 0x8000000000000000L;
1534 
1535   // Conversion
1536   switch (bytecode()) {
1537   case Bytecodes::_i2l:
1538     __ sxtw(r0, r0);
1539     break;
1540   case Bytecodes::_i2f:
1541     __ scvtfws(v0, r0);
1542     break;
1543   case Bytecodes::_i2d:
1544     __ scvtfwd(v0, r0);
1545     break;
1546   case Bytecodes::_i2b:
1547     __ sxtbw(r0, r0);
1548     break;
1549   case Bytecodes::_i2c:
1550     __ uxthw(r0, r0);
1551     break;
1552   case Bytecodes::_i2s:
1553     __ sxthw(r0, r0);
1554     break;
1555   case Bytecodes::_l2i:
1556     __ uxtw(r0, r0);
1557     break;
1558   case Bytecodes::_l2f:
1559     __ scvtfs(v0, r0);
1560     break;
1561   case Bytecodes::_l2d:
1562     __ scvtfd(v0, r0);
1563     break;
1564   case Bytecodes::_f2i:
1565   {
1566     Label L_Okay;
1567     __ clear_fpsr();
1568     __ fcvtzsw(r0, v0);
1569     __ get_fpsr(r1);
1570     __ cbzw(r1, L_Okay);
1571     __ call_VM_leaf_base1(CAST_FROM_FN_PTR(address, SharedRuntime::f2i),
1572                          0, 1, MacroAssembler::ret_type_integral);
1573     __ bind(L_Okay);
1574   }
1575     break;
1576   case Bytecodes::_f2l:
1577   {
1578     Label L_Okay;
1579     __ clear_fpsr();
1580     __ fcvtzs(r0, v0);
1581     __ get_fpsr(r1);
1582     __ cbzw(r1, L_Okay);
1583     __ call_VM_leaf_base1(CAST_FROM_FN_PTR(address, SharedRuntime::f2l),
1584                          0, 1, MacroAssembler::ret_type_integral);
1585     __ bind(L_Okay);
1586   }
1587     break;
1588   case Bytecodes::_f2d:
1589     __ fcvts(v0, v0);
1590     break;
1591   case Bytecodes::_d2i:
1592   {
1593     Label L_Okay;
1594     __ clear_fpsr();
1595     __ fcvtzdw(r0, v0);
1596     __ get_fpsr(r1);
1597     __ cbzw(r1, L_Okay);
1598     __ call_VM_leaf_base1(CAST_FROM_FN_PTR(address, SharedRuntime::d2i),
1599                          0, 1, MacroAssembler::ret_type_integral);
1600     __ bind(L_Okay);
1601   }
1602     break;
1603   case Bytecodes::_d2l:
1604   {
1605     Label L_Okay;
1606     __ clear_fpsr();
1607     __ fcvtzd(r0, v0);
1608     __ get_fpsr(r1);
1609     __ cbzw(r1, L_Okay);
1610     __ call_VM_leaf_base1(CAST_FROM_FN_PTR(address, SharedRuntime::d2l),
1611                          0, 1, MacroAssembler::ret_type_integral);
1612     __ bind(L_Okay);
1613   }
1614     break;
1615   case Bytecodes::_d2f:
1616     __ fcvtd(v0, v0);
1617     break;
1618   default:
1619     ShouldNotReachHere();
1620   }
1621 }
1622 
1623 void TemplateTable::lcmp()
1624 {
1625   transition(ltos, itos);
1626   Label done;
1627   __ pop_l(r1);
1628   __ cmp(r1, r0);
1629   __ mov(r0, (u_int64_t)-1L);
1630   __ br(Assembler::LT, done);
1631   // __ mov(r0, 1UL);
1632   // __ csel(r0, r0, zr, Assembler::NE);
1633   // and here is a faster way
1634   __ csinc(r0, zr, zr, Assembler::EQ);
1635   __ bind(done);
1636 }
1637 
1638 void TemplateTable::float_cmp(bool is_float, int unordered_result)
1639 {
1640   Label done;
1641   if (is_float) {
1642     // XXX get rid of pop here, use ... reg, mem32
1643     __ pop_f(v1);
1644     __ fcmps(v1, v0);
1645   } else {
1646     // XXX get rid of pop here, use ... reg, mem64
1647     __ pop_d(v1);
1648     __ fcmpd(v1, v0);
1649   }
1650   if (unordered_result < 0) {
1651     // we want -1 for unordered or less than, 0 for equal and 1 for
1652     // greater than.
1653     __ mov(r0, (u_int64_t)-1L);
1654     // for FP LT tests less than or unordered
1655     __ br(Assembler::LT, done);
1656     // install 0 for EQ otherwise 1
1657     __ csinc(r0, zr, zr, Assembler::EQ);
1658   } else {
1659     // we want -1 for less than, 0 for equal and 1 for unordered or
1660     // greater than.
1661     __ mov(r0, 1L);
1662     // for FP HI tests greater than or unordered
1663     __ br(Assembler::HI, done);
1664     // install 0 for EQ otherwise ~0
1665     __ csinv(r0, zr, zr, Assembler::EQ);
1666 
1667   }
1668   __ bind(done);
1669 }
1670 
1671 void TemplateTable::branch(bool is_jsr, bool is_wide)
1672 {
1673   // We might be moving to a safepoint.  The thread which calls
1674   // Interpreter::notice_safepoints() will effectively flush its cache
1675   // when it makes a system call, but we need to do something to
1676   // ensure that we see the changed dispatch table.
1677   __ membar(MacroAssembler::LoadLoad);
1678 
1679   __ profile_taken_branch(r0, r1);
1680   const ByteSize be_offset = MethodCounters::backedge_counter_offset() +
1681                              InvocationCounter::counter_offset();
1682   const ByteSize inv_offset = MethodCounters::invocation_counter_offset() +
1683                               InvocationCounter::counter_offset();
1684 
1685   // load branch displacement
1686   if (!is_wide) {
1687     __ ldrh(r2, at_bcp(1));
1688     __ rev16(r2, r2);
1689     // sign extend the 16 bit value in r2
1690     __ sbfm(r2, r2, 0, 15);
1691   } else {
1692     __ ldrw(r2, at_bcp(1));
1693     __ revw(r2, r2);
1694     // sign extend the 32 bit value in r2
1695     __ sbfm(r2, r2, 0, 31);
1696   }
1697 
1698   // Handle all the JSR stuff here, then exit.
1699   // It's much shorter and cleaner than intermingling with the non-JSR
1700   // normal-branch stuff occurring below.
1701 
1702   if (is_jsr) {
1703     // Pre-load the next target bytecode into rscratch1
1704     __ load_unsigned_byte(rscratch1, Address(rbcp, r2));
1705     // compute return address as bci
1706     __ ldr(rscratch2, Address(rmethod, Method::const_offset()));
1707     __ add(rscratch2, rscratch2,
1708            in_bytes(ConstMethod::codes_offset()) - (is_wide ? 5 : 3));
1709     __ sub(r1, rbcp, rscratch2);
1710     __ push_i(r1);
1711     // Adjust the bcp by the 16-bit displacement in r2
1712     __ add(rbcp, rbcp, r2);
1713     __ dispatch_only(vtos);
1714     return;
1715   }
1716 
1717   // Normal (non-jsr) branch handling
1718 
1719   // Adjust the bcp by the displacement in r2
1720   __ add(rbcp, rbcp, r2);
1721 
1722   assert(UseLoopCounter || !UseOnStackReplacement,
1723          "on-stack-replacement requires loop counters");
1724   Label backedge_counter_overflow;
1725   Label profile_method;
1726   Label dispatch;
1727   if (UseLoopCounter) {
1728     // increment backedge counter for backward branches
1729     // r0: MDO
1730     // w1: MDO bumped taken-count
1731     // r2: target offset
1732     __ cmp(r2, zr);
1733     __ br(Assembler::GT, dispatch); // count only if backward branch
1734 
1735     // ECN: FIXME: This code smells
1736     // check if MethodCounters exists
1737     Label has_counters;
1738     __ ldr(rscratch1, Address(rmethod, Method::method_counters_offset()));
1739     __ cbnz(rscratch1, has_counters);
1740     __ push(r0);
1741     __ push(r1);
1742     __ push(r2);
1743     __ call_VM(noreg, CAST_FROM_FN_PTR(address,
1744             InterpreterRuntime::build_method_counters), rmethod);
1745     __ pop(r2);
1746     __ pop(r1);
1747     __ pop(r0);
1748     __ ldr(rscratch1, Address(rmethod, Method::method_counters_offset()));
1749     __ cbz(rscratch1, dispatch); // No MethodCounters allocated, OutOfMemory
1750     __ bind(has_counters);
1751 
1752     if (TieredCompilation) {
1753       Label no_mdo;
1754       int increment = InvocationCounter::count_increment;
1755       if (ProfileInterpreter) {
1756         // Are we profiling?
1757         __ ldr(r1, Address(rmethod, in_bytes(Method::method_data_offset())));
1758         __ cbz(r1, no_mdo);
1759         // Increment the MDO backedge counter
1760         const Address mdo_backedge_counter(r1, in_bytes(MethodData::backedge_counter_offset()) +
1761                                            in_bytes(InvocationCounter::counter_offset()));
1762         const Address mask(r1, in_bytes(MethodData::backedge_mask_offset()));
1763         __ increment_mask_and_jump(mdo_backedge_counter, increment, mask,
1764                                    r0, rscratch1, false, Assembler::EQ, &backedge_counter_overflow);
1765         __ b(dispatch);
1766       }
1767       __ bind(no_mdo);
1768       // Increment backedge counter in MethodCounters*
1769       __ ldr(rscratch1, Address(rmethod, Method::method_counters_offset()));
1770       const Address mask(rscratch1, in_bytes(MethodCounters::backedge_mask_offset()));
1771       __ increment_mask_and_jump(Address(rscratch1, be_offset), increment, mask,
1772                                  r0, rscratch2, false, Assembler::EQ, &backedge_counter_overflow);
1773     } else { // not TieredCompilation
1774       // increment counter
1775       __ ldr(rscratch2, Address(rmethod, Method::method_counters_offset()));
1776       __ ldrw(r0, Address(rscratch2, be_offset));        // load backedge counter
1777       __ addw(rscratch1, r0, InvocationCounter::count_increment); // increment counter
1778       __ strw(rscratch1, Address(rscratch2, be_offset));        // store counter
1779 
1780       __ ldrw(r0, Address(rscratch2, inv_offset));    // load invocation counter
1781       __ andw(r0, r0, (unsigned)InvocationCounter::count_mask_value); // and the status bits
1782       __ addw(r0, r0, rscratch1);        // add both counters
1783 
1784       if (ProfileInterpreter) {
1785         // Test to see if we should create a method data oop
1786         __ ldrw(rscratch1, Address(rscratch2, in_bytes(MethodCounters::interpreter_profile_limit_offset())));
1787         __ cmpw(r0, rscratch1);
1788         __ br(Assembler::LT, dispatch);
1789 
1790         // if no method data exists, go to profile method
1791         __ test_method_data_pointer(r0, profile_method);
1792 
1793         if (UseOnStackReplacement) {
1794           // check for overflow against w1 which is the MDO taken count
1795           __ ldrw(rscratch1, Address(rscratch2, in_bytes(MethodCounters::interpreter_backward_branch_limit_offset())));
1796           __ cmpw(r1, rscratch1);
1797           __ br(Assembler::LO, dispatch); // Intel == Assembler::below
1798 
1799           // When ProfileInterpreter is on, the backedge_count comes
1800           // from the MethodData*, which value does not get reset on
1801           // the call to frequency_counter_overflow().  To avoid
1802           // excessive calls to the overflow routine while the method is
1803           // being compiled, add a second test to make sure the overflow
1804           // function is called only once every overflow_frequency.
1805           const int overflow_frequency = 1024;
1806           __ andsw(r1, r1, overflow_frequency - 1);
1807           __ br(Assembler::EQ, backedge_counter_overflow);
1808 
1809         }
1810       } else {
1811         if (UseOnStackReplacement) {
1812           // check for overflow against w0, which is the sum of the
1813           // counters
1814           __ ldrw(rscratch1, Address(rscratch2, in_bytes(MethodCounters::interpreter_backward_branch_limit_offset())));
1815           __ cmpw(r0, rscratch1);
1816           __ br(Assembler::HS, backedge_counter_overflow); // Intel == Assembler::aboveEqual
1817         }
1818       }
1819     }
1820   }
1821   __ bind(dispatch);
1822 
1823   // Pre-load the next target bytecode into rscratch1
1824   __ load_unsigned_byte(rscratch1, Address(rbcp, 0));
1825 
1826   // continue with the bytecode @ target
1827   // rscratch1: target bytecode
1828   // rbcp: target bcp
1829   __ dispatch_only(vtos);
1830 
1831   if (UseLoopCounter) {
1832     if (ProfileInterpreter) {
1833       // Out-of-line code to allocate method data oop.
1834       __ bind(profile_method);
1835       __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::profile_method));
1836       __ load_unsigned_byte(r1, Address(rbcp, 0));  // restore target bytecode
1837       __ set_method_data_pointer_for_bcp();
1838       __ b(dispatch);
1839     }
1840 
1841     if (TieredCompilation || UseOnStackReplacement) {
1842       // invocation counter overflow
1843       __ bind(backedge_counter_overflow);
1844       __ neg(r2, r2);
1845       __ add(r2, r2, rbcp);     // branch bcp
1846       // IcoResult frequency_counter_overflow([JavaThread*], address branch_bcp)
1847       __ call_VM(noreg,
1848                  CAST_FROM_FN_PTR(address,
1849                                   InterpreterRuntime::frequency_counter_overflow),
1850                  r2);
1851       if (!UseOnStackReplacement)
1852         __ b(dispatch);
1853     }
1854 
1855     if (UseOnStackReplacement) {
1856       __ load_unsigned_byte(r1, Address(rbcp, 0));  // restore target bytecode
1857 
1858       // r0: osr nmethod (osr ok) or NULL (osr not possible)
1859       // w1: target bytecode
1860       // r2: scratch
1861       __ cbz(r0, dispatch);     // test result -- no osr if null
1862       // nmethod may have been invalidated (VM may block upon call_VM return)
1863       __ ldrb(r2, Address(r0, nmethod::state_offset()));
1864       if (nmethod::in_use != 0)
1865         __ sub(r2, r2, nmethod::in_use);
1866       __ cbnz(r2, dispatch);
1867 
1868       // We have the address of an on stack replacement routine in r0
1869       // We need to prepare to execute the OSR method. First we must
1870       // migrate the locals and monitors off of the stack.
1871 
1872       __ mov(r19, r0);                             // save the nmethod
1873 
1874       call_VM(noreg, CAST_FROM_FN_PTR(address, SharedRuntime::OSR_migration_begin));
1875 
1876       // r0 is OSR buffer, move it to expected parameter location
1877       __ mov(j_rarg0, r0);
1878 
1879       // remove activation
1880       // get sender esp
1881       __ ldr(esp,
1882           Address(rfp, frame::interpreter_frame_sender_sp_offset * wordSize));
1883       // remove frame anchor
1884       __ leave();
1885       // Ensure compiled code always sees stack at proper alignment
1886       __ andr(sp, esp, -16);
1887 
1888       // and begin the OSR nmethod
1889       __ ldr(rscratch1, Address(r19, nmethod::osr_entry_point_offset()));
1890       __ br(rscratch1);
1891     }
1892   }
1893 }
1894 
1895 
1896 void TemplateTable::if_0cmp(Condition cc)
1897 {
1898   transition(itos, vtos);
1899   // assume branch is more often taken than not (loops use backward branches)
1900   Label not_taken;
1901   if (cc == equal)
1902     __ cbnzw(r0, not_taken);
1903   else if (cc == not_equal)
1904     __ cbzw(r0, not_taken);
1905   else {
1906     __ andsw(zr, r0, r0);
1907     __ br(j_not(cc), not_taken);
1908   }
1909 
1910   branch(false, false);
1911   __ bind(not_taken);
1912   __ profile_not_taken_branch(r0);
1913 }
1914 
1915 void TemplateTable::if_icmp(Condition cc)
1916 {
1917   transition(itos, vtos);
1918   // assume branch is more often taken than not (loops use backward branches)
1919   Label not_taken;
1920   __ pop_i(r1);
1921   __ cmpw(r1, r0, Assembler::LSL);
1922   __ br(j_not(cc), not_taken);
1923   branch(false, false);
1924   __ bind(not_taken);
1925   __ profile_not_taken_branch(r0);
1926 }
1927 
1928 void TemplateTable::if_nullcmp(Condition cc)
1929 {
1930   transition(atos, vtos);
1931   // assume branch is more often taken than not (loops use backward branches)
1932   Label not_taken;
1933   if (cc == equal)
1934     __ cbnz(r0, not_taken);
1935   else
1936     __ cbz(r0, not_taken);
1937   branch(false, false);
1938   __ bind(not_taken);
1939   __ profile_not_taken_branch(r0);
1940 }
1941 
1942 void TemplateTable::if_acmp(Condition cc)
1943 {
1944   transition(atos, vtos);
1945   // assume branch is more often taken than not (loops use backward branches)
1946   Label not_taken;
1947   __ pop_ptr(r1);
1948   __ cmp(r1, r0);
1949   __ br(j_not(cc), not_taken);
1950   branch(false, false);
1951   __ bind(not_taken);
1952   __ profile_not_taken_branch(r0);
1953 }
1954 
1955 void TemplateTable::ret() {
1956   transition(vtos, vtos);
1957   // We might be moving to a safepoint.  The thread which calls
1958   // Interpreter::notice_safepoints() will effectively flush its cache
1959   // when it makes a system call, but we need to do something to
1960   // ensure that we see the changed dispatch table.
1961   __ membar(MacroAssembler::LoadLoad);
1962 
1963   locals_index(r1);
1964   __ ldr(r1, aaddress(r1)); // get return bci, compute return bcp
1965   __ profile_ret(r1, r2);
1966   __ ldr(rbcp, Address(rmethod, Method::const_offset()));
1967   __ lea(rbcp, Address(rbcp, r1));
1968   __ add(rbcp, rbcp, in_bytes(ConstMethod::codes_offset()));
1969   __ dispatch_next(vtos);
1970 }
1971 
1972 void TemplateTable::wide_ret() {
1973   transition(vtos, vtos);
1974   locals_index_wide(r1);
1975   __ ldr(r1, aaddress(r1)); // get return bci, compute return bcp
1976   __ profile_ret(r1, r2);
1977   __ ldr(rbcp, Address(rmethod, Method::const_offset()));
1978   __ lea(rbcp, Address(rbcp, r1));
1979   __ add(rbcp, rbcp, in_bytes(ConstMethod::codes_offset()));
1980   __ dispatch_next(vtos);
1981 }
1982 
1983 
1984 void TemplateTable::tableswitch() {
1985   Label default_case, continue_execution;
1986   transition(itos, vtos);
1987   // align rbcp
1988   __ lea(r1, at_bcp(BytesPerInt));
1989   __ andr(r1, r1, -BytesPerInt);
1990   // load lo & hi
1991   __ ldrw(r2, Address(r1, BytesPerInt));
1992   __ ldrw(r3, Address(r1, 2 * BytesPerInt));
1993   __ rev32(r2, r2);
1994   __ rev32(r3, r3);
1995   // check against lo & hi
1996   __ cmpw(r0, r2);
1997   __ br(Assembler::LT, default_case);
1998   __ cmpw(r0, r3);
1999   __ br(Assembler::GT, default_case);
2000   // lookup dispatch offset
2001   __ subw(r0, r0, r2);
2002   __ lea(r3, Address(r1, r0, Address::uxtw(2)));
2003   __ ldrw(r3, Address(r3, 3 * BytesPerInt));
2004   __ profile_switch_case(r0, r1, r2);
2005   // continue execution
2006   __ bind(continue_execution);
2007   __ rev32(r3, r3);
2008   __ load_unsigned_byte(rscratch1, Address(rbcp, r3, Address::sxtw(0)));
2009   __ add(rbcp, rbcp, r3, ext::sxtw);
2010   __ dispatch_only(vtos);
2011   // handle default
2012   __ bind(default_case);
2013   __ profile_switch_default(r0);
2014   __ ldrw(r3, Address(r1, 0));
2015   __ b(continue_execution);
2016 }
2017 
2018 void TemplateTable::lookupswitch() {
2019   transition(itos, itos);
2020   __ stop("lookupswitch bytecode should have been rewritten");
2021 }
2022 
2023 void TemplateTable::fast_linearswitch() {
2024   transition(itos, vtos);
2025   Label loop_entry, loop, found, continue_execution;
2026   // bswap r0 so we can avoid bswapping the table entries
2027   __ rev32(r0, r0);
2028   // align rbcp
2029   __ lea(r19, at_bcp(BytesPerInt)); // btw: should be able to get rid of
2030                                     // this instruction (change offsets
2031                                     // below)
2032   __ andr(r19, r19, -BytesPerInt);
2033   // set counter
2034   __ ldrw(r1, Address(r19, BytesPerInt));
2035   __ rev32(r1, r1);
2036   __ b(loop_entry);
2037   // table search
2038   __ bind(loop);
2039   __ lea(rscratch1, Address(r19, r1, Address::lsl(3)));
2040   __ ldrw(rscratch1, Address(rscratch1, 2 * BytesPerInt));
2041   __ cmpw(r0, rscratch1);
2042   __ br(Assembler::EQ, found);
2043   __ bind(loop_entry);
2044   __ subs(r1, r1, 1);
2045   __ br(Assembler::PL, loop);
2046   // default case
2047   __ profile_switch_default(r0);
2048   __ ldrw(r3, Address(r19, 0));
2049   __ b(continue_execution);
2050   // entry found -> get offset
2051   __ bind(found);
2052   __ lea(rscratch1, Address(r19, r1, Address::lsl(3)));
2053   __ ldrw(r3, Address(rscratch1, 3 * BytesPerInt));
2054   __ profile_switch_case(r1, r0, r19);
2055   // continue execution
2056   __ bind(continue_execution);
2057   __ rev32(r3, r3);
2058   __ add(rbcp, rbcp, r3, ext::sxtw);
2059   __ ldrb(rscratch1, Address(rbcp, 0));
2060   __ dispatch_only(vtos);
2061 }
2062 
2063 void TemplateTable::fast_binaryswitch() {
2064   transition(itos, vtos);
2065   // Implementation using the following core algorithm:
2066   //
2067   // int binary_search(int key, LookupswitchPair* array, int n) {
2068   //   // Binary search according to "Methodik des Programmierens" by
2069   //   // Edsger W. Dijkstra and W.H.J. Feijen, Addison Wesley Germany 1985.
2070   //   int i = 0;
2071   //   int j = n;
2072   //   while (i+1 < j) {
2073   //     // invariant P: 0 <= i < j <= n and (a[i] <= key < a[j] or Q)
2074   //     // with      Q: for all i: 0 <= i < n: key < a[i]
2075   //     // where a stands for the array and assuming that the (inexisting)
2076   //     // element a[n] is infinitely big.
2077   //     int h = (i + j) >> 1;
2078   //     // i < h < j
2079   //     if (key < array[h].fast_match()) {
2080   //       j = h;
2081   //     } else {
2082   //       i = h;
2083   //     }
2084   //   }
2085   //   // R: a[i] <= key < a[i+1] or Q
2086   //   // (i.e., if key is within array, i is the correct index)
2087   //   return i;
2088   // }
2089 
2090   // Register allocation
2091   const Register key   = r0; // already set (tosca)
2092   const Register array = r1;
2093   const Register i     = r2;
2094   const Register j     = r3;
2095   const Register h     = rscratch1;
2096   const Register temp  = rscratch2;
2097 
2098   // Find array start
2099   __ lea(array, at_bcp(3 * BytesPerInt)); // btw: should be able to
2100                                           // get rid of this
2101                                           // instruction (change
2102                                           // offsets below)
2103   __ andr(array, array, -BytesPerInt);
2104 
2105   // Initialize i & j
2106   __ mov(i, 0);                            // i = 0;
2107   __ ldrw(j, Address(array, -BytesPerInt)); // j = length(array);
2108 
2109   // Convert j into native byteordering
2110   __ rev32(j, j);
2111 
2112   // And start
2113   Label entry;
2114   __ b(entry);
2115 
2116   // binary search loop
2117   {
2118     Label loop;
2119     __ bind(loop);
2120     // int h = (i + j) >> 1;
2121     __ addw(h, i, j);                           // h = i + j;
2122     __ lsrw(h, h, 1);                                   // h = (i + j) >> 1;
2123     // if (key < array[h].fast_match()) {
2124     //   j = h;
2125     // } else {
2126     //   i = h;
2127     // }
2128     // Convert array[h].match to native byte-ordering before compare
2129     __ ldr(temp, Address(array, h, Address::lsl(3)));
2130     __ rev32(temp, temp);
2131     __ cmpw(key, temp);
2132     // j = h if (key <  array[h].fast_match())
2133     __ csel(j, h, j, Assembler::LT);
2134     // i = h if (key >= array[h].fast_match())
2135     __ csel(i, h, i, Assembler::GE);
2136     // while (i+1 < j)
2137     __ bind(entry);
2138     __ addw(h, i, 1);          // i+1
2139     __ cmpw(h, j);             // i+1 < j
2140     __ br(Assembler::LT, loop);
2141   }
2142 
2143   // end of binary search, result index is i (must check again!)
2144   Label default_case;
2145   // Convert array[i].match to native byte-ordering before compare
2146   __ ldr(temp, Address(array, i, Address::lsl(3)));
2147   __ rev32(temp, temp);
2148   __ cmpw(key, temp);
2149   __ br(Assembler::NE, default_case);
2150 
2151   // entry found -> j = offset
2152   __ add(j, array, i, ext::uxtx, 3);
2153   __ ldrw(j, Address(j, BytesPerInt));
2154   __ profile_switch_case(i, key, array);
2155   __ rev32(j, j);
2156   __ load_unsigned_byte(rscratch1, Address(rbcp, j, Address::sxtw(0)));
2157   __ lea(rbcp, Address(rbcp, j, Address::sxtw(0)));
2158   __ dispatch_only(vtos);
2159 
2160   // default case -> j = default offset
2161   __ bind(default_case);
2162   __ profile_switch_default(i);
2163   __ ldrw(j, Address(array, -2 * BytesPerInt));
2164   __ rev32(j, j);
2165   __ load_unsigned_byte(rscratch1, Address(rbcp, j, Address::sxtw(0)));
2166   __ lea(rbcp, Address(rbcp, j, Address::sxtw(0)));
2167   __ dispatch_only(vtos);
2168 }
2169 
2170 
2171 void TemplateTable::_return(TosState state)
2172 {
2173   transition(state, state);
2174   assert(_desc->calls_vm(),
2175          "inconsistent calls_vm information"); // call in remove_activation
2176 
2177   if (_desc->bytecode() == Bytecodes::_return_register_finalizer) {
2178     assert(state == vtos, "only valid state");
2179 
2180     __ ldr(c_rarg1, aaddress(0));
2181     __ load_klass(r3, c_rarg1);
2182     __ ldrw(r3, Address(r3, Klass::access_flags_offset()));
2183     __ tst(r3, JVM_ACC_HAS_FINALIZER);
2184     Label skip_register_finalizer;
2185     __ br(Assembler::EQ, skip_register_finalizer);
2186 
2187     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::register_finalizer), c_rarg1);
2188 
2189     __ bind(skip_register_finalizer);
2190   }
2191 
2192   // Issue a StoreStore barrier after all stores but before return
2193   // from any constructor for any class with a final field.  We don't
2194   // know if this is a finalizer, so we always do so.
2195   if (_desc->bytecode() == Bytecodes::_return)
2196     __ membar(MacroAssembler::StoreStore);
2197 
2198   __ remove_activation(state);
2199   __ ret(lr);
2200 }
2201 
2202 // ----------------------------------------------------------------------------
2203 // Volatile variables demand their effects be made known to all CPU's
2204 // in order.  Store buffers on most chips allow reads & writes to
2205 // reorder; the JMM's ReadAfterWrite.java test fails in -Xint mode
2206 // without some kind of memory barrier (i.e., it's not sufficient that
2207 // the interpreter does not reorder volatile references, the hardware
2208 // also must not reorder them).
2209 //
2210 // According to the new Java Memory Model (JMM):
2211 // (1) All volatiles are serialized wrt to each other.  ALSO reads &
2212 //     writes act as aquire & release, so:
2213 // (2) A read cannot let unrelated NON-volatile memory refs that
2214 //     happen after the read float up to before the read.  It's OK for
2215 //     non-volatile memory refs that happen before the volatile read to
2216 //     float down below it.
2217 // (3) Similar a volatile write cannot let unrelated NON-volatile
2218 //     memory refs that happen BEFORE the write float down to after the
2219 //     write.  It's OK for non-volatile memory refs that happen after the
2220 //     volatile write to float up before it.
2221 //
2222 // We only put in barriers around volatile refs (they are expensive),
2223 // not _between_ memory refs (that would require us to track the
2224 // flavor of the previous memory refs).  Requirements (2) and (3)
2225 // require some barriers before volatile stores and after volatile
2226 // loads.  These nearly cover requirement (1) but miss the
2227 // volatile-store-volatile-load case.  This final case is placed after
2228 // volatile-stores although it could just as well go before
2229 // volatile-loads.
2230 
2231 void TemplateTable::resolve_cache_and_index(int byte_no,
2232                                             Register Rcache,
2233                                             Register index,
2234                                             size_t index_size) {
2235   const Register temp = r19;
2236   assert_different_registers(Rcache, index, temp);
2237 
2238   Label resolved;
2239 
2240   Bytecodes::Code code = bytecode();
2241   switch (code) {
2242   case Bytecodes::_nofast_getfield: code = Bytecodes::_getfield; break;
2243   case Bytecodes::_nofast_putfield: code = Bytecodes::_putfield; break;
2244   }
2245 
2246   assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
2247   __ get_cache_and_index_and_bytecode_at_bcp(Rcache, index, temp, byte_no, 1, index_size);
2248   __ cmp(temp, (int) code);  // have we resolved this bytecode?
2249   __ br(Assembler::EQ, resolved);
2250 
2251   // resolve first time through
2252   address entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_from_cache);
2253   __ mov(temp, (int) code);
2254   __ call_VM(noreg, entry, temp);
2255 
2256   // Update registers with resolved info
2257   __ get_cache_and_index_at_bcp(Rcache, index, 1, index_size);
2258   // n.b. unlike x86 Rcache is now rcpool plus the indexed offset
2259   // so all clients ofthis method must be modified accordingly
2260   __ bind(resolved);
2261 }
2262 
2263 // The Rcache and index registers must be set before call
2264 // n.b unlike x86 cache already includes the index offset
2265 void TemplateTable::load_field_cp_cache_entry(Register obj,
2266                                               Register cache,
2267                                               Register index,
2268                                               Register off,
2269                                               Register flags,
2270                                               bool is_static = false) {
2271   assert_different_registers(cache, index, flags, off);
2272 
2273   ByteSize cp_base_offset = ConstantPoolCache::base_offset();
2274   // Field offset
2275   __ ldr(off, Address(cache, in_bytes(cp_base_offset +
2276                                           ConstantPoolCacheEntry::f2_offset())));
2277   // Flags
2278   __ ldrw(flags, Address(cache, in_bytes(cp_base_offset +
2279                                            ConstantPoolCacheEntry::flags_offset())));
2280 
2281   // klass overwrite register
2282   if (is_static) {
2283     __ ldr(obj, Address(cache, in_bytes(cp_base_offset +
2284                                         ConstantPoolCacheEntry::f1_offset())));
2285     const int mirror_offset = in_bytes(Klass::java_mirror_offset());
2286     __ ldr(obj, Address(obj, mirror_offset));
2287   }
2288 }
2289 
2290 void TemplateTable::load_invoke_cp_cache_entry(int byte_no,
2291                                                Register method,
2292                                                Register itable_index,
2293                                                Register flags,
2294                                                bool is_invokevirtual,
2295                                                bool is_invokevfinal, /*unused*/
2296                                                bool is_invokedynamic) {
2297   // setup registers
2298   const Register cache = rscratch2;
2299   const Register index = r4;
2300   assert_different_registers(method, flags);
2301   assert_different_registers(method, cache, index);
2302   assert_different_registers(itable_index, flags);
2303   assert_different_registers(itable_index, cache, index);
2304   // determine constant pool cache field offsets
2305   assert(is_invokevirtual == (byte_no == f2_byte), "is_invokevirtual flag redundant");
2306   const int method_offset = in_bytes(
2307     ConstantPoolCache::base_offset() +
2308       (is_invokevirtual
2309        ? ConstantPoolCacheEntry::f2_offset()
2310        : ConstantPoolCacheEntry::f1_offset()));
2311   const int flags_offset = in_bytes(ConstantPoolCache::base_offset() +
2312                                     ConstantPoolCacheEntry::flags_offset());
2313   // access constant pool cache fields
2314   const int index_offset = in_bytes(ConstantPoolCache::base_offset() +
2315                                     ConstantPoolCacheEntry::f2_offset());
2316 
2317   size_t index_size = (is_invokedynamic ? sizeof(u4) : sizeof(u2));
2318   resolve_cache_and_index(byte_no, cache, index, index_size);
2319   __ ldr(method, Address(cache, method_offset));
2320 
2321   if (itable_index != noreg) {
2322     __ ldr(itable_index, Address(cache, index_offset));
2323   }
2324   __ ldrw(flags, Address(cache, flags_offset));
2325 }
2326 
2327 
2328 // The registers cache and index expected to be set before call.
2329 // Correct values of the cache and index registers are preserved.
2330 void TemplateTable::jvmti_post_field_access(Register cache, Register index,
2331                                             bool is_static, bool has_tos) {
2332   // do the JVMTI work here to avoid disturbing the register state below
2333   // We use c_rarg registers here because we want to use the register used in
2334   // the call to the VM
2335   if (JvmtiExport::can_post_field_access()) {
2336     // Check to see if a field access watch has been set before we
2337     // take the time to call into the VM.
2338     Label L1;
2339     assert_different_registers(cache, index, r0);
2340     __ lea(rscratch1, ExternalAddress((address) JvmtiExport::get_field_access_count_addr()));
2341     __ ldrw(r0, Address(rscratch1));
2342     __ cbzw(r0, L1);
2343 
2344     __ get_cache_and_index_at_bcp(c_rarg2, c_rarg3, 1);
2345     __ lea(c_rarg2, Address(c_rarg2, in_bytes(ConstantPoolCache::base_offset())));
2346 
2347     if (is_static) {
2348       __ mov(c_rarg1, zr); // NULL object reference
2349     } else {
2350       __ ldr(c_rarg1, at_tos()); // get object pointer without popping it
2351       __ verify_oop(c_rarg1);
2352     }
2353     // c_rarg1: object pointer or NULL
2354     // c_rarg2: cache entry pointer
2355     // c_rarg3: jvalue object on the stack
2356     __ call_VM(noreg, CAST_FROM_FN_PTR(address,
2357                                        InterpreterRuntime::post_field_access),
2358                c_rarg1, c_rarg2, c_rarg3);
2359     __ get_cache_and_index_at_bcp(cache, index, 1);
2360     __ bind(L1);
2361   }
2362 }
2363 
2364 void TemplateTable::pop_and_check_object(Register r)
2365 {
2366   __ pop_ptr(r);
2367   __ null_check(r);  // for field access must check obj.
2368   __ verify_oop(r);
2369 }
2370 
2371 void TemplateTable::getfield_or_static(int byte_no, bool is_static, RewriteControl rc)
2372 {
2373   const Register cache = r2;
2374   const Register index = r3;
2375   const Register obj   = r4;
2376   const Register off   = r19;
2377   const Register flags = r0;
2378   const Register bc    = r4; // uses same reg as obj, so don't mix them
2379 
2380   resolve_cache_and_index(byte_no, cache, index, sizeof(u2));
2381   jvmti_post_field_access(cache, index, is_static, false);
2382   load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
2383 
2384   if (!is_static) {
2385     // obj is on the stack
2386     pop_and_check_object(obj);
2387   }
2388 
2389   const Address field(obj, off);
2390 
2391   Label Done, notByte, notInt, notShort, notChar,
2392               notLong, notFloat, notObj, notDouble;
2393 
2394   // x86 uses a shift and mask or wings it with a shift plus assert
2395   // the mask is not needed. aarch64 just uses bitfield extract
2396   __ ubfxw(flags, flags, ConstantPoolCacheEntry::tos_state_shift,  ConstantPoolCacheEntry::tos_state_bits);
2397 
2398   assert(btos == 0, "change code, btos != 0");
2399   __ cbnz(flags, notByte);
2400 
2401   // Don't rewrite getstatic, only getfield
2402   if (is_static) rc = may_not_rewrite;
2403 
2404   // btos
2405   __ load_signed_byte(r0, field);
2406   __ push(btos);
2407   // Rewrite bytecode to be faster
2408   if (rc == may_rewrite) {
2409     patch_bytecode(Bytecodes::_fast_bgetfield, bc, r1);
2410   }
2411   __ b(Done);
2412 
2413   __ bind(notByte);
2414   __ cmp(flags, atos);
2415   __ br(Assembler::NE, notObj);
2416   // atos
2417   __ load_heap_oop(r0, field);
2418   __ push(atos);
2419   if (rc == may_rewrite) {
2420     patch_bytecode(Bytecodes::_fast_agetfield, bc, r1);
2421   }
2422   __ b(Done);
2423 
2424   __ bind(notObj);
2425   __ cmp(flags, itos);
2426   __ br(Assembler::NE, notInt);
2427   // itos
2428   __ ldrw(r0, field);
2429   __ push(itos);
2430   // Rewrite bytecode to be faster
2431   if (rc == may_rewrite) {
2432     patch_bytecode(Bytecodes::_fast_igetfield, bc, r1);
2433   }
2434   __ b(Done);
2435 
2436   __ bind(notInt);
2437   __ cmp(flags, ctos);
2438   __ br(Assembler::NE, notChar);
2439   // ctos
2440   __ load_unsigned_short(r0, field);
2441   __ push(ctos);
2442   // Rewrite bytecode to be faster
2443   if (rc == may_rewrite) {
2444     patch_bytecode(Bytecodes::_fast_cgetfield, bc, r1);
2445   }
2446   __ b(Done);
2447 
2448   __ bind(notChar);
2449   __ cmp(flags, stos);
2450   __ br(Assembler::NE, notShort);
2451   // stos
2452   __ load_signed_short(r0, field);
2453   __ push(stos);
2454   // Rewrite bytecode to be faster
2455   if (rc == may_rewrite) {
2456     patch_bytecode(Bytecodes::_fast_sgetfield, bc, r1);
2457   }
2458   __ b(Done);
2459 
2460   __ bind(notShort);
2461   __ cmp(flags, ltos);
2462   __ br(Assembler::NE, notLong);
2463   // ltos
2464   __ ldr(r0, field);
2465   __ push(ltos);
2466   // Rewrite bytecode to be faster
2467   if (rc == may_rewrite) {
2468     patch_bytecode(Bytecodes::_fast_lgetfield, bc, r1);
2469   }
2470   __ b(Done);
2471 
2472   __ bind(notLong);
2473   __ cmp(flags, ftos);
2474   __ br(Assembler::NE, notFloat);
2475   // ftos
2476   __ ldrs(v0, field);
2477   __ push(ftos);
2478   // Rewrite bytecode to be faster
2479   if (rc == may_rewrite) {
2480     patch_bytecode(Bytecodes::_fast_fgetfield, bc, r1);
2481   }
2482   __ b(Done);
2483 
2484   __ bind(notFloat);
2485 #ifdef ASSERT
2486   __ cmp(flags, dtos);
2487   __ br(Assembler::NE, notDouble);
2488 #endif
2489   // dtos
2490   __ ldrd(v0, field);
2491   __ push(dtos);
2492   // Rewrite bytecode to be faster
2493   if (rc == may_rewrite) {
2494     patch_bytecode(Bytecodes::_fast_dgetfield, bc, r1);
2495   }
2496 #ifdef ASSERT
2497   __ b(Done);
2498 
2499   __ bind(notDouble);
2500   __ stop("Bad state");
2501 #endif
2502 
2503   __ bind(Done);
2504   // It's really not worth bothering to check whether this field
2505   // really is volatile in the slow case.
2506   __ membar(MacroAssembler::LoadLoad | MacroAssembler::LoadStore);
2507 }
2508 
2509 
2510 void TemplateTable::getfield(int byte_no)
2511 {
2512   getfield_or_static(byte_no, false);
2513 }
2514 
2515 void TemplateTable::nofast_getfield(int byte_no) {
2516   getfield_or_static(byte_no, false, may_not_rewrite);
2517 }
2518 
2519 void TemplateTable::getstatic(int byte_no)
2520 {
2521   getfield_or_static(byte_no, true);
2522 }
2523 
2524 // The registers cache and index expected to be set before call.
2525 // The function may destroy various registers, just not the cache and index registers.
2526 void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
2527   transition(vtos, vtos);
2528 
2529   ByteSize cp_base_offset = ConstantPoolCache::base_offset();
2530 
2531   if (JvmtiExport::can_post_field_modification()) {
2532     // Check to see if a field modification watch has been set before
2533     // we take the time to call into the VM.
2534     Label L1;
2535     assert_different_registers(cache, index, r0);
2536     __ lea(rscratch1, ExternalAddress((address)JvmtiExport::get_field_modification_count_addr()));
2537     __ ldrw(r0, Address(rscratch1));
2538     __ cbz(r0, L1);
2539 
2540     __ get_cache_and_index_at_bcp(c_rarg2, rscratch1, 1);
2541 
2542     if (is_static) {
2543       // Life is simple.  Null out the object pointer.
2544       __ mov(c_rarg1, zr);
2545     } else {
2546       // Life is harder. The stack holds the value on top, followed by
2547       // the object.  We don't know the size of the value, though; it
2548       // could be one or two words depending on its type. As a result,
2549       // we must find the type to determine where the object is.
2550       __ ldrw(c_rarg3, Address(c_rarg2,
2551                                in_bytes(cp_base_offset +
2552                                         ConstantPoolCacheEntry::flags_offset())));
2553       __ lsr(c_rarg3, c_rarg3,
2554              ConstantPoolCacheEntry::tos_state_shift);
2555       ConstantPoolCacheEntry::verify_tos_state_shift();
2556       Label nope2, done, ok;
2557       __ ldr(c_rarg1, at_tos_p1());  // initially assume a one word jvalue
2558       __ cmpw(c_rarg3, ltos);
2559       __ br(Assembler::EQ, ok);
2560       __ cmpw(c_rarg3, dtos);
2561       __ br(Assembler::NE, nope2);
2562       __ bind(ok);
2563       __ ldr(c_rarg1, at_tos_p2()); // ltos (two word jvalue)
2564       __ bind(nope2);
2565     }
2566     // cache entry pointer
2567     __ add(c_rarg2, c_rarg2, in_bytes(cp_base_offset));
2568     // object (tos)
2569     __ mov(c_rarg3, esp);
2570     // c_rarg1: object pointer set up above (NULL if static)
2571     // c_rarg2: cache entry pointer
2572     // c_rarg3: jvalue object on the stack
2573     __ call_VM(noreg,
2574                CAST_FROM_FN_PTR(address,
2575                                 InterpreterRuntime::post_field_modification),
2576                c_rarg1, c_rarg2, c_rarg3);
2577     __ get_cache_and_index_at_bcp(cache, index, 1);
2578     __ bind(L1);
2579   }
2580 }
2581 
2582 void TemplateTable::putfield_or_static(int byte_no, bool is_static, RewriteControl rc) {
2583   transition(vtos, vtos);
2584 
2585   const Register cache = r2;
2586   const Register index = r3;
2587   const Register obj   = r2;
2588   const Register off   = r19;
2589   const Register flags = r0;
2590   const Register bc    = r4;
2591 
2592   resolve_cache_and_index(byte_no, cache, index, sizeof(u2));
2593   jvmti_post_field_mod(cache, index, is_static);
2594   load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
2595 
2596   Label Done;
2597   __ mov(r5, flags);
2598 
2599   {
2600     Label notVolatile;
2601     __ tbz(r5, ConstantPoolCacheEntry::is_volatile_shift, notVolatile);
2602     __ membar(MacroAssembler::StoreStore);
2603     __ bind(notVolatile);
2604   }
2605 
2606   // field address
2607   const Address field(obj, off);
2608 
2609   Label notByte, notInt, notShort, notChar,
2610         notLong, notFloat, notObj, notDouble;
2611 
2612   // x86 uses a shift and mask or wings it with a shift plus assert
2613   // the mask is not needed. aarch64 just uses bitfield extract
2614   __ ubfxw(flags, flags, ConstantPoolCacheEntry::tos_state_shift,  ConstantPoolCacheEntry::tos_state_bits);
2615 
2616   assert(btos == 0, "change code, btos != 0");
2617   __ cbnz(flags, notByte);
2618 
2619   // Don't rewrite putstatic, only putfield
2620   if (is_static) rc = may_not_rewrite;
2621 
2622   // btos
2623   {
2624     __ pop(btos);
2625     if (!is_static) pop_and_check_object(obj);
2626     __ strb(r0, field);
2627     if (rc == may_rewrite) {
2628       patch_bytecode(Bytecodes::_fast_bputfield, bc, r1, true, byte_no);
2629     }
2630     __ b(Done);
2631   }
2632 
2633   __ bind(notByte);
2634   __ cmp(flags, atos);
2635   __ br(Assembler::NE, notObj);
2636 
2637   // atos
2638   {
2639     __ pop(atos);
2640     if (!is_static) pop_and_check_object(obj);
2641     // Store into the field
2642     do_oop_store(_masm, field, r0, _bs->kind(), false);
2643     if (rc == may_rewrite) {
2644       patch_bytecode(Bytecodes::_fast_aputfield, bc, r1, true, byte_no);
2645     }
2646     __ b(Done);
2647   }
2648 
2649   __ bind(notObj);
2650   __ cmp(flags, itos);
2651   __ br(Assembler::NE, notInt);
2652 
2653   // itos
2654   {
2655     __ pop(itos);
2656     if (!is_static) pop_and_check_object(obj);
2657     __ strw(r0, field);
2658     if (rc == may_rewrite) {
2659       patch_bytecode(Bytecodes::_fast_iputfield, bc, r1, true, byte_no);
2660     }
2661     __ b(Done);
2662   }
2663 
2664   __ bind(notInt);
2665   __ cmp(flags, ctos);
2666   __ br(Assembler::NE, notChar);
2667 
2668   // ctos
2669   {
2670     __ pop(ctos);
2671     if (!is_static) pop_and_check_object(obj);
2672     __ strh(r0, field);
2673     if (rc == may_rewrite) {
2674       patch_bytecode(Bytecodes::_fast_cputfield, bc, r1, true, byte_no);
2675     }
2676     __ b(Done);
2677   }
2678 
2679   __ bind(notChar);
2680   __ cmp(flags, stos);
2681   __ br(Assembler::NE, notShort);
2682 
2683   // stos
2684   {
2685     __ pop(stos);
2686     if (!is_static) pop_and_check_object(obj);
2687     __ strh(r0, field);
2688     if (rc == may_rewrite) {
2689       patch_bytecode(Bytecodes::_fast_sputfield, bc, r1, true, byte_no);
2690     }
2691     __ b(Done);
2692   }
2693 
2694   __ bind(notShort);
2695   __ cmp(flags, ltos);
2696   __ br(Assembler::NE, notLong);
2697 
2698   // ltos
2699   {
2700     __ pop(ltos);
2701     if (!is_static) pop_and_check_object(obj);
2702     __ str(r0, field);
2703     if (rc == may_rewrite) {
2704       patch_bytecode(Bytecodes::_fast_lputfield, bc, r1, true, byte_no);
2705     }
2706     __ b(Done);
2707   }
2708 
2709   __ bind(notLong);
2710   __ cmp(flags, ftos);
2711   __ br(Assembler::NE, notFloat);
2712 
2713   // ftos
2714   {
2715     __ pop(ftos);
2716     if (!is_static) pop_and_check_object(obj);
2717     __ strs(v0, field);
2718     if (rc == may_rewrite) {
2719       patch_bytecode(Bytecodes::_fast_fputfield, bc, r1, true, byte_no);
2720     }
2721     __ b(Done);
2722   }
2723 
2724   __ bind(notFloat);
2725 #ifdef ASSERT
2726   __ cmp(flags, dtos);
2727   __ br(Assembler::NE, notDouble);
2728 #endif
2729 
2730   // dtos
2731   {
2732     __ pop(dtos);
2733     if (!is_static) pop_and_check_object(obj);
2734     __ strd(v0, field);
2735     if (rc == may_rewrite) {
2736       patch_bytecode(Bytecodes::_fast_dputfield, bc, r1, true, byte_no);
2737     }
2738   }
2739 
2740 #ifdef ASSERT
2741   __ b(Done);
2742 
2743   __ bind(notDouble);
2744   __ stop("Bad state");
2745 #endif
2746 
2747   __ bind(Done);
2748 
2749   {
2750     Label notVolatile;
2751     __ tbz(r5, ConstantPoolCacheEntry::is_volatile_shift, notVolatile);
2752     __ membar(MacroAssembler::StoreLoad);
2753     __ bind(notVolatile);
2754   }
2755 }
2756 
2757 void TemplateTable::putfield(int byte_no)
2758 {
2759   putfield_or_static(byte_no, false);
2760 }
2761 
2762 void TemplateTable::nofast_putfield(int byte_no) {
2763   putfield_or_static(byte_no, false, may_not_rewrite);
2764 }
2765 
2766 void TemplateTable::putstatic(int byte_no) {
2767   putfield_or_static(byte_no, true);
2768 }
2769 
2770 void TemplateTable::jvmti_post_fast_field_mod()
2771 {
2772   if (JvmtiExport::can_post_field_modification()) {
2773     // Check to see if a field modification watch has been set before
2774     // we take the time to call into the VM.
2775     Label L2;
2776     __ lea(rscratch1, ExternalAddress((address)JvmtiExport::get_field_modification_count_addr()));
2777     __ ldrw(c_rarg3, Address(rscratch1));
2778     __ cbzw(c_rarg3, L2);
2779     __ pop_ptr(r19);                  // copy the object pointer from tos
2780     __ verify_oop(r19);
2781     __ push_ptr(r19);                 // put the object pointer back on tos
2782     // Save tos values before call_VM() clobbers them. Since we have
2783     // to do it for every data type, we use the saved values as the
2784     // jvalue object.
2785     switch (bytecode()) {          // load values into the jvalue object
2786     case Bytecodes::_fast_aputfield: __ push_ptr(r0); break;
2787     case Bytecodes::_fast_bputfield: // fall through
2788     case Bytecodes::_fast_sputfield: // fall through
2789     case Bytecodes::_fast_cputfield: // fall through
2790     case Bytecodes::_fast_iputfield: __ push_i(r0); break;
2791     case Bytecodes::_fast_dputfield: __ push_d(); break;
2792     case Bytecodes::_fast_fputfield: __ push_f(); break;
2793     case Bytecodes::_fast_lputfield: __ push_l(r0); break;
2794 
2795     default:
2796       ShouldNotReachHere();
2797     }
2798     __ mov(c_rarg3, esp);             // points to jvalue on the stack
2799     // access constant pool cache entry
2800     __ get_cache_entry_pointer_at_bcp(c_rarg2, r0, 1);
2801     __ verify_oop(r19);
2802     // r19: object pointer copied above
2803     // c_rarg2: cache entry pointer
2804     // c_rarg3: jvalue object on the stack
2805     __ call_VM(noreg,
2806                CAST_FROM_FN_PTR(address,
2807                                 InterpreterRuntime::post_field_modification),
2808                r19, c_rarg2, c_rarg3);
2809 
2810     switch (bytecode()) {             // restore tos values
2811     case Bytecodes::_fast_aputfield: __ pop_ptr(r0); break;
2812     case Bytecodes::_fast_bputfield: // fall through
2813     case Bytecodes::_fast_sputfield: // fall through
2814     case Bytecodes::_fast_cputfield: // fall through
2815     case Bytecodes::_fast_iputfield: __ pop_i(r0); break;
2816     case Bytecodes::_fast_dputfield: __ pop_d(); break;
2817     case Bytecodes::_fast_fputfield: __ pop_f(); break;
2818     case Bytecodes::_fast_lputfield: __ pop_l(r0); break;
2819     }
2820     __ bind(L2);
2821   }
2822 }
2823 
2824 void TemplateTable::fast_storefield(TosState state)
2825 {
2826   transition(state, vtos);
2827 
2828   ByteSize base = ConstantPoolCache::base_offset();
2829 
2830   jvmti_post_fast_field_mod();
2831 
2832   // access constant pool cache
2833   __ get_cache_and_index_at_bcp(r2, r1, 1);
2834 
2835   // test for volatile with r3
2836   __ ldrw(r3, Address(r2, in_bytes(base +
2837                                    ConstantPoolCacheEntry::flags_offset())));
2838 
2839   // replace index with field offset from cache entry
2840   __ ldr(r1, Address(r2, in_bytes(base + ConstantPoolCacheEntry::f2_offset())));
2841 
2842   {
2843     Label notVolatile;
2844     __ tbz(r3, ConstantPoolCacheEntry::is_volatile_shift, notVolatile);
2845     __ membar(MacroAssembler::StoreStore);
2846     __ bind(notVolatile);
2847   }
2848 
2849   Label notVolatile;
2850 
2851   // Get object from stack
2852   pop_and_check_object(r2);
2853 
2854   // field address
2855   const Address field(r2, r1);
2856 
2857   // access field
2858   switch (bytecode()) {
2859   case Bytecodes::_fast_aputfield:
2860     do_oop_store(_masm, field, r0, _bs->kind(), false);
2861     break;
2862   case Bytecodes::_fast_lputfield:
2863     __ str(r0, field);
2864     break;
2865   case Bytecodes::_fast_iputfield:
2866     __ strw(r0, field);
2867     break;
2868   case Bytecodes::_fast_bputfield:
2869     __ strb(r0, field);
2870     break;
2871   case Bytecodes::_fast_sputfield:
2872     // fall through
2873   case Bytecodes::_fast_cputfield:
2874     __ strh(r0, field);
2875     break;
2876   case Bytecodes::_fast_fputfield:
2877     __ strs(v0, field);
2878     break;
2879   case Bytecodes::_fast_dputfield:
2880     __ strd(v0, field);
2881     break;
2882   default:
2883     ShouldNotReachHere();
2884   }
2885 
2886   {
2887     Label notVolatile;
2888     __ tbz(r3, ConstantPoolCacheEntry::is_volatile_shift, notVolatile);
2889     __ membar(MacroAssembler::StoreLoad);
2890     __ bind(notVolatile);
2891   }
2892 }
2893 
2894 
2895 void TemplateTable::fast_accessfield(TosState state)
2896 {
2897   transition(atos, state);
2898   // Do the JVMTI work here to avoid disturbing the register state below
2899   if (JvmtiExport::can_post_field_access()) {
2900     // Check to see if a field access watch has been set before we
2901     // take the time to call into the VM.
2902     Label L1;
2903     __ lea(rscratch1, ExternalAddress((address) JvmtiExport::get_field_access_count_addr()));
2904     __ ldrw(r2, Address(rscratch1));
2905     __ cbzw(r2, L1);
2906     // access constant pool cache entry
2907     __ get_cache_entry_pointer_at_bcp(c_rarg2, rscratch2, 1);
2908     __ verify_oop(r0);
2909     __ push_ptr(r0);  // save object pointer before call_VM() clobbers it
2910     __ mov(c_rarg1, r0);
2911     // c_rarg1: object pointer copied above
2912     // c_rarg2: cache entry pointer
2913     __ call_VM(noreg,
2914                CAST_FROM_FN_PTR(address,
2915                                 InterpreterRuntime::post_field_access),
2916                c_rarg1, c_rarg2);
2917     __ pop_ptr(r0); // restore object pointer
2918     __ bind(L1);
2919   }
2920 
2921   // access constant pool cache
2922   __ get_cache_and_index_at_bcp(r2, r1, 1);
2923   __ ldr(r1, Address(r2, in_bytes(ConstantPoolCache::base_offset() +
2924                                   ConstantPoolCacheEntry::f2_offset())));
2925   __ ldrw(r3, Address(r2, in_bytes(ConstantPoolCache::base_offset() +
2926                                    ConstantPoolCacheEntry::flags_offset())));
2927 
2928   // r0: object
2929   __ verify_oop(r0);
2930   __ null_check(r0);
2931   const Address field(r0, r1);
2932 
2933   // access field
2934   switch (bytecode()) {
2935   case Bytecodes::_fast_agetfield:
2936     __ load_heap_oop(r0, field);
2937     __ verify_oop(r0);
2938     break;
2939   case Bytecodes::_fast_lgetfield:
2940     __ ldr(r0, field);
2941     break;
2942   case Bytecodes::_fast_igetfield:
2943     __ ldrw(r0, field);
2944     break;
2945   case Bytecodes::_fast_bgetfield:
2946     __ load_signed_byte(r0, field);
2947     break;
2948   case Bytecodes::_fast_sgetfield:
2949     __ load_signed_short(r0, field);
2950     break;
2951   case Bytecodes::_fast_cgetfield:
2952     __ load_unsigned_short(r0, field);
2953     break;
2954   case Bytecodes::_fast_fgetfield:
2955     __ ldrs(v0, field);
2956     break;
2957   case Bytecodes::_fast_dgetfield:
2958     __ ldrd(v0, field);
2959     break;
2960   default:
2961     ShouldNotReachHere();
2962   }
2963   {
2964     Label notVolatile;
2965     __ tbz(r3, ConstantPoolCacheEntry::is_volatile_shift, notVolatile);
2966     __ membar(MacroAssembler::LoadLoad | MacroAssembler::LoadStore);
2967     __ bind(notVolatile);
2968   }
2969 }
2970 
2971 void TemplateTable::fast_xaccess(TosState state)
2972 {
2973   transition(vtos, state);
2974 
2975   // get receiver
2976   __ ldr(r0, aaddress(0));
2977   // access constant pool cache
2978   __ get_cache_and_index_at_bcp(r2, r3, 2);
2979   __ ldr(r1, Address(r2, in_bytes(ConstantPoolCache::base_offset() +
2980                                   ConstantPoolCacheEntry::f2_offset())));
2981   // make sure exception is reported in correct bcp range (getfield is
2982   // next instruction)
2983   __ increment(rbcp);
2984   __ null_check(r0);
2985   switch (state) {
2986   case itos:
2987     __ ldr(r0, Address(r0, r1, Address::lsl(0)));
2988     break;
2989   case atos:
2990     __ load_heap_oop(r0, Address(r0, r1, Address::lsl(0)));
2991     __ verify_oop(r0);
2992     break;
2993   case ftos:
2994     __ ldrs(v0, Address(r0, r1, Address::lsl(0)));
2995     break;
2996   default:
2997     ShouldNotReachHere();
2998   }
2999 
3000   {
3001     Label notVolatile;
3002     __ ldrw(r3, Address(r2, in_bytes(ConstantPoolCache::base_offset() +
3003                                      ConstantPoolCacheEntry::flags_offset())));
3004     __ tbz(r3, ConstantPoolCacheEntry::is_volatile_shift, notVolatile);
3005     __ membar(MacroAssembler::LoadLoad);
3006     __ bind(notVolatile);
3007   }
3008 
3009   __ decrement(rbcp);
3010 }
3011 
3012 
3013 
3014 //-----------------------------------------------------------------------------
3015 // Calls
3016 
3017 void TemplateTable::count_calls(Register method, Register temp)
3018 {
3019   __ call_Unimplemented();
3020 }
3021 
3022 void TemplateTable::prepare_invoke(int byte_no,
3023                                    Register method, // linked method (or i-klass)
3024                                    Register index,  // itable index, MethodType, etc.
3025                                    Register recv,   // if caller wants to see it
3026                                    Register flags   // if caller wants to test it
3027                                    ) {
3028   // determine flags
3029   Bytecodes::Code code = bytecode();
3030   const bool is_invokeinterface  = code == Bytecodes::_invokeinterface;
3031   const bool is_invokedynamic    = code == Bytecodes::_invokedynamic;
3032   const bool is_invokehandle     = code == Bytecodes::_invokehandle;
3033   const bool is_invokevirtual    = code == Bytecodes::_invokevirtual;
3034   const bool is_invokespecial    = code == Bytecodes::_invokespecial;
3035   const bool load_receiver       = (recv  != noreg);
3036   const bool save_flags          = (flags != noreg);
3037   assert(load_receiver == (code != Bytecodes::_invokestatic && code != Bytecodes::_invokedynamic), "");
3038   assert(save_flags    == (is_invokeinterface || is_invokevirtual), "need flags for vfinal");
3039   assert(flags == noreg || flags == r3, "");
3040   assert(recv  == noreg || recv  == r2, "");
3041 
3042   // setup registers & access constant pool cache
3043   if (recv  == noreg)  recv  = r2;
3044   if (flags == noreg)  flags = r3;
3045   assert_different_registers(method, index, recv, flags);
3046 
3047   // save 'interpreter return address'
3048   __ save_bcp();
3049 
3050   load_invoke_cp_cache_entry(byte_no, method, index, flags, is_invokevirtual, false, is_invokedynamic);
3051 
3052   // maybe push appendix to arguments (just before return address)
3053   if (is_invokedynamic || is_invokehandle) {
3054     Label L_no_push;
3055     __ tbz(flags, ConstantPoolCacheEntry::has_appendix_shift, L_no_push);
3056     // Push the appendix as a trailing parameter.
3057     // This must be done before we get the receiver,
3058     // since the parameter_size includes it.
3059     __ push(r19);
3060     __ mov(r19, index);
3061     assert(ConstantPoolCacheEntry::_indy_resolved_references_appendix_offset == 0, "appendix expected at index+0");
3062     __ load_resolved_reference_at_index(index, r19);
3063     __ pop(r19);
3064     __ push(index);  // push appendix (MethodType, CallSite, etc.)
3065     __ bind(L_no_push);
3066   }
3067 
3068   // load receiver if needed (note: no return address pushed yet)
3069   if (load_receiver) {
3070     __ andw(recv, flags, ConstantPoolCacheEntry::parameter_size_mask);
3071     // FIXME -- is this actually correct? looks like it should be 2
3072     // const int no_return_pc_pushed_yet = -1;  // argument slot correction before we push return address
3073     // const int receiver_is_at_end      = -1;  // back off one slot to get receiver
3074     // Address recv_addr = __ argument_address(recv, no_return_pc_pushed_yet + receiver_is_at_end);
3075     // __ movptr(recv, recv_addr);
3076     __ add(rscratch1, esp, recv, ext::uxtx, 3); // FIXME: uxtb here?
3077     __ ldr(recv, Address(rscratch1, -Interpreter::expr_offset_in_bytes(1)));
3078     __ verify_oop(recv);
3079   }
3080 
3081   // compute return type
3082   // x86 uses a shift and mask or wings it with a shift plus assert
3083   // the mask is not needed. aarch64 just uses bitfield extract
3084   __ ubfxw(rscratch2, flags, ConstantPoolCacheEntry::tos_state_shift,  ConstantPoolCacheEntry::tos_state_bits);
3085   // load return address
3086   {
3087     const address table_addr = (address) Interpreter::invoke_return_entry_table_for(code);
3088     __ mov(rscratch1, table_addr);
3089     __ ldr(lr, Address(rscratch1, rscratch2, Address::lsl(3)));
3090   }
3091 }
3092 
3093 
3094 void TemplateTable::invokevirtual_helper(Register index,
3095                                          Register recv,
3096                                          Register flags)
3097 {
3098   // Uses temporary registers r0, r3
3099   assert_different_registers(index, recv, r0, r3);
3100   // Test for an invoke of a final method
3101   Label notFinal;
3102   __ tbz(flags, ConstantPoolCacheEntry::is_vfinal_shift, notFinal);
3103 
3104   const Register method = index;  // method must be rmethod
3105   assert(method == rmethod,
3106          "methodOop must be rmethod for interpreter calling convention");
3107 
3108   // do the call - the index is actually the method to call
3109   // that is, f2 is a vtable index if !is_vfinal, else f2 is a Method*
3110 
3111   // It's final, need a null check here!
3112   __ null_check(recv);
3113 
3114   // profile this call
3115   __ profile_final_call(r0);
3116   __ profile_arguments_type(r0, method, r4, true);
3117 
3118   __ jump_from_interpreted(method, r0);
3119 
3120   __ bind(notFinal);
3121 
3122   // get receiver klass
3123   __ null_check(recv, oopDesc::klass_offset_in_bytes());
3124   __ load_klass(r0, recv);
3125 
3126   // profile this call
3127   __ profile_virtual_call(r0, rlocals, r3);
3128 
3129   // get target methodOop & entry point
3130   __ lookup_virtual_method(r0, index, method);
3131   __ profile_arguments_type(r3, method, r4, true);
3132   // FIXME -- this looks completely redundant. is it?
3133   // __ ldr(r3, Address(method, Method::interpreter_entry_offset()));
3134   __ jump_from_interpreted(method, r3);
3135 }
3136 
3137 void TemplateTable::invokevirtual(int byte_no)
3138 {
3139   transition(vtos, vtos);
3140   assert(byte_no == f2_byte, "use this argument");
3141 
3142   prepare_invoke(byte_no, rmethod, noreg, r2, r3);
3143 
3144   // rmethod: index (actually a Method*)
3145   // r2: receiver
3146   // r3: flags
3147 
3148   invokevirtual_helper(rmethod, r2, r3);
3149 }
3150 
3151 void TemplateTable::invokespecial(int byte_no)
3152 {
3153   transition(vtos, vtos);
3154   assert(byte_no == f1_byte, "use this argument");
3155 
3156   prepare_invoke(byte_no, rmethod, noreg,  // get f1 Method*
3157                  r2);  // get receiver also for null check
3158   __ verify_oop(r2);
3159   __ null_check(r2);
3160   // do the call
3161   __ profile_call(r0);
3162   __ profile_arguments_type(r0, rmethod, rbcp, false);
3163   __ jump_from_interpreted(rmethod, r0);
3164 }
3165 
3166 void TemplateTable::invokestatic(int byte_no)
3167 {
3168   transition(vtos, vtos);
3169   assert(byte_no == f1_byte, "use this argument");
3170 
3171   prepare_invoke(byte_no, rmethod);  // get f1 Method*
3172   // do the call
3173   __ profile_call(r0);
3174   __ profile_arguments_type(r0, rmethod, r4, false);
3175   __ jump_from_interpreted(rmethod, r0);
3176 }
3177 
3178 void TemplateTable::fast_invokevfinal(int byte_no)
3179 {
3180   __ call_Unimplemented();
3181 }
3182 
3183 void TemplateTable::invokeinterface(int byte_no) {
3184   transition(vtos, vtos);
3185   assert(byte_no == f1_byte, "use this argument");
3186 
3187   prepare_invoke(byte_no, r0, rmethod,  // get f1 Klass*, f2 itable index
3188                  r2, r3); // recv, flags
3189 
3190   // r0: interface klass (from f1)
3191   // rmethod: itable index (from f2)
3192   // r2: receiver
3193   // r3: flags
3194 
3195   // Special case of invokeinterface called for virtual method of
3196   // java.lang.Object.  See cpCacheOop.cpp for details.
3197   // This code isn't produced by javac, but could be produced by
3198   // another compliant java compiler.
3199   Label notMethod;
3200   __ tbz(r3, ConstantPoolCacheEntry::is_forced_virtual_shift, notMethod);
3201 
3202   invokevirtual_helper(rmethod, r2, r3);
3203   __ bind(notMethod);
3204 
3205   // Get receiver klass into r3 - also a null check
3206   __ restore_locals();
3207   __ null_check(r2, oopDesc::klass_offset_in_bytes());
3208   __ load_klass(r3, r2);
3209 
3210   // profile this call
3211   __ profile_virtual_call(r3, r13, r19);
3212 
3213   Label no_such_interface, no_such_method;
3214 
3215   __ lookup_interface_method(// inputs: rec. class, interface, itable index
3216                              r3, r0, rmethod,
3217                              // outputs: method, scan temp. reg
3218                              rmethod, r13,
3219                              no_such_interface);
3220 
3221   // rmethod,: methodOop to call
3222   // r2: receiver
3223   // Check for abstract method error
3224   // Note: This should be done more efficiently via a throw_abstract_method_error
3225   //       interpreter entry point and a conditional jump to it in case of a null
3226   //       method.
3227   __ cbz(rmethod, no_such_method);
3228 
3229   __ profile_arguments_type(r3, rmethod, r13, true);
3230 
3231   // do the call
3232   // r2: receiver
3233   // rmethod,: methodOop
3234   __ jump_from_interpreted(rmethod, r3);
3235   __ should_not_reach_here();
3236 
3237   // exception handling code follows...
3238   // note: must restore interpreter registers to canonical
3239   //       state for exception handling to work correctly!
3240 
3241   __ bind(no_such_method);
3242   // throw exception
3243   __ restore_bcp();      // bcp must be correct for exception handler   (was destroyed)
3244   __ restore_locals();   // make sure locals pointer is correct as well (was destroyed)
3245   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError));
3246   // the call_VM checks for exception, so we should never return here.
3247   __ should_not_reach_here();
3248 
3249   __ bind(no_such_interface);
3250   // throw exception
3251   __ restore_bcp();      // bcp must be correct for exception handler   (was destroyed)
3252   __ restore_locals();   // make sure locals pointer is correct as well (was destroyed)
3253   __ call_VM(noreg, CAST_FROM_FN_PTR(address,
3254                    InterpreterRuntime::throw_IncompatibleClassChangeError));
3255   // the call_VM checks for exception, so we should never return here.
3256   __ should_not_reach_here();
3257   return;
3258 }
3259 
3260 void TemplateTable::invokehandle(int byte_no) {
3261   transition(vtos, vtos);
3262   assert(byte_no == f1_byte, "use this argument");
3263 
3264   prepare_invoke(byte_no, rmethod, r0, r2);
3265   __ verify_method_ptr(r2);
3266   __ verify_oop(r2);
3267   __ null_check(r2);
3268 
3269   // FIXME: profile the LambdaForm also
3270 
3271   // r13 is safe to use here as a scratch reg because it is about to
3272   // be clobbered by jump_from_interpreted().
3273   __ profile_final_call(r13);
3274   __ profile_arguments_type(r13, rmethod, r4, true);
3275 
3276   __ jump_from_interpreted(rmethod, r0);
3277 }
3278 
3279 void TemplateTable::invokedynamic(int byte_no) {
3280   transition(vtos, vtos);
3281   assert(byte_no == f1_byte, "use this argument");
3282 
3283   prepare_invoke(byte_no, rmethod, r0);
3284 
3285   // r0: CallSite object (from cpool->resolved_references[])
3286   // rmethod: MH.linkToCallSite method (from f2)
3287 
3288   // Note:  r0_callsite is already pushed by prepare_invoke
3289 
3290   // %%% should make a type profile for any invokedynamic that takes a ref argument
3291   // profile this call
3292   __ profile_call(rbcp);
3293   __ profile_arguments_type(r3, rmethod, r13, false);
3294 
3295   __ verify_oop(r0);
3296 
3297   __ jump_from_interpreted(rmethod, r0);
3298 }
3299 
3300 
3301 //-----------------------------------------------------------------------------
3302 // Allocation
3303 
3304 void TemplateTable::_new() {
3305   transition(vtos, atos);
3306 
3307   __ get_unsigned_2_byte_index_at_bcp(r3, 1);
3308   Label slow_case;
3309   Label done;
3310   Label initialize_header;
3311   Label initialize_object; // including clearing the fields
3312   Label allocate_shared;
3313 
3314   __ get_cpool_and_tags(r4, r0);
3315   // Make sure the class we're about to instantiate has been resolved.
3316   // This is done before loading InstanceKlass to be consistent with the order
3317   // how Constant Pool is updated (see ConstantPool::klass_at_put)
3318   const int tags_offset = Array<u1>::base_offset_in_bytes();
3319   __ lea(rscratch1, Address(r0, r3, Address::lsl(0)));
3320   __ lea(rscratch1, Address(rscratch1, tags_offset));
3321   __ ldarb(rscratch1, rscratch1);
3322   __ cmp(rscratch1, JVM_CONSTANT_Class);
3323   __ br(Assembler::NE, slow_case);
3324 
3325   // get InstanceKlass
3326   __ lea(r4, Address(r4, r3, Address::lsl(3)));
3327   __ ldr(r4, Address(r4, sizeof(ConstantPool)));
3328 
3329   // make sure klass is initialized & doesn't have finalizer
3330   // make sure klass is fully initialized
3331   __ ldrb(rscratch1, Address(r4, InstanceKlass::init_state_offset()));
3332   __ cmp(rscratch1, InstanceKlass::fully_initialized);
3333   __ br(Assembler::NE, slow_case);
3334 
3335   // get instance_size in InstanceKlass (scaled to a count of bytes)
3336   __ ldrw(r3,
3337           Address(r4,
3338                   Klass::layout_helper_offset()));
3339   // test to see if it has a finalizer or is malformed in some way
3340   __ tbnz(r3, exact_log2(Klass::_lh_instance_slow_path_bit), slow_case);
3341 
3342   // Allocate the instance
3343   // 1) Try to allocate in the TLAB
3344   // 2) if fail and the object is large allocate in the shared Eden
3345   // 3) if the above fails (or is not applicable), go to a slow case
3346   // (creates a new TLAB, etc.)
3347 
3348   const bool allow_shared_alloc =
3349     Universe::heap()->supports_inline_contig_alloc();
3350 
3351   if (UseTLAB) {
3352     __ tlab_allocate(r0, r3, 0, noreg, r1,
3353                      allow_shared_alloc ? allocate_shared : slow_case);
3354 
3355     if (ZeroTLAB) {
3356       // the fields have been already cleared
3357       __ b(initialize_header);
3358     } else {
3359       // initialize both the header and fields
3360       __ b(initialize_object);
3361     }
3362   }
3363 
3364   // Allocation in the shared Eden, if allowed.
3365   //
3366   // r3: instance size in bytes
3367   if (allow_shared_alloc) {
3368     __ bind(allocate_shared);
3369 
3370     __ eden_allocate(r0, r3, 0, r10, slow_case);
3371     __ incr_allocated_bytes(rthread, r3, 0, rscratch1);
3372   }
3373 
3374   if (UseTLAB || Universe::heap()->supports_inline_contig_alloc()) {
3375     // The object is initialized before the header.  If the object size is
3376     // zero, go directly to the header initialization.
3377     __ bind(initialize_object);
3378     __ sub(r3, r3, sizeof(oopDesc));
3379     __ cbz(r3, initialize_header);
3380 
3381     // Initialize object fields
3382     {
3383       __ add(r2, r0, sizeof(oopDesc));
3384       Label loop;
3385       __ bind(loop);
3386       __ str(zr, Address(__ post(r2, BytesPerLong)));
3387       __ sub(r3, r3, BytesPerLong);
3388       __ cbnz(r3, loop);
3389     }
3390 
3391     // initialize object header only.
3392     __ bind(initialize_header);
3393     if (UseBiasedLocking) {
3394       __ ldr(rscratch1, Address(r4, Klass::prototype_header_offset()));
3395     } else {
3396       __ mov(rscratch1, (intptr_t)markOopDesc::prototype());
3397     }
3398     __ str(rscratch1, Address(r0, oopDesc::mark_offset_in_bytes()));
3399     __ store_klass_gap(r0, zr);  // zero klass gap for compressed oops
3400     __ store_klass(r0, r4);      // store klass last
3401 
3402     {
3403       SkipIfEqual skip(_masm, &DTraceAllocProbes, false);
3404       // Trigger dtrace event for fastpath
3405       __ push(atos); // save the return value
3406       __ call_VM_leaf(
3407            CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_object_alloc), r0);
3408       __ pop(atos); // restore the return value
3409 
3410     }
3411     __ b(done);
3412   }
3413 
3414   // slow case
3415   __ bind(slow_case);
3416   __ get_constant_pool(c_rarg1);
3417   __ get_unsigned_2_byte_index_at_bcp(c_rarg2, 1);
3418   call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), c_rarg1, c_rarg2);
3419   __ verify_oop(r0);
3420 
3421   // continue
3422   __ bind(done);
3423   // Must prevent reordering of stores for object initialization with stores that publish the new object.
3424   __ membar(Assembler::StoreStore);
3425 }
3426 
3427 void TemplateTable::newarray() {
3428   transition(itos, atos);
3429   __ load_unsigned_byte(c_rarg1, at_bcp(1));
3430   __ mov(c_rarg2, r0);
3431   call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::newarray),
3432           c_rarg1, c_rarg2);
3433   // Must prevent reordering of stores for object initialization with stores that publish the new object.
3434   __ membar(Assembler::StoreStore);
3435 }
3436 
3437 void TemplateTable::anewarray() {
3438   transition(itos, atos);
3439   __ get_unsigned_2_byte_index_at_bcp(c_rarg2, 1);
3440   __ get_constant_pool(c_rarg1);
3441   __ mov(c_rarg3, r0);
3442   call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::anewarray),
3443           c_rarg1, c_rarg2, c_rarg3);
3444   // Must prevent reordering of stores for object initialization with stores that publish the new object.
3445   __ membar(Assembler::StoreStore);
3446 }
3447 
3448 void TemplateTable::arraylength() {
3449   transition(atos, itos);
3450   __ null_check(r0, arrayOopDesc::length_offset_in_bytes());
3451   __ ldrw(r0, Address(r0, arrayOopDesc::length_offset_in_bytes()));
3452 }
3453 
3454 void TemplateTable::checkcast()
3455 {
3456   transition(atos, atos);
3457   Label done, is_null, ok_is_subtype, quicked, resolved;
3458   __ cbz(r0, is_null);
3459 
3460   // Get cpool & tags index
3461   __ get_cpool_and_tags(r2, r3); // r2=cpool, r3=tags array
3462   __ get_unsigned_2_byte_index_at_bcp(r19, 1); // r19=index
3463   // See if bytecode has already been quicked
3464   __ add(rscratch1, r3, Array<u1>::base_offset_in_bytes());
3465   __ lea(r1, Address(rscratch1, r19));
3466   __ ldarb(r1, r1);
3467   __ cmp(r1, JVM_CONSTANT_Class);
3468   __ br(Assembler::EQ, quicked);
3469 
3470   __ push(atos); // save receiver for result, and for GC
3471   call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc));
3472   // vm_result_2 has metadata result
3473   __ get_vm_result_2(r0, rthread);
3474   __ pop(r3); // restore receiver
3475   __ b(resolved);
3476 
3477   // Get superklass in r0 and subklass in r3
3478   __ bind(quicked);
3479   __ mov(r3, r0); // Save object in r3; r0 needed for subtype check
3480   __ lea(r0, Address(r2, r19, Address::lsl(3)));
3481   __ ldr(r0, Address(r0, sizeof(ConstantPool)));
3482 
3483   __ bind(resolved);
3484   __ load_klass(r19, r3);
3485 
3486   // Generate subtype check.  Blows r2, r5.  Object in r3.
3487   // Superklass in r0.  Subklass in r19.
3488   __ gen_subtype_check(r19, ok_is_subtype);
3489 
3490   // Come here on failure
3491   __ push(r3);
3492   // object is at TOS
3493   __ b(Interpreter::_throw_ClassCastException_entry);
3494 
3495   // Come here on success
3496   __ bind(ok_is_subtype);
3497   __ mov(r0, r3); // Restore object in r3
3498 
3499   // Collect counts on whether this test sees NULLs a lot or not.
3500   if (ProfileInterpreter) {
3501     __ b(done);
3502     __ bind(is_null);
3503     __ profile_null_seen(r2);
3504   } else {
3505     __ bind(is_null);   // same as 'done'
3506   }
3507   __ bind(done);
3508 }
3509 
3510 void TemplateTable::instanceof() {
3511   transition(atos, itos);
3512   Label done, is_null, ok_is_subtype, quicked, resolved;
3513   __ cbz(r0, is_null);
3514 
3515   // Get cpool & tags index
3516   __ get_cpool_and_tags(r2, r3); // r2=cpool, r3=tags array
3517   __ get_unsigned_2_byte_index_at_bcp(r19, 1); // r19=index
3518   // See if bytecode has already been quicked
3519   __ add(rscratch1, r3, Array<u1>::base_offset_in_bytes());
3520   __ lea(r1, Address(rscratch1, r19));
3521   __ ldarb(r1, r1);
3522   __ cmp(r1, JVM_CONSTANT_Class);
3523   __ br(Assembler::EQ, quicked);
3524 
3525   __ push(atos); // save receiver for result, and for GC
3526   call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc));
3527   // vm_result_2 has metadata result
3528   __ get_vm_result_2(r0, rthread);
3529   __ pop(r3); // restore receiver
3530   __ verify_oop(r3);
3531   __ load_klass(r3, r3);
3532   __ b(resolved);
3533 
3534   // Get superklass in r0 and subklass in r3
3535   __ bind(quicked);
3536   __ load_klass(r3, r0);
3537   __ lea(r0, Address(r2, r19, Address::lsl(3)));
3538   __ ldr(r0, Address(r0, sizeof(ConstantPool)));
3539 
3540   __ bind(resolved);
3541 
3542   // Generate subtype check.  Blows r2, r5
3543   // Superklass in r0.  Subklass in r3.
3544   __ gen_subtype_check(r3, ok_is_subtype);
3545 
3546   // Come here on failure
3547   __ mov(r0, 0);
3548   __ b(done);
3549   // Come here on success
3550   __ bind(ok_is_subtype);
3551   __ mov(r0, 1);
3552 
3553   // Collect counts on whether this test sees NULLs a lot or not.
3554   if (ProfileInterpreter) {
3555     __ b(done);
3556     __ bind(is_null);
3557     __ profile_null_seen(r2);
3558   } else {
3559     __ bind(is_null);   // same as 'done'
3560   }
3561   __ bind(done);
3562   // r0 = 0: obj == NULL or  obj is not an instanceof the specified klass
3563   // r0 = 1: obj != NULL and obj is     an instanceof the specified klass
3564 }
3565 
3566 //-----------------------------------------------------------------------------
3567 // Breakpoints
3568 void TemplateTable::_breakpoint() {
3569   // Note: We get here even if we are single stepping..
3570   // jbug inists on setting breakpoints at every bytecode
3571   // even if we are in single step mode.
3572 
3573   transition(vtos, vtos);
3574 
3575   // get the unpatched byte code
3576   __ get_method(c_rarg1);
3577   __ call_VM(noreg,
3578              CAST_FROM_FN_PTR(address,
3579                               InterpreterRuntime::get_original_bytecode_at),
3580              c_rarg1, rbcp);
3581   __ mov(r19, r0);
3582 
3583   // post the breakpoint event
3584   __ call_VM(noreg,
3585              CAST_FROM_FN_PTR(address, InterpreterRuntime::_breakpoint),
3586              rmethod, rbcp);
3587 
3588   // complete the execution of original bytecode
3589   __ mov(rscratch1, r19);
3590   __ dispatch_only_normal(vtos);
3591 }
3592 
3593 //-----------------------------------------------------------------------------
3594 // Exceptions
3595 
3596 void TemplateTable::athrow() {
3597   transition(atos, vtos);
3598   __ null_check(r0);
3599   __ b(Interpreter::throw_exception_entry());
3600 }
3601 
3602 //-----------------------------------------------------------------------------
3603 // Synchronization
3604 //
3605 // Note: monitorenter & exit are symmetric routines; which is reflected
3606 //       in the assembly code structure as well
3607 //
3608 // Stack layout:
3609 //
3610 // [expressions  ] <--- esp               = expression stack top
3611 // ..
3612 // [expressions  ]
3613 // [monitor entry] <--- monitor block top = expression stack bot
3614 // ..
3615 // [monitor entry]
3616 // [frame data   ] <--- monitor block bot
3617 // ...
3618 // [saved rbp    ] <--- rbp
3619 void TemplateTable::monitorenter()
3620 {
3621   transition(atos, vtos);
3622 
3623   // check for NULL object
3624   __ null_check(r0);
3625 
3626   const Address monitor_block_top(
3627         rfp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
3628   const Address monitor_block_bot(
3629         rfp, frame::interpreter_frame_initial_sp_offset * wordSize);
3630   const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
3631 
3632   Label allocated;
3633 
3634   // initialize entry pointer
3635   __ mov(c_rarg1, zr); // points to free slot or NULL
3636 
3637   // find a free slot in the monitor block (result in c_rarg1)
3638   {
3639     Label entry, loop, exit;
3640     __ ldr(c_rarg3, monitor_block_top); // points to current entry,
3641                                         // starting with top-most entry
3642     __ lea(c_rarg2, monitor_block_bot); // points to word before bottom
3643 
3644     __ b(entry);
3645 
3646     __ bind(loop);
3647     // check if current entry is used
3648     // if not used then remember entry in c_rarg1
3649     __ ldr(rscratch1, Address(c_rarg3, BasicObjectLock::obj_offset_in_bytes()));
3650     __ cmp(zr, rscratch1);
3651     __ csel(c_rarg1, c_rarg3, c_rarg1, Assembler::EQ);
3652     // check if current entry is for same object
3653     __ cmp(r0, rscratch1);
3654     // if same object then stop searching
3655     __ br(Assembler::EQ, exit);
3656     // otherwise advance to next entry
3657     __ add(c_rarg3, c_rarg3, entry_size);
3658     __ bind(entry);
3659     // check if bottom reached
3660     __ cmp(c_rarg3, c_rarg2);
3661     // if not at bottom then check this entry
3662     __ br(Assembler::NE, loop);
3663     __ bind(exit);
3664   }
3665 
3666   __ cbnz(c_rarg1, allocated); // check if a slot has been found and
3667                             // if found, continue with that on
3668 
3669   // allocate one if there's no free slot
3670   {
3671     Label entry, loop, no_adjust;
3672     // 1. compute new pointers            // rsp: old expression stack top
3673     __ ldr(c_rarg1, monitor_block_bot);   // c_rarg1: old expression stack bottom
3674     __ sub(esp, esp, entry_size);           // move expression stack top
3675     __ sub(c_rarg1, c_rarg1, entry_size); // move expression stack bottom
3676     __ mov(c_rarg3, esp);                 // set start value for copy loop
3677     __ str(c_rarg1, monitor_block_bot);   // set new monitor block bottom
3678 
3679     __ cmp(sp, c_rarg3);                  // Check if we need to move sp
3680     __ br(Assembler::LO, no_adjust);      // to allow more stack space
3681                                           // for our new esp
3682     __ sub(sp, sp, 2 * wordSize);
3683     __ bind(no_adjust);
3684 
3685     __ b(entry);
3686     // 2. move expression stack contents
3687     __ bind(loop);
3688     __ ldr(c_rarg2, Address(c_rarg3, entry_size)); // load expression stack
3689                                                    // word from old location
3690     __ str(c_rarg2, Address(c_rarg3, 0));          // and store it at new location
3691     __ add(c_rarg3, c_rarg3, wordSize);            // advance to next word
3692     __ bind(entry);
3693     __ cmp(c_rarg3, c_rarg1);        // check if bottom reached
3694     __ br(Assembler::NE, loop);      // if not at bottom then
3695                                      // copy next word
3696   }
3697 
3698   // call run-time routine
3699   // c_rarg1: points to monitor entry
3700   __ bind(allocated);
3701 
3702   // Increment bcp to point to the next bytecode, so exception
3703   // handling for async. exceptions work correctly.
3704   // The object has already been poped from the stack, so the
3705   // expression stack looks correct.
3706   __ increment(rbcp);
3707 
3708   // store object
3709   __ str(r0, Address(c_rarg1, BasicObjectLock::obj_offset_in_bytes()));
3710   __ lock_object(c_rarg1);
3711 
3712   // check to make sure this monitor doesn't cause stack overflow after locking
3713   __ save_bcp();  // in case of exception
3714   __ generate_stack_overflow_check(0);
3715 
3716   // The bcp has already been incremented. Just need to dispatch to
3717   // next instruction.
3718   __ dispatch_next(vtos);
3719 }
3720 
3721 
3722 void TemplateTable::monitorexit()
3723 {
3724   transition(atos, vtos);
3725 
3726   // check for NULL object
3727   __ null_check(r0);
3728 
3729   const Address monitor_block_top(
3730         rfp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
3731   const Address monitor_block_bot(
3732         rfp, frame::interpreter_frame_initial_sp_offset * wordSize);
3733   const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
3734 
3735   Label found;
3736 
3737   // find matching slot
3738   {
3739     Label entry, loop;
3740     __ ldr(c_rarg1, monitor_block_top); // points to current entry,
3741                                         // starting with top-most entry
3742     __ lea(c_rarg2, monitor_block_bot); // points to word before bottom
3743                                         // of monitor block
3744     __ b(entry);
3745 
3746     __ bind(loop);
3747     // check if current entry is for same object
3748     __ ldr(rscratch1, Address(c_rarg1, BasicObjectLock::obj_offset_in_bytes()));
3749     __ cmp(r0, rscratch1);
3750     // if same object then stop searching
3751     __ br(Assembler::EQ, found);
3752     // otherwise advance to next entry
3753     __ add(c_rarg1, c_rarg1, entry_size);
3754     __ bind(entry);
3755     // check if bottom reached
3756     __ cmp(c_rarg1, c_rarg2);
3757     // if not at bottom then check this entry
3758     __ br(Assembler::NE, loop);
3759   }
3760 
3761   // error handling. Unlocking was not block-structured
3762   __ call_VM(noreg, CAST_FROM_FN_PTR(address,
3763                    InterpreterRuntime::throw_illegal_monitor_state_exception));
3764   __ should_not_reach_here();
3765 
3766   // call run-time routine
3767   __ bind(found);
3768   __ push_ptr(r0); // make sure object is on stack (contract with oopMaps)
3769   __ unlock_object(c_rarg1);
3770   __ pop_ptr(r0); // discard object
3771 }
3772 
3773 
3774 // Wide instructions
3775 void TemplateTable::wide()
3776 {
3777   __ load_unsigned_byte(r19, at_bcp(1));
3778   __ mov(rscratch1, (address)Interpreter::_wentry_point);
3779   __ ldr(rscratch1, Address(rscratch1, r19, Address::uxtw(3)));
3780   __ br(rscratch1);
3781 }
3782 
3783 
3784 // Multi arrays
3785 void TemplateTable::multianewarray() {
3786   transition(vtos, atos);
3787   __ load_unsigned_byte(r0, at_bcp(3)); // get number of dimensions
3788   // last dim is on top of stack; we want address of first one:
3789   // first_addr = last_addr + (ndims - 1) * wordSize
3790   __ lea(c_rarg1, Address(esp, r0, Address::uxtw(3)));
3791   __ sub(c_rarg1, c_rarg1, wordSize);
3792   call_VM(r0,
3793           CAST_FROM_FN_PTR(address, InterpreterRuntime::multianewarray),
3794           c_rarg1);
3795   __ load_unsigned_byte(r1, at_bcp(3));
3796   __ lea(esp, Address(esp, r1, Address::uxtw(3)));
3797 }
3798 #endif // !CC_INTERP