src/cpu/mips/vm/interp_masm_mips_64.cpp

Fri, 13 Oct 2017 11:29:53 +0800

author
wangxue
date
Fri, 13 Oct 2017 11:29:53 +0800
changeset 7995
67882e9d8b35
parent 6893
5795ec554c3c
child 7999
b57e01e9f81e
permissions
-rw-r--r--

#6126 Fixed ForceEarlyReturn error
call_VM_leaf() handles the stack alignment when the assemble code calls c code.
Modified part of debugging code of call_VM_base() in macroAssembler_mips.cpp.

     1 /*
     2  * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * Copyright (c) 2015, 2016, Loongson Technology. All rights reserved.
     4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5  *
     6  * This code is free software; you can redistribute it and/or modify it
     7  * under the terms of the GNU General Public License version 2 only, as
     8  * published by the Free Software Foundation.
     9  *
    10  * This code is distributed in the hope that it will be useful, but WITHOUT
    11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    13  * version 2 for more details (a copy is included in the LICENSE file that
    14  * accompanied this code).
    15  *
    16  * You should have received a copy of the GNU General Public License version
    17  * 2 along with this work; if not, write to the Free Software Foundation,
    18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    19  *
    20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    21  * or visit www.oracle.com if you need additional information or have any
    22  * questions.
    23  *
    24  */
    26 #include "precompiled.hpp"
    27 #include "interp_masm_mips_64.hpp"
    28 #include "interpreter/interpreter.hpp"
    29 #include "interpreter/interpreterRuntime.hpp"
    30 #include "oops/arrayOop.hpp"
    31 #include "oops/markOop.hpp"
    32 #include "oops/methodData.hpp"
    33 #include "oops/method.hpp"
    34 #include "prims/jvmtiExport.hpp"
    35 #include "prims/jvmtiRedefineClassesTrace.hpp"
    36 #include "prims/jvmtiThreadState.hpp"
    37 #include "runtime/basicLock.hpp"
    38 #include "runtime/biasedLocking.hpp"
    39 #include "runtime/sharedRuntime.hpp"
    40 #include "runtime/thread.inline.hpp"
    43 // Implementation of InterpreterMacroAssembler
    45 #ifdef CC_INTERP
    46 void InterpreterMacroAssembler::get_method(Register reg) {
    47 }
    48 #endif // CC_INTERP
    50 void InterpreterMacroAssembler::get_2_byte_integer_at_bcp(Register reg, Register tmp, int offset) {
    51   /* 2016/5/6 Jin: the runtime address of BCP may be unaligned.
    52    *   Refer to the SPARC implementation. */
    53   lbu(reg, BCP, offset+1);
    54   lbu(tmp, BCP, offset);
    55 #ifdef _LP64
    56   dsll(reg, reg, 8);
    57   daddu(reg, tmp, reg);
    58 #else
    59   sll(reg, reg, 8);
    60   addu(reg, tmp, reg);
    61 #endif
    62 }
    64 void InterpreterMacroAssembler::get_4_byte_integer_at_bcp(Register reg, Register tmp, int offset) {
    65   assert(reg != tmp, "need separate temp register");
    66   if (offset & 3) { // Offset unaligned?
    67     lbu(reg, BCP, offset+3);
    68     lbu(tmp, BCP, offset+2);
    69 #ifdef _LP64
    70     dsll(reg, reg, 8);
    71     daddu(reg, tmp, reg);
    72     lbu(tmp, BCP, offset+1);
    73     dsll(reg, reg, 8);
    74     daddu(reg, tmp, reg);
    75     lbu(tmp, BCP, offset);
    76     dsll(reg, reg, 8);
    77     daddu(reg, tmp, reg);
    78 #else
    79     sll(reg, reg, 8);
    80     addu(reg, tmp, reg);
    81     lbu(tmp, BCP, offset+1);
    82     sll(reg, reg, 8);
    83     addu(reg, tmp, reg);
    84     lbu(tmp, BCP, offset);
    85     sll(reg, reg, 8);
    86     addu(reg, tmp, reg);
    87 #endif
    88   } else {
    89     lwu(reg, BCP, offset);
    90   }
    91 }
    93 #ifndef CC_INTERP
    95 void InterpreterMacroAssembler::call_VM_leaf_base(address entry_point,
    96                                                   int number_of_arguments) {
    97   // interpreter specific
    98   //
    99   // Note: No need to save/restore bcp & locals (r13 & r14) pointer
   100   //       since these are callee saved registers and no blocking/
   101   //       GC can happen in leaf calls.
   102   // Further Note: DO NOT save/restore bcp/locals. If a caller has
   103   // already saved them so that it can use esi/edi as temporaries
   104   // then a save/restore here will DESTROY the copy the caller
   105   // saved! There used to be a save_bcp() that only happened in
   106   // the ASSERT path (no restore_bcp). Which caused bizarre failures
   107   // when jvm built with ASSERTs.
   108 #ifdef ASSERT
   109   save_bcp();
   110   {
   111     Label L;
   112     ld(AT,FP,frame::interpreter_frame_last_sp_offset * wordSize);
   113     beq(AT,R0,L);
   114     delayed()->nop();
   115     stop("InterpreterMacroAssembler::call_VM_leaf_base: last_sp != NULL");
   116     bind(L);
   117   }
   118 #endif
   119   // super call
   120   MacroAssembler::call_VM_leaf_base(entry_point, number_of_arguments);
   121   // interpreter specific
   122 #ifdef ASSERT
   123   {
   124     Label L;
   125     ld(T3, FP, frame::interpreter_frame_bcx_offset * wordSize);
   126     Assembler::beq(BCP, T3, L);
   127     delayed()->nop();
   128     stop("InterpreterMacroAssembler::call_VM_leaf_base: esi not callee saved?");
   129     bind(L);
   130   }
   131   {
   132     Label L;
   133     ld(T3, FP, frame::interpreter_frame_locals_offset * wordSize);
   134     Assembler::beq(LVP, T3, L);
   135     delayed()->nop();
   136     stop("InterpreterMacroAssembler::call_VM_leaf_base: edi not callee saved?");
   137     bind(L);
   138   }
   139   #endif
   140   }
   142 void InterpreterMacroAssembler::call_VM_base(Register oop_result,
   143                                              Register java_thread,
   144                                              Register last_java_sp,
   145                                              address  entry_point,
   146                                              int      number_of_arguments,
   147                                              bool     check_exceptions) {
   148   // interpreter specific
   149   //
   150   // Note: Could avoid restoring locals ptr (callee saved) - however doesn't
   151   //       really make a difference for these runtime calls, since they are
   152   //       slow anyway. Btw., bcp must be saved/restored since it may change
   153   //       due to GC.
   154   assert(java_thread == noreg , "not expecting a precomputed java thread");
   155   save_bcp();
   156 #ifdef ASSERT
   157   {
   158     Label L;
   159     ld(AT, FP, frame::interpreter_frame_last_sp_offset * wordSize);
   160     beq(AT, R0, L);
   161     delayed()->nop();
   162     stop("InterpreterMacroAssembler::call_VM_base: last_sp != NULL");
   163     bind(L);
   164   }
   165 #endif /* ASSERT */
   166   // super call
   167   MacroAssembler::call_VM_base(oop_result, java_thread, last_java_sp,
   168                                entry_point, number_of_arguments,
   169                                check_exceptions);
   170   // interpreter specific
   171   restore_bcp();
   172   restore_locals();
   173 }
   176 void InterpreterMacroAssembler::check_and_handle_popframe(Register java_thread) {
   177   if (JvmtiExport::can_pop_frame()) {
   178     Label L;
   179     // Initiate popframe handling only if it is not already being
   180     // processed.  If the flag has the popframe_processing bit set, it
   181     // means that this code is called *during* popframe handling - we
   182     // don't want to reenter.
   183     // This method is only called just after the call into the vm in
   184     // call_VM_base, so the arg registers are available.
   185     Register pop_cond = java_thread;
   186     // Not clear if any other register is available...
   187     lw(pop_cond, java_thread, in_bytes(JavaThread::popframe_condition_offset()));
   188     andi(AT, pop_cond, JavaThread::popframe_pending_bit);
   189     beq(AT, R0, L);
   190     delayed()->andi(AT, pop_cond, JavaThread::popframe_processing_bit);
   191     bne(AT, R0, L);
   192     delayed()->nop();
   193     call(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_preserving_args_entry), relocInfo::runtime_call_type);
   194     delayed()->nop();
   195     jr(V0);
   196     delayed()->nop();
   197     bind(L);
   198     get_thread(java_thread);
   199   }
   200 }
   203 void InterpreterMacroAssembler::load_earlyret_value(TosState state) {
   204   //T8, thread
   205   get_thread(T8);
   206   ld_ptr(T8, T8,in_bytes(JavaThread::jvmti_thread_state_offset()));
   207   const Address tos_addr (T8, in_bytes(JvmtiThreadState::earlyret_tos_offset()));
   208   const Address oop_addr (T8, in_bytes(JvmtiThreadState::earlyret_oop_offset()));
   209   const Address val_addr (T8, in_bytes(JvmtiThreadState::earlyret_value_offset()));
   210   //V0, oop_addr,V1,val_addr
   211   switch (state) {
   212     case atos:
   213       ld_ptr(V0, oop_addr);
   214       st_ptr(R0, oop_addr);
   215       verify_oop(V0, state);
   216       break;
   217     case ltos:
   218       ld_ptr(V0, val_addr);               // fall through
   219       break;
   220     case btos:                                     // fall through
   221     case ctos:                                     // fall through
   222     case stos:                                     // fall through
   223     case itos:
   224       lw(V0, val_addr);
   225       break;
   226     case ftos:
   227       lwc1(F0,T8, in_bytes(JvmtiThreadState::earlyret_value_offset()));
   228       break;
   229     case dtos:
   230       ldc1(F0,T8, in_bytes(JvmtiThreadState::earlyret_value_offset()));
   231       break;
   232     case vtos: /* nothing to do */                    break;
   233     default  : ShouldNotReachHere();
   234   }
   235   // Clean up tos value in the thread object
   236   move(AT, (int)ilgl);
   237   sw(AT, tos_addr);
   238   sw(R0,T8, in_bytes(JvmtiThreadState::earlyret_value_offset()));
   239 }
   242 void InterpreterMacroAssembler::check_and_handle_earlyret(Register java_thread) {
   243   if (JvmtiExport::can_force_early_return()) {
   244     Label L;
   245     Register tmp = T9;
   247     ld_ptr(AT,java_thread, in_bytes(JavaThread::jvmti_thread_state_offset()));
   248     beq(AT,R0,L);
   249     delayed()->nop();
   251     // Initiate earlyret handling only if it is not already being processed.
   252     // If the flag has the earlyret_processing bit set, it means that this code
   253     // is called *during* earlyret handling - we don't want to reenter.
   254     lw(AT, AT, in_bytes(JvmtiThreadState::earlyret_state_offset()));
   255     move(tmp, JvmtiThreadState::earlyret_pending);
   256     bne(tmp, AT, L);
   257     delayed()->nop();
   258     get_thread(java_thread);
   260     // Call Interpreter::remove_activation_early_entry() to get the address of the
   261     // same-named entrypoint in the generated interpreter code.
   262     ld_ptr(tmp,java_thread, in_bytes(JavaThread::jvmti_thread_state_offset()));
   263     lw(AT,tmp, in_bytes(JvmtiThreadState::earlyret_tos_offset()));
   264     move(A0, AT);
   265     call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry), A0);
   266     jr(V0);
   267     delayed()->nop();
   268     bind(L);
   269     get_thread(java_thread);
   270   }
   271 }
   274 void InterpreterMacroAssembler::get_unsigned_2_byte_index_at_bcp(Register reg,
   275                                                                  int bcp_offset) {
   276   assert(bcp_offset >= 0, "bcp is still pointing to start of bytecode");
   277   lbu(AT, BCP, bcp_offset);
   278   lbu(reg, BCP, bcp_offset + 1);
   279   ins(reg, AT, 8, 8);
   280 }
   283 void InterpreterMacroAssembler::get_cache_index_at_bcp(Register index,
   284                                                        int bcp_offset,
   285                                                        size_t index_size) {
   286   assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");
   287   if (index_size == sizeof(u2)) {
   288     get_2_byte_integer_at_bcp(index, AT, bcp_offset);
   289   } else if (index_size == sizeof(u4)) {
   290     assert(EnableInvokeDynamic, "giant index used only for JSR 292");
   291     get_4_byte_integer_at_bcp(index, AT, bcp_offset);
   292     // Check if the secondary index definition is still ~x, otherwise
   293     // we have to change the following assembler code to calculate the
   294     // plain index.
   295     assert(ConstantPool::decode_invokedynamic_index(~123) == 123, "else change next line");
   296     nor(index, index, R0);
   297     sll(index, index, 0);
   298   } else if (index_size == sizeof(u1)) {
   299     lbu(index, BCP, bcp_offset);
   300   } else {
   301     ShouldNotReachHere();
   302   }
   303 }
   306 void InterpreterMacroAssembler::get_cache_and_index_at_bcp(Register cache,
   307                                                            Register index,
   308                                                            int bcp_offset,
   309                                                            size_t index_size) {
   310   assert_different_registers(cache, index);
   311   get_cache_index_at_bcp(index, bcp_offset, index_size);
   312   ld(cache, FP, frame::interpreter_frame_cache_offset * wordSize);
   313   assert(sizeof(ConstantPoolCacheEntry) == 4 * wordSize, "adjust code below");
   314   assert(exact_log2(in_words(ConstantPoolCacheEntry::size())) == 2, "else change next line");
   315   shl(index, 2);
   316 }
   319 void InterpreterMacroAssembler::get_cache_and_index_and_bytecode_at_bcp(Register cache,
   320                                                                         Register index,
   321                                                                         Register bytecode,
   322                                                                         int byte_no,
   323                                                                         int bcp_offset,
   324                                                                         size_t index_size) {
   325   get_cache_and_index_at_bcp(cache, index, bcp_offset, index_size);
   326   // We use a 32-bit load here since the layout of 64-bit words on
   327   // little-endian machines allow us that.
   328   dsll(AT, index, Address::times_ptr);
   329   dadd(AT, cache, AT);
   330   lw(bytecode, AT, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::indices_offset()));
   332   const int shift_count = (1 + byte_no) * BitsPerByte;
   333   assert((byte_no == TemplateTable::f1_byte && shift_count == ConstantPoolCacheEntry::bytecode_1_shift) ||
   334          (byte_no == TemplateTable::f2_byte && shift_count == ConstantPoolCacheEntry::bytecode_2_shift),
   335          "correct shift count");
   336   dsrl(bytecode, bytecode, shift_count);
   337   assert(ConstantPoolCacheEntry::bytecode_1_mask == ConstantPoolCacheEntry::bytecode_2_mask, "common mask");
   338   move(AT, ConstantPoolCacheEntry::bytecode_1_mask);
   339   andr(bytecode, bytecode, AT);
   340 }
   342 void InterpreterMacroAssembler::get_cache_entry_pointer_at_bcp(Register cache,
   343                                                                Register tmp,
   344                                                                int bcp_offset,
   345                                                                size_t index_size) {
   346   assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");
   347   assert(cache != tmp, "must use different register");
   348   get_cache_index_at_bcp(tmp, bcp_offset, index_size);
   349   assert(sizeof(ConstantPoolCacheEntry) == 4 * wordSize, "adjust code below");
   350   // convert from field index to ConstantPoolCacheEntry index
   351   // and from word offset to byte offset
   352   assert(exact_log2(in_bytes(ConstantPoolCacheEntry::size_in_bytes())) == 2 + LogBytesPerWord, "else change next line");
   353   shl(tmp, 2 + LogBytesPerWord);
   354   ld(cache, FP, frame::interpreter_frame_cache_offset * wordSize);
   355   // skip past the header
   356   daddi(cache, cache, in_bytes(ConstantPoolCache::base_offset()));
   357   dadd(cache, cache, tmp);
   358 }
   360 void InterpreterMacroAssembler::get_method_counters(Register method,
   361                                                     Register mcs, Label& skip) {
   362   Label has_counters;
   363   ld(mcs, method, in_bytes(Method::method_counters_offset()));
   364   bne(mcs, R0, has_counters);
   365   nop();
   366   call_VM(noreg, CAST_FROM_FN_PTR(address,
   367           InterpreterRuntime::build_method_counters), method);
   368   ld(mcs, method, in_bytes(Method::method_counters_offset()));
   369   beq(mcs, R0, skip);   // No MethodCounters allocated, OutOfMemory
   370   nop();
   371   bind(has_counters);
   372 }
   374 // Load object from cpool->resolved_references(index)
   375 void InterpreterMacroAssembler::load_resolved_reference_at_index(
   376                                            Register result, Register index) {
   377   assert_different_registers(result, index);
   378   // convert from field index to resolved_references() index and from
   379   // word index to byte offset. Since this is a java object, it can be compressed
   380   Register tmp = index;  // reuse
   381   shl(tmp, LogBytesPerHeapOop);
   383   get_constant_pool(result);
   384   // load pointer for resolved_references[] objArray
   385   ld(result, result, ConstantPool::resolved_references_offset_in_bytes());
   386   // JNIHandles::resolve(obj);
   387   ld(result, result, 0); //? is needed?
   388   // Add in the index
   389   dadd(result, result, tmp);
   390   load_heap_oop(result, Address(result, arrayOopDesc::base_offset_in_bytes(T_OBJECT)));
   391 }
   393 // Resets LVP to locals.  Register sub_klass cannot be any of the above.
   394 void InterpreterMacroAssembler::gen_subtype_check( Register Rsup_klass, Register Rsub_klass, Label &ok_is_subtype ) {
   395   assert( Rsub_klass != Rsup_klass, "Rsup_klass holds superklass" );
   396   assert( Rsub_klass != T1, "T1 holds 2ndary super array length" );
   397   assert( Rsub_klass != T0, "T0 holds 2ndary super array scan ptr" );
   398   // Profile the not-null value's klass.
   399   // [20130904] Fu: Here T9 and T1 are used as temporary registers.
   400   profile_typecheck(T9, Rsub_klass, T1); // blows rcx, reloads rdi
   402 // Do the check.
   403   check_klass_subtype(Rsub_klass, Rsup_klass, T1, ok_is_subtype); // blows rcx
   405 // Profile the failure of the check.
   406   profile_typecheck_failed(T9); // blows rcx
   407 }
   411 // Java Expression Stack
   413 void InterpreterMacroAssembler::pop_ptr(Register r) {
   414   ld(r, SP, 0);
   415   daddiu(SP, SP, Interpreter::stackElementSize);
   416 }
   418 void InterpreterMacroAssembler::pop_i(Register r) {
   419   lw(r, SP, 0);
   420   daddiu(SP, SP, Interpreter::stackElementSize);
   421 }
   423 void InterpreterMacroAssembler::pop_l(Register r) {
   424   ld(r, SP, 0);
   425   daddiu(SP, SP, 2 * Interpreter::stackElementSize);
   426 }
   428 void InterpreterMacroAssembler::pop_f(FloatRegister r) {
   429   lwc1(r, SP, 0);
   430   daddiu(SP, SP, Interpreter::stackElementSize);
   431 }
   433 void InterpreterMacroAssembler::pop_d(FloatRegister r) {
   434   ldc1(r, SP, 0);
   435   daddiu(SP, SP, 2 * Interpreter::stackElementSize);
   436 }
   438 void InterpreterMacroAssembler::push_ptr(Register r) {
   439   sd(r, SP, - Interpreter::stackElementSize);
   440   daddiu(SP, SP, - Interpreter::stackElementSize);
   441 }
   443 void InterpreterMacroAssembler::push_i(Register r) {
   444   // 20170925: For compatibility reason, don't change to sw. 
   445   sd(r, SP, - Interpreter::stackElementSize);
   446   daddiu(SP, SP, - Interpreter::stackElementSize);
   447 }
   449 void InterpreterMacroAssembler::push_l(Register r) {
   450   sd(r, SP, -2 * Interpreter::stackElementSize);
   451   daddiu(SP, SP, -2 * Interpreter::stackElementSize);
   452 }
   454 void InterpreterMacroAssembler::push_f(FloatRegister r) {
   455   swc1(r, SP, - Interpreter::stackElementSize);
   456   daddiu(SP, SP, - Interpreter::stackElementSize);
   457 }
   459 void InterpreterMacroAssembler::push_d(FloatRegister r) {
   460   sdc1(r, SP, -2 * Interpreter::stackElementSize);
   461   daddiu(SP, SP, -2 * Interpreter::stackElementSize);
   462 }
   464 void InterpreterMacroAssembler::pop(TosState state) {
   465   switch (state) {
   466     case atos: pop_ptr();           break;
   467     case btos:
   468     case ctos:
   469     case stos:
   470     case itos: pop_i();             break;
   471     case ltos: pop_l();             break;
   472     case ftos: pop_f();             break;
   473     case dtos: pop_d();             break;
   474     case vtos: /* nothing to do */  break;
   475     default:   ShouldNotReachHere();
   476   }
   477   verify_oop(FSR, state);
   478 }
   480 //FSR=V0,SSR=V1
   481 void InterpreterMacroAssembler::push(TosState state) {
   482   verify_oop(FSR, state);
   483   switch (state) {
   484     case atos: push_ptr();          break;
   485     case btos:                      
   486     case ctos:                      
   487     case stos:                      
   488     case itos: push_i();            break;
   489     case ltos: push_l();            break;
   490     case ftos: push_f();            break;
   491     case dtos: push_d();            break;
   492     case vtos: /* nothing to do */  break;
   493     default  : ShouldNotReachHere();
   494   }
   495 }
   499 void InterpreterMacroAssembler::load_ptr(int n, Register val) {
   500   ld(val, SP, Interpreter::expr_offset_in_bytes(n));
   501 }
   503 void InterpreterMacroAssembler::store_ptr(int n, Register val) {
   504   sd(val, SP, Interpreter::expr_offset_in_bytes(n));
   505 }
   507 // Jump to from_interpreted entry of a call unless single stepping is possible
   508 // in this thread in which case we must call the i2i entry
   509 void InterpreterMacroAssembler::jump_from_interpreted(Register method, Register temp) {
   510   // record last_sp
   511   move(Rsender, SP);
   512   sd(SP, FP, frame::interpreter_frame_last_sp_offset * wordSize);
   514   if (JvmtiExport::can_post_interpreter_events()) {
   515     Label run_compiled_code;
   516     // JVMTI events, such as single-stepping, are implemented partly by avoiding running
   517     // compiled code in threads for which the event is enabled.  Check here for
   518     // interp_only_mode if these events CAN be enabled.
   519 #ifndef OPT_THREAD
   520     get_thread(temp);
   521 #else
   522     move(temp, TREG);
   523 #endif
   524     // interp_only is an int, on little endian it is sufficient to test the byte only
   525     // Is a cmpl faster?
   526     lw(AT, temp, in_bytes(JavaThread::interp_only_mode_offset()));
   527     beq(AT, R0, run_compiled_code);
   528     delayed()->nop();
   529     ld(AT, method, in_bytes(Method::interpreter_entry_offset()));
   530     jr(AT);
   531     delayed()->nop();
   532     bind(run_compiled_code);
   533   }
   535   ld(AT, method, in_bytes(Method::from_interpreted_offset()));
   536   jr(AT);
   537   delayed()->nop();
   538 }
   541 // The following two routines provide a hook so that an implementation
   542 // can schedule the dispatch in two parts.  amd64 does not do this.
   543 void InterpreterMacroAssembler::dispatch_prolog(TosState state, int step) {
   544   // Nothing amd64 specific to be done here
   545 }
   547 void InterpreterMacroAssembler::dispatch_epilog(TosState state, int step) {
   548   dispatch_next(state, step);
   549 }
   551 // assume the next bytecode in T8.
   552 void InterpreterMacroAssembler::dispatch_base(TosState state,
   553                                               address* table,
   554                                               bool verifyoop) {
   555   if (VerifyActivationFrameSize) {
   556     Label L;
   558     dsub(T2, FP, SP);
   559     int min_frame_size = (frame::link_offset -
   560       frame::interpreter_frame_initial_sp_offset) * wordSize;
   561     daddi(T2, T2,- min_frame_size);
   562     bgez(T2, L);
   563     delayed()->nop();
   564     stop("broken stack frame");
   565     bind(L);
   566   }
   567   // FIXME: I do not know which register should pass to verify_oop
   568   if (verifyoop) verify_oop(FSR, state);
   569   dsll(T2, Rnext, LogBytesPerWord);
   571   if((long)table >= (long)Interpreter::dispatch_table(btos) &&
   572      (long)table <= (long)Interpreter::dispatch_table(vtos)
   573     ) {
   574      int table_size = (long)Interpreter::dispatch_table(ctos) - (long)Interpreter::dispatch_table(btos);
   575      int table_offset = ((int)state - (int)itos) * table_size;
   577      // 2013/12/17 Fu: GP points to the starting address of Interpreter::dispatch_table(itos).
   578      // See StubGenerator::generate_call_stub(address& return_address) for the initialization of GP.
   579      if(table_offset != 0) {
   580         daddiu(T3, GP, table_offset);
   581         if (UseLoongsonISA) {
   582           gsldx(T3, T2, T3, 0);
   583         } else {
   584           daddu(T3, T2, T3);
   585           ld(T3, T3, 0);
   586         }
   587      } else {
   588         if (UseLoongsonISA) {
   589           gsldx(T3, T2, GP, 0);
   590         } else {
   591           daddu(T3, T2, GP);
   592           ld(T3, T3, 0);
   593         }
   594      }
   595   } else {
   596      li(T3, (long)table);
   597      if (UseLoongsonISA) {
   598        gsldx(T3, T2, T3, 0);
   599      } else {
   600        daddu(T3, T2, T3);
   601        ld(T3, T3, 0);
   602      }
   603   }
   604   jr(T3);
   605   delayed()->nop();
   606 }
   608 void InterpreterMacroAssembler::dispatch_only(TosState state) {
   609   dispatch_base(state, Interpreter::dispatch_table(state));
   610 }
   612 void InterpreterMacroAssembler::dispatch_only_normal(TosState state) {
   613   dispatch_base(state, Interpreter::normal_table(state));
   614 }
   616 void InterpreterMacroAssembler::dispatch_only_noverify(TosState state) {
   617   dispatch_base(state, Interpreter::normal_table(state), false);
   618 }
   621 void InterpreterMacroAssembler::dispatch_next(TosState state, int step) {
   622   // load next bytecode (load before advancing r13 to prevent AGI)
   623   lbu(Rnext, BCP, step);
   624   increment(BCP, step);
   625   dispatch_base(state, Interpreter::dispatch_table(state));
   626 }
   628 void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) {
   629   // load current bytecode
   630   lbu(Rnext, BCP, 0);
   631   dispatch_base(state, table);
   632 }
   634 // remove activation
   635 //
   636 // Unlock the receiver if this is a synchronized method.
   637 // Unlock any Java monitors from syncronized blocks.
   638 // Remove the activation from the stack.
   639 //
   640 // If there are locked Java monitors
   641 //    If throw_monitor_exception
   642 //       throws IllegalMonitorStateException
   643 //    Else if install_monitor_exception
   644 //       installs IllegalMonitorStateException
   645 //    Else
   646 //       no error processing
   647 // used registers : T1, T2, T3, T8
   648 // T1 : thread, method access flags
   649 // T2 : monitor entry pointer
   650 // T3 : method, monitor top
   651 // T8 : unlock flag
   652 void InterpreterMacroAssembler::remove_activation(
   653         TosState state,
   654         Register ret_addr,
   655         bool throw_monitor_exception,
   656         bool install_monitor_exception,
   657   bool notify_jvmdi) {
   658   // Note: Registers V0, V1 and F0, F1 may be in use for the result
   659   // check if synchronized method
   660   Label unlocked, unlock, no_unlock;
   662   // get the value of _do_not_unlock_if_synchronized into T8
   663 #ifndef OPT_THREAD
   664   Register thread = T1;
   665   get_thread(thread);
   666 #else
   667   Register thread = TREG;
   668 #endif
   669   lb(T8, thread, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
   670   // reset the flag
   671   sb(R0, thread, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
   672   // get method access flags
   673   ld(T3, FP, frame::interpreter_frame_method_offset * wordSize);
   674   lw(T1, T3, in_bytes(Method::access_flags_offset()));
   675   andi(T1, T1, JVM_ACC_SYNCHRONIZED);
   676   beq(T1, R0, unlocked);
   677   delayed()->nop();
   679   // Don't unlock anything if the _do_not_unlock_if_synchronized flag is set.
   680   bne(T8, R0, no_unlock);
   681   delayed()->nop();
   682   // unlock monitor
   683   push(state); // save result
   685   // BasicObjectLock will be first in list, since this is a
   686   // synchronized method. However, need to check that the object has
   687   // not been unlocked by an explicit monitorexit bytecode.
   688   daddiu(c_rarg0, FP, frame::interpreter_frame_initial_sp_offset * wordSize
   689       - (int)sizeof(BasicObjectLock));
   690   // address of first monitor
   691   lw(T1, c_rarg0, BasicObjectLock::obj_offset_in_bytes());
   692   bne(T1, R0, unlock);
   693   delayed()->nop();
   694   pop(state);
   695   if (throw_monitor_exception) {
   696     // Entry already unlocked, need to throw exception
   697     // I think mips do not need empty_FPU_stack
   698     // remove possible return value from FPU-stack, otherwise stack could overflow
   699     empty_FPU_stack();
   700     call_VM(NOREG, CAST_FROM_FN_PTR(address,
   701     InterpreterRuntime::throw_illegal_monitor_state_exception));
   702     should_not_reach_here();
   703   } else {
   704     // Monitor already unlocked during a stack unroll. If requested,
   705     // install an illegal_monitor_state_exception.  Continue with
   706     // stack unrolling.
   707     if (install_monitor_exception) {
   708       // remove possible return value from FPU-stack,
   709       // otherwise stack could overflow
   710       empty_FPU_stack();
   711       call_VM(NOREG, CAST_FROM_FN_PTR(address,
   712       InterpreterRuntime::new_illegal_monitor_state_exception));
   714     }
   716     b(unlocked);
   717     delayed()->nop();
   718   }
   720   bind(unlock);
   721   unlock_object(c_rarg0);
   722   pop(state);
   724   // Check that for block-structured locking (i.e., that all locked
   725   // objects has been unlocked)
   726   bind(unlocked);
   728   // V0, V1: Might contain return value
   730   // Check that all monitors are unlocked
   731   {
   732     Label loop, exception, entry, restart;
   733     const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
   734     const Address monitor_block_top(FP,
   735         frame::interpreter_frame_monitor_block_top_offset * wordSize);
   737     bind(restart);
   738     // points to current entry, starting with top-most entry (ecx)
   739     ld(c_rarg0, monitor_block_top);
   740     // points to word before bottom of monitor block (ebx)
   741     daddiu(T3, FP, frame::interpreter_frame_initial_sp_offset * wordSize);
   742     b(entry);
   743     delayed()->nop();
   745     // Entry already locked, need to throw exception
   746     bind(exception);
   748     if (throw_monitor_exception) {
   749       // Throw exception
   750       // remove possible return value from FPU-stack,
   751       // otherwise stack could overflow
   752       empty_FPU_stack();
   753       MacroAssembler::call_VM(NOREG, CAST_FROM_FN_PTR(address,
   754                               InterpreterRuntime::throw_illegal_monitor_state_exception));
   755       should_not_reach_here();
   756     } else {
   757       // Stack unrolling. Unlock object and install illegal_monitor_exception
   758       // Unlock does not block, so don't have to worry about the frame
   759       // We don't have to preserve eax, edx since we are going to
   760       // throw an exception
   761       unlock_object(c_rarg0);
   762       if (install_monitor_exception) {
   763         empty_FPU_stack();
   764         call_VM(NOREG, CAST_FROM_FN_PTR(address,
   765                                         InterpreterRuntime::new_illegal_monitor_state_exception));
   766       }
   768       b(restart);
   769       delayed()->nop();
   770     }
   772     bind(loop);
   773     ld(T1, c_rarg0, BasicObjectLock::obj_offset_in_bytes());
   774     bne(T1, R0, exception);// check if current entry is used
   775     delayed()->nop();
   777     daddiu(c_rarg0, c_rarg0, entry_size);// otherwise advance to next entry
   778     bind(entry);
   779     bne(c_rarg0, T3, loop);  // check if bottom reached
   780     delayed()->nop();  // if not at bottom then check this entry
   781   }
   783   bind(no_unlock);
   785   // jvmpi support (jvmdi does not generate MethodExit on exception / popFrame)
   786   if (notify_jvmdi) {
   787     notify_method_exit(false,state,NotifyJVMTI);    // preserve TOSCA
   788   } else {
   789     notify_method_exit(false,state,SkipNotifyJVMTI);// preserve TOSCA
   790   }
   792   // remove activation
   793   ld(SP, FP, frame::interpreter_frame_sender_sp_offset * wordSize);
   794   ld(ret_addr, FP, frame::interpreter_frame_return_addr_offset * wordSize);
   795   ld(FP, FP, frame::interpreter_frame_sender_fp_offset * wordSize);
   796 }
   798 #endif // C_INTERP
   800 // Lock object
   801 //
   802 // Args:
   803 //      c_rarg1: BasicObjectLock to be used for locking
   804 //
   805 // Kills:
   806 //      rax
   807 //      c_rarg0, c_rarg1, c_rarg2, c_rarg3, .. (param regs)
   808 //      rscratch1, rscratch2 (scratch regs)
   809 void InterpreterMacroAssembler::lock_object(Register lock_reg) {
   810   assert(lock_reg == c_rarg0, "The argument is only for looks. It must be c_rarg0");
   812   if (UseHeavyMonitors) {
   813     call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
   814             lock_reg);
   815   } else {
   816     Label done;
   818     const Register swap_reg = T2;  // Must use eax for cmpxchg instruction
   819     const Register obj_reg  = T1;  // Will contain the oop
   821     const int obj_offset = BasicObjectLock::obj_offset_in_bytes();
   822     const int lock_offset = BasicObjectLock::lock_offset_in_bytes ();
   823     const int mark_offset = lock_offset +
   824                             BasicLock::displaced_header_offset_in_bytes();
   826     Label slow_case;
   828     // Load object pointer into obj_reg %ecx
   829     ld(obj_reg, lock_reg, obj_offset);
   831     if (UseBiasedLocking) {
   832       // Note: we use noreg for the temporary register since it's hard
   833       // to come up with a free register on all incoming code paths
   834       biased_locking_enter(lock_reg, obj_reg, swap_reg, noreg, false, done, &slow_case);
   835     }
   838     // Load (object->mark() | 1) into swap_reg %eax
   839     ld(AT, obj_reg, 0);
   840     ori(swap_reg, AT, 1);
   843     // Save (object->mark() | 1) into BasicLock's displaced header
   844     sd(swap_reg, lock_reg, mark_offset);
   846     assert(lock_offset == 0, "displached header must be first word in BasicObjectLock");
   847     //if (os::is_MP()) {
   848       //  lock();
   849     //}
   850     cmpxchg(lock_reg, Address(obj_reg, 0), swap_reg);
   852     if (PrintBiasedLockingStatistics) {
   853       Label L;
   854       beq(AT, R0, L);
   855       delayed()->nop();
   856       push(T0);
   857       push(T1);
   858       atomic_inc32((address)BiasedLocking::fast_path_entry_count_addr(), 1, T0, T1);
   859       pop(T1);
   860       pop(T0);
   861       bind(L);
   862     }
   864     bne(AT, R0, done);
   865     delayed()->nop();
   867     // Test if the oopMark is an obvious stack pointer, i.e.,
   868     //  1) (mark & 3) == 0, and
   869     //  2) SP <= mark < SP + os::pagesize()
   870     //
   871     // These 3 tests can be done by evaluating the following
   872     // expression: ((mark - esp) & (3 - os::vm_page_size())),
   873     // assuming both stack pointer and pagesize have their
   874     // least significant 2 bits clear.
   875     // NOTE: the oopMark is in swap_reg %eax as the result of cmpxchg
   877     dsub(swap_reg, swap_reg, SP);
   878     move(AT, 3 - os::vm_page_size());
   879     andr(swap_reg, swap_reg, AT);
   880     // Save the test result, for recursive case, the result is zero
   881     sd(swap_reg, lock_reg, mark_offset);
   882     if (PrintBiasedLockingStatistics) {
   883       Label L;
   884       bne(swap_reg, R0, L);
   885       delayed()->nop();
   886       push(T0);
   887       push(T1);
   888       atomic_inc32((address)BiasedLocking::fast_path_entry_count_addr(), 1, T0, T1);
   889       pop(T1);
   890       pop(T0);
   891       bind(L);
   892     }
   894     beq(swap_reg, R0, done);
   895     delayed()->nop();
   896     bind(slow_case);
   897     // Call the runtime routine for slow case
   898     call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), lock_reg);
   900     bind(done);
   901   }
   902 }
   905 // Unlocks an object. Used in monitorexit bytecode and
   906 // remove_activation.  Throws an IllegalMonitorException if object is
   907 // not locked by current thread.
   908 //
   909 // Args:
   910 //      c_rarg1: BasicObjectLock for lock
   911 //
   912 // Kills:
   913 //      rax
   914 //      c_rarg0, c_rarg1, c_rarg2, c_rarg3, ... (param regs)
   915 //      rscratch1, rscratch2 (scratch regs)
   916 // Argument: T6 : Points to BasicObjectLock structure for lock
   917 // Argument: c_rarg0 : Points to BasicObjectLock structure for lock
   918 // Throw an IllegalMonitorException if object is not locked by current thread
   919 void InterpreterMacroAssembler::unlock_object(Register lock_reg) {
   920   assert(lock_reg == c_rarg0, "The argument is only for looks. It must be c_rarg0");
   922   if (UseHeavyMonitors) {
   923     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg);
   924   } else {
   925     Label done;
   927     const Register swap_reg   = T2;  // Must use eax for cmpxchg instruction
   928     const Register header_reg = T3;  // Will contain the old oopMark
   929     const Register obj_reg    = T1;  // Will contain the oop
   931     save_bcp(); // Save in case of exception
   933     // Convert from BasicObjectLock structure to object and BasicLock structure
   934     // Store the BasicLock address into %eax
   935     daddi(swap_reg, lock_reg, BasicObjectLock::lock_offset_in_bytes());
   937     // Load oop into obj_reg(%ecx)
   938     ld(obj_reg, lock_reg, BasicObjectLock::obj_offset_in_bytes ());
   939     //free entry
   940     sd(R0, lock_reg, BasicObjectLock::obj_offset_in_bytes());
   941     if (UseBiasedLocking) {
   942       biased_locking_exit(obj_reg, header_reg, done);
   943     }
   945     // Load the old header from BasicLock structure
   946     ld(header_reg, swap_reg, BasicLock::displaced_header_offset_in_bytes());
   947     // zero for recursive case
   948     beq(header_reg, R0, done);
   949     delayed()->nop();
   951     // Atomic swap back the old header
   952     if (os::is_MP()); //lock();
   953     cmpxchg(header_reg, Address(obj_reg, 0), swap_reg);
   955     // zero for recursive case
   956     bne(AT, R0, done);
   957     delayed()->nop();
   959     // Call the runtime routine for slow case.
   960     sd(obj_reg, lock_reg, BasicObjectLock::obj_offset_in_bytes()); // restore obj
   961     call_VM(NOREG,
   962             CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit),
   963             lock_reg);
   965     bind(done);
   967     restore_bcp();
   968   }
   969 }
   971 #ifndef CC_INTERP
   973 void InterpreterMacroAssembler::test_method_data_pointer(Register mdp,
   974                                                          Label& zero_continue) {
   975   assert(ProfileInterpreter, "must be profiling interpreter");
   976   ld(mdp, Address(FP, frame::interpreter_frame_mdx_offset * wordSize));
   977   beq(mdp, R0, zero_continue);
   978   delayed()->nop();
   979 }
   982 // Set the method data pointer for the current bcp.
   983 void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() {
   984   assert(ProfileInterpreter, "must be profiling interpreter");
   985   Label set_mdp;
   987   // V0 and T0 will be used as two temporary registers.
   988   sd(V0, SP, (-1) * wordSize);
   989   sd(T0, SP, (-2) * wordSize);
   990   daddiu(SP, SP, (-2) * wordSize);
   992   get_method(T0);
   993   // Test MDO to avoid the call if it is NULL.
   994   ld(V0, T0, in_bytes(Method::method_data_offset()));
   995   beq(V0, R0, set_mdp);
   996   delayed()->nop();
   998   // method: T0
   999   // bcp: BCP --> S0
  1000   call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), T0, BCP);
  1001   // mdi: V0
  1002   // mdo is guaranteed to be non-zero here, we checked for it before the call.
  1003   get_method(T0);
  1004   ld(T0, T0, in_bytes(Method::method_data_offset()));
  1005   daddiu(T0, T0, in_bytes(MethodData::data_offset()));
  1006   daddu(V0, T0, V0);
  1007   bind(set_mdp);
  1008   sd(V0, FP, frame::interpreter_frame_mdx_offset * wordSize);
  1009   daddiu(SP, SP, 2 * wordSize);
  1010   ld(V0, SP, (-1) * wordSize);
  1011   ld(T0, SP, (-2) * wordSize);
  1014 void InterpreterMacroAssembler::verify_method_data_pointer() {
  1015   assert(ProfileInterpreter, "must be profiling interpreter");
  1016 #ifdef ASSERT
  1017   Label verify_continue;
  1018   Register method = V0;
  1019   Register mdp = V1;
  1020   Register tmp = A0;
  1021   push(method);
  1022   push(mdp);
  1023   push(tmp);
  1024   test_method_data_pointer(mdp, verify_continue); // If mdp is zero, continue
  1025   get_method(method);
  1027   // If the mdp is valid, it will point to a DataLayout header which is
  1028   // consistent with the bcp.  The converse is highly probable also.
  1029   lhu(tmp, mdp, in_bytes(DataLayout::bci_offset()));
  1030   ld(AT, method, in_bytes(Method::const_offset()));
  1031   daddu(tmp, tmp, AT);
  1032   daddiu(tmp, tmp, in_bytes(ConstMethod::codes_offset()));
  1033   beq(tmp, BCP, verify_continue);
  1034   nop();
  1035   call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp), method, BCP, mdp);
  1036   bind(verify_continue);
  1037   pop(tmp);
  1038   pop(mdp);
  1039   pop(method);
  1040 #endif // ASSERT
  1044 void InterpreterMacroAssembler::set_mdp_data_at(Register mdp_in,
  1045                                                 int constant,
  1046                                                 Register value) {
  1047   assert(ProfileInterpreter, "must be profiling interpreter");
  1048   Address data(mdp_in, constant);
  1049   sd(value, data);
  1053 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
  1054                                                       int constant,
  1055                                                       bool decrement) {
  1056   // Counter address
  1057   Address data(mdp_in, constant);
  1059   increment_mdp_data_at(data, decrement);
  1062 void InterpreterMacroAssembler::increment_mdp_data_at(Address data,
  1063                                                       bool decrement) {
  1064   assert(ProfileInterpreter, "must be profiling interpreter");
  1065   // %%% this does 64bit counters at best it is wasting space
  1066   // at worst it is a rare bug when counters overflow
  1067   Register tmp = S0;
  1068   push(tmp);
  1069   if (decrement) {
  1070     // Decrement the register.
  1071     ld(AT, data);
  1072     daddiu(tmp, AT, (int32_t) -DataLayout::counter_increment);
  1073     // If the decrement causes the counter to overflow, stay negative
  1074     Label L;
  1075     slt(AT, tmp, R0);
  1076     bne(AT, R0, L);
  1077     nop();
  1078     daddi(tmp, tmp, (int32_t) DataLayout::counter_increment);
  1079     bind(L);
  1080     sd(tmp, data);
  1081   } else {
  1082     assert(DataLayout::counter_increment == 1,
  1083            "flow-free idiom only works with 1");
  1084     ld(AT, data);
  1085     // Increment the register.
  1086     daddiu(tmp, AT, DataLayout::counter_increment);
  1087     // If the increment causes the counter to overflow, pull back by 1.
  1088     slt(AT, tmp, R0);
  1089     dsubu(tmp, tmp, AT);
  1090     sd(tmp, data);
  1092   pop(tmp);
  1096 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
  1097                                                       Register reg,
  1098                                                       int constant,
  1099                                                       bool decrement) {
  1100   Register tmp = S0;
  1101   push(S0);
  1102   if (decrement) {
  1103     // Decrement the register.
  1104     daddu(AT, mdp_in, reg);
  1105     assert(Assembler::is_simm16(constant), "constant is not a simm16 !");
  1106     ld(AT, AT, constant);
  1108     daddiu(tmp, AT, (int32_t) -DataLayout::counter_increment);
  1109     // If the decrement causes the counter to overflow, stay negative
  1110     Label L;
  1111     slt(AT, tmp, R0);
  1112     bne(AT, R0, L);
  1113     nop();
  1114     daddi(tmp, tmp, (int32_t) DataLayout::counter_increment);
  1115     bind(L);
  1117     daddu(AT, mdp_in, reg);
  1118     sd(tmp, AT, constant);
  1119   } else {
  1120     daddu(AT, mdp_in, reg);
  1121     assert(Assembler::is_simm16(constant), "constant is not a simm16 !");
  1122     ld(AT, AT, constant);
  1124     // Increment the register.
  1125     daddiu(tmp, AT, DataLayout::counter_increment);
  1126     // If the increment causes the counter to overflow, pull back by 1.
  1127     slt(AT, tmp, R0);
  1128     dsubu(tmp, tmp, AT);
  1130     daddu(AT, mdp_in, reg);
  1131     sd(tmp, AT, constant);
  1133   pop(S0);
  1136 void InterpreterMacroAssembler::set_mdp_flag_at(Register mdp_in,
  1137                                                 int flag_byte_constant) {
  1138   assert(ProfileInterpreter, "must be profiling interpreter");
  1139   int header_offset = in_bytes(DataLayout::header_offset());
  1140   int header_bits = DataLayout::flag_mask_to_header_mask(flag_byte_constant);
  1141   // Set the flag
  1142   lw(AT, Address(mdp_in, header_offset));
  1143   if(Assembler::is_simm16(header_bits)) {
  1144     ori(AT, AT, header_bits);
  1145   } else {
  1146     push(T8);
  1147     // T8 is used as a temporary register.
  1148     move(T8, header_bits);
  1149     orr(AT, AT, T8);
  1150     pop(T8);
  1152   sw(AT, Address(mdp_in, header_offset));
  1157 void InterpreterMacroAssembler::test_mdp_data_at(Register mdp_in,
  1158                                                  int offset,
  1159                                                  Register value,
  1160                                                  Register test_value_out,
  1161                                                  Label& not_equal_continue) {
  1162   assert(ProfileInterpreter, "must be profiling interpreter");
  1163   if (test_value_out == noreg) {
  1164     ld(AT, Address(mdp_in, offset));
  1165     bne(AT, value, not_equal_continue);
  1166     nop();
  1167   } else {
  1168     // Put the test value into a register, so caller can use it:
  1169     ld(test_value_out, Address(mdp_in, offset));
  1170     bne(value, test_value_out, not_equal_continue);
  1171     nop();
  1176 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,
  1177                                                      int offset_of_disp) {
  1178   assert(ProfileInterpreter, "must be profiling interpreter");
  1179   assert(Assembler::is_simm16(offset_of_disp), "offset is not an simm16");
  1180   ld(AT, mdp_in, offset_of_disp);
  1181   daddu(mdp_in, mdp_in, AT);
  1182   sd(mdp_in, Address(FP, frame::interpreter_frame_mdx_offset * wordSize));
  1186 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,
  1187                                                      Register reg,
  1188                                                      int offset_of_disp) {
  1189   assert(ProfileInterpreter, "must be profiling interpreter");
  1190 //  Attention: Until now (20121217), we do not support this kind of addressing on Loongson.
  1191 //  Address disp_address(mdp_in, reg, Address::times_1, offset_of_disp);
  1192   daddu(AT, reg, mdp_in);
  1193   assert(Assembler::is_simm16(offset_of_disp), "offset is not an simm16");
  1194   ld(AT, AT, offset_of_disp);
  1195   daddu(mdp_in, mdp_in, AT);
  1196   sd(mdp_in, Address(FP, frame::interpreter_frame_mdx_offset * wordSize));
  1200 void InterpreterMacroAssembler::update_mdp_by_constant(Register mdp_in,
  1201                                                        int constant) {
  1202   assert(ProfileInterpreter, "must be profiling interpreter");
  1203   if(Assembler::is_simm16(constant)) {
  1204     daddiu(mdp_in, mdp_in, constant);
  1205   } else {
  1206     move(AT, constant);
  1207     daddu(mdp_in, mdp_in, AT);
  1209   sd(mdp_in, Address(FP, frame::interpreter_frame_mdx_offset * wordSize));
  1213 void InterpreterMacroAssembler::update_mdp_for_ret(Register return_bci) {
  1214   assert(ProfileInterpreter, "must be profiling interpreter");
  1215   push(return_bci); // save/restore across call_VM
  1216   call_VM(noreg,
  1217           CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret),
  1218           return_bci);
  1219   pop(return_bci);
  1223 void InterpreterMacroAssembler::profile_taken_branch(Register mdp,
  1224                                                      Register bumped_count) {
  1225   if (ProfileInterpreter) {
  1226     Label profile_continue;
  1228     // If no method data exists, go to profile_continue.
  1229     // Otherwise, assign to mdp
  1230     test_method_data_pointer(mdp, profile_continue);
  1232     // We are taking a branch.  Increment the taken count.
  1233     // We inline increment_mdp_data_at to return bumped_count in a register
  1234     //increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset()));
  1235     ld(bumped_count, mdp, in_bytes(JumpData::taken_offset()));
  1236     assert(DataLayout::counter_increment == 1,
  1237            "flow-free idiom only works with 1");
  1238     push(T8);
  1239     // T8 is used as a temporary register.
  1240     daddiu(T8, bumped_count, DataLayout::counter_increment);
  1241     slt(AT, T8, R0);
  1242     dsubu(bumped_count, T8, AT);
  1243     pop(T8);
  1244     sd(bumped_count, mdp, in_bytes(JumpData::taken_offset())); // Store back out
  1245     // The method data pointer needs to be updated to reflect the new target.
  1246     update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset()));
  1247     bind(profile_continue);
  1252 void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp) {
  1253   if (ProfileInterpreter) {
  1254     Label profile_continue;
  1256     // If no method data exists, go to profile_continue.
  1257     test_method_data_pointer(mdp, profile_continue);
  1259     // We are taking a branch.  Increment the not taken count.
  1260     increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset()));
  1262     // The method data pointer needs to be updated to correspond to
  1263     // the next bytecode
  1264     update_mdp_by_constant(mdp, in_bytes(BranchData::branch_data_size()));
  1265     bind(profile_continue);
  1270 void InterpreterMacroAssembler::profile_call(Register mdp) {
  1271   if (ProfileInterpreter) {
  1272     Label profile_continue;
  1274     // If no method data exists, go to profile_continue.
  1275     test_method_data_pointer(mdp, profile_continue);
  1277     // We are making a call.  Increment the count.
  1278     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1280     // The method data pointer needs to be updated to reflect the new target.
  1281     update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size()));
  1282     bind(profile_continue);
  1287 void InterpreterMacroAssembler::profile_final_call(Register mdp) {
  1288   if (ProfileInterpreter) {
  1289     Label profile_continue;
  1291     // If no method data exists, go to profile_continue.
  1292     test_method_data_pointer(mdp, profile_continue);
  1294     // We are making a call.  Increment the count.
  1295     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1297     // The method data pointer needs to be updated to reflect the new target.
  1298     update_mdp_by_constant(mdp,
  1299                            in_bytes(VirtualCallData::
  1300                                     virtual_call_data_size()));
  1301     bind(profile_continue);
  1306 void InterpreterMacroAssembler::profile_virtual_call(Register receiver,
  1307                                                      Register mdp,
  1308                                                      Register reg2,
  1309                                                      bool receiver_can_be_null) {
  1310   if (ProfileInterpreter) {
  1311     Label profile_continue;
  1313     // If no method data exists, go to profile_continue.
  1314     test_method_data_pointer(mdp, profile_continue);
  1316     Label skip_receiver_profile;
  1317     if (receiver_can_be_null) {
  1318       Label not_null;
  1319       bne(receiver, R0, not_null);
  1320       nop();
  1321       // We are making a call.  Increment the count.
  1322       increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1323       beq(R0, R0, skip_receiver_profile);
  1324       nop();
  1325       bind(not_null);
  1328     // Record the receiver type.
  1329     record_klass_in_profile(receiver, mdp, reg2, true);
  1330     bind(skip_receiver_profile);
  1332     // The method data pointer needs to be updated to reflect the new target.
  1333     update_mdp_by_constant(mdp,
  1334                            in_bytes(VirtualCallData::
  1335                                     virtual_call_data_size()));
  1336     bind(profile_continue);
  1340 // This routine creates a state machine for updating the multi-row
  1341 // type profile at a virtual call site (or other type-sensitive bytecode).
  1342 // The machine visits each row (of receiver/count) until the receiver type
  1343 // is found, or until it runs out of rows.  At the same time, it remembers
  1344 // the location of the first empty row.  (An empty row records null for its
  1345 // receiver, and can be allocated for a newly-observed receiver type.)
  1346 // Because there are two degrees of freedom in the state, a simple linear
  1347 // search will not work; it must be a decision tree.  Hence this helper
  1348 // function is recursive, to generate the required tree structured code.
  1349 // It's the interpreter, so we are trading off code space for speed.
  1350 // See below for example code.
  1351 void InterpreterMacroAssembler::record_klass_in_profile_helper(
  1352                                         Register receiver, Register mdp,
  1353                                         Register reg2, int start_row,
  1354                                         Label& done, bool is_virtual_call) {
  1355   if (TypeProfileWidth == 0) {
  1356     if (is_virtual_call) {
  1357       increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1359     return;
  1362   int last_row = VirtualCallData::row_limit() - 1;
  1363   assert(start_row <= last_row, "must be work left to do");
  1364   // Test this row for both the receiver and for null.
  1365   // Take any of three different outcomes:
  1366   //   1. found receiver => increment count and goto done
  1367   //   2. found null => keep looking for case 1, maybe allocate this cell
  1368   //   3. found something else => keep looking for cases 1 and 2
  1369   // Case 3 is handled by a recursive call.
  1370   for (int row = start_row; row <= last_row; row++) {
  1371     Label next_test;
  1372     bool test_for_null_also = (row == start_row);
  1374     // See if the receiver is receiver[n].
  1375     int recvr_offset = in_bytes(VirtualCallData::receiver_offset(row));
  1376     test_mdp_data_at(mdp, recvr_offset, receiver,
  1377                      (test_for_null_also ? reg2 : noreg),
  1378                      next_test);
  1379     // (Reg2 now contains the receiver from the CallData.)
  1381     // The receiver is receiver[n].  Increment count[n].
  1382     int count_offset = in_bytes(VirtualCallData::receiver_count_offset(row));
  1383     increment_mdp_data_at(mdp, count_offset);
  1384     beq(R0, R0, done);
  1385     nop();
  1386     bind(next_test);
  1388     if (test_for_null_also) {
  1389       Label found_null;
  1390       // Failed the equality check on receiver[n]...  Test for null.
  1391       if (start_row == last_row) {
  1392         // The only thing left to do is handle the null case.
  1393         if (is_virtual_call) {
  1394           beq(reg2, R0, found_null);
  1395           nop();
  1396           // Receiver did not match any saved receiver and there is no empty row for it.
  1397           // Increment total counter to indicate polymorphic case.
  1398           increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1399           beq(R0, R0, done);
  1400           nop();
  1401           bind(found_null);
  1402         } else {
  1403           bne(reg2, R0, done);
  1404           nop();
  1406         break;
  1408       // Since null is rare, make it be the branch-taken case.
  1409       beq(reg2, R0, found_null);
  1410       nop();
  1412       // Put all the "Case 3" tests here.
  1413       record_klass_in_profile_helper(receiver, mdp, reg2, start_row + 1, done, is_virtual_call);
  1415       // Found a null.  Keep searching for a matching receiver,
  1416       // but remember that this is an empty (unused) slot.
  1417       bind(found_null);
  1421   // In the fall-through case, we found no matching receiver, but we
  1422   // observed the receiver[start_row] is NULL.
  1424   // Fill in the receiver field and increment the count.
  1425   int recvr_offset = in_bytes(VirtualCallData::receiver_offset(start_row));
  1426   set_mdp_data_at(mdp, recvr_offset, receiver);
  1427   int count_offset = in_bytes(VirtualCallData::receiver_count_offset(start_row));
  1428   move(reg2, DataLayout::counter_increment);
  1429   set_mdp_data_at(mdp, count_offset, reg2);
  1430   if (start_row > 0) {
  1431     beq(R0, R0, done);
  1432     nop();
  1436 // Example state machine code for three profile rows:
  1437 //   // main copy of decision tree, rooted at row[1]
  1438 //   if (row[0].rec == rec) { row[0].incr(); goto done; }
  1439 //   if (row[0].rec != NULL) {
  1440 //     // inner copy of decision tree, rooted at row[1]
  1441 //     if (row[1].rec == rec) { row[1].incr(); goto done; }
  1442 //     if (row[1].rec != NULL) {
  1443 //       // degenerate decision tree, rooted at row[2]
  1444 //       if (row[2].rec == rec) { row[2].incr(); goto done; }
  1445 //       if (row[2].rec != NULL) { goto done; } // overflow
  1446 //       row[2].init(rec); goto done;
  1447 //     } else {
  1448 //       // remember row[1] is empty
  1449 //       if (row[2].rec == rec) { row[2].incr(); goto done; }
  1450 //       row[1].init(rec); goto done;
  1451 //     }
  1452 //   } else {
  1453 //     // remember row[0] is empty
  1454 //     if (row[1].rec == rec) { row[1].incr(); goto done; }
  1455 //     if (row[2].rec == rec) { row[2].incr(); goto done; }
  1456 //     row[0].init(rec); goto done;
  1457 //   }
  1458 //   done:
  1460 void InterpreterMacroAssembler::record_klass_in_profile(Register receiver,
  1461                                                         Register mdp, Register reg2,
  1462                                                         bool is_virtual_call) {
  1463   assert(ProfileInterpreter, "must be profiling");
  1464   Label done;
  1466   record_klass_in_profile_helper(receiver, mdp, reg2, 0, done, is_virtual_call);
  1468   bind (done);
  1471 void InterpreterMacroAssembler::profile_ret(Register return_bci,
  1472                                             Register mdp) {
  1473   if (ProfileInterpreter) {
  1474     Label profile_continue;
  1475     uint row;
  1477     // If no method data exists, go to profile_continue.
  1478     test_method_data_pointer(mdp, profile_continue);
  1480     // Update the total ret count.
  1481     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1483     for (row = 0; row < RetData::row_limit(); row++) {
  1484       Label next_test;
  1486       // See if return_bci is equal to bci[n]:
  1487       test_mdp_data_at(mdp,
  1488                        in_bytes(RetData::bci_offset(row)),
  1489                        return_bci, noreg,
  1490                        next_test);
  1492       // return_bci is equal to bci[n].  Increment the count.
  1493       increment_mdp_data_at(mdp, in_bytes(RetData::bci_count_offset(row)));
  1495       // The method data pointer needs to be updated to reflect the new target.
  1496       update_mdp_by_offset(mdp,
  1497                            in_bytes(RetData::bci_displacement_offset(row)));
  1498       beq(R0, R0, profile_continue);
  1499       nop();
  1500       bind(next_test);
  1503     update_mdp_for_ret(return_bci);
  1505     bind(profile_continue);
  1510 void InterpreterMacroAssembler::profile_null_seen(Register mdp) {
  1511   if (ProfileInterpreter) {
  1512     Label profile_continue;
  1514     // If no method data exists, go to profile_continue.
  1515     test_method_data_pointer(mdp, profile_continue);
  1517     set_mdp_flag_at(mdp, BitData::null_seen_byte_constant());
  1519     // The method data pointer needs to be updated.
  1520     int mdp_delta = in_bytes(BitData::bit_data_size());
  1521     if (TypeProfileCasts) {
  1522       mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
  1524     update_mdp_by_constant(mdp, mdp_delta);
  1526     bind(profile_continue);
  1531 void InterpreterMacroAssembler::profile_typecheck_failed(Register mdp) {
  1532   if (ProfileInterpreter && TypeProfileCasts) {
  1533     Label profile_continue;
  1535     // If no method data exists, go to profile_continue.
  1536     test_method_data_pointer(mdp, profile_continue);
  1538     int count_offset = in_bytes(CounterData::count_offset());
  1539     // Back up the address, since we have already bumped the mdp.
  1540     count_offset -= in_bytes(VirtualCallData::virtual_call_data_size());
  1542     // *Decrement* the counter.  We expect to see zero or small negatives.
  1543     increment_mdp_data_at(mdp, count_offset, true);
  1545     bind (profile_continue);
  1550 void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2) {
  1551   if (ProfileInterpreter) {
  1552     Label profile_continue;
  1554     // If no method data exists, go to profile_continue.
  1555     test_method_data_pointer(mdp, profile_continue);
  1557     // The method data pointer needs to be updated.
  1558     int mdp_delta = in_bytes(BitData::bit_data_size());
  1559     if (TypeProfileCasts) {
  1560       mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
  1562       // Record the object type.
  1563       record_klass_in_profile(klass, mdp, reg2, false);
  1565     update_mdp_by_constant(mdp, mdp_delta);
  1567     bind(profile_continue);
  1572 void InterpreterMacroAssembler::profile_switch_default(Register mdp) {
  1573   if (ProfileInterpreter) {
  1574     Label profile_continue;
  1576     // If no method data exists, go to profile_continue.
  1577     test_method_data_pointer(mdp, profile_continue);
  1579     // Update the default case count
  1580     increment_mdp_data_at(mdp,
  1581                           in_bytes(MultiBranchData::default_count_offset()));
  1583     // The method data pointer needs to be updated.
  1584     update_mdp_by_offset(mdp,
  1585                          in_bytes(MultiBranchData::
  1586                                   default_displacement_offset()));
  1588     bind(profile_continue);
  1593 void InterpreterMacroAssembler::profile_switch_case(Register index,
  1594                                                     Register mdp,
  1595                                                     Register reg2) {
  1596   if (ProfileInterpreter) {
  1597     Label profile_continue;
  1599     // If no method data exists, go to profile_continue.
  1600     test_method_data_pointer(mdp, profile_continue);
  1602     // Build the base (index * per_case_size_in_bytes()) +
  1603     // case_array_offset_in_bytes()
  1604     move(reg2, in_bytes(MultiBranchData::per_case_size()));
  1605     if (UseLoongsonISA) {
  1606       gsdmult(index, index, reg2);
  1607     } else {
  1608       dmult(index, reg2);
  1609       mflo(index);
  1611     daddiu(index, index, in_bytes(MultiBranchData::case_array_offset()));
  1613     // Update the case count
  1614     increment_mdp_data_at(mdp,
  1615                           index,
  1616                           in_bytes(MultiBranchData::relative_count_offset()));
  1618     // The method data pointer needs to be updated.
  1619     update_mdp_by_offset(mdp,
  1620                          index,
  1621                          in_bytes(MultiBranchData::
  1622                                   relative_displacement_offset()));
  1624     bind(profile_continue);
  1628 void InterpreterMacroAssembler::profile_obj_type(Register obj, const Address& mdo_addr) {
  1629   Label update, next, none;
  1631   verify_oop(obj);
  1633   bne(obj, R0, update);
  1634   nop();
  1636   push(T1);
  1637   if (mdo_addr.index() == noreg) {
  1638     ld(T1, mdo_addr);
  1639   } else {
  1640     guarantee(T1 != mdo_addr.base(), "The base register will be corrupted !");
  1641     guarantee(T1 != mdo_addr.index(), "The index register will be corrupted !");
  1643     dsll(AT, mdo_addr.index(), mdo_addr.scale());
  1644     daddu(AT, AT, mdo_addr.base());
  1645     ld(T1, AT, mdo_addr.disp());
  1647   li(AT, TypeEntries::null_seen);
  1648   orr(AT, T1, AT);
  1649   if (mdo_addr.index() == noreg) {
  1650     sd(AT, mdo_addr);
  1651   } else {
  1652     guarantee(T1 != mdo_addr.base(), "The base register will be corrupted !");
  1653     guarantee(T1 != mdo_addr.index(), "The index register will be corrupted !");
  1655     dsll(T1, mdo_addr.index(), mdo_addr.scale());
  1656     daddu(T1, T1, mdo_addr.base());
  1657     sd(AT, T1, mdo_addr.disp());
  1659   pop(T1);
  1661   beq(R0, R0, next);
  1662   nop();
  1664   bind(update);
  1665   load_klass(obj, obj);
  1667   if (mdo_addr.index() == noreg) {
  1668     ld(AT, mdo_addr);
  1669   } else {
  1670     dsll(AT, mdo_addr.index(), mdo_addr.scale());
  1671     daddu(AT, AT, mdo_addr.base());
  1672     ld(AT, AT, mdo_addr.disp());
  1674   xorr(obj, obj, AT);
  1676   li(AT, TypeEntries::type_klass_mask);
  1677   andr(AT, obj, AT);
  1678   beq(AT, R0, next);
  1679   nop();
  1681   li(AT, TypeEntries::type_unknown);
  1682   andr(AT, AT, obj);
  1683   bne(AT, R0, next);
  1684   nop();
  1686   if (mdo_addr.index() == noreg) {
  1687     ld(AT, mdo_addr);
  1688   } else {
  1689     dsll(AT, mdo_addr.index(), mdo_addr.scale());
  1690     daddu(AT, AT, mdo_addr.base());
  1691     ld(AT, AT, mdo_addr.disp());
  1693   beq(AT, R0, none);
  1694   nop();
  1697   push(T1);
  1698   if (mdo_addr.index() == noreg) {
  1699     ld(T1, mdo_addr);
  1700   } else {
  1701     guarantee(T1 != mdo_addr.base(), "The base register will be corrupted !");
  1702     guarantee(T1 != mdo_addr.index(), "The index register will be corrupted !");
  1704     dsll(AT, mdo_addr.index(), mdo_addr.scale());
  1705     daddu(AT, AT, mdo_addr.base());
  1706     ld(T1, AT, mdo_addr.disp());
  1708   li(AT, TypeEntries::null_seen);
  1709   subu(AT, AT, T1);
  1710   pop(T1);
  1711   beq(AT, R0, none);
  1712   nop();
  1714   // There is a chance that the checks above (re-reading profiling
  1715   // data from memory) fail if another thread has just set the
  1716   // profiling to this obj's klass
  1717   if (mdo_addr.index() == noreg) {
  1718     ld(AT, mdo_addr);
  1719   } else {
  1720     dsll(AT, mdo_addr.index(), mdo_addr.scale());
  1721     daddu(AT, AT, mdo_addr.base());
  1722     ld(AT, AT, mdo_addr.disp());
  1724   xorr(obj, obj, AT);
  1725   li(AT, TypeEntries::type_klass_mask);
  1726   andr(AT, obj, AT);
  1727   beq(AT, R0, next);
  1728   nop();
  1730   // different than before. Cannot keep accurate profile.
  1731   push(T1);
  1732   if (mdo_addr.index() == noreg) {
  1733     ld(T1, mdo_addr);
  1734   } else {
  1735     guarantee(T1 != mdo_addr.base(), "The base register will be corrupted !");
  1736     guarantee(T1 != mdo_addr.index(), "The index register will be corrupted !");
  1738     dsll(AT, mdo_addr.index(), mdo_addr.scale());
  1739     daddu(AT, AT, mdo_addr.base());
  1740     ld(T1, AT, mdo_addr.disp());
  1742   li(AT, TypeEntries::type_unknown);
  1743   orr(AT, T1, AT);
  1744   if (mdo_addr.index() == noreg) {
  1745     sd(AT, mdo_addr);
  1746   } else {
  1747     guarantee(T1 != mdo_addr.base(), "The base register will be corrupted !");
  1748     guarantee(T1 != mdo_addr.index(), "The index register will be corrupted !");
  1750     dsll(T1, mdo_addr.index(), mdo_addr.scale());
  1751     daddu(T1, T1, mdo_addr.base());
  1752     sd(AT, T1, mdo_addr.disp());
  1754   pop(T1);
  1755   beq(R0, R0, next);
  1756   nop();
  1759   bind(none);
  1760   // first time here. Set profile type.
  1761   if (mdo_addr.index() == noreg) {
  1762     sd(obj, mdo_addr);
  1763   } else {
  1764     dsll(AT, mdo_addr.index(), mdo_addr.scale());
  1765     daddu(AT, AT, mdo_addr.base());
  1766     sd(obj, AT, mdo_addr.disp());
  1769   bind(next);
  1772 void InterpreterMacroAssembler::profile_arguments_type(Register mdp, Register callee, Register tmp, bool is_virtual) {
  1773   if (!ProfileInterpreter) {
  1774     return;
  1777   if (MethodData::profile_arguments() || MethodData::profile_return()) {
  1778     Label profile_continue;
  1780     test_method_data_pointer(mdp, profile_continue);
  1782     int off_to_start = is_virtual ? in_bytes(VirtualCallData::virtual_call_data_size()) : in_bytes(CounterData::counter_data_size());
  1784     lb(AT, mdp, in_bytes(DataLayout::tag_offset()) - off_to_start);
  1785     li(tmp, is_virtual ? DataLayout::virtual_call_type_data_tag : DataLayout::call_type_data_tag);
  1786     bne(tmp, AT, profile_continue);
  1787     nop();
  1790     if (MethodData::profile_arguments()) {
  1791       Label done;
  1792       int off_to_args = in_bytes(TypeEntriesAtCall::args_data_offset());
  1793       if (Assembler::is_simm16(off_to_args)) {
  1794         daddiu(mdp, mdp, off_to_args);
  1795       } else {
  1796         move(AT, off_to_args);
  1797         daddu(mdp, mdp, AT);
  1801       for (int i = 0; i < TypeProfileArgsLimit; i++) {
  1802         if (i > 0 || MethodData::profile_return()) {
  1803           // If return value type is profiled we may have no argument to profile
  1804           ld(tmp, mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args);
  1806           if (Assembler::is_simm16(-1 * i * TypeStackSlotEntries::per_arg_count())) {
  1807             addiu32(tmp, tmp, -1 * i * TypeStackSlotEntries::per_arg_count());
  1808           } else {
  1809             li(AT, i*TypeStackSlotEntries::per_arg_count());
  1810             subu32(tmp, tmp, AT);
  1813           li(AT, TypeStackSlotEntries::per_arg_count());
  1814           slt(AT, tmp, AT);
  1815           bne(AT, R0, done);
  1816           nop();
  1818         ld(tmp, callee, in_bytes(Method::const_offset()));
  1820         lhu(tmp, tmp, in_bytes(ConstMethod::size_of_parameters_offset()));
  1822         // stack offset o (zero based) from the start of the argument
  1823         // list, for n arguments translates into offset n - o - 1 from
  1824         // the end of the argument list
  1825         ld(AT, mdp, in_bytes(TypeEntriesAtCall::stack_slot_offset(i))-off_to_args);
  1826         subu(tmp, tmp, AT);
  1828         addiu32(tmp, tmp, -1);
  1830         Address arg_addr = argument_address(tmp);
  1831         ld(tmp, arg_addr);
  1833         Address mdo_arg_addr(mdp, in_bytes(TypeEntriesAtCall::argument_type_offset(i))-off_to_args);
  1834         profile_obj_type(tmp, mdo_arg_addr);
  1836         int to_add = in_bytes(TypeStackSlotEntries::per_arg_size());
  1837         if (Assembler::is_simm16(to_add)) {
  1838           daddiu(mdp, mdp, to_add);
  1839         } else {
  1840           move(AT, to_add);
  1841           daddu(mdp, mdp, AT);
  1844         off_to_args += to_add;
  1847       if (MethodData::profile_return()) {
  1848         ld(tmp, mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args);
  1850         int tmp_arg_counts = TypeProfileArgsLimit*TypeStackSlotEntries::per_arg_count();
  1851         if (Assembler::is_simm16(-1 * tmp_arg_counts)) {
  1852           addiu32(tmp, tmp, -1 * tmp_arg_counts);
  1853         } else {
  1854           move(AT, tmp_arg_counts);
  1855           subu32(mdp, mdp, AT);
  1859       bind(done);
  1861       if (MethodData::profile_return()) {
  1862         // We're right after the type profile for the last
  1863         // argument. tmp is the number of cells left in the
  1864         // CallTypeData/VirtualCallTypeData to reach its end. Non null
  1865         // if there's a return to profile.
  1866         assert(ReturnTypeEntry::static_cell_count() < TypeStackSlotEntries::per_arg_count(), "can't move past ret type");
  1867         sll(tmp, tmp, exact_log2(DataLayout::cell_size));
  1868         daddu(mdp, mdp, tmp);
  1870       sd(mdp, FP, frame::interpreter_frame_mdx_offset * wordSize);
  1871     } else {
  1872       assert(MethodData::profile_return(), "either profile call args or call ret");
  1873       update_mdp_by_constant(mdp, in_bytes(TypeEntriesAtCall::return_only_size()));
  1876     // mdp points right after the end of the
  1877     // CallTypeData/VirtualCallTypeData, right after the cells for the
  1878     // return value type if there's one
  1880     bind(profile_continue);
  1884 void InterpreterMacroAssembler::profile_return_type(Register mdp, Register ret, Register tmp) {
  1885   assert_different_registers(mdp, ret, tmp, _bcp_register);
  1886   if (ProfileInterpreter && MethodData::profile_return()) {
  1887     Label profile_continue, done;
  1889     test_method_data_pointer(mdp, profile_continue);
  1891     if (MethodData::profile_return_jsr292_only()) {
  1892       // If we don't profile all invoke bytecodes we must make sure
  1893       // it's a bytecode we indeed profile. We can't go back to the
  1894       // begining of the ProfileData we intend to update to check its
  1895       // type because we're right after it and we don't known its
  1896       // length
  1897       Label do_profile;
  1898       lb(AT, _bcp_register, 0);
  1899       daddiu(AT, AT, -1 * Bytecodes::_invokedynamic);
  1900       beq(AT, R0, do_profile);
  1901       nop();
  1903       lb(AT, _bcp_register, 0);
  1904       daddiu(AT, AT, -1 * Bytecodes::_invokehandle);
  1905       beq(AT, R0, do_profile);
  1906       nop();
  1908       get_method(tmp);
  1909       lb(tmp, tmp, Method::intrinsic_id_offset_in_bytes());
  1910       li(AT, vmIntrinsics::_compiledLambdaForm);
  1911       bne(tmp, AT, profile_continue);
  1912       nop();
  1914       bind(do_profile);
  1917     Address mdo_ret_addr(mdp, -in_bytes(ReturnTypeEntry::size()));
  1918     daddu(tmp, ret, R0);
  1919     profile_obj_type(tmp, mdo_ret_addr);
  1921     bind(profile_continue);
  1925 void InterpreterMacroAssembler::profile_parameters_type(Register mdp, Register tmp1, Register tmp2) {
  1926   guarantee(T9 == tmp1, "You are reqired to use T9 as the index register for MIPS !");
  1928   if (ProfileInterpreter && MethodData::profile_parameters()) {
  1929     Label profile_continue, done;
  1931     test_method_data_pointer(mdp, profile_continue);
  1933     // Load the offset of the area within the MDO used for
  1934     // parameters. If it's negative we're not profiling any parameters
  1935     lw(tmp1, mdp, in_bytes(MethodData::parameters_type_data_di_offset()) - in_bytes(MethodData::data_offset()));
  1936     bltz(tmp1, profile_continue);
  1937     nop();
  1939     // Compute a pointer to the area for parameters from the offset
  1940     // and move the pointer to the slot for the last
  1941     // parameters. Collect profiling from last parameter down.
  1942     // mdo start + parameters offset + array length - 1
  1943     daddu(mdp, mdp, tmp1);
  1944     ld(tmp1, mdp, in_bytes(ArrayData::array_len_offset()));
  1945     decrement(tmp1, TypeStackSlotEntries::per_arg_count());
  1948     Label loop;
  1949     bind(loop);
  1951     int off_base = in_bytes(ParametersTypeData::stack_slot_offset(0));
  1952     int type_base = in_bytes(ParametersTypeData::type_offset(0));
  1953     Address::ScaleFactor per_arg_scale = Address::times(DataLayout::cell_size);
  1954     Address arg_type(mdp, tmp1, per_arg_scale, type_base);
  1956     // load offset on the stack from the slot for this parameter
  1957     dsll(AT, tmp1, per_arg_scale);
  1958     daddu(AT, AT, mdp);
  1959     ld(tmp2, AT, off_base);
  1961     subu(tmp2, R0, tmp2);
  1963     // read the parameter from the local area
  1964     dsll(AT, tmp2, Interpreter::stackElementScale());
  1965     daddu(AT, AT, _locals_register);
  1966     ld(tmp2, AT, 0);
  1968     // profile the parameter
  1969     profile_obj_type(tmp2, arg_type);
  1971     // go to next parameter
  1972     decrement(tmp1, TypeStackSlotEntries::per_arg_count());
  1973     bgtz(tmp1, loop);
  1974     nop();
  1976     bind(profile_continue);
  1980 void InterpreterMacroAssembler::verify_oop(Register reg, TosState state) {
  1981   if (state == atos) {
  1982     MacroAssembler::verify_oop(reg);
  1986 void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) {
  1988 #endif // !CC_INTERP
  1991 void InterpreterMacroAssembler::notify_method_entry() {
  1992   // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
  1993   // track stack depth.  If it is possible to enter interp_only_mode we add
  1994   // the code to check if the event should be sent.
  1995   Register tempreg = T0;
  1996   if (JvmtiExport::can_post_interpreter_events()) {
  1997     Label L;
  1998     get_thread(AT);
  1999     lw(tempreg, AT, in_bytes(JavaThread::interp_only_mode_offset()));
  2000     beq(tempreg, R0, L);
  2001     delayed()->nop();
  2002     call_VM(noreg, CAST_FROM_FN_PTR(address,
  2003                                     InterpreterRuntime::post_method_entry));
  2004     bind(L);
  2008     SkipIfEqual skip_if(this, &DTraceMethodProbes, 0);
  2009     call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry),
  2010                                   //Rthread,
  2011                                   AT,
  2012                                   //Rmethod);
  2013                                   S3);
  2018 void InterpreterMacroAssembler::notify_method_exit(
  2019   //TosState state, NotifyMethodExitMode mode) {
  2020   bool is_native_method, TosState state, NotifyMethodExitMode mode) {
  2021   // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
  2022   // track stack depth.  If it is possible to enter interp_only_mode we add
  2023   // the code to check if the event should be sent.
  2024   Register tempreg = T0;
  2025   if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) {
  2026     Label skip;
  2027     //lw(tempreg, in_bytes(JavaThread::interp_only_mode_offset()), Rthread);
  2028     get_thread(AT);
  2029     lw(tempreg, AT, in_bytes(JavaThread::interp_only_mode_offset()));
  2030     beq(tempreg, R0, skip);
  2031     delayed()->nop();
  2032     // Note: frame::interpreter_frame_result has a dependency on how the
  2033     // method result is saved across the call to post_method_exit. If this
  2034     // is changed then the interpreter_frame_result implementation will
  2035     // need to be updated too.
  2037     // For c++ interpreter the result is always stored at a known location in the frame
  2038     // template interpreter will leave it on the top of the stack.
  2039     save_return_value(state, is_native_method);
  2040     call_VM(noreg,
  2041             CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit));
  2042     restore_return_value(state, is_native_method);
  2043     bind(skip);
  2047     // Dtrace notification
  2048     //SkipIfEqual skip_if(this, tempreg, R0, &DTraceMethodProbes, equal);
  2049     SkipIfEqual skip_if(this, &DTraceMethodProbes, 0);
  2050     save_return_value(state, is_native_method);
  2051     call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),
  2052                  //Rthread, Rmethod);
  2053                  AT, S3);
  2054     restore_return_value(state, is_native_method);
  2058 void InterpreterMacroAssembler::save_return_value(TosState state, bool is_native_call) {
  2059   if (is_native_call) {
  2060     // save any potential method result value
  2061     sw(V0, FP, (-9) * wordSize);
  2062     swc1(F0, FP, (-10) * wordSize);
  2063   } else {
  2064     push(state);
  2068 void InterpreterMacroAssembler::restore_return_value(TosState state, bool is_native_call) {
  2069   if (is_native_call) {
  2070     // Restore any method result value
  2071     lw(V0, FP, (-9) * wordSize);
  2072     lwc1(F0, FP, (-10) * wordSize);
  2073   } else {
  2074     pop(state);

mercurial