src/cpu/x86/vm/interp_masm_x86_64.cpp

Tue, 24 Jul 2012 10:51:00 -0700

author
twisti
date
Tue, 24 Jul 2012 10:51:00 -0700
changeset 3969
1d7922586cf6
parent 3156
f08d439fab8c
child 4037
da91efe96a93
permissions
-rw-r--r--

7023639: JSR 292 method handle invocation needs a fast path for compiled code
6984705: JSR 292 method handle creation should not go through JNI
Summary: remove assembly code for JDK 7 chained method handles
Reviewed-by: jrose, twisti, kvn, mhaupt
Contributed-by: John Rose <john.r.rose@oracle.com>, Christian Thalinger <christian.thalinger@oracle.com>, Michael Haupt <michael.haupt@oracle.com>

     1 /*
     2  * Copyright (c) 2003, 2011, 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  */
    25 #include "precompiled.hpp"
    26 #include "interp_masm_x86_64.hpp"
    27 #include "interpreter/interpreter.hpp"
    28 #include "interpreter/interpreterRuntime.hpp"
    29 #include "oops/arrayOop.hpp"
    30 #include "oops/markOop.hpp"
    31 #include "oops/methodDataOop.hpp"
    32 #include "oops/methodOop.hpp"
    33 #include "prims/jvmtiExport.hpp"
    34 #include "prims/jvmtiRedefineClassesTrace.hpp"
    35 #include "prims/jvmtiThreadState.hpp"
    36 #include "runtime/basicLock.hpp"
    37 #include "runtime/biasedLocking.hpp"
    38 #include "runtime/sharedRuntime.hpp"
    39 #ifdef TARGET_OS_FAMILY_linux
    40 # include "thread_linux.inline.hpp"
    41 #endif
    42 #ifdef TARGET_OS_FAMILY_solaris
    43 # include "thread_solaris.inline.hpp"
    44 #endif
    45 #ifdef TARGET_OS_FAMILY_windows
    46 # include "thread_windows.inline.hpp"
    47 #endif
    48 #ifdef TARGET_OS_FAMILY_bsd
    49 # include "thread_bsd.inline.hpp"
    50 #endif
    53 // Implementation of InterpreterMacroAssembler
    55 #ifdef CC_INTERP
    56 void InterpreterMacroAssembler::get_method(Register reg) {
    57   movptr(reg, Address(rbp, -((int)sizeof(BytecodeInterpreter) + 2 * wordSize)));
    58   movptr(reg, Address(reg, byte_offset_of(BytecodeInterpreter, _method)));
    59 }
    60 #endif // CC_INTERP
    62 #ifndef CC_INTERP
    64 void InterpreterMacroAssembler::call_VM_leaf_base(address entry_point,
    65                                                   int number_of_arguments) {
    66   // interpreter specific
    67   //
    68   // Note: No need to save/restore bcp & locals (r13 & r14) pointer
    69   //       since these are callee saved registers and no blocking/
    70   //       GC can happen in leaf calls.
    71   // Further Note: DO NOT save/restore bcp/locals. If a caller has
    72   // already saved them so that it can use esi/edi as temporaries
    73   // then a save/restore here will DESTROY the copy the caller
    74   // saved! There used to be a save_bcp() that only happened in
    75   // the ASSERT path (no restore_bcp). Which caused bizarre failures
    76   // when jvm built with ASSERTs.
    77 #ifdef ASSERT
    78   {
    79     Label L;
    80     cmpptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
    81     jcc(Assembler::equal, L);
    82     stop("InterpreterMacroAssembler::call_VM_leaf_base:"
    83          " last_sp != NULL");
    84     bind(L);
    85   }
    86 #endif
    87   // super call
    88   MacroAssembler::call_VM_leaf_base(entry_point, number_of_arguments);
    89   // interpreter specific
    90   // Used to ASSERT that r13/r14 were equal to frame's bcp/locals
    91   // but since they may not have been saved (and we don't want to
    92   // save thme here (see note above) the assert is invalid.
    93 }
    95 void InterpreterMacroAssembler::call_VM_base(Register oop_result,
    96                                              Register java_thread,
    97                                              Register last_java_sp,
    98                                              address  entry_point,
    99                                              int      number_of_arguments,
   100                                              bool     check_exceptions) {
   101   // interpreter specific
   102   //
   103   // Note: Could avoid restoring locals ptr (callee saved) - however doesn't
   104   //       really make a difference for these runtime calls, since they are
   105   //       slow anyway. Btw., bcp must be saved/restored since it may change
   106   //       due to GC.
   107   // assert(java_thread == noreg , "not expecting a precomputed java thread");
   108   save_bcp();
   109 #ifdef ASSERT
   110   {
   111     Label L;
   112     cmpptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
   113     jcc(Assembler::equal, L);
   114     stop("InterpreterMacroAssembler::call_VM_leaf_base:"
   115          " last_sp != NULL");
   116     bind(L);
   117   }
   118 #endif /* ASSERT */
   119   // super call
   120   MacroAssembler::call_VM_base(oop_result, noreg, last_java_sp,
   121                                entry_point, number_of_arguments,
   122                                check_exceptions);
   123   // interpreter specific
   124   restore_bcp();
   125   restore_locals();
   126 }
   129 void InterpreterMacroAssembler::check_and_handle_popframe(Register java_thread) {
   130   if (JvmtiExport::can_pop_frame()) {
   131     Label L;
   132     // Initiate popframe handling only if it is not already being
   133     // processed.  If the flag has the popframe_processing bit set, it
   134     // means that this code is called *during* popframe handling - we
   135     // don't want to reenter.
   136     // This method is only called just after the call into the vm in
   137     // call_VM_base, so the arg registers are available.
   138     movl(c_rarg0, Address(r15_thread, JavaThread::popframe_condition_offset()));
   139     testl(c_rarg0, JavaThread::popframe_pending_bit);
   140     jcc(Assembler::zero, L);
   141     testl(c_rarg0, JavaThread::popframe_processing_bit);
   142     jcc(Assembler::notZero, L);
   143     // Call Interpreter::remove_activation_preserving_args_entry() to get the
   144     // address of the same-named entrypoint in the generated interpreter code.
   145     call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_preserving_args_entry));
   146     jmp(rax);
   147     bind(L);
   148   }
   149 }
   152 void InterpreterMacroAssembler::load_earlyret_value(TosState state) {
   153   movptr(rcx, Address(r15_thread, JavaThread::jvmti_thread_state_offset()));
   154   const Address tos_addr(rcx, JvmtiThreadState::earlyret_tos_offset());
   155   const Address oop_addr(rcx, JvmtiThreadState::earlyret_oop_offset());
   156   const Address val_addr(rcx, JvmtiThreadState::earlyret_value_offset());
   157   switch (state) {
   158     case atos: movptr(rax, oop_addr);
   159                movptr(oop_addr, (int32_t)NULL_WORD);
   160                verify_oop(rax, state);              break;
   161     case ltos: movptr(rax, val_addr);                 break;
   162     case btos:                                   // fall through
   163     case ctos:                                   // fall through
   164     case stos:                                   // fall through
   165     case itos: movl(rax, val_addr);                 break;
   166     case ftos: movflt(xmm0, val_addr);              break;
   167     case dtos: movdbl(xmm0, val_addr);              break;
   168     case vtos: /* nothing to do */                  break;
   169     default  : ShouldNotReachHere();
   170   }
   171   // Clean up tos value in the thread object
   172   movl(tos_addr,  (int) ilgl);
   173   movl(val_addr,  (int32_t) NULL_WORD);
   174 }
   177 void InterpreterMacroAssembler::check_and_handle_earlyret(Register java_thread) {
   178   if (JvmtiExport::can_force_early_return()) {
   179     Label L;
   180     movptr(c_rarg0, Address(r15_thread, JavaThread::jvmti_thread_state_offset()));
   181     testptr(c_rarg0, c_rarg0);
   182     jcc(Assembler::zero, L); // if (thread->jvmti_thread_state() == NULL) exit;
   184     // Initiate earlyret handling only if it is not already being processed.
   185     // If the flag has the earlyret_processing bit set, it means that this code
   186     // is called *during* earlyret handling - we don't want to reenter.
   187     movl(c_rarg0, Address(c_rarg0, JvmtiThreadState::earlyret_state_offset()));
   188     cmpl(c_rarg0, JvmtiThreadState::earlyret_pending);
   189     jcc(Assembler::notEqual, L);
   191     // Call Interpreter::remove_activation_early_entry() to get the address of the
   192     // same-named entrypoint in the generated interpreter code.
   193     movptr(c_rarg0, Address(r15_thread, JavaThread::jvmti_thread_state_offset()));
   194     movl(c_rarg0, Address(c_rarg0, JvmtiThreadState::earlyret_tos_offset()));
   195     call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry), c_rarg0);
   196     jmp(rax);
   197     bind(L);
   198   }
   199 }
   202 void InterpreterMacroAssembler::get_unsigned_2_byte_index_at_bcp(
   203   Register reg,
   204   int bcp_offset) {
   205   assert(bcp_offset >= 0, "bcp is still pointing to start of bytecode");
   206   movl(reg, Address(r13, bcp_offset));
   207   bswapl(reg);
   208   shrl(reg, 16);
   209 }
   212 void InterpreterMacroAssembler::get_cache_index_at_bcp(Register index,
   213                                                        int bcp_offset,
   214                                                        size_t index_size) {
   215   assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");
   216   if (index_size == sizeof(u2)) {
   217     load_unsigned_short(index, Address(r13, bcp_offset));
   218   } else if (index_size == sizeof(u4)) {
   219     assert(EnableInvokeDynamic, "giant index used only for JSR 292");
   220     movl(index, Address(r13, bcp_offset));
   221     // Check if the secondary index definition is still ~x, otherwise
   222     // we have to change the following assembler code to calculate the
   223     // plain index.
   224     assert(constantPoolCacheOopDesc::decode_secondary_index(~123) == 123, "else change next line");
   225     notl(index);  // convert to plain index
   226   } else if (index_size == sizeof(u1)) {
   227     assert(EnableInvokeDynamic, "tiny index used only for JSR 292");
   228     load_unsigned_byte(index, Address(r13, bcp_offset));
   229   } else {
   230     ShouldNotReachHere();
   231   }
   232 }
   235 void InterpreterMacroAssembler::get_cache_and_index_at_bcp(Register cache,
   236                                                            Register index,
   237                                                            int bcp_offset,
   238                                                            size_t index_size) {
   239   assert_different_registers(cache, index);
   240   get_cache_index_at_bcp(index, bcp_offset, index_size);
   241   movptr(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize));
   242   assert(sizeof(ConstantPoolCacheEntry) == 4 * wordSize, "adjust code below");
   243   // convert from field index to ConstantPoolCacheEntry index
   244   shll(index, 2);
   245 }
   248 void InterpreterMacroAssembler::get_cache_and_index_and_bytecode_at_bcp(Register cache,
   249                                                                         Register index,
   250                                                                         Register bytecode,
   251                                                                         int byte_no,
   252                                                                         int bcp_offset,
   253                                                                         size_t index_size) {
   254   get_cache_and_index_at_bcp(cache, index, bcp_offset, index_size);
   255   // We use a 32-bit load here since the layout of 64-bit words on
   256   // little-endian machines allow us that.
   257   movl(bytecode, Address(cache, index, Address::times_ptr, constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::indices_offset()));
   258   const int shift_count = (1 + byte_no) * BitsPerByte;
   259   assert((byte_no == TemplateTable::f1_byte && shift_count == ConstantPoolCacheEntry::bytecode_1_shift) ||
   260          (byte_no == TemplateTable::f2_byte && shift_count == ConstantPoolCacheEntry::bytecode_2_shift),
   261          "correct shift count");
   262   shrl(bytecode, shift_count);
   263   assert(ConstantPoolCacheEntry::bytecode_1_mask == ConstantPoolCacheEntry::bytecode_2_mask, "common mask");
   264   andl(bytecode, ConstantPoolCacheEntry::bytecode_1_mask);
   265 }
   268 void InterpreterMacroAssembler::get_cache_entry_pointer_at_bcp(Register cache,
   269                                                                Register tmp,
   270                                                                int bcp_offset,
   271                                                                size_t index_size) {
   272   assert(cache != tmp, "must use different register");
   273   get_cache_index_at_bcp(tmp, bcp_offset, index_size);
   274   assert(sizeof(ConstantPoolCacheEntry) == 4 * wordSize, "adjust code below");
   275   // convert from field index to ConstantPoolCacheEntry index
   276   // and from word offset to byte offset
   277   shll(tmp, 2 + LogBytesPerWord);
   278   movptr(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize));
   279   // skip past the header
   280   addptr(cache, in_bytes(constantPoolCacheOopDesc::base_offset()));
   281   addptr(cache, tmp);  // construct pointer to cache entry
   282 }
   285 // Generate a subtype check: branch to ok_is_subtype if sub_klass is a
   286 // subtype of super_klass.
   287 //
   288 // Args:
   289 //      rax: superklass
   290 //      Rsub_klass: subklass
   291 //
   292 // Kills:
   293 //      rcx, rdi
   294 void InterpreterMacroAssembler::gen_subtype_check(Register Rsub_klass,
   295                                                   Label& ok_is_subtype) {
   296   assert(Rsub_klass != rax, "rax holds superklass");
   297   assert(Rsub_klass != r14, "r14 holds locals");
   298   assert(Rsub_klass != r13, "r13 holds bcp");
   299   assert(Rsub_klass != rcx, "rcx holds 2ndary super array length");
   300   assert(Rsub_klass != rdi, "rdi holds 2ndary super array scan ptr");
   302   // Profile the not-null value's klass.
   303   profile_typecheck(rcx, Rsub_klass, rdi); // blows rcx, reloads rdi
   305   // Do the check.
   306   check_klass_subtype(Rsub_klass, rax, rcx, ok_is_subtype); // blows rcx
   308   // Profile the failure of the check.
   309   profile_typecheck_failed(rcx); // blows rcx
   310 }
   314 // Java Expression Stack
   316 void InterpreterMacroAssembler::pop_ptr(Register r) {
   317   pop(r);
   318 }
   320 void InterpreterMacroAssembler::pop_i(Register r) {
   321   // XXX can't use pop currently, upper half non clean
   322   movl(r, Address(rsp, 0));
   323   addptr(rsp, wordSize);
   324 }
   326 void InterpreterMacroAssembler::pop_l(Register r) {
   327   movq(r, Address(rsp, 0));
   328   addptr(rsp, 2 * Interpreter::stackElementSize);
   329 }
   331 void InterpreterMacroAssembler::pop_f(XMMRegister r) {
   332   movflt(r, Address(rsp, 0));
   333   addptr(rsp, wordSize);
   334 }
   336 void InterpreterMacroAssembler::pop_d(XMMRegister r) {
   337   movdbl(r, Address(rsp, 0));
   338   addptr(rsp, 2 * Interpreter::stackElementSize);
   339 }
   341 void InterpreterMacroAssembler::push_ptr(Register r) {
   342   push(r);
   343 }
   345 void InterpreterMacroAssembler::push_i(Register r) {
   346   push(r);
   347 }
   349 void InterpreterMacroAssembler::push_l(Register r) {
   350   subptr(rsp, 2 * wordSize);
   351   movq(Address(rsp, 0), r);
   352 }
   354 void InterpreterMacroAssembler::push_f(XMMRegister r) {
   355   subptr(rsp, wordSize);
   356   movflt(Address(rsp, 0), r);
   357 }
   359 void InterpreterMacroAssembler::push_d(XMMRegister r) {
   360   subptr(rsp, 2 * wordSize);
   361   movdbl(Address(rsp, 0), r);
   362 }
   364 void InterpreterMacroAssembler::pop(TosState state) {
   365   switch (state) {
   366   case atos: pop_ptr();                 break;
   367   case btos:
   368   case ctos:
   369   case stos:
   370   case itos: pop_i();                   break;
   371   case ltos: pop_l();                   break;
   372   case ftos: pop_f();                   break;
   373   case dtos: pop_d();                   break;
   374   case vtos: /* nothing to do */        break;
   375   default:   ShouldNotReachHere();
   376   }
   377   verify_oop(rax, state);
   378 }
   380 void InterpreterMacroAssembler::push(TosState state) {
   381   verify_oop(rax, state);
   382   switch (state) {
   383   case atos: push_ptr();                break;
   384   case btos:
   385   case ctos:
   386   case stos:
   387   case itos: push_i();                  break;
   388   case ltos: push_l();                  break;
   389   case ftos: push_f();                  break;
   390   case dtos: push_d();                  break;
   391   case vtos: /* nothing to do */        break;
   392   default  : ShouldNotReachHere();
   393   }
   394 }
   397 // Helpers for swap and dup
   398 void InterpreterMacroAssembler::load_ptr(int n, Register val) {
   399   movptr(val, Address(rsp, Interpreter::expr_offset_in_bytes(n)));
   400 }
   402 void InterpreterMacroAssembler::store_ptr(int n, Register val) {
   403   movptr(Address(rsp, Interpreter::expr_offset_in_bytes(n)), val);
   404 }
   407 void InterpreterMacroAssembler::prepare_to_jump_from_interpreted() {
   408   // set sender sp
   409   lea(r13, Address(rsp, wordSize));
   410   // record last_sp
   411   movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), r13);
   412 }
   415 // Jump to from_interpreted entry of a call unless single stepping is possible
   416 // in this thread in which case we must call the i2i entry
   417 void InterpreterMacroAssembler::jump_from_interpreted(Register method, Register temp) {
   418   prepare_to_jump_from_interpreted();
   420   if (JvmtiExport::can_post_interpreter_events()) {
   421     Label run_compiled_code;
   422     // JVMTI events, such as single-stepping, are implemented partly by avoiding running
   423     // compiled code in threads for which the event is enabled.  Check here for
   424     // interp_only_mode if these events CAN be enabled.
   425     // interp_only is an int, on little endian it is sufficient to test the byte only
   426     // Is a cmpl faster?
   427     cmpb(Address(r15_thread, JavaThread::interp_only_mode_offset()), 0);
   428     jccb(Assembler::zero, run_compiled_code);
   429     jmp(Address(method, methodOopDesc::interpreter_entry_offset()));
   430     bind(run_compiled_code);
   431   }
   433   jmp(Address(method, methodOopDesc::from_interpreted_offset()));
   435 }
   438 // The following two routines provide a hook so that an implementation
   439 // can schedule the dispatch in two parts.  amd64 does not do this.
   440 void InterpreterMacroAssembler::dispatch_prolog(TosState state, int step) {
   441   // Nothing amd64 specific to be done here
   442 }
   444 void InterpreterMacroAssembler::dispatch_epilog(TosState state, int step) {
   445   dispatch_next(state, step);
   446 }
   448 void InterpreterMacroAssembler::dispatch_base(TosState state,
   449                                               address* table,
   450                                               bool verifyoop) {
   451   verify_FPU(1, state);
   452   if (VerifyActivationFrameSize) {
   453     Label L;
   454     mov(rcx, rbp);
   455     subptr(rcx, rsp);
   456     int32_t min_frame_size =
   457       (frame::link_offset - frame::interpreter_frame_initial_sp_offset) *
   458       wordSize;
   459     cmpptr(rcx, (int32_t)min_frame_size);
   460     jcc(Assembler::greaterEqual, L);
   461     stop("broken stack frame");
   462     bind(L);
   463   }
   464   if (verifyoop) {
   465     verify_oop(rax, state);
   466   }
   467   lea(rscratch1, ExternalAddress((address)table));
   468   jmp(Address(rscratch1, rbx, Address::times_8));
   469 }
   471 void InterpreterMacroAssembler::dispatch_only(TosState state) {
   472   dispatch_base(state, Interpreter::dispatch_table(state));
   473 }
   475 void InterpreterMacroAssembler::dispatch_only_normal(TosState state) {
   476   dispatch_base(state, Interpreter::normal_table(state));
   477 }
   479 void InterpreterMacroAssembler::dispatch_only_noverify(TosState state) {
   480   dispatch_base(state, Interpreter::normal_table(state), false);
   481 }
   484 void InterpreterMacroAssembler::dispatch_next(TosState state, int step) {
   485   // load next bytecode (load before advancing r13 to prevent AGI)
   486   load_unsigned_byte(rbx, Address(r13, step));
   487   // advance r13
   488   increment(r13, step);
   489   dispatch_base(state, Interpreter::dispatch_table(state));
   490 }
   492 void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) {
   493   // load current bytecode
   494   load_unsigned_byte(rbx, Address(r13, 0));
   495   dispatch_base(state, table);
   496 }
   498 // remove activation
   499 //
   500 // Unlock the receiver if this is a synchronized method.
   501 // Unlock any Java monitors from syncronized blocks.
   502 // Remove the activation from the stack.
   503 //
   504 // If there are locked Java monitors
   505 //    If throw_monitor_exception
   506 //       throws IllegalMonitorStateException
   507 //    Else if install_monitor_exception
   508 //       installs IllegalMonitorStateException
   509 //    Else
   510 //       no error processing
   511 void InterpreterMacroAssembler::remove_activation(
   512         TosState state,
   513         Register ret_addr,
   514         bool throw_monitor_exception,
   515         bool install_monitor_exception,
   516         bool notify_jvmdi) {
   517   // Note: Registers rdx xmm0 may be in use for the
   518   // result check if synchronized method
   519   Label unlocked, unlock, no_unlock;
   521   // get the value of _do_not_unlock_if_synchronized into rdx
   522   const Address do_not_unlock_if_synchronized(r15_thread,
   523     in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
   524   movbool(rdx, do_not_unlock_if_synchronized);
   525   movbool(do_not_unlock_if_synchronized, false); // reset the flag
   527  // get method access flags
   528   movptr(rbx, Address(rbp, frame::interpreter_frame_method_offset * wordSize));
   529   movl(rcx, Address(rbx, methodOopDesc::access_flags_offset()));
   530   testl(rcx, JVM_ACC_SYNCHRONIZED);
   531   jcc(Assembler::zero, unlocked);
   533   // Don't unlock anything if the _do_not_unlock_if_synchronized flag
   534   // is set.
   535   testbool(rdx);
   536   jcc(Assembler::notZero, no_unlock);
   538   // unlock monitor
   539   push(state); // save result
   541   // BasicObjectLock will be first in list, since this is a
   542   // synchronized method. However, need to check that the object has
   543   // not been unlocked by an explicit monitorexit bytecode.
   544   const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset *
   545                         wordSize - (int) sizeof(BasicObjectLock));
   546   // We use c_rarg1 so that if we go slow path it will be the correct
   547   // register for unlock_object to pass to VM directly
   548   lea(c_rarg1, monitor); // address of first monitor
   550   movptr(rax, Address(c_rarg1, BasicObjectLock::obj_offset_in_bytes()));
   551   testptr(rax, rax);
   552   jcc(Assembler::notZero, unlock);
   554   pop(state);
   555   if (throw_monitor_exception) {
   556     // Entry already unlocked, need to throw exception
   557     call_VM(noreg, CAST_FROM_FN_PTR(address,
   558                    InterpreterRuntime::throw_illegal_monitor_state_exception));
   559     should_not_reach_here();
   560   } else {
   561     // Monitor already unlocked during a stack unroll. If requested,
   562     // install an illegal_monitor_state_exception.  Continue with
   563     // stack unrolling.
   564     if (install_monitor_exception) {
   565       call_VM(noreg, CAST_FROM_FN_PTR(address,
   566                      InterpreterRuntime::new_illegal_monitor_state_exception));
   567     }
   568     jmp(unlocked);
   569   }
   571   bind(unlock);
   572   unlock_object(c_rarg1);
   573   pop(state);
   575   // Check that for block-structured locking (i.e., that all locked
   576   // objects has been unlocked)
   577   bind(unlocked);
   579   // rax: Might contain return value
   581   // Check that all monitors are unlocked
   582   {
   583     Label loop, exception, entry, restart;
   584     const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
   585     const Address monitor_block_top(
   586         rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
   587     const Address monitor_block_bot(
   588         rbp, frame::interpreter_frame_initial_sp_offset * wordSize);
   590     bind(restart);
   591     // We use c_rarg1 so that if we go slow path it will be the correct
   592     // register for unlock_object to pass to VM directly
   593     movptr(c_rarg1, monitor_block_top); // points to current entry, starting
   594                                   // with top-most entry
   595     lea(rbx, monitor_block_bot);  // points to word before bottom of
   596                                   // monitor block
   597     jmp(entry);
   599     // Entry already locked, need to throw exception
   600     bind(exception);
   602     if (throw_monitor_exception) {
   603       // Throw exception
   604       MacroAssembler::call_VM(noreg,
   605                               CAST_FROM_FN_PTR(address, InterpreterRuntime::
   606                                    throw_illegal_monitor_state_exception));
   607       should_not_reach_here();
   608     } else {
   609       // Stack unrolling. Unlock object and install illegal_monitor_exception.
   610       // Unlock does not block, so don't have to worry about the frame.
   611       // We don't have to preserve c_rarg1 since we are going to throw an exception.
   613       push(state);
   614       unlock_object(c_rarg1);
   615       pop(state);
   617       if (install_monitor_exception) {
   618         call_VM(noreg, CAST_FROM_FN_PTR(address,
   619                                         InterpreterRuntime::
   620                                         new_illegal_monitor_state_exception));
   621       }
   623       jmp(restart);
   624     }
   626     bind(loop);
   627     // check if current entry is used
   628     cmpptr(Address(c_rarg1, BasicObjectLock::obj_offset_in_bytes()), (int32_t) NULL);
   629     jcc(Assembler::notEqual, exception);
   631     addptr(c_rarg1, entry_size); // otherwise advance to next entry
   632     bind(entry);
   633     cmpptr(c_rarg1, rbx); // check if bottom reached
   634     jcc(Assembler::notEqual, loop); // if not at bottom then check this entry
   635   }
   637   bind(no_unlock);
   639   // jvmti support
   640   if (notify_jvmdi) {
   641     notify_method_exit(state, NotifyJVMTI);    // preserve TOSCA
   642   } else {
   643     notify_method_exit(state, SkipNotifyJVMTI); // preserve TOSCA
   644   }
   646   // remove activation
   647   // get sender sp
   648   movptr(rbx,
   649          Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize));
   650   leave();                           // remove frame anchor
   651   pop(ret_addr);                     // get return address
   652   mov(rsp, rbx);                     // set sp to sender sp
   653 }
   655 #endif // C_INTERP
   657 // Lock object
   658 //
   659 // Args:
   660 //      c_rarg1: BasicObjectLock to be used for locking
   661 //
   662 // Kills:
   663 //      rax
   664 //      c_rarg0, c_rarg1, c_rarg2, c_rarg3, .. (param regs)
   665 //      rscratch1, rscratch2 (scratch regs)
   666 void InterpreterMacroAssembler::lock_object(Register lock_reg) {
   667   assert(lock_reg == c_rarg1, "The argument is only for looks. It must be c_rarg1");
   669   if (UseHeavyMonitors) {
   670     call_VM(noreg,
   671             CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
   672             lock_reg);
   673   } else {
   674     Label done;
   676     const Register swap_reg = rax; // Must use rax for cmpxchg instruction
   677     const Register obj_reg = c_rarg3; // Will contain the oop
   679     const int obj_offset = BasicObjectLock::obj_offset_in_bytes();
   680     const int lock_offset = BasicObjectLock::lock_offset_in_bytes ();
   681     const int mark_offset = lock_offset +
   682                             BasicLock::displaced_header_offset_in_bytes();
   684     Label slow_case;
   686     // Load object pointer into obj_reg %c_rarg3
   687     movptr(obj_reg, Address(lock_reg, obj_offset));
   689     if (UseBiasedLocking) {
   690       biased_locking_enter(lock_reg, obj_reg, swap_reg, rscratch1, false, done, &slow_case);
   691     }
   693     // Load immediate 1 into swap_reg %rax
   694     movl(swap_reg, 1);
   696     // Load (object->mark() | 1) into swap_reg %rax
   697     orptr(swap_reg, Address(obj_reg, 0));
   699     // Save (object->mark() | 1) into BasicLock's displaced header
   700     movptr(Address(lock_reg, mark_offset), swap_reg);
   702     assert(lock_offset == 0,
   703            "displached header must be first word in BasicObjectLock");
   705     if (os::is_MP()) lock();
   706     cmpxchgptr(lock_reg, Address(obj_reg, 0));
   707     if (PrintBiasedLockingStatistics) {
   708       cond_inc32(Assembler::zero,
   709                  ExternalAddress((address) BiasedLocking::fast_path_entry_count_addr()));
   710     }
   711     jcc(Assembler::zero, done);
   713     // Test if the oopMark is an obvious stack pointer, i.e.,
   714     //  1) (mark & 7) == 0, and
   715     //  2) rsp <= mark < mark + os::pagesize()
   716     //
   717     // These 3 tests can be done by evaluating the following
   718     // expression: ((mark - rsp) & (7 - os::vm_page_size())),
   719     // assuming both stack pointer and pagesize have their
   720     // least significant 3 bits clear.
   721     // NOTE: the oopMark is in swap_reg %rax as the result of cmpxchg
   722     subptr(swap_reg, rsp);
   723     andptr(swap_reg, 7 - os::vm_page_size());
   725     // Save the test result, for recursive case, the result is zero
   726     movptr(Address(lock_reg, mark_offset), swap_reg);
   728     if (PrintBiasedLockingStatistics) {
   729       cond_inc32(Assembler::zero,
   730                  ExternalAddress((address) BiasedLocking::fast_path_entry_count_addr()));
   731     }
   732     jcc(Assembler::zero, done);
   734     bind(slow_case);
   736     // Call the runtime routine for slow case
   737     call_VM(noreg,
   738             CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
   739             lock_reg);
   741     bind(done);
   742   }
   743 }
   746 // Unlocks an object. Used in monitorexit bytecode and
   747 // remove_activation.  Throws an IllegalMonitorException if object is
   748 // not locked by current thread.
   749 //
   750 // Args:
   751 //      c_rarg1: BasicObjectLock for lock
   752 //
   753 // Kills:
   754 //      rax
   755 //      c_rarg0, c_rarg1, c_rarg2, c_rarg3, ... (param regs)
   756 //      rscratch1, rscratch2 (scratch regs)
   757 void InterpreterMacroAssembler::unlock_object(Register lock_reg) {
   758   assert(lock_reg == c_rarg1, "The argument is only for looks. It must be rarg1");
   760   if (UseHeavyMonitors) {
   761     call_VM(noreg,
   762             CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit),
   763             lock_reg);
   764   } else {
   765     Label done;
   767     const Register swap_reg   = rax;  // Must use rax for cmpxchg instruction
   768     const Register header_reg = c_rarg2;  // Will contain the old oopMark
   769     const Register obj_reg    = c_rarg3;  // Will contain the oop
   771     save_bcp(); // Save in case of exception
   773     // Convert from BasicObjectLock structure to object and BasicLock
   774     // structure Store the BasicLock address into %rax
   775     lea(swap_reg, Address(lock_reg, BasicObjectLock::lock_offset_in_bytes()));
   777     // Load oop into obj_reg(%c_rarg3)
   778     movptr(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()));
   780     // Free entry
   781     movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()), (int32_t)NULL_WORD);
   783     if (UseBiasedLocking) {
   784       biased_locking_exit(obj_reg, header_reg, done);
   785     }
   787     // Load the old header from BasicLock structure
   788     movptr(header_reg, Address(swap_reg,
   789                                BasicLock::displaced_header_offset_in_bytes()));
   791     // Test for recursion
   792     testptr(header_reg, header_reg);
   794     // zero for recursive case
   795     jcc(Assembler::zero, done);
   797     // Atomic swap back the old header
   798     if (os::is_MP()) lock();
   799     cmpxchgptr(header_reg, Address(obj_reg, 0));
   801     // zero for recursive case
   802     jcc(Assembler::zero, done);
   804     // Call the runtime routine for slow case.
   805     movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()),
   806          obj_reg); // restore obj
   807     call_VM(noreg,
   808             CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit),
   809             lock_reg);
   811     bind(done);
   813     restore_bcp();
   814   }
   815 }
   817 #ifndef CC_INTERP
   819 void InterpreterMacroAssembler::test_method_data_pointer(Register mdp,
   820                                                          Label& zero_continue) {
   821   assert(ProfileInterpreter, "must be profiling interpreter");
   822   movptr(mdp, Address(rbp, frame::interpreter_frame_mdx_offset * wordSize));
   823   testptr(mdp, mdp);
   824   jcc(Assembler::zero, zero_continue);
   825 }
   828 // Set the method data pointer for the current bcp.
   829 void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() {
   830   assert(ProfileInterpreter, "must be profiling interpreter");
   831   Label set_mdp;
   832   push(rax);
   833   push(rbx);
   835   get_method(rbx);
   836   // Test MDO to avoid the call if it is NULL.
   837   movptr(rax, Address(rbx, in_bytes(methodOopDesc::method_data_offset())));
   838   testptr(rax, rax);
   839   jcc(Assembler::zero, set_mdp);
   840   // rbx: method
   841   // r13: bcp
   842   call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), rbx, r13);
   843   // rax: mdi
   844   // mdo is guaranteed to be non-zero here, we checked for it before the call.
   845   movptr(rbx, Address(rbx, in_bytes(methodOopDesc::method_data_offset())));
   846   addptr(rbx, in_bytes(methodDataOopDesc::data_offset()));
   847   addptr(rax, rbx);
   848   bind(set_mdp);
   849   movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), rax);
   850   pop(rbx);
   851   pop(rax);
   852 }
   854 void InterpreterMacroAssembler::verify_method_data_pointer() {
   855   assert(ProfileInterpreter, "must be profiling interpreter");
   856 #ifdef ASSERT
   857   Label verify_continue;
   858   push(rax);
   859   push(rbx);
   860   push(c_rarg3);
   861   push(c_rarg2);
   862   test_method_data_pointer(c_rarg3, verify_continue); // If mdp is zero, continue
   863   get_method(rbx);
   865   // If the mdp is valid, it will point to a DataLayout header which is
   866   // consistent with the bcp.  The converse is highly probable also.
   867   load_unsigned_short(c_rarg2,
   868                       Address(c_rarg3, in_bytes(DataLayout::bci_offset())));
   869   addptr(c_rarg2, Address(rbx, methodOopDesc::const_offset()));
   870   lea(c_rarg2, Address(c_rarg2, constMethodOopDesc::codes_offset()));
   871   cmpptr(c_rarg2, r13);
   872   jcc(Assembler::equal, verify_continue);
   873   // rbx: method
   874   // r13: bcp
   875   // c_rarg3: mdp
   876   call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp),
   877                rbx, r13, c_rarg3);
   878   bind(verify_continue);
   879   pop(c_rarg2);
   880   pop(c_rarg3);
   881   pop(rbx);
   882   pop(rax);
   883 #endif // ASSERT
   884 }
   887 void InterpreterMacroAssembler::set_mdp_data_at(Register mdp_in,
   888                                                 int constant,
   889                                                 Register value) {
   890   assert(ProfileInterpreter, "must be profiling interpreter");
   891   Address data(mdp_in, constant);
   892   movptr(data, value);
   893 }
   896 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
   897                                                       int constant,
   898                                                       bool decrement) {
   899   // Counter address
   900   Address data(mdp_in, constant);
   902   increment_mdp_data_at(data, decrement);
   903 }
   905 void InterpreterMacroAssembler::increment_mdp_data_at(Address data,
   906                                                       bool decrement) {
   907   assert(ProfileInterpreter, "must be profiling interpreter");
   908   // %%% this does 64bit counters at best it is wasting space
   909   // at worst it is a rare bug when counters overflow
   911   if (decrement) {
   912     // Decrement the register.  Set condition codes.
   913     addptr(data, (int32_t) -DataLayout::counter_increment);
   914     // If the decrement causes the counter to overflow, stay negative
   915     Label L;
   916     jcc(Assembler::negative, L);
   917     addptr(data, (int32_t) DataLayout::counter_increment);
   918     bind(L);
   919   } else {
   920     assert(DataLayout::counter_increment == 1,
   921            "flow-free idiom only works with 1");
   922     // Increment the register.  Set carry flag.
   923     addptr(data, DataLayout::counter_increment);
   924     // If the increment causes the counter to overflow, pull back by 1.
   925     sbbptr(data, (int32_t)0);
   926   }
   927 }
   930 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
   931                                                       Register reg,
   932                                                       int constant,
   933                                                       bool decrement) {
   934   Address data(mdp_in, reg, Address::times_1, constant);
   936   increment_mdp_data_at(data, decrement);
   937 }
   939 void InterpreterMacroAssembler::set_mdp_flag_at(Register mdp_in,
   940                                                 int flag_byte_constant) {
   941   assert(ProfileInterpreter, "must be profiling interpreter");
   942   int header_offset = in_bytes(DataLayout::header_offset());
   943   int header_bits = DataLayout::flag_mask_to_header_mask(flag_byte_constant);
   944   // Set the flag
   945   orl(Address(mdp_in, header_offset), header_bits);
   946 }
   950 void InterpreterMacroAssembler::test_mdp_data_at(Register mdp_in,
   951                                                  int offset,
   952                                                  Register value,
   953                                                  Register test_value_out,
   954                                                  Label& not_equal_continue) {
   955   assert(ProfileInterpreter, "must be profiling interpreter");
   956   if (test_value_out == noreg) {
   957     cmpptr(value, Address(mdp_in, offset));
   958   } else {
   959     // Put the test value into a register, so caller can use it:
   960     movptr(test_value_out, Address(mdp_in, offset));
   961     cmpptr(test_value_out, value);
   962   }
   963   jcc(Assembler::notEqual, not_equal_continue);
   964 }
   967 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,
   968                                                      int offset_of_disp) {
   969   assert(ProfileInterpreter, "must be profiling interpreter");
   970   Address disp_address(mdp_in, offset_of_disp);
   971   addptr(mdp_in, disp_address);
   972   movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in);
   973 }
   976 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,
   977                                                      Register reg,
   978                                                      int offset_of_disp) {
   979   assert(ProfileInterpreter, "must be profiling interpreter");
   980   Address disp_address(mdp_in, reg, Address::times_1, offset_of_disp);
   981   addptr(mdp_in, disp_address);
   982   movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in);
   983 }
   986 void InterpreterMacroAssembler::update_mdp_by_constant(Register mdp_in,
   987                                                        int constant) {
   988   assert(ProfileInterpreter, "must be profiling interpreter");
   989   addptr(mdp_in, constant);
   990   movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in);
   991 }
   994 void InterpreterMacroAssembler::update_mdp_for_ret(Register return_bci) {
   995   assert(ProfileInterpreter, "must be profiling interpreter");
   996   push(return_bci); // save/restore across call_VM
   997   call_VM(noreg,
   998           CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret),
   999           return_bci);
  1000   pop(return_bci);
  1004 void InterpreterMacroAssembler::profile_taken_branch(Register mdp,
  1005                                                      Register bumped_count) {
  1006   if (ProfileInterpreter) {
  1007     Label profile_continue;
  1009     // If no method data exists, go to profile_continue.
  1010     // Otherwise, assign to mdp
  1011     test_method_data_pointer(mdp, profile_continue);
  1013     // We are taking a branch.  Increment the taken count.
  1014     // We inline increment_mdp_data_at to return bumped_count in a register
  1015     //increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset()));
  1016     Address data(mdp, in_bytes(JumpData::taken_offset()));
  1017     movptr(bumped_count, data);
  1018     assert(DataLayout::counter_increment == 1,
  1019             "flow-free idiom only works with 1");
  1020     addptr(bumped_count, DataLayout::counter_increment);
  1021     sbbptr(bumped_count, 0);
  1022     movptr(data, bumped_count); // Store back out
  1024     // The method data pointer needs to be updated to reflect the new target.
  1025     update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset()));
  1026     bind(profile_continue);
  1031 void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp) {
  1032   if (ProfileInterpreter) {
  1033     Label profile_continue;
  1035     // If no method data exists, go to profile_continue.
  1036     test_method_data_pointer(mdp, profile_continue);
  1038     // We are taking a branch.  Increment the not taken count.
  1039     increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset()));
  1041     // The method data pointer needs to be updated to correspond to
  1042     // the next bytecode
  1043     update_mdp_by_constant(mdp, in_bytes(BranchData::branch_data_size()));
  1044     bind(profile_continue);
  1049 void InterpreterMacroAssembler::profile_call(Register mdp) {
  1050   if (ProfileInterpreter) {
  1051     Label profile_continue;
  1053     // If no method data exists, go to profile_continue.
  1054     test_method_data_pointer(mdp, profile_continue);
  1056     // We are making a call.  Increment the count.
  1057     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1059     // The method data pointer needs to be updated to reflect the new target.
  1060     update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size()));
  1061     bind(profile_continue);
  1066 void InterpreterMacroAssembler::profile_final_call(Register mdp) {
  1067   if (ProfileInterpreter) {
  1068     Label profile_continue;
  1070     // If no method data exists, go to profile_continue.
  1071     test_method_data_pointer(mdp, profile_continue);
  1073     // We are making a call.  Increment the count.
  1074     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1076     // The method data pointer needs to be updated to reflect the new target.
  1077     update_mdp_by_constant(mdp,
  1078                            in_bytes(VirtualCallData::
  1079                                     virtual_call_data_size()));
  1080     bind(profile_continue);
  1085 void InterpreterMacroAssembler::profile_virtual_call(Register receiver,
  1086                                                      Register mdp,
  1087                                                      Register reg2,
  1088                                                      bool receiver_can_be_null) {
  1089   if (ProfileInterpreter) {
  1090     Label profile_continue;
  1092     // If no method data exists, go to profile_continue.
  1093     test_method_data_pointer(mdp, profile_continue);
  1095     Label skip_receiver_profile;
  1096     if (receiver_can_be_null) {
  1097       Label not_null;
  1098       testptr(receiver, receiver);
  1099       jccb(Assembler::notZero, not_null);
  1100       // We are making a call.  Increment the count for null receiver.
  1101       increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1102       jmp(skip_receiver_profile);
  1103       bind(not_null);
  1106     // Record the receiver type.
  1107     record_klass_in_profile(receiver, mdp, reg2, true);
  1108     bind(skip_receiver_profile);
  1110     // The method data pointer needs to be updated to reflect the new target.
  1111     update_mdp_by_constant(mdp,
  1112                            in_bytes(VirtualCallData::
  1113                                     virtual_call_data_size()));
  1114     bind(profile_continue);
  1118 // This routine creates a state machine for updating the multi-row
  1119 // type profile at a virtual call site (or other type-sensitive bytecode).
  1120 // The machine visits each row (of receiver/count) until the receiver type
  1121 // is found, or until it runs out of rows.  At the same time, it remembers
  1122 // the location of the first empty row.  (An empty row records null for its
  1123 // receiver, and can be allocated for a newly-observed receiver type.)
  1124 // Because there are two degrees of freedom in the state, a simple linear
  1125 // search will not work; it must be a decision tree.  Hence this helper
  1126 // function is recursive, to generate the required tree structured code.
  1127 // It's the interpreter, so we are trading off code space for speed.
  1128 // See below for example code.
  1129 void InterpreterMacroAssembler::record_klass_in_profile_helper(
  1130                                         Register receiver, Register mdp,
  1131                                         Register reg2, int start_row,
  1132                                         Label& done, bool is_virtual_call) {
  1133   if (TypeProfileWidth == 0) {
  1134     if (is_virtual_call) {
  1135       increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1137     return;
  1140   int last_row = VirtualCallData::row_limit() - 1;
  1141   assert(start_row <= last_row, "must be work left to do");
  1142   // Test this row for both the receiver and for null.
  1143   // Take any of three different outcomes:
  1144   //   1. found receiver => increment count and goto done
  1145   //   2. found null => keep looking for case 1, maybe allocate this cell
  1146   //   3. found something else => keep looking for cases 1 and 2
  1147   // Case 3 is handled by a recursive call.
  1148   for (int row = start_row; row <= last_row; row++) {
  1149     Label next_test;
  1150     bool test_for_null_also = (row == start_row);
  1152     // See if the receiver is receiver[n].
  1153     int recvr_offset = in_bytes(VirtualCallData::receiver_offset(row));
  1154     test_mdp_data_at(mdp, recvr_offset, receiver,
  1155                      (test_for_null_also ? reg2 : noreg),
  1156                      next_test);
  1157     // (Reg2 now contains the receiver from the CallData.)
  1159     // The receiver is receiver[n].  Increment count[n].
  1160     int count_offset = in_bytes(VirtualCallData::receiver_count_offset(row));
  1161     increment_mdp_data_at(mdp, count_offset);
  1162     jmp(done);
  1163     bind(next_test);
  1165     if (test_for_null_also) {
  1166       Label found_null;
  1167       // Failed the equality check on receiver[n]...  Test for null.
  1168       testptr(reg2, reg2);
  1169       if (start_row == last_row) {
  1170         // The only thing left to do is handle the null case.
  1171         if (is_virtual_call) {
  1172           jccb(Assembler::zero, found_null);
  1173           // Receiver did not match any saved receiver and there is no empty row for it.
  1174           // Increment total counter to indicate polymorphic case.
  1175           increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1176           jmp(done);
  1177           bind(found_null);
  1178         } else {
  1179           jcc(Assembler::notZero, done);
  1181         break;
  1183       // Since null is rare, make it be the branch-taken case.
  1184       jcc(Assembler::zero, found_null);
  1186       // Put all the "Case 3" tests here.
  1187       record_klass_in_profile_helper(receiver, mdp, reg2, start_row + 1, done, is_virtual_call);
  1189       // Found a null.  Keep searching for a matching receiver,
  1190       // but remember that this is an empty (unused) slot.
  1191       bind(found_null);
  1195   // In the fall-through case, we found no matching receiver, but we
  1196   // observed the receiver[start_row] is NULL.
  1198   // Fill in the receiver field and increment the count.
  1199   int recvr_offset = in_bytes(VirtualCallData::receiver_offset(start_row));
  1200   set_mdp_data_at(mdp, recvr_offset, receiver);
  1201   int count_offset = in_bytes(VirtualCallData::receiver_count_offset(start_row));
  1202   movl(reg2, DataLayout::counter_increment);
  1203   set_mdp_data_at(mdp, count_offset, reg2);
  1204   if (start_row > 0) {
  1205     jmp(done);
  1209 // Example state machine code for three profile rows:
  1210 //   // main copy of decision tree, rooted at row[1]
  1211 //   if (row[0].rec == rec) { row[0].incr(); goto done; }
  1212 //   if (row[0].rec != NULL) {
  1213 //     // inner copy of decision tree, rooted at row[1]
  1214 //     if (row[1].rec == rec) { row[1].incr(); goto done; }
  1215 //     if (row[1].rec != NULL) {
  1216 //       // degenerate decision tree, rooted at row[2]
  1217 //       if (row[2].rec == rec) { row[2].incr(); goto done; }
  1218 //       if (row[2].rec != NULL) { count.incr(); goto done; } // overflow
  1219 //       row[2].init(rec); goto done;
  1220 //     } else {
  1221 //       // remember row[1] is empty
  1222 //       if (row[2].rec == rec) { row[2].incr(); goto done; }
  1223 //       row[1].init(rec); goto done;
  1224 //     }
  1225 //   } else {
  1226 //     // remember row[0] is empty
  1227 //     if (row[1].rec == rec) { row[1].incr(); goto done; }
  1228 //     if (row[2].rec == rec) { row[2].incr(); goto done; }
  1229 //     row[0].init(rec); goto done;
  1230 //   }
  1231 //   done:
  1233 void InterpreterMacroAssembler::record_klass_in_profile(Register receiver,
  1234                                                         Register mdp, Register reg2,
  1235                                                         bool is_virtual_call) {
  1236   assert(ProfileInterpreter, "must be profiling");
  1237   Label done;
  1239   record_klass_in_profile_helper(receiver, mdp, reg2, 0, done, is_virtual_call);
  1241   bind (done);
  1244 void InterpreterMacroAssembler::profile_ret(Register return_bci,
  1245                                             Register mdp) {
  1246   if (ProfileInterpreter) {
  1247     Label profile_continue;
  1248     uint row;
  1250     // If no method data exists, go to profile_continue.
  1251     test_method_data_pointer(mdp, profile_continue);
  1253     // Update the total ret count.
  1254     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1256     for (row = 0; row < RetData::row_limit(); row++) {
  1257       Label next_test;
  1259       // See if return_bci is equal to bci[n]:
  1260       test_mdp_data_at(mdp,
  1261                        in_bytes(RetData::bci_offset(row)),
  1262                        return_bci, noreg,
  1263                        next_test);
  1265       // return_bci is equal to bci[n].  Increment the count.
  1266       increment_mdp_data_at(mdp, in_bytes(RetData::bci_count_offset(row)));
  1268       // The method data pointer needs to be updated to reflect the new target.
  1269       update_mdp_by_offset(mdp,
  1270                            in_bytes(RetData::bci_displacement_offset(row)));
  1271       jmp(profile_continue);
  1272       bind(next_test);
  1275     update_mdp_for_ret(return_bci);
  1277     bind(profile_continue);
  1282 void InterpreterMacroAssembler::profile_null_seen(Register mdp) {
  1283   if (ProfileInterpreter) {
  1284     Label profile_continue;
  1286     // If no method data exists, go to profile_continue.
  1287     test_method_data_pointer(mdp, profile_continue);
  1289     set_mdp_flag_at(mdp, BitData::null_seen_byte_constant());
  1291     // The method data pointer needs to be updated.
  1292     int mdp_delta = in_bytes(BitData::bit_data_size());
  1293     if (TypeProfileCasts) {
  1294       mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
  1296     update_mdp_by_constant(mdp, mdp_delta);
  1298     bind(profile_continue);
  1303 void InterpreterMacroAssembler::profile_typecheck_failed(Register mdp) {
  1304   if (ProfileInterpreter && TypeProfileCasts) {
  1305     Label profile_continue;
  1307     // If no method data exists, go to profile_continue.
  1308     test_method_data_pointer(mdp, profile_continue);
  1310     int count_offset = in_bytes(CounterData::count_offset());
  1311     // Back up the address, since we have already bumped the mdp.
  1312     count_offset -= in_bytes(VirtualCallData::virtual_call_data_size());
  1314     // *Decrement* the counter.  We expect to see zero or small negatives.
  1315     increment_mdp_data_at(mdp, count_offset, true);
  1317     bind (profile_continue);
  1322 void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2) {
  1323   if (ProfileInterpreter) {
  1324     Label profile_continue;
  1326     // If no method data exists, go to profile_continue.
  1327     test_method_data_pointer(mdp, profile_continue);
  1329     // The method data pointer needs to be updated.
  1330     int mdp_delta = in_bytes(BitData::bit_data_size());
  1331     if (TypeProfileCasts) {
  1332       mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
  1334       // Record the object type.
  1335       record_klass_in_profile(klass, mdp, reg2, false);
  1337     update_mdp_by_constant(mdp, mdp_delta);
  1339     bind(profile_continue);
  1344 void InterpreterMacroAssembler::profile_switch_default(Register mdp) {
  1345   if (ProfileInterpreter) {
  1346     Label profile_continue;
  1348     // If no method data exists, go to profile_continue.
  1349     test_method_data_pointer(mdp, profile_continue);
  1351     // Update the default case count
  1352     increment_mdp_data_at(mdp,
  1353                           in_bytes(MultiBranchData::default_count_offset()));
  1355     // The method data pointer needs to be updated.
  1356     update_mdp_by_offset(mdp,
  1357                          in_bytes(MultiBranchData::
  1358                                   default_displacement_offset()));
  1360     bind(profile_continue);
  1365 void InterpreterMacroAssembler::profile_switch_case(Register index,
  1366                                                     Register mdp,
  1367                                                     Register reg2) {
  1368   if (ProfileInterpreter) {
  1369     Label profile_continue;
  1371     // If no method data exists, go to profile_continue.
  1372     test_method_data_pointer(mdp, profile_continue);
  1374     // Build the base (index * per_case_size_in_bytes()) +
  1375     // case_array_offset_in_bytes()
  1376     movl(reg2, in_bytes(MultiBranchData::per_case_size()));
  1377     imulptr(index, reg2); // XXX l ?
  1378     addptr(index, in_bytes(MultiBranchData::case_array_offset())); // XXX l ?
  1380     // Update the case count
  1381     increment_mdp_data_at(mdp,
  1382                           index,
  1383                           in_bytes(MultiBranchData::relative_count_offset()));
  1385     // The method data pointer needs to be updated.
  1386     update_mdp_by_offset(mdp,
  1387                          index,
  1388                          in_bytes(MultiBranchData::
  1389                                   relative_displacement_offset()));
  1391     bind(profile_continue);
  1397 void InterpreterMacroAssembler::verify_oop(Register reg, TosState state) {
  1398   if (state == atos) {
  1399     MacroAssembler::verify_oop(reg);
  1403 void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) {
  1405 #endif // !CC_INTERP
  1408 void InterpreterMacroAssembler::notify_method_entry() {
  1409   // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
  1410   // track stack depth.  If it is possible to enter interp_only_mode we add
  1411   // the code to check if the event should be sent.
  1412   if (JvmtiExport::can_post_interpreter_events()) {
  1413     Label L;
  1414     movl(rdx, Address(r15_thread, JavaThread::interp_only_mode_offset()));
  1415     testl(rdx, rdx);
  1416     jcc(Assembler::zero, L);
  1417     call_VM(noreg, CAST_FROM_FN_PTR(address,
  1418                                     InterpreterRuntime::post_method_entry));
  1419     bind(L);
  1423     SkipIfEqual skip(this, &DTraceMethodProbes, false);
  1424     get_method(c_rarg1);
  1425     call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry),
  1426                  r15_thread, c_rarg1);
  1429   // RedefineClasses() tracing support for obsolete method entry
  1430   if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
  1431     get_method(c_rarg1);
  1432     call_VM_leaf(
  1433       CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry),
  1434       r15_thread, c_rarg1);
  1439 void InterpreterMacroAssembler::notify_method_exit(
  1440     TosState state, NotifyMethodExitMode mode) {
  1441   // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
  1442   // track stack depth.  If it is possible to enter interp_only_mode we add
  1443   // the code to check if the event should be sent.
  1444   if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) {
  1445     Label L;
  1446     // Note: frame::interpreter_frame_result has a dependency on how the
  1447     // method result is saved across the call to post_method_exit. If this
  1448     // is changed then the interpreter_frame_result implementation will
  1449     // need to be updated too.
  1451     // For c++ interpreter the result is always stored at a known location in the frame
  1452     // template interpreter will leave it on the top of the stack.
  1453     NOT_CC_INTERP(push(state);)
  1454     movl(rdx, Address(r15_thread, JavaThread::interp_only_mode_offset()));
  1455     testl(rdx, rdx);
  1456     jcc(Assembler::zero, L);
  1457     call_VM(noreg,
  1458             CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit));
  1459     bind(L);
  1460     NOT_CC_INTERP(pop(state));
  1464     SkipIfEqual skip(this, &DTraceMethodProbes, false);
  1465     NOT_CC_INTERP(push(state));
  1466     get_method(c_rarg1);
  1467     call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),
  1468                  r15_thread, c_rarg1);
  1469     NOT_CC_INTERP(pop(state));
  1473 // Jump if ((*counter_addr += increment) & mask) satisfies the condition.
  1474 void InterpreterMacroAssembler::increment_mask_and_jump(Address counter_addr,
  1475                                                         int increment, int mask,
  1476                                                         Register scratch, bool preloaded,
  1477                                                         Condition cond, Label* where) {
  1478   if (!preloaded) {
  1479     movl(scratch, counter_addr);
  1481   incrementl(scratch, increment);
  1482   movl(counter_addr, scratch);
  1483   andl(scratch, mask);
  1484   jcc(cond, *where);

mercurial