1 /*
   2  * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "compiler/compiler_globals.hpp"
  27 #include "interp_masm_x86.hpp"
  28 #include "interpreter/interpreter.hpp"
  29 #include "interpreter/interpreterRuntime.hpp"
  30 #include "logging/log.hpp"
  31 #include "oops/arrayOop.hpp"
  32 #include "oops/markWord.hpp"
  33 #include "oops/methodData.hpp"
  34 #include "oops/method.hpp"
  35 #include "oops/inlineKlass.hpp"
  36 #include "prims/jvmtiExport.hpp"
  37 #include "prims/jvmtiThreadState.hpp"
  38 #include "runtime/basicLock.hpp"
  39 #include "runtime/frame.inline.hpp"
  40 #include "runtime/safepointMechanism.hpp"
  41 #include "runtime/sharedRuntime.hpp"
  42 #include "runtime/thread.inline.hpp"
  43 #include "utilities/powerOfTwo.hpp"
  44 
  45 // Implementation of InterpreterMacroAssembler
  46 
  47 void InterpreterMacroAssembler::jump_to_entry(address entry) {
  48   assert(entry, "Entry must have been generated by now");
  49   jump(RuntimeAddress(entry));
  50 }
  51 
  52 void InterpreterMacroAssembler::profile_obj_type(Register obj, const Address& mdo_addr) {
  53   Label update, next, none;
  54 
  55   interp_verify_oop(obj, atos);
  56 
  57   testptr(obj, obj);
  58   jccb(Assembler::notZero, update);
  59   orptr(mdo_addr, TypeEntries::null_seen);
  60   jmpb(next);
  61 
  62   bind(update);
  63   Register tmp_load_klass = LP64_ONLY(rscratch1) NOT_LP64(noreg);
  64   load_klass(obj, obj, tmp_load_klass);
  65 
  66   xorptr(obj, mdo_addr);
  67   testptr(obj, TypeEntries::type_klass_mask);
  68   jccb(Assembler::zero, next); // klass seen before, nothing to
  69                                // do. The unknown bit may have been
  70                                // set already but no need to check.
  71 
  72   testptr(obj, TypeEntries::type_unknown);
  73   jccb(Assembler::notZero, next); // already unknown. Nothing to do anymore.
  74 
  75   cmpptr(mdo_addr, 0);
  76   jccb(Assembler::equal, none);
  77   cmpptr(mdo_addr, TypeEntries::null_seen);
  78   jccb(Assembler::equal, none);
  79   // There is a chance that the checks above (re-reading profiling
  80   // data from memory) fail if another thread has just set the
  81   // profiling to this obj's klass
  82   xorptr(obj, mdo_addr);
  83   testptr(obj, TypeEntries::type_klass_mask);
  84   jccb(Assembler::zero, next);
  85 
  86   // different than before. Cannot keep accurate profile.
  87   orptr(mdo_addr, TypeEntries::type_unknown);
  88   jmpb(next);
  89 
  90   bind(none);
  91   // first time here. Set profile type.
  92   movptr(mdo_addr, obj);
  93 
  94   bind(next);
  95 }
  96 
  97 void InterpreterMacroAssembler::profile_arguments_type(Register mdp, Register callee, Register tmp, bool is_virtual) {
  98   if (!ProfileInterpreter) {
  99     return;
 100   }
 101 
 102   if (MethodData::profile_arguments() || MethodData::profile_return()) {
 103     Label profile_continue;
 104 
 105     test_method_data_pointer(mdp, profile_continue);
 106 
 107     int off_to_start = is_virtual ? in_bytes(VirtualCallData::virtual_call_data_size()) : in_bytes(CounterData::counter_data_size());
 108 
 109     cmpb(Address(mdp, in_bytes(DataLayout::tag_offset()) - off_to_start), is_virtual ? DataLayout::virtual_call_type_data_tag : DataLayout::call_type_data_tag);
 110     jcc(Assembler::notEqual, profile_continue);
 111 
 112     if (MethodData::profile_arguments()) {
 113       Label done;
 114       int off_to_args = in_bytes(TypeEntriesAtCall::args_data_offset());
 115       addptr(mdp, off_to_args);
 116 
 117       for (int i = 0; i < TypeProfileArgsLimit; i++) {
 118         if (i > 0 || MethodData::profile_return()) {
 119           // If return value type is profiled we may have no argument to profile
 120           movptr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args));
 121           subl(tmp, i*TypeStackSlotEntries::per_arg_count());
 122           cmpl(tmp, TypeStackSlotEntries::per_arg_count());
 123           jcc(Assembler::less, done);
 124         }
 125         movptr(tmp, Address(callee, Method::const_offset()));
 126         load_unsigned_short(tmp, Address(tmp, ConstMethod::size_of_parameters_offset()));
 127         // stack offset o (zero based) from the start of the argument
 128         // list, for n arguments translates into offset n - o - 1 from
 129         // the end of the argument list
 130         subptr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::stack_slot_offset(i))-off_to_args));
 131         subl(tmp, 1);
 132         Address arg_addr = argument_address(tmp);
 133         movptr(tmp, arg_addr);
 134 
 135         Address mdo_arg_addr(mdp, in_bytes(TypeEntriesAtCall::argument_type_offset(i))-off_to_args);
 136         profile_obj_type(tmp, mdo_arg_addr);
 137 
 138         int to_add = in_bytes(TypeStackSlotEntries::per_arg_size());
 139         addptr(mdp, to_add);
 140         off_to_args += to_add;
 141       }
 142 
 143       if (MethodData::profile_return()) {
 144         movptr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args));
 145         subl(tmp, TypeProfileArgsLimit*TypeStackSlotEntries::per_arg_count());
 146       }
 147 
 148       bind(done);
 149 
 150       if (MethodData::profile_return()) {
 151         // We're right after the type profile for the last
 152         // argument. tmp is the number of cells left in the
 153         // CallTypeData/VirtualCallTypeData to reach its end. Non null
 154         // if there's a return to profile.
 155         assert(SingleTypeEntry::static_cell_count() < TypeStackSlotEntries::per_arg_count(), "can't move past ret type");
 156         shll(tmp, log2i_exact((int)DataLayout::cell_size));
 157         addptr(mdp, tmp);
 158       }
 159       movptr(Address(rbp, frame::interpreter_frame_mdp_offset * wordSize), mdp);
 160     } else {
 161       assert(MethodData::profile_return(), "either profile call args or call ret");
 162       update_mdp_by_constant(mdp, in_bytes(TypeEntriesAtCall::return_only_size()));
 163     }
 164 
 165     // mdp points right after the end of the
 166     // CallTypeData/VirtualCallTypeData, right after the cells for the
 167     // return value type if there's one
 168 
 169     bind(profile_continue);
 170   }
 171 }
 172 
 173 void InterpreterMacroAssembler::profile_return_type(Register mdp, Register ret, Register tmp) {
 174   assert_different_registers(mdp, ret, tmp, _bcp_register);
 175   if (ProfileInterpreter && MethodData::profile_return()) {
 176     Label profile_continue;
 177 
 178     test_method_data_pointer(mdp, profile_continue);
 179 
 180     if (MethodData::profile_return_jsr292_only()) {
 181       assert(Method::intrinsic_id_size_in_bytes() == 2, "assuming Method::_intrinsic_id is u2");
 182 
 183       // If we don't profile all invoke bytecodes we must make sure
 184       // it's a bytecode we indeed profile. We can't go back to the
 185       // begining of the ProfileData we intend to update to check its
 186       // type because we're right after it and we don't known its
 187       // length
 188       Label do_profile;
 189       cmpb(Address(_bcp_register, 0), Bytecodes::_invokedynamic);
 190       jcc(Assembler::equal, do_profile);
 191       cmpb(Address(_bcp_register, 0), Bytecodes::_invokehandle);
 192       jcc(Assembler::equal, do_profile);
 193       get_method(tmp);
 194       cmpw(Address(tmp, Method::intrinsic_id_offset_in_bytes()), static_cast<int>(vmIntrinsics::_compiledLambdaForm));
 195       jcc(Assembler::notEqual, profile_continue);
 196 
 197       bind(do_profile);
 198     }
 199 
 200     Address mdo_ret_addr(mdp, -in_bytes(SingleTypeEntry::size()));
 201     mov(tmp, ret);
 202     profile_obj_type(tmp, mdo_ret_addr);
 203 
 204     bind(profile_continue);
 205   }
 206 }
 207 
 208 void InterpreterMacroAssembler::profile_parameters_type(Register mdp, Register tmp1, Register tmp2) {
 209   if (ProfileInterpreter && MethodData::profile_parameters()) {
 210     Label profile_continue;
 211 
 212     test_method_data_pointer(mdp, profile_continue);
 213 
 214     // Load the offset of the area within the MDO used for
 215     // parameters. If it's negative we're not profiling any parameters
 216     movl(tmp1, Address(mdp, in_bytes(MethodData::parameters_type_data_di_offset()) - in_bytes(MethodData::data_offset())));
 217     testl(tmp1, tmp1);
 218     jcc(Assembler::negative, profile_continue);
 219 
 220     // Compute a pointer to the area for parameters from the offset
 221     // and move the pointer to the slot for the last
 222     // parameters. Collect profiling from last parameter down.
 223     // mdo start + parameters offset + array length - 1
 224     addptr(mdp, tmp1);
 225     movptr(tmp1, Address(mdp, ArrayData::array_len_offset()));
 226     decrement(tmp1, TypeStackSlotEntries::per_arg_count());
 227 
 228     Label loop;
 229     bind(loop);
 230 
 231     int off_base = in_bytes(ParametersTypeData::stack_slot_offset(0));
 232     int type_base = in_bytes(ParametersTypeData::type_offset(0));
 233     Address::ScaleFactor per_arg_scale = Address::times(DataLayout::cell_size);
 234     Address arg_off(mdp, tmp1, per_arg_scale, off_base);
 235     Address arg_type(mdp, tmp1, per_arg_scale, type_base);
 236 
 237     // load offset on the stack from the slot for this parameter
 238     movptr(tmp2, arg_off);
 239     negptr(tmp2);
 240     // read the parameter from the local area
 241     movptr(tmp2, Address(_locals_register, tmp2, Interpreter::stackElementScale()));
 242 
 243     // profile the parameter
 244     profile_obj_type(tmp2, arg_type);
 245 
 246     // go to next parameter
 247     decrement(tmp1, TypeStackSlotEntries::per_arg_count());
 248     jcc(Assembler::positive, loop);
 249 
 250     bind(profile_continue);
 251   }
 252 }
 253 
 254 void InterpreterMacroAssembler::call_VM_leaf_base(address entry_point,
 255                                                   int number_of_arguments) {
 256   // interpreter specific
 257   //
 258   // Note: No need to save/restore bcp & locals registers
 259   //       since these are callee saved registers and no blocking/
 260   //       GC can happen in leaf calls.
 261   // Further Note: DO NOT save/restore bcp/locals. If a caller has
 262   // already saved them so that it can use rsi/rdi as temporaries
 263   // then a save/restore here will DESTROY the copy the caller
 264   // saved! There used to be a save_bcp() that only happened in
 265   // the ASSERT path (no restore_bcp). Which caused bizarre failures
 266   // when jvm built with ASSERTs.
 267 #ifdef ASSERT
 268   {
 269     Label L;
 270     cmpptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
 271     jcc(Assembler::equal, L);
 272     stop("InterpreterMacroAssembler::call_VM_leaf_base:"
 273          " last_sp != NULL");
 274     bind(L);
 275   }
 276 #endif
 277   // super call
 278   MacroAssembler::call_VM_leaf_base(entry_point, number_of_arguments);
 279   // interpreter specific
 280   // LP64: Used to ASSERT that r13/r14 were equal to frame's bcp/locals
 281   // but since they may not have been saved (and we don't want to
 282   // save them here (see note above) the assert is invalid.
 283 }
 284 
 285 void InterpreterMacroAssembler::call_VM_base(Register oop_result,
 286                                              Register java_thread,
 287                                              Register last_java_sp,
 288                                              address  entry_point,
 289                                              int      number_of_arguments,
 290                                              bool     check_exceptions) {
 291   // interpreter specific
 292   //
 293   // Note: Could avoid restoring locals ptr (callee saved) - however doesn't
 294   //       really make a difference for these runtime calls, since they are
 295   //       slow anyway. Btw., bcp must be saved/restored since it may change
 296   //       due to GC.
 297   NOT_LP64(assert(java_thread == noreg , "not expecting a precomputed java thread");)
 298   save_bcp();
 299 #ifdef ASSERT
 300   {
 301     Label L;
 302     cmpptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
 303     jcc(Assembler::equal, L);
 304     stop("InterpreterMacroAssembler::call_VM_base:"
 305          " last_sp != NULL");
 306     bind(L);
 307   }
 308 #endif /* ASSERT */
 309   // super call
 310   MacroAssembler::call_VM_base(oop_result, noreg, last_java_sp,
 311                                entry_point, number_of_arguments,
 312                                check_exceptions);
 313   // interpreter specific
 314   restore_bcp();
 315   restore_locals();
 316 }
 317 
 318 void InterpreterMacroAssembler::check_and_handle_popframe(Register java_thread) {
 319   if (JvmtiExport::can_pop_frame()) {
 320     Label L;
 321     // Initiate popframe handling only if it is not already being
 322     // processed.  If the flag has the popframe_processing bit set, it
 323     // means that this code is called *during* popframe handling - we
 324     // don't want to reenter.
 325     // This method is only called just after the call into the vm in
 326     // call_VM_base, so the arg registers are available.
 327     Register pop_cond = NOT_LP64(java_thread) // Not clear if any other register is available on 32 bit
 328                         LP64_ONLY(c_rarg0);
 329     movl(pop_cond, Address(java_thread, JavaThread::popframe_condition_offset()));
 330     testl(pop_cond, JavaThread::popframe_pending_bit);
 331     jcc(Assembler::zero, L);
 332     testl(pop_cond, JavaThread::popframe_processing_bit);
 333     jcc(Assembler::notZero, L);
 334     // Call Interpreter::remove_activation_preserving_args_entry() to get the
 335     // address of the same-named entrypoint in the generated interpreter code.
 336     call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_preserving_args_entry));
 337     jmp(rax);
 338     bind(L);
 339     NOT_LP64(get_thread(java_thread);)
 340   }
 341 }
 342 
 343 void InterpreterMacroAssembler::load_earlyret_value(TosState state) {
 344   Register thread = LP64_ONLY(r15_thread) NOT_LP64(rcx);
 345   NOT_LP64(get_thread(thread);)
 346   movptr(rcx, Address(thread, JavaThread::jvmti_thread_state_offset()));
 347   const Address tos_addr(rcx, JvmtiThreadState::earlyret_tos_offset());
 348   const Address oop_addr(rcx, JvmtiThreadState::earlyret_oop_offset());
 349   const Address val_addr(rcx, JvmtiThreadState::earlyret_value_offset());
 350 #ifdef _LP64
 351   switch (state) {
 352     case atos: movptr(rax, oop_addr);
 353                movptr(oop_addr, (int32_t)NULL_WORD);
 354                interp_verify_oop(rax, state);         break;
 355     case ltos: movptr(rax, val_addr);                 break;
 356     case btos:                                   // fall through
 357     case ztos:                                   // fall through
 358     case ctos:                                   // fall through
 359     case stos:                                   // fall through
 360     case itos: movl(rax, val_addr);                 break;
 361     case ftos: load_float(val_addr);                break;
 362     case dtos: load_double(val_addr);               break;
 363     case vtos: /* nothing to do */                  break;
 364     default  : ShouldNotReachHere();
 365   }
 366   // Clean up tos value in the thread object
 367   movl(tos_addr,  (int) ilgl);
 368   movl(val_addr,  (int32_t) NULL_WORD);
 369 #else
 370   const Address val_addr1(rcx, JvmtiThreadState::earlyret_value_offset()
 371                              + in_ByteSize(wordSize));
 372   switch (state) {
 373     case atos: movptr(rax, oop_addr);
 374                movptr(oop_addr, NULL_WORD);
 375                interp_verify_oop(rax, state);         break;
 376     case ltos:
 377                movl(rdx, val_addr1);               // fall through
 378     case btos:                                     // fall through
 379     case ztos:                                     // fall through
 380     case ctos:                                     // fall through
 381     case stos:                                     // fall through
 382     case itos: movl(rax, val_addr);                   break;
 383     case ftos: load_float(val_addr);                  break;
 384     case dtos: load_double(val_addr);                 break;
 385     case vtos: /* nothing to do */                    break;
 386     default  : ShouldNotReachHere();
 387   }
 388 #endif // _LP64
 389   // Clean up tos value in the thread object
 390   movl(tos_addr,  (int32_t) ilgl);
 391   movptr(val_addr,  NULL_WORD);
 392   NOT_LP64(movptr(val_addr1, NULL_WORD);)
 393 }
 394 
 395 
 396 void InterpreterMacroAssembler::check_and_handle_earlyret(Register java_thread) {
 397   if (JvmtiExport::can_force_early_return()) {
 398     Label L;
 399     Register tmp = LP64_ONLY(c_rarg0) NOT_LP64(java_thread);
 400     Register rthread = LP64_ONLY(r15_thread) NOT_LP64(java_thread);
 401 
 402     movptr(tmp, Address(rthread, JavaThread::jvmti_thread_state_offset()));
 403     testptr(tmp, tmp);
 404     jcc(Assembler::zero, L); // if (thread->jvmti_thread_state() == NULL) exit;
 405 
 406     // Initiate earlyret handling only if it is not already being processed.
 407     // If the flag has the earlyret_processing bit set, it means that this code
 408     // is called *during* earlyret handling - we don't want to reenter.
 409     movl(tmp, Address(tmp, JvmtiThreadState::earlyret_state_offset()));
 410     cmpl(tmp, JvmtiThreadState::earlyret_pending);
 411     jcc(Assembler::notEqual, L);
 412 
 413     // Call Interpreter::remove_activation_early_entry() to get the address of the
 414     // same-named entrypoint in the generated interpreter code.
 415     NOT_LP64(get_thread(java_thread);)
 416     movptr(tmp, Address(rthread, JavaThread::jvmti_thread_state_offset()));
 417 #ifdef _LP64
 418     movl(tmp, Address(tmp, JvmtiThreadState::earlyret_tos_offset()));
 419     call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry), tmp);
 420 #else
 421     pushl(Address(tmp, JvmtiThreadState::earlyret_tos_offset()));
 422     call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry), 1);
 423 #endif // _LP64
 424     jmp(rax);
 425     bind(L);
 426     NOT_LP64(get_thread(java_thread);)
 427   }
 428 }
 429 
 430 void InterpreterMacroAssembler::get_unsigned_2_byte_index_at_bcp(Register reg, int bcp_offset) {
 431   assert(bcp_offset >= 0, "bcp is still pointing to start of bytecode");
 432   load_unsigned_short(reg, Address(_bcp_register, bcp_offset));
 433   bswapl(reg);
 434   shrl(reg, 16);
 435 }
 436 
 437 void InterpreterMacroAssembler::get_cache_index_at_bcp(Register index,
 438                                                        int bcp_offset,
 439                                                        size_t index_size) {
 440   assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");
 441   if (index_size == sizeof(u2)) {
 442     load_unsigned_short(index, Address(_bcp_register, bcp_offset));
 443   } else if (index_size == sizeof(u4)) {
 444     movl(index, Address(_bcp_register, bcp_offset));
 445     // Check if the secondary index definition is still ~x, otherwise
 446     // we have to change the following assembler code to calculate the
 447     // plain index.
 448     assert(ConstantPool::decode_invokedynamic_index(~123) == 123, "else change next line");
 449     notl(index);  // convert to plain index
 450   } else if (index_size == sizeof(u1)) {
 451     load_unsigned_byte(index, Address(_bcp_register, bcp_offset));
 452   } else {
 453     ShouldNotReachHere();
 454   }
 455 }
 456 
 457 void InterpreterMacroAssembler::get_cache_and_index_at_bcp(Register cache,
 458                                                            Register index,
 459                                                            int bcp_offset,
 460                                                            size_t index_size) {
 461   assert_different_registers(cache, index);
 462   get_cache_index_at_bcp(index, bcp_offset, index_size);
 463   movptr(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize));
 464   assert(sizeof(ConstantPoolCacheEntry) == 4 * wordSize, "adjust code below");
 465   // convert from field index to ConstantPoolCacheEntry index
 466   assert(exact_log2(in_words(ConstantPoolCacheEntry::size())) == 2, "else change next line");
 467   shll(index, 2);
 468 }
 469 
 470 void InterpreterMacroAssembler::get_cache_and_index_and_bytecode_at_bcp(Register cache,
 471                                                                         Register index,
 472                                                                         Register bytecode,
 473                                                                         int byte_no,
 474                                                                         int bcp_offset,
 475                                                                         size_t index_size) {
 476   get_cache_and_index_at_bcp(cache, index, bcp_offset, index_size);
 477   // We use a 32-bit load here since the layout of 64-bit words on
 478   // little-endian machines allow us that.
 479   movl(bytecode, Address(cache, index, Address::times_ptr, ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::indices_offset()));
 480   const int shift_count = (1 + byte_no) * BitsPerByte;
 481   assert((byte_no == TemplateTable::f1_byte && shift_count == ConstantPoolCacheEntry::bytecode_1_shift) ||
 482          (byte_no == TemplateTable::f2_byte && shift_count == ConstantPoolCacheEntry::bytecode_2_shift),
 483          "correct shift count");
 484   shrl(bytecode, shift_count);
 485   assert(ConstantPoolCacheEntry::bytecode_1_mask == ConstantPoolCacheEntry::bytecode_2_mask, "common mask");
 486   andl(bytecode, ConstantPoolCacheEntry::bytecode_1_mask);
 487 }
 488 
 489 void InterpreterMacroAssembler::get_cache_entry_pointer_at_bcp(Register cache,
 490                                                                Register tmp,
 491                                                                int bcp_offset,
 492                                                                size_t index_size) {
 493   assert_different_registers(cache, tmp);
 494 
 495   get_cache_index_at_bcp(tmp, bcp_offset, index_size);
 496   assert(sizeof(ConstantPoolCacheEntry) == 4 * wordSize, "adjust code below");
 497   // convert from field index to ConstantPoolCacheEntry index
 498   // and from word offset to byte offset
 499   assert(exact_log2(in_bytes(ConstantPoolCacheEntry::size_in_bytes())) == 2 + LogBytesPerWord, "else change next line");
 500   shll(tmp, 2 + LogBytesPerWord);
 501   movptr(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize));
 502   // skip past the header
 503   addptr(cache, in_bytes(ConstantPoolCache::base_offset()));
 504   addptr(cache, tmp);  // construct pointer to cache entry
 505 }
 506 
 507 // Load object from cpool->resolved_references(index)
 508 void InterpreterMacroAssembler::load_resolved_reference_at_index(Register result,
 509                                                                  Register index,
 510                                                                  Register tmp) {
 511   assert_different_registers(result, index);
 512 
 513   get_constant_pool(result);
 514   // load pointer for resolved_references[] objArray
 515   movptr(result, Address(result, ConstantPool::cache_offset_in_bytes()));
 516   movptr(result, Address(result, ConstantPoolCache::resolved_references_offset_in_bytes()));
 517   resolve_oop_handle(result, tmp);
 518   load_heap_oop(result, Address(result, index,
 519                                 UseCompressedOops ? Address::times_4 : Address::times_ptr,
 520                                 arrayOopDesc::base_offset_in_bytes(T_OBJECT)), tmp);
 521 }
 522 
 523 // load cpool->resolved_klass_at(index)
 524 void InterpreterMacroAssembler::load_resolved_klass_at_index(Register klass,
 525                                                              Register cpool,
 526                                                              Register index) {
 527   assert_different_registers(cpool, index);
 528 
 529   movw(index, Address(cpool, index, Address::times_ptr, sizeof(ConstantPool)));
 530   Register resolved_klasses = cpool;
 531   movptr(resolved_klasses, Address(cpool, ConstantPool::resolved_klasses_offset_in_bytes()));
 532   movptr(klass, Address(resolved_klasses, index, Address::times_ptr, Array<Klass*>::base_offset_in_bytes()));
 533 }
 534 
 535 void InterpreterMacroAssembler::load_resolved_method_at_index(int byte_no,
 536                                                               Register method,
 537                                                               Register cache,
 538                                                               Register index) {
 539   assert_different_registers(cache, index);
 540 
 541   const int method_offset = in_bytes(
 542     ConstantPoolCache::base_offset() +
 543       ((byte_no == TemplateTable::f2_byte)
 544        ? ConstantPoolCacheEntry::f2_offset()
 545        : ConstantPoolCacheEntry::f1_offset()));
 546 
 547   movptr(method, Address(cache, index, Address::times_ptr, method_offset)); // get f1 Method*
 548 }
 549 
 550 // Generate a subtype check: branch to ok_is_subtype if sub_klass is a
 551 // subtype of super_klass.
 552 //
 553 // Args:
 554 //      rax: superklass
 555 //      Rsub_klass: subklass
 556 //
 557 // Kills:
 558 //      rcx, rdi
 559 void InterpreterMacroAssembler::gen_subtype_check(Register Rsub_klass,
 560                                                   Label& ok_is_subtype,
 561                                                   bool profile) {
 562   assert(Rsub_klass != rax, "rax holds superklass");
 563   LP64_ONLY(assert(Rsub_klass != r14, "r14 holds locals");)
 564   LP64_ONLY(assert(Rsub_klass != r13, "r13 holds bcp");)
 565   assert(Rsub_klass != rcx, "rcx holds 2ndary super array length");
 566   assert(Rsub_klass != rdi, "rdi holds 2ndary super array scan ptr");
 567 
 568   // Profile the not-null value's klass.
 569   if (profile) {
 570     profile_typecheck(rcx, Rsub_klass, rdi); // blows rcx, reloads rdi
 571   }
 572 
 573   // Do the check.
 574   check_klass_subtype(Rsub_klass, rax, rcx, ok_is_subtype); // blows rcx
 575 
 576   // Profile the failure of the check.
 577   if (profile) {
 578     profile_typecheck_failed(rcx); // blows rcx
 579   }
 580 }
 581 
 582 
 583 #ifndef _LP64
 584 void InterpreterMacroAssembler::f2ieee() {
 585   if (IEEEPrecision) {
 586     fstp_s(Address(rsp, 0));
 587     fld_s(Address(rsp, 0));
 588   }
 589 }
 590 
 591 
 592 void InterpreterMacroAssembler::d2ieee() {
 593   if (IEEEPrecision) {
 594     fstp_d(Address(rsp, 0));
 595     fld_d(Address(rsp, 0));
 596   }
 597 }
 598 #endif // _LP64
 599 
 600 // Java Expression Stack
 601 
 602 void InterpreterMacroAssembler::pop_ptr(Register r) {
 603   pop(r);
 604 }
 605 
 606 void InterpreterMacroAssembler::push_ptr(Register r) {
 607   push(r);
 608 }
 609 
 610 void InterpreterMacroAssembler::push_i(Register r) {
 611   push(r);
 612 }
 613 
 614 void InterpreterMacroAssembler::push_i_or_ptr(Register r) {
 615   push(r);
 616 }
 617 
 618 void InterpreterMacroAssembler::push_f(XMMRegister r) {
 619   subptr(rsp, wordSize);
 620   movflt(Address(rsp, 0), r);
 621 }
 622 
 623 void InterpreterMacroAssembler::pop_f(XMMRegister r) {
 624   movflt(r, Address(rsp, 0));
 625   addptr(rsp, wordSize);
 626 }
 627 
 628 void InterpreterMacroAssembler::push_d(XMMRegister r) {
 629   subptr(rsp, 2 * wordSize);
 630   movdbl(Address(rsp, 0), r);
 631 }
 632 
 633 void InterpreterMacroAssembler::pop_d(XMMRegister r) {
 634   movdbl(r, Address(rsp, 0));
 635   addptr(rsp, 2 * Interpreter::stackElementSize);
 636 }
 637 
 638 #ifdef _LP64
 639 void InterpreterMacroAssembler::pop_i(Register r) {
 640   // XXX can't use pop currently, upper half non clean
 641   movl(r, Address(rsp, 0));
 642   addptr(rsp, wordSize);
 643 }
 644 
 645 void InterpreterMacroAssembler::pop_l(Register r) {
 646   movq(r, Address(rsp, 0));
 647   addptr(rsp, 2 * Interpreter::stackElementSize);
 648 }
 649 
 650 void InterpreterMacroAssembler::push_l(Register r) {
 651   subptr(rsp, 2 * wordSize);
 652   movptr(Address(rsp, Interpreter::expr_offset_in_bytes(0)), r         );
 653   movptr(Address(rsp, Interpreter::expr_offset_in_bytes(1)), NULL_WORD );
 654 }
 655 
 656 void InterpreterMacroAssembler::pop(TosState state) {
 657   switch (state) {
 658   case atos: pop_ptr();                 break;
 659   case btos:
 660   case ztos:
 661   case ctos:
 662   case stos:
 663   case itos: pop_i();                   break;
 664   case ltos: pop_l();                   break;
 665   case ftos: pop_f(xmm0);               break;
 666   case dtos: pop_d(xmm0);               break;
 667   case vtos: /* nothing to do */        break;
 668   default:   ShouldNotReachHere();
 669   }
 670   interp_verify_oop(rax, state);
 671 }
 672 
 673 void InterpreterMacroAssembler::push(TosState state) {
 674   interp_verify_oop(rax, state);
 675   switch (state) {
 676   case atos: push_ptr();                break;
 677   case btos:
 678   case ztos:
 679   case ctos:
 680   case stos:
 681   case itos: push_i();                  break;
 682   case ltos: push_l();                  break;
 683   case ftos: push_f(xmm0);              break;
 684   case dtos: push_d(xmm0);              break;
 685   case vtos: /* nothing to do */        break;
 686   default  : ShouldNotReachHere();
 687   }
 688 }
 689 #else
 690 void InterpreterMacroAssembler::pop_i(Register r) {
 691   pop(r);
 692 }
 693 
 694 void InterpreterMacroAssembler::pop_l(Register lo, Register hi) {
 695   pop(lo);
 696   pop(hi);
 697 }
 698 
 699 void InterpreterMacroAssembler::pop_f() {
 700   fld_s(Address(rsp, 0));
 701   addptr(rsp, 1 * wordSize);
 702 }
 703 
 704 void InterpreterMacroAssembler::pop_d() {
 705   fld_d(Address(rsp, 0));
 706   addptr(rsp, 2 * wordSize);
 707 }
 708 
 709 
 710 void InterpreterMacroAssembler::pop(TosState state) {
 711   switch (state) {
 712     case atos: pop_ptr(rax);                                 break;
 713     case btos:                                               // fall through
 714     case ztos:                                               // fall through
 715     case ctos:                                               // fall through
 716     case stos:                                               // fall through
 717     case itos: pop_i(rax);                                   break;
 718     case ltos: pop_l(rax, rdx);                              break;
 719     case ftos:
 720       if (UseSSE >= 1) {
 721         pop_f(xmm0);
 722       } else {
 723         pop_f();
 724       }
 725       break;
 726     case dtos:
 727       if (UseSSE >= 2) {
 728         pop_d(xmm0);
 729       } else {
 730         pop_d();
 731       }
 732       break;
 733     case vtos: /* nothing to do */                           break;
 734     default  : ShouldNotReachHere();
 735   }
 736   interp_verify_oop(rax, state);
 737 }
 738 
 739 
 740 void InterpreterMacroAssembler::push_l(Register lo, Register hi) {
 741   push(hi);
 742   push(lo);
 743 }
 744 
 745 void InterpreterMacroAssembler::push_f() {
 746   // Do not schedule for no AGI! Never write beyond rsp!
 747   subptr(rsp, 1 * wordSize);
 748   fstp_s(Address(rsp, 0));
 749 }
 750 
 751 void InterpreterMacroAssembler::push_d() {
 752   // Do not schedule for no AGI! Never write beyond rsp!
 753   subptr(rsp, 2 * wordSize);
 754   fstp_d(Address(rsp, 0));
 755 }
 756 
 757 
 758 void InterpreterMacroAssembler::push(TosState state) {
 759   interp_verify_oop(rax, state);
 760   switch (state) {
 761     case atos: push_ptr(rax); break;
 762     case btos:                                               // fall through
 763     case ztos:                                               // fall through
 764     case ctos:                                               // fall through
 765     case stos:                                               // fall through
 766     case itos: push_i(rax);                                    break;
 767     case ltos: push_l(rax, rdx);                               break;
 768     case ftos:
 769       if (UseSSE >= 1) {
 770         push_f(xmm0);
 771       } else {
 772         push_f();
 773       }
 774       break;
 775     case dtos:
 776       if (UseSSE >= 2) {
 777         push_d(xmm0);
 778       } else {
 779         push_d();
 780       }
 781       break;
 782     case vtos: /* nothing to do */                             break;
 783     default  : ShouldNotReachHere();
 784   }
 785 }
 786 #endif // _LP64
 787 
 788 
 789 // Helpers for swap and dup
 790 void InterpreterMacroAssembler::load_ptr(int n, Register val) {
 791   movptr(val, Address(rsp, Interpreter::expr_offset_in_bytes(n)));
 792 }
 793 
 794 void InterpreterMacroAssembler::store_ptr(int n, Register val) {
 795   movptr(Address(rsp, Interpreter::expr_offset_in_bytes(n)), val);
 796 }
 797 
 798 
 799 void InterpreterMacroAssembler::prepare_to_jump_from_interpreted() {
 800   // set sender sp
 801   lea(_bcp_register, Address(rsp, wordSize));
 802   // record last_sp
 803   movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), _bcp_register);
 804 }
 805 
 806 
 807 // Jump to from_interpreted entry of a call unless single stepping is possible
 808 // in this thread in which case we must call the i2i entry
 809 void InterpreterMacroAssembler::jump_from_interpreted(Register method, Register temp) {
 810   prepare_to_jump_from_interpreted();
 811 
 812   if (JvmtiExport::can_post_interpreter_events()) {
 813     Label run_compiled_code;
 814     // JVMTI events, such as single-stepping, are implemented partly by avoiding running
 815     // compiled code in threads for which the event is enabled.  Check here for
 816     // interp_only_mode if these events CAN be enabled.
 817     // interp_only is an int, on little endian it is sufficient to test the byte only
 818     // Is a cmpl faster?
 819     LP64_ONLY(temp = r15_thread;)
 820     NOT_LP64(get_thread(temp);)
 821     cmpb(Address(temp, JavaThread::interp_only_mode_offset()), 0);
 822     jccb(Assembler::zero, run_compiled_code);
 823     jmp(Address(method, Method::interpreter_entry_offset()));
 824     bind(run_compiled_code);
 825   }
 826 
 827   jmp(Address(method, Method::from_interpreted_offset()));
 828 }
 829 
 830 // The following two routines provide a hook so that an implementation
 831 // can schedule the dispatch in two parts.  x86 does not do this.
 832 void InterpreterMacroAssembler::dispatch_prolog(TosState state, int step) {
 833   // Nothing x86 specific to be done here
 834 }
 835 
 836 void InterpreterMacroAssembler::dispatch_epilog(TosState state, int step) {
 837   dispatch_next(state, step);
 838 }
 839 
 840 void InterpreterMacroAssembler::dispatch_base(TosState state,
 841                                               address* table,
 842                                               bool verifyoop,
 843                                               bool generate_poll) {
 844   verify_FPU(1, state);
 845   if (VerifyActivationFrameSize) {
 846     Label L;
 847     mov(rcx, rbp);
 848     subptr(rcx, rsp);
 849     int32_t min_frame_size =
 850       (frame::link_offset - frame::interpreter_frame_initial_sp_offset) *
 851       wordSize;
 852     cmpptr(rcx, (int32_t)min_frame_size);
 853     jcc(Assembler::greaterEqual, L);
 854     stop("broken stack frame");
 855     bind(L);
 856   }
 857   if (verifyoop) {
 858     interp_verify_oop(rax, state);
 859   }
 860 
 861   address* const safepoint_table = Interpreter::safept_table(state);
 862 #ifdef _LP64
 863   Label no_safepoint, dispatch;
 864   if (table != safepoint_table && generate_poll) {
 865     NOT_PRODUCT(block_comment("Thread-local Safepoint poll"));
 866     testb(Address(r15_thread, JavaThread::polling_word_offset()), SafepointMechanism::poll_bit());
 867 
 868     jccb(Assembler::zero, no_safepoint);
 869     lea(rscratch1, ExternalAddress((address)safepoint_table));
 870     jmpb(dispatch);
 871   }
 872 
 873   bind(no_safepoint);
 874   lea(rscratch1, ExternalAddress((address)table));
 875   bind(dispatch);
 876   jmp(Address(rscratch1, rbx, Address::times_8));
 877 
 878 #else
 879   Address index(noreg, rbx, Address::times_ptr);
 880   if (table != safepoint_table && generate_poll) {
 881     NOT_PRODUCT(block_comment("Thread-local Safepoint poll"));
 882     Label no_safepoint;
 883     const Register thread = rcx;
 884     get_thread(thread);
 885     testb(Address(thread, JavaThread::polling_word_offset()), SafepointMechanism::poll_bit());
 886 
 887     jccb(Assembler::zero, no_safepoint);
 888     ArrayAddress dispatch_addr(ExternalAddress((address)safepoint_table), index);
 889     jump(dispatch_addr);
 890     bind(no_safepoint);
 891   }
 892 
 893   {
 894     ArrayAddress dispatch_addr(ExternalAddress((address)table), index);
 895     jump(dispatch_addr);
 896   }
 897 #endif // _LP64
 898 }
 899 
 900 void InterpreterMacroAssembler::dispatch_only(TosState state, bool generate_poll) {
 901   dispatch_base(state, Interpreter::dispatch_table(state), true, generate_poll);
 902 }
 903 
 904 void InterpreterMacroAssembler::dispatch_only_normal(TosState state) {
 905   dispatch_base(state, Interpreter::normal_table(state));
 906 }
 907 
 908 void InterpreterMacroAssembler::dispatch_only_noverify(TosState state) {
 909   dispatch_base(state, Interpreter::normal_table(state), false);
 910 }
 911 
 912 
 913 void InterpreterMacroAssembler::dispatch_next(TosState state, int step, bool generate_poll) {
 914   // load next bytecode (load before advancing _bcp_register to prevent AGI)
 915   load_unsigned_byte(rbx, Address(_bcp_register, step));
 916   // advance _bcp_register
 917   increment(_bcp_register, step);
 918   dispatch_base(state, Interpreter::dispatch_table(state), true, generate_poll);
 919 }
 920 
 921 void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) {
 922   // load current bytecode
 923   load_unsigned_byte(rbx, Address(_bcp_register, 0));
 924   dispatch_base(state, table);
 925 }
 926 
 927 void InterpreterMacroAssembler::narrow(Register result) {
 928 
 929   // Get method->_constMethod->_result_type
 930   movptr(rcx, Address(rbp, frame::interpreter_frame_method_offset * wordSize));
 931   movptr(rcx, Address(rcx, Method::const_offset()));
 932   load_unsigned_byte(rcx, Address(rcx, ConstMethod::result_type_offset()));
 933 
 934   Label done, notBool, notByte, notChar;
 935 
 936   // common case first
 937   cmpl(rcx, T_INT);
 938   jcc(Assembler::equal, done);
 939 
 940   // mask integer result to narrower return type.
 941   cmpl(rcx, T_BOOLEAN);
 942   jcc(Assembler::notEqual, notBool);
 943   andl(result, 0x1);
 944   jmp(done);
 945 
 946   bind(notBool);
 947   cmpl(rcx, T_BYTE);
 948   jcc(Assembler::notEqual, notByte);
 949   LP64_ONLY(movsbl(result, result);)
 950   NOT_LP64(shll(result, 24);)      // truncate upper 24 bits
 951   NOT_LP64(sarl(result, 24);)      // and sign-extend byte
 952   jmp(done);
 953 
 954   bind(notByte);
 955   cmpl(rcx, T_CHAR);
 956   jcc(Assembler::notEqual, notChar);
 957   LP64_ONLY(movzwl(result, result);)
 958   NOT_LP64(andl(result, 0xFFFF);)  // truncate upper 16 bits
 959   jmp(done);
 960 
 961   bind(notChar);
 962   // cmpl(rcx, T_SHORT);  // all that's left
 963   // jcc(Assembler::notEqual, done);
 964   LP64_ONLY(movswl(result, result);)
 965   NOT_LP64(shll(result, 16);)      // truncate upper 16 bits
 966   NOT_LP64(sarl(result, 16);)      // and sign-extend short
 967 
 968   // Nothing to do for T_INT
 969   bind(done);
 970 }
 971 
 972 // remove activation
 973 //
 974 // Apply stack watermark barrier.
 975 // Unlock the receiver if this is a synchronized method.
 976 // Unlock any Java monitors from syncronized blocks.
 977 // Remove the activation from the stack.
 978 //
 979 // If there are locked Java monitors
 980 //    If throw_monitor_exception
 981 //       throws IllegalMonitorStateException
 982 //    Else if install_monitor_exception
 983 //       installs IllegalMonitorStateException
 984 //    Else
 985 //       no error processing
 986 void InterpreterMacroAssembler::remove_activation(
 987         TosState state,
 988         Register ret_addr,
 989         bool throw_monitor_exception,
 990         bool install_monitor_exception,
 991         bool notify_jvmdi) {
 992   // Note: Registers rdx xmm0 may be in use for the
 993   // result check if synchronized method
 994   Label unlocked, unlock, no_unlock;
 995 
 996   const Register rthread = LP64_ONLY(r15_thread) NOT_LP64(rcx);
 997   const Register robj    = LP64_ONLY(c_rarg1) NOT_LP64(rdx);
 998   const Register rmon    = LP64_ONLY(c_rarg1) NOT_LP64(rcx);
 999                               // monitor pointers need different register
1000                               // because rdx may have the result in it
1001   NOT_LP64(get_thread(rthread);)
1002 
1003   // The below poll is for the stack watermark barrier. It allows fixing up frames lazily,
1004   // that would normally not be safe to use. Such bad returns into unsafe territory of
1005   // the stack, will call InterpreterRuntime::at_unwind.
1006   Label slow_path;
1007   Label fast_path;
1008   safepoint_poll(slow_path, rthread, true /* at_return */, false /* in_nmethod */);
1009   jmp(fast_path);
1010   bind(slow_path);
1011   push(state);
1012   set_last_Java_frame(rthread, noreg, rbp, (address)pc());
1013   super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::at_unwind), rthread);
1014   NOT_LP64(get_thread(rthread);) // call_VM clobbered it, restore
1015   reset_last_Java_frame(rthread, true);
1016   pop(state);
1017   bind(fast_path);
1018 
1019   // get the value of _do_not_unlock_if_synchronized into rdx
1020   const Address do_not_unlock_if_synchronized(rthread,
1021     in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
1022   movbool(rbx, do_not_unlock_if_synchronized);
1023   movbool(do_not_unlock_if_synchronized, false); // reset the flag
1024 
1025   // get method access flags
1026   movptr(rcx, Address(rbp, frame::interpreter_frame_method_offset * wordSize));
1027   movl(rcx, Address(rcx, Method::access_flags_offset()));
1028   testl(rcx, JVM_ACC_SYNCHRONIZED);
1029   jcc(Assembler::zero, unlocked);
1030 
1031   // Don't unlock anything if the _do_not_unlock_if_synchronized flag
1032   // is set.
1033   testbool(rbx);
1034   jcc(Assembler::notZero, no_unlock);
1035 
1036   // unlock monitor
1037   push(state); // save result
1038 
1039   // BasicObjectLock will be first in list, since this is a
1040   // synchronized method. However, need to check that the object has
1041   // not been unlocked by an explicit monitorexit bytecode.
1042   const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset *
1043                         wordSize - (int) sizeof(BasicObjectLock));
1044   // We use c_rarg1/rdx so that if we go slow path it will be the correct
1045   // register for unlock_object to pass to VM directly
1046   lea(robj, monitor); // address of first monitor
1047 
1048   movptr(rax, Address(robj, BasicObjectLock::obj_offset_in_bytes()));
1049   testptr(rax, rax);
1050   jcc(Assembler::notZero, unlock);
1051 
1052   pop(state);
1053   if (throw_monitor_exception) {
1054     // Entry already unlocked, need to throw exception
1055     NOT_LP64(empty_FPU_stack();)  // remove possible return value from FPU-stack, otherwise stack could overflow
1056     call_VM(noreg, CAST_FROM_FN_PTR(address,
1057                    InterpreterRuntime::throw_illegal_monitor_state_exception));
1058     should_not_reach_here();
1059   } else {
1060     // Monitor already unlocked during a stack unroll. If requested,
1061     // install an illegal_monitor_state_exception.  Continue with
1062     // stack unrolling.
1063     if (install_monitor_exception) {
1064       NOT_LP64(empty_FPU_stack();)
1065       call_VM(noreg, CAST_FROM_FN_PTR(address,
1066                      InterpreterRuntime::new_illegal_monitor_state_exception));
1067     }
1068     jmp(unlocked);
1069   }
1070 
1071   bind(unlock);
1072   unlock_object(robj);
1073   pop(state);
1074 
1075   // Check that for block-structured locking (i.e., that all locked
1076   // objects has been unlocked)
1077   bind(unlocked);
1078 
1079   // rax, rdx: Might contain return value
1080 
1081   // Check that all monitors are unlocked
1082   {
1083     Label loop, exception, entry, restart;
1084     const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
1085     const Address monitor_block_top(
1086         rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
1087     const Address monitor_block_bot(
1088         rbp, frame::interpreter_frame_initial_sp_offset * wordSize);
1089 
1090     bind(restart);
1091     // We use c_rarg1 so that if we go slow path it will be the correct
1092     // register for unlock_object to pass to VM directly
1093     movptr(rmon, monitor_block_top); // points to current entry, starting
1094                                   // with top-most entry
1095     lea(rbx, monitor_block_bot);  // points to word before bottom of
1096                                   // monitor block
1097     jmp(entry);
1098 
1099     // Entry already locked, need to throw exception
1100     bind(exception);
1101 
1102     if (throw_monitor_exception) {
1103       // Throw exception
1104       NOT_LP64(empty_FPU_stack();)
1105       MacroAssembler::call_VM(noreg,
1106                               CAST_FROM_FN_PTR(address, InterpreterRuntime::
1107                                    throw_illegal_monitor_state_exception));
1108       should_not_reach_here();
1109     } else {
1110       // Stack unrolling. Unlock object and install illegal_monitor_exception.
1111       // Unlock does not block, so don't have to worry about the frame.
1112       // We don't have to preserve c_rarg1 since we are going to throw an exception.
1113 
1114       push(state);
1115       mov(robj, rmon);   // nop if robj and rmon are the same
1116       unlock_object(robj);
1117       pop(state);
1118 
1119       if (install_monitor_exception) {
1120         NOT_LP64(empty_FPU_stack();)
1121         call_VM(noreg, CAST_FROM_FN_PTR(address,
1122                                         InterpreterRuntime::
1123                                         new_illegal_monitor_state_exception));
1124       }
1125 
1126       jmp(restart);
1127     }
1128 
1129     bind(loop);
1130     // check if current entry is used
1131     cmpptr(Address(rmon, BasicObjectLock::obj_offset_in_bytes()), (int32_t) NULL);
1132     jcc(Assembler::notEqual, exception);
1133 
1134     addptr(rmon, entry_size); // otherwise advance to next entry
1135     bind(entry);
1136     cmpptr(rmon, rbx); // check if bottom reached
1137     jcc(Assembler::notEqual, loop); // if not at bottom then check this entry
1138   }
1139 
1140   bind(no_unlock);
1141 
1142   // jvmti support
1143   if (notify_jvmdi) {
1144     notify_method_exit(state, NotifyJVMTI);    // preserve TOSCA
1145   } else {
1146     notify_method_exit(state, SkipNotifyJVMTI); // preserve TOSCA
1147   }
1148 
1149   if (StackReservedPages > 0) {
1150     movptr(rbx,
1151                Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize));
1152     // testing if reserved zone needs to be re-enabled
1153     Register rthread = LP64_ONLY(r15_thread) NOT_LP64(rcx);
1154     Label no_reserved_zone_enabling;
1155 
1156     NOT_LP64(get_thread(rthread);)
1157 
1158     cmpl(Address(rthread, JavaThread::stack_guard_state_offset()), StackOverflow::stack_guard_enabled);
1159     jcc(Assembler::equal, no_reserved_zone_enabling);
1160 
1161     cmpptr(rbx, Address(rthread, JavaThread::reserved_stack_activation_offset()));
1162     jcc(Assembler::lessEqual, no_reserved_zone_enabling);
1163 
1164     call_VM_leaf(
1165       CAST_FROM_FN_PTR(address, SharedRuntime::enable_stack_reserved_zone), rthread);
1166     call_VM(noreg, CAST_FROM_FN_PTR(address,
1167                    InterpreterRuntime::throw_delayed_StackOverflowError));
1168     should_not_reach_here();
1169 
1170     bind(no_reserved_zone_enabling);
1171   }
1172 
1173   // remove activation
1174   // get sender sp
1175   movptr(rbx,
1176          Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize));
1177 
1178   if (state == atos && InlineTypeReturnedAsFields) {
1179     // Check if we are returning an non-null inline type and load its fields into registers
1180     Label skip;
1181     test_oop_is_not_inline_type(rax, rscratch1, skip);
1182 
1183 #ifndef _LP64
1184     super_call_VM_leaf(StubRoutines::load_inline_type_fields_in_regs());
1185 #else
1186     // Load fields from a buffered value with an inline class specific handler
1187     load_klass(rdi, rax, rscratch1);
1188     movptr(rdi, Address(rdi, InstanceKlass::adr_inlineklass_fixed_block_offset()));
1189     movptr(rdi, Address(rdi, InlineKlass::unpack_handler_offset()));
1190     // Unpack handler can be null if inline type is not scalarizable in returns
1191     testptr(rdi, rdi);
1192     jcc(Assembler::zero, skip);
1193     call(rdi);
1194 #endif
1195 #ifdef ASSERT
1196     if (StressInlineTypeReturnedAsFields) {
1197       // TODO 8284443 Enable this for value class returns (L-type descriptor)
1198       Label skip_stress;
1199       movptr(rscratch1, Address(rbp, frame::interpreter_frame_method_offset * wordSize));
1200       movptr(rscratch1, Address(rscratch1, Method::const_offset()));
1201       load_unsigned_byte(rscratch1, Address(rscratch1, ConstMethod::result_type_offset()));
1202       cmpl(rscratch1, T_PRIMITIVE_OBJECT);
1203       jcc(Assembler::notEqual, skip_stress);
1204       load_klass(rax, rax, rscratch1);
1205       orptr(rax, 1);
1206       bind(skip_stress);
1207     }
1208 #endif
1209     // call above kills the value in rbx. Reload it.
1210     movptr(rbx, Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize));
1211     bind(skip);
1212   }
1213   leave();                           // remove frame anchor
1214   pop(ret_addr);                     // get return address
1215   mov(rsp, rbx);                     // set sp to sender sp
1216 }
1217 
1218 void InterpreterMacroAssembler::get_method_counters(Register method,
1219                                                     Register mcs, Label& skip) {
1220   Label has_counters;
1221   movptr(mcs, Address(method, Method::method_counters_offset()));
1222   testptr(mcs, mcs);
1223   jcc(Assembler::notZero, has_counters);
1224   call_VM(noreg, CAST_FROM_FN_PTR(address,
1225           InterpreterRuntime::build_method_counters), method);
1226   movptr(mcs, Address(method,Method::method_counters_offset()));
1227   testptr(mcs, mcs);
1228   jcc(Assembler::zero, skip); // No MethodCounters allocated, OutOfMemory
1229   bind(has_counters);
1230 }
1231 
1232 void InterpreterMacroAssembler::allocate_instance(Register klass, Register new_obj,
1233                                                   Register t1, Register t2,
1234                                                   bool clear_fields, Label& alloc_failed) {
1235   MacroAssembler::allocate_instance(klass, new_obj, t1, t2, clear_fields, alloc_failed);
1236   {
1237     SkipIfEqual skip_if(this, &DTraceAllocProbes, 0);
1238     // Trigger dtrace event for fastpath
1239     push(atos);
1240     call_VM_leaf(CAST_FROM_FN_PTR(address, static_cast<int (*)(oopDesc*)>(SharedRuntime::dtrace_object_alloc)), new_obj);
1241     pop(atos);
1242   }
1243 }
1244 
1245 
1246 void InterpreterMacroAssembler::read_inlined_field(Register holder_klass,
1247                                                      Register field_index, Register field_offset,
1248                                                      Register obj) {
1249   Label alloc_failed, empty_value, done;
1250   const Register src = field_offset;
1251   const Register alloc_temp = LP64_ONLY(rscratch1) NOT_LP64(rsi);
1252   const Register dst_temp   = LP64_ONLY(rscratch2) NOT_LP64(rdi);
1253   assert_different_registers(obj, holder_klass, field_index, field_offset, dst_temp);
1254 
1255   // Grap the inline field klass
1256   push(holder_klass);
1257   const Register field_klass = holder_klass;
1258   get_inline_type_field_klass(holder_klass, field_index, field_klass);
1259 
1260   //check for empty value klass
1261   test_klass_is_empty_inline_type(field_klass, dst_temp, empty_value);
1262 
1263   // allocate buffer
1264   push(obj); // save holder
1265   allocate_instance(field_klass, obj, alloc_temp, dst_temp, false, alloc_failed);
1266 
1267   // Have an oop instance buffer, copy into it
1268   data_for_oop(obj, dst_temp, field_klass);
1269   pop(alloc_temp);             // restore holder
1270   lea(src, Address(alloc_temp, field_offset));
1271   // call_VM_leaf, clobbers a few regs, save restore new obj
1272   push(obj);
1273   access_value_copy(IS_DEST_UNINITIALIZED, src, dst_temp, field_klass);
1274   pop(obj);
1275   pop(holder_klass);
1276   jmp(done);
1277 
1278   bind(empty_value);
1279   get_empty_inline_type_oop(field_klass, dst_temp, obj);
1280   pop(holder_klass);
1281   jmp(done);
1282 
1283   bind(alloc_failed);
1284   pop(obj);
1285   pop(holder_klass);
1286   call_VM(obj, CAST_FROM_FN_PTR(address, InterpreterRuntime::read_inlined_field),
1287           obj, field_index, holder_klass);
1288 
1289   bind(done);
1290 }
1291 
1292 void InterpreterMacroAssembler::read_flattened_element(Register array, Register index,
1293                                                        Register t1, Register t2,
1294                                                        Register obj) {
1295   assert_different_registers(array, index, t1, t2);
1296   Label alloc_failed, empty_value, done;
1297   const Register array_klass = t2;
1298   const Register elem_klass = t1;
1299   const Register alloc_temp = LP64_ONLY(rscratch1) NOT_LP64(rsi);
1300   const Register dst_temp   = LP64_ONLY(rscratch2) NOT_LP64(rdi);
1301 
1302   // load in array->klass()->element_klass()
1303   Register tmp_load_klass = LP64_ONLY(rscratch1) NOT_LP64(noreg);
1304   load_klass(array_klass, array, tmp_load_klass);
1305   movptr(elem_klass, Address(array_klass, ArrayKlass::element_klass_offset()));
1306 
1307   //check for empty value klass
1308   test_klass_is_empty_inline_type(elem_klass, dst_temp, empty_value);
1309 
1310   // calc source into "array_klass" and free up some regs
1311   const Register src = array_klass;
1312   push(index); // preserve index reg in case alloc_failed
1313   data_for_value_array_index(array, array_klass, index, src);
1314 
1315   allocate_instance(elem_klass, obj, alloc_temp, dst_temp, false, alloc_failed);
1316   // Have an oop instance buffer, copy into it
1317   store_ptr(0, obj); // preserve obj (overwrite index, no longer needed)
1318   data_for_oop(obj, dst_temp, elem_klass);
1319   access_value_copy(IS_DEST_UNINITIALIZED, src, dst_temp, elem_klass);
1320   pop(obj);
1321   jmp(done);
1322 
1323   bind(empty_value);
1324   get_empty_inline_type_oop(elem_klass, dst_temp, obj);
1325   jmp(done);
1326 
1327   bind(alloc_failed);
1328   pop(index);
1329   if (array == c_rarg2) {
1330     mov(elem_klass, array);
1331     array = elem_klass;
1332   }
1333   call_VM(obj, CAST_FROM_FN_PTR(address, InterpreterRuntime::value_array_load), array, index);
1334 
1335   bind(done);
1336 }
1337 
1338 
1339 // Lock object
1340 //
1341 // Args:
1342 //      rdx, c_rarg1: BasicObjectLock to be used for locking
1343 //
1344 // Kills:
1345 //      rax, rbx
1346 void InterpreterMacroAssembler::lock_object(Register lock_reg) {
1347   assert(lock_reg == LP64_ONLY(c_rarg1) NOT_LP64(rdx),
1348          "The argument is only for looks. It must be c_rarg1");
1349 
1350   if (UseHeavyMonitors) {
1351     call_VM(noreg,
1352             CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
1353             lock_reg);
1354   } else {
1355     Label done;
1356 
1357     const Register swap_reg = rax; // Must use rax for cmpxchg instruction
1358     const Register tmp_reg = rbx;
1359     const Register obj_reg = LP64_ONLY(c_rarg3) NOT_LP64(rcx); // Will contain the oop
1360     const Register rklass_decode_tmp = LP64_ONLY(rscratch1) NOT_LP64(noreg);
1361 
1362     const int obj_offset = BasicObjectLock::obj_offset_in_bytes();
1363     const int lock_offset = BasicObjectLock::lock_offset_in_bytes ();
1364     const int mark_offset = lock_offset +
1365                             BasicLock::displaced_header_offset_in_bytes();
1366 
1367     Label slow_case;
1368 
1369     // Load object pointer into obj_reg
1370     movptr(obj_reg, Address(lock_reg, obj_offset));
1371 
1372     if (DiagnoseSyncOnValueBasedClasses != 0) {
1373       load_klass(tmp_reg, obj_reg, rklass_decode_tmp);
1374       movl(tmp_reg, Address(tmp_reg, Klass::access_flags_offset()));
1375       testl(tmp_reg, JVM_ACC_IS_VALUE_BASED_CLASS);
1376       jcc(Assembler::notZero, slow_case);
1377     }
1378 
1379     // Load immediate 1 into swap_reg %rax
1380     movl(swap_reg, (int32_t)1);
1381 
1382     // Load (object->mark() | 1) into swap_reg %rax
1383     orptr(swap_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
1384     if (EnableValhalla) {
1385       // Mask inline_type bit such that we go to the slow path if object is an inline type
1386       andptr(swap_reg, ~((int) markWord::inline_type_bit_in_place));
1387     }
1388 
1389     // Save (object->mark() | 1) into BasicLock's displaced header
1390     movptr(Address(lock_reg, mark_offset), swap_reg);
1391 
1392     assert(lock_offset == 0,
1393            "displaced header must be first word in BasicObjectLock");
1394 
1395     lock();
1396     cmpxchgptr(lock_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
1397     jcc(Assembler::zero, done);
1398 
1399     const int zero_bits = LP64_ONLY(7) NOT_LP64(3);
1400 
1401     // Fast check for recursive lock.
1402     //
1403     // Can apply the optimization only if this is a stack lock
1404     // allocated in this thread. For efficiency, we can focus on
1405     // recently allocated stack locks (instead of reading the stack
1406     // base and checking whether 'mark' points inside the current
1407     // thread stack):
1408     //  1) (mark & zero_bits) == 0, and
1409     //  2) rsp <= mark < mark + os::pagesize()
1410     //
1411     // Warning: rsp + os::pagesize can overflow the stack base. We must
1412     // neither apply the optimization for an inflated lock allocated
1413     // just above the thread stack (this is why condition 1 matters)
1414     // nor apply the optimization if the stack lock is inside the stack
1415     // of another thread. The latter is avoided even in case of overflow
1416     // because we have guard pages at the end of all stacks. Hence, if
1417     // we go over the stack base and hit the stack of another thread,
1418     // this should not be in a writeable area that could contain a
1419     // stack lock allocated by that thread. As a consequence, a stack
1420     // lock less than page size away from rsp is guaranteed to be
1421     // owned by the current thread.
1422     //
1423     // These 3 tests can be done by evaluating the following
1424     // expression: ((mark - rsp) & (zero_bits - os::vm_page_size())),
1425     // assuming both stack pointer and pagesize have their
1426     // least significant bits clear.
1427     // NOTE: the mark is in swap_reg %rax as the result of cmpxchg
1428     subptr(swap_reg, rsp);
1429     andptr(swap_reg, zero_bits - os::vm_page_size());
1430 
1431     // Save the test result, for recursive case, the result is zero
1432     movptr(Address(lock_reg, mark_offset), swap_reg);
1433     jcc(Assembler::zero, done);
1434 
1435     bind(slow_case);
1436 
1437     // Call the runtime routine for slow case
1438     call_VM(noreg,
1439             CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
1440             lock_reg);
1441 
1442     bind(done);
1443   }
1444 }
1445 
1446 
1447 // Unlocks an object. Used in monitorexit bytecode and
1448 // remove_activation.  Throws an IllegalMonitorException if object is
1449 // not locked by current thread.
1450 //
1451 // Args:
1452 //      rdx, c_rarg1: BasicObjectLock for lock
1453 //
1454 // Kills:
1455 //      rax
1456 //      c_rarg0, c_rarg1, c_rarg2, c_rarg3, ... (param regs)
1457 //      rscratch1 (scratch reg)
1458 // rax, rbx, rcx, rdx
1459 void InterpreterMacroAssembler::unlock_object(Register lock_reg) {
1460   assert(lock_reg == LP64_ONLY(c_rarg1) NOT_LP64(rdx),
1461          "The argument is only for looks. It must be c_rarg1");
1462 
1463   if (UseHeavyMonitors) {
1464     call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg);
1465   } else {
1466     Label done;
1467 
1468     const Register swap_reg   = rax;  // Must use rax for cmpxchg instruction
1469     const Register header_reg = LP64_ONLY(c_rarg2) NOT_LP64(rbx);  // Will contain the old oopMark
1470     const Register obj_reg    = LP64_ONLY(c_rarg3) NOT_LP64(rcx);  // Will contain the oop
1471 
1472     save_bcp(); // Save in case of exception
1473 
1474     // Convert from BasicObjectLock structure to object and BasicLock
1475     // structure Store the BasicLock address into %rax
1476     lea(swap_reg, Address(lock_reg, BasicObjectLock::lock_offset_in_bytes()));
1477 
1478     // Load oop into obj_reg(%c_rarg3)
1479     movptr(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()));
1480 
1481     // Free entry
1482     movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()), (int32_t)NULL_WORD);
1483 
1484     // Load the old header from BasicLock structure
1485     movptr(header_reg, Address(swap_reg,
1486                                BasicLock::displaced_header_offset_in_bytes()));
1487 
1488     // Test for recursion
1489     testptr(header_reg, header_reg);
1490 
1491     // zero for recursive case
1492     jcc(Assembler::zero, done);
1493 
1494     // Atomic swap back the old header
1495     lock();
1496     cmpxchgptr(header_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
1497 
1498     // zero for simple unlock of a stack-lock case
1499     jcc(Assembler::zero, done);
1500 
1501 
1502     // Call the runtime routine for slow case.
1503     movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()), obj_reg); // restore obj
1504     call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg);
1505 
1506     bind(done);
1507 
1508     restore_bcp();
1509   }
1510 }
1511 
1512 void InterpreterMacroAssembler::test_method_data_pointer(Register mdp,
1513                                                          Label& zero_continue) {
1514   assert(ProfileInterpreter, "must be profiling interpreter");
1515   movptr(mdp, Address(rbp, frame::interpreter_frame_mdp_offset * wordSize));
1516   testptr(mdp, mdp);
1517   jcc(Assembler::zero, zero_continue);
1518 }
1519 
1520 
1521 // Set the method data pointer for the current bcp.
1522 void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() {
1523   assert(ProfileInterpreter, "must be profiling interpreter");
1524   Label set_mdp;
1525   push(rax);
1526   push(rbx);
1527 
1528   get_method(rbx);
1529   // Test MDO to avoid the call if it is NULL.
1530   movptr(rax, Address(rbx, in_bytes(Method::method_data_offset())));
1531   testptr(rax, rax);
1532   jcc(Assembler::zero, set_mdp);
1533   // rbx: method
1534   // _bcp_register: bcp
1535   call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), rbx, _bcp_register);
1536   // rax: mdi
1537   // mdo is guaranteed to be non-zero here, we checked for it before the call.
1538   movptr(rbx, Address(rbx, in_bytes(Method::method_data_offset())));
1539   addptr(rbx, in_bytes(MethodData::data_offset()));
1540   addptr(rax, rbx);
1541   bind(set_mdp);
1542   movptr(Address(rbp, frame::interpreter_frame_mdp_offset * wordSize), rax);
1543   pop(rbx);
1544   pop(rax);
1545 }
1546 
1547 void InterpreterMacroAssembler::verify_method_data_pointer() {
1548   assert(ProfileInterpreter, "must be profiling interpreter");
1549 #ifdef ASSERT
1550   Label verify_continue;
1551   push(rax);
1552   push(rbx);
1553   Register arg3_reg = LP64_ONLY(c_rarg3) NOT_LP64(rcx);
1554   Register arg2_reg = LP64_ONLY(c_rarg2) NOT_LP64(rdx);
1555   push(arg3_reg);
1556   push(arg2_reg);
1557   test_method_data_pointer(arg3_reg, verify_continue); // If mdp is zero, continue
1558   get_method(rbx);
1559 
1560   // If the mdp is valid, it will point to a DataLayout header which is
1561   // consistent with the bcp.  The converse is highly probable also.
1562   load_unsigned_short(arg2_reg,
1563                       Address(arg3_reg, in_bytes(DataLayout::bci_offset())));
1564   addptr(arg2_reg, Address(rbx, Method::const_offset()));
1565   lea(arg2_reg, Address(arg2_reg, ConstMethod::codes_offset()));
1566   cmpptr(arg2_reg, _bcp_register);
1567   jcc(Assembler::equal, verify_continue);
1568   // rbx: method
1569   // _bcp_register: bcp
1570   // c_rarg3: mdp
1571   call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp),
1572                rbx, _bcp_register, arg3_reg);
1573   bind(verify_continue);
1574   pop(arg2_reg);
1575   pop(arg3_reg);
1576   pop(rbx);
1577   pop(rax);
1578 #endif // ASSERT
1579 }
1580 
1581 
1582 void InterpreterMacroAssembler::set_mdp_data_at(Register mdp_in,
1583                                                 int constant,
1584                                                 Register value) {
1585   assert(ProfileInterpreter, "must be profiling interpreter");
1586   Address data(mdp_in, constant);
1587   movptr(data, value);
1588 }
1589 
1590 
1591 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
1592                                                       int constant,
1593                                                       bool decrement) {
1594   // Counter address
1595   Address data(mdp_in, constant);
1596 
1597   increment_mdp_data_at(data, decrement);
1598 }
1599 
1600 void InterpreterMacroAssembler::increment_mdp_data_at(Address data,
1601                                                       bool decrement) {
1602   assert(ProfileInterpreter, "must be profiling interpreter");
1603   // %%% this does 64bit counters at best it is wasting space
1604   // at worst it is a rare bug when counters overflow
1605 
1606   if (decrement) {
1607     // Decrement the register.  Set condition codes.
1608     addptr(data, (int32_t) -DataLayout::counter_increment);
1609     // If the decrement causes the counter to overflow, stay negative
1610     Label L;
1611     jcc(Assembler::negative, L);
1612     addptr(data, (int32_t) DataLayout::counter_increment);
1613     bind(L);
1614   } else {
1615     assert(DataLayout::counter_increment == 1,
1616            "flow-free idiom only works with 1");
1617     // Increment the register.  Set carry flag.
1618     addptr(data, DataLayout::counter_increment);
1619     // If the increment causes the counter to overflow, pull back by 1.
1620     sbbptr(data, (int32_t)0);
1621   }
1622 }
1623 
1624 
1625 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
1626                                                       Register reg,
1627                                                       int constant,
1628                                                       bool decrement) {
1629   Address data(mdp_in, reg, Address::times_1, constant);
1630 
1631   increment_mdp_data_at(data, decrement);
1632 }
1633 
1634 void InterpreterMacroAssembler::set_mdp_flag_at(Register mdp_in,
1635                                                 int flag_byte_constant) {
1636   assert(ProfileInterpreter, "must be profiling interpreter");
1637   int header_offset = in_bytes(DataLayout::flags_offset());
1638   int header_bits = flag_byte_constant;
1639   // Set the flag
1640   orb(Address(mdp_in, header_offset), header_bits);
1641 }
1642 
1643 
1644 
1645 void InterpreterMacroAssembler::test_mdp_data_at(Register mdp_in,
1646                                                  int offset,
1647                                                  Register value,
1648                                                  Register test_value_out,
1649                                                  Label& not_equal_continue) {
1650   assert(ProfileInterpreter, "must be profiling interpreter");
1651   if (test_value_out == noreg) {
1652     cmpptr(value, Address(mdp_in, offset));
1653   } else {
1654     // Put the test value into a register, so caller can use it:
1655     movptr(test_value_out, Address(mdp_in, offset));
1656     cmpptr(test_value_out, value);
1657   }
1658   jcc(Assembler::notEqual, not_equal_continue);
1659 }
1660 
1661 
1662 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,
1663                                                      int offset_of_disp) {
1664   assert(ProfileInterpreter, "must be profiling interpreter");
1665   Address disp_address(mdp_in, offset_of_disp);
1666   addptr(mdp_in, disp_address);
1667   movptr(Address(rbp, frame::interpreter_frame_mdp_offset * wordSize), mdp_in);
1668 }
1669 
1670 
1671 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,
1672                                                      Register reg,
1673                                                      int offset_of_disp) {
1674   assert(ProfileInterpreter, "must be profiling interpreter");
1675   Address disp_address(mdp_in, reg, Address::times_1, offset_of_disp);
1676   addptr(mdp_in, disp_address);
1677   movptr(Address(rbp, frame::interpreter_frame_mdp_offset * wordSize), mdp_in);
1678 }
1679 
1680 
1681 void InterpreterMacroAssembler::update_mdp_by_constant(Register mdp_in,
1682                                                        int constant) {
1683   assert(ProfileInterpreter, "must be profiling interpreter");
1684   addptr(mdp_in, constant);
1685   movptr(Address(rbp, frame::interpreter_frame_mdp_offset * wordSize), mdp_in);
1686 }
1687 
1688 
1689 void InterpreterMacroAssembler::update_mdp_for_ret(Register return_bci) {
1690   assert(ProfileInterpreter, "must be profiling interpreter");
1691   push(return_bci); // save/restore across call_VM
1692   call_VM(noreg,
1693           CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret),
1694           return_bci);
1695   pop(return_bci);
1696 }
1697 
1698 
1699 void InterpreterMacroAssembler::profile_taken_branch(Register mdp,
1700                                                      Register bumped_count) {
1701   if (ProfileInterpreter) {
1702     Label profile_continue;
1703 
1704     // If no method data exists, go to profile_continue.
1705     // Otherwise, assign to mdp
1706     test_method_data_pointer(mdp, profile_continue);
1707 
1708     // We are taking a branch.  Increment the taken count.
1709     // We inline increment_mdp_data_at to return bumped_count in a register
1710     //increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset()));
1711     Address data(mdp, in_bytes(JumpData::taken_offset()));
1712     movptr(bumped_count, data);
1713     assert(DataLayout::counter_increment == 1,
1714             "flow-free idiom only works with 1");
1715     addptr(bumped_count, DataLayout::counter_increment);
1716     sbbptr(bumped_count, 0);
1717     movptr(data, bumped_count); // Store back out
1718 
1719     // The method data pointer needs to be updated to reflect the new target.
1720     update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset()));
1721     bind(profile_continue);
1722   }
1723 }
1724 
1725 
1726 void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp, bool acmp) {
1727   if (ProfileInterpreter) {
1728     Label profile_continue;
1729 
1730     // If no method data exists, go to profile_continue.
1731     test_method_data_pointer(mdp, profile_continue);
1732 
1733     // We are taking a branch.  Increment the not taken count.
1734     increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset()));
1735 
1736     // The method data pointer needs to be updated to correspond to
1737     // the next bytecode
1738     update_mdp_by_constant(mdp, acmp ? in_bytes(ACmpData::acmp_data_size()): in_bytes(BranchData::branch_data_size()));
1739     bind(profile_continue);
1740   }
1741 }
1742 
1743 void InterpreterMacroAssembler::profile_call(Register mdp) {
1744   if (ProfileInterpreter) {
1745     Label profile_continue;
1746 
1747     // If no method data exists, go to profile_continue.
1748     test_method_data_pointer(mdp, profile_continue);
1749 
1750     // We are making a call.  Increment the count.
1751     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1752 
1753     // The method data pointer needs to be updated to reflect the new target.
1754     update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size()));
1755     bind(profile_continue);
1756   }
1757 }
1758 
1759 
1760 void InterpreterMacroAssembler::profile_final_call(Register mdp) {
1761   if (ProfileInterpreter) {
1762     Label profile_continue;
1763 
1764     // If no method data exists, go to profile_continue.
1765     test_method_data_pointer(mdp, profile_continue);
1766 
1767     // We are making a call.  Increment the count.
1768     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1769 
1770     // The method data pointer needs to be updated to reflect the new target.
1771     update_mdp_by_constant(mdp,
1772                            in_bytes(VirtualCallData::
1773                                     virtual_call_data_size()));
1774     bind(profile_continue);
1775   }
1776 }
1777 
1778 
1779 void InterpreterMacroAssembler::profile_virtual_call(Register receiver,
1780                                                      Register mdp,
1781                                                      Register reg2,
1782                                                      bool receiver_can_be_null) {
1783   if (ProfileInterpreter) {
1784     Label profile_continue;
1785 
1786     // If no method data exists, go to profile_continue.
1787     test_method_data_pointer(mdp, profile_continue);
1788 
1789     Label skip_receiver_profile;
1790     if (receiver_can_be_null) {
1791       Label not_null;
1792       testptr(receiver, receiver);
1793       jccb(Assembler::notZero, not_null);
1794       // We are making a call.  Increment the count for null receiver.
1795       increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1796       jmp(skip_receiver_profile);
1797       bind(not_null);
1798     }
1799 
1800     // Record the receiver type.
1801     record_klass_in_profile(receiver, mdp, reg2, true);
1802     bind(skip_receiver_profile);
1803 
1804     // The method data pointer needs to be updated to reflect the new target.
1805     update_mdp_by_constant(mdp, in_bytes(VirtualCallData::virtual_call_data_size()));
1806     bind(profile_continue);
1807   }
1808 }
1809 
1810 // This routine creates a state machine for updating the multi-row
1811 // type profile at a virtual call site (or other type-sensitive bytecode).
1812 // The machine visits each row (of receiver/count) until the receiver type
1813 // is found, or until it runs out of rows.  At the same time, it remembers
1814 // the location of the first empty row.  (An empty row records null for its
1815 // receiver, and can be allocated for a newly-observed receiver type.)
1816 // Because there are two degrees of freedom in the state, a simple linear
1817 // search will not work; it must be a decision tree.  Hence this helper
1818 // function is recursive, to generate the required tree structured code.
1819 // It's the interpreter, so we are trading off code space for speed.
1820 // See below for example code.
1821 void InterpreterMacroAssembler::record_klass_in_profile_helper(
1822                                         Register receiver, Register mdp,
1823                                         Register reg2, int start_row,
1824                                         Label& done, bool is_virtual_call) {
1825   if (TypeProfileWidth == 0) {
1826     if (is_virtual_call) {
1827       increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1828     }
1829 #if INCLUDE_JVMCI
1830     else if (EnableJVMCI) {
1831       increment_mdp_data_at(mdp, in_bytes(ReceiverTypeData::nonprofiled_receiver_count_offset()));
1832     }
1833 #endif // INCLUDE_JVMCI
1834   } else {
1835     int non_profiled_offset = -1;
1836     if (is_virtual_call) {
1837       non_profiled_offset = in_bytes(CounterData::count_offset());
1838     }
1839 #if INCLUDE_JVMCI
1840     else if (EnableJVMCI) {
1841       non_profiled_offset = in_bytes(ReceiverTypeData::nonprofiled_receiver_count_offset());
1842     }
1843 #endif // INCLUDE_JVMCI
1844 
1845     record_item_in_profile_helper(receiver, mdp, reg2, 0, done, TypeProfileWidth,
1846         &VirtualCallData::receiver_offset, &VirtualCallData::receiver_count_offset, non_profiled_offset);
1847   }
1848 }
1849 
1850 void InterpreterMacroAssembler::record_item_in_profile_helper(Register item, Register mdp,
1851                                         Register reg2, int start_row, Label& done, int total_rows,
1852                                         OffsetFunction item_offset_fn, OffsetFunction item_count_offset_fn,
1853                                         int non_profiled_offset) {
1854   int last_row = total_rows - 1;
1855   assert(start_row <= last_row, "must be work left to do");
1856   // Test this row for both the item and for null.
1857   // Take any of three different outcomes:
1858   //   1. found item => increment count and goto done
1859   //   2. found null => keep looking for case 1, maybe allocate this cell
1860   //   3. found something else => keep looking for cases 1 and 2
1861   // Case 3 is handled by a recursive call.
1862   for (int row = start_row; row <= last_row; row++) {
1863     Label next_test;
1864     bool test_for_null_also = (row == start_row);
1865 
1866     // See if the item is item[n].
1867     int item_offset = in_bytes(item_offset_fn(row));
1868     test_mdp_data_at(mdp, item_offset, item,
1869                      (test_for_null_also ? reg2 : noreg),
1870                      next_test);
1871     // (Reg2 now contains the item from the CallData.)
1872 
1873     // The item is item[n].  Increment count[n].
1874     int count_offset = in_bytes(item_count_offset_fn(row));
1875     increment_mdp_data_at(mdp, count_offset);
1876     jmp(done);
1877     bind(next_test);
1878 
1879     if (test_for_null_also) {
1880       // Failed the equality check on item[n]...  Test for null.
1881       testptr(reg2, reg2);
1882       if (start_row == last_row) {
1883         // The only thing left to do is handle the null case.
1884         if (non_profiled_offset >= 0) {
1885           Label found_null;
1886           jccb(Assembler::zero, found_null);
1887           // Item did not match any saved item and there is no empty row for it.
1888           // Increment total counter to indicate polymorphic case.
1889           increment_mdp_data_at(mdp, non_profiled_offset);
1890           jmp(done);
1891           bind(found_null);
1892         } else {
1893           jcc(Assembler::notZero, done);
1894         }
1895         break;
1896       }
1897       Label found_null;
1898       // Since null is rare, make it be the branch-taken case.
1899       jcc(Assembler::zero, found_null);
1900 
1901       // Put all the "Case 3" tests here.
1902       record_item_in_profile_helper(item, mdp, reg2, start_row + 1, done, total_rows,
1903         item_offset_fn, item_count_offset_fn, non_profiled_offset);
1904 
1905       // Found a null.  Keep searching for a matching item,
1906       // but remember that this is an empty (unused) slot.
1907       bind(found_null);
1908     }
1909   }
1910 
1911   // In the fall-through case, we found no matching item, but we
1912   // observed the item[start_row] is NULL.
1913 
1914   // Fill in the item field and increment the count.
1915   int item_offset = in_bytes(item_offset_fn(start_row));
1916   set_mdp_data_at(mdp, item_offset, item);
1917   int count_offset = in_bytes(item_count_offset_fn(start_row));
1918   movl(reg2, DataLayout::counter_increment);
1919   set_mdp_data_at(mdp, count_offset, reg2);
1920   if (start_row > 0) {
1921     jmp(done);
1922   }
1923 }
1924 
1925 // Example state machine code for three profile rows:
1926 //   // main copy of decision tree, rooted at row[1]
1927 //   if (row[0].rec == rec) { row[0].incr(); goto done; }
1928 //   if (row[0].rec != NULL) {
1929 //     // inner copy of decision tree, rooted at row[1]
1930 //     if (row[1].rec == rec) { row[1].incr(); goto done; }
1931 //     if (row[1].rec != NULL) {
1932 //       // degenerate decision tree, rooted at row[2]
1933 //       if (row[2].rec == rec) { row[2].incr(); goto done; }
1934 //       if (row[2].rec != NULL) { count.incr(); goto done; } // overflow
1935 //       row[2].init(rec); goto done;
1936 //     } else {
1937 //       // remember row[1] is empty
1938 //       if (row[2].rec == rec) { row[2].incr(); goto done; }
1939 //       row[1].init(rec); goto done;
1940 //     }
1941 //   } else {
1942 //     // remember row[0] is empty
1943 //     if (row[1].rec == rec) { row[1].incr(); goto done; }
1944 //     if (row[2].rec == rec) { row[2].incr(); goto done; }
1945 //     row[0].init(rec); goto done;
1946 //   }
1947 //   done:
1948 
1949 void InterpreterMacroAssembler::record_klass_in_profile(Register receiver,
1950                                                         Register mdp, Register reg2,
1951                                                         bool is_virtual_call) {
1952   assert(ProfileInterpreter, "must be profiling");
1953   Label done;
1954 
1955   record_klass_in_profile_helper(receiver, mdp, reg2, 0, done, is_virtual_call);
1956 
1957   bind (done);
1958 }
1959 
1960 void InterpreterMacroAssembler::profile_ret(Register return_bci,
1961                                             Register mdp) {
1962   if (ProfileInterpreter) {
1963     Label profile_continue;
1964     uint row;
1965 
1966     // If no method data exists, go to profile_continue.
1967     test_method_data_pointer(mdp, profile_continue);
1968 
1969     // Update the total ret count.
1970     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1971 
1972     for (row = 0; row < RetData::row_limit(); row++) {
1973       Label next_test;
1974 
1975       // See if return_bci is equal to bci[n]:
1976       test_mdp_data_at(mdp,
1977                        in_bytes(RetData::bci_offset(row)),
1978                        return_bci, noreg,
1979                        next_test);
1980 
1981       // return_bci is equal to bci[n].  Increment the count.
1982       increment_mdp_data_at(mdp, in_bytes(RetData::bci_count_offset(row)));
1983 
1984       // The method data pointer needs to be updated to reflect the new target.
1985       update_mdp_by_offset(mdp,
1986                            in_bytes(RetData::bci_displacement_offset(row)));
1987       jmp(profile_continue);
1988       bind(next_test);
1989     }
1990 
1991     update_mdp_for_ret(return_bci);
1992 
1993     bind(profile_continue);
1994   }
1995 }
1996 
1997 
1998 void InterpreterMacroAssembler::profile_null_seen(Register mdp) {
1999   if (ProfileInterpreter) {
2000     Label profile_continue;
2001 
2002     // If no method data exists, go to profile_continue.
2003     test_method_data_pointer(mdp, profile_continue);
2004 
2005     set_mdp_flag_at(mdp, BitData::null_seen_byte_constant());
2006 
2007     // The method data pointer needs to be updated.
2008     int mdp_delta = in_bytes(BitData::bit_data_size());
2009     if (TypeProfileCasts) {
2010       mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
2011     }
2012     update_mdp_by_constant(mdp, mdp_delta);
2013 
2014     bind(profile_continue);
2015   }
2016 }
2017 
2018 
2019 void InterpreterMacroAssembler::profile_typecheck_failed(Register mdp) {
2020   if (ProfileInterpreter && TypeProfileCasts) {
2021     Label profile_continue;
2022 
2023     // If no method data exists, go to profile_continue.
2024     test_method_data_pointer(mdp, profile_continue);
2025 
2026     int count_offset = in_bytes(CounterData::count_offset());
2027     // Back up the address, since we have already bumped the mdp.
2028     count_offset -= in_bytes(VirtualCallData::virtual_call_data_size());
2029 
2030     // *Decrement* the counter.  We expect to see zero or small negatives.
2031     increment_mdp_data_at(mdp, count_offset, true);
2032 
2033     bind (profile_continue);
2034   }
2035 }
2036 
2037 
2038 void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2) {
2039   if (ProfileInterpreter) {
2040     Label profile_continue;
2041 
2042     // If no method data exists, go to profile_continue.
2043     test_method_data_pointer(mdp, profile_continue);
2044 
2045     // The method data pointer needs to be updated.
2046     int mdp_delta = in_bytes(BitData::bit_data_size());
2047     if (TypeProfileCasts) {
2048       mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
2049 
2050       // Record the object type.
2051       record_klass_in_profile(klass, mdp, reg2, false);
2052       NOT_LP64(assert(reg2 == rdi, "we know how to fix this blown reg");)
2053       NOT_LP64(restore_locals();)         // Restore EDI
2054     }
2055     update_mdp_by_constant(mdp, mdp_delta);
2056 
2057     bind(profile_continue);
2058   }
2059 }
2060 
2061 
2062 void InterpreterMacroAssembler::profile_switch_default(Register mdp) {
2063   if (ProfileInterpreter) {
2064     Label profile_continue;
2065 
2066     // If no method data exists, go to profile_continue.
2067     test_method_data_pointer(mdp, profile_continue);
2068 
2069     // Update the default case count
2070     increment_mdp_data_at(mdp,
2071                           in_bytes(MultiBranchData::default_count_offset()));
2072 
2073     // The method data pointer needs to be updated.
2074     update_mdp_by_offset(mdp,
2075                          in_bytes(MultiBranchData::
2076                                   default_displacement_offset()));
2077 
2078     bind(profile_continue);
2079   }
2080 }
2081 
2082 
2083 void InterpreterMacroAssembler::profile_switch_case(Register index,
2084                                                     Register mdp,
2085                                                     Register reg2) {
2086   if (ProfileInterpreter) {
2087     Label profile_continue;
2088 
2089     // If no method data exists, go to profile_continue.
2090     test_method_data_pointer(mdp, profile_continue);
2091 
2092     // Build the base (index * per_case_size_in_bytes()) +
2093     // case_array_offset_in_bytes()
2094     movl(reg2, in_bytes(MultiBranchData::per_case_size()));
2095     imulptr(index, reg2); // XXX l ?
2096     addptr(index, in_bytes(MultiBranchData::case_array_offset())); // XXX l ?
2097 
2098     // Update the case count
2099     increment_mdp_data_at(mdp,
2100                           index,
2101                           in_bytes(MultiBranchData::relative_count_offset()));
2102 
2103     // The method data pointer needs to be updated.
2104     update_mdp_by_offset(mdp,
2105                          index,
2106                          in_bytes(MultiBranchData::
2107                                   relative_displacement_offset()));
2108 
2109     bind(profile_continue);
2110   }
2111 }
2112 
2113 void InterpreterMacroAssembler::profile_array(Register mdp,
2114                                               Register array,
2115                                               Register tmp) {
2116   if (ProfileInterpreter) {
2117     Label profile_continue;
2118 
2119     // If no method data exists, go to profile_continue.
2120     test_method_data_pointer(mdp, profile_continue);
2121 
2122     mov(tmp, array);
2123     profile_obj_type(tmp, Address(mdp, in_bytes(ArrayLoadStoreData::array_offset())));
2124 
2125     Label not_flat;
2126     test_non_flattened_array_oop(array, tmp, not_flat);
2127 
2128     set_mdp_flag_at(mdp, ArrayLoadStoreData::flat_array_byte_constant());
2129 
2130     bind(not_flat);
2131 
2132     Label not_null_free;
2133     test_non_null_free_array_oop(array, tmp, not_null_free);
2134 
2135     set_mdp_flag_at(mdp, ArrayLoadStoreData::null_free_array_byte_constant());
2136 
2137     bind(not_null_free);
2138 
2139     bind(profile_continue);
2140   }
2141 }
2142 
2143 void InterpreterMacroAssembler::profile_element(Register mdp,
2144                                                 Register element,
2145                                                 Register tmp) {
2146   if (ProfileInterpreter) {
2147     Label profile_continue;
2148 
2149     // If no method data exists, go to profile_continue.
2150     test_method_data_pointer(mdp, profile_continue);
2151 
2152     mov(tmp, element);
2153     profile_obj_type(tmp, Address(mdp, in_bytes(ArrayLoadStoreData::element_offset())));
2154 
2155     // The method data pointer needs to be updated.
2156     update_mdp_by_constant(mdp, in_bytes(ArrayLoadStoreData::array_load_store_data_size()));
2157 
2158     bind(profile_continue);
2159   }
2160 }
2161 
2162 void InterpreterMacroAssembler::profile_acmp(Register mdp,
2163                                              Register left,
2164                                              Register right,
2165                                              Register tmp) {
2166   if (ProfileInterpreter) {
2167     Label profile_continue;
2168 
2169     // If no method data exists, go to profile_continue.
2170     test_method_data_pointer(mdp, profile_continue);
2171 
2172     mov(tmp, left);
2173     profile_obj_type(tmp, Address(mdp, in_bytes(ACmpData::left_offset())));
2174 
2175     Label left_not_inline_type;
2176     test_oop_is_not_inline_type(left, tmp, left_not_inline_type);
2177     set_mdp_flag_at(mdp, ACmpData::left_inline_type_byte_constant());
2178     bind(left_not_inline_type);
2179 
2180     mov(tmp, right);
2181     profile_obj_type(tmp, Address(mdp, in_bytes(ACmpData::right_offset())));
2182 
2183     Label right_not_inline_type;
2184     test_oop_is_not_inline_type(right, tmp, right_not_inline_type);
2185     set_mdp_flag_at(mdp, ACmpData::right_inline_type_byte_constant());
2186     bind(right_not_inline_type);
2187 
2188     bind(profile_continue);
2189   }
2190 }
2191 
2192 
2193 void InterpreterMacroAssembler::_interp_verify_oop(Register reg, TosState state, const char* file, int line) {
2194   if (state == atos) {
2195     MacroAssembler::_verify_oop_checked(reg, "broken oop", file, line);
2196   }
2197 }
2198 
2199 void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) {
2200 #ifndef _LP64
2201   if ((state == ftos && UseSSE < 1) ||
2202       (state == dtos && UseSSE < 2)) {
2203     MacroAssembler::verify_FPU(stack_depth);
2204   }
2205 #endif
2206 }
2207 
2208 // Jump if ((*counter_addr += increment) & mask) == 0
2209 void InterpreterMacroAssembler::increment_mask_and_jump(Address counter_addr, Address mask,
2210                                                         Register scratch, Label* where) {
2211   // This update is actually not atomic and can lose a number of updates
2212   // under heavy contention, but the alternative of using the (contended)
2213   // atomic update here penalizes profiling paths too much.
2214   movl(scratch, counter_addr);
2215   incrementl(scratch, InvocationCounter::count_increment);
2216   movl(counter_addr, scratch);
2217   andl(scratch, mask);
2218   if (where != NULL) {
2219     jcc(Assembler::zero, *where);
2220   }
2221 }
2222 
2223 void InterpreterMacroAssembler::notify_method_entry() {
2224   // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
2225   // track stack depth.  If it is possible to enter interp_only_mode we add
2226   // the code to check if the event should be sent.
2227   Register rthread = LP64_ONLY(r15_thread) NOT_LP64(rcx);
2228   Register rarg = LP64_ONLY(c_rarg1) NOT_LP64(rbx);
2229   if (JvmtiExport::can_post_interpreter_events()) {
2230     Label L;
2231     NOT_LP64(get_thread(rthread);)
2232     movl(rdx, Address(rthread, JavaThread::interp_only_mode_offset()));
2233     testl(rdx, rdx);
2234     jcc(Assembler::zero, L);
2235     call_VM(noreg, CAST_FROM_FN_PTR(address,
2236                                     InterpreterRuntime::post_method_entry));
2237     bind(L);
2238   }
2239 
2240   {
2241     SkipIfEqual skip(this, &DTraceMethodProbes, false);
2242     NOT_LP64(get_thread(rthread);)
2243     get_method(rarg);
2244     call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry),
2245                  rthread, rarg);
2246   }
2247 
2248   // RedefineClasses() tracing support for obsolete method entry
2249   if (log_is_enabled(Trace, redefine, class, obsolete)) {
2250     NOT_LP64(get_thread(rthread);)
2251     get_method(rarg);
2252     call_VM_leaf(
2253       CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry),
2254       rthread, rarg);
2255   }
2256 }
2257 
2258 
2259 void InterpreterMacroAssembler::notify_method_exit(
2260     TosState state, NotifyMethodExitMode mode) {
2261   // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
2262   // track stack depth.  If it is possible to enter interp_only_mode we add
2263   // the code to check if the event should be sent.
2264   Register rthread = LP64_ONLY(r15_thread) NOT_LP64(rcx);
2265   Register rarg = LP64_ONLY(c_rarg1) NOT_LP64(rbx);
2266   if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) {
2267     Label L;
2268     // Note: frame::interpreter_frame_result has a dependency on how the
2269     // method result is saved across the call to post_method_exit. If this
2270     // is changed then the interpreter_frame_result implementation will
2271     // need to be updated too.
2272 
2273     // template interpreter will leave the result on the top of the stack.
2274     push(state);
2275     NOT_LP64(get_thread(rthread);)
2276     movl(rdx, Address(rthread, JavaThread::interp_only_mode_offset()));
2277     testl(rdx, rdx);
2278     jcc(Assembler::zero, L);
2279     call_VM(noreg,
2280             CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit));
2281     bind(L);
2282     pop(state);
2283   }
2284 
2285   {
2286     SkipIfEqual skip(this, &DTraceMethodProbes, false);
2287     push(state);
2288     NOT_LP64(get_thread(rthread);)
2289     get_method(rarg);
2290     call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),
2291                  rthread, rarg);
2292     pop(state);
2293   }
2294 }