1 /*
   2  * Copyright (c) 2003, 2026, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2014, 2020, Red Hat Inc. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 #include "asm/macroAssembler.inline.hpp"
  27 #include "compiler/compiler_globals.hpp"
  28 #include "gc/shared/barrierSet.hpp"
  29 #include "gc/shared/barrierSetAssembler.hpp"
  30 #include "interp_masm_aarch64.hpp"
  31 #include "interpreter/interpreter.hpp"
  32 #include "interpreter/interpreterRuntime.hpp"
  33 #include "logging/log.hpp"
  34 #include "oops/arrayOop.hpp"
  35 #include "oops/constMethodFlags.hpp"
  36 #include "oops/markWord.hpp"
  37 #include "oops/method.hpp"
  38 #include "oops/methodData.hpp"
  39 #include "oops/inlineKlass.hpp"
  40 #include "oops/resolvedFieldEntry.hpp"
  41 #include "oops/resolvedIndyEntry.hpp"
  42 #include "oops/resolvedMethodEntry.hpp"
  43 #include "prims/jvmtiExport.hpp"
  44 #include "prims/jvmtiThreadState.hpp"
  45 #include "runtime/basicLock.hpp"
  46 #include "runtime/frame.inline.hpp"
  47 #include "runtime/javaThread.hpp"
  48 #include "runtime/safepointMechanism.hpp"
  49 #include "runtime/sharedRuntime.hpp"
  50 #include "utilities/powerOfTwo.hpp"
  51 
  52 void InterpreterMacroAssembler::narrow(Register result) {
  53 
  54   // Get method->_constMethod->_result_type
  55   ldr(rscratch1, Address(rfp, frame::interpreter_frame_method_offset * wordSize));
  56   ldr(rscratch1, Address(rscratch1, Method::const_offset()));
  57   ldrb(rscratch1, Address(rscratch1, ConstMethod::result_type_offset()));
  58 
  59   Label done, notBool, notByte, notChar;
  60 
  61   // common case first
  62   cmpw(rscratch1, T_INT);
  63   br(Assembler::EQ, done);
  64 
  65   // mask integer result to narrower return type.
  66   cmpw(rscratch1, T_BOOLEAN);
  67   br(Assembler::NE, notBool);
  68   andw(result, result, 0x1);
  69   b(done);
  70 
  71   bind(notBool);
  72   cmpw(rscratch1, T_BYTE);
  73   br(Assembler::NE, notByte);
  74   sbfx(result, result, 0, 8);
  75   b(done);
  76 
  77   bind(notByte);
  78   cmpw(rscratch1, T_CHAR);
  79   br(Assembler::NE, notChar);
  80   ubfx(result, result, 0, 16);  // truncate upper 16 bits
  81   b(done);
  82 
  83   bind(notChar);
  84   sbfx(result, result, 0, 16);     // sign-extend short
  85 
  86   // Nothing to do for T_INT
  87   bind(done);
  88 }
  89 
  90 void InterpreterMacroAssembler::jump_to_entry(address entry) {
  91   assert(entry, "Entry must have been generated by now");
  92   b(entry);
  93 }
  94 
  95 void InterpreterMacroAssembler::check_and_handle_popframe(Register java_thread) {
  96   if (JvmtiExport::can_pop_frame()) {
  97     Label L;
  98     // Initiate popframe handling only if it is not already being
  99     // processed.  If the flag has the popframe_processing bit set, it
 100     // means that this code is called *during* popframe handling - we
 101     // don't want to reenter.
 102     // This method is only called just after the call into the vm in
 103     // call_VM_base, so the arg registers are available.
 104     ldrw(rscratch1, Address(rthread, JavaThread::popframe_condition_offset()));
 105     tbz(rscratch1, exact_log2(JavaThread::popframe_pending_bit), L);
 106     tbnz(rscratch1, exact_log2(JavaThread::popframe_processing_bit), L);
 107     // Call Interpreter::remove_activation_preserving_args_entry() to get the
 108     // address of the same-named entrypoint in the generated interpreter code.
 109     call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_preserving_args_entry));
 110     br(r0);
 111     bind(L);
 112   }
 113 }
 114 
 115 
 116 void InterpreterMacroAssembler::load_earlyret_value(TosState state) {
 117   ldr(r2, Address(rthread, JavaThread::jvmti_thread_state_offset()));
 118   const Address tos_addr(r2, JvmtiThreadState::earlyret_tos_offset());
 119   const Address oop_addr(r2, JvmtiThreadState::earlyret_oop_offset());
 120   const Address val_addr(r2, JvmtiThreadState::earlyret_value_offset());
 121   switch (state) {
 122     case atos: ldr(r0, oop_addr);
 123                str(zr, oop_addr);
 124                interp_verify_oop(r0, state);        break;
 125     case ltos: ldr(r0, val_addr);                   break;
 126     case btos:                                   // fall through
 127     case ztos:                                   // fall through
 128     case ctos:                                   // fall through
 129     case stos:                                   // fall through
 130     case itos: ldrw(r0, val_addr);                  break;
 131     case ftos: ldrs(v0, val_addr);                  break;
 132     case dtos: ldrd(v0, val_addr);                  break;
 133     case vtos: /* nothing to do */                  break;
 134     default  : ShouldNotReachHere();
 135   }
 136   // Clean up tos value in the thread object
 137   movw(rscratch1, (int) ilgl);
 138   strw(rscratch1, tos_addr);
 139   strw(zr, val_addr);
 140 }
 141 
 142 
 143 void InterpreterMacroAssembler::check_and_handle_earlyret(Register java_thread) {
 144   if (JvmtiExport::can_force_early_return()) {
 145     Label L;
 146     ldr(rscratch1, Address(rthread, JavaThread::jvmti_thread_state_offset()));
 147     cbz(rscratch1, L); // if (thread->jvmti_thread_state() == nullptr) exit;
 148 
 149     // Initiate earlyret handling only if it is not already being processed.
 150     // If the flag has the earlyret_processing bit set, it means that this code
 151     // is called *during* earlyret handling - we don't want to reenter.
 152     ldrw(rscratch1, Address(rscratch1, JvmtiThreadState::earlyret_state_offset()));
 153     cmpw(rscratch1, JvmtiThreadState::earlyret_pending);
 154     br(Assembler::NE, L);
 155 
 156     // Call Interpreter::remove_activation_early_entry() to get the address of the
 157     // same-named entrypoint in the generated interpreter code.
 158     ldr(rscratch1, Address(rthread, JavaThread::jvmti_thread_state_offset()));
 159     ldrw(rscratch1, Address(rscratch1, JvmtiThreadState::earlyret_tos_offset()));
 160     call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry), rscratch1);
 161     br(r0);
 162     bind(L);
 163   }
 164 }
 165 
 166 void InterpreterMacroAssembler::get_unsigned_2_byte_index_at_bcp(
 167   Register reg,
 168   int bcp_offset) {
 169   assert(bcp_offset >= 0, "bcp is still pointing to start of bytecode");
 170   ldrh(reg, Address(rbcp, bcp_offset));
 171   rev16(reg, reg);
 172 }
 173 
 174 void InterpreterMacroAssembler::get_dispatch() {
 175   uint64_t offset;
 176   adrp(rdispatch, ExternalAddress((address)Interpreter::dispatch_table()), offset);
 177   // Use add() here after ARDP, rather than lea().
 178   // lea() does not generate anything if its offset is zero.
 179   // However, relocs expect to find either an ADD or a load/store
 180   // insn after an ADRP.  add() always generates an ADD insn, even
 181   // for add(Rn, Rn, 0).
 182   add(rdispatch, rdispatch, offset);
 183 }
 184 
 185 void InterpreterMacroAssembler::get_cache_index_at_bcp(Register index,
 186                                                        int bcp_offset,
 187                                                        size_t index_size) {
 188   assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");
 189   if (index_size == sizeof(u2)) {
 190     load_unsigned_short(index, Address(rbcp, bcp_offset));
 191   } else if (index_size == sizeof(u4)) {
 192     // assert(EnableInvokeDynamic, "giant index used only for JSR 292");
 193     ldrw(index, Address(rbcp, bcp_offset));
 194   } else if (index_size == sizeof(u1)) {
 195     load_unsigned_byte(index, Address(rbcp, bcp_offset));
 196   } else {
 197     ShouldNotReachHere();
 198   }
 199 }
 200 
 201 void InterpreterMacroAssembler::get_method_counters(Register method,
 202                                                     Register mcs, Label& skip) {
 203   Label has_counters;
 204   ldr(mcs, Address(method, Method::method_counters_offset()));
 205   cbnz(mcs, has_counters);
 206   call_VM(noreg, CAST_FROM_FN_PTR(address,
 207           InterpreterRuntime::build_method_counters), method);
 208   ldr(mcs, Address(method, Method::method_counters_offset()));
 209   cbz(mcs, skip); // No MethodCounters allocated, OutOfMemory
 210   bind(has_counters);
 211 }
 212 
 213 void InterpreterMacroAssembler::read_flat_field(Register entry, Register obj) {
 214   call_VM(obj, CAST_FROM_FN_PTR(address, InterpreterRuntime::read_flat_field), obj, entry);
 215 }
 216 
 217 void InterpreterMacroAssembler::write_flat_field(Register entry, Register field_offset,
 218                                                  Register tmp1, Register tmp2,
 219                                                  Register obj) {
 220   assert_different_registers(entry, field_offset, tmp1, tmp2, obj);
 221   Label slow_path, done;
 222 
 223   load_unsigned_byte(tmp1, Address(entry, in_bytes(ResolvedFieldEntry::flags_offset())));
 224   test_field_is_not_null_free_inline_type(tmp1, noreg /* temp */, slow_path);
 225 
 226   null_check(r0); // FIXME JDK-8341120
 227 
 228   add(obj, obj, field_offset);
 229 
 230   load_klass(tmp1, r0);
 231   payload_address(r0, r0, tmp1);
 232 
 233   Register layout_info = field_offset;
 234   load_unsigned_short(tmp1, Address(entry, in_bytes(ResolvedFieldEntry::field_index_offset())));
 235   ldr(tmp2, Address(entry, in_bytes(ResolvedFieldEntry::field_holder_offset())));
 236   inline_layout_info(tmp2, tmp1, layout_info);
 237 
 238   flat_field_copy(IN_HEAP, r0, obj, layout_info);
 239   b(done);
 240 
 241   bind(slow_path);
 242   call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::write_flat_field), obj, r0, entry);
 243   bind(done);
 244 }
 245 
 246 // Load object from cpool->resolved_references(index)
 247 void InterpreterMacroAssembler::load_resolved_reference_at_index(
 248                                            Register result, Register index, Register tmp) {
 249   assert_different_registers(result, index);
 250 
 251   get_constant_pool(result);
 252   // load pointer for resolved_references[] objArray
 253   ldr(result, Address(result, ConstantPool::cache_offset()));
 254   ldr(result, Address(result, ConstantPoolCache::resolved_references_offset()));
 255   resolve_oop_handle(result, tmp, rscratch2);
 256   // Add in the index
 257   add(index, index, arrayOopDesc::base_offset_in_bytes(T_OBJECT) >> LogBytesPerHeapOop);
 258   load_heap_oop(result, Address(result, index, Address::uxtw(LogBytesPerHeapOop)), tmp, rscratch2);
 259 }
 260 
 261 void InterpreterMacroAssembler::load_resolved_klass_at_offset(
 262                              Register cpool, Register index, Register klass, Register temp) {
 263   add(temp, cpool, index, LSL, LogBytesPerWord);
 264   ldrh(temp, Address(temp, sizeof(ConstantPool))); // temp = resolved_klass_index
 265   ldr(klass, Address(cpool,  ConstantPool::resolved_klasses_offset())); // klass = cpool->_resolved_klasses
 266   add(klass, klass, temp, LSL, LogBytesPerWord);
 267   ldr(klass, Address(klass, Array<Klass*>::base_offset_in_bytes()));
 268 }
 269 
 270 // Generate a subtype check: branch to ok_is_subtype if sub_klass is a
 271 // subtype of super_klass.
 272 //
 273 // Args:
 274 //      r0: superklass
 275 //      Rsub_klass: subklass
 276 //
 277 // Kills:
 278 //      r2
 279 void InterpreterMacroAssembler::gen_subtype_check(Register Rsub_klass,
 280                                                   Label& ok_is_subtype,
 281                                                   bool profile) {
 282   assert(Rsub_klass != r0, "r0 holds superklass");
 283   assert(Rsub_klass != r2, "r2 holds 2ndary super array length");
 284 
 285   // Profile the not-null value's klass.
 286   if (profile) {
 287     profile_typecheck(r2, Rsub_klass); // blows r2
 288   }
 289   // Do the check.
 290   check_klass_subtype(Rsub_klass, r0, r2, ok_is_subtype); // blows r2
 291 }
 292 
 293 // Java Expression Stack
 294 
 295 void InterpreterMacroAssembler::pop_ptr(Register r) {
 296   ldr(r, post(esp, wordSize));
 297 }
 298 
 299 void InterpreterMacroAssembler::pop_i(Register r) {
 300   ldrw(r, post(esp, wordSize));
 301 }
 302 
 303 void InterpreterMacroAssembler::pop_l(Register r) {
 304   ldr(r, post(esp, 2 * Interpreter::stackElementSize));
 305 }
 306 
 307 void InterpreterMacroAssembler::push_ptr(Register r) {
 308   str(r, pre(esp, -wordSize));
 309  }
 310 
 311 void InterpreterMacroAssembler::push_i(Register r) {
 312   str(r, pre(esp, -wordSize));
 313 }
 314 
 315 void InterpreterMacroAssembler::push_l(Register r) {
 316   str(zr, pre(esp, -wordSize));
 317   str(r, pre(esp, - wordSize));
 318 }
 319 
 320 void InterpreterMacroAssembler::pop_f(FloatRegister r) {
 321   ldrs(r, post(esp, wordSize));
 322 }
 323 
 324 void InterpreterMacroAssembler::pop_d(FloatRegister r) {
 325   ldrd(r, post(esp, 2 * Interpreter::stackElementSize));
 326 }
 327 
 328 void InterpreterMacroAssembler::push_f(FloatRegister r) {
 329   strs(r, pre(esp, -wordSize));
 330 }
 331 
 332 void InterpreterMacroAssembler::push_d(FloatRegister r) {
 333   strd(r, pre(esp, 2* -wordSize));
 334 }
 335 
 336 void InterpreterMacroAssembler::pop(TosState state) {
 337   switch (state) {
 338   case atos: pop_ptr();                 break;
 339   case btos:
 340   case ztos:
 341   case ctos:
 342   case stos:
 343   case itos: pop_i();                   break;
 344   case ltos: pop_l();                   break;
 345   case ftos: pop_f();                   break;
 346   case dtos: pop_d();                   break;
 347   case vtos: /* nothing to do */        break;
 348   default:   ShouldNotReachHere();
 349   }
 350   interp_verify_oop(r0, state);
 351 }
 352 
 353 void InterpreterMacroAssembler::push(TosState state) {
 354   interp_verify_oop(r0, state);
 355   switch (state) {
 356   case atos: push_ptr();                break;
 357   case btos:
 358   case ztos:
 359   case ctos:
 360   case stos:
 361   case itos: push_i();                  break;
 362   case ltos: push_l();                  break;
 363   case ftos: push_f();                  break;
 364   case dtos: push_d();                  break;
 365   case vtos: /* nothing to do */        break;
 366   default  : ShouldNotReachHere();
 367   }
 368 }
 369 
 370 // Helpers for swap and dup
 371 void InterpreterMacroAssembler::load_ptr(int n, Register val) {
 372   ldr(val, Address(esp, Interpreter::expr_offset_in_bytes(n)));
 373 }
 374 
 375 void InterpreterMacroAssembler::store_ptr(int n, Register val) {
 376   str(val, Address(esp, Interpreter::expr_offset_in_bytes(n)));
 377 }
 378 
 379 void InterpreterMacroAssembler::load_float(Address src) {
 380   ldrs(v0, src);
 381 }
 382 
 383 void InterpreterMacroAssembler::load_double(Address src) {
 384   ldrd(v0, src);
 385 }
 386 
 387 void InterpreterMacroAssembler::prepare_to_jump_from_interpreted() {
 388   // set sender sp
 389   mov(r19_sender_sp, sp);
 390   // record last_sp
 391   sub(rscratch1, esp, rfp);
 392   asr(rscratch1, rscratch1, Interpreter::logStackElementSize);
 393   str(rscratch1, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize));
 394 }
 395 
 396 // Jump to from_interpreted entry of a call unless single stepping is possible
 397 // in this thread in which case we must call the i2i entry
 398 void InterpreterMacroAssembler::jump_from_interpreted(Register method, Register temp) {
 399   prepare_to_jump_from_interpreted();
 400 
 401   if (JvmtiExport::can_post_interpreter_events()) {
 402     Label run_compiled_code;
 403     // JVMTI events, such as single-stepping, are implemented partly by avoiding running
 404     // compiled code in threads for which the event is enabled.  Check here for
 405     // interp_only_mode if these events CAN be enabled.
 406     ldrw(rscratch1, Address(rthread, JavaThread::interp_only_mode_offset()));
 407     cbzw(rscratch1, run_compiled_code);
 408     ldr(rscratch1, Address(method, Method::interpreter_entry_offset()));
 409     br(rscratch1);
 410     bind(run_compiled_code);
 411   }
 412 
 413   ldr(rscratch1, Address(method, Method::from_interpreted_offset()));
 414   br(rscratch1);
 415 }
 416 
 417 // The following two routines provide a hook so that an implementation
 418 // can schedule the dispatch in two parts.  amd64 does not do this.
 419 void InterpreterMacroAssembler::dispatch_prolog(TosState state, int step) {
 420 }
 421 
 422 void InterpreterMacroAssembler::dispatch_epilog(TosState state, int step) {
 423     dispatch_next(state, step);
 424 }
 425 
 426 void InterpreterMacroAssembler::dispatch_base(TosState state,
 427                                               address* table,
 428                                               bool verifyoop,
 429                                               bool generate_poll) {
 430   if (VerifyActivationFrameSize) {
 431     Label L;
 432     sub(rscratch2, rfp, esp);
 433     int min_frame_size = (frame::link_offset - frame::interpreter_frame_initial_sp_offset) * wordSize;
 434     subs(rscratch2, rscratch2, min_frame_size);
 435     br(Assembler::GE, L);
 436     stop("broken stack frame");
 437     bind(L);
 438   }
 439   if (verifyoop) {
 440     interp_verify_oop(r0, state);
 441   }
 442 
 443   Label safepoint;
 444   address* const safepoint_table = Interpreter::safept_table(state);
 445   bool needs_thread_local_poll = generate_poll && table != safepoint_table;
 446 
 447   if (needs_thread_local_poll) {
 448     NOT_PRODUCT(block_comment("Thread-local Safepoint poll"));
 449     ldr(rscratch2, Address(rthread, JavaThread::polling_word_offset()));
 450     tbnz(rscratch2, exact_log2(SafepointMechanism::poll_bit()), safepoint);
 451   }
 452 
 453   if (table == Interpreter::dispatch_table(state)) {
 454     addw(rscratch2, rscratch1, Interpreter::distance_from_dispatch_table(state));
 455     ldr(rscratch2, Address(rdispatch, rscratch2, Address::uxtw(3)));
 456   } else {
 457     mov(rscratch2, (address)table);
 458     ldr(rscratch2, Address(rscratch2, rscratch1, Address::uxtw(3)));
 459   }
 460   br(rscratch2);
 461 
 462   if (needs_thread_local_poll) {
 463     bind(safepoint);
 464     lea(rscratch2, ExternalAddress((address)safepoint_table));
 465     ldr(rscratch2, Address(rscratch2, rscratch1, Address::uxtw(3)));
 466     br(rscratch2);
 467   }
 468 }
 469 
 470 void InterpreterMacroAssembler::dispatch_only(TosState state, bool generate_poll) {
 471   dispatch_base(state, Interpreter::dispatch_table(state), true, generate_poll);
 472 }
 473 
 474 void InterpreterMacroAssembler::dispatch_only_normal(TosState state) {
 475   dispatch_base(state, Interpreter::normal_table(state));
 476 }
 477 
 478 void InterpreterMacroAssembler::dispatch_only_noverify(TosState state) {
 479   dispatch_base(state, Interpreter::normal_table(state), false);
 480 }
 481 
 482 
 483 void InterpreterMacroAssembler::dispatch_next(TosState state, int step, bool generate_poll) {
 484   // load next bytecode
 485   ldrb(rscratch1, Address(pre(rbcp, step)));
 486   dispatch_base(state, Interpreter::dispatch_table(state), /*verifyoop*/true, generate_poll);
 487 }
 488 
 489 void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) {
 490   // load current bytecode
 491   ldrb(rscratch1, Address(rbcp, 0));
 492   dispatch_base(state, table);
 493 }
 494 
 495 // remove activation
 496 //
 497 // Unlock the receiver if this is a synchronized method.
 498 // Unlock any Java monitors from synchronized blocks.
 499 // Apply stack watermark barrier.
 500 // Notify JVMTI.
 501 // Remove the activation from the stack.
 502 //
 503 // If there are locked Java monitors
 504 //    If throw_monitor_exception
 505 //       throws IllegalMonitorStateException
 506 //    Else if install_monitor_exception
 507 //       installs IllegalMonitorStateException
 508 //    Else
 509 //       no error processing
 510 void InterpreterMacroAssembler::remove_activation(TosState state,
 511                                                   bool throw_monitor_exception,
 512                                                   bool install_monitor_exception,
 513                                                   bool notify_jvmdi) {
 514   // Note: Registers r3 xmm0 may be in use for the
 515   // result check if synchronized method
 516   Label unlocked, unlock, no_unlock;
 517 
 518 #ifdef ASSERT
 519   Label not_preempted;
 520   ldr(rscratch1, Address(rthread, JavaThread::preempt_alternate_return_offset()));
 521   cbz(rscratch1, not_preempted);
 522   stop("remove_activation: should not have alternate return address set");
 523   bind(not_preempted);
 524 #endif /* ASSERT */
 525 
 526   // get the value of _do_not_unlock_if_synchronized into r3
 527   const Address do_not_unlock_if_synchronized(rthread,
 528     in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
 529   ldrb(r3, do_not_unlock_if_synchronized);
 530   strb(zr, do_not_unlock_if_synchronized); // reset the flag
 531 
 532  // get method access flags
 533   ldr(r1, Address(rfp, frame::interpreter_frame_method_offset * wordSize));
 534   ldrh(r2, Address(r1, Method::access_flags_offset()));
 535   tbz(r2, exact_log2(JVM_ACC_SYNCHRONIZED), unlocked);
 536 
 537   // Don't unlock anything if the _do_not_unlock_if_synchronized flag
 538   // is set.
 539   cbnz(r3, no_unlock);
 540 
 541   // unlock monitor
 542   push(state); // save result
 543 
 544   // BasicObjectLock will be first in list, since this is a
 545   // synchronized method. However, need to check that the object has
 546   // not been unlocked by an explicit monitorexit bytecode.
 547   const Address monitor(rfp, frame::interpreter_frame_initial_sp_offset *
 548                         wordSize - (int) sizeof(BasicObjectLock));
 549   // We use c_rarg1 so that if we go slow path it will be the correct
 550   // register for unlock_object to pass to VM directly
 551   lea(c_rarg1, monitor); // address of first monitor
 552 
 553   ldr(r0, Address(c_rarg1, BasicObjectLock::obj_offset()));
 554   cbnz(r0, unlock);
 555 
 556   pop(state);
 557   if (throw_monitor_exception) {
 558     // Entry already unlocked, need to throw exception
 559     call_VM(noreg, CAST_FROM_FN_PTR(address,
 560                    InterpreterRuntime::throw_illegal_monitor_state_exception));
 561     should_not_reach_here();
 562   } else {
 563     // Monitor already unlocked during a stack unroll. If requested,
 564     // install an illegal_monitor_state_exception.  Continue with
 565     // stack unrolling.
 566     if (install_monitor_exception) {
 567       call_VM(noreg, CAST_FROM_FN_PTR(address,
 568                      InterpreterRuntime::new_illegal_monitor_state_exception));
 569     }
 570     b(unlocked);
 571   }
 572 
 573   bind(unlock);
 574   unlock_object(c_rarg1);
 575   pop(state);
 576 
 577   // Check that for block-structured locking (i.e., that all locked
 578   // objects has been unlocked)
 579   bind(unlocked);
 580 
 581   // r0: Might contain return value
 582 
 583   // Check that all monitors are unlocked
 584   {
 585     Label loop, exception, entry, restart;
 586     const int entry_size = frame::interpreter_frame_monitor_size_in_bytes();
 587     const Address monitor_block_top(
 588         rfp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
 589     const Address monitor_block_bot(
 590         rfp, frame::interpreter_frame_initial_sp_offset * wordSize);
 591 
 592     bind(restart);
 593     // We use c_rarg1 so that if we go slow path it will be the correct
 594     // register for unlock_object to pass to VM directly
 595     ldr(c_rarg1, monitor_block_top); // derelativize pointer
 596     lea(c_rarg1, Address(rfp, c_rarg1, Address::lsl(Interpreter::logStackElementSize)));
 597     // c_rarg1 points to current entry, starting with top-most entry
 598 
 599     lea(r19, monitor_block_bot);  // points to word before bottom of
 600                                   // monitor block
 601     b(entry);
 602 
 603     // Entry already locked, need to throw exception
 604     bind(exception);
 605 
 606     if (throw_monitor_exception) {
 607       // Throw exception
 608       MacroAssembler::call_VM(noreg,
 609                               CAST_FROM_FN_PTR(address, InterpreterRuntime::
 610                                    throw_illegal_monitor_state_exception));
 611       should_not_reach_here();
 612     } else {
 613       // Stack unrolling. Unlock object and install illegal_monitor_exception.
 614       // Unlock does not block, so don't have to worry about the frame.
 615       // We don't have to preserve c_rarg1 since we are going to throw an exception.
 616 
 617       push(state);
 618       unlock_object(c_rarg1);
 619       pop(state);
 620 
 621       if (install_monitor_exception) {
 622         call_VM(noreg, CAST_FROM_FN_PTR(address,
 623                                         InterpreterRuntime::
 624                                         new_illegal_monitor_state_exception));
 625       }
 626 
 627       b(restart);
 628     }
 629 
 630     bind(loop);
 631     // check if current entry is used
 632     ldr(rscratch1, Address(c_rarg1, BasicObjectLock::obj_offset()));
 633     cbnz(rscratch1, exception);
 634 
 635     add(c_rarg1, c_rarg1, entry_size); // otherwise advance to next entry
 636     bind(entry);
 637     cmp(c_rarg1, r19); // check if bottom reached
 638     br(Assembler::NE, loop); // if not at bottom then check this entry
 639   }
 640 
 641   bind(no_unlock);
 642 
 643   JFR_ONLY(enter_jfr_critical_section();)
 644 
 645   // The below poll is for the stack watermark barrier. It allows fixing up frames lazily,
 646   // that would normally not be safe to use. Such bad returns into unsafe territory of
 647   // the stack, will call InterpreterRuntime::at_unwind.
 648   Label slow_path;
 649   Label fast_path;
 650   safepoint_poll(slow_path, true /* at_return */, false /* in_nmethod */);
 651   br(Assembler::AL, fast_path);
 652   bind(slow_path);
 653   push(state);
 654   set_last_Java_frame(esp, rfp, pc(), rscratch1);
 655   super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::at_unwind), rthread);
 656   reset_last_Java_frame(true);
 657   pop(state);
 658   bind(fast_path);
 659 
 660   // JVMTI support. Make sure the safepoint poll test is issued prior.
 661   if (notify_jvmdi) {
 662     notify_method_exit(state, NotifyJVMTI);    // preserve TOSCA
 663   } else {
 664     notify_method_exit(state, SkipNotifyJVMTI); // preserve TOSCA
 665   }
 666 
 667   // remove activation
 668   // get sender esp
 669   ldr(rscratch2,
 670       Address(rfp, frame::interpreter_frame_sender_sp_offset * wordSize));
 671   if (StackReservedPages > 0) {
 672     // testing if reserved zone needs to be re-enabled
 673     Label no_reserved_zone_enabling;
 674 
 675     // check if already enabled - if so no re-enabling needed
 676     assert(sizeof(StackOverflow::StackGuardState) == 4, "unexpected size");
 677     ldrw(rscratch1, Address(rthread, JavaThread::stack_guard_state_offset()));
 678     cmpw(rscratch1, (u1)StackOverflow::stack_guard_enabled);
 679     br(Assembler::EQ, no_reserved_zone_enabling);
 680 
 681     // look for an overflow into the stack reserved zone, i.e.
 682     // interpreter_frame_sender_sp <= JavaThread::reserved_stack_activation
 683     ldr(rscratch1, Address(rthread, JavaThread::reserved_stack_activation_offset()));
 684     cmp(rscratch2, rscratch1);
 685     br(Assembler::LS, no_reserved_zone_enabling);
 686 
 687     JFR_ONLY(leave_jfr_critical_section();)
 688 
 689     call_VM_leaf(
 690       CAST_FROM_FN_PTR(address, SharedRuntime::enable_stack_reserved_zone), rthread);
 691     call_VM(noreg, CAST_FROM_FN_PTR(address,
 692                    InterpreterRuntime::throw_delayed_StackOverflowError));
 693     should_not_reach_here();
 694 
 695     bind(no_reserved_zone_enabling);
 696   }
 697 
 698   if (state == atos && InlineTypeReturnedAsFields) {
 699     Label skip;
 700     Label not_null;
 701     cbnz(r0, not_null);
 702     // Returned value is null, zero all return registers because they may belong to oop fields
 703     mov(j_rarg1, zr);
 704     mov(j_rarg2, zr);
 705     mov(j_rarg3, zr);
 706     mov(j_rarg4, zr);
 707     mov(j_rarg5, zr);
 708     mov(j_rarg6, zr);
 709     mov(j_rarg7, zr);
 710     b(skip);
 711     bind(not_null);
 712 
 713     // Check if we are returning a non-null inline type and load its fields into registers
 714     test_oop_is_not_inline_type(r0, rscratch2, skip, /* can_be_null= */ false);
 715 
 716     // Load fields from a buffered value with an inline class specific handler
 717     load_klass(rscratch1 /*dst*/, r0 /*src*/);
 718     ldr(rscratch1, Address(rscratch1, InlineKlass::adr_members_offset()));
 719     ldr(rscratch1, Address(rscratch1, InlineKlass::unpack_handler_offset()));
 720     // Unpack handler can be null if inline type is not scalarizable in returns
 721     cbz(rscratch1, skip);
 722 
 723     blr(rscratch1);
 724     bind(skip);
 725     // Check above kills sender esp in rscratch2. Reload it.
 726     ldr(rscratch2, Address(rfp, frame::interpreter_frame_sender_sp_offset * wordSize));
 727   }
 728 
 729   // remove frame anchor
 730   leave();
 731 
 732   JFR_ONLY(leave_jfr_critical_section();)
 733 
 734   // restore sender esp
 735   mov(esp, rscratch2);
 736 
 737   // If we're returning to interpreted code we will shortly be
 738   // adjusting SP to allow some space for ESP.  If we're returning to
 739   // compiled code the saved sender SP was saved in sender_sp, so this
 740   // restores it.
 741   andr(sp, esp, -16);
 742 }
 743 
 744 #if INCLUDE_JFR
 745 void InterpreterMacroAssembler::enter_jfr_critical_section() {
 746   const Address sampling_critical_section(rthread, in_bytes(SAMPLING_CRITICAL_SECTION_OFFSET_JFR));
 747   mov(rscratch1, true);
 748   strb(rscratch1, sampling_critical_section);
 749 }
 750 
 751 void InterpreterMacroAssembler::leave_jfr_critical_section() {
 752   const Address sampling_critical_section(rthread, in_bytes(SAMPLING_CRITICAL_SECTION_OFFSET_JFR));
 753   strb(zr, sampling_critical_section);
 754 }
 755 #endif // INCLUDE_JFR
 756 
 757 // Lock object
 758 //
 759 // Args:
 760 //      c_rarg1: BasicObjectLock to be used for locking
 761 //
 762 // Kills:
 763 //      r0
 764 //      c_rarg0, c_rarg1, c_rarg2, c_rarg3, c_rarg4, .. (param regs)
 765 //      rscratch1, rscratch2 (scratch regs)
 766 void InterpreterMacroAssembler::lock_object(Register lock_reg)
 767 {
 768   assert(lock_reg == c_rarg1, "The argument is only for looks. It must be c_rarg1");
 769 
 770   const Register tmp = c_rarg2;
 771   const Register obj_reg = c_rarg3; // Will contain the oop
 772   const Register tmp2 = c_rarg4;
 773   const Register tmp3 = c_rarg5;
 774 
 775   // Load object pointer into obj_reg %c_rarg3
 776   ldr(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset()));
 777 
 778   Label slow_case, done;
 779   fast_lock(lock_reg, obj_reg, tmp, tmp2, tmp3, slow_case);
 780   b(done);
 781 
 782   bind(slow_case);
 783 
 784   // Call the runtime routine for slow case
 785   call_VM_preemptable(noreg,
 786           CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
 787           lock_reg);
 788 
 789   bind(done);
 790 }
 791 
 792 
 793 // Unlocks an object. Used in monitorexit bytecode and
 794 // remove_activation.  Throws an IllegalMonitorException if object is
 795 // not locked by current thread.
 796 //
 797 // Args:
 798 //      c_rarg1: BasicObjectLock for lock
 799 //
 800 // Kills:
 801 //      r0
 802 //      c_rarg0, c_rarg1, c_rarg2, c_rarg3, ... (param regs)
 803 //      rscratch1, rscratch2 (scratch regs)
 804 void InterpreterMacroAssembler::unlock_object(Register lock_reg)
 805 {
 806   assert(lock_reg == c_rarg1, "The argument is only for looks. It must be rarg1");
 807 
 808   const Register swap_reg   = r0;
 809   const Register header_reg = c_rarg2;  // Will contain the old oopMark
 810   const Register obj_reg    = c_rarg3;  // Will contain the oop
 811   const Register tmp_reg    = c_rarg4;  // Temporary used by fast_unlock
 812 
 813   save_bcp(); // Save in case of exception
 814 
 815   // Load oop into obj_reg(%c_rarg3)
 816   ldr(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset()));
 817 
 818   // Free entry
 819   str(zr, Address(lock_reg, BasicObjectLock::obj_offset()));
 820 
 821   Label slow_case, done;
 822   fast_unlock(obj_reg, header_reg, swap_reg, tmp_reg, slow_case);
 823   b(done);
 824 
 825   bind(slow_case);
 826   // Call the runtime routine for slow case.
 827   str(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset())); // restore obj
 828   call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg);
 829   bind(done);
 830   restore_bcp();
 831 }
 832 
 833 void InterpreterMacroAssembler::test_method_data_pointer(Register mdp,
 834                                                          Label& zero_continue) {
 835   assert(ProfileInterpreter, "must be profiling interpreter");
 836   ldr(mdp, Address(rfp, frame::interpreter_frame_mdp_offset * wordSize));
 837   cbz(mdp, zero_continue);
 838 }
 839 
 840 // Set the method data pointer for the current bcp.
 841 void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() {
 842   assert(ProfileInterpreter, "must be profiling interpreter");
 843   Label set_mdp;
 844   stp(r0, r1, Address(pre(sp, -2 * wordSize)));
 845 
 846   // Test MDO to avoid the call if it is null.
 847   ldr(r0, Address(rmethod, in_bytes(Method::method_data_offset())));
 848   cbz(r0, set_mdp);
 849   call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), rmethod, rbcp);
 850   // r0: mdi
 851   // mdo is guaranteed to be non-zero here, we checked for it before the call.
 852   ldr(r1, Address(rmethod, in_bytes(Method::method_data_offset())));
 853   lea(r1, Address(r1, in_bytes(MethodData::data_offset())));
 854   add(r0, r1, r0);
 855   str(r0, Address(rfp, frame::interpreter_frame_mdp_offset * wordSize));
 856   bind(set_mdp);
 857   ldp(r0, r1, Address(post(sp, 2 * wordSize)));
 858 }
 859 
 860 void InterpreterMacroAssembler::verify_method_data_pointer() {
 861   assert(ProfileInterpreter, "must be profiling interpreter");
 862 #ifdef ASSERT
 863   Label verify_continue;
 864   stp(r0, r1, Address(pre(sp, -2 * wordSize)));
 865   stp(r2, r3, Address(pre(sp, -2 * wordSize)));
 866   test_method_data_pointer(r3, verify_continue); // If mdp is zero, continue
 867   get_method(r1);
 868 
 869   // If the mdp is valid, it will point to a DataLayout header which is
 870   // consistent with the bcp.  The converse is highly probable also.
 871   ldrsh(r2, Address(r3, in_bytes(DataLayout::bci_offset())));
 872   ldr(rscratch1, Address(r1, Method::const_offset()));
 873   add(r2, r2, rscratch1, Assembler::LSL);
 874   lea(r2, Address(r2, ConstMethod::codes_offset()));
 875   cmp(r2, rbcp);
 876   br(Assembler::EQ, verify_continue);
 877   // r1: method
 878   // rbcp: bcp // rbcp == 22
 879   // r3: mdp
 880   call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp),
 881                r1, rbcp, r3);
 882   bind(verify_continue);
 883   ldp(r2, r3, Address(post(sp, 2 * wordSize)));
 884   ldp(r0, r1, Address(post(sp, 2 * wordSize)));
 885 #endif // ASSERT
 886 }
 887 
 888 
 889 void InterpreterMacroAssembler::set_mdp_data_at(Register mdp_in,
 890                                                 int constant,
 891                                                 Register value) {
 892   assert(ProfileInterpreter, "must be profiling interpreter");
 893   Address data(mdp_in, constant);
 894   str(value, data);
 895 }
 896 
 897 
 898 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
 899                                                       int constant) {
 900   increment_mdp_data_at(mdp_in, noreg, constant);
 901 }
 902 
 903 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
 904                                                       Register index,
 905                                                       int constant) {
 906   assert(ProfileInterpreter, "must be profiling interpreter");
 907 
 908   assert_different_registers(rscratch2, rscratch1, mdp_in, index);
 909 
 910   Address addr1(mdp_in, constant);
 911   Address addr2(rscratch2, index, Address::lsl(0));
 912   Address &addr = addr1;
 913   if (index != noreg) {
 914     lea(rscratch2, addr1);
 915     addr = addr2;
 916   }
 917 
 918   increment(addr, DataLayout::counter_increment);
 919 }
 920 
 921 void InterpreterMacroAssembler::set_mdp_flag_at(Register mdp_in,
 922                                                 int flag_byte_constant) {
 923   assert(ProfileInterpreter, "must be profiling interpreter");
 924   int flags_offset = in_bytes(DataLayout::flags_offset());
 925   // Set the flag
 926   ldrb(rscratch1, Address(mdp_in, flags_offset));
 927   orr(rscratch1, rscratch1, flag_byte_constant);
 928   strb(rscratch1, Address(mdp_in, flags_offset));
 929 }
 930 
 931 
 932 void InterpreterMacroAssembler::test_mdp_data_at(Register mdp_in,
 933                                                  int offset,
 934                                                  Register value,
 935                                                  Register test_value_out,
 936                                                  Label& not_equal_continue) {
 937   assert(ProfileInterpreter, "must be profiling interpreter");
 938   if (test_value_out == noreg) {
 939     ldr(rscratch1, Address(mdp_in, offset));
 940     cmp(value, rscratch1);
 941   } else {
 942     // Put the test value into a register, so caller can use it:
 943     ldr(test_value_out, Address(mdp_in, offset));
 944     cmp(value, test_value_out);
 945   }
 946   br(Assembler::NE, not_equal_continue);
 947 }
 948 
 949 
 950 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,
 951                                                      int offset_of_disp) {
 952   assert(ProfileInterpreter, "must be profiling interpreter");
 953   ldr(rscratch1, Address(mdp_in, offset_of_disp));
 954   add(mdp_in, mdp_in, rscratch1, LSL);
 955   str(mdp_in, Address(rfp, frame::interpreter_frame_mdp_offset * wordSize));
 956 }
 957 
 958 
 959 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,
 960                                                      Register reg,
 961                                                      int offset_of_disp) {
 962   assert(ProfileInterpreter, "must be profiling interpreter");
 963   lea(rscratch1, Address(mdp_in, offset_of_disp));
 964   ldr(rscratch1, Address(rscratch1, reg, Address::lsl(0)));
 965   add(mdp_in, mdp_in, rscratch1, LSL);
 966   str(mdp_in, Address(rfp, frame::interpreter_frame_mdp_offset * wordSize));
 967 }
 968 
 969 
 970 void InterpreterMacroAssembler::update_mdp_by_constant(Register mdp_in,
 971                                                        int constant) {
 972   assert(ProfileInterpreter, "must be profiling interpreter");
 973   add(mdp_in, mdp_in, (unsigned)constant);
 974   str(mdp_in, Address(rfp, frame::interpreter_frame_mdp_offset * wordSize));
 975 }
 976 
 977 
 978 void InterpreterMacroAssembler::update_mdp_for_ret(Register return_bci) {
 979   assert(ProfileInterpreter, "must be profiling interpreter");
 980   // save/restore across call_VM
 981   stp(zr, return_bci, Address(pre(sp, -2 * wordSize)));
 982   call_VM(noreg,
 983           CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret),
 984           return_bci);
 985   ldp(zr, return_bci, Address(post(sp, 2 * wordSize)));
 986 }
 987 
 988 
 989 void InterpreterMacroAssembler::profile_taken_branch(Register mdp) {
 990   if (ProfileInterpreter) {
 991     Label profile_continue;
 992 
 993     // If no method data exists, go to profile_continue.
 994     test_method_data_pointer(mdp, profile_continue);
 995 
 996     // We are taking a branch.  Increment the taken count.
 997     increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset()));
 998 
 999     // The method data pointer needs to be updated to reflect the new target.
