1 /*
   2  * Copyright (c) 2003, 2017, 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 "interp_masm_aarch64.hpp"
  28 #include "interpreter/interpreter.hpp"
  29 #include "interpreter/interpreterRuntime.hpp"
  30 #include "logging/log.hpp"
  31 #include "oops/arrayOop.hpp"
  32 #include "oops/markOop.hpp"
  33 #include "oops/methodData.hpp"
  34 #include "oops/method.hpp"
  35 #include "prims/jvmtiExport.hpp"
  36 #include "prims/jvmtiThreadState.hpp"
  37 #include "runtime/basicLock.hpp"
  38 #include "runtime/biasedLocking.hpp"
  39 #include "runtime/sharedRuntime.hpp"
  40 #include "runtime/thread.inline.hpp"
  41 
  42 
  43 void InterpreterMacroAssembler::narrow(Register result) {
  44 
  45   // Get method->_constMethod->_result_type
  46   ldr(rscratch1, Address(rfp, frame::interpreter_frame_method_offset * wordSize));
  47   ldr(rscratch1, Address(rscratch1, Method::const_offset()));
  48   ldrb(rscratch1, Address(rscratch1, ConstMethod::result_type_offset()));
  49 
  50   Label done, notBool, notByte, notChar;
  51 
  52   // common case first
  53   cmpw(rscratch1, T_INT);
  54   br(Assembler::EQ, done);
  55 
  56   // mask integer result to narrower return type.
  57   cmpw(rscratch1, T_BOOLEAN);
  58   br(Assembler::NE, notBool);
  59   andw(result, result, 0x1);
  60   b(done);
  61 
  62   bind(notBool);
  63   cmpw(rscratch1, T_BYTE);
  64   br(Assembler::NE, notByte);
  65   sbfx(result, result, 0, 8);
  66   b(done);
  67 
  68   bind(notByte);
  69   cmpw(rscratch1, T_CHAR);
  70   br(Assembler::NE, notChar);
  71   ubfx(result, result, 0, 16);  // truncate upper 16 bits
  72   b(done);
  73 
  74   bind(notChar);
  75   sbfx(result, result, 0, 16);     // sign-extend short
  76 
  77   // Nothing to do for T_INT
  78   bind(done);
  79 }
  80 
  81 void InterpreterMacroAssembler::jump_to_entry(address entry) {
  82   assert(entry, "Entry must have been generated by now");
  83   b(entry);
  84 }
  85 
  86 void InterpreterMacroAssembler::check_and_handle_popframe(Register java_thread) {
  87   if (JvmtiExport::can_pop_frame()) {
  88     Label L;
  89     // Initiate popframe handling only if it is not already being
  90     // processed.  If the flag has the popframe_processing bit set, it
  91     // means that this code is called *during* popframe handling - we
  92     // don't want to reenter.
  93     // This method is only called just after the call into the vm in
  94     // call_VM_base, so the arg registers are available.
  95     ldrw(rscratch1, Address(rthread, JavaThread::popframe_condition_offset()));
  96     tbz(rscratch1, exact_log2(JavaThread::popframe_pending_bit), L);
  97     tbnz(rscratch1, exact_log2(JavaThread::popframe_processing_bit), L);
  98     // Call Interpreter::remove_activation_preserving_args_entry() to get the
  99     // address of the same-named entrypoint in the generated interpreter code.
 100     call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_preserving_args_entry));
 101     br(r0);
 102     bind(L);
 103   }
 104 }
 105 
 106 
 107 void InterpreterMacroAssembler::load_earlyret_value(TosState state) {
 108   ldr(r2, Address(rthread, JavaThread::jvmti_thread_state_offset()));
 109   const Address tos_addr(r2, JvmtiThreadState::earlyret_tos_offset());
 110   const Address oop_addr(r2, JvmtiThreadState::earlyret_oop_offset());
 111   const Address val_addr(r2, JvmtiThreadState::earlyret_value_offset());
 112   switch (state) {
 113     case atos: ldr(r0, oop_addr);
 114                str(zr, oop_addr);
 115                verify_oop(r0, state);               break;
 116     case ltos: ldr(r0, val_addr);                   break;
 117     case btos:                                   // fall through
 118     case ztos:                                   // fall through
 119     case ctos:                                   // fall through
 120     case stos:                                   // fall through
 121     case itos: ldrw(r0, val_addr);                  break;
 122     case ftos: ldrs(v0, val_addr);                  break;
 123     case dtos: ldrd(v0, val_addr);                  break;
 124     case vtos: /* nothing to do */                  break;
 125     default  : ShouldNotReachHere();
 126   }
 127   // Clean up tos value in the thread object
 128   movw(rscratch1, (int) ilgl);
 129   strw(rscratch1, tos_addr);
 130   strw(zr, val_addr);
 131 }
 132 
 133 
 134 void InterpreterMacroAssembler::check_and_handle_earlyret(Register java_thread) {
 135   if (JvmtiExport::can_force_early_return()) {
 136     Label L;
 137     ldr(rscratch1, Address(rthread, JavaThread::jvmti_thread_state_offset()));
 138     cbz(rscratch1, L); // if (thread->jvmti_thread_state() == NULL) exit;
 139 
 140     // Initiate earlyret handling only if it is not already being processed.
 141     // If the flag has the earlyret_processing bit set, it means that this code
 142     // is called *during* earlyret handling - we don't want to reenter.
 143     ldrw(rscratch1, Address(rscratch1, JvmtiThreadState::earlyret_state_offset()));
 144     cmpw(rscratch1, JvmtiThreadState::earlyret_pending);
 145     br(Assembler::NE, L);
 146 
 147     // Call Interpreter::remove_activation_early_entry() to get the address of the
 148     // same-named entrypoint in the generated interpreter code.
 149     ldr(rscratch1, Address(rthread, JavaThread::jvmti_thread_state_offset()));
 150     ldrw(rscratch1, Address(rscratch1, JvmtiThreadState::earlyret_tos_offset()));
 151     call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry), rscratch1);
 152     br(r0);
 153     bind(L);
 154   }
 155 }
 156 
 157 void InterpreterMacroAssembler::get_unsigned_2_byte_index_at_bcp(
 158   Register reg,
 159   int bcp_offset) {
 160   assert(bcp_offset >= 0, "bcp is still pointing to start of bytecode");
 161   ldrh(reg, Address(rbcp, bcp_offset));
 162   rev16(reg, reg);
 163 }
 164 
 165 void InterpreterMacroAssembler::get_dispatch() {
 166   unsigned long offset;
 167   adrp(rdispatch, ExternalAddress((address)Interpreter::dispatch_table()), offset);
 168   lea(rdispatch, Address(rdispatch, offset));
 169 }
 170 
 171 void InterpreterMacroAssembler::get_cache_index_at_bcp(Register index,
 172                                                        int bcp_offset,
 173                                                        size_t index_size) {
 174   assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");
 175   if (index_size == sizeof(u2)) {
 176     load_unsigned_short(index, Address(rbcp, bcp_offset));
 177   } else if (index_size == sizeof(u4)) {
 178     // assert(EnableInvokeDynamic, "giant index used only for JSR 292");
 179     ldrw(index, Address(rbcp, bcp_offset));
 180     // Check if the secondary index definition is still ~x, otherwise
 181     // we have to change the following assembler code to calculate the
 182     // plain index.
 183     assert(ConstantPool::decode_invokedynamic_index(~123) == 123, "else change next line");
 184     eonw(index, index, zr);  // convert to plain index
 185   } else if (index_size == sizeof(u1)) {
 186     load_unsigned_byte(index, Address(rbcp, bcp_offset));
 187   } else {
 188     ShouldNotReachHere();
 189   }
 190 }
 191 
 192 // Return
 193 // Rindex: index into constant pool
 194 // Rcache: address of cache entry - ConstantPoolCache::base_offset()
 195 //
 196 // A caller must add ConstantPoolCache::base_offset() to Rcache to get
 197 // the true address of the cache entry.
 198 //
 199 void InterpreterMacroAssembler::get_cache_and_index_at_bcp(Register cache,
 200                                                            Register index,
 201                                                            int bcp_offset,
 202                                                            size_t index_size) {
 203   assert_different_registers(cache, index);
 204   assert_different_registers(cache, rcpool);
 205   get_cache_index_at_bcp(index, bcp_offset, index_size);
 206   assert(sizeof(ConstantPoolCacheEntry) == 4 * wordSize, "adjust code below");
 207   // convert from field index to ConstantPoolCacheEntry
 208   // aarch64 already has the cache in rcpool so there is no need to
 209   // install it in cache. instead we pre-add the indexed offset to
 210   // rcpool and return it in cache. All clients of this method need to
 211   // be modified accordingly.
 212   add(cache, rcpool, index, Assembler::LSL, 5);
 213 }
 214 
 215 
 216 void InterpreterMacroAssembler::get_cache_and_index_and_bytecode_at_bcp(Register cache,
 217                                                                         Register index,
 218                                                                         Register bytecode,
 219                                                                         int byte_no,
 220                                                                         int bcp_offset,
 221                                                                         size_t index_size) {
 222   get_cache_and_index_at_bcp(cache, index, bcp_offset, index_size);
 223   // We use a 32-bit load here since the layout of 64-bit words on
 224   // little-endian machines allow us that.
 225   // n.b. unlike x86 cache already includes the index offset
 226   lea(bytecode, Address(cache,
 227                          ConstantPoolCache::base_offset()
 228                          + ConstantPoolCacheEntry::indices_offset()));
 229   ldarw(bytecode, bytecode);
 230   const int shift_count = (1 + byte_no) * BitsPerByte;
 231   ubfx(bytecode, bytecode, shift_count, BitsPerByte);
 232 }
 233 
 234 void InterpreterMacroAssembler::get_cache_entry_pointer_at_bcp(Register cache,
 235                                                                Register tmp,
 236                                                                int bcp_offset,
 237                                                                size_t index_size) {
 238   assert(cache != tmp, "must use different register");
 239   get_cache_index_at_bcp(tmp, bcp_offset, index_size);
 240   assert(sizeof(ConstantPoolCacheEntry) == 4 * wordSize, "adjust code below");
 241   // convert from field index to ConstantPoolCacheEntry index
 242   // and from word offset to byte offset
 243   assert(exact_log2(in_bytes(ConstantPoolCacheEntry::size_in_bytes())) == 2 + LogBytesPerWord, "else change next line");
 244   ldr(cache, Address(rfp, frame::interpreter_frame_cache_offset * wordSize));
 245   // skip past the header
 246   add(cache, cache, in_bytes(ConstantPoolCache::base_offset()));
 247   add(cache, cache, tmp, Assembler::LSL, 2 + LogBytesPerWord);  // construct pointer to cache entry
 248 }
 249 
 250 void InterpreterMacroAssembler::get_method_counters(Register method,
 251                                                     Register mcs, Label& skip) {
 252   Label has_counters;
 253   ldr(mcs, Address(method, Method::method_counters_offset()));
 254   cbnz(mcs, has_counters);
 255   call_VM(noreg, CAST_FROM_FN_PTR(address,
 256           InterpreterRuntime::build_method_counters), method);
 257   ldr(mcs, Address(method, Method::method_counters_offset()));
 258   cbz(mcs, skip); // No MethodCounters allocated, OutOfMemory
 259   bind(has_counters);
 260 }
 261 
 262 // Load object from cpool->resolved_references(index)
 263 void InterpreterMacroAssembler::load_resolved_reference_at_index(
 264                                            Register result, Register index) {
 265   assert_different_registers(result, index);
 266   // convert from field index to resolved_references() index and from
 267   // word index to byte offset. Since this is a java object, it can be compressed
 268   Register tmp = index;  // reuse
 269   lslw(tmp, tmp, LogBytesPerHeapOop);
 270 
 271   get_constant_pool(result);
 272   // load pointer for resolved_references[] objArray
 273   ldr(result, Address(result, ConstantPool::cache_offset_in_bytes()));
 274   ldr(result, Address(result, ConstantPoolCache::resolved_references_offset_in_bytes()));
 275   // JNIHandles::resolve(obj);
 276   ldr(result, Address(result, 0));
 277   // Add in the index
 278   add(result, result, tmp);
 279   load_heap_oop(result, Address(result, arrayOopDesc::base_offset_in_bytes(T_OBJECT)));
 280 }
 281 
 282 // Generate a subtype check: branch to ok_is_subtype if sub_klass is a
 283 // subtype of super_klass.
 284 //
 285 // Args:
 286 //      r0: superklass
 287 //      Rsub_klass: subklass
 288 //
 289 // Kills:
 290 //      r2, r5
 291 void InterpreterMacroAssembler::gen_subtype_check(Register Rsub_klass,
 292                                                   Label& ok_is_subtype) {
 293   assert(Rsub_klass != r0, "r0 holds superklass");
 294   assert(Rsub_klass != r2, "r2 holds 2ndary super array length");
 295   assert(Rsub_klass != r5, "r5 holds 2ndary super array scan ptr");
 296 
 297   // Profile the not-null value's klass.
 298   profile_typecheck(r2, Rsub_klass, r5); // blows r2, reloads r5
 299 
 300   // Do the check.
 301   check_klass_subtype(Rsub_klass, r0, r2, ok_is_subtype); // blows r2
 302 
 303   // Profile the failure of the check.
 304   profile_typecheck_failed(r2); // blows r2
 305 }
 306 
 307 // Java Expression Stack
 308 
 309 void InterpreterMacroAssembler::pop_ptr(Register r) {
 310   ldr(r, post(esp, wordSize));
 311 }
 312 
 313 void InterpreterMacroAssembler::pop_i(Register r) {
 314   ldrw(r, post(esp, wordSize));
 315 }
 316 
 317 void InterpreterMacroAssembler::pop_l(Register r) {
 318   ldr(r, post(esp, 2 * Interpreter::stackElementSize));
 319 }
 320 
 321 void InterpreterMacroAssembler::push_ptr(Register r) {
 322   str(r, pre(esp, -wordSize));
 323  }
 324 
 325 void InterpreterMacroAssembler::push_i(Register r) {
 326   str(r, pre(esp, -wordSize));
 327 }
 328 
 329 void InterpreterMacroAssembler::push_l(Register r) {
 330   str(zr, pre(esp, -wordSize));
 331   str(r, pre(esp, - wordSize));
 332 }
 333 
 334 void InterpreterMacroAssembler::pop_f(FloatRegister r) {
 335   ldrs(r, post(esp, wordSize));
 336 }
 337 
 338 void InterpreterMacroAssembler::pop_d(FloatRegister r) {
 339   ldrd(r, post(esp, 2 * Interpreter::stackElementSize));
 340 }
 341 
 342 void InterpreterMacroAssembler::push_f(FloatRegister r) {
 343   strs(r, pre(esp, -wordSize));
 344 }
 345 
 346 void InterpreterMacroAssembler::push_d(FloatRegister r) {
 347   strd(r, pre(esp, 2* -wordSize));
 348 }
 349 
 350 void InterpreterMacroAssembler::pop(TosState state) {
 351   switch (state) {
 352   case atos: pop_ptr();                 break;
 353   case btos:
 354   case ztos:
 355   case ctos:
 356   case stos:
 357   case itos: pop_i();                   break;
 358   case ltos: pop_l();                   break;
 359   case ftos: pop_f();                   break;
 360   case dtos: pop_d();                   break;
 361   case vtos: /* nothing to do */        break;
 362   default:   ShouldNotReachHere();
 363   }
 364   verify_oop(r0, state);
 365 }
 366 
 367 void InterpreterMacroAssembler::push(TosState state) {
 368   verify_oop(r0, state);
 369   switch (state) {
 370   case atos: push_ptr();                break;
 371   case btos:
 372   case ztos:
 373   case ctos:
 374   case stos:
 375   case itos: push_i();                  break;
 376   case ltos: push_l();                  break;
 377   case ftos: push_f();                  break;
 378   case dtos: push_d();                  break;
 379   case vtos: /* nothing to do */        break;
 380   default  : ShouldNotReachHere();
 381   }
 382 }
 383 
 384 // Helpers for swap and dup
 385 void InterpreterMacroAssembler::load_ptr(int n, Register val) {
 386   ldr(val, Address(esp, Interpreter::expr_offset_in_bytes(n)));
 387 }
 388 
 389 void InterpreterMacroAssembler::store_ptr(int n, Register val) {
 390   str(val, Address(esp, Interpreter::expr_offset_in_bytes(n)));
 391 }
 392 
 393 
 394 void InterpreterMacroAssembler::prepare_to_jump_from_interpreted() {
 395   // set sender sp
 396   mov(r13, sp);
 397   // record last_sp
 398   str(esp, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize));
 399 }
 400 
 401 // Jump to from_interpreted entry of a call unless single stepping is possible
 402 // in this thread in which case we must call the i2i entry
 403 void InterpreterMacroAssembler::jump_from_interpreted(Register method, Register temp) {
 404   prepare_to_jump_from_interpreted();
 405 
 406   if (JvmtiExport::can_post_interpreter_events()) {
 407     Label run_compiled_code;
 408     // JVMTI events, such as single-stepping, are implemented partly by avoiding running
 409     // compiled code in threads for which the event is enabled.  Check here for
 410     // interp_only_mode if these events CAN be enabled.
 411     ldrw(rscratch1, Address(rthread, JavaThread::interp_only_mode_offset()));
 412     cbzw(rscratch1, run_compiled_code);
 413     ldr(rscratch1, Address(method, Method::interpreter_entry_offset()));
 414     br(rscratch1);
 415     bind(run_compiled_code);
 416   }
 417 
 418   ldr(rscratch1, Address(method, Method::from_interpreted_offset()));
 419   br(rscratch1);
 420 }
 421 
 422 // The following two routines provide a hook so that an implementation
 423 // can schedule the dispatch in two parts.  amd64 does not do this.
 424 void InterpreterMacroAssembler::dispatch_prolog(TosState state, int step) {
 425 }
 426 
 427 void InterpreterMacroAssembler::dispatch_epilog(TosState state, int step) {
 428     dispatch_next(state, step);
 429 }
 430 
 431 void InterpreterMacroAssembler::dispatch_base(TosState state,
 432                                               address* table,
 433                                               bool verifyoop) {
 434   if (VerifyActivationFrameSize) {
 435     Unimplemented();
 436   }
 437   if (verifyoop) {
 438     verify_oop(r0, state);
 439   }
 440   if (table == Interpreter::dispatch_table(state)) {
 441     addw(rscratch2, rscratch1, Interpreter::distance_from_dispatch_table(state));
 442     ldr(rscratch2, Address(rdispatch, rscratch2, Address::uxtw(3)));
 443   } else {
 444     mov(rscratch2, (address)table);
 445     ldr(rscratch2, Address(rscratch2, rscratch1, Address::uxtw(3)));
 446   }
 447   br(rscratch2);
 448 }
 449 
 450 void InterpreterMacroAssembler::dispatch_only(TosState state) {
 451   dispatch_base(state, Interpreter::dispatch_table(state));
 452 }
 453 
 454 void InterpreterMacroAssembler::dispatch_only_normal(TosState state) {
 455   dispatch_base(state, Interpreter::normal_table(state));
 456 }
 457 
 458 void InterpreterMacroAssembler::dispatch_only_noverify(TosState state) {
 459   dispatch_base(state, Interpreter::normal_table(state), false);
 460 }
 461 
 462 
 463 void InterpreterMacroAssembler::dispatch_next(TosState state, int step) {
 464   // load next bytecode
 465   ldrb(rscratch1, Address(pre(rbcp, step)));
 466   dispatch_base(state, Interpreter::dispatch_table(state));
 467 }
 468 
 469 void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) {
 470   // load current bytecode
 471   ldrb(rscratch1, Address(rbcp, 0));
 472   dispatch_base(state, table);
 473 }
 474 
 475 // remove activation
 476 //
 477 // Unlock the receiver if this is a synchronized method.
 478 // Unlock any Java monitors from syncronized blocks.
 479 // Remove the activation from the stack.
 480 //
 481 // If there are locked Java monitors
 482 //    If throw_monitor_exception
 483 //       throws IllegalMonitorStateException
 484 //    Else if install_monitor_exception
 485 //       installs IllegalMonitorStateException
 486 //    Else
 487 //       no error processing
 488 void InterpreterMacroAssembler::remove_activation(
 489         TosState state,
 490         bool throw_monitor_exception,
 491         bool install_monitor_exception,
 492         bool notify_jvmdi) {
 493   // Note: Registers r3 xmm0 may be in use for the
 494   // result check if synchronized method
 495   Label unlocked, unlock, no_unlock;
 496 
 497   // get the value of _do_not_unlock_if_synchronized into r3
 498   const Address do_not_unlock_if_synchronized(rthread,
 499     in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
 500   ldrb(r3, do_not_unlock_if_synchronized);
 501   strb(zr, do_not_unlock_if_synchronized); // reset the flag
 502 
 503  // get method access flags
 504   ldr(r1, Address(rfp, frame::interpreter_frame_method_offset * wordSize));
 505   ldr(r2, Address(r1, Method::access_flags_offset()));
 506   tbz(r2, exact_log2(JVM_ACC_SYNCHRONIZED), unlocked);
 507 
 508   // Don't unlock anything if the _do_not_unlock_if_synchronized flag
 509   // is set.
 510   cbnz(r3, no_unlock);
 511 
 512   // unlock monitor
 513   push(state); // save result
 514 
 515   // BasicObjectLock will be first in list, since this is a
 516   // synchronized method. However, need to check that the object has
 517   // not been unlocked by an explicit monitorexit bytecode.
 518   const Address monitor(rfp, frame::interpreter_frame_initial_sp_offset *
 519                         wordSize - (int) sizeof(BasicObjectLock));
 520   // We use c_rarg1 so that if we go slow path it will be the correct
 521   // register for unlock_object to pass to VM directly
 522   lea(c_rarg1, monitor); // address of first monitor
 523 
 524   ldr(r0, Address(c_rarg1, BasicObjectLock::obj_offset_in_bytes()));
 525   cbnz(r0, unlock);
 526 
 527   pop(state);
 528   if (throw_monitor_exception) {
 529     // Entry already unlocked, need to throw exception
 530     call_VM(noreg, CAST_FROM_FN_PTR(address,
 531                    InterpreterRuntime::throw_illegal_monitor_state_exception));
 532     should_not_reach_here();
 533   } else {
 534     // Monitor already unlocked during a stack unroll. If requested,
 535     // install an illegal_monitor_state_exception.  Continue with
 536     // stack unrolling.
 537     if (install_monitor_exception) {
 538       call_VM(noreg, CAST_FROM_FN_PTR(address,
 539                      InterpreterRuntime::new_illegal_monitor_state_exception));
 540     }
 541     b(unlocked);
 542   }
 543 
 544   bind(unlock);
 545   unlock_object(c_rarg1);
 546   pop(state);
 547 
 548   // Check that for block-structured locking (i.e., that all locked
 549   // objects has been unlocked)
 550   bind(unlocked);
 551 
 552   // r0: Might contain return value
 553 
 554   // Check that all monitors are unlocked
 555   {
 556     Label loop, exception, entry, restart;
 557     const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
 558     const Address monitor_block_top(
 559         rfp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
 560     const Address monitor_block_bot(
 561         rfp, frame::interpreter_frame_initial_sp_offset * wordSize);
 562 
 563     bind(restart);
 564     // We use c_rarg1 so that if we go slow path it will be the correct
 565     // register for unlock_object to pass to VM directly
 566     ldr(c_rarg1, monitor_block_top); // points to current entry, starting
 567                                      // with top-most entry
 568     lea(r19, monitor_block_bot);  // points to word before bottom of
 569                                   // monitor block
 570     b(entry);
 571 
 572     // Entry already locked, need to throw exception
 573     bind(exception);
 574 
 575     if (throw_monitor_exception) {
 576       // Throw exception
 577       MacroAssembler::call_VM(noreg,
 578                               CAST_FROM_FN_PTR(address, InterpreterRuntime::
 579                                    throw_illegal_monitor_state_exception));
 580       should_not_reach_here();
 581     } else {
 582       // Stack unrolling. Unlock object and install illegal_monitor_exception.
 583       // Unlock does not block, so don't have to worry about the frame.
 584       // We don't have to preserve c_rarg1 since we are going to throw an exception.
 585 
 586       push(state);
 587       unlock_object(c_rarg1);
 588       pop(state);
 589 
 590       if (install_monitor_exception) {
 591         call_VM(noreg, CAST_FROM_FN_PTR(address,
 592                                         InterpreterRuntime::
 593                                         new_illegal_monitor_state_exception));
 594       }
 595 
 596       b(restart);
 597     }
 598 
 599     bind(loop);
 600     // check if current entry is used
 601     ldr(rscratch1, Address(c_rarg1, BasicObjectLock::obj_offset_in_bytes()));
 602     cbnz(rscratch1, exception);
 603 
 604     add(c_rarg1, c_rarg1, entry_size); // otherwise advance to next entry
 605     bind(entry);
 606     cmp(c_rarg1, r19); // check if bottom reached
 607     br(Assembler::NE, loop); // if not at bottom then check this entry
 608   }
 609 
 610   bind(no_unlock);
 611 
 612   // jvmti support
 613   if (notify_jvmdi) {
 614     notify_method_exit(state, NotifyJVMTI);    // preserve TOSCA
 615   } else {
 616     notify_method_exit(state, SkipNotifyJVMTI); // preserve TOSCA
 617   }
 618 
 619   // remove activation
 620   // get sender esp
 621   ldr(esp,
 622       Address(rfp, frame::interpreter_frame_sender_sp_offset * wordSize));
 623   if (StackReservedPages > 0) {
 624     // testing if reserved zone needs to be re-enabled
 625     Label no_reserved_zone_enabling;
 626 
 627     ldr(rscratch1, Address(rthread, JavaThread::reserved_stack_activation_offset()));
 628     cmp(esp, rscratch1);
 629     br(Assembler::LS, no_reserved_zone_enabling);
 630 
 631     call_VM_leaf(
 632       CAST_FROM_FN_PTR(address, SharedRuntime::enable_stack_reserved_zone), rthread);
 633     call_VM(noreg, CAST_FROM_FN_PTR(address,
 634                    InterpreterRuntime::throw_delayed_StackOverflowError));
 635     should_not_reach_here();
 636 
 637     bind(no_reserved_zone_enabling);
 638   }
 639   // remove frame anchor
 640   leave();
 641   // If we're returning to interpreted code we will shortly be
 642   // adjusting SP to allow some space for ESP.  If we're returning to
 643   // compiled code the saved sender SP was saved in sender_sp, so this
 644   // restores it.
 645   andr(sp, esp, -16);
 646 }
 647 
 648 // Lock object
 649 //
 650 // Args:
 651 //      c_rarg1: BasicObjectLock to be used for locking
 652 //
 653 // Kills:
 654 //      r0
 655 //      c_rarg0, c_rarg1, c_rarg2, c_rarg3, .. (param regs)
 656 //      rscratch1, rscratch2 (scratch regs)
 657 void InterpreterMacroAssembler::lock_object(Register lock_reg)
 658 {
 659   assert(lock_reg == c_rarg1, "The argument is only for looks. It must be c_rarg1");
 660   if (UseHeavyMonitors) {
 661     call_VM(noreg,
 662             CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
 663             lock_reg);
 664   } else {
 665     Label done;
 666 
 667     const Register swap_reg = r0;
 668     const Register tmp = c_rarg2;
 669     const Register obj_reg = c_rarg3; // Will contain the oop
 670 
 671     const int obj_offset = BasicObjectLock::obj_offset_in_bytes();
 672     const int lock_offset = BasicObjectLock::lock_offset_in_bytes ();
 673     const int mark_offset = lock_offset +
 674                             BasicLock::displaced_header_offset_in_bytes();
 675 
 676     Label slow_case;
 677 
 678     // Load object pointer into obj_reg %c_rarg3
 679     ldr(obj_reg, Address(lock_reg, obj_offset));
 680 
 681     if (UseBiasedLocking) {
 682       biased_locking_enter(lock_reg, obj_reg, swap_reg, tmp, false, done, &slow_case);
 683     }
 684 
 685     // Load (object->mark() | 1) into swap_reg
 686     ldr(rscratch1, Address(obj_reg, 0));
 687     orr(swap_reg, rscratch1, 1);
 688 
 689     // Save (object->mark() | 1) into BasicLock's displaced header
 690     str(swap_reg, Address(lock_reg, mark_offset));
 691 
 692     assert(lock_offset == 0,
 693            "displached header must be first word in BasicObjectLock");
 694 
 695     Label fail;
 696     if (PrintBiasedLockingStatistics) {
 697       Label fast;
 698       cmpxchgptr(swap_reg, lock_reg, obj_reg, rscratch1, fast, &fail);
 699       bind(fast);
 700       atomic_incw(Address((address)BiasedLocking::fast_path_entry_count_addr()),
 701                   rscratch2, rscratch1, tmp);
 702       b(done);
 703       bind(fail);
 704     } else {
 705       cmpxchgptr(swap_reg, lock_reg, obj_reg, rscratch1, done, /*fallthrough*/NULL);
 706     }
 707 
 708     // Test if the oopMark is an obvious stack pointer, i.e.,
 709     //  1) (mark & 7) == 0, and
 710     //  2) rsp <= mark < mark + os::pagesize()
 711     //
 712     // These 3 tests can be done by evaluating the following
 713     // expression: ((mark - rsp) & (7 - os::vm_page_size())),
 714     // assuming both stack pointer and pagesize have their
 715     // least significant 3 bits clear.
 716     // NOTE: the oopMark is in swap_reg %r0 as the result of cmpxchg
 717     // NOTE2: aarch64 does not like to subtract sp from rn so take a
 718     // copy
 719     mov(rscratch1, sp);
 720     sub(swap_reg, swap_reg, rscratch1);
 721     ands(swap_reg, swap_reg, (unsigned long)(7 - os::vm_page_size()));
 722 
 723     // Save the test result, for recursive case, the result is zero
 724     str(swap_reg, Address(lock_reg, mark_offset));
 725 
 726     if (PrintBiasedLockingStatistics) {
 727       br(Assembler::NE, slow_case);
 728       atomic_incw(Address((address)BiasedLocking::fast_path_entry_count_addr()),
 729                   rscratch2, rscratch1, tmp);
 730     }
 731     br(Assembler::EQ, done);
 732 
 733     bind(slow_case);
 734 
 735     // Call the runtime routine for slow case
 736     call_VM(noreg,
 737             CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
 738             lock_reg);
 739 
 740     bind(done);
 741   }
 742 }
 743 
 744 
 745 // Unlocks an object. Used in monitorexit bytecode and
 746 // remove_activation.  Throws an IllegalMonitorException if object is
 747 // not locked by current thread.
 748 //
 749 // Args:
 750 //      c_rarg1: BasicObjectLock for lock
 751 //
 752 // Kills:
 753 //      r0
 754 //      c_rarg0, c_rarg1, c_rarg2, c_rarg3, ... (param regs)
 755 //      rscratch1, rscratch2 (scratch regs)
 756 void InterpreterMacroAssembler::unlock_object(Register lock_reg)
 757 {
 758   assert(lock_reg == c_rarg1, "The argument is only for looks. It must be rarg1");
 759 
 760   if (UseHeavyMonitors) {
 761     call_VM(noreg,
 762             CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit),
 763             lock_reg);
 764   } else {
 765     Label done;
 766 
 767     const Register swap_reg   = r0;
 768     const Register header_reg = c_rarg2;  // Will contain the old oopMark
 769     const Register obj_reg    = c_rarg3;  // Will contain the oop
 770 
 771     save_bcp(); // Save in case of exception
 772 
 773     // Convert from BasicObjectLock structure to object and BasicLock
 774     // structure Store the BasicLock address into %r0
 775     lea(swap_reg, Address(lock_reg, BasicObjectLock::lock_offset_in_bytes()));
 776 
 777     // Load oop into obj_reg(%c_rarg3)
 778     ldr(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()));
 779 
 780     // Free entry
 781     str(zr, Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()));
 782 
 783     if (UseBiasedLocking) {
 784       biased_locking_exit(obj_reg, header_reg, done);
 785     }
 786 
 787     // Load the old header from BasicLock structure
 788     ldr(header_reg, Address(swap_reg,
 789                             BasicLock::displaced_header_offset_in_bytes()));
 790 
 791     // Test for recursion
 792     cbz(header_reg, done);
 793 
 794     // Atomic swap back the old header
 795     cmpxchgptr(swap_reg, header_reg, obj_reg, rscratch1, done, /*fallthrough*/NULL);
 796 
 797     // Call the runtime routine for slow case.
 798     str(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset_in_bytes())); // restore obj
 799     call_VM(noreg,
 800             CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit),
 801             lock_reg);
 802 
 803     bind(done);
 804 
 805     restore_bcp();
 806   }
 807 }
 808 
 809 void InterpreterMacroAssembler::test_method_data_pointer(Register mdp,
 810                                                          Label& zero_continue) {
 811   assert(ProfileInterpreter, "must be profiling interpreter");
 812   ldr(mdp, Address(rfp, frame::interpreter_frame_mdp_offset * wordSize));
 813   cbz(mdp, zero_continue);
 814 }
 815 
 816 // Set the method data pointer for the current bcp.
 817 void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() {
 818   assert(ProfileInterpreter, "must be profiling interpreter");
 819   Label set_mdp;
 820   stp(r0, r1, Address(pre(sp, -2 * wordSize)));
 821 
 822   // Test MDO to avoid the call if it is NULL.
 823   ldr(r0, Address(rmethod, in_bytes(Method::method_data_offset())));
 824   cbz(r0, set_mdp);
 825   call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), rmethod, rbcp);
 826   // r0: mdi
 827   // mdo is guaranteed to be non-zero here, we checked for it before the call.
 828   ldr(r1, Address(rmethod, in_bytes(Method::method_data_offset())));
 829   lea(r1, Address(r1, in_bytes(MethodData::data_offset())));
 830   add(r0, r1, r0);
 831   str(r0, Address(rfp, frame::interpreter_frame_mdp_offset * wordSize));
 832   bind(set_mdp);
 833   ldp(r0, r1, Address(post(sp, 2 * wordSize)));
 834 }
 835 
 836 void InterpreterMacroAssembler::verify_method_data_pointer() {
 837   assert(ProfileInterpreter, "must be profiling interpreter");
 838 #ifdef ASSERT
 839   Label verify_continue;
 840   stp(r0, r1, Address(pre(sp, -2 * wordSize)));
 841   stp(r2, r3, Address(pre(sp, -2 * wordSize)));
 842   test_method_data_pointer(r3, verify_continue); // If mdp is zero, continue
 843   get_method(r1);
 844 
 845   // If the mdp is valid, it will point to a DataLayout header which is
 846   // consistent with the bcp.  The converse is highly probable also.
 847   ldrsh(r2, Address(r3, in_bytes(DataLayout::bci_offset())));
 848   ldr(rscratch1, Address(r1, Method::const_offset()));
 849   add(r2, r2, rscratch1, Assembler::LSL);
 850   lea(r2, Address(r2, ConstMethod::codes_offset()));
 851   cmp(r2, rbcp);
 852   br(Assembler::EQ, verify_continue);
 853   // r1: method
 854   // rbcp: bcp // rbcp == 22
 855   // r3: mdp
 856   call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp),
 857                r1, rbcp, r3);
 858   bind(verify_continue);
 859   ldp(r2, r3, Address(post(sp, 2 * wordSize)));
 860   ldp(r0, r1, Address(post(sp, 2 * wordSize)));
 861 #endif // ASSERT
 862 }
 863 
 864 
 865 void InterpreterMacroAssembler::set_mdp_data_at(Register mdp_in,
 866                                                 int constant,
 867                                                 Register value) {
 868   assert(ProfileInterpreter, "must be profiling interpreter");
 869   Address data(mdp_in, constant);
 870   str(value, data);
 871 }
 872 
 873 
 874 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
 875                                                       int constant,
 876                                                       bool decrement) {
 877   increment_mdp_data_at(mdp_in, noreg, constant, decrement);
 878 }
 879 
 880 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
 881                                                       Register reg,
 882                                                       int constant,
 883                                                       bool decrement) {
 884   assert(ProfileInterpreter, "must be profiling interpreter");
 885   // %%% this does 64bit counters at best it is wasting space
 886   // at worst it is a rare bug when counters overflow
 887 
 888   assert_different_registers(rscratch2, rscratch1, mdp_in, reg);
 889 
 890   Address addr1(mdp_in, constant);
 891   Address addr2(rscratch2, reg, Address::lsl(0));
 892   Address &addr = addr1;
 893   if (reg != noreg) {
 894     lea(rscratch2, addr1);
 895     addr = addr2;
 896   }
 897 
 898   if (decrement) {
 899     // Decrement the register.  Set condition codes.
 900     // Intel does this
 901     // addptr(data, (int32_t) -DataLayout::counter_increment);
 902     // If the decrement causes the counter to overflow, stay negative
 903     // Label L;
 904     // jcc(Assembler::negative, L);
 905     // addptr(data, (int32_t) DataLayout::counter_increment);
 906     // so we do this
 907     ldr(rscratch1, addr);
 908     subs(rscratch1, rscratch1, (unsigned)DataLayout::counter_increment);
 909     Label L;
 910     br(Assembler::LO, L);       // skip store if counter underflow
 911     str(rscratch1, addr);
 912     bind(L);
 913   } else {
 914     assert(DataLayout::counter_increment == 1,
 915            "flow-free idiom only works with 1");
 916     // Intel does this
 917     // Increment the register.  Set carry flag.
 918     // addptr(data, DataLayout::counter_increment);
 919     // If the increment causes the counter to overflow, pull back by 1.
 920     // sbbptr(data, (int32_t)0);
 921     // so we do this
 922     ldr(rscratch1, addr);
 923     adds(rscratch1, rscratch1, DataLayout::counter_increment);
 924     Label L;
 925     br(Assembler::CS, L);       // skip store if counter overflow
 926     str(rscratch1, addr);
 927     bind(L);
 928   }
 929 }
 930 
 931 void InterpreterMacroAssembler::set_mdp_flag_at(Register mdp_in,
 932                                                 int flag_byte_constant) {
 933   assert(ProfileInterpreter, "must be profiling interpreter");
 934   int header_offset = in_bytes(DataLayout::header_offset());
 935   int header_bits = DataLayout::flag_mask_to_header_mask(flag_byte_constant);
 936   // Set the flag
 937   ldr(rscratch1, Address(mdp_in, header_offset));
 938   orr(rscratch1, rscratch1, header_bits);
 939   str(rscratch1, Address(mdp_in, header_offset));
 940 }
 941 
 942 
 943 void InterpreterMacroAssembler::test_mdp_data_at(Register mdp_in,
 944                                                  int offset,
 945                                                  Register value,
 946                                                  Register test_value_out,
 947                                                  Label& not_equal_continue) {
 948   assert(ProfileInterpreter, "must be profiling interpreter");
 949   if (test_value_out == noreg) {
 950     ldr(rscratch1, Address(mdp_in, offset));
 951     cmp(value, rscratch1);
 952   } else {
 953     // Put the test value into a register, so caller can use it:
 954     ldr(test_value_out, Address(mdp_in, offset));
 955     cmp(value, test_value_out);
 956   }
 957   br(Assembler::NE, not_equal_continue);
 958 }
 959 
 960 
 961 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,
 962                                                      int offset_of_disp) {
 963   assert(ProfileInterpreter, "must be profiling interpreter");
 964   ldr(rscratch1, Address(mdp_in, offset_of_disp));
 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_offset(Register mdp_in,
 971                                                      Register reg,
 972                                                      int offset_of_disp) {
 973   assert(ProfileInterpreter, "must be profiling interpreter");
 974   lea(rscratch1, Address(mdp_in, offset_of_disp));
 975   ldr(rscratch1, Address(rscratch1, reg, Address::lsl(0)));
 976   add(mdp_in, mdp_in, rscratch1, LSL);
 977   str(mdp_in, Address(rfp, frame::interpreter_frame_mdp_offset * wordSize));
 978 }
 979 
 980 
 981 void InterpreterMacroAssembler::update_mdp_by_constant(Register mdp_in,
 982                                                        int constant) {
 983   assert(ProfileInterpreter, "must be profiling interpreter");
 984   add(mdp_in, mdp_in, (unsigned)constant);
 985   str(mdp_in, Address(rfp, frame::interpreter_frame_mdp_offset * wordSize));
 986 }
 987 
 988 
 989 void InterpreterMacroAssembler::update_mdp_for_ret(Register return_bci) {
 990   assert(ProfileInterpreter, "must be profiling interpreter");
 991   // save/restore across call_VM
 992   stp(zr, return_bci, Address(pre(sp, -2 * wordSize)));
 993   call_VM(noreg,
 994           CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret),
 995           return_bci);
 996   ldp(zr, return_bci, Address(post(sp, 2 * wordSize)));
 997 }
 998 
 999 
