src/cpu/mips/vm/interp_masm_mips_64.cpp

Tue, 10 Apr 2018 10:21:49 +0800

author
fujie
date
Tue, 10 Apr 2018 10:21:49 +0800
changeset 8858
e3f4d3592615
parent 7999
b57e01e9f81e
child 8863
5376ce0dc552
permissions
-rw-r--r--

[Upgrade] jdk8u77-b03 --> jdk8u91-b15 (ztos support for MIPS)

     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     get_thread(java_thread);
   194     call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_preserving_args_entry));
   195     delayed()->nop();
   196     jr(V0);
   197     delayed()->nop();
   198     bind(L);
   199     get_thread(java_thread);
   200   }
   201 }
   204 void InterpreterMacroAssembler::load_earlyret_value(TosState state) {
   205   //T8, thread
   206   get_thread(T8);
   207   ld_ptr(T8, T8,in_bytes(JavaThread::jvmti_thread_state_offset()));
   208   const Address tos_addr (T8, in_bytes(JvmtiThreadState::earlyret_tos_offset()));
   209   const Address oop_addr (T8, in_bytes(JvmtiThreadState::earlyret_oop_offset()));
   210   const Address val_addr (T8, in_bytes(JvmtiThreadState::earlyret_value_offset()));
   211   //V0, oop_addr,V1,val_addr
   212   switch (state) {
   213     case atos:
   214       ld_ptr(V0, oop_addr);
   215       st_ptr(R0, oop_addr);
   216       verify_oop(V0, state);
   217       break;
   218     case ltos:
   219       ld_ptr(V0, val_addr);               // fall through
   220       break;
   221     case btos:                                     // fall through
   222     case ztos:                                     // fall through
   223     case ctos:                                     // fall through
   224     case stos:                                     // fall through
   225     case itos:
   226       lw(V0, val_addr);
   227       break;
   228     case ftos:
   229       lwc1(F0,T8, in_bytes(JvmtiThreadState::earlyret_value_offset()));
   230       break;
   231     case dtos:
   232       ldc1(F0,T8, in_bytes(JvmtiThreadState::earlyret_value_offset()));
   233       break;
   234     case vtos: /* nothing to do */                    break;
   235     default  : ShouldNotReachHere();
   236   }
   237   // Clean up tos value in the thread object
   238   move(AT, (int)ilgl);
   239   sw(AT, tos_addr);
   240   sw(R0,T8, in_bytes(JvmtiThreadState::earlyret_value_offset()));
   241 }
   244 void InterpreterMacroAssembler::check_and_handle_earlyret(Register java_thread) {
   245   if (JvmtiExport::can_force_early_return()) {
   246     Label L;
   247     Register tmp = T9;
   249     ld_ptr(AT,java_thread, in_bytes(JavaThread::jvmti_thread_state_offset()));
   250     beq(AT,R0,L);
   251     delayed()->nop();
   253     // Initiate earlyret handling only if it is not already being processed.
   254     // If the flag has the earlyret_processing bit set, it means that this code
   255     // is called *during* earlyret handling - we don't want to reenter.
   256     lw(AT, AT, in_bytes(JvmtiThreadState::earlyret_state_offset()));
   257     move(tmp, JvmtiThreadState::earlyret_pending);
   258     bne(tmp, AT, L);
   259     delayed()->nop();
   260     get_thread(java_thread);
   262     // Call Interpreter::remove_activation_early_entry() to get the address of the
   263     // same-named entrypoint in the generated interpreter code.
   264     ld_ptr(tmp,java_thread, in_bytes(JavaThread::jvmti_thread_state_offset()));
   265     lw(AT,tmp, in_bytes(JvmtiThreadState::earlyret_tos_offset()));
   266     move(A0, AT);
   267     call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry), A0);
   268     jr(V0);
   269     delayed()->nop();
   270     bind(L);
   271     get_thread(java_thread);
   272   }
   273 }
   276 void InterpreterMacroAssembler::get_unsigned_2_byte_index_at_bcp(Register reg,
   277                                                                  int bcp_offset) {
   278   assert(bcp_offset >= 0, "bcp is still pointing to start of bytecode");
   279   lbu(AT, BCP, bcp_offset);
   280   lbu(reg, BCP, bcp_offset + 1);
   281   ins(reg, AT, 8, 8);
   282 }
   285 void InterpreterMacroAssembler::get_cache_index_at_bcp(Register index,
   286                                                        int bcp_offset,
   287                                                        size_t index_size) {
   288   assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");
   289   if (index_size == sizeof(u2)) {
   290     get_2_byte_integer_at_bcp(index, AT, bcp_offset);
   291   } else if (index_size == sizeof(u4)) {
   292     assert(EnableInvokeDynamic, "giant index used only for JSR 292");
   293     get_4_byte_integer_at_bcp(index, AT, bcp_offset);
   294     // Check if the secondary index definition is still ~x, otherwise
   295     // we have to change the following assembler code to calculate the
   296     // plain index.
   297     assert(ConstantPool::decode_invokedynamic_index(~123) == 123, "else change next line");
   298     nor(index, index, R0);
   299     sll(index, index, 0);
   300   } else if (index_size == sizeof(u1)) {
   301     lbu(index, BCP, bcp_offset);
   302   } else {
   303     ShouldNotReachHere();
   304   }
   305 }
   308 void InterpreterMacroAssembler::get_cache_and_index_at_bcp(Register cache,
   309                                                            Register index,
   310                                                            int bcp_offset,
   311                                                            size_t index_size) {
   312   assert_different_registers(cache, index);
   313   get_cache_index_at_bcp(index, bcp_offset, index_size);
   314   ld(cache, FP, frame::interpreter_frame_cache_offset * wordSize);
   315   assert(sizeof(ConstantPoolCacheEntry) == 4 * wordSize, "adjust code below");
   316   assert(exact_log2(in_words(ConstantPoolCacheEntry::size())) == 2, "else change next line");
   317   shl(index, 2);
   318 }
   321 void InterpreterMacroAssembler::get_cache_and_index_and_bytecode_at_bcp(Register cache,
   322                                                                         Register index,
   323                                                                         Register bytecode,
   324                                                                         int byte_no,
   325                                                                         int bcp_offset,
   326                                                                         size_t index_size) {
   327   get_cache_and_index_at_bcp(cache, index, bcp_offset, index_size);
   328   // We use a 32-bit load here since the layout of 64-bit words on
   329   // little-endian machines allow us that.
   330   dsll(AT, index, Address::times_ptr);
   331   dadd(AT, cache, AT);
   332   lw(bytecode, AT, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::indices_offset()));
   334   const int shift_count = (1 + byte_no) * BitsPerByte;
   335   assert((byte_no == TemplateTable::f1_byte && shift_count == ConstantPoolCacheEntry::bytecode_1_shift) ||
   336          (byte_no == TemplateTable::f2_byte && shift_count == ConstantPoolCacheEntry::bytecode_2_shift),
   337          "correct shift count");
   338   dsrl(bytecode, bytecode, shift_count);
   339   assert(ConstantPoolCacheEntry::bytecode_1_mask == ConstantPoolCacheEntry::bytecode_2_mask, "common mask");
   340   move(AT, ConstantPoolCacheEntry::bytecode_1_mask);
   341   andr(bytecode, bytecode, AT);
   342 }
   344 void InterpreterMacroAssembler::get_cache_entry_pointer_at_bcp(Register cache,
   345                                                                Register tmp,
   346                                                                int bcp_offset,
   347                                                                size_t index_size) {
   348   assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");
   349   assert(cache != tmp, "must use different register");
   350   get_cache_index_at_bcp(tmp, bcp_offset, index_size);
   351   assert(sizeof(ConstantPoolCacheEntry) == 4 * wordSize, "adjust code below");
   352   // convert from field index to ConstantPoolCacheEntry index
   353   // and from word offset to byte offset
   354   assert(exact_log2(in_bytes(ConstantPoolCacheEntry::size_in_bytes())) == 2 + LogBytesPerWord, "else change next line");
   355   shl(tmp, 2 + LogBytesPerWord);
   356   ld(cache, FP, frame::interpreter_frame_cache_offset * wordSize);
   357   // skip past the header
   358   daddi(cache, cache, in_bytes(ConstantPoolCache::base_offset()));
   359   dadd(cache, cache, tmp);
   360 }
   362 void InterpreterMacroAssembler::get_method_counters(Register method,
   363                                                     Register mcs, Label& skip) {
   364   Label has_counters;
   365   ld(mcs, method, in_bytes(Method::method_counters_offset()));
   366   bne(mcs, R0, has_counters);
   367   nop();
   368   call_VM(noreg, CAST_FROM_FN_PTR(address,
   369           InterpreterRuntime::build_method_counters), method);
   370   ld(mcs, method, in_bytes(Method::method_counters_offset()));
   371   beq(mcs, R0, skip);   // No MethodCounters allocated, OutOfMemory
   372   nop();
   373   bind(has_counters);
   374 }
   376 // Load object from cpool->resolved_references(index)
   377 void InterpreterMacroAssembler::load_resolved_reference_at_index(
   378                                            Register result, Register index) {
   379   assert_different_registers(result, index);
   380   // convert from field index to resolved_references() index and from
   381   // word index to byte offset. Since this is a java object, it can be compressed
   382   Register tmp = index;  // reuse
   383   shl(tmp, LogBytesPerHeapOop);
   385   get_constant_pool(result);
   386   // load pointer for resolved_references[] objArray
   387   ld(result, result, ConstantPool::resolved_references_offset_in_bytes());
   388   // JNIHandles::resolve(obj);
   389   ld(result, result, 0); //? is needed?
   390   // Add in the index
   391   dadd(result, result, tmp);
   392   load_heap_oop(result, Address(result, arrayOopDesc::base_offset_in_bytes(T_OBJECT)));
   393 }
   395 // Resets LVP to locals.  Register sub_klass cannot be any of the above.
   396 void InterpreterMacroAssembler::gen_subtype_check( Register Rsup_klass, Register Rsub_klass, Label &ok_is_subtype ) {
   397   assert( Rsub_klass != Rsup_klass, "Rsup_klass holds superklass" );
   398   assert( Rsub_klass != T1, "T1 holds 2ndary super array length" );
   399   assert( Rsub_klass != T0, "T0 holds 2ndary super array scan ptr" );
   400   // Profile the not-null value's klass.
   401   // [20130904] Fu: Here T9 and T1 are used as temporary registers.
   402   profile_typecheck(T9, Rsub_klass, T1); // blows rcx, reloads rdi
   404 // Do the check.
   405   check_klass_subtype(Rsub_klass, Rsup_klass, T1, ok_is_subtype); // blows rcx
   407 // Profile the failure of the check.
   408   profile_typecheck_failed(T9); // blows rcx
   409 }
   413 // Java Expression Stack
   415 void InterpreterMacroAssembler::pop_ptr(Register r) {
   416   ld(r, SP, 0);
   417   daddiu(SP, SP, Interpreter::stackElementSize);
   418 }
   420 void InterpreterMacroAssembler::pop_i(Register r) {
   421   lw(r, SP, 0);
   422   daddiu(SP, SP, Interpreter::stackElementSize);
   423 }
   425 void InterpreterMacroAssembler::pop_l(Register r) {
   426   ld(r, SP, 0);
   427   daddiu(SP, SP, 2 * Interpreter::stackElementSize);
   428 }
   430 void InterpreterMacroAssembler::pop_f(FloatRegister r) {
   431   lwc1(r, SP, 0);
   432   daddiu(SP, SP, Interpreter::stackElementSize);
   433 }
   435 void InterpreterMacroAssembler::pop_d(FloatRegister r) {
   436   ldc1(r, SP, 0);
   437   daddiu(SP, SP, 2 * Interpreter::stackElementSize);
   438 }
   440 void InterpreterMacroAssembler::push_ptr(Register r) {
   441   sd(r, SP, - Interpreter::stackElementSize);
   442   daddiu(SP, SP, - Interpreter::stackElementSize);
   443 }
   445 void InterpreterMacroAssembler::push_i(Register r) {
   446   // 20170925: For compatibility reason, don't change to sw.
   447   sd(r, SP, - Interpreter::stackElementSize);
   448   daddiu(SP, SP, - Interpreter::stackElementSize);
   449 }
   451 void InterpreterMacroAssembler::push_l(Register r) {
   452   sd(r, SP, -2 * Interpreter::stackElementSize);
   453   daddiu(SP, SP, -2 * Interpreter::stackElementSize);
   454 }
   456 void InterpreterMacroAssembler::push_f(FloatRegister r) {
   457   swc1(r, SP, - Interpreter::stackElementSize);
   458   daddiu(SP, SP, - Interpreter::stackElementSize);
   459 }
   461 void InterpreterMacroAssembler::push_d(FloatRegister r) {
   462   sdc1(r, SP, -2 * Interpreter::stackElementSize);
   463   daddiu(SP, SP, -2 * Interpreter::stackElementSize);
   464 }
   466 void InterpreterMacroAssembler::pop(TosState state) {
   467   switch (state) {
   468     case atos: pop_ptr();           break;
   469     case btos:
   470     case ztos:
   471     case ctos:
   472     case stos:
   473     case itos: pop_i();             break;
   474     case ltos: pop_l();             break;
   475     case ftos: pop_f();             break;
   476     case dtos: pop_d();             break;
   477     case vtos: /* nothing to do */  break;
   478     default:   ShouldNotReachHere();
   479   }
   480   verify_oop(FSR, state);
   481 }
   483 //FSR=V0,SSR=V1
   484 void InterpreterMacroAssembler::push(TosState state) {
   485   verify_oop(FSR, state);
   486   switch (state) {
   487     case atos: push_ptr();          break;
   488     case btos:
   489     case ztos:
   490     case ctos:
   491     case stos:
   492     case itos: push_i();            break;
   493     case ltos: push_l();            break;
   494     case ftos: push_f();            break;
   495     case dtos: push_d();            break;
   496     case vtos: /* nothing to do */  break;
   497     default  : ShouldNotReachHere();
   498   }
   499 }
   503 void InterpreterMacroAssembler::load_ptr(int n, Register val) {
   504   ld(val, SP, Interpreter::expr_offset_in_bytes(n));
   505 }
   507 void InterpreterMacroAssembler::store_ptr(int n, Register val) {
   508   sd(val, SP, Interpreter::expr_offset_in_bytes(n));
   509 }
   511 // Jump to from_interpreted entry of a call unless single stepping is possible
   512 // in this thread in which case we must call the i2i entry
   513 void InterpreterMacroAssembler::jump_from_interpreted(Register method, Register temp) {
   514   // record last_sp
   515   move(Rsender, SP);
   516   sd(SP, FP, frame::interpreter_frame_last_sp_offset * wordSize);
   518   if (JvmtiExport::can_post_interpreter_events()) {
   519     Label run_compiled_code;
   520     // JVMTI events, such as single-stepping, are implemented partly by avoiding running
   521     // compiled code in threads for which the event is enabled.  Check here for
   522     // interp_only_mode if these events CAN be enabled.
   523 #ifndef OPT_THREAD
   524     get_thread(temp);
   525 #else
   526     move(temp, TREG);
   527 #endif
   528     // interp_only is an int, on little endian it is sufficient to test the byte only
   529     // Is a cmpl faster?
   530     lw(AT, temp, in_bytes(JavaThread::interp_only_mode_offset()));
   531     beq(AT, R0, run_compiled_code);
   532     delayed()->nop();
   533     ld(AT, method, in_bytes(Method::interpreter_entry_offset()));
   534     jr(AT);
   535     delayed()->nop();
   536     bind(run_compiled_code);
   537   }
   539   ld(AT, method, in_bytes(Method::from_interpreted_offset()));
   540   jr(AT);
   541   delayed()->nop();
   542 }
   545 // The following two routines provide a hook so that an implementation
   546 // can schedule the dispatch in two parts.  amd64 does not do this.
   547 void InterpreterMacroAssembler::dispatch_prolog(TosState state, int step) {
   548   // Nothing amd64 specific to be done here
   549 }
   551 void InterpreterMacroAssembler::dispatch_epilog(TosState state, int step) {
   552   dispatch_next(state, step);
   553 }
   555 // assume the next bytecode in T8.
   556 void InterpreterMacroAssembler::dispatch_base(TosState state,
   557                                               address* table,
   558                                               bool verifyoop) {
   559   if (VerifyActivationFrameSize) {
   560     Label L;
   562     dsub(T2, FP, SP);
   563     int min_frame_size = (frame::link_offset -
   564       frame::interpreter_frame_initial_sp_offset) * wordSize;
   565     daddi(T2, T2,- min_frame_size);
   566     bgez(T2, L);
   567     delayed()->nop();
   568     stop("broken stack frame");
   569     bind(L);
   570   }
   571   // FIXME: I do not know which register should pass to verify_oop
   572   if (verifyoop) verify_oop(FSR, state);
   573   dsll(T2, Rnext, LogBytesPerWord);
   575   if((long)table >= (long)Interpreter::dispatch_table(btos) &&
   576      (long)table <= (long)Interpreter::dispatch_table(vtos)
   577     ) {
   578      int table_size = (long)Interpreter::dispatch_table(itos) - (long)Interpreter::dispatch_table(stos);
   579      int table_offset = ((int)state - (int)itos) * table_size;
   581      // 2013/12/17 Fu: GP points to the starting address of Interpreter::dispatch_table(itos).
   582      // See StubGenerator::generate_call_stub(address& return_address) for the initialization of GP.
   583      if(table_offset != 0) {
   584         daddiu(T3, GP, table_offset);
   585         if (UseLoongsonISA) {
   586           gsldx(T3, T2, T3, 0);
   587         } else {
   588           daddu(T3, T2, T3);
   589           ld(T3, T3, 0);
   590         }
   591      } else {
   592         if (UseLoongsonISA) {
   593           gsldx(T3, T2, GP, 0);
   594         } else {
   595           daddu(T3, T2, GP);
   596           ld(T3, T3, 0);
   597         }
   598      }
   599   } else {
   600      li(T3, (long)table);
   601      if (UseLoongsonISA) {
   602        gsldx(T3, T2, T3, 0);
   603      } else {
   604        daddu(T3, T2, T3);
   605        ld(T3, T3, 0);
   606      }
   607   }
   608   jr(T3);
   609   delayed()->nop();
   610 }
   612 void InterpreterMacroAssembler::dispatch_only(TosState state) {
   613   dispatch_base(state, Interpreter::dispatch_table(state));
   614 }
   616 void InterpreterMacroAssembler::dispatch_only_normal(TosState state) {
   617   dispatch_base(state, Interpreter::normal_table(state));
   618 }
   620 void InterpreterMacroAssembler::dispatch_only_noverify(TosState state) {
   621   dispatch_base(state, Interpreter::normal_table(state), false);
   622 }
   625 void InterpreterMacroAssembler::dispatch_next(TosState state, int step) {
   626   // load next bytecode (load before advancing r13 to prevent AGI)
   627   lbu(Rnext, BCP, step);
   628   increment(BCP, step);
   629   dispatch_base(state, Interpreter::dispatch_table(state));
   630 }
   632 void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) {
   633   // load current bytecode
   634   lbu(Rnext, BCP, 0);
   635   dispatch_base(state, table);
   636 }
   638 // remove activation
   639 //
   640 // Unlock the receiver if this is a synchronized method.
   641 // Unlock any Java monitors from syncronized blocks.
   642 // Remove the activation from the stack.
   643 //
   644 // If there are locked Java monitors
   645 //    If throw_monitor_exception
   646 //       throws IllegalMonitorStateException
   647 //    Else if install_monitor_exception
   648 //       installs IllegalMonitorStateException
   649 //    Else
   650 //       no error processing
   651 // used registers : T1, T2, T3, T8
   652 // T1 : thread, method access flags
   653 // T2 : monitor entry pointer
   654 // T3 : method, monitor top
   655 // T8 : unlock flag
   656 void InterpreterMacroAssembler::remove_activation(
   657         TosState state,
   658         Register ret_addr,
   659         bool throw_monitor_exception,
   660         bool install_monitor_exception,
   661   bool notify_jvmdi) {
   662   // Note: Registers V0, V1 and F0, F1 may be in use for the result
   663   // check if synchronized method
   664   Label unlocked, unlock, no_unlock;
   666   // get the value of _do_not_unlock_if_synchronized into T8
   667 #ifndef OPT_THREAD
   668   Register thread = T1;
   669   get_thread(thread);
   670 #else
   671   Register thread = TREG;
   672 #endif
   673   lb(T8, thread, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
   674   // reset the flag
   675   sb(R0, thread, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
   676   // get method access flags
   677   ld(T3, FP, frame::interpreter_frame_method_offset * wordSize);
   678   lw(T1, T3, in_bytes(Method::access_flags_offset()));
   679   andi(T1, T1, JVM_ACC_SYNCHRONIZED);
   680   beq(T1, R0, unlocked);
   681   delayed()->nop();
   683   // Don't unlock anything if the _do_not_unlock_if_synchronized flag is set.
   684   bne(T8, R0, no_unlock);
   685   delayed()->nop();
   686   // unlock monitor
   687   push(state); // save result
   689   // BasicObjectLock will be first in list, since this is a
   690   // synchronized method. However, need to check that the object has
   691   // not been unlocked by an explicit monitorexit bytecode.
   692   daddiu(c_rarg0, FP, frame::interpreter_frame_initial_sp_offset * wordSize
   693       - (int)sizeof(BasicObjectLock));
   694   // address of first monitor
   695   lw(T1, c_rarg0, BasicObjectLock::obj_offset_in_bytes());
   696   bne(T1, R0, unlock);
   697   delayed()->nop();
   698   pop(state);
   699   if (throw_monitor_exception) {
   700     // Entry already unlocked, need to throw exception
   701     // I think mips do not need empty_FPU_stack
   702     // remove possible return value from FPU-stack, otherwise stack could overflow
   703     empty_FPU_stack();
   704     call_VM(NOREG, CAST_FROM_FN_PTR(address,
   705     InterpreterRuntime::throw_illegal_monitor_state_exception));
   706     should_not_reach_here();
   707   } else {
   708     // Monitor already unlocked during a stack unroll. If requested,
   709     // install an illegal_monitor_state_exception.  Continue with
   710     // stack unrolling.
   711     if (install_monitor_exception) {
   712       // remove possible return value from FPU-stack,
   713       // otherwise stack could overflow
   714       empty_FPU_stack();
   715       call_VM(NOREG, CAST_FROM_FN_PTR(address,
   716       InterpreterRuntime::new_illegal_monitor_state_exception));
   718     }
   720     b(unlocked);
   721     delayed()->nop();
   722   }
   724   bind(unlock);
   725   unlock_object(c_rarg0);
   726   pop(state);
   728   // Check that for block-structured locking (i.e., that all locked
   729   // objects has been unlocked)
   730   bind(unlocked);
   732   // V0, V1: Might contain return value
   734   // Check that all monitors are unlocked
   735   {
   736     Label loop, exception, entry, restart;
   737     const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
   738     const Address monitor_block_top(FP,
   739         frame::interpreter_frame_monitor_block_top_offset * wordSize);
   741     bind(restart);
   742     // points to current entry, starting with top-most entry (ecx)
   743     ld(c_rarg0, monitor_block_top);
   744     // points to word before bottom of monitor block (ebx)
   745     daddiu(T3, FP, frame::interpreter_frame_initial_sp_offset * wordSize);
   746     b(entry);
   747     delayed()->nop();
   749     // Entry already locked, need to throw exception
   750     bind(exception);
   752     if (throw_monitor_exception) {
   753       // Throw exception
   754       // remove possible return value from FPU-stack,
   755       // otherwise stack could overflow
   756       empty_FPU_stack();
   757       MacroAssembler::call_VM(NOREG, CAST_FROM_FN_PTR(address,
   758                               InterpreterRuntime::throw_illegal_monitor_state_exception));
   759       should_not_reach_here();
   760     } else {
   761       // Stack unrolling. Unlock object and install illegal_monitor_exception
   762       // Unlock does not block, so don't have to worry about the frame
   763       // We don't have to preserve eax, edx since we are going to
   764       // throw an exception
   765       unlock_object(c_rarg0);
   766       if (install_monitor_exception) {
   767         empty_FPU_stack();
   768         call_VM(NOREG, CAST_FROM_FN_PTR(address,
   769                                         InterpreterRuntime::new_illegal_monitor_state_exception));
   770       }
   772       b(restart);
   773       delayed()->nop();
   774     }
   776     bind(loop);
   777     ld(T1, c_rarg0, BasicObjectLock::obj_offset_in_bytes());
   778     bne(T1, R0, exception);// check if current entry is used
   779     delayed()->nop();
   781     daddiu(c_rarg0, c_rarg0, entry_size);// otherwise advance to next entry
   782     bind(entry);
   783     bne(c_rarg0, T3, loop);  // check if bottom reached
   784     delayed()->nop();  // if not at bottom then check this entry
   785   }
   787   bind(no_unlock);
   789   // jvmpi support (jvmdi does not generate MethodExit on exception / popFrame)
   790   if (notify_jvmdi) {
   791     notify_method_exit(false,state,NotifyJVMTI);    // preserve TOSCA
   792   } else {
   793     notify_method_exit(false,state,SkipNotifyJVMTI);// preserve TOSCA
   794   }
   796   // remove activation
   797   ld(SP, FP, frame::interpreter_frame_sender_sp_offset * wordSize);
   798   ld(ret_addr, FP, frame::interpreter_frame_return_addr_offset * wordSize);
   799   ld(FP, FP, frame::interpreter_frame_sender_fp_offset * wordSize);
   800 }
   802 #endif // C_INTERP
   804 // Lock object
   805 //
   806 // Args:
   807 //      c_rarg1: BasicObjectLock to be used for locking
   808 //
   809 // Kills:
   810 //      rax
   811 //      c_rarg0, c_rarg1, c_rarg2, c_rarg3, .. (param regs)
   812 //      rscratch1, rscratch2 (scratch regs)
   813 void InterpreterMacroAssembler::lock_object(Register lock_reg) {
   814   assert(lock_reg == c_rarg0, "The argument is only for looks. It must be c_rarg0");
   816   if (UseHeavyMonitors) {
   817     call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
   818             lock_reg);
   819   } else {
   820     Label done;
   822     const Register swap_reg = T2;  // Must use eax for cmpxchg instruction
   823     const Register obj_reg  = T1;  // Will contain the oop
   825     const int obj_offset = BasicObjectLock::obj_offset_in_bytes();
   826     const int lock_offset = BasicObjectLock::lock_offset_in_bytes ();
   827     const int mark_offset = lock_offset +
   828                             BasicLock::displaced_header_offset_in_bytes();
   830     Label slow_case;
   832     // Load object pointer into obj_reg %ecx
   833     ld(obj_reg, lock_reg, obj_offset);
   835     if (UseBiasedLocking) {
   836       // Note: we use noreg for the temporary register since it's hard
   837       // to come up with a free register on all incoming code paths
   838       biased_locking_enter(lock_reg, obj_reg, swap_reg, noreg, false, done, &slow_case);
   839     }
   842     // Load (object->mark() | 1) into swap_reg %eax
   843     ld(AT, obj_reg, 0);
   844     ori(swap_reg, AT, 1);
   847     // Save (object->mark() | 1) into BasicLock's displaced header
   848     sd(swap_reg, lock_reg, mark_offset);
   850     assert(lock_offset == 0, "displached header must be first word in BasicObjectLock");
   851     //if (os::is_MP()) {
   852       //  lock();
   853     //}
   854     cmpxchg(lock_reg, Address(obj_reg, 0), swap_reg);
   856     if (PrintBiasedLockingStatistics) {
   857       Label L;
   858       beq(AT, R0, L);
   859       delayed()->nop();
   860       push(T0);
   861       push(T1);
   862       atomic_inc32((address)BiasedLocking::fast_path_entry_count_addr(), 1, T0, T1);
   863       pop(T1);
   864       pop(T0);
   865       bind(L);
   866     }
   868     bne(AT, R0, done);
   869     delayed()->nop();
   871     // Test if the oopMark is an obvious stack pointer, i.e.,
   872     //  1) (mark & 3) == 0, and
   873     //  2) SP <= mark < SP + os::pagesize()
   874     //
   875     // These 3 tests can be done by evaluating the following
   876     // expression: ((mark - esp) & (3 - os::vm_page_size())),
   877     // assuming both stack pointer and pagesize have their
   878     // least significant 2 bits clear.
   879     // NOTE: the oopMark is in swap_reg %eax as the result of cmpxchg
   881     dsub(swap_reg, swap_reg, SP);
   882     move(AT, 3 - os::vm_page_size());
   883     andr(swap_reg, swap_reg, AT);
   884     // Save the test result, for recursive case, the result is zero
   885     sd(swap_reg, lock_reg, mark_offset);
   886     if (PrintBiasedLockingStatistics) {
   887       Label L;
   888       bne(swap_reg, R0, L);
   889       delayed()->nop();
   890       push(T0);
   891       push(T1);
   892       atomic_inc32((address)BiasedLocking::fast_path_entry_count_addr(), 1, T0, T1);
   893       pop(T1);
   894       pop(T0);
   895       bind(L);
   896     }
   898     beq(swap_reg, R0, done);
   899     delayed()->nop();
   900     bind(slow_case);
   901     // Call the runtime routine for slow case
   902     call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), lock_reg);
   904     bind(done);
   905   }
   906 }
   909 // Unlocks an object. Used in monitorexit bytecode and
   910 // remove_activation.  Throws an IllegalMonitorException if object is
   911 // not locked by current thread.
   912 //
   913 // Args:
   914 //      c_rarg1: BasicObjectLock for lock
   915 //
   916 // Kills:
   917 //      rax
   918 //      c_rarg0, c_rarg1, c_rarg2, c_rarg3, ... (param regs)
   919 //      rscratch1, rscratch2 (scratch regs)
   920 // Argument: T6 : Points to BasicObjectLock structure for lock
   921 // Argument: c_rarg0 : Points to BasicObjectLock structure for lock
   922 // Throw an IllegalMonitorException if object is not locked by current thread
   923 void InterpreterMacroAssembler::unlock_object(Register lock_reg) {
   924   assert(lock_reg == c_rarg0, "The argument is only for looks. It must be c_rarg0");
   926   if (UseHeavyMonitors) {
   927     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg);
   928   } else {
   929     Label done;
   931     const Register swap_reg   = T2;  // Must use eax for cmpxchg instruction
   932     const Register header_reg = T3;  // Will contain the old oopMark
   933     const Register obj_reg    = T1;  // Will contain the oop
   935     save_bcp(); // Save in case of exception
   937     // Convert from BasicObjectLock structure to object and BasicLock structure
   938     // Store the BasicLock address into %eax
   939     daddi(swap_reg, lock_reg, BasicObjectLock::lock_offset_in_bytes());
   941     // Load oop into obj_reg(%ecx)
   942     ld(obj_reg, lock_reg, BasicObjectLock::obj_offset_in_bytes ());
   943     //free entry
   944     sd(R0, lock_reg, BasicObjectLock::obj_offset_in_bytes());
   945     if (UseBiasedLocking) {
   946       biased_locking_exit(obj_reg, header_reg, done);
   947     }
   949     // Load the old header from BasicLock structure
   950     ld(header_reg, swap_reg, BasicLock::displaced_header_offset_in_bytes());
   951     // zero for recursive case
   952     beq(header_reg, R0, done);
   953     delayed()->nop();
   955     // Atomic swap back the old header
   956     if (os::is_MP()); //lock();
   957     cmpxchg(header_reg, Address(obj_reg, 0), swap_reg);
   959     // zero for recursive case
   960     bne(AT, R0, done);
   961     delayed()->nop();
   963     // Call the runtime routine for slow case.
   964     sd(obj_reg, lock_reg, BasicObjectLock::obj_offset_in_bytes()); // restore obj
   965     call_VM(NOREG,
   966             CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit),
   967             lock_reg);
   969     bind(done);
   971     restore_bcp();
   972   }
   973 }
   975 #ifndef CC_INTERP
   977 void InterpreterMacroAssembler::test_method_data_pointer(Register mdp,
   978                                                          Label& zero_continue) {
   979   assert(ProfileInterpreter, "must be profiling interpreter");
   980   ld(mdp, Address(FP, frame::interpreter_frame_mdx_offset * wordSize));
   981   beq(mdp, R0, zero_continue);
   982   delayed()->nop();
   983 }
   986 // Set the method data pointer for the current bcp.
   987 void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() {
   988   assert(ProfileInterpreter, "must be profiling interpreter");
   989   Label set_mdp;
   991   // V0 and T0 will be used as two temporary registers.
   992   sd(V0, SP, (-1) * wordSize);
   993   sd(T0, SP, (-2) * wordSize);
   994   daddiu(SP, SP, (-2) * wordSize);
   996   get_method(T0);
   997   // Test MDO to avoid the call if it is NULL.
   998   ld(V0, T0, in_bytes(Method::method_data_offset()));
   999   beq(V0, R0, set_mdp);
  1000   delayed()->nop();
  1002   // method: T0
  1003   // bcp: BCP --> S0
  1004   call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), T0, BCP);
  1005   // mdi: V0
  1006   // mdo is guaranteed to be non-zero here, we checked for it before the call.
  1007   get_method(T0);
  1008   ld(T0, T0, in_bytes(Method::method_data_offset()));
  1009   daddiu(T0, T0, in_bytes(MethodData::data_offset()));
  1010   daddu(V0, T0, V0);
  1011   bind(set_mdp);
  1012   sd(V0, FP, frame::interpreter_frame_mdx_offset * wordSize);
  1013   daddiu(SP, SP, 2 * wordSize);
  1014   ld(V0, SP, (-1) * wordSize);
  1015   ld(T0, SP, (-2) * wordSize);
  1018 void InterpreterMacroAssembler::verify_method_data_pointer() {
  1019   assert(ProfileInterpreter, "must be profiling interpreter");
  1020 #ifdef ASSERT
  1021   Label verify_continue;
  1022   Register method = V0;
  1023   Register mdp = V1;
  1024   Register tmp = A0;
  1025   push(method);
  1026   push(mdp);
  1027   push(tmp);
  1028   test_method_data_pointer(mdp, verify_continue); // If mdp is zero, continue
  1029   get_method(method);
  1031   // If the mdp is valid, it will point to a DataLayout header which is
  1032   // consistent with the bcp.  The converse is highly probable also.
  1033   lhu(tmp, mdp, in_bytes(DataLayout::bci_offset()));
  1034   ld(AT, method, in_bytes(Method::const_offset()));
  1035   daddu(tmp, tmp, AT);
  1036   daddiu(tmp, tmp, in_bytes(ConstMethod::codes_offset()));
  1037   beq(tmp, BCP, verify_continue);
  1038   nop();
  1039   call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp), method, BCP, mdp);
  1040   bind(verify_continue);
  1041   pop(tmp);
  1042   pop(mdp);
  1043   pop(method);
  1044 #endif // ASSERT
  1048 void InterpreterMacroAssembler::set_mdp_data_at(Register mdp_in,
  1049                                                 int constant,
  1050                                                 Register value) {
  1051   assert(ProfileInterpreter, "must be profiling interpreter");
  1052   Address data(mdp_in, constant);
  1053   sd(value, data);
  1057 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
  1058                                                       int constant,
  1059                                                       bool decrement) {
  1060   // Counter address
  1061   Address data(mdp_in, constant);
  1063   increment_mdp_data_at(data, decrement);
  1066 void InterpreterMacroAssembler::increment_mdp_data_at(Address data,
  1067                                                       bool decrement) {
  1068   assert(ProfileInterpreter, "must be profiling interpreter");
  1069   // %%% this does 64bit counters at best it is wasting space
  1070   // at worst it is a rare bug when counters overflow
  1071   Register tmp = S0;
  1072   push(tmp);
  1073   if (decrement) {
  1074     // Decrement the register.
  1075     ld(AT, data);
  1076     daddiu(tmp, AT, (int32_t) -DataLayout::counter_increment);
  1077     // If the decrement causes the counter to overflow, stay negative
  1078     Label L;
  1079     slt(AT, tmp, R0);
  1080     bne(AT, R0, L);
  1081     nop();
  1082     daddi(tmp, tmp, (int32_t) DataLayout::counter_increment);
  1083     bind(L);
  1084     sd(tmp, data);
  1085   } else {
  1086     assert(DataLayout::counter_increment == 1,
  1087            "flow-free idiom only works with 1");
  1088     ld(AT, data);
  1089     // Increment the register.
  1090     daddiu(tmp, AT, DataLayout::counter_increment);
  1091     // If the increment causes the counter to overflow, pull back by 1.
  1092     slt(AT, tmp, R0);
  1093     dsubu(tmp, tmp, AT);
  1094     sd(tmp, data);
  1096   pop(tmp);
  1100 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
  1101                                                       Register reg,
  1102                                                       int constant,
  1103                                                       bool decrement) {
  1104   Register tmp = S0;
  1105   push(S0);
  1106   if (decrement) {
  1107     // Decrement the register.
  1108     daddu(AT, mdp_in, reg);
  1109     assert(Assembler::is_simm16(constant), "constant is not a simm16 !");
  1110     ld(AT, AT, constant);
  1112     daddiu(tmp, AT, (int32_t) -DataLayout::counter_increment);
  1113     // If the decrement causes the counter to overflow, stay negative
  1114     Label L;
  1115     slt(AT, tmp, R0);
  1116     bne(AT, R0, L);
  1117     nop();
  1118     daddi(tmp, tmp, (int32_t) DataLayout::counter_increment);
  1119     bind(L);
  1121     daddu(AT, mdp_in, reg);
  1122     sd(tmp, AT, constant);
  1123   } else {
  1124     daddu(AT, mdp_in, reg);
  1125     assert(Assembler::is_simm16(constant), "constant is not a simm16 !");
  1126     ld(AT, AT, constant);
  1128     // Increment the register.
  1129     daddiu(tmp, AT, DataLayout::counter_increment);
  1130     // If the increment causes the counter to overflow, pull back by 1.
  1131     slt(AT, tmp, R0);
  1132     dsubu(tmp, tmp, AT);
  1134     daddu(AT, mdp_in, reg);
  1135     sd(tmp, AT, constant);
  1137   pop(S0);
  1140 void InterpreterMacroAssembler::set_mdp_flag_at(Register mdp_in,
  1141                                                 int flag_byte_constant) {
  1142   assert(ProfileInterpreter, "must be profiling interpreter");
  1143   int header_offset = in_bytes(DataLayout::header_offset());
  1144   int header_bits = DataLayout::flag_mask_to_header_mask(flag_byte_constant);
  1145   // Set the flag
  1146   lw(AT, Address(mdp_in, header_offset));
  1147   if(Assembler::is_simm16(header_bits)) {
  1148     ori(AT, AT, header_bits);
  1149   } else {
  1150     push(T8);
  1151     // T8 is used as a temporary register.
  1152     move(T8, header_bits);
  1153     orr(AT, AT, T8);
  1154     pop(T8);
  1156   sw(AT, Address(mdp_in, header_offset));
  1161 void InterpreterMacroAssembler::test_mdp_data_at(Register mdp_in,
  1162                                                  int offset,
  1163                                                  Register value,
  1164                                                  Register test_value_out,
  1165                                                  Label& not_equal_continue) {
  1166   assert(ProfileInterpreter, "must be profiling interpreter");
  1167   if (test_value_out == noreg) {
  1168     ld(AT, Address(mdp_in, offset));
  1169     bne(AT, value, not_equal_continue);
  1170     nop();
  1171   } else {
  1172     // Put the test value into a register, so caller can use it:
  1173     ld(test_value_out, Address(mdp_in, offset));
  1174     bne(value, test_value_out, not_equal_continue);
  1175     nop();
  1180 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,
  1181                                                      int offset_of_disp) {
  1182   assert(ProfileInterpreter, "must be profiling interpreter");
  1183   assert(Assembler::is_simm16(offset_of_disp), "offset is not an simm16");
  1184   ld(AT, mdp_in, offset_of_disp);
  1185   daddu(mdp_in, mdp_in, AT);
  1186   sd(mdp_in, Address(FP, frame::interpreter_frame_mdx_offset * wordSize));
  1190 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,
  1191                                                      Register reg,
  1192                                                      int offset_of_disp) {
  1193   assert(ProfileInterpreter, "must be profiling interpreter");
  1194 //  Attention: Until now (20121217), we do not support this kind of addressing on Loongson.
  1195 //  Address disp_address(mdp_in, reg, Address::times_1, offset_of_disp);
  1196   daddu(AT, reg, mdp_in);
  1197   assert(Assembler::is_simm16(offset_of_disp), "offset is not an simm16");
  1198   ld(AT, AT, offset_of_disp);
  1199   daddu(mdp_in, mdp_in, AT);
  1200   sd(mdp_in, Address(FP, frame::interpreter_frame_mdx_offset * wordSize));
  1204 void InterpreterMacroAssembler::update_mdp_by_constant(Register mdp_in,
  1205                                                        int constant) {
  1206   assert(ProfileInterpreter, "must be profiling interpreter");
  1207   if(Assembler::is_simm16(constant)) {
  1208     daddiu(mdp_in, mdp_in, constant);
  1209   } else {
  1210     move(AT, constant);
  1211     daddu(mdp_in, mdp_in, AT);
  1213   sd(mdp_in, Address(FP, frame::interpreter_frame_mdx_offset * wordSize));
  1217 void InterpreterMacroAssembler::update_mdp_for_ret(Register return_bci) {
  1218   assert(ProfileInterpreter, "must be profiling interpreter");
  1219   push(return_bci); // save/restore across call_VM
  1220   call_VM(noreg,
  1221           CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret),
  1222           return_bci);
  1223   pop(return_bci);
  1227 void InterpreterMacroAssembler::profile_taken_branch(Register mdp,
  1228                                                      Register bumped_count) {
  1229   if (ProfileInterpreter) {
  1230     Label profile_continue;
  1232     // If no method data exists, go to profile_continue.
  1233     // Otherwise, assign to mdp
  1234     test_method_data_pointer(mdp, profile_continue);
  1236     // We are taking a branch.  Increment the taken count.
  1237     // We inline increment_mdp_data_at to return bumped_count in a register
  1238     //increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset()));
  1239     ld(bumped_count, mdp, in_bytes(JumpData::taken_offset()));
  1240     assert(DataLayout::counter_increment == 1,
  1241            "flow-free idiom only works with 1");
  1242     push(T8);
  1243     // T8 is used as a temporary register.
  1244     daddiu(T8, bumped_count, DataLayout::counter_increment);
  1245     slt(AT, T8, R0);
  1246     dsubu(bumped_count, T8, AT);
  1247     pop(T8);
  1248     sd(bumped_count, mdp, in_bytes(JumpData::taken_offset())); // Store back out
  1249     // The method data pointer needs to be updated to reflect the new target.
  1250     update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset()));
  1251     bind(profile_continue);
  1256 void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp) {
  1257   if (ProfileInterpreter) {
  1258     Label profile_continue;
  1260     // If no method data exists, go to profile_continue.
  1261     test_method_data_pointer(mdp, profile_continue);
  1263     // We are taking a branch.  Increment the not taken count.
  1264     increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset()));
  1266     // The method data pointer needs to be updated to correspond to
  1267     // the next bytecode
  1268     update_mdp_by_constant(mdp, in_bytes(BranchData::branch_data_size()));
  1269     bind(profile_continue);
  1274 void InterpreterMacroAssembler::profile_call(Register mdp) {
  1275   if (ProfileInterpreter) {
  1276     Label profile_continue;
  1278     // If no method data exists, go to profile_continue.
  1279     test_method_data_pointer(mdp, profile_continue);
  1281     // We are making a call.  Increment the count.
  1282     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1284     // The method data pointer needs to be updated to reflect the new target.
  1285     update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size()));
  1286     bind(profile_continue);
  1291 void InterpreterMacroAssembler::profile_final_call(Register mdp) {
  1292   if (ProfileInterpreter) {
  1293     Label profile_continue;
  1295     // If no method data exists, go to profile_continue.
  1296     test_method_data_pointer(mdp, profile_continue);
  1298     // We are making a call.  Increment the count.
  1299     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1301     // The method data pointer needs to be updated to reflect the new target.
  1302     update_mdp_by_constant(mdp,
  1303                            in_bytes(VirtualCallData::
  1304                                     virtual_call_data_size()));
  1305     bind(profile_continue);
  1310 void InterpreterMacroAssembler::profile_virtual_call(Register receiver,
  1311                                                      Register mdp,
  1312                                                      Register reg2,
  1313                                                      bool receiver_can_be_null) {
  1314   if (ProfileInterpreter) {
  1315     Label profile_continue;
  1317     // If no method data exists, go to profile_continue.
  1318     test_method_data_pointer(mdp, profile_continue);
  1320     Label skip_receiver_profile;
  1321     if (receiver_can_be_null) {
  1322       Label not_null;
  1323       bne(receiver, R0, not_null);
  1324       nop();
  1325       // We are making a call.  Increment the count.
  1326       increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1327       beq(R0, R0, skip_receiver_profile);
  1328       nop();
  1329       bind(not_null);
  1332     // Record the receiver type.
  1333     record_klass_in_profile(receiver, mdp, reg2, true);
  1334     bind(skip_receiver_profile);
  1336     // The method data pointer needs to be updated to reflect the new target.
  1337     update_mdp_by_constant(mdp,
  1338                            in_bytes(VirtualCallData::
  1339                                     virtual_call_data_size()));
  1340     bind(profile_continue);
  1344 // This routine creates a state machine for updating the multi-row
  1345 // type profile at a virtual call site (or other type-sensitive bytecode).
  1346 // The machine visits each row (of receiver/count) until the receiver type
  1347 // is found, or until it runs out of rows.  At the same time, it remembers
  1348 // the location of the first empty row.  (An empty row records null for its
  1349 // receiver, and can be allocated for a newly-observed receiver type.)
  1350 // Because there are two degrees of freedom in the state, a simple linear
  1351 // search will not work; it must be a decision tree.  Hence this helper
  1352 // function is recursive, to generate the required tree structured code.
  1353 // It's the interpreter, so we are trading off code space for speed.
  1354 // See below for example code.
  1355 void InterpreterMacroAssembler::record_klass_in_profile_helper(
  1356                                         Register receiver, Register mdp,
  1357                                         Register reg2, int start_row,
  1358                                         Label& done, bool is_virtual_call) {
  1359   if (TypeProfileWidth == 0) {
  1360     if (is_virtual_call) {
  1361       increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1363     return;
  1366   int last_row = VirtualCallData::row_limit() - 1;
  1367   assert(start_row <= last_row, "must be work left to do");
  1368   // Test this row for both the receiver and for null.
  1369   // Take any of three different outcomes:
  1370   //   1. found receiver => increment count and goto done
  1371   //   2. found null => keep looking for case 1, maybe allocate this cell
  1372   //   3. found something else => keep looking for cases 1 and 2
  1373   // Case 3 is handled by a recursive call.
  1374   for (int row = start_row; row <= last_row; row++) {
  1375     Label next_test;
  1376     bool test_for_null_also = (row == start_row);
  1378     // See if the receiver is receiver[n].
  1379     int recvr_offset = in_bytes(VirtualCallData::receiver_offset(row));
  1380     test_mdp_data_at(mdp, recvr_offset, receiver,
  1381                      (test_for_null_also ? reg2 : noreg),
  1382                      next_test);
  1383     // (Reg2 now contains the receiver from the CallData.)
  1385     // The receiver is receiver[n].  Increment count[n].
  1386     int count_offset = in_bytes(VirtualCallData::receiver_count_offset(row));
  1387     increment_mdp_data_at(mdp, count_offset);
  1388     beq(R0, R0, done);
  1389     nop();
  1390     bind(next_test);
  1392     if (test_for_null_also) {
  1393       Label found_null;
  1394       // Failed the equality check on receiver[n]...  Test for null.
  1395       if (start_row == last_row) {
  1396         // The only thing left to do is handle the null case.
  1397         if (is_virtual_call) {
  1398           beq(reg2, R0, found_null);
  1399           nop();
  1400           // Receiver did not match any saved receiver and there is no empty row for it.
  1401           // Increment total counter to indicate polymorphic case.
  1402           increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1403           beq(R0, R0, done);
  1404           nop();
  1405           bind(found_null);
  1406         } else {
  1407           bne(reg2, R0, done);
  1408           nop();
  1410         break;
  1412       // Since null is rare, make it be the branch-taken case.
  1413       beq(reg2, R0, found_null);
  1414       nop();
  1416       // Put all the "Case 3" tests here.
  1417       record_klass_in_profile_helper(receiver, mdp, reg2, start_row + 1, done, is_virtual_call);
  1419       // Found a null.  Keep searching for a matching receiver,
  1420       // but remember that this is an empty (unused) slot.
  1421       bind(found_null);
  1425   // In the fall-through case, we found no matching receiver, but we
  1426   // observed the receiver[start_row] is NULL.
  1428   // Fill in the receiver field and increment the count.
  1429   int recvr_offset = in_bytes(VirtualCallData::receiver_offset(start_row));
  1430   set_mdp_data_at(mdp, recvr_offset, receiver);
  1431   int count_offset = in_bytes(VirtualCallData::receiver_count_offset(start_row));
  1432   move(reg2, DataLayout::counter_increment);
  1433   set_mdp_data_at(mdp, count_offset, reg2);
  1434   if (start_row > 0) {
  1435     beq(R0, R0, done);
  1436     nop();
  1440 // Example state machine code for three profile rows:
  1441 //   // main copy of decision tree, rooted at row[1]
  1442 //   if (row[0].rec == rec) { row[0].incr(); goto done; }
  1443 //   if (row[0].rec != NULL) {
  1444 //     // inner copy of decision tree, rooted at row[1]
  1445 //     if (row[1].rec == rec) { row[1].incr(); goto done; }
  1446 //     if (row[1].rec != NULL) {
  1447 //       // degenerate decision tree, rooted at row[2]
  1448 //       if (row[2].rec == rec) { row[2].incr(); goto done; }
  1449 //       if (row[2].rec != NULL) { goto done; } // overflow
  1450 //       row[2].init(rec); goto done;
  1451 //     } else {
  1452 //       // remember row[1] is empty
  1453 //       if (row[2].rec == rec) { row[2].incr(); goto done; }
  1454 //       row[1].init(rec); goto done;
  1455 //     }
  1456 //   } else {
  1457 //     // remember row[0] is empty
  1458 //     if (row[1].rec == rec) { row[1].incr(); goto done; }
  1459 //     if (row[2].rec == rec) { row[2].incr(); goto done; }
  1460 //     row[0].init(rec); goto done;
  1461 //   }
  1462 //   done:
  1464 void InterpreterMacroAssembler::record_klass_in_profile(Register receiver,
  1465                                                         Register mdp, Register reg2,
  1466                                                         bool is_virtual_call) {
  1467   assert(ProfileInterpreter, "must be profiling");
  1468   Label done;
  1470   record_klass_in_profile_helper(receiver, mdp, reg2, 0, done, is_virtual_call);
  1472   bind (done);
  1475 void InterpreterMacroAssembler::profile_ret(Register return_bci,
  1476                                             Register mdp) {
  1477   if (ProfileInterpreter) {
  1478     Label profile_continue;
  1479     uint row;
  1481     // If no method data exists, go to profile_continue.
  1482     test_method_data_pointer(mdp, profile_continue);
  1484     // Update the total ret count.
  1485     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1487     for (row = 0; row < RetData::row_limit(); row++) {
  1488       Label next_test;
  1490       // See if return_bci is equal to bci[n]:
  1491       test_mdp_data_at(mdp,
  1492                        in_bytes(RetData::bci_offset(row)),
  1493                        return_bci, noreg,
  1494                        next_test);
  1496       // return_bci is equal to bci[n].  Increment the count.
  1497       increment_mdp_data_at(mdp, in_bytes(RetData::bci_count_offset(row)));
  1499       // The method data pointer needs to be updated to reflect the new target.
  1500       update_mdp_by_offset(mdp,
  1501                            in_bytes(RetData::bci_displacement_offset(row)));
  1502       beq(R0, R0, profile_continue);
  1503       nop();
  1504       bind(next_test);
  1507     update_mdp_for_ret(return_bci);
  1509     bind(profile_continue);
  1514 void InterpreterMacroAssembler::profile_null_seen(Register mdp) {
  1515   if (ProfileInterpreter) {
  1516     Label profile_continue;
  1518     // If no method data exists, go to profile_continue.
  1519     test_method_data_pointer(mdp, profile_continue);
  1521     set_mdp_flag_at(mdp, BitData::null_seen_byte_constant());
  1523     // The method data pointer needs to be updated.
  1524     int mdp_delta = in_bytes(BitData::bit_data_size());
  1525     if (TypeProfileCasts) {
  1526       mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
  1528     update_mdp_by_constant(mdp, mdp_delta);
  1530     bind(profile_continue);
  1535 void InterpreterMacroAssembler::profile_typecheck_failed(Register mdp) {
  1536   if (ProfileInterpreter && TypeProfileCasts) {
  1537     Label profile_continue;
  1539     // If no method data exists, go to profile_continue.
  1540     test_method_data_pointer(mdp, profile_continue);
  1542     int count_offset = in_bytes(CounterData::count_offset());
  1543     // Back up the address, since we have already bumped the mdp.
  1544     count_offset -= in_bytes(VirtualCallData::virtual_call_data_size());
  1546     // *Decrement* the counter.  We expect to see zero or small negatives.
  1547     increment_mdp_data_at(mdp, count_offset, true);
  1549     bind (profile_continue);
  1554 void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2) {
  1555   if (ProfileInterpreter) {
  1556     Label profile_continue;
  1558     // If no method data exists, go to profile_continue.
  1559     test_method_data_pointer(mdp, profile_continue);
  1561     // The method data pointer needs to be updated.
  1562     int mdp_delta = in_bytes(BitData::bit_data_size());
  1563     if (TypeProfileCasts) {
  1564       mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
  1566       // Record the object type.
  1567       record_klass_in_profile(klass, mdp, reg2, false);
  1569     update_mdp_by_constant(mdp, mdp_delta);
  1571     bind(profile_continue);
  1576 void InterpreterMacroAssembler::profile_switch_default(Register mdp) {
  1577   if (ProfileInterpreter) {
  1578     Label profile_continue;
  1580     // If no method data exists, go to profile_continue.
  1581     test_method_data_pointer(mdp, profile_continue);
  1583     // Update the default case count
  1584     increment_mdp_data_at(mdp,
  1585                           in_bytes(MultiBranchData::default_count_offset()));
  1587     // The method data pointer needs to be updated.
  1588     update_mdp_by_offset(mdp,
  1589                          in_bytes(MultiBranchData::
  1590                                   default_displacement_offset()));
  1592     bind(profile_continue);
  1597 void InterpreterMacroAssembler::profile_switch_case(Register index,
  1598                                                     Register mdp,
  1599                                                     Register reg2) {
  1600   if (ProfileInterpreter) {
  1601     Label profile_continue;
  1603     // If no method data exists, go to profile_continue.
  1604     test_method_data_pointer(mdp, profile_continue);
  1606     // Build the base (index * per_case_size_in_bytes()) +
  1607     // case_array_offset_in_bytes()
  1608     move(reg2, in_bytes(MultiBranchData::per_case_size()));
  1609     if (UseLoongsonISA) {
  1610       gsdmult(index, index, reg2);
  1611     } else {
  1612       dmult(index, reg2);
  1613       mflo(index);
  1615     daddiu(index, index, in_bytes(MultiBranchData::case_array_offset()));
  1617     // Update the case count
  1618     increment_mdp_data_at(mdp,
  1619                           index,
  1620                           in_bytes(MultiBranchData::relative_count_offset()));
  1622     // The method data pointer needs to be updated.
  1623     update_mdp_by_offset(mdp,
  1624                          index,
  1625                          in_bytes(MultiBranchData::
  1626                                   relative_displacement_offset()));
  1628     bind(profile_continue);
  1633 void InterpreterMacroAssembler::narrow(Register result) {
  1635   // Get method->_constMethod->_result_type
  1636   ld(T9, FP, frame::interpreter_frame_method_offset * wordSize);
  1637   ld(T9, T9, in_bytes(Method::const_offset()));
  1638   lbu(T9, T9, in_bytes(ConstMethod::result_type_offset()));
  1640   Label done, notBool, notByte, notChar;
  1642   // common case first
  1643   addiu(AT, T9, -T_INT);
  1644   beq(AT, R0, done);
  1645   nop();
  1647   // mask integer result to narrower return type.
  1648   addiu(AT, T9, -T_BOOLEAN);
  1649   bne(AT, R0, notBool);
  1650   nop();
  1651   andi(result, result, 0x1);
  1652   beq(R0, R0, done);
  1653   nop();
  1655   bind(notBool);
  1656   addiu(AT, T9, -T_BYTE);
  1657   bne(AT, R0, notByte);
  1658   nop();
  1659   seb(result, result);
  1660   beq(R0, R0, done);
  1661   nop();
  1663   bind(notByte);
  1664   addiu(AT, T9, -T_CHAR);
  1665   bne(AT, R0, notChar);
  1666   nop();
  1667   andi(result, result, 0xFFFF);
  1668   beq(R0, R0, done);
  1669   nop();
  1671   bind(notChar);
  1672   seh(result, result);
  1674   // Nothing to do for T_INT
  1675   bind(done);
  1679 void InterpreterMacroAssembler::profile_obj_type(Register obj, const Address& mdo_addr) {
  1680   Label update, next, none;
  1682   verify_oop(obj);
  1684   bne(obj, R0, update);
  1685   nop();
  1687   push(T1);
  1688   if (mdo_addr.index() == noreg) {
  1689     ld(T1, mdo_addr);
  1690   } else {
  1691     guarantee(T1 != mdo_addr.base(), "The base register will be corrupted !");
  1692     guarantee(T1 != mdo_addr.index(), "The index register will be corrupted !");
  1694     dsll(AT, mdo_addr.index(), mdo_addr.scale());
  1695     daddu(AT, AT, mdo_addr.base());
  1696     ld(T1, AT, mdo_addr.disp());
  1698   li(AT, TypeEntries::null_seen);
  1699   orr(AT, T1, AT);
  1700   if (mdo_addr.index() == noreg) {
  1701     sd(AT, mdo_addr);
  1702   } else {
  1703     guarantee(T1 != mdo_addr.base(), "The base register will be corrupted !");
  1704     guarantee(T1 != mdo_addr.index(), "The index register will be corrupted !");
  1706     dsll(T1, mdo_addr.index(), mdo_addr.scale());
  1707     daddu(T1, T1, mdo_addr.base());
  1708     sd(AT, T1, mdo_addr.disp());
  1710   pop(T1);
  1712   beq(R0, R0, next);
  1713   nop();
  1715   bind(update);
  1716   load_klass(obj, obj);
  1718   if (mdo_addr.index() == noreg) {
  1719     ld(AT, mdo_addr);
  1720   } else {
  1721     dsll(AT, mdo_addr.index(), mdo_addr.scale());
  1722     daddu(AT, AT, mdo_addr.base());
  1723     ld(AT, AT, mdo_addr.disp());
  1725   xorr(obj, obj, AT);
  1727   li(AT, TypeEntries::type_klass_mask);
  1728   andr(AT, obj, AT);
  1729   beq(AT, R0, next);
  1730   nop();
  1732   li(AT, TypeEntries::type_unknown);
  1733   andr(AT, AT, obj);
  1734   bne(AT, R0, next);
  1735   nop();
  1737   if (mdo_addr.index() == noreg) {
  1738     ld(AT, mdo_addr);
  1739   } else {
  1740     dsll(AT, mdo_addr.index(), mdo_addr.scale());
  1741     daddu(AT, AT, mdo_addr.base());
  1742     ld(AT, AT, mdo_addr.disp());
  1744   beq(AT, R0, none);
  1745   nop();
  1748   push(T1);
  1749   if (mdo_addr.index() == noreg) {
  1750     ld(T1, mdo_addr);
  1751   } else {
  1752     guarantee(T1 != mdo_addr.base(), "The base register will be corrupted !");
  1753     guarantee(T1 != mdo_addr.index(), "The index register will be corrupted !");
  1755     dsll(AT, mdo_addr.index(), mdo_addr.scale());
  1756     daddu(AT, AT, mdo_addr.base());
  1757     ld(T1, AT, mdo_addr.disp());
  1759   li(AT, TypeEntries::null_seen);
  1760   subu(AT, AT, T1);
  1761   pop(T1);
  1762   beq(AT, R0, none);
  1763   nop();
  1765   // There is a chance that the checks above (re-reading profiling
  1766   // data from memory) fail if another thread has just set the
  1767   // profiling to this obj's klass
  1768   if (mdo_addr.index() == noreg) {
  1769     ld(AT, mdo_addr);
  1770   } else {
  1771     dsll(AT, mdo_addr.index(), mdo_addr.scale());
  1772     daddu(AT, AT, mdo_addr.base());
  1773     ld(AT, AT, mdo_addr.disp());
  1775   xorr(obj, obj, AT);
  1776   li(AT, TypeEntries::type_klass_mask);
  1777   andr(AT, obj, AT);
  1778   beq(AT, R0, next);
  1779   nop();
  1781   // different than before. Cannot keep accurate profile.
  1782   push(T1);
  1783   if (mdo_addr.index() == noreg) {
  1784     ld(T1, mdo_addr);
  1785   } else {
  1786     guarantee(T1 != mdo_addr.base(), "The base register will be corrupted !");
  1787     guarantee(T1 != mdo_addr.index(), "The index register will be corrupted !");
  1789     dsll(AT, mdo_addr.index(), mdo_addr.scale());
  1790     daddu(AT, AT, mdo_addr.base());
  1791     ld(T1, AT, mdo_addr.disp());
  1793   li(AT, TypeEntries::type_unknown);
  1794   orr(AT, T1, AT);
  1795   if (mdo_addr.index() == noreg) {
  1796     sd(AT, mdo_addr);
  1797   } else {
  1798     guarantee(T1 != mdo_addr.base(), "The base register will be corrupted !");
  1799     guarantee(T1 != mdo_addr.index(), "The index register will be corrupted !");
  1801     dsll(T1, mdo_addr.index(), mdo_addr.scale());
  1802     daddu(T1, T1, mdo_addr.base());
  1803     sd(AT, T1, mdo_addr.disp());
  1805   pop(T1);
  1806   beq(R0, R0, next);
  1807   nop();
  1810   bind(none);
  1811   // first time here. Set profile type.
  1812   if (mdo_addr.index() == noreg) {
  1813     sd(obj, mdo_addr);
  1814   } else {
  1815     dsll(AT, mdo_addr.index(), mdo_addr.scale());
  1816     daddu(AT, AT, mdo_addr.base());
  1817     sd(obj, AT, mdo_addr.disp());
  1820   bind(next);
  1823 void InterpreterMacroAssembler::profile_arguments_type(Register mdp, Register callee, Register tmp, bool is_virtual) {
  1824   if (!ProfileInterpreter) {
  1825     return;
  1828   if (MethodData::profile_arguments() || MethodData::profile_return()) {
  1829     Label profile_continue;
  1831     test_method_data_pointer(mdp, profile_continue);
  1833     int off_to_start = is_virtual ? in_bytes(VirtualCallData::virtual_call_data_size()) : in_bytes(CounterData::counter_data_size());
  1835     lb(AT, mdp, in_bytes(DataLayout::tag_offset()) - off_to_start);
  1836     li(tmp, is_virtual ? DataLayout::virtual_call_type_data_tag : DataLayout::call_type_data_tag);
  1837     bne(tmp, AT, profile_continue);
  1838     nop();
  1841     if (MethodData::profile_arguments()) {
  1842       Label done;
  1843       int off_to_args = in_bytes(TypeEntriesAtCall::args_data_offset());
  1844       if (Assembler::is_simm16(off_to_args)) {
  1845         daddiu(mdp, mdp, off_to_args);
  1846       } else {
  1847         move(AT, off_to_args);
  1848         daddu(mdp, mdp, AT);
  1852       for (int i = 0; i < TypeProfileArgsLimit; i++) {
  1853         if (i > 0 || MethodData::profile_return()) {
  1854           // If return value type is profiled we may have no argument to profile
  1855           ld(tmp, mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args);
  1857           if (Assembler::is_simm16(-1 * i * TypeStackSlotEntries::per_arg_count())) {
  1858             addiu32(tmp, tmp, -1 * i * TypeStackSlotEntries::per_arg_count());
  1859           } else {
  1860             li(AT, i*TypeStackSlotEntries::per_arg_count());
  1861             subu32(tmp, tmp, AT);
  1864           li(AT, TypeStackSlotEntries::per_arg_count());
  1865           slt(AT, tmp, AT);
  1866           bne(AT, R0, done);
  1867           nop();
  1869         ld(tmp, callee, in_bytes(Method::const_offset()));
  1871         lhu(tmp, tmp, in_bytes(ConstMethod::size_of_parameters_offset()));
  1873         // stack offset o (zero based) from the start of the argument
  1874         // list, for n arguments translates into offset n - o - 1 from
  1875         // the end of the argument list
  1876         ld(AT, mdp, in_bytes(TypeEntriesAtCall::stack_slot_offset(i))-off_to_args);
  1877         subu(tmp, tmp, AT);
  1879         addiu32(tmp, tmp, -1);
  1881         Address arg_addr = argument_address(tmp);
  1882         ld(tmp, arg_addr);
  1884         Address mdo_arg_addr(mdp, in_bytes(TypeEntriesAtCall::argument_type_offset(i))-off_to_args);
  1885         profile_obj_type(tmp, mdo_arg_addr);
  1887         int to_add = in_bytes(TypeStackSlotEntries::per_arg_size());
  1888         if (Assembler::is_simm16(to_add)) {
  1889           daddiu(mdp, mdp, to_add);
  1890         } else {
  1891           move(AT, to_add);
  1892           daddu(mdp, mdp, AT);
  1895         off_to_args += to_add;
  1898       if (MethodData::profile_return()) {
  1899         ld(tmp, mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args);
  1901         int tmp_arg_counts = TypeProfileArgsLimit*TypeStackSlotEntries::per_arg_count();
  1902         if (Assembler::is_simm16(-1 * tmp_arg_counts)) {
  1903           addiu32(tmp, tmp, -1 * tmp_arg_counts);
  1904         } else {
  1905           move(AT, tmp_arg_counts);
  1906           subu32(mdp, mdp, AT);
  1910       bind(done);
  1912       if (MethodData::profile_return()) {
  1913         // We're right after the type profile for the last
  1914         // argument. tmp is the number of cells left in the
  1915         // CallTypeData/VirtualCallTypeData to reach its end. Non null
  1916         // if there's a return to profile.
  1917         assert(ReturnTypeEntry::static_cell_count() < TypeStackSlotEntries::per_arg_count(), "can't move past ret type");
  1918         sll(tmp, tmp, exact_log2(DataLayout::cell_size));
  1919         daddu(mdp, mdp, tmp);
  1921       sd(mdp, FP, frame::interpreter_frame_mdx_offset * wordSize);
  1922     } else {
  1923       assert(MethodData::profile_return(), "either profile call args or call ret");
  1924       update_mdp_by_constant(mdp, in_bytes(TypeEntriesAtCall::return_only_size()));
  1927     // mdp points right after the end of the
  1928     // CallTypeData/VirtualCallTypeData, right after the cells for the
  1929     // return value type if there's one
  1931     bind(profile_continue);
  1935 void InterpreterMacroAssembler::profile_return_type(Register mdp, Register ret, Register tmp) {
  1936   assert_different_registers(mdp, ret, tmp, _bcp_register);
  1937   if (ProfileInterpreter && MethodData::profile_return()) {
  1938     Label profile_continue, done;
  1940     test_method_data_pointer(mdp, profile_continue);
  1942     if (MethodData::profile_return_jsr292_only()) {
  1943       // If we don't profile all invoke bytecodes we must make sure
  1944       // it's a bytecode we indeed profile. We can't go back to the
  1945       // begining of the ProfileData we intend to update to check its
  1946       // type because we're right after it and we don't known its
  1947       // length
  1948       Label do_profile;
  1949       lb(AT, _bcp_register, 0);
  1950       daddiu(AT, AT, -1 * Bytecodes::_invokedynamic);
  1951       beq(AT, R0, do_profile);
  1952       nop();
  1954       lb(AT, _bcp_register, 0);
  1955       daddiu(AT, AT, -1 * Bytecodes::_invokehandle);
  1956       beq(AT, R0, do_profile);
  1957       nop();
  1959       get_method(tmp);
  1960       lb(tmp, tmp, Method::intrinsic_id_offset_in_bytes());
  1961       li(AT, vmIntrinsics::_compiledLambdaForm);
  1962       bne(tmp, AT, profile_continue);
  1963       nop();
  1965       bind(do_profile);
  1968     Address mdo_ret_addr(mdp, -in_bytes(ReturnTypeEntry::size()));
  1969     daddu(tmp, ret, R0);
  1970     profile_obj_type(tmp, mdo_ret_addr);
  1972     bind(profile_continue);
  1976 void InterpreterMacroAssembler::profile_parameters_type(Register mdp, Register tmp1, Register tmp2) {
  1977   guarantee(T9 == tmp1, "You are reqired to use T9 as the index register for MIPS !");
  1979   if (ProfileInterpreter && MethodData::profile_parameters()) {
  1980     Label profile_continue, done;
  1982     test_method_data_pointer(mdp, profile_continue);
  1984     // Load the offset of the area within the MDO used for
  1985     // parameters. If it's negative we're not profiling any parameters
  1986     lw(tmp1, mdp, in_bytes(MethodData::parameters_type_data_di_offset()) - in_bytes(MethodData::data_offset()));
  1987     bltz(tmp1, profile_continue);
  1988     nop();
  1990     // Compute a pointer to the area for parameters from the offset
  1991     // and move the pointer to the slot for the last
  1992     // parameters. Collect profiling from last parameter down.
  1993     // mdo start + parameters offset + array length - 1
  1994     daddu(mdp, mdp, tmp1);
  1995     ld(tmp1, mdp, in_bytes(ArrayData::array_len_offset()));
  1996     decrement(tmp1, TypeStackSlotEntries::per_arg_count());
  1999     Label loop;
  2000     bind(loop);
  2002     int off_base = in_bytes(ParametersTypeData::stack_slot_offset(0));
  2003     int type_base = in_bytes(ParametersTypeData::type_offset(0));
  2004     Address::ScaleFactor per_arg_scale = Address::times(DataLayout::cell_size);
  2005     Address arg_type(mdp, tmp1, per_arg_scale, type_base);
  2007     // load offset on the stack from the slot for this parameter
  2008     dsll(AT, tmp1, per_arg_scale);
  2009     daddu(AT, AT, mdp);
  2010     ld(tmp2, AT, off_base);
  2012     subu(tmp2, R0, tmp2);
  2014     // read the parameter from the local area
  2015     dsll(AT, tmp2, Interpreter::stackElementScale());
  2016     daddu(AT, AT, _locals_register);
  2017     ld(tmp2, AT, 0);
  2019     // profile the parameter
  2020     profile_obj_type(tmp2, arg_type);
  2022     // go to next parameter
  2023     decrement(tmp1, TypeStackSlotEntries::per_arg_count());
  2024     bgtz(tmp1, loop);
  2025     nop();
  2027     bind(profile_continue);
  2031 void InterpreterMacroAssembler::verify_oop(Register reg, TosState state) {
  2032   if (state == atos) {
  2033     MacroAssembler::verify_oop(reg);
  2037 void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) {
  2039 #endif // !CC_INTERP
  2042 void InterpreterMacroAssembler::notify_method_entry() {
  2043   // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
  2044   // track stack depth.  If it is possible to enter interp_only_mode we add
  2045   // the code to check if the event should be sent.
  2046   Register tempreg = T0;
  2047   if (JvmtiExport::can_post_interpreter_events()) {
  2048     Label L;
  2049     get_thread(AT);
  2050     lw(tempreg, AT, in_bytes(JavaThread::interp_only_mode_offset()));
  2051     beq(tempreg, R0, L);
  2052     delayed()->nop();
  2053     call_VM(noreg, CAST_FROM_FN_PTR(address,
  2054                                     InterpreterRuntime::post_method_entry));
  2055     bind(L);
  2059     SkipIfEqual skip_if(this, &DTraceMethodProbes, 0);
  2060     call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry),
  2061                                   //Rthread,
  2062                                   AT,
  2063                                   //Rmethod);
  2064                                   S3);
  2069 void InterpreterMacroAssembler::notify_method_exit(
  2070   //TosState state, NotifyMethodExitMode mode) {
  2071   bool is_native_method, TosState state, NotifyMethodExitMode mode) {
  2072   // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
  2073   // track stack depth.  If it is possible to enter interp_only_mode we add
  2074   // the code to check if the event should be sent.
  2075   Register tempreg = T0;
  2076   if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) {
  2077     Label skip;
  2078     //lw(tempreg, in_bytes(JavaThread::interp_only_mode_offset()), Rthread);
  2079     get_thread(AT);
  2080     lw(tempreg, AT, in_bytes(JavaThread::interp_only_mode_offset()));
  2081     beq(tempreg, R0, skip);
  2082     delayed()->nop();
  2083     // Note: frame::interpreter_frame_result has a dependency on how the
  2084     // method result is saved across the call to post_method_exit. If this
  2085     // is changed then the interpreter_frame_result implementation will
  2086     // need to be updated too.
  2088     // For c++ interpreter the result is always stored at a known location in the frame
  2089     // template interpreter will leave it on the top of the stack.
  2090     save_return_value(state, is_native_method);
  2091     call_VM(noreg,
  2092             CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit));
  2093     restore_return_value(state, is_native_method);
  2094     bind(skip);
  2098     // Dtrace notification
  2099     //SkipIfEqual skip_if(this, tempreg, R0, &DTraceMethodProbes, equal);
  2100     SkipIfEqual skip_if(this, &DTraceMethodProbes, 0);
  2101     save_return_value(state, is_native_method);
  2102     call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),
  2103                  //Rthread, Rmethod);
  2104                  AT, S3);
  2105     restore_return_value(state, is_native_method);
  2109 void InterpreterMacroAssembler::save_return_value(TosState state, bool is_native_call) {
  2110   if (is_native_call) {
  2111     // save any potential method result value
  2112     sw(V0, FP, (-9) * wordSize);
  2113     swc1(F0, FP, (-10) * wordSize);
  2114   } else {
  2115     push(state);
  2119 void InterpreterMacroAssembler::restore_return_value(TosState state, bool is_native_call) {
  2120   if (is_native_call) {
  2121     // Restore any method result value
  2122     lw(V0, FP, (-9) * wordSize);
  2123     lwc1(F0, FP, (-10) * wordSize);
  2124   } else {
  2125     pop(state);

mercurial