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