src/cpu/x86/vm/interp_masm_x86_32.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) 1997, 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_32.cpp.incl"
    29 // Implementation of InterpreterMacroAssembler
    30 #ifdef CC_INTERP
    31 void InterpreterMacroAssembler::get_method(Register reg) {
    32   movptr(reg, Address(rbp, -(sizeof(BytecodeInterpreter) + 2 * wordSize)));
    33   movptr(reg, Address(reg, byte_offset_of(BytecodeInterpreter, _method)));
    34 }
    35 #endif // CC_INTERP
    38 #ifndef CC_INTERP
    39 void InterpreterMacroAssembler::call_VM_leaf_base(
    40   address entry_point,
    41   int     number_of_arguments
    42 ) {
    43   // interpreter specific
    44   //
    45   // Note: No need to save/restore bcp & locals (rsi & rdi) pointer
    46   //       since these are callee saved registers and no blocking/
    47   //       GC can happen in leaf calls.
    48   // Further Note: DO NOT save/restore bcp/locals. If a caller has
    49   // already saved them so that it can use rsi/rdi as temporaries
    50   // then a save/restore here will DESTROY the copy the caller
    51   // saved! There used to be a save_bcp() that only happened in
    52   // the ASSERT path (no restore_bcp). Which caused bizarre failures
    53   // when jvm built with ASSERTs.
    54 #ifdef ASSERT
    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: last_sp != NULL");
    59     bind(L);
    60   }
    61 #endif
    62   // super call
    63   MacroAssembler::call_VM_leaf_base(entry_point, number_of_arguments);
    64   // interpreter specific
    66   // Used to ASSERT that rsi/rdi were equal to frame's bcp/locals
    67   // but since they may not have been saved (and we don't want to
    68   // save them here (see note above) the assert is invalid.
    69 }
    72 void InterpreterMacroAssembler::call_VM_base(
    73   Register oop_result,
    74   Register java_thread,
    75   Register last_java_sp,
    76   address  entry_point,
    77   int      number_of_arguments,
    78   bool     check_exceptions
    79 ) {
    80 #ifdef ASSERT
    81   { Label L;
    82     cmpptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
    83     jcc(Assembler::equal, L);
    84     stop("InterpreterMacroAssembler::call_VM_base: last_sp != NULL");
    85     bind(L);
    86   }
    87 #endif /* ASSERT */
    88   // interpreter specific
    89   //
    90   // Note: Could avoid restoring locals ptr (callee saved) - however doesn't
    91   //       really make a difference for these runtime calls, since they are
    92   //       slow anyway. Btw., bcp must be saved/restored since it may change
    93   //       due to GC.
    94   assert(java_thread == noreg , "not expecting a precomputed java thread");
    95   save_bcp();
    96   // super call
    97   MacroAssembler::call_VM_base(oop_result, java_thread, last_java_sp, entry_point, number_of_arguments, check_exceptions);
    98   // interpreter specific
    99   restore_bcp();
   100   restore_locals();
   101 }
   104 void InterpreterMacroAssembler::check_and_handle_popframe(Register java_thread) {
   105   if (JvmtiExport::can_pop_frame()) {
   106     Label L;
   107     // Initiate popframe handling only if it is not already being processed.  If the flag
   108     // has the popframe_processing bit set, it means that this code is called *during* popframe
   109     // handling - we don't want to reenter.
   110     Register pop_cond = java_thread;  // Not clear if any other register is available...
   111     movl(pop_cond, Address(java_thread, JavaThread::popframe_condition_offset()));
   112     testl(pop_cond, JavaThread::popframe_pending_bit);
   113     jcc(Assembler::zero, L);
   114     testl(pop_cond, JavaThread::popframe_processing_bit);
   115     jcc(Assembler::notZero, L);
   116     // Call Interpreter::remove_activation_preserving_args_entry() to get the
   117     // address of the same-named entrypoint in the generated interpreter code.
   118     call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_preserving_args_entry));
   119     jmp(rax);
   120     bind(L);
   121     get_thread(java_thread);
   122   }
   123 }
   126 void InterpreterMacroAssembler::load_earlyret_value(TosState state) {
   127   get_thread(rcx);
   128   movl(rcx, Address(rcx, JavaThread::jvmti_thread_state_offset()));
   129   const Address tos_addr (rcx, JvmtiThreadState::earlyret_tos_offset());
   130   const Address oop_addr (rcx, JvmtiThreadState::earlyret_oop_offset());
   131   const Address val_addr (rcx, JvmtiThreadState::earlyret_value_offset());
   132   const Address val_addr1(rcx, JvmtiThreadState::earlyret_value_offset()
   133                              + in_ByteSize(wordSize));
   134   switch (state) {
   135     case atos: movptr(rax, oop_addr);
   136                movptr(oop_addr, NULL_WORD);
   137                verify_oop(rax, state);                break;
   138     case ltos:
   139                movl(rdx, val_addr1);               // fall through
   140     case btos:                                     // fall through
   141     case ctos:                                     // fall through
   142     case stos:                                     // fall through
   143     case itos: movl(rax, val_addr);                   break;
   144     case ftos: fld_s(val_addr);                       break;
   145     case dtos: fld_d(val_addr);                       break;
   146     case vtos: /* nothing to do */                    break;
   147     default  : ShouldNotReachHere();
   148   }
   149   // Clean up tos value in the thread object
   150   movl(tos_addr,  (int32_t) ilgl);
   151   movptr(val_addr,  NULL_WORD);
   152   NOT_LP64(movptr(val_addr1, NULL_WORD));
   153 }
   156 void InterpreterMacroAssembler::check_and_handle_earlyret(Register java_thread) {
   157   if (JvmtiExport::can_force_early_return()) {
   158     Label L;
   159     Register tmp = java_thread;
   160     movptr(tmp, Address(tmp, JavaThread::jvmti_thread_state_offset()));
   161     testptr(tmp, tmp);
   162     jcc(Assembler::zero, L); // if (thread->jvmti_thread_state() == NULL) exit;
   164     // Initiate earlyret handling only if it is not already being processed.
   165     // If the flag has the earlyret_processing bit set, it means that this code
   166     // is called *during* earlyret handling - we don't want to reenter.
   167     movl(tmp, Address(tmp, JvmtiThreadState::earlyret_state_offset()));
   168     cmpl(tmp, JvmtiThreadState::earlyret_pending);
   169     jcc(Assembler::notEqual, L);
   171     // Call Interpreter::remove_activation_early_entry() to get the address of the
   172     // same-named entrypoint in the generated interpreter code.
   173     get_thread(java_thread);
   174     movptr(tmp, Address(java_thread, JavaThread::jvmti_thread_state_offset()));
   175     pushl(Address(tmp, JvmtiThreadState::earlyret_tos_offset()));
   176     call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry), 1);
   177     jmp(rax);
   178     bind(L);
   179     get_thread(java_thread);
   180   }
   181 }
   184 void InterpreterMacroAssembler::get_unsigned_2_byte_index_at_bcp(Register reg, int bcp_offset) {
   185   assert(bcp_offset >= 0, "bcp is still pointing to start of bytecode");
   186   movl(reg, Address(rsi, bcp_offset));
   187   bswapl(reg);
   188   shrl(reg, 16);
   189 }
   192 void InterpreterMacroAssembler::get_cache_index_at_bcp(Register reg, int bcp_offset, bool giant_index) {
   193   assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");
   194   if (!giant_index) {
   195     load_unsigned_short(reg, Address(rsi, bcp_offset));
   196   } else {
   197     assert(EnableInvokeDynamic, "giant index used only for EnableInvokeDynamic");
   198     movl(reg, Address(rsi, bcp_offset));
   199     // Check if the secondary index definition is still ~x, otherwise
   200     // we have to change the following assembler code to calculate the
   201     // plain index.
   202     assert(constantPoolCacheOopDesc::decode_secondary_index(~123) == 123, "else change next line");
   203     notl(reg);  // convert to plain index
   204   }
   205 }
   208 void InterpreterMacroAssembler::get_cache_and_index_at_bcp(Register cache, Register index,
   209                                                            int bcp_offset, 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   shlptr(index, 2); // convert from field index to ConstantPoolCacheEntry index
   215 }
   218 void InterpreterMacroAssembler::get_cache_entry_pointer_at_bcp(Register cache, Register tmp,
   219                                                                int bcp_offset, bool giant_index) {
   220   assert(cache != tmp, "must use different register");
   221   get_cache_index_at_bcp(tmp, bcp_offset, giant_index);
   222   assert(sizeof(ConstantPoolCacheEntry) == 4*wordSize, "adjust code below");
   223                                // convert from field index to ConstantPoolCacheEntry index
   224                                // and from word offset to byte offset
   225   shll(tmp, 2 + LogBytesPerWord);
   226   movptr(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize));
   227                                // skip past the header
   228   addptr(cache, in_bytes(constantPoolCacheOopDesc::base_offset()));
   229   addptr(cache, tmp);            // construct pointer to cache entry
   230 }
   233   // Generate a subtype check: branch to ok_is_subtype if sub_klass is
   234   // a subtype of super_klass.  EAX holds the super_klass.  Blows ECX.
   235   // Resets EDI to locals.  Register sub_klass cannot be any of the above.
   236 void InterpreterMacroAssembler::gen_subtype_check( Register Rsub_klass, Label &ok_is_subtype ) {
   237   assert( Rsub_klass != rax, "rax, holds superklass" );
   238   assert( Rsub_klass != rcx, "used as a temp" );
   239   assert( Rsub_klass != rdi, "used as a temp, restored from locals" );
   241   // Profile the not-null value's klass.
   242   profile_typecheck(rcx, Rsub_klass, rdi); // blows rcx, reloads rdi
   244   // Do the check.
   245   check_klass_subtype(Rsub_klass, rax, rcx, ok_is_subtype); // blows rcx
   247   // Profile the failure of the check.
   248   profile_typecheck_failed(rcx); // blows rcx
   249 }
   251 void InterpreterMacroAssembler::f2ieee() {
   252   if (IEEEPrecision) {
   253     fstp_s(Address(rsp, 0));
   254     fld_s(Address(rsp, 0));
   255   }
   256 }
   259 void InterpreterMacroAssembler::d2ieee() {
   260   if (IEEEPrecision) {
   261     fstp_d(Address(rsp, 0));
   262     fld_d(Address(rsp, 0));
   263   }
   264 }
   266 // Java Expression Stack
   268 void InterpreterMacroAssembler::pop_ptr(Register r) {
   269   pop(r);
   270 }
   272 void InterpreterMacroAssembler::pop_i(Register r) {
   273   pop(r);
   274 }
   276 void InterpreterMacroAssembler::pop_l(Register lo, Register hi) {
   277   pop(lo);
   278   pop(hi);
   279 }
   281 void InterpreterMacroAssembler::pop_f() {
   282   fld_s(Address(rsp, 0));
   283   addptr(rsp, 1 * wordSize);
   284 }
   286 void InterpreterMacroAssembler::pop_d() {
   287   fld_d(Address(rsp, 0));
   288   addptr(rsp, 2 * wordSize);
   289 }
   292 void InterpreterMacroAssembler::pop(TosState state) {
   293   switch (state) {
   294     case atos: pop_ptr(rax);                                 break;
   295     case btos:                                               // fall through
   296     case ctos:                                               // fall through
   297     case stos:                                               // fall through
   298     case itos: pop_i(rax);                                   break;
   299     case ltos: pop_l(rax, rdx);                              break;
   300     case ftos: pop_f();                                      break;
   301     case dtos: pop_d();                                      break;
   302     case vtos: /* nothing to do */                           break;
   303     default  : ShouldNotReachHere();
   304   }
   305   verify_oop(rax, state);
   306 }
   308 void InterpreterMacroAssembler::push_ptr(Register r) {
   309   push(r);
   310 }
   312 void InterpreterMacroAssembler::push_i(Register r) {
   313   push(r);
   314 }
   316 void InterpreterMacroAssembler::push_l(Register lo, Register hi) {
   317   push(hi);
   318   push(lo);
   319 }
   321 void InterpreterMacroAssembler::push_f() {
   322   // Do not schedule for no AGI! Never write beyond rsp!
   323   subptr(rsp, 1 * wordSize);
   324   fstp_s(Address(rsp, 0));
   325 }
   327 void InterpreterMacroAssembler::push_d(Register r) {
   328   // Do not schedule for no AGI! Never write beyond rsp!
   329   subptr(rsp, 2 * wordSize);
   330   fstp_d(Address(rsp, 0));
   331 }
   334 void InterpreterMacroAssembler::push(TosState state) {
   335   verify_oop(rax, state);
   336   switch (state) {
   337     case atos: push_ptr(rax); break;
   338     case btos:                                               // fall through
   339     case ctos:                                               // fall through
   340     case stos:                                               // fall through
   341     case itos: push_i(rax);                                    break;
   342     case ltos: push_l(rax, rdx);                               break;
   343     case ftos: push_f();                                       break;
   344     case dtos: push_d(rax);                                    break;
   345     case vtos: /* nothing to do */                             break;
   346     default  : ShouldNotReachHere();
   347   }
   348 }
   351 // Helpers for swap and dup
   352 void InterpreterMacroAssembler::load_ptr(int n, Register val) {
   353   movptr(val, Address(rsp, Interpreter::expr_offset_in_bytes(n)));
   354 }
   356 void InterpreterMacroAssembler::store_ptr(int n, Register val) {
   357   movptr(Address(rsp, Interpreter::expr_offset_in_bytes(n)), val);
   358 }
   360 void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point) {
   361   MacroAssembler::call_VM_leaf_base(entry_point, 0);
   362 }
   365 void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point, Register arg_1) {
   366   push(arg_1);
   367   MacroAssembler::call_VM_leaf_base(entry_point, 1);
   368 }
   371 void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point, Register arg_1, Register arg_2) {
   372   push(arg_2);
   373   push(arg_1);
   374   MacroAssembler::call_VM_leaf_base(entry_point, 2);
   375 }
   378 void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point, Register arg_1, Register arg_2, Register arg_3) {
   379   push(arg_3);
   380   push(arg_2);
   381   push(arg_1);
   382   MacroAssembler::call_VM_leaf_base(entry_point, 3);
   383 }
   386 void InterpreterMacroAssembler::prepare_to_jump_from_interpreted() {
   387   // set sender sp
   388   lea(rsi, Address(rsp, wordSize));
   389   // record last_sp
   390   movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), rsi);
   391 }
   394 // Jump to from_interpreted entry of a call unless single stepping is possible
   395 // in this thread in which case we must call the i2i entry
   396 void InterpreterMacroAssembler::jump_from_interpreted(Register method, Register temp) {
   397   prepare_to_jump_from_interpreted();
   399   if (JvmtiExport::can_post_interpreter_events()) {
   400     Label run_compiled_code;
   401     // JVMTI events, such as single-stepping, are implemented partly by avoiding running
   402     // compiled code in threads for which the event is enabled.  Check here for
   403     // interp_only_mode if these events CAN be enabled.
   404     get_thread(temp);
   405     // interp_only is an int, on little endian it is sufficient to test the byte only
   406     // Is a cmpl faster (ce
   407     cmpb(Address(temp, JavaThread::interp_only_mode_offset()), 0);
   408     jcc(Assembler::zero, run_compiled_code);
   409     jmp(Address(method, methodOopDesc::interpreter_entry_offset()));
   410     bind(run_compiled_code);
   411   }
   413   jmp(Address(method, methodOopDesc::from_interpreted_offset()));
   415 }
   418 // The following two routines provide a hook so that an implementation
   419 // can schedule the dispatch in two parts.  Intel does not do this.
   420 void InterpreterMacroAssembler::dispatch_prolog(TosState state, int step) {
   421   // Nothing Intel-specific to be done here.
   422 }
   424 void InterpreterMacroAssembler::dispatch_epilog(TosState state, int step) {
   425   dispatch_next(state, step);
   426 }
   428 void InterpreterMacroAssembler::dispatch_base(TosState state, address* table,
   429                                               bool verifyoop) {
   430   verify_FPU(1, state);
   431   if (VerifyActivationFrameSize) {
   432     Label L;
   433     mov(rcx, rbp);
   434     subptr(rcx, rsp);
   435     int min_frame_size = (frame::link_offset - frame::interpreter_frame_initial_sp_offset) * wordSize;
   436     cmpptr(rcx, min_frame_size);
   437     jcc(Assembler::greaterEqual, L);
   438     stop("broken stack frame");
   439     bind(L);
   440   }
   441   if (verifyoop) verify_oop(rax, state);
   442   Address index(noreg, rbx, Address::times_ptr);
   443   ExternalAddress tbl((address)table);
   444   ArrayAddress dispatch(tbl, index);
   445   jump(dispatch);
   446 }
   449 void InterpreterMacroAssembler::dispatch_only(TosState state) {
   450   dispatch_base(state, Interpreter::dispatch_table(state));
   451 }
   454 void InterpreterMacroAssembler::dispatch_only_normal(TosState state) {
   455   dispatch_base(state, Interpreter::normal_table(state));
   456 }
   458 void InterpreterMacroAssembler::dispatch_only_noverify(TosState state) {
   459   dispatch_base(state, Interpreter::normal_table(state), false);
   460 }
   463 void InterpreterMacroAssembler::dispatch_next(TosState state, int step) {
   464   // load next bytecode (load before advancing rsi to prevent AGI)
   465   load_unsigned_byte(rbx, Address(rsi, step));
   466   // advance rsi
   467   increment(rsi, step);
   468   dispatch_base(state, Interpreter::dispatch_table(state));
   469 }
   472 void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) {
   473   // load current bytecode
   474   load_unsigned_byte(rbx, Address(rsi, 0));
   475   dispatch_base(state, table);
   476 }
   478 // remove activation
   479 //
   480 // Unlock the receiver if this is a synchronized method.
   481 // Unlock any Java monitors from syncronized blocks.
   482 // Remove the activation from the stack.
   483 //
   484 // If there are locked Java monitors
   485 //    If throw_monitor_exception
   486 //       throws IllegalMonitorStateException
   487 //    Else if install_monitor_exception
   488 //       installs IllegalMonitorStateException
   489 //    Else
   490 //       no error processing
   491 void InterpreterMacroAssembler::remove_activation(TosState state, Register ret_addr,
   492                                                   bool throw_monitor_exception,
   493                                                   bool install_monitor_exception,
   494                                                   bool notify_jvmdi) {
   495   // Note: Registers rax, rdx and FPU ST(0) may be in use for the result
   496   // check if synchronized method
   497   Label unlocked, unlock, no_unlock;
   499   get_thread(rcx);
   500   const Address do_not_unlock_if_synchronized(rcx,
   501     in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
   503   movbool(rbx, do_not_unlock_if_synchronized);
   504   mov(rdi,rbx);
   505   movbool(do_not_unlock_if_synchronized, false); // reset the flag
   507   movptr(rbx, Address(rbp, frame::interpreter_frame_method_offset * wordSize)); // get method access flags
   508   movl(rcx, Address(rbx, methodOopDesc::access_flags_offset()));
   510   testl(rcx, JVM_ACC_SYNCHRONIZED);
   511   jcc(Assembler::zero, unlocked);
   513   // Don't unlock anything if the _do_not_unlock_if_synchronized flag
   514   // is set.
   515   mov(rcx,rdi);
   516   testbool(rcx);
   517   jcc(Assembler::notZero, no_unlock);
   519   // unlock monitor
   520   push(state);                                   // save result
   522   // BasicObjectLock will be first in list, since this is a synchronized method. However, need
   523   // to check that the object has not been unlocked by an explicit monitorexit bytecode.
   524   const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset * wordSize - (int)sizeof(BasicObjectLock));
   525   lea   (rdx, monitor);                          // address of first monitor
   527   movptr (rax, Address(rdx, BasicObjectLock::obj_offset_in_bytes()));
   528   testptr(rax, rax);
   529   jcc    (Assembler::notZero, unlock);
   531   pop(state);
   532   if (throw_monitor_exception) {
   533     empty_FPU_stack();  // remove possible return value from FPU-stack, otherwise stack could overflow
   535     // Entry already unlocked, need to throw exception
   536     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));
   537     should_not_reach_here();
   538   } else {
   539     // Monitor already unlocked during a stack unroll.
   540     // If requested, install an illegal_monitor_state_exception.
   541     // Continue with stack unrolling.
   542     if (install_monitor_exception) {
   543       empty_FPU_stack();  // remove possible return value from FPU-stack, otherwise stack could overflow
   544       call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::new_illegal_monitor_state_exception));
   545     }
   546     jmp(unlocked);
   547   }
   549   bind(unlock);
   550   unlock_object(rdx);
   551   pop(state);
   553   // Check that for block-structured locking (i.e., that all locked objects has been unlocked)
   554   bind(unlocked);
   556   // rax, rdx: Might contain return value
   558   // Check that all monitors are unlocked
   559   {
   560     Label loop, exception, entry, restart;
   561     const int entry_size               = frame::interpreter_frame_monitor_size()           * wordSize;
   562     const Address monitor_block_top(rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
   563     const Address monitor_block_bot(rbp, frame::interpreter_frame_initial_sp_offset        * wordSize);
   565     bind(restart);
   566     movptr(rcx, monitor_block_top);           // points to current entry, starting with top-most entry
   567     lea(rbx, monitor_block_bot);              // points to word before bottom of monitor block
   568     jmp(entry);
   570     // Entry already locked, need to throw exception
   571     bind(exception);
   573     if (throw_monitor_exception) {
   574       empty_FPU_stack();  // remove possible return value from FPU-stack, otherwise stack could overflow
   576       // Throw exception
   577       call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));
   578       should_not_reach_here();
   579     } else {
   580       // Stack unrolling. Unlock object and install illegal_monitor_exception
   581       // Unlock does not block, so don't have to worry about the frame
   583       push(state);
   584       mov(rdx, rcx);
   585       unlock_object(rdx);
   586       pop(state);
   588       if (install_monitor_exception) {
   589         empty_FPU_stack();  // remove possible return value from FPU-stack, otherwise stack could overflow
   590         call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::new_illegal_monitor_state_exception));
   591       }
   593       jmp(restart);
   594     }
   596     bind(loop);
   597     cmpptr(Address(rcx, BasicObjectLock::obj_offset_in_bytes()), (int32_t)NULL_WORD);  // check if current entry is used
   598     jcc(Assembler::notEqual, exception);
   600     addptr(rcx, entry_size);                     // otherwise advance to next entry
   601     bind(entry);
   602     cmpptr(rcx, rbx);                            // check if bottom reached
   603     jcc(Assembler::notEqual, loop);              // if not at bottom then check this entry
   604   }
   606   bind(no_unlock);
   608   // jvmti support
   609   if (notify_jvmdi) {
   610     notify_method_exit(state, NotifyJVMTI);     // preserve TOSCA
   611   } else {
   612     notify_method_exit(state, SkipNotifyJVMTI); // preserve TOSCA
   613   }
   615   // remove activation
   616   movptr(rbx, Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize)); // get sender sp
   617   leave();                                     // remove frame anchor
   618   pop(ret_addr);                               // get return address
   619   mov(rsp, rbx);                               // set sp to sender sp
   620   if (UseSSE) {
   621     // float and double are returned in xmm register in SSE-mode
   622     if (state == ftos && UseSSE >= 1) {
   623       subptr(rsp, wordSize);
   624       fstp_s(Address(rsp, 0));
   625       movflt(xmm0, Address(rsp, 0));
   626       addptr(rsp, wordSize);
   627     } else if (state == dtos && UseSSE >= 2) {
   628       subptr(rsp, 2*wordSize);
   629       fstp_d(Address(rsp, 0));
   630       movdbl(xmm0, Address(rsp, 0));
   631       addptr(rsp, 2*wordSize);
   632     }
   633   }
   634 }
   636 #endif /* !CC_INTERP */
   639 // Lock object
   640 //
   641 // Argument: rdx : Points to BasicObjectLock to be used for locking. Must
   642 // be initialized with object to lock
   643 void InterpreterMacroAssembler::lock_object(Register lock_reg) {
   644   assert(lock_reg == rdx, "The argument is only for looks. It must be rdx");
   646   if (UseHeavyMonitors) {
   647     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), lock_reg);
   648   } else {
   650     Label done;
   652     const Register swap_reg = rax;  // Must use rax, for cmpxchg instruction
   653     const Register obj_reg  = rcx;  // Will contain the oop
   655     const int obj_offset = BasicObjectLock::obj_offset_in_bytes();
   656     const int lock_offset = BasicObjectLock::lock_offset_in_bytes ();
   657     const int mark_offset = lock_offset + BasicLock::displaced_header_offset_in_bytes();
   659     Label slow_case;
   661     // Load object pointer into obj_reg %rcx
   662     movptr(obj_reg, Address(lock_reg, obj_offset));
   664     if (UseBiasedLocking) {
   665       // Note: we use noreg for the temporary register since it's hard
   666       // to come up with a free register on all incoming code paths
   667       biased_locking_enter(lock_reg, obj_reg, swap_reg, noreg, false, done, &slow_case);
   668     }
   670     // Load immediate 1 into swap_reg %rax,
   671     movptr(swap_reg, (int32_t)1);
   673     // Load (object->mark() | 1) into swap_reg %rax,
   674     orptr(swap_reg, Address(obj_reg, 0));
   676     // Save (object->mark() | 1) into BasicLock's displaced header
   677     movptr(Address(lock_reg, mark_offset), swap_reg);
   679     assert(lock_offset == 0, "displached header must be first word in BasicObjectLock");
   680     if (os::is_MP()) {
   681       lock();
   682     }
   683     cmpxchgptr(lock_reg, Address(obj_reg, 0));
   684     if (PrintBiasedLockingStatistics) {
   685       cond_inc32(Assembler::zero,
   686                  ExternalAddress((address) BiasedLocking::fast_path_entry_count_addr()));
   687     }
   688     jcc(Assembler::zero, done);
   690     // Test if the oopMark is an obvious stack pointer, i.e.,
   691     //  1) (mark & 3) == 0, and
   692     //  2) rsp <= mark < mark + os::pagesize()
   693     //
   694     // These 3 tests can be done by evaluating the following
   695     // expression: ((mark - rsp) & (3 - os::vm_page_size())),
   696     // assuming both stack pointer and pagesize have their
   697     // least significant 2 bits clear.
   698     // NOTE: the oopMark is in swap_reg %rax, as the result of cmpxchg
   699     subptr(swap_reg, rsp);
   700     andptr(swap_reg, 3 - os::vm_page_size());
   702     // Save the test result, for recursive case, the result is zero
   703     movptr(Address(lock_reg, mark_offset), swap_reg);
   705     if (PrintBiasedLockingStatistics) {
   706       cond_inc32(Assembler::zero,
   707                  ExternalAddress((address) BiasedLocking::fast_path_entry_count_addr()));
   708     }
   709     jcc(Assembler::zero, done);
   711     bind(slow_case);
   713     // Call the runtime routine for slow case
   714     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), lock_reg);
   716     bind(done);
   717   }
   718 }
   721 // Unlocks an object. Used in monitorexit bytecode and remove_activation.
   722 //
   723 // Argument: rdx : Points to BasicObjectLock structure for lock
   724 // Throw an IllegalMonitorException if object is not locked by current thread
   725 //
   726 // Uses: rax, rbx, rcx, rdx
   727 void InterpreterMacroAssembler::unlock_object(Register lock_reg) {
   728   assert(lock_reg == rdx, "The argument is only for looks. It must be rdx");
   730   if (UseHeavyMonitors) {
   731     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg);
   732   } else {
   733     Label done;
   735     const Register swap_reg   = rax;  // Must use rax, for cmpxchg instruction
   736     const Register header_reg = rbx;  // Will contain the old oopMark
   737     const Register obj_reg    = rcx;  // Will contain the oop
   739     save_bcp(); // Save in case of exception
   741     // Convert from BasicObjectLock structure to object and BasicLock structure
   742     // Store the BasicLock address into %rax,
   743     lea(swap_reg, Address(lock_reg, BasicObjectLock::lock_offset_in_bytes()));
   745     // Load oop into obj_reg(%rcx)
   746     movptr(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset_in_bytes ()));
   748     // Free entry
   749     movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()), NULL_WORD);
   751     if (UseBiasedLocking) {
   752       biased_locking_exit(obj_reg, header_reg, done);
   753     }
   755     // Load the old header from BasicLock structure
   756     movptr(header_reg, Address(swap_reg, BasicLock::displaced_header_offset_in_bytes()));
   758     // Test for recursion
   759     testptr(header_reg, header_reg);
   761     // zero for recursive case
   762     jcc(Assembler::zero, done);
   764     // Atomic swap back the old header
   765     if (os::is_MP()) lock();
   766     cmpxchgptr(header_reg, Address(obj_reg, 0));
   768     // zero for recursive case
   769     jcc(Assembler::zero, done);
   771     // Call the runtime routine for slow case.
   772     movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()), obj_reg); // restore obj
   773     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg);
   775     bind(done);
   777     restore_bcp();
   778   }
   779 }
   782 #ifndef CC_INTERP
   784 // Test ImethodDataPtr.  If it is null, continue at the specified label
   785 void InterpreterMacroAssembler::test_method_data_pointer(Register mdp, Label& zero_continue) {
   786   assert(ProfileInterpreter, "must be profiling interpreter");
   787   movptr(mdp, Address(rbp, frame::interpreter_frame_mdx_offset * wordSize));
   788   testptr(mdp, mdp);
   789   jcc(Assembler::zero, zero_continue);
   790 }
   793 // Set the method data pointer for the current bcp.
   794 void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() {
   795   assert(ProfileInterpreter, "must be profiling interpreter");
   796   Label zero_continue;
   797   push(rax);
   798   push(rbx);
   800   get_method(rbx);
   801   // Test MDO to avoid the call if it is NULL.
   802   movptr(rax, Address(rbx, in_bytes(methodOopDesc::method_data_offset())));
   803   testptr(rax, rax);
   804   jcc(Assembler::zero, zero_continue);
   806   // rbx,: method
   807   // rsi: bcp
   808   call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), rbx, rsi);
   809   // rax,: mdi
   811   movptr(rbx, Address(rbx, in_bytes(methodOopDesc::method_data_offset())));
   812   testptr(rbx, rbx);
   813   jcc(Assembler::zero, zero_continue);
   814   addptr(rbx, in_bytes(methodDataOopDesc::data_offset()));
   815   addptr(rbx, rax);
   816   movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), rbx);
   818   bind(zero_continue);
   819   pop(rbx);
   820   pop(rax);
   821 }
   823 void InterpreterMacroAssembler::verify_method_data_pointer() {
   824   assert(ProfileInterpreter, "must be profiling interpreter");
   825 #ifdef ASSERT
   826   Label verify_continue;
   827   push(rax);
   828   push(rbx);
   829   push(rcx);
   830   push(rdx);
   831   test_method_data_pointer(rcx, verify_continue); // If mdp is zero, continue
   832   get_method(rbx);
   834   // If the mdp is valid, it will point to a DataLayout header which is
   835   // consistent with the bcp.  The converse is highly probable also.
   836   load_unsigned_short(rdx, Address(rcx, in_bytes(DataLayout::bci_offset())));
   837   addptr(rdx, Address(rbx, methodOopDesc::const_offset()));
   838   lea(rdx, Address(rdx, constMethodOopDesc::codes_offset()));
   839   cmpptr(rdx, rsi);
   840   jcc(Assembler::equal, verify_continue);
   841   // rbx,: method
   842   // rsi: bcp
   843   // rcx: mdp
   844   call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp), rbx, rsi, rcx);
   845   bind(verify_continue);
   846   pop(rdx);
   847   pop(rcx);
   848   pop(rbx);
   849   pop(rax);
   850 #endif // ASSERT
   851 }
   854 void InterpreterMacroAssembler::set_mdp_data_at(Register mdp_in, int constant, Register value) {
   855   // %%% this seems to be used to store counter data which is surely 32bits
   856   // however 64bit side stores 64 bits which seems wrong
   857   assert(ProfileInterpreter, "must be profiling interpreter");
   858   Address data(mdp_in, constant);
   859   movptr(data, value);
   860 }
   863 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
   864                                                       int constant,
   865                                                       bool decrement) {
   866   // Counter address
   867   Address data(mdp_in, constant);
   869   increment_mdp_data_at(data, decrement);
   870 }
   873 void InterpreterMacroAssembler::increment_mdp_data_at(Address data,
   874                                                       bool decrement) {
   876   assert( DataLayout::counter_increment==1, "flow-free idiom only works with 1" );
   877   assert(ProfileInterpreter, "must be profiling interpreter");
   879   // %%% 64bit treats this as 64 bit which seems unlikely
   880   if (decrement) {
   881     // Decrement the register.  Set condition codes.
   882     addl(data, -DataLayout::counter_increment);
   883     // If the decrement causes the counter to overflow, stay negative
   884     Label L;
   885     jcc(Assembler::negative, L);
   886     addl(data, DataLayout::counter_increment);
   887     bind(L);
   888   } else {
   889     assert(DataLayout::counter_increment == 1,
   890            "flow-free idiom only works with 1");
   891     // Increment the register.  Set carry flag.
   892     addl(data, DataLayout::counter_increment);
   893     // If the increment causes the counter to overflow, pull back by 1.
   894     sbbl(data, 0);
   895   }
   896 }
   899 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
   900                                                       Register reg,
   901                                                       int constant,
   902                                                       bool decrement) {
   903   Address data(mdp_in, reg, Address::times_1, constant);
   905   increment_mdp_data_at(data, decrement);
   906 }
   909 void InterpreterMacroAssembler::set_mdp_flag_at(Register mdp_in, int flag_byte_constant) {
   910   assert(ProfileInterpreter, "must be profiling interpreter");
   911   int header_offset = in_bytes(DataLayout::header_offset());
   912   int header_bits = DataLayout::flag_mask_to_header_mask(flag_byte_constant);
   913   // Set the flag
   914   orl(Address(mdp_in, header_offset), header_bits);
   915 }
   919 void InterpreterMacroAssembler::test_mdp_data_at(Register mdp_in,
   920                                                  int offset,
   921                                                  Register value,
   922                                                  Register test_value_out,
   923                                                  Label& not_equal_continue) {
   924   assert(ProfileInterpreter, "must be profiling interpreter");
   925   if (test_value_out == noreg) {
   926     cmpptr(value, Address(mdp_in, offset));
   927   } else {
   928     // Put the test value into a register, so caller can use it:
   929     movptr(test_value_out, Address(mdp_in, offset));
   930     cmpptr(test_value_out, value);
   931   }
   932   jcc(Assembler::notEqual, not_equal_continue);
   933 }
   936 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in, int offset_of_disp) {
   937   assert(ProfileInterpreter, "must be profiling interpreter");
   938   Address disp_address(mdp_in, offset_of_disp);
   939   addptr(mdp_in,disp_address);
   940   movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in);
   941 }
   944 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in, Register reg, int offset_of_disp) {
   945   assert(ProfileInterpreter, "must be profiling interpreter");
   946   Address disp_address(mdp_in, reg, Address::times_1, offset_of_disp);
   947   addptr(mdp_in, disp_address);
   948   movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in);
   949 }
   952 void InterpreterMacroAssembler::update_mdp_by_constant(Register mdp_in, int constant) {
   953   assert(ProfileInterpreter, "must be profiling interpreter");
   954   addptr(mdp_in, constant);
   955   movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in);
   956 }
   959 void InterpreterMacroAssembler::update_mdp_for_ret(Register return_bci) {
   960   assert(ProfileInterpreter, "must be profiling interpreter");
   961   push(return_bci);             // save/restore across call_VM
   962   call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret), return_bci);
   963   pop(return_bci);
   964 }
   967 void InterpreterMacroAssembler::profile_taken_branch(Register mdp, Register bumped_count) {
   968   if (ProfileInterpreter) {
   969     Label profile_continue;
   971     // If no method data exists, go to profile_continue.
   972     // Otherwise, assign to mdp
   973     test_method_data_pointer(mdp, profile_continue);
   975     // We are taking a branch.  Increment the taken count.
   976     // We inline increment_mdp_data_at to return bumped_count in a register
   977     //increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset()));
   978     Address data(mdp, in_bytes(JumpData::taken_offset()));
   980     // %%% 64bit treats these cells as 64 bit but they seem to be 32 bit
   981     movl(bumped_count,data);
   982     assert( DataLayout::counter_increment==1, "flow-free idiom only works with 1" );
   983     addl(bumped_count, DataLayout::counter_increment);
   984     sbbl(bumped_count, 0);
   985     movl(data,bumped_count);    // Store back out
   987     // The method data pointer needs to be updated to reflect the new target.
   988     update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset()));
   989     bind (profile_continue);
   990   }
   991 }
   994 void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp) {
   995   if (ProfileInterpreter) {
   996     Label profile_continue;
   998     // If no method data exists, go to profile_continue.
   999     test_method_data_pointer(mdp, profile_continue);
  1001     // We are taking a branch.  Increment the not taken count.
  1002     increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset()));
  1004     // The method data pointer needs to be updated to correspond to the next bytecode
  1005     update_mdp_by_constant(mdp, in_bytes(BranchData::branch_data_size()));
  1006     bind (profile_continue);
  1011 void InterpreterMacroAssembler::profile_call(Register mdp) {
  1012   if (ProfileInterpreter) {
  1013     Label profile_continue;
  1015     // If no method data exists, go to profile_continue.
  1016     test_method_data_pointer(mdp, profile_continue);
  1018     // We are making a call.  Increment the count.
  1019     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1021     // The method data pointer needs to be updated to reflect the new target.
  1022     update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size()));
  1023     bind (profile_continue);
  1028 void InterpreterMacroAssembler::profile_final_call(Register mdp) {
  1029   if (ProfileInterpreter) {
  1030     Label profile_continue;
  1032     // If no method data exists, go to profile_continue.
  1033     test_method_data_pointer(mdp, profile_continue);
  1035     // We are making a call.  Increment the count.
  1036     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1038     // The method data pointer needs to be updated to reflect the new target.
  1039     update_mdp_by_constant(mdp, in_bytes(VirtualCallData::virtual_call_data_size()));
  1040     bind (profile_continue);
  1045 void InterpreterMacroAssembler::profile_virtual_call(Register receiver, Register mdp,
  1046                                                      Register reg2,
  1047                                                      bool receiver_can_be_null) {
  1048   if (ProfileInterpreter) {
  1049     Label profile_continue;
  1051     // If no method data exists, go to profile_continue.
  1052     test_method_data_pointer(mdp, profile_continue);
  1054     Label skip_receiver_profile;
  1055     if (receiver_can_be_null) {
  1056       Label not_null;
  1057       testptr(receiver, receiver);
  1058       jccb(Assembler::notZero, not_null);
  1059       // We are making a call.  Increment the count for null receiver.
  1060       increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1061       jmp(skip_receiver_profile);
  1062       bind(not_null);
  1065     // Record the receiver type.
  1066     record_klass_in_profile(receiver, mdp, reg2, true);
  1067     bind(skip_receiver_profile);
  1069     // The method data pointer needs to be updated to reflect the new target.
  1070     update_mdp_by_constant(mdp,
  1071                            in_bytes(VirtualCallData::
  1072                                     virtual_call_data_size()));
  1073     bind(profile_continue);
  1078 void InterpreterMacroAssembler::record_klass_in_profile_helper(
  1079                                         Register receiver, Register mdp,
  1080                                         Register reg2, int start_row,
  1081                                         Label& done, bool is_virtual_call) {
  1082   if (TypeProfileWidth == 0) {
  1083     if (is_virtual_call) {
  1084       increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1086     return;
  1089   int last_row = VirtualCallData::row_limit() - 1;
  1090   assert(start_row <= last_row, "must be work left to do");
  1091   // Test this row for both the receiver and for null.
  1092   // Take any of three different outcomes:
  1093   //   1. found receiver => increment count and goto done
  1094   //   2. found null => keep looking for case 1, maybe allocate this cell
  1095   //   3. found something else => keep looking for cases 1 and 2
  1096   // Case 3 is handled by a recursive call.
  1097   for (int row = start_row; row <= last_row; row++) {
  1098     Label next_test;
  1099     bool test_for_null_also = (row == start_row);
  1101     // See if the receiver is receiver[n].
  1102     int recvr_offset = in_bytes(VirtualCallData::receiver_offset(row));
  1103     test_mdp_data_at(mdp, recvr_offset, receiver,
  1104                      (test_for_null_also ? reg2 : noreg),
  1105                      next_test);
  1106     // (Reg2 now contains the receiver from the CallData.)
  1108     // The receiver is receiver[n].  Increment count[n].
  1109     int count_offset = in_bytes(VirtualCallData::receiver_count_offset(row));
  1110     increment_mdp_data_at(mdp, count_offset);
  1111     jmp(done);
  1112     bind(next_test);
  1114     if (row == start_row) {
  1115       Label found_null;
  1116       // Failed the equality check on receiver[n]...  Test for null.
  1117       testptr(reg2, reg2);
  1118       if (start_row == last_row) {
  1119         // The only thing left to do is handle the null case.
  1120         if (is_virtual_call) {
  1121           jccb(Assembler::zero, found_null);
  1122           // Receiver did not match any saved receiver and there is no empty row for it.
  1123           // Increment total counter to indicate polymorphic case.
  1124           increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1125           jmp(done);
  1126           bind(found_null);
  1127         } else {
  1128           jcc(Assembler::notZero, done);
  1130         break;
  1132       // Since null is rare, make it be the branch-taken case.
  1133       jcc(Assembler::zero, found_null);
  1135       // Put all the "Case 3" tests here.
  1136       record_klass_in_profile_helper(receiver, mdp, reg2, start_row + 1, done, is_virtual_call);
  1138       // Found a null.  Keep searching for a matching receiver,
  1139       // but remember that this is an empty (unused) slot.
  1140       bind(found_null);
  1144   // In the fall-through case, we found no matching receiver, but we
  1145   // observed the receiver[start_row] is NULL.
  1147   // Fill in the receiver field and increment the count.
  1148   int recvr_offset = in_bytes(VirtualCallData::receiver_offset(start_row));
  1149   set_mdp_data_at(mdp, recvr_offset, receiver);
  1150   int count_offset = in_bytes(VirtualCallData::receiver_count_offset(start_row));
  1151   movptr(reg2, (int32_t)DataLayout::counter_increment);
  1152   set_mdp_data_at(mdp, count_offset, reg2);
  1153   if (start_row > 0) {
  1154     jmp(done);
  1158 void InterpreterMacroAssembler::record_klass_in_profile(Register receiver,
  1159                                                         Register mdp, Register reg2,
  1160                                                         bool is_virtual_call) {
  1161   assert(ProfileInterpreter, "must be profiling");
  1162   Label done;
  1164   record_klass_in_profile_helper(receiver, mdp, reg2, 0, done, is_virtual_call);
  1166   bind (done);
  1169 void InterpreterMacroAssembler::profile_ret(Register return_bci, Register mdp) {
  1170   if (ProfileInterpreter) {
  1171     Label profile_continue;
  1172     uint row;
  1174     // If no method data exists, go to profile_continue.
  1175     test_method_data_pointer(mdp, profile_continue);
  1177     // Update the total ret count.
  1178     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1180     for (row = 0; row < RetData::row_limit(); row++) {
  1181       Label next_test;
  1183       // See if return_bci is equal to bci[n]:
  1184       test_mdp_data_at(mdp, in_bytes(RetData::bci_offset(row)), return_bci,
  1185                        noreg, next_test);
  1187       // return_bci is equal to bci[n].  Increment the count.
  1188       increment_mdp_data_at(mdp, in_bytes(RetData::bci_count_offset(row)));
  1190       // The method data pointer needs to be updated to reflect the new target.
  1191       update_mdp_by_offset(mdp, in_bytes(RetData::bci_displacement_offset(row)));
  1192       jmp(profile_continue);
  1193       bind(next_test);
  1196     update_mdp_for_ret(return_bci);
  1198     bind (profile_continue);
  1203 void InterpreterMacroAssembler::profile_null_seen(Register mdp) {
  1204   if (ProfileInterpreter) {
  1205     Label profile_continue;
  1207     // If no method data exists, go to profile_continue.
  1208     test_method_data_pointer(mdp, profile_continue);
  1210     set_mdp_flag_at(mdp, BitData::null_seen_byte_constant());
  1212     // The method data pointer needs to be updated.
  1213     int mdp_delta = in_bytes(BitData::bit_data_size());
  1214     if (TypeProfileCasts) {
  1215       mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
  1217     update_mdp_by_constant(mdp, mdp_delta);
  1219     bind (profile_continue);
  1224 void InterpreterMacroAssembler::profile_typecheck_failed(Register mdp) {
  1225   if (ProfileInterpreter && TypeProfileCasts) {
  1226     Label profile_continue;
  1228     // If no method data exists, go to profile_continue.
  1229     test_method_data_pointer(mdp, profile_continue);
  1231     int count_offset = in_bytes(CounterData::count_offset());
  1232     // Back up the address, since we have already bumped the mdp.
  1233     count_offset -= in_bytes(VirtualCallData::virtual_call_data_size());
  1235     // *Decrement* the counter.  We expect to see zero or small negatives.
  1236     increment_mdp_data_at(mdp, count_offset, true);
  1238     bind (profile_continue);
  1243 void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2)
  1245   if (ProfileInterpreter) {
  1246     Label profile_continue;
  1248     // If no method data exists, go to profile_continue.
  1249     test_method_data_pointer(mdp, profile_continue);
  1251     // The method data pointer needs to be updated.
  1252     int mdp_delta = in_bytes(BitData::bit_data_size());
  1253     if (TypeProfileCasts) {
  1254       mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
  1256       // Record the object type.
  1257       record_klass_in_profile(klass, mdp, reg2, false);
  1258       assert(reg2 == rdi, "we know how to fix this blown reg");
  1259       restore_locals();         // Restore EDI
  1261     update_mdp_by_constant(mdp, mdp_delta);
  1263     bind(profile_continue);
  1268 void InterpreterMacroAssembler::profile_switch_default(Register mdp) {
  1269   if (ProfileInterpreter) {
  1270     Label profile_continue;
  1272     // If no method data exists, go to profile_continue.
  1273     test_method_data_pointer(mdp, profile_continue);
  1275     // Update the default case count
  1276     increment_mdp_data_at(mdp, in_bytes(MultiBranchData::default_count_offset()));
  1278     // The method data pointer needs to be updated.
  1279     update_mdp_by_offset(mdp, in_bytes(MultiBranchData::default_displacement_offset()));
  1281     bind (profile_continue);
  1286 void InterpreterMacroAssembler::profile_switch_case(Register index, Register mdp, Register reg2) {
  1287   if (ProfileInterpreter) {
  1288     Label profile_continue;
  1290     // If no method data exists, go to profile_continue.
  1291     test_method_data_pointer(mdp, profile_continue);
  1293     // Build the base (index * per_case_size_in_bytes()) + case_array_offset_in_bytes()
  1294     movptr(reg2, (int32_t)in_bytes(MultiBranchData::per_case_size()));
  1295     // index is positive and so should have correct value if this code were
  1296     // used on 64bits
  1297     imulptr(index, reg2);
  1298     addptr(index, in_bytes(MultiBranchData::case_array_offset()));
  1300     // Update the case count
  1301     increment_mdp_data_at(mdp, index, in_bytes(MultiBranchData::relative_count_offset()));
  1303     // The method data pointer needs to be updated.
  1304     update_mdp_by_offset(mdp, index, in_bytes(MultiBranchData::relative_displacement_offset()));
  1306     bind (profile_continue);
  1310 #endif // !CC_INTERP
  1314 void InterpreterMacroAssembler::verify_oop(Register reg, TosState state) {
  1315   if (state == atos) MacroAssembler::verify_oop(reg);
  1319 #ifndef CC_INTERP
  1320 void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) {
  1321   if (state == ftos || state == dtos) MacroAssembler::verify_FPU(stack_depth);
  1324 #endif /* CC_INTERP */
  1327 void InterpreterMacroAssembler::notify_method_entry() {
  1328   // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
  1329   // track stack depth.  If it is possible to enter interp_only_mode we add
  1330   // the code to check if the event should be sent.
  1331   if (JvmtiExport::can_post_interpreter_events()) {
  1332     Label L;
  1333     get_thread(rcx);
  1334     movl(rcx, Address(rcx, JavaThread::interp_only_mode_offset()));
  1335     testl(rcx,rcx);
  1336     jcc(Assembler::zero, L);
  1337     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_entry));
  1338     bind(L);
  1342     SkipIfEqual skip_if(this, &DTraceMethodProbes, 0);
  1343     get_thread(rcx);
  1344     get_method(rbx);
  1345     call_VM_leaf(
  1346       CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry), rcx, rbx);
  1349   // RedefineClasses() tracing support for obsolete method entry
  1350   if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
  1351     get_thread(rcx);
  1352     get_method(rbx);
  1353     call_VM_leaf(
  1354       CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry),
  1355       rcx, rbx);
  1360 void InterpreterMacroAssembler::notify_method_exit(
  1361     TosState state, NotifyMethodExitMode mode) {
  1362   // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
  1363   // track stack depth.  If it is possible to enter interp_only_mode we add
  1364   // the code to check if the event should be sent.
  1365   if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) {
  1366     Label L;
  1367     // Note: frame::interpreter_frame_result has a dependency on how the
  1368     // method result is saved across the call to post_method_exit. If this
  1369     // is changed then the interpreter_frame_result implementation will
  1370     // need to be updated too.
  1372     // For c++ interpreter the result is always stored at a known location in the frame
  1373     // template interpreter will leave it on the top of the stack.
  1374     NOT_CC_INTERP(push(state);)
  1375     get_thread(rcx);
  1376     movl(rcx, Address(rcx, JavaThread::interp_only_mode_offset()));
  1377     testl(rcx,rcx);
  1378     jcc(Assembler::zero, L);
  1379     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit));
  1380     bind(L);
  1381     NOT_CC_INTERP(pop(state);)
  1385     SkipIfEqual skip_if(this, &DTraceMethodProbes, 0);
  1386     NOT_CC_INTERP(push(state));
  1387     get_thread(rbx);
  1388     get_method(rcx);
  1389     call_VM_leaf(
  1390       CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),
  1391       rbx, rcx);
  1392     NOT_CC_INTERP(pop(state));

mercurial