src/cpu/x86/vm/interp_masm_x86_64.cpp

Thu, 27 May 2010 19:08:38 -0700

author
trims
date
Thu, 27 May 2010 19:08:38 -0700
changeset 1907
c18cbe5936b8
parent 1861
2338d41fbd81
child 1934
e9ff18c4ace7
permissions
-rw-r--r--

6941466: Oracle rebranding changes for Hotspot repositories
Summary: Change all the Sun copyrights to Oracle copyright
Reviewed-by: ohair

     1 /*
     2  * Copyright (c) 2003, 2010, 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 "incls/_precompiled.incl"
    26 #include "incls/_interp_masm_x86_64.cpp.incl"
    29 // Implementation of InterpreterMacroAssembler
    31 #ifdef CC_INTERP
    32 void InterpreterMacroAssembler::get_method(Register reg) {
    33   movptr(reg, Address(rbp, -((int)sizeof(BytecodeInterpreter) + 2 * wordSize)));
    34   movptr(reg, Address(reg, byte_offset_of(BytecodeInterpreter, _method)));
    35 }
    36 #endif // CC_INTERP
    38 #ifndef CC_INTERP
    40 void InterpreterMacroAssembler::call_VM_leaf_base(address entry_point,
    41                                                   int number_of_arguments) {
    42   // interpreter specific
    43   //
    44   // Note: No need to save/restore bcp & locals (r13 & r14) pointer
    45   //       since these are callee saved registers and no blocking/
    46   //       GC can happen in leaf calls.
    47   // Further Note: DO NOT save/restore bcp/locals. If a caller has
    48   // already saved them so that it can use esi/edi as temporaries
    49   // then a save/restore here will DESTROY the copy the caller
    50   // saved! There used to be a save_bcp() that only happened in
    51   // the ASSERT path (no restore_bcp). Which caused bizarre failures
    52   // when jvm built with ASSERTs.
    53 #ifdef ASSERT
    54   {
    55     Label L;
    56     cmpptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
    57     jcc(Assembler::equal, L);
    58     stop("InterpreterMacroAssembler::call_VM_leaf_base:"
    59          " last_sp != NULL");
    60     bind(L);
    61   }
    62 #endif
    63   // super call
    64   MacroAssembler::call_VM_leaf_base(entry_point, number_of_arguments);
    65   // interpreter specific
    66   // Used to ASSERT that r13/r14 were equal to frame's bcp/locals
    67   // but since they may not have been saved (and we don't want to
    68   // save thme here (see note above) the assert is invalid.
    69 }
    71 void InterpreterMacroAssembler::call_VM_base(Register oop_result,
    72                                              Register java_thread,
    73                                              Register last_java_sp,
    74                                              address  entry_point,
    75                                              int      number_of_arguments,
    76                                              bool     check_exceptions) {
    77   // interpreter specific
    78   //
    79   // Note: Could avoid restoring locals ptr (callee saved) - however doesn't
    80   //       really make a difference for these runtime calls, since they are
    81   //       slow anyway. Btw., bcp must be saved/restored since it may change
    82   //       due to GC.
    83   // assert(java_thread == noreg , "not expecting a precomputed java thread");
    84   save_bcp();
    85 #ifdef ASSERT
    86   {
    87     Label L;
    88     cmpptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
    89     jcc(Assembler::equal, L);
    90     stop("InterpreterMacroAssembler::call_VM_leaf_base:"
    91          " last_sp != NULL");
    92     bind(L);
    93   }
    94 #endif /* ASSERT */
    95   // super call
    96   MacroAssembler::call_VM_base(oop_result, noreg, last_java_sp,
    97                                entry_point, number_of_arguments,
    98                                check_exceptions);
    99   // interpreter specific
   100   restore_bcp();
   101   restore_locals();
   102 }
   105 void InterpreterMacroAssembler::check_and_handle_popframe(Register java_thread) {
   106   if (JvmtiExport::can_pop_frame()) {
   107     Label L;
   108     // Initiate popframe handling only if it is not already being
   109     // processed.  If the flag has the popframe_processing bit set, it
   110     // means that this code is called *during* popframe handling - we
   111     // don't want to reenter.
   112     // This method is only called just after the call into the vm in
   113     // call_VM_base, so the arg registers are available.
   114     movl(c_rarg0, Address(r15_thread, JavaThread::popframe_condition_offset()));
   115     testl(c_rarg0, JavaThread::popframe_pending_bit);
   116     jcc(Assembler::zero, L);
   117     testl(c_rarg0, JavaThread::popframe_processing_bit);
   118     jcc(Assembler::notZero, L);
   119     // Call Interpreter::remove_activation_preserving_args_entry() to get the
   120     // address of the same-named entrypoint in the generated interpreter code.
   121     call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_preserving_args_entry));
   122     jmp(rax);
   123     bind(L);
   124   }
   125 }
   128 void InterpreterMacroAssembler::load_earlyret_value(TosState state) {
   129   movptr(rcx, Address(r15_thread, JavaThread::jvmti_thread_state_offset()));
   130   const Address tos_addr(rcx, JvmtiThreadState::earlyret_tos_offset());
   131   const Address oop_addr(rcx, JvmtiThreadState::earlyret_oop_offset());
   132   const Address val_addr(rcx, JvmtiThreadState::earlyret_value_offset());
   133   switch (state) {
   134     case atos: movptr(rax, oop_addr);
   135                movptr(oop_addr, (int32_t)NULL_WORD);
   136                verify_oop(rax, state);              break;
   137     case ltos: movptr(rax, val_addr);                 break;
   138     case btos:                                   // fall through
   139     case ctos:                                   // fall through
   140     case stos:                                   // fall through
   141     case itos: movl(rax, val_addr);                 break;
   142     case ftos: movflt(xmm0, val_addr);              break;
   143     case dtos: movdbl(xmm0, val_addr);              break;
   144     case vtos: /* nothing to do */                  break;
   145     default  : ShouldNotReachHere();
   146   }
   147   // Clean up tos value in the thread object
   148   movl(tos_addr,  (int) ilgl);
   149   movl(val_addr,  (int32_t) NULL_WORD);
   150 }
   153 void InterpreterMacroAssembler::check_and_handle_earlyret(Register java_thread) {
   154   if (JvmtiExport::can_force_early_return()) {
   155     Label L;
   156     movptr(c_rarg0, Address(r15_thread, JavaThread::jvmti_thread_state_offset()));
   157     testptr(c_rarg0, c_rarg0);
   158     jcc(Assembler::zero, L); // if (thread->jvmti_thread_state() == NULL) exit;
   160     // Initiate earlyret handling only if it is not already being processed.
   161     // If the flag has the earlyret_processing bit set, it means that this code
   162     // is called *during* earlyret handling - we don't want to reenter.
   163     movl(c_rarg0, Address(c_rarg0, JvmtiThreadState::earlyret_state_offset()));
   164     cmpl(c_rarg0, JvmtiThreadState::earlyret_pending);
   165     jcc(Assembler::notEqual, L);
   167     // Call Interpreter::remove_activation_early_entry() to get the address of the
   168     // same-named entrypoint in the generated interpreter code.
   169     movptr(c_rarg0, Address(r15_thread, JavaThread::jvmti_thread_state_offset()));
   170     movl(c_rarg0, Address(c_rarg0, JvmtiThreadState::earlyret_tos_offset()));
   171     call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry), c_rarg0);
   172     jmp(rax);
   173     bind(L);
   174   }
   175 }
   178 void InterpreterMacroAssembler::get_unsigned_2_byte_index_at_bcp(
   179   Register reg,
   180   int bcp_offset) {
   181   assert(bcp_offset >= 0, "bcp is still pointing to start of bytecode");
   182   movl(reg, Address(r13, bcp_offset));
   183   bswapl(reg);
   184   shrl(reg, 16);
   185 }
   188 void InterpreterMacroAssembler::get_cache_index_at_bcp(Register index,
   189                                                        int bcp_offset,
   190                                                        bool giant_index) {
   191   assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");
   192   if (!giant_index) {
   193     load_unsigned_short(index, Address(r13, bcp_offset));
   194   } else {
   195     assert(EnableInvokeDynamic, "giant index used only for EnableInvokeDynamic");
   196     movl(index, Address(r13, bcp_offset));
   197     // Check if the secondary index definition is still ~x, otherwise
   198     // we have to change the following assembler code to calculate the
   199     // plain index.
   200     assert(constantPoolCacheOopDesc::decode_secondary_index(~123) == 123, "else change next line");
   201     notl(index);  // convert to plain index
   202   }
   203 }
   206 void InterpreterMacroAssembler::get_cache_and_index_at_bcp(Register cache,
   207                                                            Register index,
   208                                                            int bcp_offset,
   209                                                            bool giant_index) {
   210   assert(cache != index, "must use different registers");
   211   get_cache_index_at_bcp(index, bcp_offset, giant_index);
   212   movptr(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize));
   213   assert(sizeof(ConstantPoolCacheEntry) == 4 * wordSize, "adjust code below");
   214   // convert from field index to ConstantPoolCacheEntry index
   215   shll(index, 2);
   216 }
   219 void InterpreterMacroAssembler::get_cache_entry_pointer_at_bcp(Register cache,
   220                                                                Register tmp,
   221                                                                int bcp_offset,
   222                                                                bool giant_index) {
   223   assert(cache != tmp, "must use different register");
   224   get_cache_index_at_bcp(tmp, bcp_offset, giant_index);
   225   assert(sizeof(ConstantPoolCacheEntry) == 4 * wordSize, "adjust code below");
   226   // convert from field index to ConstantPoolCacheEntry index
   227   // and from word offset to byte offset
   228   shll(tmp, 2 + LogBytesPerWord);
   229   movptr(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize));
   230   // skip past the header
   231   addptr(cache, in_bytes(constantPoolCacheOopDesc::base_offset()));
   232   addptr(cache, tmp);  // construct pointer to cache entry
   233 }
   236 // Generate a subtype check: branch to ok_is_subtype if sub_klass is a
   237 // subtype of super_klass.
   238 //
   239 // Args:
   240 //      rax: superklass
   241 //      Rsub_klass: subklass
   242 //
   243 // Kills:
   244 //      rcx, rdi
   245 void InterpreterMacroAssembler::gen_subtype_check(Register Rsub_klass,
   246                                                   Label& ok_is_subtype) {
   247   assert(Rsub_klass != rax, "rax holds superklass");
   248   assert(Rsub_klass != r14, "r14 holds locals");
   249   assert(Rsub_klass != r13, "r13 holds bcp");
   250   assert(Rsub_klass != rcx, "rcx holds 2ndary super array length");
   251   assert(Rsub_klass != rdi, "rdi holds 2ndary super array scan ptr");
   253   // Profile the not-null value's klass.
   254   profile_typecheck(rcx, Rsub_klass, rdi); // blows rcx, reloads rdi
   256   // Do the check.
   257   check_klass_subtype(Rsub_klass, rax, rcx, ok_is_subtype); // blows rcx
   259   // Profile the failure of the check.
   260   profile_typecheck_failed(rcx); // blows rcx
   261 }
   265 // Java Expression Stack
   267 void InterpreterMacroAssembler::pop_ptr(Register r) {
   268   pop(r);
   269 }
   271 void InterpreterMacroAssembler::pop_i(Register r) {
   272   // XXX can't use pop currently, upper half non clean
   273   movl(r, Address(rsp, 0));
   274   addptr(rsp, wordSize);
   275 }
   277 void InterpreterMacroAssembler::pop_l(Register r) {
   278   movq(r, Address(rsp, 0));
   279   addptr(rsp, 2 * Interpreter::stackElementSize);
   280 }
   282 void InterpreterMacroAssembler::pop_f(XMMRegister r) {
   283   movflt(r, Address(rsp, 0));
   284   addptr(rsp, wordSize);
   285 }
   287 void InterpreterMacroAssembler::pop_d(XMMRegister r) {
   288   movdbl(r, Address(rsp, 0));
   289   addptr(rsp, 2 * Interpreter::stackElementSize);
   290 }
   292 void InterpreterMacroAssembler::push_ptr(Register r) {
   293   push(r);
   294 }
   296 void InterpreterMacroAssembler::push_i(Register r) {
   297   push(r);
   298 }
   300 void InterpreterMacroAssembler::push_l(Register r) {
   301   subptr(rsp, 2 * wordSize);
   302   movq(Address(rsp, 0), r);
   303 }
   305 void InterpreterMacroAssembler::push_f(XMMRegister r) {
   306   subptr(rsp, wordSize);
   307   movflt(Address(rsp, 0), r);
   308 }
   310 void InterpreterMacroAssembler::push_d(XMMRegister r) {
   311   subptr(rsp, 2 * wordSize);
   312   movdbl(Address(rsp, 0), r);
   313 }
   315 void InterpreterMacroAssembler::pop(TosState state) {
   316   switch (state) {
   317   case atos: pop_ptr();                 break;
   318   case btos:
   319   case ctos:
   320   case stos:
   321   case itos: pop_i();                   break;
   322   case ltos: pop_l();                   break;
   323   case ftos: pop_f();                   break;
   324   case dtos: pop_d();                   break;
   325   case vtos: /* nothing to do */        break;
   326   default:   ShouldNotReachHere();
   327   }
   328   verify_oop(rax, state);
   329 }
   331 void InterpreterMacroAssembler::push(TosState state) {
   332   verify_oop(rax, state);
   333   switch (state) {
   334   case atos: push_ptr();                break;
   335   case btos:
   336   case ctos:
   337   case stos:
   338   case itos: push_i();                  break;
   339   case ltos: push_l();                  break;
   340   case ftos: push_f();                  break;
   341   case dtos: push_d();                  break;
   342   case vtos: /* nothing to do */        break;
   343   default  : ShouldNotReachHere();
   344   }
   345 }
   348 // Helpers for swap and dup
   349 void InterpreterMacroAssembler::load_ptr(int n, Register val) {
   350   movptr(val, Address(rsp, Interpreter::expr_offset_in_bytes(n)));
   351 }
   353 void InterpreterMacroAssembler::store_ptr(int n, Register val) {
   354   movptr(Address(rsp, Interpreter::expr_offset_in_bytes(n)), val);
   355 }
   358 void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point) {
   359   MacroAssembler::call_VM_leaf_base(entry_point, 0);
   360 }
   363 void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point,
   364                                                    Register arg_1) {
   365   if (c_rarg0 != arg_1) {
   366     mov(c_rarg0, arg_1);
   367   }
   368   MacroAssembler::call_VM_leaf_base(entry_point, 1);
   369 }
   372 void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point,
   373                                                    Register arg_1,
   374                                                    Register arg_2) {
   375   assert(c_rarg0 != arg_2, "smashed argument");
   376   assert(c_rarg1 != arg_1, "smashed argument");
   377   if (c_rarg0 != arg_1) {
   378     mov(c_rarg0, arg_1);
   379   }
   380   if (c_rarg1 != arg_2) {
   381     mov(c_rarg1, arg_2);
   382   }
   383   MacroAssembler::call_VM_leaf_base(entry_point, 2);
   384 }
   386 void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point,
   387                                                    Register arg_1,
   388                                                    Register arg_2,
   389                                                    Register arg_3) {
   390   assert(c_rarg0 != arg_2, "smashed argument");
   391   assert(c_rarg0 != arg_3, "smashed argument");
   392   assert(c_rarg1 != arg_1, "smashed argument");
   393   assert(c_rarg1 != arg_3, "smashed argument");
   394   assert(c_rarg2 != arg_1, "smashed argument");
   395   assert(c_rarg2 != arg_2, "smashed argument");
   396   if (c_rarg0 != arg_1) {
   397     mov(c_rarg0, arg_1);
   398   }
   399   if (c_rarg1 != arg_2) {
   400     mov(c_rarg1, arg_2);
   401   }
   402   if (c_rarg2 != arg_3) {
   403     mov(c_rarg2, arg_3);
   404   }
   405   MacroAssembler::call_VM_leaf_base(entry_point, 3);
   406 }
   408 void InterpreterMacroAssembler::prepare_to_jump_from_interpreted() {
   409   // set sender sp
   410   lea(r13, Address(rsp, wordSize));
   411   // record last_sp
   412   movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), r13);
   413 }
   416 // Jump to from_interpreted entry of a call unless single stepping is possible
   417 // in this thread in which case we must call the i2i entry
   418 void InterpreterMacroAssembler::jump_from_interpreted(Register method, Register temp) {
   419   prepare_to_jump_from_interpreted();
   421   if (JvmtiExport::can_post_interpreter_events()) {
   422     Label run_compiled_code;
   423     // JVMTI events, such as single-stepping, are implemented partly by avoiding running
   424     // compiled code in threads for which the event is enabled.  Check here for
   425     // interp_only_mode if these events CAN be enabled.
   426     get_thread(temp);
   427     // interp_only is an int, on little endian it is sufficient to test the byte only
   428     // Is a cmpl faster (ce
   429     cmpb(Address(temp, JavaThread::interp_only_mode_offset()), 0);
   430     jcc(Assembler::zero, run_compiled_code);
   431     jmp(Address(method, methodOopDesc::interpreter_entry_offset()));
   432     bind(run_compiled_code);
   433   }
   435   jmp(Address(method, methodOopDesc::from_interpreted_offset()));
   437 }
   440 // The following two routines provide a hook so that an implementation
   441 // can schedule the dispatch in two parts.  amd64 does not do this.
   442 void InterpreterMacroAssembler::dispatch_prolog(TosState state, int step) {
   443   // Nothing amd64 specific to be done here
   444 }
   446 void InterpreterMacroAssembler::dispatch_epilog(TosState state, int step) {
   447   dispatch_next(state, step);
   448 }
   450 void InterpreterMacroAssembler::dispatch_base(TosState state,
   451                                               address* table,
   452                                               bool verifyoop) {
   453   verify_FPU(1, state);
   454   if (VerifyActivationFrameSize) {
   455     Label L;
   456     mov(rcx, rbp);
   457     subptr(rcx, rsp);
   458     int32_t min_frame_size =
   459       (frame::link_offset - frame::interpreter_frame_initial_sp_offset) *
   460       wordSize;
   461     cmpptr(rcx, (int32_t)min_frame_size);
   462     jcc(Assembler::greaterEqual, L);
   463     stop("broken stack frame");
   464     bind(L);
   465   }
   466   if (verifyoop) {
   467     verify_oop(rax, state);
   468   }
   469   lea(rscratch1, ExternalAddress((address)table));
   470   jmp(Address(rscratch1, rbx, Address::times_8));
   471 }
   473 void InterpreterMacroAssembler::dispatch_only(TosState state) {
   474   dispatch_base(state, Interpreter::dispatch_table(state));
   475 }
   477 void InterpreterMacroAssembler::dispatch_only_normal(TosState state) {
   478   dispatch_base(state, Interpreter::normal_table(state));
   479 }
   481 void InterpreterMacroAssembler::dispatch_only_noverify(TosState state) {
   482   dispatch_base(state, Interpreter::normal_table(state), false);
   483 }
   486 void InterpreterMacroAssembler::dispatch_next(TosState state, int step) {
   487   // load next bytecode (load before advancing r13 to prevent AGI)
   488   load_unsigned_byte(rbx, Address(r13, step));
   489   // advance r13
   490   increment(r13, step);
   491   dispatch_base(state, Interpreter::dispatch_table(state));
   492 }
   494 void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) {
   495   // load current bytecode
   496   load_unsigned_byte(rbx, Address(r13, 0));
   497   dispatch_base(state, table);
   498 }
   500 // remove activation
   501 //
   502 // Unlock the receiver if this is a synchronized method.
   503 // Unlock any Java monitors from syncronized blocks.
   504 // Remove the activation from the stack.
   505 //
   506 // If there are locked Java monitors
   507 //    If throw_monitor_exception
   508 //       throws IllegalMonitorStateException
   509 //    Else if install_monitor_exception
   510 //       installs IllegalMonitorStateException
   511 //    Else
   512 //       no error processing
   513 void InterpreterMacroAssembler::remove_activation(
   514         TosState state,
   515         Register ret_addr,
   516         bool throw_monitor_exception,
   517         bool install_monitor_exception,
   518         bool notify_jvmdi) {
   519   // Note: Registers rdx xmm0 may be in use for the
   520   // result check if synchronized method
   521   Label unlocked, unlock, no_unlock;
   523   // get the value of _do_not_unlock_if_synchronized into rdx
   524   const Address do_not_unlock_if_synchronized(r15_thread,
   525     in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
   526   movbool(rdx, do_not_unlock_if_synchronized);
   527   movbool(do_not_unlock_if_synchronized, false); // reset the flag
   529  // get method access flags
   530   movptr(rbx, Address(rbp, frame::interpreter_frame_method_offset * wordSize));
   531   movl(rcx, Address(rbx, methodOopDesc::access_flags_offset()));
   532   testl(rcx, JVM_ACC_SYNCHRONIZED);
   533   jcc(Assembler::zero, unlocked);
   535   // Don't unlock anything if the _do_not_unlock_if_synchronized flag
   536   // is set.
   537   testbool(rdx);
   538   jcc(Assembler::notZero, no_unlock);
   540   // unlock monitor
   541   push(state); // save result
   543   // BasicObjectLock will be first in list, since this is a
   544   // synchronized method. However, need to check that the object has
   545   // not been unlocked by an explicit monitorexit bytecode.
   546   const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset *
   547                         wordSize - (int) sizeof(BasicObjectLock));
   548   // We use c_rarg1 so that if we go slow path it will be the correct
   549   // register for unlock_object to pass to VM directly
   550   lea(c_rarg1, monitor); // address of first monitor
   552   movptr(rax, Address(c_rarg1, BasicObjectLock::obj_offset_in_bytes()));
   553   testptr(rax, rax);
   554   jcc(Assembler::notZero, unlock);
   556   pop(state);
   557   if (throw_monitor_exception) {
   558     // Entry already unlocked, need to throw exception
   559     call_VM(noreg, CAST_FROM_FN_PTR(address,
   560                    InterpreterRuntime::throw_illegal_monitor_state_exception));
   561     should_not_reach_here();
   562   } else {
   563     // Monitor already unlocked during a stack unroll. If requested,
   564     // install an illegal_monitor_state_exception.  Continue with
   565     // stack unrolling.
   566     if (install_monitor_exception) {
   567       call_VM(noreg, CAST_FROM_FN_PTR(address,
   568                      InterpreterRuntime::new_illegal_monitor_state_exception));
   569     }
   570     jmp(unlocked);
   571   }
   573   bind(unlock);
   574   unlock_object(c_rarg1);
   575   pop(state);
   577   // Check that for block-structured locking (i.e., that all locked
   578   // objects has been unlocked)
   579   bind(unlocked);
   581   // rax: Might contain return value
   583   // Check that all monitors are unlocked
   584   {
   585     Label loop, exception, entry, restart;
   586     const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
   587     const Address monitor_block_top(
   588         rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
   589     const Address monitor_block_bot(
   590         rbp, frame::interpreter_frame_initial_sp_offset * wordSize);
   592     bind(restart);
   593     // We use c_rarg1 so that if we go slow path it will be the correct
   594     // register for unlock_object to pass to VM directly
   595     movptr(c_rarg1, monitor_block_top); // points to current entry, starting
   596                                   // with top-most entry
   597     lea(rbx, monitor_block_bot);  // points to word before bottom of
   598                                   // monitor block
   599     jmp(entry);
   601     // Entry already locked, need to throw exception
   602     bind(exception);
   604     if (throw_monitor_exception) {
   605       // Throw exception
   606       MacroAssembler::call_VM(noreg,
   607                               CAST_FROM_FN_PTR(address, InterpreterRuntime::
   608                                    throw_illegal_monitor_state_exception));
   609       should_not_reach_here();
   610     } else {
   611       // Stack unrolling. Unlock object and install illegal_monitor_exception.
   612       // Unlock does not block, so don't have to worry about the frame.
   613       // We don't have to preserve c_rarg1 since we are going to throw an exception.
   615       push(state);
   616       unlock_object(c_rarg1);
   617       pop(state);
   619       if (install_monitor_exception) {
   620         call_VM(noreg, CAST_FROM_FN_PTR(address,
   621                                         InterpreterRuntime::
   622                                         new_illegal_monitor_state_exception));
   623       }
   625       jmp(restart);
   626     }
   628     bind(loop);
   629     // check if current entry is used
   630     cmpptr(Address(c_rarg1, BasicObjectLock::obj_offset_in_bytes()), (int32_t) NULL);
   631     jcc(Assembler::notEqual, exception);
   633     addptr(c_rarg1, entry_size); // otherwise advance to next entry
   634     bind(entry);
   635     cmpptr(c_rarg1, rbx); // check if bottom reached
   636     jcc(Assembler::notEqual, loop); // if not at bottom then check this entry
   637   }
   639   bind(no_unlock);
   641   // jvmti support
   642   if (notify_jvmdi) {
   643     notify_method_exit(state, NotifyJVMTI);    // preserve TOSCA
   644   } else {
   645     notify_method_exit(state, SkipNotifyJVMTI); // preserve TOSCA
   646   }
   648   // remove activation
   649   // get sender sp
   650   movptr(rbx,
   651          Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize));
   652   leave();                           // remove frame anchor
   653   pop(ret_addr);                     // get return address
   654   mov(rsp, rbx);                     // set sp to sender sp
   655 }
   657 #endif // C_INTERP
   659 // Lock object
   660 //
   661 // Args:
   662 //      c_rarg1: BasicObjectLock to be used for locking
   663 //
   664 // Kills:
   665 //      rax
   666 //      c_rarg0, c_rarg1, c_rarg2, c_rarg3, .. (param regs)
   667 //      rscratch1, rscratch2 (scratch regs)
   668 void InterpreterMacroAssembler::lock_object(Register lock_reg) {
   669   assert(lock_reg == c_rarg1, "The argument is only for looks. It must be c_rarg1");
   671   if (UseHeavyMonitors) {
   672     call_VM(noreg,
   673             CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
   674             lock_reg);
   675   } else {
   676     Label done;
   678     const Register swap_reg = rax; // Must use rax for cmpxchg instruction
   679     const Register obj_reg = c_rarg3; // Will contain the oop
   681     const int obj_offset = BasicObjectLock::obj_offset_in_bytes();
   682     const int lock_offset = BasicObjectLock::lock_offset_in_bytes ();
   683     const int mark_offset = lock_offset +
   684                             BasicLock::displaced_header_offset_in_bytes();
   686     Label slow_case;
   688     // Load object pointer into obj_reg %c_rarg3
   689     movptr(obj_reg, Address(lock_reg, obj_offset));
   691     if (UseBiasedLocking) {
   692       biased_locking_enter(lock_reg, obj_reg, swap_reg, rscratch1, false, done, &slow_case);
   693     }
   695     // Load immediate 1 into swap_reg %rax
   696     movl(swap_reg, 1);
   698     // Load (object->mark() | 1) into swap_reg %rax
   699     orptr(swap_reg, Address(obj_reg, 0));
   701     // Save (object->mark() | 1) into BasicLock's displaced header
   702     movptr(Address(lock_reg, mark_offset), swap_reg);
   704     assert(lock_offset == 0,
   705            "displached header must be first word in BasicObjectLock");
   707     if (os::is_MP()) lock();
   708     cmpxchgptr(lock_reg, Address(obj_reg, 0));
   709     if (PrintBiasedLockingStatistics) {
   710       cond_inc32(Assembler::zero,
   711                  ExternalAddress((address) BiasedLocking::fast_path_entry_count_addr()));
   712     }
   713     jcc(Assembler::zero, done);
   715     // Test if the oopMark is an obvious stack pointer, i.e.,
   716     //  1) (mark & 7) == 0, and
   717     //  2) rsp <= mark < mark + os::pagesize()
   718     //
   719     // These 3 tests can be done by evaluating the following
   720     // expression: ((mark - rsp) & (7 - os::vm_page_size())),
   721     // assuming both stack pointer and pagesize have their
   722     // least significant 3 bits clear.
   723     // NOTE: the oopMark is in swap_reg %rax as the result of cmpxchg
   724     subptr(swap_reg, rsp);
   725     andptr(swap_reg, 7 - os::vm_page_size());
   727     // Save the test result, for recursive case, the result is zero
   728     movptr(Address(lock_reg, mark_offset), swap_reg);
   730     if (PrintBiasedLockingStatistics) {
   731       cond_inc32(Assembler::zero,
   732                  ExternalAddress((address) BiasedLocking::fast_path_entry_count_addr()));
   733     }
   734     jcc(Assembler::zero, done);
   736     bind(slow_case);
   738     // Call the runtime routine for slow case
   739     call_VM(noreg,
   740             CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
   741             lock_reg);
   743     bind(done);
   744   }
   745 }
   748 // Unlocks an object. Used in monitorexit bytecode and
   749 // remove_activation.  Throws an IllegalMonitorException if object is
   750 // not locked by current thread.
   751 //
   752 // Args:
   753 //      c_rarg1: BasicObjectLock for lock
   754 //
   755 // Kills:
   756 //      rax
   757 //      c_rarg0, c_rarg1, c_rarg2, c_rarg3, ... (param regs)
   758 //      rscratch1, rscratch2 (scratch regs)
   759 void InterpreterMacroAssembler::unlock_object(Register lock_reg) {
   760   assert(lock_reg == c_rarg1, "The argument is only for looks. It must be rarg1");
   762   if (UseHeavyMonitors) {
   763     call_VM(noreg,
   764             CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit),
   765             lock_reg);
   766   } else {
   767     Label done;
   769     const Register swap_reg   = rax;  // Must use rax for cmpxchg instruction
   770     const Register header_reg = c_rarg2;  // Will contain the old oopMark
   771     const Register obj_reg    = c_rarg3;  // Will contain the oop
   773     save_bcp(); // Save in case of exception
   775     // Convert from BasicObjectLock structure to object and BasicLock
   776     // structure Store the BasicLock address into %rax
   777     lea(swap_reg, Address(lock_reg, BasicObjectLock::lock_offset_in_bytes()));
   779     // Load oop into obj_reg(%c_rarg3)
   780     movptr(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()));
   782     // Free entry
   783     movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()), (int32_t)NULL_WORD);
   785     if (UseBiasedLocking) {
   786       biased_locking_exit(obj_reg, header_reg, done);
   787     }
   789     // Load the old header from BasicLock structure
   790     movptr(header_reg, Address(swap_reg,
   791                                BasicLock::displaced_header_offset_in_bytes()));
   793     // Test for recursion
   794     testptr(header_reg, header_reg);
   796     // zero for recursive case
   797     jcc(Assembler::zero, done);
   799     // Atomic swap back the old header
   800     if (os::is_MP()) lock();
   801     cmpxchgptr(header_reg, Address(obj_reg, 0));
   803     // zero for recursive case
   804     jcc(Assembler::zero, done);
   806     // Call the runtime routine for slow case.
   807     movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()),
   808          obj_reg); // restore obj
   809     call_VM(noreg,
   810             CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit),
   811             lock_reg);
   813     bind(done);
   815     restore_bcp();
   816   }
   817 }
   819 #ifndef CC_INTERP
   821 void InterpreterMacroAssembler::test_method_data_pointer(Register mdp,
   822                                                          Label& zero_continue) {
   823   assert(ProfileInterpreter, "must be profiling interpreter");
   824   movptr(mdp, Address(rbp, frame::interpreter_frame_mdx_offset * wordSize));
   825   testptr(mdp, mdp);
   826   jcc(Assembler::zero, zero_continue);
   827 }
   830 // Set the method data pointer for the current bcp.
   831 void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() {
   832   assert(ProfileInterpreter, "must be profiling interpreter");
   833   Label zero_continue;
   834   push(rax);
   835   push(rbx);
   837   get_method(rbx);
   838   // Test MDO to avoid the call if it is NULL.
   839   movptr(rax, Address(rbx, in_bytes(methodOopDesc::method_data_offset())));
   840   testptr(rax, rax);
   841   jcc(Assembler::zero, zero_continue);
   843   // rbx: method
   844   // r13: bcp
   845   call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), rbx, r13);
   846   // rax: mdi
   848   movptr(rbx, Address(rbx, in_bytes(methodOopDesc::method_data_offset())));
   849   testptr(rbx, rbx);
   850   jcc(Assembler::zero, zero_continue);
   851   addptr(rbx, in_bytes(methodDataOopDesc::data_offset()));
   852   addptr(rbx, rax);
   853   movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), rbx);
   855   bind(zero_continue);
   856   pop(rbx);
   857   pop(rax);
   858 }
   860 void InterpreterMacroAssembler::verify_method_data_pointer() {
   861   assert(ProfileInterpreter, "must be profiling interpreter");
   862 #ifdef ASSERT
   863   Label verify_continue;
   864   push(rax);
   865   push(rbx);
   866   push(c_rarg3);
   867   push(c_rarg2);
   868   test_method_data_pointer(c_rarg3, verify_continue); // If mdp is zero, continue
   869   get_method(rbx);
   871   // If the mdp is valid, it will point to a DataLayout header which is
   872   // consistent with the bcp.  The converse is highly probable also.
   873   load_unsigned_short(c_rarg2,
   874                       Address(c_rarg3, in_bytes(DataLayout::bci_offset())));
   875   addptr(c_rarg2, Address(rbx, methodOopDesc::const_offset()));
   876   lea(c_rarg2, Address(c_rarg2, constMethodOopDesc::codes_offset()));
   877   cmpptr(c_rarg2, r13);
   878   jcc(Assembler::equal, verify_continue);
   879   // rbx: method
   880   // r13: bcp
   881   // c_rarg3: mdp
   882   call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp),
   883                rbx, r13, c_rarg3);
   884   bind(verify_continue);
   885   pop(c_rarg2);
   886   pop(c_rarg3);
   887   pop(rbx);
   888   pop(rax);
   889 #endif // ASSERT
   890 }
   893 void InterpreterMacroAssembler::set_mdp_data_at(Register mdp_in,
   894                                                 int constant,
   895                                                 Register value) {
   896   assert(ProfileInterpreter, "must be profiling interpreter");
   897   Address data(mdp_in, constant);
   898   movptr(data, value);
   899 }
   902 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
   903                                                       int constant,
   904                                                       bool decrement) {
   905   // Counter address
   906   Address data(mdp_in, constant);
   908   increment_mdp_data_at(data, decrement);
   909 }
   911 void InterpreterMacroAssembler::increment_mdp_data_at(Address data,
   912                                                       bool decrement) {
   913   assert(ProfileInterpreter, "must be profiling interpreter");
   914   // %%% this does 64bit counters at best it is wasting space
   915   // at worst it is a rare bug when counters overflow
   917   if (decrement) {
   918     // Decrement the register.  Set condition codes.
   919     addptr(data, (int32_t) -DataLayout::counter_increment);
   920     // If the decrement causes the counter to overflow, stay negative
   921     Label L;
   922     jcc(Assembler::negative, L);
   923     addptr(data, (int32_t) DataLayout::counter_increment);
   924     bind(L);
   925   } else {
   926     assert(DataLayout::counter_increment == 1,
   927            "flow-free idiom only works with 1");
   928     // Increment the register.  Set carry flag.
   929     addptr(data, DataLayout::counter_increment);
   930     // If the increment causes the counter to overflow, pull back by 1.
   931     sbbptr(data, (int32_t)0);
   932   }
   933 }
   936 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
   937                                                       Register reg,
   938                                                       int constant,
   939                                                       bool decrement) {
   940   Address data(mdp_in, reg, Address::times_1, constant);
   942   increment_mdp_data_at(data, decrement);
   943 }
   945 void InterpreterMacroAssembler::set_mdp_flag_at(Register mdp_in,
   946                                                 int flag_byte_constant) {
   947   assert(ProfileInterpreter, "must be profiling interpreter");
   948   int header_offset = in_bytes(DataLayout::header_offset());
   949   int header_bits = DataLayout::flag_mask_to_header_mask(flag_byte_constant);
   950   // Set the flag
   951   orl(Address(mdp_in, header_offset), header_bits);
   952 }
   956 void InterpreterMacroAssembler::test_mdp_data_at(Register mdp_in,
   957                                                  int offset,
   958                                                  Register value,
   959                                                  Register test_value_out,
   960                                                  Label& not_equal_continue) {
   961   assert(ProfileInterpreter, "must be profiling interpreter");
   962   if (test_value_out == noreg) {
   963     cmpptr(value, Address(mdp_in, offset));
   964   } else {
   965     // Put the test value into a register, so caller can use it:
   966     movptr(test_value_out, Address(mdp_in, offset));
   967     cmpptr(test_value_out, value);
   968   }
   969   jcc(Assembler::notEqual, not_equal_continue);
   970 }
   973 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,
   974                                                      int offset_of_disp) {
   975   assert(ProfileInterpreter, "must be profiling interpreter");
   976   Address disp_address(mdp_in, offset_of_disp);
   977   addptr(mdp_in, disp_address);
   978   movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in);
   979 }
   982 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,
   983                                                      Register reg,
   984                                                      int offset_of_disp) {
   985   assert(ProfileInterpreter, "must be profiling interpreter");
   986   Address disp_address(mdp_in, reg, Address::times_1, offset_of_disp);
   987   addptr(mdp_in, disp_address);
   988   movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in);
   989 }
   992 void InterpreterMacroAssembler::update_mdp_by_constant(Register mdp_in,
   993                                                        int constant) {
   994   assert(ProfileInterpreter, "must be profiling interpreter");
   995   addptr(mdp_in, constant);
   996   movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in);
   997 }
  1000 void InterpreterMacroAssembler::update_mdp_for_ret(Register return_bci) {
  1001   assert(ProfileInterpreter, "must be profiling interpreter");
  1002   push(return_bci); // save/restore across call_VM
  1003   call_VM(noreg,
  1004           CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret),
  1005           return_bci);
  1006   pop(return_bci);
  1010 void InterpreterMacroAssembler::profile_taken_branch(Register mdp,
  1011                                                      Register bumped_count) {
  1012   if (ProfileInterpreter) {
  1013     Label profile_continue;
  1015     // If no method data exists, go to profile_continue.
  1016     // Otherwise, assign to mdp
  1017     test_method_data_pointer(mdp, profile_continue);
  1019     // We are taking a branch.  Increment the taken count.
  1020     // We inline increment_mdp_data_at to return bumped_count in a register
  1021     //increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset()));
  1022     Address data(mdp, in_bytes(JumpData::taken_offset()));
  1023     movptr(bumped_count, data);
  1024     assert(DataLayout::counter_increment == 1,
  1025             "flow-free idiom only works with 1");
  1026     addptr(bumped_count, DataLayout::counter_increment);
  1027     sbbptr(bumped_count, 0);
  1028     movptr(data, bumped_count); // Store back out
  1030     // The method data pointer needs to be updated to reflect the new target.
  1031     update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset()));
  1032     bind(profile_continue);
  1037 void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp) {
  1038   if (ProfileInterpreter) {
  1039     Label profile_continue;
  1041     // If no method data exists, go to profile_continue.
  1042     test_method_data_pointer(mdp, profile_continue);
  1044     // We are taking a branch.  Increment the not taken count.
  1045     increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset()));
  1047     // The method data pointer needs to be updated to correspond to
  1048     // the next bytecode
  1049     update_mdp_by_constant(mdp, in_bytes(BranchData::branch_data_size()));
  1050     bind(profile_continue);
  1055 void InterpreterMacroAssembler::profile_call(Register mdp) {
  1056   if (ProfileInterpreter) {
  1057     Label profile_continue;
  1059     // If no method data exists, go to profile_continue.
  1060     test_method_data_pointer(mdp, profile_continue);
  1062     // We are making a call.  Increment the count.
  1063     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1065     // The method data pointer needs to be updated to reflect the new target.
  1066     update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size()));
  1067     bind(profile_continue);
  1072 void InterpreterMacroAssembler::profile_final_call(Register mdp) {
  1073   if (ProfileInterpreter) {
  1074     Label profile_continue;
  1076     // If no method data exists, go to profile_continue.
  1077     test_method_data_pointer(mdp, profile_continue);
  1079     // We are making a call.  Increment the count.
  1080     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1082     // The method data pointer needs to be updated to reflect the new target.
  1083     update_mdp_by_constant(mdp,
  1084                            in_bytes(VirtualCallData::
  1085                                     virtual_call_data_size()));
  1086     bind(profile_continue);
  1091 void InterpreterMacroAssembler::profile_virtual_call(Register receiver,
  1092                                                      Register mdp,
  1093                                                      Register reg2,
  1094                                                      bool receiver_can_be_null) {
  1095   if (ProfileInterpreter) {
  1096     Label profile_continue;
  1098     // If no method data exists, go to profile_continue.
  1099     test_method_data_pointer(mdp, profile_continue);
  1101     Label skip_receiver_profile;
  1102     if (receiver_can_be_null) {
  1103       Label not_null;
  1104       testptr(receiver, receiver);
  1105       jccb(Assembler::notZero, not_null);
  1106       // We are making a call.  Increment the count for null receiver.
  1107       increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1108       jmp(skip_receiver_profile);
  1109       bind(not_null);
  1112     // Record the receiver type.
  1113     record_klass_in_profile(receiver, mdp, reg2, true);
  1114     bind(skip_receiver_profile);
  1116     // The method data pointer needs to be updated to reflect the new target.
  1117     update_mdp_by_constant(mdp,
  1118                            in_bytes(VirtualCallData::
  1119                                     virtual_call_data_size()));
  1120     bind(profile_continue);
  1124 // This routine creates a state machine for updating the multi-row
  1125 // type profile at a virtual call site (or other type-sensitive bytecode).
  1126 // The machine visits each row (of receiver/count) until the receiver type
  1127 // is found, or until it runs out of rows.  At the same time, it remembers
  1128 // the location of the first empty row.  (An empty row records null for its
  1129 // receiver, and can be allocated for a newly-observed receiver type.)
  1130 // Because there are two degrees of freedom in the state, a simple linear
  1131 // search will not work; it must be a decision tree.  Hence this helper
  1132 // function is recursive, to generate the required tree structured code.
  1133 // It's the interpreter, so we are trading off code space for speed.
  1134 // See below for example code.
  1135 void InterpreterMacroAssembler::record_klass_in_profile_helper(
  1136                                         Register receiver, Register mdp,
  1137                                         Register reg2, int start_row,
  1138                                         Label& done, bool is_virtual_call) {
  1139   if (TypeProfileWidth == 0) {
  1140     if (is_virtual_call) {
  1141       increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1143     return;
  1146   int last_row = VirtualCallData::row_limit() - 1;
  1147   assert(start_row <= last_row, "must be work left to do");
  1148   // Test this row for both the receiver and for null.
  1149   // Take any of three different outcomes:
  1150   //   1. found receiver => increment count and goto done
  1151   //   2. found null => keep looking for case 1, maybe allocate this cell
  1152   //   3. found something else => keep looking for cases 1 and 2
  1153   // Case 3 is handled by a recursive call.
  1154   for (int row = start_row; row <= last_row; row++) {
  1155     Label next_test;
  1156     bool test_for_null_also = (row == start_row);
  1158     // See if the receiver is receiver[n].
  1159     int recvr_offset = in_bytes(VirtualCallData::receiver_offset(row));
  1160     test_mdp_data_at(mdp, recvr_offset, receiver,
  1161                      (test_for_null_also ? reg2 : noreg),
  1162                      next_test);
  1163     // (Reg2 now contains the receiver from the CallData.)
  1165     // The receiver is receiver[n].  Increment count[n].
  1166     int count_offset = in_bytes(VirtualCallData::receiver_count_offset(row));
  1167     increment_mdp_data_at(mdp, count_offset);
  1168     jmp(done);
  1169     bind(next_test);
  1171     if (test_for_null_also) {
  1172       Label found_null;
  1173       // Failed the equality check on receiver[n]...  Test for null.
  1174       testptr(reg2, reg2);
  1175       if (start_row == last_row) {
  1176         // The only thing left to do is handle the null case.
  1177         if (is_virtual_call) {
  1178           jccb(Assembler::zero, found_null);
  1179           // Receiver did not match any saved receiver and there is no empty row for it.
  1180           // Increment total counter to indicate polymorphic case.
  1181           increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1182           jmp(done);
  1183           bind(found_null);
  1184         } else {
  1185           jcc(Assembler::notZero, done);
  1187         break;
  1189       // Since null is rare, make it be the branch-taken case.
  1190       jcc(Assembler::zero, found_null);
  1192       // Put all the "Case 3" tests here.
  1193       record_klass_in_profile_helper(receiver, mdp, reg2, start_row + 1, done, is_virtual_call);
  1195       // Found a null.  Keep searching for a matching receiver,
  1196       // but remember that this is an empty (unused) slot.
  1197       bind(found_null);
  1201   // In the fall-through case, we found no matching receiver, but we
  1202   // observed the receiver[start_row] is NULL.
  1204   // Fill in the receiver field and increment the count.
  1205   int recvr_offset = in_bytes(VirtualCallData::receiver_offset(start_row));
  1206   set_mdp_data_at(mdp, recvr_offset, receiver);
  1207   int count_offset = in_bytes(VirtualCallData::receiver_count_offset(start_row));
  1208   movl(reg2, DataLayout::counter_increment);
  1209   set_mdp_data_at(mdp, count_offset, reg2);
  1210   if (start_row > 0) {
  1211     jmp(done);
  1215 // Example state machine code for three profile rows:
  1216 //   // main copy of decision tree, rooted at row[1]
  1217 //   if (row[0].rec == rec) { row[0].incr(); goto done; }
  1218 //   if (row[0].rec != NULL) {
  1219 //     // inner copy of decision tree, rooted at row[1]
  1220 //     if (row[1].rec == rec) { row[1].incr(); goto done; }
  1221 //     if (row[1].rec != NULL) {
  1222 //       // degenerate decision tree, rooted at row[2]
  1223 //       if (row[2].rec == rec) { row[2].incr(); goto done; }
  1224 //       if (row[2].rec != NULL) { count.incr(); goto done; } // overflow
  1225 //       row[2].init(rec); goto done;
  1226 //     } else {
  1227 //       // remember row[1] is empty
  1228 //       if (row[2].rec == rec) { row[2].incr(); goto done; }
  1229 //       row[1].init(rec); goto done;
  1230 //     }
  1231 //   } else {
  1232 //     // remember row[0] is empty
  1233 //     if (row[1].rec == rec) { row[1].incr(); goto done; }
  1234 //     if (row[2].rec == rec) { row[2].incr(); goto done; }
  1235 //     row[0].init(rec); goto done;
  1236 //   }
  1237 //   done:
  1239 void InterpreterMacroAssembler::record_klass_in_profile(Register receiver,
  1240                                                         Register mdp, Register reg2,
  1241                                                         bool is_virtual_call) {
  1242   assert(ProfileInterpreter, "must be profiling");
  1243   Label done;
  1245   record_klass_in_profile_helper(receiver, mdp, reg2, 0, done, is_virtual_call);
  1247   bind (done);
  1250 void InterpreterMacroAssembler::profile_ret(Register return_bci,
  1251                                             Register mdp) {
  1252   if (ProfileInterpreter) {
  1253     Label profile_continue;
  1254     uint row;
  1256     // If no method data exists, go to profile_continue.
  1257     test_method_data_pointer(mdp, profile_continue);
  1259     // Update the total ret count.
  1260     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1262     for (row = 0; row < RetData::row_limit(); row++) {
  1263       Label next_test;
  1265       // See if return_bci is equal to bci[n]:
  1266       test_mdp_data_at(mdp,
  1267                        in_bytes(RetData::bci_offset(row)),
  1268                        return_bci, noreg,
  1269                        next_test);
  1271       // return_bci is equal to bci[n].  Increment the count.
  1272       increment_mdp_data_at(mdp, in_bytes(RetData::bci_count_offset(row)));
  1274       // The method data pointer needs to be updated to reflect the new target.
  1275       update_mdp_by_offset(mdp,
  1276                            in_bytes(RetData::bci_displacement_offset(row)));
  1277       jmp(profile_continue);
  1278       bind(next_test);
  1281     update_mdp_for_ret(return_bci);
  1283     bind(profile_continue);
  1288 void InterpreterMacroAssembler::profile_null_seen(Register mdp) {
  1289   if (ProfileInterpreter) {
  1290     Label profile_continue;
  1292     // If no method data exists, go to profile_continue.
  1293     test_method_data_pointer(mdp, profile_continue);
  1295     set_mdp_flag_at(mdp, BitData::null_seen_byte_constant());
  1297     // The method data pointer needs to be updated.
  1298     int mdp_delta = in_bytes(BitData::bit_data_size());
  1299     if (TypeProfileCasts) {
  1300       mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
  1302     update_mdp_by_constant(mdp, mdp_delta);
  1304     bind(profile_continue);
  1309 void InterpreterMacroAssembler::profile_typecheck_failed(Register mdp) {
  1310   if (ProfileInterpreter && TypeProfileCasts) {
  1311     Label profile_continue;
  1313     // If no method data exists, go to profile_continue.
  1314     test_method_data_pointer(mdp, profile_continue);
  1316     int count_offset = in_bytes(CounterData::count_offset());
  1317     // Back up the address, since we have already bumped the mdp.
  1318     count_offset -= in_bytes(VirtualCallData::virtual_call_data_size());
  1320     // *Decrement* the counter.  We expect to see zero or small negatives.
  1321     increment_mdp_data_at(mdp, count_offset, true);
  1323     bind (profile_continue);
  1328 void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2) {
  1329   if (ProfileInterpreter) {
  1330     Label profile_continue;
  1332     // If no method data exists, go to profile_continue.
  1333     test_method_data_pointer(mdp, profile_continue);
  1335     // The method data pointer needs to be updated.
  1336     int mdp_delta = in_bytes(BitData::bit_data_size());
  1337     if (TypeProfileCasts) {
  1338       mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
  1340       // Record the object type.
  1341       record_klass_in_profile(klass, mdp, reg2, false);
  1343     update_mdp_by_constant(mdp, mdp_delta);
  1345     bind(profile_continue);
  1350 void InterpreterMacroAssembler::profile_switch_default(Register mdp) {
  1351   if (ProfileInterpreter) {
  1352     Label profile_continue;
  1354     // If no method data exists, go to profile_continue.
  1355     test_method_data_pointer(mdp, profile_continue);
  1357     // Update the default case count
  1358     increment_mdp_data_at(mdp,
  1359                           in_bytes(MultiBranchData::default_count_offset()));
  1361     // The method data pointer needs to be updated.
  1362     update_mdp_by_offset(mdp,
  1363                          in_bytes(MultiBranchData::
  1364                                   default_displacement_offset()));
  1366     bind(profile_continue);
  1371 void InterpreterMacroAssembler::profile_switch_case(Register index,
  1372                                                     Register mdp,
  1373                                                     Register reg2) {
  1374   if (ProfileInterpreter) {
  1375     Label profile_continue;
  1377     // If no method data exists, go to profile_continue.
  1378     test_method_data_pointer(mdp, profile_continue);
  1380     // Build the base (index * per_case_size_in_bytes()) +
  1381     // case_array_offset_in_bytes()
  1382     movl(reg2, in_bytes(MultiBranchData::per_case_size()));
  1383     imulptr(index, reg2); // XXX l ?
  1384     addptr(index, in_bytes(MultiBranchData::case_array_offset())); // XXX l ?
  1386     // Update the case count
  1387     increment_mdp_data_at(mdp,
  1388                           index,
  1389                           in_bytes(MultiBranchData::relative_count_offset()));
  1391     // The method data pointer needs to be updated.
  1392     update_mdp_by_offset(mdp,
  1393                          index,
  1394                          in_bytes(MultiBranchData::
  1395                                   relative_displacement_offset()));
  1397     bind(profile_continue);
  1403 void InterpreterMacroAssembler::verify_oop(Register reg, TosState state) {
  1404   if (state == atos) {
  1405     MacroAssembler::verify_oop(reg);
  1409 void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) {
  1411 #endif // !CC_INTERP
  1414 void InterpreterMacroAssembler::notify_method_entry() {
  1415   // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
  1416   // track stack depth.  If it is possible to enter interp_only_mode we add
  1417   // the code to check if the event should be sent.
  1418   if (JvmtiExport::can_post_interpreter_events()) {
  1419     Label L;
  1420     movl(rdx, Address(r15_thread, JavaThread::interp_only_mode_offset()));
  1421     testl(rdx, rdx);
  1422     jcc(Assembler::zero, L);
  1423     call_VM(noreg, CAST_FROM_FN_PTR(address,
  1424                                     InterpreterRuntime::post_method_entry));
  1425     bind(L);
  1429     SkipIfEqual skip(this, &DTraceMethodProbes, false);
  1430     get_method(c_rarg1);
  1431     call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry),
  1432                  r15_thread, c_rarg1);
  1435   // RedefineClasses() tracing support for obsolete method entry
  1436   if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
  1437     get_method(c_rarg1);
  1438     call_VM_leaf(
  1439       CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry),
  1440       r15_thread, c_rarg1);
  1445 void InterpreterMacroAssembler::notify_method_exit(
  1446     TosState state, NotifyMethodExitMode mode) {
  1447   // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
  1448   // track stack depth.  If it is possible to enter interp_only_mode we add
  1449   // the code to check if the event should be sent.
  1450   if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) {
  1451     Label L;
  1452     // Note: frame::interpreter_frame_result has a dependency on how the
  1453     // method result is saved across the call to post_method_exit. If this
  1454     // is changed then the interpreter_frame_result implementation will
  1455     // need to be updated too.
  1457     // For c++ interpreter the result is always stored at a known location in the frame
  1458     // template interpreter will leave it on the top of the stack.
  1459     NOT_CC_INTERP(push(state);)
  1460     movl(rdx, Address(r15_thread, JavaThread::interp_only_mode_offset()));
  1461     testl(rdx, rdx);
  1462     jcc(Assembler::zero, L);
  1463     call_VM(noreg,
  1464             CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit));
  1465     bind(L);
  1466     NOT_CC_INTERP(pop(state));
  1470     SkipIfEqual skip(this, &DTraceMethodProbes, false);
  1471     NOT_CC_INTERP(push(state));
  1472     get_method(c_rarg1);
  1473     call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),
  1474                  r15_thread, c_rarg1);
  1475     NOT_CC_INTERP(pop(state));

mercurial