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