1000     update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset()));
1001     bind(profile_continue);
1002   }
1003 }
1004 
1005 
1006 void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp, bool acmp) {
1007   if (ProfileInterpreter) {
1008     Label profile_continue;
1009 
1010     // If no method data exists, go to profile_continue.
1011     test_method_data_pointer(mdp, profile_continue);
1012 
1013     // We are not taking a branch.  Increment the not taken count.
1014     increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset()));
1015 
1016     // The method data pointer needs to be updated to correspond to
1017     // the next bytecode
1018     update_mdp_by_constant(mdp, acmp ? in_bytes(ACmpData::acmp_data_size()) : in_bytes(BranchData::branch_data_size()));
1019     bind(profile_continue);
1020   }
1021 }
1022 
1023 
1024 void InterpreterMacroAssembler::profile_call(Register mdp) {
1025   if (ProfileInterpreter) {
1026     Label profile_continue;
1027 
1028     // If no method data exists, go to profile_continue.
1029     test_method_data_pointer(mdp, profile_continue);
1030 
1031     // We are making a call.  Increment the count.
1032     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1033 
1034     // The method data pointer needs to be updated to reflect the new target.
1035     update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size()));
1036     bind(profile_continue);
1037   }
1038 }
1039 
1040 void InterpreterMacroAssembler::profile_final_call(Register mdp) {
1041   if (ProfileInterpreter) {
1042     Label profile_continue;
1043 
1044     // If no method data exists, go to profile_continue.
1045     test_method_data_pointer(mdp, profile_continue);
1046 
1047     // We are making a call.  Increment the count.
1048     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1049 
1050     // The method data pointer needs to be updated to reflect the new target.
1051     update_mdp_by_constant(mdp,
1052                            in_bytes(VirtualCallData::
1053                                     virtual_call_data_size()));
1054     bind(profile_continue);
1055   }
1056 }
1057 
1058 
1059 void InterpreterMacroAssembler::profile_virtual_call(Register receiver,
1060                                                      Register mdp) {
1061   if (ProfileInterpreter) {
1062     Label profile_continue;
1063 
1064     // If no method data exists, go to profile_continue.
1065     test_method_data_pointer(mdp, profile_continue);
1066 
1067     // Record the receiver type.
1068     profile_receiver_type(receiver, mdp, 0);
1069 
1070     // The method data pointer needs to be updated to reflect the new target.
1071     update_mdp_by_constant(mdp, in_bytes(VirtualCallData::virtual_call_data_size()));
1072     bind(profile_continue);
1073   }
1074 }
1075 
1076 void InterpreterMacroAssembler::profile_ret(Register return_bci,
1077                                             Register mdp) {
1078   if (ProfileInterpreter) {
1079     Label profile_continue;
1080     uint row;
1081 
1082     // If no method data exists, go to profile_continue.
1083     test_method_data_pointer(mdp, profile_continue);
1084 
1085     // Update the total ret count.
1086     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1087 
1088     for (row = 0; row < RetData::row_limit(); row++) {
1089       Label next_test;
1090 
1091       // See if return_bci is equal to bci[n]:
1092       test_mdp_data_at(mdp,
1093                        in_bytes(RetData::bci_offset(row)),
1094                        return_bci, noreg,
1095                        next_test);
1096 
1097       // return_bci is equal to bci[n].  Increment the count.
1098       increment_mdp_data_at(mdp, in_bytes(RetData::bci_count_offset(row)));
1099 
1100       // The method data pointer needs to be updated to reflect the new target.
1101       update_mdp_by_offset(mdp,
1102                            in_bytes(RetData::bci_displacement_offset(row)));
1103       b(profile_continue);
1104       bind(next_test);
1105     }
1106 
1107     update_mdp_for_ret(return_bci);
1108 
1109     bind(profile_continue);
1110   }
1111 }
1112 
1113 void InterpreterMacroAssembler::profile_null_seen(Register mdp) {
1114   if (ProfileInterpreter) {
1115     Label profile_continue;
1116 
1117     // If no method data exists, go to profile_continue.
1118     test_method_data_pointer(mdp, profile_continue);
1119 
1120     set_mdp_flag_at(mdp, BitData::null_seen_byte_constant());
1121 
1122     // The method data pointer needs to be updated.
1123     int mdp_delta = in_bytes(BitData::bit_data_size());
1124     if (TypeProfileCasts) {
1125       mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1126     }
1127     update_mdp_by_constant(mdp, mdp_delta);
1128 
1129     bind(profile_continue);
1130   }
1131 }
1132 
1133 void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass) {
1134   if (ProfileInterpreter) {
1135     Label profile_continue;
1136 
1137     // If no method data exists, go to profile_continue.
1138     test_method_data_pointer(mdp, profile_continue);
1139 
1140     // The method data pointer needs to be updated.
1141     int mdp_delta = in_bytes(BitData::bit_data_size());
1142     if (TypeProfileCasts) {
1143       mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1144 
1145       // Record the object type.
1146       profile_receiver_type(klass, mdp, 0);
1147     }
1148     update_mdp_by_constant(mdp, mdp_delta);
1149 
1150     bind(profile_continue);
1151   }
1152 }
1153 
1154 void InterpreterMacroAssembler::profile_switch_default(Register mdp) {
1155   if (ProfileInterpreter) {
1156     Label profile_continue;
1157 
1158     // If no method data exists, go to profile_continue.
1159     test_method_data_pointer(mdp, profile_continue);
1160 
1161     // Update the default case count
1162     increment_mdp_data_at(mdp,
1163                           in_bytes(MultiBranchData::default_count_offset()));
1164 
1165     // The method data pointer needs to be updated.
1166     update_mdp_by_offset(mdp,
1167                          in_bytes(MultiBranchData::
1168                                   default_displacement_offset()));
1169 
1170     bind(profile_continue);
1171   }
1172 }
1173 
1174 void InterpreterMacroAssembler::profile_switch_case(Register index,
1175                                                     Register mdp,
1176                                                     Register reg2) {
1177   if (ProfileInterpreter) {
1178     Label profile_continue;
1179 
1180     // If no method data exists, go to profile_continue.
1181     test_method_data_pointer(mdp, profile_continue);
1182 
1183     // Build the base (index * per_case_size_in_bytes()) +
1184     // case_array_offset_in_bytes()
1185     movw(reg2, in_bytes(MultiBranchData::per_case_size()));
1186     movw(rscratch1, in_bytes(MultiBranchData::case_array_offset()));
1187     Assembler::maddw(index, index, reg2, rscratch1);
1188 
1189     // Update the case count
1190     increment_mdp_data_at(mdp,
1191                           index,
1192                           in_bytes(MultiBranchData::relative_count_offset()));
1193 
1194     // The method data pointer needs to be updated.
1195     update_mdp_by_offset(mdp,
1196                          index,
1197                          in_bytes(MultiBranchData::
1198                                   relative_displacement_offset()));
1199 
1200     bind(profile_continue);
1201   }
1202 }
1203 
1204 template <class ArrayData> void InterpreterMacroAssembler::profile_array_type(Register mdp,
1205                                                                               Register array,
1206                                                                               Register tmp) {
1207   if (ProfileInterpreter) {
1208     Label profile_continue;
1209 
1210     // If no method data exists, go to profile_continue.
1211     test_method_data_pointer(mdp, profile_continue);
1212 
1213     mov(tmp, array);
1214     profile_obj_type(tmp, Address(mdp, in_bytes(ArrayData::array_offset())));
1215 
1216     Label not_flat;
1217     test_non_flat_array_oop(array, tmp, not_flat);
1218 
1219     set_mdp_flag_at(mdp, ArrayData::flat_array_byte_constant());
1220 
1221     bind(not_flat);
1222 
1223     Label not_null_free;
1224     test_non_null_free_array_oop(array, tmp, not_null_free);
1225 
1226     set_mdp_flag_at(mdp, ArrayData::null_free_array_byte_constant());
1227 
1228     bind(not_null_free);
1229 
1230     bind(profile_continue);
1231   }
1232 }
1233 
1234 template void InterpreterMacroAssembler::profile_array_type<ArrayLoadData>(Register mdp,
1235                                                                            Register array,
1236                                                                            Register tmp);
1237 template void InterpreterMacroAssembler::profile_array_type<ArrayStoreData>(Register mdp,
1238                                                                             Register array,
1239                                                                             Register tmp);
1240 
1241 void InterpreterMacroAssembler::profile_multiple_element_types(Register mdp, Register element, Register tmp, const Register tmp2) {
1242   if (ProfileInterpreter) {
1243     Label profile_continue;
1244 
1245     // If no method data exists, go to profile_continue.
1246     test_method_data_pointer(mdp, profile_continue);
1247 
1248     Label done, update;
1249     cbnz(element, update);
1250     set_mdp_flag_at(mdp, BitData::null_seen_byte_constant());
1251     b(done);
1252 
1253     bind(update);
1254     load_klass(tmp, element);
1255 
1256     // Record the object type.
1257     profile_receiver_type(tmp, mdp, 0);
1258 
1259     bind(done);
1260 
1261     // The method data pointer needs to be updated.
1262     update_mdp_by_constant(mdp, in_bytes(ArrayStoreData::array_store_data_size()));
1263 
1264     bind(profile_continue);
1265   }
1266 }
1267 
1268 
1269 void InterpreterMacroAssembler::profile_element_type(Register mdp,
1270                                                      Register element,
1271                                                      Register tmp) {
1272   if (ProfileInterpreter) {
1273     Label profile_continue;
1274 
1275     // If no method data exists, go to profile_continue.
1276     test_method_data_pointer(mdp, profile_continue);
1277 
1278     mov(tmp, element);
1279     profile_obj_type(tmp, Address(mdp, in_bytes(ArrayLoadData::element_offset())));
1280 
1281     // The method data pointer needs to be updated.
1282     update_mdp_by_constant(mdp, in_bytes(ArrayLoadData::array_load_data_size()));
1283 
1284     bind(profile_continue);
1285   }
1286 }
1287 
1288 void InterpreterMacroAssembler::profile_acmp(Register mdp,
1289                                              Register left,
1290                                              Register right,
1291                                              Register tmp) {
1292   if (ProfileInterpreter) {
1293     Label profile_continue;
1294 
1295     // If no method data exists, go to profile_continue.
1296     test_method_data_pointer(mdp, profile_continue);
1297 
1298     mov(tmp, left);
1299     profile_obj_type(tmp, Address(mdp, in_bytes(ACmpData::left_offset())));
1300 
1301     Label left_not_inline_type;
1302     test_oop_is_not_inline_type(left, tmp, left_not_inline_type);
1303     set_mdp_flag_at(mdp, ACmpData::left_inline_type_byte_constant());
1304     bind(left_not_inline_type);
1305 
1306     mov(tmp, right);
1307     profile_obj_type(tmp, Address(mdp, in_bytes(ACmpData::right_offset())));
1308 
1309     Label right_not_inline_type;
1310     test_oop_is_not_inline_type(right, tmp, right_not_inline_type);
1311     set_mdp_flag_at(mdp, ACmpData::right_inline_type_byte_constant());
1312     bind(right_not_inline_type);
1313 
1314     bind(profile_continue);
1315   }
1316 }
1317 
1318 void InterpreterMacroAssembler::_interp_verify_oop(Register reg, TosState state, const char* file, int line) {
1319   if (state == atos) {
1320     MacroAssembler::_verify_oop_checked(reg, "broken oop", file, line);
1321   }
1322 }
1323 
1324 void InterpreterMacroAssembler::notify_method_entry() {
1325   // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
1326   // track stack depth.  If it is possible to enter interp_only_mode we add
1327   // the code to check if the event should be sent.
1328   if (JvmtiExport::can_post_interpreter_events()) {
1329     Label L;
1330     ldrw(r3, Address(rthread, JavaThread::interp_only_mode_offset()));
1331     cbzw(r3, L);
1332     call_VM(noreg, CAST_FROM_FN_PTR(address,
1333                                     InterpreterRuntime::post_method_entry));
1334     bind(L);
1335   }
1336 
1337   if (DTraceMethodProbes) {
1338     get_method(c_rarg1);
1339     call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry),
1340                  rthread, c_rarg1);
1341   }
1342 
1343   // RedefineClasses() tracing support for obsolete method entry
1344   if (log_is_enabled(Trace, redefine, class, obsolete)) {
1345     get_method(c_rarg1);
1346     call_VM_leaf(
1347       CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry),
1348       rthread, c_rarg1);
1349   }
1350 
1351  }
1352 
1353 
1354 void InterpreterMacroAssembler::notify_method_exit(
1355     TosState state, NotifyMethodExitMode mode) {
1356   // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
1357   // track stack depth.  If it is possible to enter interp_only_mode we add
1358   // the code to check if the event should be sent.
1359   if (mode == NotifyJVMTI && (JvmtiExport::can_post_interpreter_events() || JvmtiExport::can_post_frame_pop())) {
1360     Label L;
1361     // Note: frame::interpreter_frame_result has a dependency on how the
1362     // method result is saved across the call to post_method_exit. If this
1363     // is changed then the interpreter_frame_result implementation will
1364     // need to be updated too.
1365 
1366     // template interpreter will leave the result on the top of the stack.
1367     push(state);
1368 
1369     ldr(rscratch1, Address(rthread, JavaThread::jvmti_thread_state_offset()));
1370     cbz(rscratch1, L); // if (thread->jvmti_thread_state() == nullptr) exit;
1371 
1372     ldrw(rscratch1, Address(rscratch1, JvmtiThreadState::frame_pop_cnt_offset()));
1373     ldrw(rscratch2, Address(rthread, JavaThread::interp_only_mode_offset()));
1374     orrw(rscratch1, rscratch1, rscratch2);
1375     cbzw(rscratch1, L);
1376 
1377     call_VM(noreg,
1378             CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit));
1379     bind(L);
1380     pop(state);
1381   }
1382 
1383   if (DTraceMethodProbes) {
1384     push(state);
1385     get_method(c_rarg1);
1386     call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),
1387                  rthread, c_rarg1);
1388     pop(state);
1389   }
1390 }
1391 
1392 
1393 // Jump if ((*counter_addr += increment) & mask) satisfies the condition.
1394 void InterpreterMacroAssembler::increment_mask_and_jump(Address counter_addr,
1395                                                         int increment, Address mask,
1396                                                         Register scratch, Register scratch2,
1397                                                         bool preloaded, Condition cond,
1398                                                         Label* where) {
1399   if (!preloaded) {
1400     ldrw(scratch, counter_addr);
1401   }
1402   add(scratch, scratch, increment);
1403   strw(scratch, counter_addr);
1404   ldrw(scratch2, mask);
1405   ands(scratch, scratch, scratch2);
1406   br(cond, *where);
1407 }
1408 
1409 void InterpreterMacroAssembler::call_VM_leaf_base(address entry_point,
1410                                                   int number_of_arguments) {
1411   // interpreter specific
1412   //
1413   // Note: No need to save/restore rbcp & rlocals pointer since these
1414   //       are callee saved registers and no blocking/ GC can happen
1415   //       in leaf calls.
1416 #ifdef ASSERT
1417   {
1418     Label L;
1419     ldr(rscratch1, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize));
1420     cbz(rscratch1, L);
1421     stop("InterpreterMacroAssembler::call_VM_leaf_base:"
1422          " last_sp != nullptr");
1423     bind(L);
1424   }
1425 #endif /* ASSERT */
1426   // super call
1427   MacroAssembler::call_VM_leaf_base(entry_point, number_of_arguments);
1428 }
1429 
1430 void InterpreterMacroAssembler::call_VM_base(Register oop_result,
1431                                              Register java_thread,
1432                                              Register last_java_sp,
1433                                              Label*   return_pc,
1434                                              address  entry_point,
1435                                              int      number_of_arguments,
1436                                              bool     check_exceptions) {
1437   // interpreter specific
1438   //
1439   // Note: Could avoid restoring locals ptr (callee saved) - however doesn't
1440   //       really make a difference for these runtime calls, since they are
1441   //       slow anyway. Btw., bcp must be saved/restored since it may change
1442   //       due to GC.
1443   // assert(java_thread == noreg , "not expecting a precomputed java thread");
1444   save_bcp();
1445 #ifdef ASSERT
1446   {
1447     Label L;
1448     ldr(rscratch1, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize));
1449     cbz(rscratch1, L);
1450     stop("InterpreterMacroAssembler::call_VM_base:"
1451          " last_sp != nullptr");
1452     bind(L);
1453   }
1454 #endif /* ASSERT */
1455   // super call
1456   MacroAssembler::call_VM_base(oop_result, noreg, last_java_sp,
1457                                return_pc, entry_point,
1458                                number_of_arguments, check_exceptions);
1459 // interpreter specific
1460   restore_bcp();
1461   restore_locals();
1462 }
1463 
1464 void InterpreterMacroAssembler::call_VM_preemptable_helper(Register oop_result,
1465                                                            address entry_point,
1466                                                            int number_of_arguments,
1467                                                            bool check_exceptions) {
1468   assert(InterpreterRuntime::is_preemptable_call(entry_point), "VM call not preemptable, should use call_VM()");
1469   Label resume_pc, not_preempted;
1470 
1471 #ifdef ASSERT
1472   {
1473     Label L1, L2;
1474     ldr(rscratch1, Address(rthread, JavaThread::preempt_alternate_return_offset()));
1475     cbz(rscratch1, L1);
1476     stop("call_VM_preemptable_helper: Should not have alternate return address set");
1477     bind(L1);
1478     // We check this counter in patch_return_pc_with_preempt_stub() during freeze.
1479     incrementw(Address(rthread, JavaThread::interp_at_preemptable_vmcall_cnt_offset()));
1480     ldrw(rscratch1, Address(rthread, JavaThread::interp_at_preemptable_vmcall_cnt_offset()));
1481     cmpw(rscratch1, 0);
1482     br(Assembler::GT, L2);
1483     stop("call_VM_preemptable_helper: should be > 0");
1484     bind(L2);
1485   }
1486 #endif /* ASSERT */
1487 
1488   // Force freeze slow path.
1489   push_cont_fastpath();
1490 
1491   // Make VM call. In case of preemption set last_pc to the one we want to resume to.
1492   // Note: call_VM_base will use resume_pc label to set last_Java_pc.
1493   call_VM_base(noreg, noreg, noreg, &resume_pc, entry_point, number_of_arguments, false /*check_exceptions*/);
1494 
1495   pop_cont_fastpath();
1496 
1497 #ifdef ASSERT
1498   {
1499     Label L;
1500     decrementw(Address(rthread, JavaThread::interp_at_preemptable_vmcall_cnt_offset()));
1501     ldrw(rscratch1, Address(rthread, JavaThread::interp_at_preemptable_vmcall_cnt_offset()));
1502     cmpw(rscratch1, 0);
1503     br(Assembler::GE, L);
1504     stop("call_VM_preemptable_helper: should be >= 0");
1505     bind(L);
1506   }
1507 #endif /* ASSERT */
1508 
1509   // Check if preempted.
1510   ldr(rscratch1, Address(rthread, JavaThread::preempt_alternate_return_offset()));
1511   cbz(rscratch1, not_preempted);
1512   str(zr, Address(rthread, JavaThread::preempt_alternate_return_offset()));
1513   br(rscratch1);
1514 
1515   // In case of preemption, this is where we will resume once we finally acquire the monitor.
1516   bind(resume_pc);
1517   restore_after_resume(false /* is_native */);
1518 
1519   bind(not_preempted);
1520   if (check_exceptions) {
1521     // check for pending exceptions
1522     ldr(rscratch1, Address(rthread, in_bytes(Thread::pending_exception_offset())));
1523     Label ok;
1524     cbz(rscratch1, ok);
1525     lea(rscratch1, RuntimeAddress(StubRoutines::forward_exception_entry()));
1526     br(rscratch1);
1527     bind(ok);
1528   }
1529 
1530   // get oop result if there is one and reset the value in the thread
1531   if (oop_result->is_valid()) {
1532     get_vm_result_oop(oop_result, rthread);
1533   }
1534 }
1535 
1536 static void pass_arg1(MacroAssembler* masm, Register arg) {
1537   if (c_rarg1 != arg ) {
1538     masm->mov(c_rarg1, arg);
1539   }
1540 }
1541 
1542 static void pass_arg2(MacroAssembler* masm, Register arg) {
1543   if (c_rarg2 != arg ) {
1544     masm->mov(c_rarg2, arg);
1545   }
1546 }
1547 
1548 void InterpreterMacroAssembler::call_VM_preemptable(Register oop_result,
1549                                          address entry_point,
1550                                          Register arg_1,
1551                                          bool check_exceptions) {
1552   pass_arg1(this, arg_1);
1553   call_VM_preemptable_helper(oop_result, entry_point, 1, check_exceptions);
1554 }
1555 
1556 void InterpreterMacroAssembler::call_VM_preemptable(Register oop_result,
1557                                          address entry_point,
1558                                          Register arg_1,
1559                                          Register arg_2,
1560                                          bool check_exceptions) {
1561   LP64_ONLY(assert_different_registers(arg_1, c_rarg2));
1562   pass_arg2(this, arg_2);
1563   pass_arg1(this, arg_1);
1564   call_VM_preemptable_helper(oop_result, entry_point, 2, check_exceptions);
1565 }
1566 
1567 void InterpreterMacroAssembler::restore_after_resume(bool is_native) {
1568   lea(rscratch1, ExternalAddress(Interpreter::cont_resume_interpreter_adapter()));
1569   blr(rscratch1);
1570   if (is_native) {
1571     // On resume we need to set up stack as expected
1572     push(dtos);
1573     push(ltos);
1574   }
1575 }
1576 
1577 void InterpreterMacroAssembler::profile_obj_type(Register obj, const Address& mdo_addr) {
1578   assert_different_registers(obj, rscratch1, mdo_addr.base(), mdo_addr.index());
1579   Label update, next, none;
1580 
1581   verify_oop(obj);
1582 
1583   cbnz(obj, update);
1584   orptr(mdo_addr, TypeEntries::null_seen);
1585   b(next);
1586 
1587   bind(update);
1588   load_klass(obj, obj);
1589 
1590   ldr(rscratch1, mdo_addr);
1591   eor(obj, obj, rscratch1);
1592   tst(obj, TypeEntries::type_klass_mask);
1593   br(Assembler::EQ, next); // klass seen before, nothing to
1594                            // do. The unknown bit may have been
1595                            // set already but no need to check.
1596 
1597   tbnz(obj, exact_log2(TypeEntries::type_unknown), next);
1598   // already unknown. Nothing to do anymore.
1599 
1600   cbz(rscratch1, none);
1601   cmp(rscratch1, (u1)TypeEntries::null_seen);
1602   br(Assembler::EQ, none);
1603   // There is a chance that the checks above
1604   // fail if another thread has just set the
1605   // profiling to this obj's klass
1606   eor(obj, obj, rscratch1); // get back original value before XOR
1607   ldr(rscratch1, mdo_addr);
1608   eor(obj, obj, rscratch1);
1609   tst(obj, TypeEntries::type_klass_mask);
1610   br(Assembler::EQ, next);
1611 
1612   // different than before. Cannot keep accurate profile.
1613   orptr(mdo_addr, TypeEntries::type_unknown);
1614   b(next);
1615 
1616   bind(none);
1617   // first time here. Set profile type.
1618   str(obj, mdo_addr);
1619 #ifdef ASSERT
1620   andr(obj, obj, TypeEntries::type_mask);
1621   verify_klass_ptr(obj);
1622 #endif
1623 
1624   bind(next);
1625 }
1626 
1627 void InterpreterMacroAssembler::profile_arguments_type(Register mdp, Register callee, Register tmp, bool is_virtual) {
1628   if (!ProfileInterpreter) {
1629     return;
1630   }
1631 
1632   if (MethodData::profile_arguments() || MethodData::profile_return()) {
1633     Label profile_continue;
1634 
1635     test_method_data_pointer(mdp, profile_continue);
1636 
1637     int off_to_start = is_virtual ? in_bytes(VirtualCallData::virtual_call_data_size()) : in_bytes(CounterData::counter_data_size());
1638 
1639     ldrb(rscratch1, Address(mdp, in_bytes(DataLayout::tag_offset()) - off_to_start));
1640     cmp(rscratch1, u1(is_virtual ? DataLayout::virtual_call_type_data_tag : DataLayout::call_type_data_tag));
1641     br(Assembler::NE, profile_continue);
1642 
1643     if (MethodData::profile_arguments()) {
1644       Label done;
1645       int off_to_args = in_bytes(TypeEntriesAtCall::args_data_offset());
1646 
1647       for (int i = 0; i < TypeProfileArgsLimit; i++) {
1648         if (i > 0 || MethodData::profile_return()) {
1649           // If return value type is profiled we may have no argument to profile
1650           ldr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())));
1651           sub(tmp, tmp, i*TypeStackSlotEntries::per_arg_count());
1652           cmp(tmp, (u1)TypeStackSlotEntries::per_arg_count());
1653           add(rscratch1, mdp, off_to_args);
1654           br(Assembler::LT, done);
1655         }
1656         ldr(tmp, Address(callee, Method::const_offset()));
1657         load_unsigned_short(tmp, Address(tmp, ConstMethod::size_of_parameters_offset()));
1658         // stack offset o (zero based) from the start of the argument
1659         // list, for n arguments translates into offset n - o - 1 from
1660         // the end of the argument list
1661         ldr(rscratch1, Address(mdp, in_bytes(TypeEntriesAtCall::stack_slot_offset(i))));
1662         sub(tmp, tmp, rscratch1);
1663         sub(tmp, tmp, 1);
1664         Address arg_addr = argument_address(tmp);
1665         ldr(tmp, arg_addr);
1666 
1667         Address mdo_arg_addr(mdp, in_bytes(TypeEntriesAtCall::argument_type_offset(i)));
1668         profile_obj_type(tmp, mdo_arg_addr);
1669 
1670         int to_add = in_bytes(TypeStackSlotEntries::per_arg_size());
1671         off_to_args += to_add;
1672       }
1673 
1674       if (MethodData::profile_return()) {
1675         ldr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())));
1676         sub(tmp, tmp, TypeProfileArgsLimit*TypeStackSlotEntries::per_arg_count());
1677       }
1678 
1679       add(rscratch1, mdp, off_to_args);
1680       bind(done);
1681       mov(mdp, rscratch1);
1682 
1683       if (MethodData::profile_return()) {
1684         // We're right after the type profile for the last
1685         // argument. tmp is the number of cells left in the
1686         // CallTypeData/VirtualCallTypeData to reach its end. Non null
1687         // if there's a return to profile.
1688         assert(SingleTypeEntry::static_cell_count() < TypeStackSlotEntries::per_arg_count(), "can't move past ret type");
1689         add(mdp, mdp, tmp, LSL, exact_log2(DataLayout::cell_size));
1690       }
1691       str(mdp, Address(rfp, frame::interpreter_frame_mdp_offset * wordSize));
1692     } else {
1693       assert(MethodData::profile_return(), "either profile call args or call ret");
1694       update_mdp_by_constant(mdp, in_bytes(TypeEntriesAtCall::return_only_size()));
1695     }
1696 
1697     // mdp points right after the end of the
1698     // CallTypeData/VirtualCallTypeData, right after the cells for the
1699     // return value type if there's one
1700 
1701     bind(profile_continue);
1702   }
1703 }
1704 
1705 void InterpreterMacroAssembler::profile_return_type(Register mdp, Register ret, Register tmp) {
1706   assert_different_registers(mdp, ret, tmp, rbcp);
1707   if (ProfileInterpreter && MethodData::profile_return()) {
1708     Label profile_continue, done;
1709 
1710     test_method_data_pointer(mdp, profile_continue);
1711 
1712     if (MethodData::profile_return_jsr292_only()) {
1713       assert(Method::intrinsic_id_size_in_bytes() == 2, "assuming Method::_intrinsic_id is u2");
1714 
1715       // If we don't profile all invoke bytecodes we must make sure
1716       // it's a bytecode we indeed profile. We can't go back to the
1717       // beginning of the ProfileData we intend to update to check its
1718       // type because we're right after it and we don't known its
1719       // length
1720       Label do_profile;
1721       ldrb(rscratch1, Address(rbcp, 0));
1722       cmp(rscratch1, (u1)Bytecodes::_invokedynamic);
1723       br(Assembler::EQ, do_profile);
1724       cmp(rscratch1, (u1)Bytecodes::_invokehandle);
1725       br(Assembler::EQ, do_profile);
1726       get_method(tmp);
1727       ldrh(rscratch1, Address(tmp, Method::intrinsic_id_offset()));
1728       subs(zr, rscratch1, static_cast<int>(vmIntrinsics::_compiledLambdaForm));
1729       br(Assembler::NE, profile_continue);
1730 
1731       bind(do_profile);
1732     }
1733 
1734     Address mdo_ret_addr(mdp, -in_bytes(SingleTypeEntry::size()));
1735     mov(tmp, ret);
1736     profile_obj_type(tmp, mdo_ret_addr);
1737 
1738     bind(profile_continue);
1739   }
1740 }
1741 
1742 void InterpreterMacroAssembler::profile_parameters_type(Register mdp, Register tmp1, Register tmp2) {
1743   assert_different_registers(rscratch1, rscratch2, mdp, tmp1, tmp2);
1744   if (ProfileInterpreter && MethodData::profile_parameters()) {
1745     Label profile_continue, done;
1746 
1747     test_method_data_pointer(mdp, profile_continue);
1748 
1749     // Load the offset of the area within the MDO used for
1750     // parameters. If it's negative we're not profiling any parameters
1751     ldrw(tmp1, Address(mdp, in_bytes(MethodData::parameters_type_data_di_offset()) - in_bytes(MethodData::data_offset())));
1752     tbnz(tmp1, 31, profile_continue);  // i.e. sign bit set
1753 
1754     // Compute a pointer to the area for parameters from the offset
1755     // and move the pointer to the slot for the last
1756     // parameters. Collect profiling from last parameter down.
1757     // mdo start + parameters offset + array length - 1
1758     add(mdp, mdp, tmp1);
1759     ldr(tmp1, Address(mdp, ArrayData::array_len_offset()));
1760     sub(tmp1, tmp1, TypeStackSlotEntries::per_arg_count());
1761 
1762     Label loop;
1763     bind(loop);
1764 
1765     int off_base = in_bytes(ParametersTypeData::stack_slot_offset(0));
1766     int type_base = in_bytes(ParametersTypeData::type_offset(0));
1767     int per_arg_scale = exact_log2(DataLayout::cell_size);
1768     add(rscratch1, mdp, off_base);
1769     add(rscratch2, mdp, type_base);
1770 
1771     Address arg_off(rscratch1, tmp1, Address::lsl(per_arg_scale));
1772     Address arg_type(rscratch2, tmp1, Address::lsl(per_arg_scale));
1773 
1774     // load offset on the stack from the slot for this parameter
1775     ldr(tmp2, arg_off);
1776     neg(tmp2, tmp2);
1777     // read the parameter from the local area
1778     ldr(tmp2, Address(rlocals, tmp2, Address::lsl(Interpreter::logStackElementSize)));
1779 
1780     // profile the parameter
1781     profile_obj_type(tmp2, arg_type);
1782 
1783     // go to next parameter
1784     subs(tmp1, tmp1, TypeStackSlotEntries::per_arg_count());
1785     br(Assembler::GE, loop);
1786 
1787     bind(profile_continue);
1788   }
1789 }
1790 
1791 void InterpreterMacroAssembler::load_resolved_indy_entry(Register cache, Register index) {
1792   // Get index out of bytecode pointer, get_cache_entry_pointer_at_bcp
1793   get_cache_index_at_bcp(index, 1, sizeof(u4));
1794   // Get address of invokedynamic array
1795   ldr(cache, Address(rcpool, in_bytes(ConstantPoolCache::invokedynamic_entries_offset())));
1796   // Scale the index to be the entry index * sizeof(ResolvedIndyEntry)
1797   lsl(index, index, log2i_exact(sizeof(ResolvedIndyEntry)));
1798   add(cache, cache, Array<ResolvedIndyEntry>::base_offset_in_bytes());
1799   lea(cache, Address(cache, index));
1800 }
1801 
1802 void InterpreterMacroAssembler::load_field_entry(Register cache, Register index, int bcp_offset) {
1803   // Get index out of bytecode pointer
1804   get_cache_index_at_bcp(index, bcp_offset, sizeof(u2));
1805   // Take shortcut if the size is a power of 2
1806   if (is_power_of_2(sizeof(ResolvedFieldEntry))) {
1807     lsl(index, index, log2i_exact(sizeof(ResolvedFieldEntry))); // Scale index by power of 2
1808   } else {
1809     mov(cache, sizeof(ResolvedFieldEntry));
1810     mul(index, index, cache); // Scale the index to be the entry index * sizeof(ResolvedFieldEntry)
1811   }
1812   // Get address of field entries array
1813   ldr(cache, Address(rcpool, ConstantPoolCache::field_entries_offset()));
1814   add(cache, cache, Array<ResolvedFieldEntry>::base_offset_in_bytes());
1815   lea(cache, Address(cache, index));
1816   // Prevents stale data from being read after the bytecode is patched to the fast bytecode
1817   membar(MacroAssembler::LoadLoad);
1818 }
1819 
1820 void InterpreterMacroAssembler::load_method_entry(Register cache, Register index, int bcp_offset) {
1821   // Get index out of bytecode pointer
1822   get_cache_index_at_bcp(index, bcp_offset, sizeof(u2));
1823   mov(cache, sizeof(ResolvedMethodEntry));
1824   mul(index, index, cache); // Scale the index to be the entry index * sizeof(ResolvedMethodEntry)
1825 
1826   // Get address of field entries array
1827   ldr(cache, Address(rcpool, ConstantPoolCache::method_entries_offset()));
1828   add(cache, cache, Array<ResolvedMethodEntry>::base_offset_in_bytes());
1829   lea(cache, Address(cache, index));
1830 }
1831 
1832 #ifdef ASSERT
1833 void InterpreterMacroAssembler::verify_field_offset(Register reg) {
1834   // Verify the field offset is not in the header, implicitly checks for 0
1835   Label L;
1836   subs(zr, reg, oopDesc::base_offset_in_bytes());
1837   br(Assembler::GE, L);
1838   stop("bad field offset");
1839   bind(L);
1840 }
1841 #endif