1000 void InterpreterMacroAssembler::profile_taken_branch(Register mdp,
1001                                                      Register bumped_count) {
1002   if (ProfileInterpreter) {
1003     Label profile_continue;
1004 
1005     // If no method data exists, go to profile_continue.
1006     // Otherwise, assign to mdp
1007     test_method_data_pointer(mdp, profile_continue);
1008 
1009     // We are taking a branch.  Increment the taken count.
1010     // We inline increment_mdp_data_at to return bumped_count in a register
1011     //increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset()));
1012     Address data(mdp, in_bytes(JumpData::taken_offset()));
1013     ldr(bumped_count, data);
1014     assert(DataLayout::counter_increment == 1,
1015             "flow-free idiom only works with 1");
1016     // Intel does this to catch overflow
1017     // addptr(bumped_count, DataLayout::counter_increment);
1018     // sbbptr(bumped_count, 0);
1019     // so we do this
1020     adds(bumped_count, bumped_count, DataLayout::counter_increment);
1021     Label L;
1022     br(Assembler::CS, L);       // skip store if counter overflow
1023     str(bumped_count, data);
1024     bind(L);
1025     // The method data pointer needs to be updated to reflect the new target.
1026     update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset()));
1027     bind(profile_continue);
1028   }
1029 }
1030 
1031 
1032 void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp) {
1033   if (ProfileInterpreter) {
1034     Label profile_continue;
1035 
1036     // If no method data exists, go to profile_continue.
1037     test_method_data_pointer(mdp, profile_continue);
1038 
1039     // We are taking a branch.  Increment the not taken count.
1040     increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset()));
1041 
1042     // The method data pointer needs to be updated to correspond to
1043     // the next bytecode
1044     update_mdp_by_constant(mdp, in_bytes(BranchData::branch_data_size()));
1045     bind(profile_continue);
1046   }
1047 }
1048 
1049 
1050 void InterpreterMacroAssembler::profile_call(Register mdp) {
1051   if (ProfileInterpreter) {
1052     Label profile_continue;
1053 
1054     // If no method data exists, go to profile_continue.
1055     test_method_data_pointer(mdp, profile_continue);
1056 
1057     // We are making a call.  Increment the count.
1058     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1059 
1060     // The method data pointer needs to be updated to reflect the new target.
1061     update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size()));
1062     bind(profile_continue);
1063   }
1064 }
1065 
1066 void InterpreterMacroAssembler::profile_final_call(Register mdp) {
1067   if (ProfileInterpreter) {
1068     Label profile_continue;
1069 
1070     // If no method data exists, go to profile_continue.
1071     test_method_data_pointer(mdp, profile_continue);
1072 
1073     // We are making a call.  Increment the count.
1074     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1075 
1076     // The method data pointer needs to be updated to reflect the new target.
1077     update_mdp_by_constant(mdp,
1078                            in_bytes(VirtualCallData::
1079                                     virtual_call_data_size()));
1080     bind(profile_continue);
1081   }
1082 }
1083 
1084 
1085 void InterpreterMacroAssembler::profile_virtual_call(Register receiver,
1086                                                      Register mdp,
1087                                                      Register reg2,
1088                                                      bool receiver_can_be_null) {
1089   if (ProfileInterpreter) {
1090     Label profile_continue;
1091 
1092     // If no method data exists, go to profile_continue.
1093     test_method_data_pointer(mdp, profile_continue);
1094 
1095     Label skip_receiver_profile;
1096     if (receiver_can_be_null) {
1097       Label not_null;
1098       // We are making a call.  Increment the count for null receiver.
1099       increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1100       b(skip_receiver_profile);
1101       bind(not_null);
1102     }
1103 
1104     // Record the receiver type.
1105     record_klass_in_profile(receiver, mdp, reg2, true);
1106     bind(skip_receiver_profile);
1107 
1108     // The method data pointer needs to be updated to reflect the new target.
1109 #if INCLUDE_JVMCI
1110     if (MethodProfileWidth == 0) {
1111       update_mdp_by_constant(mdp, in_bytes(VirtualCallData::virtual_call_data_size()));
1112     }
1113 #else // INCLUDE_JVMCI
1114     update_mdp_by_constant(mdp,
1115                            in_bytes(VirtualCallData::
1116                                     virtual_call_data_size()));
1117 #endif // INCLUDE_JVMCI
1118     bind(profile_continue);
1119   }
1120 }
1121 
1122 #if INCLUDE_JVMCI
1123 void InterpreterMacroAssembler::profile_called_method(Register method, Register mdp, Register reg2) {
1124   assert_different_registers(method, mdp, reg2);
1125   if (ProfileInterpreter && MethodProfileWidth > 0) {
1126     Label profile_continue;
1127 
1128     // If no method data exists, go to profile_continue.
1129     test_method_data_pointer(mdp, profile_continue);
1130 
1131     Label done;
1132     record_item_in_profile_helper(method, mdp, reg2, 0, done, MethodProfileWidth,
1133       &VirtualCallData::method_offset, &VirtualCallData::method_count_offset, in_bytes(VirtualCallData::nonprofiled_receiver_count_offset()));
1134     bind(done);
1135 
1136     update_mdp_by_constant(mdp, in_bytes(VirtualCallData::virtual_call_data_size()));
1137     bind(profile_continue);
1138   }
1139 }
1140 #endif // INCLUDE_JVMCI
1141 
1142 // This routine creates a state machine for updating the multi-row
1143 // type profile at a virtual call site (or other type-sensitive bytecode).
1144 // The machine visits each row (of receiver/count) until the receiver type
1145 // is found, or until it runs out of rows.  At the same time, it remembers
1146 // the location of the first empty row.  (An empty row records null for its
1147 // receiver, and can be allocated for a newly-observed receiver type.)
1148 // Because there are two degrees of freedom in the state, a simple linear
1149 // search will not work; it must be a decision tree.  Hence this helper
1150 // function is recursive, to generate the required tree structured code.
1151 // It's the interpreter, so we are trading off code space for speed.
1152 // See below for example code.
1153 void InterpreterMacroAssembler::record_klass_in_profile_helper(
1154                                         Register receiver, Register mdp,
1155                                         Register reg2, int start_row,
1156                                         Label& done, bool is_virtual_call) {
1157   if (TypeProfileWidth == 0) {
1158     if (is_virtual_call) {
1159       increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1160     }
1161 #if INCLUDE_JVMCI
1162     else if (EnableJVMCI) {
1163       increment_mdp_data_at(mdp, in_bytes(ReceiverTypeData::nonprofiled_receiver_count_offset()));
1164     }
1165 #endif // INCLUDE_JVMCI
1166   } else {
1167     int non_profiled_offset = -1;
1168     if (is_virtual_call) {
1169       non_profiled_offset = in_bytes(CounterData::count_offset());
1170     }
1171 #if INCLUDE_JVMCI
1172     else if (EnableJVMCI) {
1173       non_profiled_offset = in_bytes(ReceiverTypeData::nonprofiled_receiver_count_offset());
1174     }
1175 #endif // INCLUDE_JVMCI
1176 
1177     record_item_in_profile_helper(receiver, mdp, reg2, 0, done, TypeProfileWidth,
1178         &VirtualCallData::receiver_offset, &VirtualCallData::receiver_count_offset, non_profiled_offset);
1179   }
1180 }
1181 
1182 void InterpreterMacroAssembler::record_item_in_profile_helper(Register item, Register mdp,
1183                                         Register reg2, int start_row, Label& done, int total_rows,
1184                                         OffsetFunction item_offset_fn, OffsetFunction item_count_offset_fn,
1185                                         int non_profiled_offset) {
1186   int last_row = total_rows - 1;
1187   assert(start_row <= last_row, "must be work left to do");
1188   // Test this row for both the item and for null.
1189   // Take any of three different outcomes:
1190   //   1. found item => increment count and goto done
1191   //   2. found null => keep looking for case 1, maybe allocate this cell
1192   //   3. found something else => keep looking for cases 1 and 2
1193   // Case 3 is handled by a recursive call.
1194   for (int row = start_row; row <= last_row; row++) {
1195     Label next_test;
1196     bool test_for_null_also = (row == start_row);
1197 
1198     // See if the item is item[n].
1199     int item_offset = in_bytes(item_offset_fn(row));
1200     test_mdp_data_at(mdp, item_offset, item,
1201                      (test_for_null_also ? reg2 : noreg),
1202                      next_test);
1203     // (Reg2 now contains the item from the CallData.)
1204 
1205     // The item is item[n].  Increment count[n].
1206     int count_offset = in_bytes(item_count_offset_fn(row));
1207     increment_mdp_data_at(mdp, count_offset);
1208     b(done);
1209     bind(next_test);
1210 
1211     if (test_for_null_also) {
1212       Label found_null;
1213       // Failed the equality check on item[n]...  Test for null.
1214       if (start_row == last_row) {
1215         // The only thing left to do is handle the null case.
1216         if (non_profiled_offset >= 0) {
1217           cbz(reg2, found_null);
1218           // Item did not match any saved item and there is no empty row for it.
1219           // Increment total counter to indicate polymorphic case.
1220           increment_mdp_data_at(mdp, non_profiled_offset);
1221           b(done);
1222           bind(found_null);
1223         } else {
1224           cbnz(reg2, done);
1225         }
1226         break;
1227       }
1228       // Since null is rare, make it be the branch-taken case.
1229       cbz(reg2, found_null);
1230 
1231       // Put all the "Case 3" tests here.
1232       record_item_in_profile_helper(item, mdp, reg2, start_row + 1, done, total_rows,
1233         item_offset_fn, item_count_offset_fn, non_profiled_offset);
1234 
1235       // Found a null.  Keep searching for a matching item,
1236       // but remember that this is an empty (unused) slot.
1237       bind(found_null);
1238     }
1239   }
1240 
1241   // In the fall-through case, we found no matching item, but we
1242   // observed the item[start_row] is NULL.
1243 
1244   // Fill in the item field and increment the count.
1245   int item_offset = in_bytes(item_offset_fn(start_row));
1246   set_mdp_data_at(mdp, item_offset, item);
1247   int count_offset = in_bytes(item_count_offset_fn(start_row));
1248   mov(reg2, DataLayout::counter_increment);
1249   set_mdp_data_at(mdp, count_offset, reg2);
1250   if (start_row > 0) {
1251     b(done);
1252   }
1253 }
1254 
1255 // Example state machine code for three profile rows:
1256 //   // main copy of decision tree, rooted at row[1]
1257 //   if (row[0].rec == rec) { row[0].incr(); goto done; }
1258 //   if (row[0].rec != NULL) {
1259 //     // inner copy of decision tree, rooted at row[1]
1260 //     if (row[1].rec == rec) { row[1].incr(); goto done; }
1261 //     if (row[1].rec != NULL) {
1262 //       // degenerate decision tree, rooted at row[2]
1263 //       if (row[2].rec == rec) { row[2].incr(); goto done; }
1264 //       if (row[2].rec != NULL) { count.incr(); goto done; } // overflow
1265 //       row[2].init(rec); goto done;
1266 //     } else {
1267 //       // remember row[1] is empty
1268 //       if (row[2].rec == rec) { row[2].incr(); goto done; }
1269 //       row[1].init(rec); goto done;
1270 //     }
1271 //   } else {
1272 //     // remember row[0] is empty
1273 //     if (row[1].rec == rec) { row[1].incr(); goto done; }
1274 //     if (row[2].rec == rec) { row[2].incr(); goto done; }
1275 //     row[0].init(rec); goto done;
1276 //   }
1277 //   done:
1278 
1279 void InterpreterMacroAssembler::record_klass_in_profile(Register receiver,
1280                                                         Register mdp, Register reg2,
1281                                                         bool is_virtual_call) {
1282   assert(ProfileInterpreter, "must be profiling");
1283   Label done;
1284 
1285   record_klass_in_profile_helper(receiver, mdp, reg2, 0, done, is_virtual_call);
1286 
1287   bind (done);
1288 }
1289 
1290 void InterpreterMacroAssembler::profile_ret(Register return_bci,
1291                                             Register mdp) {
1292   if (ProfileInterpreter) {
1293     Label profile_continue;
1294     uint row;
1295 
1296     // If no method data exists, go to profile_continue.
1297     test_method_data_pointer(mdp, profile_continue);
1298 
1299     // Update the total ret count.
1300     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1301 
1302     for (row = 0; row < RetData::row_limit(); row++) {
1303       Label next_test;
1304 
1305       // See if return_bci is equal to bci[n]:
1306       test_mdp_data_at(mdp,
1307                        in_bytes(RetData::bci_offset(row)),
1308                        return_bci, noreg,
1309                        next_test);
1310 
1311       // return_bci is equal to bci[n].  Increment the count.
1312       increment_mdp_data_at(mdp, in_bytes(RetData::bci_count_offset(row)));
1313 
1314       // The method data pointer needs to be updated to reflect the new target.
1315       update_mdp_by_offset(mdp,
1316                            in_bytes(RetData::bci_displacement_offset(row)));
1317       b(profile_continue);
1318       bind(next_test);
1319     }
1320 
1321     update_mdp_for_ret(return_bci);
1322 
1323     bind(profile_continue);
1324   }
1325 }
1326 
1327 void InterpreterMacroAssembler::profile_null_seen(Register mdp) {
1328   if (ProfileInterpreter) {
1329     Label profile_continue;
1330 
1331     // If no method data exists, go to profile_continue.
1332     test_method_data_pointer(mdp, profile_continue);
1333 
1334     set_mdp_flag_at(mdp, BitData::null_seen_byte_constant());
1335 
1336     // The method data pointer needs to be updated.
1337     int mdp_delta = in_bytes(BitData::bit_data_size());
1338     if (TypeProfileCasts) {
1339       mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1340     }
1341     update_mdp_by_constant(mdp, mdp_delta);
1342 
1343     bind(profile_continue);
1344   }
1345 }
1346 
1347 void InterpreterMacroAssembler::profile_typecheck_failed(Register mdp) {
1348   if (ProfileInterpreter && TypeProfileCasts) {
1349     Label profile_continue;
1350 
1351     // If no method data exists, go to profile_continue.
1352     test_method_data_pointer(mdp, profile_continue);
1353 
1354     int count_offset = in_bytes(CounterData::count_offset());
1355     // Back up the address, since we have already bumped the mdp.
1356     count_offset -= in_bytes(VirtualCallData::virtual_call_data_size());
1357 
1358     // *Decrement* the counter.  We expect to see zero or small negatives.
1359     increment_mdp_data_at(mdp, count_offset, true);
1360 
1361     bind (profile_continue);
1362   }
1363 }
1364 
1365 void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2) {
1366   if (ProfileInterpreter) {
1367     Label profile_continue;
1368 
1369     // If no method data exists, go to profile_continue.
1370     test_method_data_pointer(mdp, profile_continue);
1371 
1372     // The method data pointer needs to be updated.
1373     int mdp_delta = in_bytes(BitData::bit_data_size());
1374     if (TypeProfileCasts) {
1375       mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1376 
1377       // Record the object type.
1378       record_klass_in_profile(klass, mdp, reg2, false);
1379     }
1380     update_mdp_by_constant(mdp, mdp_delta);
1381 
1382     bind(profile_continue);
1383   }
1384 }
1385 
1386 void InterpreterMacroAssembler::profile_switch_default(Register mdp) {
1387   if (ProfileInterpreter) {
1388     Label profile_continue;
1389 
1390     // If no method data exists, go to profile_continue.
1391     test_method_data_pointer(mdp, profile_continue);
1392 
1393     // Update the default case count
1394     increment_mdp_data_at(mdp,
1395                           in_bytes(MultiBranchData::default_count_offset()));
1396 
1397     // The method data pointer needs to be updated.
1398     update_mdp_by_offset(mdp,
1399                          in_bytes(MultiBranchData::
1400                                   default_displacement_offset()));
1401 
1402     bind(profile_continue);
1403   }
1404 }
1405 
1406 void InterpreterMacroAssembler::profile_switch_case(Register index,
1407                                                     Register mdp,
1408                                                     Register reg2) {
1409   if (ProfileInterpreter) {
1410     Label profile_continue;
1411 
1412     // If no method data exists, go to profile_continue.
1413     test_method_data_pointer(mdp, profile_continue);
1414 
1415     // Build the base (index * per_case_size_in_bytes()) +
1416     // case_array_offset_in_bytes()
1417     movw(reg2, in_bytes(MultiBranchData::per_case_size()));
1418     movw(rscratch1, in_bytes(MultiBranchData::case_array_offset()));
1419     Assembler::maddw(index, index, reg2, rscratch1);
1420 
1421     // Update the case count
1422     increment_mdp_data_at(mdp,
1423                           index,
1424                           in_bytes(MultiBranchData::relative_count_offset()));
1425 
1426     // The method data pointer needs to be updated.
1427     update_mdp_by_offset(mdp,
1428                          index,
1429                          in_bytes(MultiBranchData::
1430                                   relative_displacement_offset()));
1431 
1432     bind(profile_continue);
1433   }
1434 }
1435 
1436 void InterpreterMacroAssembler::verify_oop(Register reg, TosState state) {
1437   if (state == atos) {
1438     MacroAssembler::verify_oop(reg);
1439   }
1440 }
1441 
1442 void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) { ; }
1443 
1444 
1445 void InterpreterMacroAssembler::notify_method_entry() {
1446   // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
1447   // track stack depth.  If it is possible to enter interp_only_mode we add
1448   // the code to check if the event should be sent.
1449   if (JvmtiExport::can_post_interpreter_events()) {
1450     Label L;
1451     ldrw(r3, Address(rthread, JavaThread::interp_only_mode_offset()));
1452     cbzw(r3, L);
1453     call_VM(noreg, CAST_FROM_FN_PTR(address,
1454                                     InterpreterRuntime::post_method_entry));
1455     bind(L);
1456   }
1457 
1458   {
1459     SkipIfEqual skip(this, &DTraceMethodProbes, false);
1460     get_method(c_rarg1);
1461     call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry),
1462                  rthread, c_rarg1);
1463   }
1464 
1465   // RedefineClasses() tracing support for obsolete method entry
1466   if (log_is_enabled(Trace, redefine, class, obsolete)) {
1467     get_method(c_rarg1);
1468     call_VM_leaf(
1469       CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry),
1470       rthread, c_rarg1);
1471   }
1472 
1473  }
1474 
1475 
1476 void InterpreterMacroAssembler::notify_method_exit(
1477     TosState state, NotifyMethodExitMode mode) {
1478   // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
1479   // track stack depth.  If it is possible to enter interp_only_mode we add
1480   // the code to check if the event should be sent.
1481   if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) {
1482     Label L;
1483     // Note: frame::interpreter_frame_result has a dependency on how the
1484     // method result is saved across the call to post_method_exit. If this
1485     // is changed then the interpreter_frame_result implementation will
1486     // need to be updated too.
1487 
1488     // template interpreter will leave the result on the top of the stack.
1489     push(state);
1490     ldrw(r3, Address(rthread, JavaThread::interp_only_mode_offset()));
1491     cbz(r3, L);
1492     call_VM(noreg,
1493             CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit));
1494     bind(L);
1495     pop(state);
1496   }
1497 
1498   {
1499     SkipIfEqual skip(this, &DTraceMethodProbes, false);
1500     push(state);
1501     get_method(c_rarg1);
1502     call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),
1503                  rthread, c_rarg1);
1504     pop(state);
1505   }
1506 }
1507 
1508 
1509 // Jump if ((*counter_addr += increment) & mask) satisfies the condition.
1510 void InterpreterMacroAssembler::increment_mask_and_jump(Address counter_addr,
1511                                                         int increment, Address mask,
1512                                                         Register scratch, Register scratch2,
1513                                                         bool preloaded, Condition cond,
1514                                                         Label* where) {
1515   if (!preloaded) {
1516     ldrw(scratch, counter_addr);
1517   }
1518   add(scratch, scratch, increment);
1519   strw(scratch, counter_addr);
1520   ldrw(scratch2, mask);
1521   ands(scratch, scratch, scratch2);
1522   br(cond, *where);
1523 }
1524 
1525 void InterpreterMacroAssembler::call_VM_leaf_base(address entry_point,
1526                                                   int number_of_arguments) {
1527   // interpreter specific
1528   //
1529   // Note: No need to save/restore rbcp & rlocals pointer since these
1530   //       are callee saved registers and no blocking/ GC can happen
1531   //       in leaf calls.
1532 #ifdef ASSERT
1533   {
1534     Label L;
1535     ldr(rscratch1, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize));
1536     cbz(rscratch1, L);
1537     stop("InterpreterMacroAssembler::call_VM_leaf_base:"
1538          " last_sp != NULL");
1539     bind(L);
1540   }
1541 #endif /* ASSERT */
1542   // super call
1543   MacroAssembler::call_VM_leaf_base(entry_point, number_of_arguments);
1544 }
1545 
1546 void InterpreterMacroAssembler::call_VM_base(Register oop_result,
1547                                              Register java_thread,
1548                                              Register last_java_sp,
1549                                              address  entry_point,
1550                                              int      number_of_arguments,
1551                                              bool     check_exceptions) {
1552   // interpreter specific
1553   //
1554   // Note: Could avoid restoring locals ptr (callee saved) - however doesn't
1555   //       really make a difference for these runtime calls, since they are
1556   //       slow anyway. Btw., bcp must be saved/restored since it may change
1557   //       due to GC.
1558   // assert(java_thread == noreg , "not expecting a precomputed java thread");
1559   save_bcp();
1560 #ifdef ASSERT
1561   {
1562     Label L;
1563     ldr(rscratch1, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize));
1564     cbz(rscratch1, L);
1565     stop("InterpreterMacroAssembler::call_VM_leaf_base:"
1566          " last_sp != NULL");
1567     bind(L);
1568   }
1569 #endif /* ASSERT */
1570   // super call
1571   MacroAssembler::call_VM_base(oop_result, noreg, last_java_sp,
1572                                entry_point, number_of_arguments,
1573                      check_exceptions);
1574 // interpreter specific
1575   restore_bcp();
1576   restore_locals();
1577 }
1578 
1579 void InterpreterMacroAssembler::profile_obj_type(Register obj, const Address& mdo_addr) {
1580   Label update, next, none;
1581 
1582   verify_oop(obj);
1583 
1584   cbnz(obj, update);
1585   orptr(mdo_addr, TypeEntries::null_seen);
1586   b(next);
1587 
1588   bind(update);
1589   load_klass(obj, obj);
1590 
1591   ldr(rscratch1, mdo_addr);
1592   eor(obj, obj, rscratch1);
1593   tst(obj, TypeEntries::type_klass_mask);
1594   br(Assembler::EQ, next); // klass seen before, nothing to
1595                            // do. The unknown bit may have been
1596                            // set already but no need to check.
1597 
1598   tbnz(obj, exact_log2(TypeEntries::type_unknown), next);
1599   // already unknown. Nothing to do anymore.
1600 
1601   ldr(rscratch1, mdo_addr);
1602   cbz(rscratch1, none);
1603   cmp(rscratch1, TypeEntries::null_seen);
1604   br(Assembler::EQ, none);
1605   // There is a chance that the checks above (re-reading profiling
1606   // data from memory) fail if another thread has just set the
1607   // profiling to this obj's klass
1608   ldr(rscratch1, mdo_addr);
1609   eor(obj, obj, rscratch1);
1610   tst(obj, TypeEntries::type_klass_mask);
1611   br(Assembler::EQ, next);
1612 
1613   // different than before. Cannot keep accurate profile.
1614   orptr(mdo_addr, TypeEntries::type_unknown);
1615   b(next);
1616 
1617   bind(none);
1618   // first time here. Set profile type.
1619   str(obj, mdo_addr);
1620 
1621   bind(next);
1622 }
1623 
1624 void InterpreterMacroAssembler::profile_arguments_type(Register mdp, Register callee, Register tmp, bool is_virtual) {
1625   if (!ProfileInterpreter) {
1626     return;
1627   }
1628 
1629   if (MethodData::profile_arguments() || MethodData::profile_return()) {
1630     Label profile_continue;
1631 
1632     test_method_data_pointer(mdp, profile_continue);
1633 
1634     int off_to_start = is_virtual ? in_bytes(VirtualCallData::virtual_call_data_size()) : in_bytes(CounterData::counter_data_size());
1635 
1636     ldrb(rscratch1, Address(mdp, in_bytes(DataLayout::tag_offset()) - off_to_start));
1637     cmp(rscratch1, is_virtual ? DataLayout::virtual_call_type_data_tag : DataLayout::call_type_data_tag);
1638     br(Assembler::NE, profile_continue);
1639 
1640     if (MethodData::profile_arguments()) {
1641       Label done;
1642       int off_to_args = in_bytes(TypeEntriesAtCall::args_data_offset());
1643 
1644       for (int i = 0; i < TypeProfileArgsLimit; i++) {
1645         if (i > 0 || MethodData::profile_return()) {
1646           // If return value type is profiled we may have no argument to profile
1647           ldr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())));
1648           sub(tmp, tmp, i*TypeStackSlotEntries::per_arg_count());
1649           cmp(tmp, TypeStackSlotEntries::per_arg_count());
1650           add(rscratch1, mdp, off_to_args);
1651           br(Assembler::LT, done);
1652         }
1653         ldr(tmp, Address(callee, Method::const_offset()));
1654         load_unsigned_short(tmp, Address(tmp, ConstMethod::size_of_parameters_offset()));
1655         // stack offset o (zero based) from the start of the argument
1656         // list, for n arguments translates into offset n - o - 1 from
1657         // the end of the argument list
1658         ldr(rscratch1, Address(mdp, in_bytes(TypeEntriesAtCall::stack_slot_offset(i))));
1659         sub(tmp, tmp, rscratch1);
1660         sub(tmp, tmp, 1);
1661         Address arg_addr = argument_address(tmp);
1662         ldr(tmp, arg_addr);
1663 
1664         Address mdo_arg_addr(mdp, in_bytes(TypeEntriesAtCall::argument_type_offset(i)));
1665         profile_obj_type(tmp, mdo_arg_addr);
1666 
1667         int to_add = in_bytes(TypeStackSlotEntries::per_arg_size());
1668         off_to_args += to_add;
1669       }
1670 
1671       if (MethodData::profile_return()) {
1672         ldr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())));
1673         sub(tmp, tmp, TypeProfileArgsLimit*TypeStackSlotEntries::per_arg_count());
1674       }
1675 
1676       add(rscratch1, mdp, off_to_args);
1677       bind(done);
1678       mov(mdp, rscratch1);
1679 
1680       if (MethodData::profile_return()) {
1681         // We're right after the type profile for the last
1682         // argument. tmp is the number of cells left in the
1683         // CallTypeData/VirtualCallTypeData to reach its end. Non null
1684         // if there's a return to profile.
1685         assert(ReturnTypeEntry::static_cell_count() < TypeStackSlotEntries::per_arg_count(), "can't move past ret type");
1686         add(mdp, mdp, tmp, LSL, exact_log2(DataLayout::cell_size));
1687       }
1688       str(mdp, Address(rfp, frame::interpreter_frame_mdp_offset * wordSize));
1689     } else {
1690       assert(MethodData::profile_return(), "either profile call args or call ret");
1691       update_mdp_by_constant(mdp, in_bytes(TypeEntriesAtCall::return_only_size()));
1692     }
1693 
1694     // mdp points right after the end of the
1695     // CallTypeData/VirtualCallTypeData, right after the cells for the
1696     // return value type if there's one
1697 
1698     bind(profile_continue);
1699   }
1700 }
1701 
1702 void InterpreterMacroAssembler::profile_return_type(Register mdp, Register ret, Register tmp) {
1703   assert_different_registers(mdp, ret, tmp, rbcp);
1704   if (ProfileInterpreter && MethodData::profile_return()) {
1705     Label profile_continue, done;
1706 
1707     test_method_data_pointer(mdp, profile_continue);
1708 
1709     if (MethodData::profile_return_jsr292_only()) {
1710       assert(Method::intrinsic_id_size_in_bytes() == 2, "assuming Method::_intrinsic_id is u2");
1711 
1712       // If we don't profile all invoke bytecodes we must make sure
1713       // it's a bytecode we indeed profile. We can't go back to the
1714       // begining of the ProfileData we intend to update to check its
1715       // type because we're right after it and we don't known its
1716       // length
1717       Label do_profile;
1718       ldrb(rscratch1, Address(rbcp, 0));
1719       cmp(rscratch1, Bytecodes::_invokedynamic);
1720       br(Assembler::EQ, do_profile);
1721       cmp(rscratch1, Bytecodes::_invokehandle);
1722       br(Assembler::EQ, do_profile);
1723       get_method(tmp);
1724       ldrh(rscratch1, Address(tmp, Method::intrinsic_id_offset_in_bytes()));
1725       cmp(rscratch1, vmIntrinsics::_compiledLambdaForm);
1726       br(Assembler::NE, profile_continue);
1727 
1728       bind(do_profile);
1729     }
1730 
1731     Address mdo_ret_addr(mdp, -in_bytes(ReturnTypeEntry::size()));
1732     mov(tmp, ret);
1733     profile_obj_type(tmp, mdo_ret_addr);
1734 
1735     bind(profile_continue);
1736   }
1737 }
1738 
1739 void InterpreterMacroAssembler::profile_parameters_type(Register mdp, Register tmp1, Register tmp2) {
1740   if (ProfileInterpreter && MethodData::profile_parameters()) {
1741     Label profile_continue, done;
1742 
1743     test_method_data_pointer(mdp, profile_continue);
1744 
1745     // Load the offset of the area within the MDO used for
1746     // parameters. If it's negative we're not profiling any parameters
1747     ldr(tmp1, Address(mdp, in_bytes(MethodData::parameters_type_data_di_offset()) - in_bytes(MethodData::data_offset())));
1748     cmp(tmp1, 0u);
1749     br(Assembler::LT, profile_continue);
1750 
1751     // Compute a pointer to the area for parameters from the offset
1752     // and move the pointer to the slot for the last
1753     // parameters. Collect profiling from last parameter down.
1754     // mdo start + parameters offset + array length - 1
1755     add(mdp, mdp, tmp1);
1756     ldr(tmp1, Address(mdp, ArrayData::array_len_offset()));
1757     sub(tmp1, tmp1, TypeStackSlotEntries::per_arg_count());
1758 
1759     Label loop;
1760     bind(loop);
1761 
1762     int off_base = in_bytes(ParametersTypeData::stack_slot_offset(0));
1763     int type_base = in_bytes(ParametersTypeData::type_offset(0));
1764     int per_arg_scale = exact_log2(DataLayout::cell_size);
1765     add(rscratch1, mdp, off_base);
1766     add(rscratch2, mdp, type_base);
1767 
1768     Address arg_off(rscratch1, tmp1, Address::lsl(per_arg_scale));
1769     Address arg_type(rscratch2, tmp1, Address::lsl(per_arg_scale));
1770 
1771     // load offset on the stack from the slot for this parameter
1772     ldr(tmp2, arg_off);
1773     neg(tmp2, tmp2);
1774     // read the parameter from the local area
1775     ldr(tmp2, Address(rlocals, tmp2, Address::lsl(Interpreter::logStackElementSize)));
1776 
1777     // profile the parameter
1778     profile_obj_type(tmp2, arg_type);
1779 
1780     // go to next parameter
1781     subs(tmp1, tmp1, TypeStackSlotEntries::per_arg_count());
1782     br(Assembler::GE, loop);
1783 
1784     bind(profile_continue);
1785   }
1786 }