src/cpu/mips/vm/templateInterpreter_mips_64.cpp

Tue, 10 Jul 2018 14:18:39 +0800

author
fujie
date
Tue, 10 Jul 2018 14:18:39 +0800
changeset 9160
b6ac0b9d8b02
parent 9144
cecfc245b19a
child 9171
c67c94f5b85d
permissions
-rw-r--r--

#7243 Fix an incorrect stack alignment assert in the interpreter

# Internal Error (/home/loongson/aoqi/jdk8-mips/hotspot/src/os_cpu/linux_mips/vm/os_linux_mips.cpp:1006), pid=15645, tid=0x000000fff3f071f0
# assert(((intptr_t)os::current_stack_pointer() & (StackAlignmentInBytes-1)) == 0) failed: incorrect stack alignment

     1 /*
     2  * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * Copyright (c) 2015, 2018, 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 "asm/macroAssembler.hpp"
    28 #include "interpreter/bytecodeHistogram.hpp"
    29 #include "interpreter/interpreter.hpp"
    30 #include "interpreter/interpreterGenerator.hpp"
    31 #include "interpreter/interpreterRuntime.hpp"
    32 #include "interpreter/templateTable.hpp"
    33 #include "oops/arrayOop.hpp"
    34 #include "oops/methodData.hpp"
    35 #include "oops/method.hpp"
    36 #include "oops/oop.inline.hpp"
    37 #include "prims/jvmtiExport.hpp"
    38 #include "prims/jvmtiThreadState.hpp"
    39 #include "runtime/arguments.hpp"
    40 #include "runtime/deoptimization.hpp"
    41 #include "runtime/frame.inline.hpp"
    42 #include "runtime/sharedRuntime.hpp"
    43 #include "runtime/stubRoutines.hpp"
    44 #include "runtime/synchronizer.hpp"
    45 #include "runtime/timer.hpp"
    46 #include "runtime/vframeArray.hpp"
    47 #include "utilities/debug.hpp"
    49 #define __ _masm->
    51 #ifndef CC_INTERP
    53 // asm based interpreter deoptimization helpers
    54 int AbstractInterpreter::size_activation(int max_stack,
    55                                          int temps,
    56                                          int extra_args,
    57                                          int monitors,
    58                                          int callee_params,
    59                                          int callee_locals,
    60                                          bool is_top_frame) {
    61   // Note: This calculation must exactly parallel the frame setup
    62   // in AbstractInterpreterGenerator::generate_method_entry.
    64   // fixed size of an interpreter frame:
    65   int overhead = frame::sender_sp_offset -
    66                  frame::interpreter_frame_initial_sp_offset;
    67   // Our locals were accounted for by the caller (or last_frame_adjust
    68   // on the transistion) Since the callee parameters already account
    69   // for the callee's params we only need to account for the extra
    70   // locals.
    71   int size = overhead +
    72          (callee_locals - callee_params)*Interpreter::stackElementWords +
    73          monitors * frame::interpreter_frame_monitor_size() +
    74          temps* Interpreter::stackElementWords + extra_args;
    76   return size;
    77 }
    80 const int Interpreter::return_sentinel = 0xfeedbeed;
    81 const int method_offset = frame::interpreter_frame_method_offset * wordSize;
    82 const int bci_offset    = frame::interpreter_frame_bcx_offset    * wordSize;
    83 const int locals_offset = frame::interpreter_frame_locals_offset * wordSize;
    85 //-----------------------------------------------------------------------------
    87 address TemplateInterpreterGenerator::generate_StackOverflowError_handler() {
    88   address entry = __ pc();
    90 #ifdef ASSERT
    91   {
    92     Label L;
    93     __ addi(T1, FP, frame::interpreter_frame_monitor_block_top_offset * wordSize);
    94     __ sub(T1, T1, SP); // T1 = maximal sp for current fp
    95     __ bgez(T1, L);     // check if frame is complete
    96     __ delayed()->nop();
    97     __ stop("interpreter frame not set up");
    98     __ bind(L);
    99   }
   100 #endif // ASSERT
   101   // Restore bcp under the assumption that the current frame is still
   102   // interpreted
   103   // FIXME: please change the func restore_bcp
   104   // S0 is the conventional register for bcp
   105   __ restore_bcp();
   107   // expression stack must be empty before entering the VM if an
   108   // exception happened
   109   __ empty_expression_stack();
   110   // throw exception
   111   // FIXME: why do not pass parameter thread ?
   112   __ call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_StackOverflowError));
   113   return entry;
   114 }
   116 address TemplateInterpreterGenerator::generate_ArrayIndexOutOfBounds_handler(
   117         const char* name) {
   118   address entry = __ pc();
   119   // expression stack must be empty before entering the VM if an
   120   // exception happened
   121   __ empty_expression_stack();
   122   __ li(A1, (long)name);
   123   __ call_VM(noreg, CAST_FROM_FN_PTR(address,
   124   InterpreterRuntime::throw_ArrayIndexOutOfBoundsException), A1, A2);
   125   return entry;
   126 }
   128 address TemplateInterpreterGenerator::generate_ClassCastException_handler() {
   129   address entry = __ pc();
   131   // object is at TOS
   132   //FIXME, I am not sure if the object is at TOS as x86 do now @jerome, 04/20,2007
   133   //__ pop(c_rarg1);
   135   // expression stack must be empty before entering the VM if an
   136   // exception happened
   137   __ empty_expression_stack();
   138   __ empty_FPU_stack();
   139   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_ClassCastException),  FSR);
   140   return entry;
   141 }
   143 address TemplateInterpreterGenerator::generate_exception_handler_common(
   144         const char* name, const char* message, bool pass_oop) {
   145   assert(!pass_oop || message == NULL, "either oop or message but not both");
   146   address entry = __ pc();
   148   // expression stack must be empty before entering the VM if an exception happened
   149   __ empty_expression_stack();
   150   // setup parameters
   151   __ li(A1, (long)name);
   152   if (pass_oop) {
   153     __ call_VM(V0,
   154     CAST_FROM_FN_PTR(address, InterpreterRuntime::create_klass_exception), A1, FSR);
   155   } else {
   156     __ li(A2, (long)message);
   157     __ call_VM(V0,
   158     CAST_FROM_FN_PTR(address, InterpreterRuntime::create_exception), A1, A2);
   159   }
   160   // throw exception
   161   __ jmp(Interpreter::throw_exception_entry(), relocInfo::none);
   162   __ delayed()->nop();
   163   return entry;
   164 }
   167 address TemplateInterpreterGenerator::generate_continuation_for(TosState state) {
   168   address entry = __ pc();
   169   // NULL last_sp until next java call
   170   __ sd(R0,Address(FP, frame::interpreter_frame_last_sp_offset * wordSize));
   171   __ dispatch_next(state);
   172   return entry;
   173 }
   176 address TemplateInterpreterGenerator::generate_return_entry_for(TosState state, int step, size_t index_size) {
   178   address entry = __ pc();
   180   // Restore stack bottom in case i2c adjusted stack
   181   __ ld(SP, Address(FP, frame::interpreter_frame_last_sp_offset * wordSize));
   182   // and NULL it as marker that esp is now tos until next java call
   183   __ sd(R0, FP, frame::interpreter_frame_last_sp_offset * wordSize);
   185   __ restore_bcp();
   186   __ restore_locals();
   188   // 2014/11/24 Fu
   189   // mdp: T8
   190   // ret: FSR
   191   // tmp: T9
   192   if (state == atos) {
   193     Register mdp = T8;
   194     Register tmp = T9;
   195     __ profile_return_type(mdp, FSR, tmp);
   196   }
   199   const Register cache = T9;
   200   const Register index = T3;
   201   __ get_cache_and_index_at_bcp(cache, index, 1, index_size);
   203   const Register flags = cache;
   204   __ dsll(AT, index, Address::times_ptr);
   205   __ daddu(AT, cache, AT);
   206   __ lw(flags, AT, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::flags_offset()));
   207   __ andi(flags, flags, ConstantPoolCacheEntry::parameter_size_mask);
   208   __ dsll(AT, flags, Interpreter::stackElementScale());
   209   __ daddu(SP, SP, AT);
   211   __ dispatch_next(state, step);
   213   return entry;
   214 }
   217 address TemplateInterpreterGenerator::generate_deopt_entry_for(TosState state,
   218                                                                int step) {
   219   address entry = __ pc();
   220   // NULL last_sp until next java call
   221   __ sd(R0, FP, frame::interpreter_frame_last_sp_offset * wordSize);
   222   __ restore_bcp();
   223   __ restore_locals();
   224   // handle exceptions
   225   {
   226     Label L;
   227     const Register thread = TREG;
   228 #ifndef OPT_THREAD
   229     __ get_thread(thread);
   230 #endif
   231     __ lw(AT, thread, in_bytes(Thread::pending_exception_offset()));
   232     __ beq(AT, R0, L);
   233     __ delayed()->nop();
   234     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_pending_exception));
   235     __ should_not_reach_here();
   236     __ bind(L);
   237   }
   238   __ dispatch_next(state, step);
   239   return entry;
   240 }
   242 int AbstractInterpreter::BasicType_as_index(BasicType type) {
   243   int i = 0;
   244   switch (type) {
   245     case T_BOOLEAN: i = 0; break;
   246     case T_CHAR   : i = 1; break;
   247     case T_BYTE   : i = 2; break;
   248     case T_SHORT  : i = 3; break;
   249     case T_INT    : // fall through
   250     case T_LONG   : // fall through
   251     case T_VOID   : i = 4; break;
   252     case T_FLOAT  : i = 5; break;
   253     case T_DOUBLE : i = 6; break;
   254     case T_OBJECT : // fall through
   255     case T_ARRAY  : i = 7; break;
   256     default       : ShouldNotReachHere();
   257   }
   258   assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers,
   259          "index out of bounds");
   260   return i;
   261 }
   264 // why do not consider float and double , @jerome, 12/27,06, @jerome
   265 //FIXME, aoqi
   266 address TemplateInterpreterGenerator::generate_result_handler_for(
   267         BasicType type) {
   268   address entry = __ pc();
   269   switch (type) {
   270     case T_BOOLEAN: __ c2bool(V0);             break;
   271     case T_CHAR   : __ andi(V0, V0, 0xFFFF);   break;
   272     case T_BYTE   : __ sign_extend_byte (V0);  break;
   273     case T_SHORT  : __ sign_extend_short(V0);  break;
   274     case T_INT    : /* nothing to do */        break;
   275     case T_FLOAT  : /* nothing to do */        break;
   276     case T_DOUBLE : /* nothing to do */        break;
   277     case T_OBJECT :
   278     {
   279        __ ld(V0, FP, frame::interpreter_frame_oop_temp_offset * wordSize);
   280       __ verify_oop(V0);         // and verify it
   281     }
   282                  break;
   283     default       : ShouldNotReachHere();
   284   }
   285   __ jr(RA);                                  // return from result handler
   286   __ delayed()->nop();
   287   return entry;
   288 }
   290 address TemplateInterpreterGenerator::generate_safept_entry_for(
   291         TosState state,
   292         address runtime_entry) {
   293   address entry = __ pc();
   294   __ push(state);
   295   __ call_VM(noreg, runtime_entry);
   296   __ dispatch_via(vtos, Interpreter::_normal_table.table_for(vtos));
   297   return entry;
   298 }
   302 // Helpers for commoning out cases in the various type of method entries.
   303 //
   306 // increment invocation count & check for overflow
   307 //
   308 // Note: checking for negative value instead of overflow
   309 //       so we have a 'sticky' overflow test
   310 //
   311 // prerequisites : method in T0, invocation counter in T3
   312 void InterpreterGenerator::generate_counter_incr(
   313         Label* overflow,
   314         Label* profile_method,
   315         Label* profile_method_continue) {
   316   Label done;
   317   const Address invocation_counter(FSR, in_bytes(MethodCounters::invocation_counter_offset())
   318       + in_bytes(InvocationCounter::counter_offset()));
   319   const Address backedge_counter  (FSR, in_bytes(MethodCounters::backedge_counter_offset())
   320       + in_bytes(InvocationCounter::counter_offset()));
   322   __ get_method_counters(Rmethod, FSR, done);
   324   if (ProfileInterpreter) { // %%% Merge this into methodDataOop
   325     __ lw(T9, FSR, in_bytes(MethodCounters::interpreter_invocation_counter_offset()));
   326     __ incrementl(T9, 1);
   327     __ sw(T9, FSR, in_bytes(MethodCounters::interpreter_invocation_counter_offset()));
   328   }
   329   // Update standard invocation counters
   330   __ lw(T3, invocation_counter);
   331   __ increment(T3, InvocationCounter::count_increment);
   332   __ sw(T3, invocation_counter);  // save invocation count
   334   __ lw(FSR, backedge_counter);  // load backedge counter
   335   __ li(AT, InvocationCounter::count_mask_value);   // mask out the status bits
   336   __ andr(FSR, FSR, AT);
   338   __ dadd(T3, T3, FSR);          // add both counters
   340   if (ProfileInterpreter && profile_method != NULL) {
   341     // Test to see if we should create a method data oop
   342     if (Assembler::is_simm16(InvocationCounter::InterpreterProfileLimit)) {
   343       __ slti(AT, T3, InvocationCounter::InterpreterProfileLimit);
   344     } else {
   345       __ li(AT, (long)&InvocationCounter::InterpreterProfileLimit);
   346       __ lw(AT, AT, 0);
   347       __ slt(AT, T3, AT);
   348     }
   350     __ bne_far(AT, R0, *profile_method_continue);
   351     __ delayed()->nop();
   353     // if no method data exists, go to profile_method
   354     __ test_method_data_pointer(FSR, *profile_method);
   355   }
   357   if (Assembler::is_simm16(CompileThreshold)) {
   358     __ srl(AT, T3, InvocationCounter::count_shift);
   359     __ slti(AT, AT, CompileThreshold);
   360   } else {
   361     __ li(AT, (long)&InvocationCounter::InterpreterInvocationLimit);
   362     __ lw(AT, AT, 0);
   363     __ slt(AT, T3, AT);
   364   }
   366   __ beq_far(AT, R0, *overflow);
   367   __ delayed()->nop();
   368   __ bind(done);
   369 }
   371 void InterpreterGenerator::generate_counter_overflow(Label* do_continue) {
   373   // Asm interpreter on entry
   374   // S7 - locals
   375   // S0 - bcp
   376   // Rmethod - method
   377   // FP - interpreter frame
   379   // On return (i.e. jump to entry_point)
   380   // Rmethod - method
   381   // RA - return address of interpreter caller
   382   // tos - the last parameter to Java method
   383   // SP - sender_sp
   385   //const Address size_of_parameters(Rmethod,in_bytes( Method::size_of_parameters_offset()));
   387   // the bcp is valid if and only if it's not null
   388   __ call_VM(NOREG, CAST_FROM_FN_PTR(address,
   389       InterpreterRuntime::frequency_counter_overflow), R0);
   390   __ ld(Rmethod, FP, method_offset);
   391   // Preserve invariant that esi/edi contain bcp/locals of sender frame
   392   __ b_far(*do_continue);
   393   __ delayed()->nop();
   394 }
   396 // See if we've got enough room on the stack for locals plus overhead.
   397 // The expression stack grows down incrementally, so the normal guard
   398 // page mechanism will work for that.
   399 //
   400 // NOTE: Since the additional locals are also always pushed (wasn't
   401 // obvious in generate_method_entry) so the guard should work for them
   402 // too.
   403 //
   404 // Args:
   405 //      rdx: number of additional locals this frame needs (what we must check)
   406 //      rbx: Method*
   407 //
   408 // Kills:
   409 //      rax
   410 void InterpreterGenerator::generate_stack_overflow_check(void) {
   411   // see if we've got enough room on the stack for locals plus overhead.
   412   // the expression stack grows down incrementally, so the normal guard
   413   // page mechanism will work for that.
   414   //
   415   // Registers live on entry:
   416   //
   417   // T0: Method*
   418   // T2: number of additional locals this frame needs (what we must check)
   420   // NOTE:  since the additional locals are also always pushed (wasn't obvious in
   421   // generate_method_entry) so the guard should work for them too.
   422   //
   424   // monitor entry size: see picture of stack set (generate_method_entry) and frame_i486.hpp
   425   const int entry_size    = frame::interpreter_frame_monitor_size() * wordSize;
   427   // total overhead size: entry_size + (saved ebp thru expr stack bottom).
   428   // be sure to change this if you add/subtract anything to/from the overhead area
   429   const int overhead_size = -(frame::interpreter_frame_initial_sp_offset*wordSize)
   430     + entry_size;
   432   const int page_size = os::vm_page_size();
   434   Label after_frame_check;
   436   // see if the frame is greater than one page in size. If so,
   437   // then we need to verify there is enough stack space remaining
   438   // for the additional locals.
   439   __ move(AT, (page_size - overhead_size) / Interpreter::stackElementSize);
   440   __ slt(AT, AT, T2);
   441   __ beq(AT, R0, after_frame_check);
   442   __ delayed()->nop();
   444   // compute sp as if this were going to be the last frame on
   445   // the stack before the red zone
   446 #ifndef OPT_THREAD
   447   Register thread = T1;
   448   __ get_thread(thread);
   449 #else
   450   Register thread = TREG;
   451 #endif
   453   // locals + overhead, in bytes
   454   //FIXME aoqi
   455   __ dsll(T3, T2, Interpreter::stackElementScale());
   456   __ daddiu(T3, T3, overhead_size);   // locals * 4 + overhead_size --> T3
   458 #ifdef ASSERT
   459   Label stack_base_okay, stack_size_okay;
   460   // verify that thread stack base is non-zero
   461   __ ld(AT, thread, in_bytes(Thread::stack_base_offset()));
   462   __ bne(AT, R0, stack_base_okay);
   463   __ delayed()->nop();
   464   __ stop("stack base is zero");
   465   __ bind(stack_base_okay);
   466   // verify that thread stack size is non-zero
   467   __ ld(AT, thread, in_bytes(Thread::stack_size_offset()));
   468   __ bne(AT, R0, stack_size_okay);
   469   __ delayed()->nop();
   470   __ stop("stack size is zero");
   471   __ bind(stack_size_okay);
   472 #endif
   474   // Add stack base to locals and subtract stack size
   475   __ ld(AT, thread, in_bytes(Thread::stack_base_offset())); // stack_base --> AT
   476   __ dadd(T3, T3, AT);   // locals * 4 + overhead_size + stack_base--> T3
   477   __ ld(AT, thread, in_bytes(Thread::stack_size_offset()));  // stack_size --> AT
   478   __ dsub(T3, T3, AT);  // locals * 4 + overhead_size + stack_base - stack_size --> T3
   481   // add in the redzone and yellow size
   482   __ move(AT, (StackRedPages+StackYellowPages) * page_size);
   483   __ add(T3, T3, AT);
   485   // check against the current stack bottom
   486   __ slt(AT, T3, SP);
   487   __ bne(AT, R0, after_frame_check);
   488   __ delayed()->nop();
   490   // Note: the restored frame is not necessarily interpreted.
   491   // Use the shared runtime version of the StackOverflowError.
   492   __ move(SP, Rsender);
   493   assert(StubRoutines::throw_StackOverflowError_entry() != NULL, "stub not yet generated");
   494   __ jmp(StubRoutines::throw_StackOverflowError_entry(), relocInfo::runtime_call_type);
   495   __ delayed()->nop();
   497   // all done with frame size check
   498   __ bind(after_frame_check);
   499 }
   501 // Allocate monitor and lock method (asm interpreter)
   502 // Rmethod - Method*
   503 void InterpreterGenerator::lock_method(void) {
   504   // synchronize method
   505   const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
   507 #ifdef ASSERT
   508   { Label L;
   509     __ lw(T0, Rmethod, in_bytes(Method::access_flags_offset()));
   510     __ andi(T0, T0, JVM_ACC_SYNCHRONIZED);
   511     __ bne(T0, R0, L);
   512     __ delayed()->nop();
   513     __ stop("method doesn't need synchronization");
   514     __ bind(L);
   515   }
   516 #endif // ASSERT
   517   // get synchronization object
   518   {
   519     Label done;
   520     const int mirror_offset = in_bytes(Klass::java_mirror_offset());
   521     __ lw(T0, Rmethod, in_bytes(Method::access_flags_offset()));
   522     __ andi(T2, T0, JVM_ACC_STATIC);
   523     __ ld(T0, LVP, Interpreter::local_offset_in_bytes(0));
   524     __ beq(T2, R0, done);
   525     __ delayed()->nop();
   526     __ ld(T0, Rmethod, in_bytes(Method::const_offset()));
   527     __ ld(T0, T0, in_bytes(ConstMethod::constants_offset()));
   528     __ ld(T0, T0, ConstantPool::pool_holder_offset_in_bytes());
   529     __ ld(T0, T0, mirror_offset);
   530     __ bind(done);
   531   }
   532   // add space for monitor & lock
   533   __ daddi(SP, SP, (-1) * entry_size);           // add space for a monitor entry
   534   __ sd(SP, FP, frame::interpreter_frame_monitor_block_top_offset * wordSize);
   535   // set new monitor block top
   536   __ sd(T0, SP, BasicObjectLock::obj_offset_in_bytes());   // store object
   537   // FIXME: I do not know what lock_object will do and what it will need
   538   __ move(c_rarg0, SP);      // object address
   539   __ lock_object(c_rarg0);
   540 }
   542 // Generate a fixed interpreter frame. This is identical setup for
   543 // interpreted methods and for native methods hence the shared code.
   544 void TemplateInterpreterGenerator::generate_fixed_frame(bool native_call) {
   546   // [ local var m-1      ] <--- sp
   547   //   ...
   548   // [ local var 0        ]
   549   // [ argumnet word n-1  ] <--- T0(sender's sp)
   550   //   ...
   551   // [ argument word 0    ] <--- S7
   553   // initialize fixed part of activation frame
   554   // sender's sp in Rsender
   555   int i = 0;
   556   __ sd(RA, SP, (-1) * wordSize);   // save return address
   557   __ sd(FP, SP, (-2) * wordSize);  // save sender's fp
   558   __ daddiu(FP, SP, (-2) * wordSize);
   559   __ sd(Rsender, FP, (-++i) * wordSize);  // save sender's sp
   560   __ sd(R0, FP,(-++i)*wordSize);       //save last_sp as null, FIXME aoqi
   561   __ sd(LVP, FP, (-++i) * wordSize);  // save locals offset
   562   __ ld(BCP, Rmethod, in_bytes(Method::const_offset())); // get constMethodOop
   563   __ daddiu(BCP, BCP, in_bytes(ConstMethod::codes_offset())); // get codebase
   564   __ sd(Rmethod, FP, (-++i) * wordSize);                              // save Method*
   565 #ifndef CORE
   566   if (ProfileInterpreter) {
   567     Label method_data_continue;
   568     __ ld(AT, Rmethod,  in_bytes(Method::method_data_offset()));
   569     __ beq(AT, R0, method_data_continue);
   570     __ delayed()->nop();
   571     __ daddi(AT, AT, in_bytes(MethodData::data_offset()));
   572     __ bind(method_data_continue);
   573     __ sd(AT, FP,  (-++i) * wordSize);
   574   } else {
   575     __ sd(R0, FP, (-++i) * wordSize);
   576   }
   577 #endif // !CORE
   579   __ ld(T2, Rmethod, in_bytes(Method::const_offset()));
   580   __ ld(T2, T2, in_bytes(ConstMethod::constants_offset()));
   581   __ ld(T2, T2, ConstantPool::cache_offset_in_bytes());
   582   __ sd(T2, FP, (-++i) * wordSize);                    // set constant pool cache
   583   if (native_call) {
   584     __ sd(R0, FP, (-++i) * wordSize);          // no bcp
   585   } else {
   586     __ sd(BCP, FP, (-++i) * wordSize);          // set bcp
   587   }
   588   __ daddiu(SP, FP, (-++i) * wordSize);
   589   __ sd(SP, FP, (-i) * wordSize);               // reserve word for pointer to expression stack bottom
   590 }
   592 // End of helpers
   594 // Various method entries
   595 //------------------------------------------------------------------------------------------------------------------------
   596 //
   597 //
   599 // Call an accessor method (assuming it is resolved, otherwise drop
   600 // into vanilla (slow path) entry
   601 address InterpreterGenerator::generate_accessor_entry(void) {
   603   // Rmethod: Method*
   604   // V0: receiver (preserve for slow entry into asm interpreter)
   605   //  Rsender: senderSP must preserved for slow path, set SP to it on fast path
   607   address entry_point = __ pc();
   608   Label xreturn_path;
   609   // do fastpath for resolved accessor methods
   610   if (UseFastAccessorMethods) {
   611     Label slow_path;
   612     __ li(T2, SafepointSynchronize::address_of_state());
   613     __ lw(AT, T2, 0);
   614     __ daddi(AT, AT, -(SafepointSynchronize::_not_synchronized));
   615     __ bne(AT, R0, slow_path);
   616     __ delayed()->nop();
   617     // Code: _aload_0, _(i|a)getfield, _(i|a)return or any rewrites thereof;
   618     // parameter size = 1
   619     // Note: We can only use this code if the getfield has been resolved
   620     //       and if we don't have a null-pointer exception => check for
   621     //       these conditions first and use slow path if necessary.
   622     // Rmethod: method
   623     // V0: receiver
   625     // [ receiver  ] <-- sp
   626     __ ld(T0, SP, 0);
   628     // check if local 0 != NULL and read field
   629     __ beq(T0, R0, slow_path);
   630     __ delayed()->nop();
   631     __ ld(T2, Rmethod, in_bytes(Method::const_offset()));
   632     __ ld(T2, T2, in_bytes(ConstMethod::constants_offset()));
   633     // read first instruction word and extract bytecode @ 1 and index @ 2
   634     __ ld(T3, Rmethod, in_bytes(Method::const_offset()));
   635     __ lw(T3, T3, in_bytes(ConstMethod::codes_offset()));
   636     // Shift codes right to get the index on the right.
   637     // The bytecode fetched looks like <index><0xb4><0x2a>
   638     __ dsrl(T3, T3, 2 * BitsPerByte);
   639     // FIXME: maybe it's wrong
   640     __ dsll(T3, T3, exact_log2(in_words(ConstantPoolCacheEntry::size())));
   641     __ ld(T2, T2, ConstantPool::cache_offset_in_bytes());
   643     // T0: local 0 eax
   644     // Rmethod: method ebx
   645     // V0: receiver - do not destroy since it is needed for slow path! ecx
   646     // ecx: scratch use which register instead ?
   647     // T1: scratch use which register instead ?
   648     // T3: constant pool cache index  edx
   649     // T2: constant pool cache  edi
   650     // esi: send's sp
   651     // Rsender: send's sp
   652     // check if getfield has been resolved and read constant pool cache entry
   653     // check the validity of the cache entry by testing whether _indices field
   654     // contains Bytecode::_getfield in b1 byte.
   655     assert(in_words(ConstantPoolCacheEntry::size()) == 4, "adjust shift below");
   656     //    __ movl(esi,
   657     //      Address(edi,
   658     //        edx,
   659     //        Address::times_4, ConstantPoolCache::base_offset()
   660     //        + ConstantPoolCacheEntry::indices_offset()));
   663     __ dsll(T8, T3, Address::times_8);
   664     __ move(T1, in_bytes(ConstantPoolCache::base_offset()
   665     + ConstantPoolCacheEntry::indices_offset()));
   666     __ dadd(T1, T8, T1);
   667     __ dadd(T1, T1, T2);
   668     __ lw(T1, T1, 0);
   669     __ dsrl(T1, T1, 2 * BitsPerByte);
   670     __ andi(T1, T1, 0xFF);
   671     __ daddi(T1, T1, (-1) * Bytecodes::_getfield);
   672     __ bne(T1, R0, slow_path);
   673     __ delayed()->nop();
   675     // Note: constant pool entry is not valid before bytecode is resolved
   677     __ move(T1, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::f2_offset()));
   678     __ dadd(T1, T1, T8);
   679     __ dadd(T1, T1, T2);
   680     __ lw(AT, T1, 0);
   682     __ move(T1, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::flags_offset()));
   683     __ dadd(T1, T1, T8);
   684     __ dadd(T1, T1, T2);
   685     __ lw(T3, T1, 0);
   687     Label notByte, notBool, notShort, notChar, notObj;
   688     //    const Address field_address (eax, esi, Address::times_1);
   690     // Need to differentiate between igetfield, agetfield, bgetfield etc.
   691     // because they are different sizes.
   692     // Use the type from the constant pool cache
   693     __ srl(T3, T3, ConstantPoolCacheEntry::tos_state_shift);
   694     // Make sure we don't need to mask edx for tosBits after the above shift
   695     ConstantPoolCacheEntry::verify_tos_state_shift();
   696     // btos = 0
   697     __ bne(T3, R0, notByte);
   698     __ delayed()->dadd(T0, T0, AT);
   700     __ lb(V0, T0, 0);
   701     __ b(xreturn_path);
   702     __ delayed()->nop();
   704     //ztos
   705     __ bind(notByte);
   706     __ daddi(T1, T3, (-1) * ztos);
   707     __ bne(T1, R0, notBool);
   708     __ delayed()->nop();
   709     __ lb(V0, T0, 0);
   710     __ b(xreturn_path);
   711     __ delayed()->nop();
   713     //stos
   714     __ bind(notBool);
   715     __ daddi(T1, T3, (-1) * stos);
   716     __ bne(T1, R0, notShort);
   717     __ delayed()->nop();
   718     __ lh(V0, T0, 0);
   719     __ b(xreturn_path);
   720     __ delayed()->nop();
   722     //ctos
   723     __ bind(notShort);
   724     __ daddi(T1, T3, (-1) * ctos);
   725     __ bne(T1, R0, notChar);
   726     __ delayed()->nop();
   727     __ lhu(V0, T0, 0);
   728     __ b(xreturn_path);
   729     __ delayed()->nop();
   731     //atos
   732     __ bind(notChar);
   733     __ daddi(T1, T3, (-1) * atos);
   734     __ bne(T1, R0, notObj);
   735     __ delayed()->nop();
   736     //add for compressedoops
   737     __ load_heap_oop(V0, Address(T0, 0));
   738     __ b(xreturn_path);
   739     __ delayed()->nop();
   741     //itos
   742     __ bind(notObj);
   743 #ifdef ASSERT
   744     Label okay;
   745     __ daddi(T1, T3, (-1) * itos);
   746     __ beq(T1, R0, okay);
   747     __ delayed()->nop();
   748     __ stop("what type is this?");
   749     __ bind(okay);
   750 #endif // ASSERT
   751     __ lw(V0, T0, 0);
   753     __ bind(xreturn_path);
   755     // _ireturn/_areturn
   756     //FIXME
   757     __ move(SP, Rsender);//FIXME, set sender's fp to SP
   758     __ jr(RA);
   759     __ delayed()->nop();
   761     // generate a vanilla interpreter entry as the slow path
   762     __ bind(slow_path);
   763     (void) generate_normal_entry(false);
   764   } else {
   765     (void) generate_normal_entry(false);
   766   }
   768   return entry_point;
   769 }
   771 // Method entry for java.lang.ref.Reference.get.
   772 address InterpreterGenerator::generate_Reference_get_entry(void) {
   773 #if INCLUDE_ALL_GCS
   774   // Code: _aload_0, _getfield, _areturn
   775   // parameter size = 1
   776   //
   777   // The code that gets generated by this routine is split into 2 parts:
   778   //    1. The "intrinsified" code for G1 (or any SATB based GC),
   779   //    2. The slow path - which is an expansion of the regular method entry.
   780   //
   781   // Notes:-
   782   // * In the G1 code we do not check whether we need to block for
   783   //   a safepoint. If G1 is enabled then we must execute the specialized
   784   //   code for Reference.get (except when the Reference object is null)
   785   //   so that we can log the value in the referent field with an SATB
   786   //   update buffer.
   787   //   If the code for the getfield template is modified so that the
   788   //   G1 pre-barrier code is executed when the current method is
   789   //   Reference.get() then going through the normal method entry
   790   //   will be fine.
   791   // * The G1 code can, however, check the receiver object (the instance
   792   //   of java.lang.Reference) and jump to the slow path if null. If the
   793   //   Reference object is null then we obviously cannot fetch the referent
   794   //   and so we don't need to call the G1 pre-barrier. Thus we can use the
   795   //   regular method entry code to generate the NPE.
   796   //
   797   // This code is based on generate_accessor_enty.
   798   //
   799   // rbx: Method* (Rmethod)
   801   // r13: senderSP must preserve for slow path, set SP to it on fast path (Rsender)
   803   // rax: V0
   804   // rbx: Rmethod
   805   // r13: Rsender
   806   // rdi: T9
   808   address entry = __ pc();
   810   const int referent_offset = java_lang_ref_Reference::referent_offset;
   811   guarantee(referent_offset > 0, "referent offset not initialized");
   813   if (UseG1GC) {
   814     Label slow_path;
   816     // Check if local 0 != NULL
   817     // If the receiver is null then it is OK to jump to the slow path.
   818     __ ld(V0, SP, 0);
   820     __ beq(V0, R0, slow_path);
   821     __ delayed()->nop();
   823     // Generate the G1 pre-barrier code to log the value of
   824     // the referent field in an SATB buffer.
   826     // Load the value of the referent field.
   827     const Address field_address(V0, referent_offset);
   828     __ load_heap_oop(V0, field_address);
   830     __ push(RA);
   831     // Generate the G1 pre-barrier code to log the value of
   832     // the referent field in an SATB buffer.
   833     __ g1_write_barrier_pre(noreg /* obj */,
   834                             V0 /* pre_val */,
   835                             TREG /* thread */,
   836                             Rmethod /* tmp */,
   837                             true /* tosca_live */,
   838                             true /* expand_call */);
   839     __ pop(RA);
   841     __ jr(RA);
   842     __ delayed()->daddu(SP, Rsender, R0);      // set sp to sender sp
   844     // generate a vanilla interpreter entry as the slow path
   845     __ bind(slow_path);
   846     (void) generate_normal_entry(false);
   848     return entry;
   849   }
   850 #endif // INCLUDE_ALL_GCS
   852   // If G1 is not enabled then attempt to go through the accessor entry point
   853   // Reference.get is an accessor
   854   return generate_accessor_entry();
   855 }
   857 // Interpreter stub for calling a native method. (asm interpreter)
   858 // This sets up a somewhat different looking stack for calling the
   859 // native method than the typical interpreter frame setup.
   860 address InterpreterGenerator::generate_native_entry(bool synchronized) {
   861   // determine code generation flags
   862   bool inc_counter  = UseCompiler || CountCompiledCalls;
   863   // Rsender: sender's sp
   864   // Rmethod: Method*
   865   address entry_point = __ pc();
   867 #ifndef CORE
   868   const Address invocation_counter(Rmethod,in_bytes(MethodCounters::invocation_counter_offset() +   // Fu: 20130814
   869   InvocationCounter::counter_offset()));
   870 #endif
   872   // get parameter size (always needed)
   873   // the size in the java stack
   874   __ ld(V0, Rmethod, in_bytes(Method::const_offset()));
   875   __ lhu(V0, V0, in_bytes(ConstMethod::size_of_parameters_offset()));   // Fu: 20130814
   877   // native calls don't need the stack size check since they have no expression stack
   878   // and the arguments are already on the stack and we only add a handful of words
   879   // to the stack
   881   // Rmethod: Method*
   882   // V0: size of parameters
   883   // Layout of frame at this point
   884   //
   885   // [ argument word n-1  ] <--- sp
   886   //   ...
   887   // [ argument word 0    ]
   889   // for natives the size of locals is zero
   891   // compute beginning of parameters (S7)
   892   __ dsll(LVP, V0, Address::times_8);
   893   __ daddiu(LVP, LVP, (-1) * wordSize);
   894   __ dadd(LVP, LVP, SP);
   897   // add 2 zero-initialized slots for native calls
   898   __ daddi(SP, SP, (-2) * wordSize);
   899   __ sd(R0, SP, 1 * wordSize);  // slot for native oop temp offset (setup via runtime)
   900   __ sd(R0, SP, 0 * wordSize);  // slot for static native result handler3 (setup via runtime)
   902   // Layout of frame at this point
   903   // [ method holder mirror  ] <--- sp
   904   // [ result type info      ]
   905   // [ argument word n-1     ] <--- T0
   906   //   ...
   907   // [ argument word 0      ] <--- LVP
   910 #ifndef CORE
   911   if (inc_counter) __ lw(T3, invocation_counter);  // (pre-)fetch invocation count
   912 #endif
   914   // initialize fixed part of activation frame
   915   generate_fixed_frame(true);
   916   // after this function, the layout of frame is as following
   917   //
   918   // [ monitor block top        ] <--- sp ( the top monitor entry )
   919   // [ byte code pointer (0)    ] (if native, bcp = 0)
   920   // [ constant pool cache      ]
   921   // [ Method*                ]
   922   // [ locals offset            ]
   923   // [ sender's sp              ]
   924   // [ sender's fp              ]
   925   // [ return address           ] <--- fp
   926   // [ method holder mirror     ]
   927   // [ result type info         ]
   928   // [ argumnet word n-1        ] <--- sender's sp
   929   //   ...
   930   // [ argument word 0          ] <--- S7
   933   // make sure method is native & not abstract
   934 #ifdef ASSERT
   935   __ lw(T0, Rmethod, in_bytes(Method::access_flags_offset()));
   936   {
   937     Label L;
   938     __ andi(AT, T0, JVM_ACC_NATIVE);
   939     __ bne(AT, R0, L);
   940     __ delayed()->nop();
   941     __ stop("tried to execute native method as non-native");
   942     __ bind(L);
   943   }
   944   {
   945     Label L;
   946     __ andi(AT, T0, JVM_ACC_ABSTRACT);
   947     __ beq(AT, R0, L);
   948     __ delayed()->nop();
   949     __ stop("tried to execute abstract method in interpreter");
   950     __ bind(L);
   951   }
   952 #endif
   954   // Since at this point in the method invocation the exception handler
   955   // would try to exit the monitor of synchronized methods which hasn't
   956   // been entered yet, we set the thread local variable
   957   // _do_not_unlock_if_synchronized to true. The remove_activation will
   958   // check this flag.
   959   Register thread = TREG;
   960 #ifndef OPT_THREAD
   961   __ get_thread(thread);
   962 #endif
   963   __ move(AT, (int)true);
   964   __ sb(AT, thread, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
   966 #ifndef CORE
   967   // increment invocation count & check for overflow
   968   Label invocation_counter_overflow;
   969   if (inc_counter) {
   970     generate_counter_incr(&invocation_counter_overflow, NULL, NULL);
   971   }
   973   Label continue_after_compile;
   974   __ bind(continue_after_compile);
   975 #endif // CORE
   977   bang_stack_shadow_pages(true);
   979   // reset the _do_not_unlock_if_synchronized flag
   980 #ifndef OPT_THREAD
   981   __ get_thread(thread);
   982 #endif
   983   __ sb(R0, thread, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
   985   // check for synchronized methods
   986   // Must happen AFTER invocation_counter check and stack overflow check,
   987   // so method is not locked if overflows.
   988   if (synchronized) {
   989     lock_method();
   990   } else {
   991     // no synchronization necessary
   992 #ifdef ASSERT
   993     {
   994       Label L;
   995       __ lw(T0, Rmethod, in_bytes(Method::access_flags_offset()));
   996       __ andi(AT, T0, JVM_ACC_SYNCHRONIZED);
   997       __ beq(AT, R0, L);
   998       __ delayed()->nop();
   999       __ stop("method needs synchronization");
  1000       __ bind(L);
  1002 #endif
  1005   // after method_lock, the layout of frame is as following
  1006   //
  1007   // [ monitor entry            ] <--- sp
  1008   //   ...
  1009   // [ monitor entry            ]
  1010   // [ monitor block top        ] ( the top monitor entry )
  1011   // [ byte code pointer (0)    ] (if native, bcp = 0)
  1012   // [ constant pool cache      ]
  1013   // [ Method*                ]
  1014   // [ locals offset        ]
  1015   // [ sender's sp              ]
  1016   // [ sender's fp              ]
  1017   // [ return address           ] <--- fp
  1018   // [ method holder mirror     ]
  1019   // [ result type info         ]
  1020   // [ argumnet word n-1        ] <--- ( sender's sp )
  1021   //   ...
  1022   // [ argument word 0          ] <--- S7
  1024   // start execution
  1025 #ifdef ASSERT
  1027     Label L;
  1028     __ ld(AT, FP, frame::interpreter_frame_monitor_block_top_offset * wordSize);
  1029     __ beq(AT, SP, L);
  1030     __ delayed()->nop();
  1031     __ stop("broken stack frame setup in interpreter in asm");
  1032     __ bind(L);
  1034 #endif
  1036   // jvmti/jvmpi support
  1037   __ notify_method_entry();
  1039   // work registers
  1040   const Register method = Rmethod;
  1041   //const Register thread = T2;
  1042   const Register t      = RT4;
  1044   __ get_method(method);
  1045   __ verify_oop(method);
  1047     Label L, Lstatic;
  1048     __ ld(t,method,in_bytes(Method::const_offset()));
  1049     __ lhu(t, t, in_bytes(ConstMethod::size_of_parameters_offset()));  // Fu: 20130814
  1050     // MIPS n64 ABI: caller does not reserve space for the register auguments.
  1051     //FIXME, aoqi: A1?
  1052     // A0 and A1(if needed)
  1053     __ lw(AT, Rmethod, in_bytes(Method::access_flags_offset()));
  1054     __ andi(AT, AT, JVM_ACC_STATIC);
  1055     __ beq(AT, R0, Lstatic);
  1056     __ delayed()->nop();
  1057     __ daddiu(t, t, 1);
  1058     __ bind(Lstatic);
  1059     __ daddiu(t, t, -7);
  1060     __ blez(t, L);
  1061     __ delayed()->nop();
  1062     __ dsll(t, t, Address::times_8);
  1063     __ dsub(SP, SP, t);
  1064     __ bind(L);
  1066   __ move(AT, -(StackAlignmentInBytes));
  1067   __ andr(SP, SP, AT);
  1068   __ move(AT, SP);
  1069   // [        ] <--- sp
  1070   //   ...                        (size of parameters - 8 )
  1071   // [ monitor entry            ]
  1072   //   ...
  1073   // [ monitor entry            ]
  1074   // [ monitor block top        ] ( the top monitor entry )
  1075   // [ byte code pointer (0)    ] (if native, bcp = 0)
  1076   // [ constant pool cache      ]
  1077   // [ Method*                ]
  1078   // [ locals offset            ]
  1079   // [ sender's sp              ]
  1080   // [ sender's fp              ]
  1081   // [ return address           ] <--- fp
  1082   // [ method holder mirror     ]
  1083   // [ result type info         ]
  1084   // [ argumnet word n-1        ] <--- ( sender's sp )
  1085   //   ...
  1086   // [ argument word 0          ] <--- LVP
  1088   // get signature handler
  1090     Label L;
  1091     __ ld(T9, method, in_bytes(Method::signature_handler_offset()));
  1092     __ bne(T9, R0, L);
  1093     __ delayed()->nop();
  1094     __ call_VM(NOREG, CAST_FROM_FN_PTR(address,
  1095                InterpreterRuntime::prepare_native_call), method);
  1096     __ get_method(method);
  1097     __ ld(T9, method, in_bytes(Method::signature_handler_offset()));
  1098     __ bind(L);
  1101   // call signature handler
  1102   // FIXME: when change codes in InterpreterRuntime, note this point
  1103   // from: begin of parameters
  1104   assert(InterpreterRuntime::SignatureHandlerGenerator::from() == LVP, "adjust this code");
  1105   // to: current sp
  1106   assert(InterpreterRuntime::SignatureHandlerGenerator::to  () == SP, "adjust this code");
  1107   // temp: T3
  1108   assert(InterpreterRuntime::SignatureHandlerGenerator::temp() == t  , "adjust this code");
  1110   __ jalr(T9);
  1111   __ delayed()->nop();
  1112   __ get_method(method);  // slow path call blows EBX on DevStudio 5.0
  1114   /*
  1115      if native function is static, and its second parameter has type length of double word,
  1116      and first parameter has type length of word, we have to reserve one word
  1117      for the first parameter, according to mips o32 abi.
  1118      if native function is not static, and its third parameter has type length of double word,
  1119      and second parameter has type length of word, we have to reserve one word for the second
  1120      parameter.
  1121    */
  1124   // result handler is in V0
  1125   // set result handler
  1126   __ sd(V0, FP, (frame::interpreter_frame_result_handler_offset)*wordSize);
  1128 #define FIRSTPARA_SHIFT_COUNT 5
  1129 #define SECONDPARA_SHIFT_COUNT 9
  1130 #define THIRDPARA_SHIFT_COUNT 13
  1131 #define PARA_MASK  0xf
  1133   // pass mirror handle if static call
  1135     Label L;
  1136     const int mirror_offset = in_bytes(Klass::java_mirror_offset());
  1137     __ lw(t, method, in_bytes(Method::access_flags_offset()));
  1138     __ andi(AT, t, JVM_ACC_STATIC);
  1139     __ beq(AT, R0, L);
  1140     __ delayed()->nop();
  1142     // get mirror
  1143     __ ld(t, method, in_bytes(Method:: const_offset()));
  1144     __ ld(t, t, in_bytes(ConstMethod::constants_offset())); //??
  1145     __ ld(t, t, ConstantPool::pool_holder_offset_in_bytes());
  1146     __ ld(t, t, mirror_offset);
  1147     // copy mirror into activation frame
  1148     //__ sw(t, FP, frame::interpreter_frame_oop_temp_offset * wordSize);
  1149     // pass handle to mirror
  1150     __ sd(t, FP, frame::interpreter_frame_oop_temp_offset * wordSize);
  1151     __ daddi(t, FP, frame::interpreter_frame_oop_temp_offset * wordSize);
  1152     __ move(A1, t);
  1153     __ bind(L);
  1156   // [ mthd holder mirror ptr   ] <--- sp  --------------------| (only for static method)
  1157   // [                          ]                              |
  1158   //   ...                        size of parameters(or +1)    |
  1159   // [ monitor entry            ]                              |
  1160   //   ...                                                     |
  1161   // [ monitor entry            ]                              |
  1162   // [ monitor block top        ] ( the top monitor entry )    |
  1163   // [ byte code pointer (0)    ] (if native, bcp = 0)         |
  1164   // [ constant pool cache      ]                              |
  1165   // [ Method*                ]                              |
  1166   // [ locals offset            ]                              |
  1167   // [ sender's sp              ]                              |
  1168   // [ sender's fp              ]                              |
  1169   // [ return address           ] <--- fp                      |
  1170   // [ method holder mirror     ] <----------------------------|
  1171   // [ result type info         ]
  1172   // [ argumnet word n-1        ] <--- ( sender's sp )
  1173   //   ...
  1174   // [ argument word 0          ] <--- S7
  1176   // get native function entry point
  1177   { Label L;
  1178     __ ld(T9, method, in_bytes(Method::native_function_offset()));
  1179     __ li(V1, SharedRuntime::native_method_throw_unsatisfied_link_error_entry());
  1180     __ bne(V1, T9, L);
  1181     __ delayed()->nop();
  1182     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), method);
  1183     __ get_method(method);
  1184     __ verify_oop(method);
  1185     __ ld(T9, method, in_bytes(Method::native_function_offset()));
  1186     __ bind(L);
  1188   /*
  1189   __ pushad();
  1190   __ move(A0, T9);
  1191   __ call(CAST_FROM_FN_PTR(address, SharedRuntime::func_debug),relocInfo::runtime_call_type);
  1192   __ popad();
  1193   */
  1195   // pass JNIEnv
  1196   // native function in T9
  1197 #ifndef OPT_THREAD
  1198   __ get_thread(thread);
  1199 #endif
  1200   __ daddi(t, thread, in_bytes(JavaThread::jni_environment_offset()));
  1201   // stack,but I think it won't work when pass float,double etc @jerome,10/17,2006
  1202   __ move(A0, t);
  1203   // [ jni environment          ] <--- sp
  1204   // [ mthd holder mirror ptr   ] ---------------------------->| (only for static method)
  1205   // [                          ]                              |
  1206   //   ...                        size of parameters           |
  1207   // [ monitor entry            ]                              |
  1208   //   ...                                                     |
  1209   // [ monitor entry            ]                              |
  1210   // [ monitor block top        ] ( the top monitor entry )    |
  1211   // [ byte code pointer (0)    ] (if native, bcp = 0)         |
  1212   // [ constant pool cache      ]                              |
  1213   // [ Method*                ]                              |
  1214   // [ locals offset            ]                              |
  1215   // [ sender's sp              ]                              |
  1216   // [ sender's fp              ]                              |
  1217   // [ return address           ] <--- fp                      |
  1218   // [ method holder mirror     ] <----------------------------|
  1219   // [ result type info         ]
  1220   // [ argumnet word n-1        ] <--- ( sender's sp )
  1221   //   ...
  1222   // [ argument word 0          ] <--- S7
  1224   // set_last_Java_frame_before_call
  1225   __ sd(FP, thread, in_bytes(JavaThread::last_Java_fp_offset()));
  1226   // Change state to native (we save the return address in the thread, since it might not
  1227   // be pushed on the stack when we do a a stack traversal). It is enough that the pc()
  1228   // points into the right code segment. It does not have to be the correct return pc.
  1229   __ li(t, __ pc());
  1230   __ sd(t, thread, in_bytes(JavaThread::last_Java_pc_offset()));
  1231   __ sd(SP, thread, in_bytes(JavaThread::last_Java_sp_offset()));
  1233   // change thread state
  1234 #ifdef ASSERT
  1236     Label L;
  1237     __ lw(t, thread, in_bytes(JavaThread::thread_state_offset()));
  1238     __ daddi(t, t, (-1) * _thread_in_Java);
  1239     __ beq(t, R0, L);
  1240     __ delayed()->nop();
  1241     __ stop("Wrong thread state in native stub");
  1242     __ bind(L);
  1244 #endif
  1246   __ move(t, _thread_in_native);
  1247   __ sw(t, thread, in_bytes(JavaThread::thread_state_offset()));
  1249   // call native method
  1250   __ jalr(T9);
  1251   __ delayed()->nop();
  1252   // result potentially in V2:V1 or F0:F1
  1255   // via _last_native_pc and not via _last_jave_sp
  1256   // NOTE: the order of theses push(es) is known to frame::interpreter_frame_result.
  1257   //  If the order changes or anything else is added to the stack the code in
  1258   // interpreter_frame_result will have to be changed.
  1259   //FIXME, should modify here
  1260   // save return value to keep the value from being destroyed by other calls
  1261   __ move(S1, V0);
  1262   __ move(S3, V1);
  1263   __ dmfc1(S4, F0);
  1264   __ dmfc1(S2, F1);
  1266   // change thread state
  1267   __ get_thread(thread);
  1268   __ move(t, _thread_in_native_trans);
  1269   __ sw(t, thread, in_bytes(JavaThread::thread_state_offset()));
  1271   if( os::is_MP() ) __ sync(); // Force this write out before the read below
  1273   // check for safepoint operation in progress and/or pending suspend requests
  1274   { Label Continue;
  1276     // Don't use call_VM as it will see a possible pending exception and forward it
  1277     // and never return here preventing us from clearing _last_native_pc down below.
  1278     // Also can't use call_VM_leaf either as it will check to see if esi & edi are
  1279     // preserved and correspond to the bcp/locals pointers. So we do a runtime call
  1280     // by hand.
  1281     //
  1282     Label L;
  1283     __ li(AT, SafepointSynchronize::address_of_state());
  1284     __ lw(AT, AT, 0);
  1285     __ bne(AT, R0, L);
  1286     __ delayed()->nop();
  1287     __ lw(AT, thread, in_bytes(JavaThread::suspend_flags_offset()));
  1288     __ beq(AT, R0, Continue);
  1289     __ delayed()->nop();
  1290     __ bind(L);
  1291     __ move(A0, thread);
  1292     __ call(CAST_FROM_FN_PTR(address,
  1293     JavaThread::check_special_condition_for_native_trans),
  1294   relocInfo::runtime_call_type);
  1295     __ delayed()->nop();
  1297 #ifndef OPT_THREAD
  1298     __ get_thread(thread);
  1299 #endif
  1300     //add for compressedoops
  1301     __ reinit_heapbase();
  1302     __ bind(Continue);
  1305   // change thread state
  1306   __ move(t, _thread_in_Java);
  1307   __ sw(t, thread, in_bytes(JavaThread::thread_state_offset()));
  1308   __ reset_last_Java_frame(thread, true, true);
  1310   // reset handle block
  1311   __ ld(t, thread, in_bytes(JavaThread::active_handles_offset()));
  1312   __ sw(R0, t, JNIHandleBlock::top_offset_in_bytes());
  1314   // If result was an oop then unbox and save it in the frame
  1315   { Label L;
  1316     Label no_oop, store_result;
  1317     //FIXME, addi only support 16-bit imeditate
  1318     __ ld(AT, FP, frame::interpreter_frame_result_handler_offset*wordSize);
  1319     __ li(T0, AbstractInterpreter::result_handler(T_OBJECT));
  1320     __ bne(AT, T0, no_oop);
  1321     __ delayed()->nop();
  1322     __ move(V0, S1);
  1323     __ beq(V0, R0, store_result);
  1324     __ delayed()->nop();
  1325     // unbox
  1326     __ ld(V0, V0, 0);
  1327     __ bind(store_result);
  1328     __ sd(V0, FP, (frame::interpreter_frame_oop_temp_offset)*wordSize);
  1329     // keep stack depth as expected by pushing oop which will eventually be discarded
  1330     __ bind(no_oop);
  1333     Label no_reguard;
  1334     __ lw(t, thread, in_bytes(JavaThread::stack_guard_state_offset()));
  1335     __ move(AT,(int) JavaThread::stack_guard_yellow_disabled);
  1336     __ bne(t, AT, no_reguard);
  1337     __ delayed()->nop();
  1338     __ pushad();
  1339     __ move(S5_heapbase, SP);
  1340     __ move(AT, -StackAlignmentInBytes);
  1341     __ andr(SP, SP, AT);
  1342     __ call(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages), relocInfo::runtime_call_type);
  1343     __ delayed()->nop();
  1344     __ move(SP, S5_heapbase);
  1345     __ popad();
  1346     //add for compressedoops
  1347     __ reinit_heapbase();
  1348     __ bind(no_reguard);
  1350   // restore esi to have legal interpreter frame,
  1351   // i.e., bci == 0 <=> esi == code_base()
  1352   // Can't call_VM until bcp is within reasonable.
  1353   __ get_method(method);      // method is junk from thread_in_native to now.
  1354   __ verify_oop(method);
  1355   __ ld(BCP, method, in_bytes(Method::const_offset()));
  1356   __ lea(BCP, Address(BCP, in_bytes(ConstMethod::codes_offset())));
  1357   // handle exceptions (exception handling will handle unlocking!)
  1359     Label L;
  1360     __ lw(t, thread, in_bytes(Thread::pending_exception_offset()));
  1361     __ beq(t, R0, L);
  1362     __ delayed()->nop();
  1363     // Note: At some point we may want to unify this with the code used in
  1364     // call_VM_base();
  1365     // i.e., we should use the StubRoutines::forward_exception code. For now this
  1366     // doesn't work here because the esp is not correctly set at this point.
  1367     __ MacroAssembler::call_VM(noreg, CAST_FROM_FN_PTR(address,
  1368     InterpreterRuntime::throw_pending_exception));
  1369     __ should_not_reach_here();
  1370     __ bind(L);
  1373   // do unlocking if necessary
  1375     Label L;
  1376     __ lw(t, method, in_bytes(Method::access_flags_offset()));
  1377     __ andi(t, t, JVM_ACC_SYNCHRONIZED);
  1378     __ beq(t, R0, L);
  1379     // the code below should be shared with interpreter macro assembler implementation
  1381       Label unlock;
  1382       // BasicObjectLock will be first in list,
  1383       // since this is a synchronized method. However, need
  1384       // to check that the object has not been unlocked by
  1385       // an explicit monitorexit bytecode.
  1386       __ delayed()->daddi(c_rarg0, FP, frame::interpreter_frame_initial_sp_offset * wordSize - (int)sizeof(BasicObjectLock));
  1387       // address of first monitor
  1389       __ ld(t, c_rarg0, BasicObjectLock::obj_offset_in_bytes());
  1390       __ bne(t, R0, unlock);
  1391       __ delayed()->nop();
  1393       // Entry already unlocked, need to throw exception
  1394       __ MacroAssembler::call_VM(NOREG, CAST_FROM_FN_PTR(address,
  1395       InterpreterRuntime::throw_illegal_monitor_state_exception));
  1396       __ should_not_reach_here();
  1398       __ bind(unlock);
  1399       __ unlock_object(c_rarg0);
  1401     __ bind(L);
  1404   // jvmti/jvmpi support
  1405   // Note: This must happen _after_ handling/throwing any exceptions since
  1406   //       the exception handler code notifies the runtime of method exits
  1407   //       too. If this happens before, method entry/exit notifications are
  1408   //       not properly paired (was bug - gri 11/22/99).
  1409   __ notify_method_exit(false, vtos, InterpreterMacroAssembler::NotifyJVMTI );
  1411   // restore potential result in V0:V1,
  1412   // call result handler to restore potential result in ST0 & handle result
  1413   //__ lw(V0, SP, 3 * wordSize);
  1414   //__ lw(V1, SP, 2 * wordSize);
  1415   //__ lwc1(F0, SP, 1 * wordSize);
  1416   //__ lwc1(F1, SP, 0 * wordSize);
  1417   //__ addi(SP, SP, 4 * wordSize);
  1418   __ move(V0, S1);
  1419   __ move(V1, S3);
  1420   __ dmtc1(S4, F0);
  1421   __ dmtc1(S2, F1);
  1422   __ ld(t, FP, (frame::interpreter_frame_result_handler_offset) * wordSize);
  1423   __ jalr(t);
  1424   __ delayed()->nop();
  1427   // remove activation
  1428   __ ld(SP, FP, frame::interpreter_frame_sender_sp_offset * wordSize); // get sender sp
  1429   __ ld(RA, FP, frame::interpreter_frame_return_addr_offset * wordSize); // get return address
  1430   __ ld(FP, FP, frame::interpreter_frame_sender_fp_offset * wordSize); // restore sender's fp
  1431   __ jr(RA);
  1432   __ delayed()->nop();
  1434 #ifndef CORE
  1435   if (inc_counter) {
  1436     // Handle overflow of counter and compile method
  1437     __ bind(invocation_counter_overflow);
  1438     generate_counter_overflow(&continue_after_compile);
  1439     // entry_point is the beginning of this
  1440     // function and checks again for compiled code
  1442 #endif
  1443   return entry_point;
  1446 //
  1447 // Generic interpreted method entry to (asm) interpreter
  1448 //
  1449 // Layout of frame just at the entry
  1450 //
  1451 //   [ argument word n-1  ] <--- sp
  1452 //     ...
  1453 //   [ argument word 0    ]
  1454 // assume Method* in Rmethod before call this method.
  1455 // prerequisites to the generated stub : the callee Method* in Rmethod
  1456 // note you must save the caller bcp before call the generated stub
  1457 //
  1458 address InterpreterGenerator::generate_normal_entry(bool synchronized) {
  1459   // determine code generation flags
  1460   bool inc_counter  = UseCompiler || CountCompiledCalls;
  1462   // Rmethod: Method*
  1463   // Rsender: sender 's sp
  1464   address entry_point = __ pc();
  1466   const Address invocation_counter(Rmethod,
  1467       in_bytes(MethodCounters::invocation_counter_offset() + InvocationCounter::counter_offset()));
  1469   // get parameter size (always needed)
  1470   __ ld(T3, Rmethod, in_bytes(Method::const_offset()));  //T3 --> Rmethod._constMethod
  1471   __ lhu(V0, T3, in_bytes(ConstMethod::size_of_parameters_offset()));
  1473   // Rmethod: Method*
  1474   // V0: size of parameters
  1475   // Rsender: sender 's sp ,could be different frome sp+ wordSize if we call via c2i
  1476   // get size of locals in words to T2
  1477   __ lhu(T2, T3, in_bytes(ConstMethod::size_of_locals_offset()));
  1478   // T2 = no. of additional locals, locals include parameters
  1479   __ dsub(T2, T2, V0);
  1481   // see if we've got enough room on the stack for locals plus overhead.
  1482   // Layout of frame at this point
  1483   //
  1484   // [ argument word n-1  ] <--- sp
  1485   //   ...
  1486   // [ argument word 0    ]
  1487   generate_stack_overflow_check();
  1488   // after this function, the layout of frame does not change
  1490   // compute beginning of parameters (LVP)
  1491   __ dsll(LVP, V0, LogBytesPerWord);
  1492   __ daddiu(LVP, LVP, (-1) * wordSize);
  1493   __ dadd(LVP, LVP, SP);
  1495   // T2 - # of additional locals
  1496   // allocate space for locals
  1497   // explicitly initialize locals
  1499     Label exit, loop;
  1500     __ beq(T2, R0, exit);
  1501     __ delayed()->nop();
  1503     __ bind(loop);
  1504     __ sd(R0, SP, -1 * wordSize);     // initialize local variables
  1505     __ daddiu(T2, T2, -1);               // until everything initialized
  1506     __ bne(T2, R0, loop);
  1507     __ delayed();
  1509     __ daddiu(SP, SP, (-1) * wordSize); //fill delay slot
  1511     __ bind(exit);
  1514   //
  1515   // [ local var m-1  ] <--- sp
  1516   //   ...
  1517   // [ local var 0  ]
  1518   // [ argument word n-1  ] <--- T0?
  1519   //   ...
  1520   // [ argument word 0    ] <--- LVP
  1522   // initialize fixed part of activation frame
  1524   generate_fixed_frame(false);
  1527   // after this function, the layout of frame is as following
  1528   //
  1529   // [ monitor block top        ] <--- sp ( the top monitor entry )
  1530   // [ byte code pointer        ] (if native, bcp = 0)
  1531   // [ constant pool cache      ]
  1532   // [ Method*                ]
  1533   // [ locals offset    ]
  1534   // [ sender's sp              ]
  1535   // [ sender's fp              ] <--- fp
  1536   // [ return address           ]
  1537   // [ local var m-1            ]
  1538   //   ...
  1539   // [ local var 0              ]
  1540   // [ argumnet word n-1        ] <--- ( sender's sp )
  1541   //   ...
  1542   // [ argument word 0          ] <--- LVP
  1545   // make sure method is not native & not abstract
  1546 #ifdef ASSERT
  1547   __ ld(AT, Rmethod, in_bytes(Method::access_flags_offset()));
  1549     Label L;
  1550     __ andi(T2, AT, JVM_ACC_NATIVE);
  1551     __ beq(T2, R0, L);
  1552     __ delayed()->nop();
  1553     __ stop("tried to execute native method as non-native");
  1554     __ bind(L);
  1557     Label L;
  1558     __ andi(T2, AT, JVM_ACC_ABSTRACT);
  1559     __ beq(T2, R0, L);
  1560     __ delayed()->nop();
  1561     __ stop("tried to execute abstract method in interpreter");
  1562     __ bind(L);
  1564 #endif
  1566   // Since at this point in the method invocation the exception handler
  1567   // would try to exit the monitor of synchronized methods which hasn't
  1568   // been entered yet, we set the thread local variable
  1569   // _do_not_unlock_if_synchronized to true. The remove_activation will
  1570   // check this flag.
  1572 #ifndef OPT_THREAD
  1573   Register thread = T8;
  1574   __ get_thread(thread);
  1575 #else
  1576   Register thread = TREG;
  1577 #endif
  1578   __ move(AT, (int)true);
  1579   __ sb(AT, thread, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
  1581 #ifndef CORE
  1583   // 2014/11/24 Fu
  1584   // mdp : T8
  1585   // tmp1: T9
  1586   // tmp2: T2
  1587    __ profile_parameters_type(T8, T9, T2);
  1589   // increment invocation count & check for overflow
  1590   Label invocation_counter_overflow;
  1591   Label profile_method;
  1592   Label profile_method_continue;
  1593   if (inc_counter) {
  1594     generate_counter_incr(&invocation_counter_overflow,
  1595                           &profile_method,
  1596                           &profile_method_continue);
  1597     if (ProfileInterpreter) {
  1598       __ bind(profile_method_continue);
  1602   Label continue_after_compile;
  1603   __ bind(continue_after_compile);
  1605 #endif // CORE
  1607   bang_stack_shadow_pages(false);
  1609   // reset the _do_not_unlock_if_synchronized flag
  1610 #ifndef OPT_THREAD
  1611   __ get_thread(thread);
  1612 #endif
  1613   __ sb(R0, thread, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
  1615   // check for synchronized methods
  1616   // Must happen AFTER invocation_counter check and stack overflow check,
  1617   // so method is not locked if overflows.
  1618   //
  1619   if (synchronized) {
  1620     // Allocate monitor and lock method
  1621     lock_method();
  1622   } else {
  1623     // no synchronization necessary
  1624 #ifdef ASSERT
  1625     { Label L;
  1626       __ lw(AT, Rmethod, in_bytes(Method::access_flags_offset()));
  1627       __ andi(T2, AT, JVM_ACC_SYNCHRONIZED);
  1628       __ beq(T2, R0, L);
  1629       __ delayed()->nop();
  1630       __ stop("method needs synchronization");
  1631       __ bind(L);
  1633 #endif
  1636   // layout of frame after lock_method
  1637   // [ monitor entry        ] <--- sp
  1638   //   ...
  1639   // [ monitor entry        ]
  1640   // [ monitor block top        ] ( the top monitor entry )
  1641   // [ byte code pointer        ] (if native, bcp = 0)
  1642   // [ constant pool cache      ]
  1643   // [ Method*                ]
  1644   // [ locals offset        ]
  1645   // [ sender's sp              ]
  1646   // [ sender's fp              ]
  1647   // [ return address           ] <--- fp
  1648   // [ local var m-1            ]
  1649   //   ...
  1650   // [ local var 0              ]
  1651   // [ argumnet word n-1        ] <--- ( sender's sp )
  1652   //   ...
  1653   // [ argument word 0          ] <--- LVP
  1656   // start execution
  1657 #ifdef ASSERT
  1659     Label L;
  1660     __ ld(AT, FP, frame::interpreter_frame_monitor_block_top_offset * wordSize);
  1661     __ beq(AT, SP, L);
  1662     __ delayed()->nop();
  1663     __ stop("broken stack frame setup in interpreter in native");
  1664     __ bind(L);
  1666 #endif
  1668   // jvmti/jvmpi support
  1669   __ notify_method_entry();
  1671   __ dispatch_next(vtos);
  1673   // invocation counter overflow
  1674   if (inc_counter) {
  1675     if (ProfileInterpreter) {
  1676       // We have decided to profile this method in the interpreter
  1677       __ bind(profile_method);
  1678       __ call_VM(noreg, CAST_FROM_FN_PTR(address,
  1679                  InterpreterRuntime::profile_method));
  1680       __ set_method_data_pointer_for_bcp();
  1681       __ get_method(Rmethod);
  1682       __ b(profile_method_continue);
  1683       __ delayed()->nop();
  1685     // Handle overflow of counter and compile method
  1686     __ bind(invocation_counter_overflow);
  1687     generate_counter_overflow(&continue_after_compile);
  1690   return entry_point;
  1693 // Entry points
  1694 //
  1695 // Here we generate the various kind of entries into the interpreter.
  1696 // The two main entry type are generic bytecode methods and native
  1697 // call method.  These both come in synchronized and non-synchronized
  1698 // versions but the frame layout they create is very similar. The
  1699 // other method entry types are really just special purpose entries
  1700 // that are really entry and interpretation all in one. These are for
  1701 // trivial methods like accessor, empty, or special math methods.
  1702 //
  1703 // When control flow reaches any of the entry types for the interpreter
  1704 // the following holds ->
  1705 //
  1706 // Arguments:
  1707 //
  1708 // Rmethod: Method*
  1709 // V0: receiver
  1710 //
  1711 //
  1712 // Stack layout immediately at entry
  1713 //
  1714 // [ parameter n-1      ] <--- sp
  1715 //   ...
  1716 // [ parameter 0        ]
  1717 // [ expression stack   ] (caller's java expression stack)
  1719 // Assuming that we don't go to one of the trivial specialized entries
  1720 // the stack will look like below when we are ready to execute the
  1721 // first bytecode (or call the native routine). The register usage
  1722 // will be as the template based interpreter expects (see
  1723 // interpreter_amd64.hpp).
  1724 //
  1725 // local variables follow incoming parameters immediately; i.e.
  1726 // the return address is moved to the end of the locals).
  1727 //
  1728 // [ monitor entry        ] <--- sp
  1729 //   ...
  1730 // [ monitor entry        ]
  1731 // [ monitor block top        ] ( the top monitor entry )
  1732 // [ byte code pointer        ] (if native, bcp = 0)
  1733 // [ constant pool cache      ]
  1734 // [ Method*                ]
  1735 // [ locals offset        ]
  1736 // [ sender's sp              ]
  1737 // [ sender's fp              ]
  1738 // [ return address           ] <--- fp
  1739 // [ local var m-1            ]
  1740 //   ...
  1741 // [ local var 0              ]
  1742 // [ argumnet word n-1        ] <--- ( sender's sp )
  1743 //   ...
  1744 // [ argument word 0          ] <--- S7
  1746 address AbstractInterpreterGenerator::generate_method_entry(
  1747                                         AbstractInterpreter::MethodKind kind) {
  1748   // determine code generation flags
  1749   bool synchronized = false;
  1750   address entry_point = NULL;
  1751   switch (kind) {
  1752     case Interpreter::zerolocals             :
  1753       break;
  1754     case Interpreter::zerolocals_synchronized:
  1755       synchronized = true;
  1756       break;
  1757     case Interpreter::native                 :
  1758       entry_point = ((InterpreterGenerator*)this)->generate_native_entry(false);
  1759       break;
  1760     case Interpreter::native_synchronized    :
  1761       entry_point = ((InterpreterGenerator*)this)->generate_native_entry(true);
  1762       break;
  1763     case Interpreter::empty                  :
  1764       entry_point = ((InterpreterGenerator*)this)->generate_empty_entry();
  1765       break;
  1766     case Interpreter::accessor               :
  1767       entry_point = ((InterpreterGenerator*)this)->generate_accessor_entry();
  1768       break;
  1769     case Interpreter::abstract               :
  1770       entry_point = ((InterpreterGenerator*)this)->generate_abstract_entry();
  1771       break;
  1773     case Interpreter::java_lang_math_sin     : // fall thru
  1774     case Interpreter::java_lang_math_cos     : // fall thru
  1775     case Interpreter::java_lang_math_tan     : // fall thru
  1776     case Interpreter::java_lang_math_log     : // fall thru
  1777     case Interpreter::java_lang_math_log10   : // fall thru
  1778     case Interpreter::java_lang_math_pow     : // fall thru
  1779     case Interpreter::java_lang_math_exp     : break;
  1780     case Interpreter::java_lang_math_abs     : // fall thru
  1781     case Interpreter::java_lang_math_sqrt    :
  1782       entry_point = ((InterpreterGenerator*)this)->generate_math_entry(kind);    break;
  1783     case Interpreter::java_lang_ref_reference_get:
  1784       entry_point = ((InterpreterGenerator*)this)->generate_Reference_get_entry(); break;
  1785     default:
  1786       fatal(err_msg("unexpected method kind: %d", kind));
  1787       break;
  1789   if (entry_point) return entry_point;
  1791   return ((InterpreterGenerator*)this)->generate_normal_entry(synchronized);
  1794 // These should never be compiled since the interpreter will prefer
  1795 // the compiled version to the intrinsic version.
  1796 bool AbstractInterpreter::can_be_compiled(methodHandle m) {
  1797   switch (method_kind(m)) {
  1798     case Interpreter::java_lang_math_sin     : // fall thru
  1799     case Interpreter::java_lang_math_cos     : // fall thru
  1800     case Interpreter::java_lang_math_tan     : // fall thru
  1801     case Interpreter::java_lang_math_abs     : // fall thru
  1802     case Interpreter::java_lang_math_log     : // fall thru
  1803     case Interpreter::java_lang_math_log10   : // fall thru
  1804     case Interpreter::java_lang_math_sqrt    : // fall thru
  1805     case Interpreter::java_lang_math_pow     : // fall thru
  1806     case Interpreter::java_lang_math_exp     :
  1807       return false;
  1808     default:
  1809       return true;
  1813 // How much stack a method activation needs in words.
  1814 int AbstractInterpreter::size_top_interpreter_activation(Method* method) {
  1816   const int entry_size    = frame::interpreter_frame_monitor_size();
  1818   // total overhead size: entry_size + (saved ebp thru expr stack bottom).
  1819   // be sure to change this if you add/subtract anything to/from the overhead area
  1820   const int overhead_size = -(frame::interpreter_frame_initial_sp_offset) + entry_size;
  1822   const int stub_code = 6;  // see generate_call_stub
  1823   // return overhead_size + method->max_locals() + method->max_stack() + stub_code;
  1824   const int method_stack = (method->max_locals() + method->max_stack()) *
  1825           Interpreter::stackElementWords;
  1826   return overhead_size + method_stack + stub_code;
  1829 void AbstractInterpreter::layout_activation(Method* method,
  1830                                            int tempcount,
  1831                                            int popframe_extra_args,
  1832                                            int moncount,
  1833                                            int caller_actual_parameters,
  1834                                            int callee_param_count,
  1835                                            int callee_locals,
  1836                                            frame* caller,
  1837                                            frame* interpreter_frame,
  1838                                            bool is_top_frame,
  1839                                            bool is_bottom_frame) {
  1840   // Note: This calculation must exactly parallel the frame setup
  1841   // in AbstractInterpreterGenerator::generate_method_entry.
  1842   // If interpreter_frame!=NULL, set up the method, locals, and monitors.
  1843   // The frame interpreter_frame, if not NULL, is guaranteed to be the
  1844   // right size, as determined by a previous call to this method.
  1845   // It is also guaranteed to be walkable even though it is in a skeletal state
  1847   // fixed size of an interpreter frame:
  1849   int max_locals = method->max_locals() * Interpreter::stackElementWords;
  1850   int extra_locals = (method->max_locals() - method->size_of_parameters()) * Interpreter::stackElementWords;
  1852 #ifdef ASSERT
  1853   if (!EnableInvokeDynamic) {
  1854     // @@@ FIXME: Should we correct interpreter_frame_sender_sp in the calling sequences?
  1855     // Probably, since deoptimization doesn't work yet.
  1856     assert(caller->unextended_sp() == interpreter_frame->interpreter_frame_sender_sp(), "Frame not properly walkable");
  1858   assert(caller->sp() == interpreter_frame->interpreter_frame_sender_sp(), "Frame not properly walkable(2)");
  1859 #endif
  1861     interpreter_frame->interpreter_frame_set_method(method);
  1862     // NOTE the difference in using sender_sp and interpreter_frame_sender_sp
  1863     // interpreter_frame_sender_sp is the original sp of the caller (the unextended_sp)
  1864     // and sender_sp is fp+8
  1865     intptr_t* locals = interpreter_frame->sender_sp() + max_locals - 1;
  1867 #ifdef ASSERT
  1868   if (caller->is_interpreted_frame()) {
  1869     assert(locals < caller->fp() + frame::interpreter_frame_initial_sp_offset, "bad placement");
  1871 #endif
  1873   interpreter_frame->interpreter_frame_set_locals(locals);
  1874   BasicObjectLock* montop = interpreter_frame->interpreter_frame_monitor_begin();
  1875   BasicObjectLock* monbot = montop - moncount;
  1876   interpreter_frame->interpreter_frame_set_monitor_end(montop - moncount);
  1878   //set last sp;
  1879   intptr_t*  esp = (intptr_t*) monbot - tempcount*Interpreter::stackElementWords -
  1880                       popframe_extra_args;
  1881   interpreter_frame->interpreter_frame_set_last_sp(esp);
  1882   // All frames but the initial interpreter frame we fill in have a
  1883   // value for sender_sp that allows walking the stack but isn't
  1884   // truly correct. Correct the value here.
  1885   //
  1886     if (extra_locals != 0 &&
  1887         interpreter_frame->sender_sp() == interpreter_frame->interpreter_frame_sender_sp() ) {
  1888       interpreter_frame->set_interpreter_frame_sender_sp(caller->sp() + extra_locals);
  1890     *interpreter_frame->interpreter_frame_cache_addr() = method->constants()->cache();
  1893 //-----------------------------------------------------------------------------
  1894 // Exceptions
  1896 void TemplateInterpreterGenerator::generate_throw_exception() {
  1897   // Entry point in previous activation (i.e., if the caller was
  1898   // interpreted)
  1899   Interpreter::_rethrow_exception_entry = __ pc();
  1900   // Restore sp to interpreter_frame_last_sp even though we are going
  1901   // to empty the expression stack for the exception processing.
  1902   __ sd(R0,FP, frame::interpreter_frame_last_sp_offset * wordSize);
  1904   // V0: exception
  1905   // V1: return address/pc that threw exception
  1906   __ restore_bcp();                              // esi points to call/send
  1907   __ restore_locals();
  1909   //add for compressedoops
  1910   __ reinit_heapbase();
  1911   // Entry point for exceptions thrown within interpreter code
  1912   Interpreter::_throw_exception_entry = __ pc();
  1913   // expression stack is undefined here
  1914   // V0: exception
  1915   // BCP: exception bcp
  1916   __ verify_oop(V0);
  1918   // expression stack must be empty before entering the VM in case of an exception
  1919   __ empty_expression_stack();
  1920   // find exception handler address and preserve exception oop
  1921   __ move(A1, V0);
  1922   __ call_VM(V1, CAST_FROM_FN_PTR(address, InterpreterRuntime::exception_handler_for_exception), A1);
  1923   // V0: exception handler entry point
  1924   // V1: preserved exception oop
  1925   // S0: bcp for exception handler
  1926   __ daddi(SP, SP, (-1) * wordSize);
  1927   __ sd(V1, SP, 0);                              // push exception which is now the only value on the stack
  1928   __ jr(V0);                                   // jump to exception handler (may be _remove_activation_entry!)
  1929   __ delayed()->nop();
  1931   // If the exception is not handled in the current frame the frame is removed and
  1932   // the exception is rethrown (i.e. exception continuation is _rethrow_exception).
  1933   //
  1934   // Note: At this point the bci is still the bxi for the instruction which caused
  1935   //       the exception and the expression stack is empty. Thus, for any VM calls
  1936   //       at this point, GC will find a legal oop map (with empty expression stack).
  1938   // In current activation
  1939   // V0: exception
  1940   // BCP: exception bcp
  1942   //
  1943   // JVMTI PopFrame support
  1944   //
  1946   Interpreter::_remove_activation_preserving_args_entry = __ pc();
  1947   __ empty_expression_stack();
  1948   // Set the popframe_processing bit in pending_popframe_condition indicating that we are
  1949   // currently handling popframe, so that call_VMs that may happen later do not trigger new
  1950   // popframe handling cycles.
  1951 #ifndef OPT_THREAD
  1952   Register thread = T2;
  1953   __ get_thread(T2);
  1954 #else
  1955   Register thread = TREG;
  1956 #endif
  1957   __ lw(T3, thread, in_bytes(JavaThread::popframe_condition_offset()));
  1958   __ ori(T3, T3, JavaThread::popframe_processing_bit);
  1959   __ sw(T3, thread, in_bytes(JavaThread::popframe_condition_offset()));
  1961 #ifndef CORE
  1963     // Check to see whether we are returning to a deoptimized frame.
  1964     // (The PopFrame call ensures that the caller of the popped frame is
  1965     // either interpreted or compiled and deoptimizes it if compiled.)
  1966     // In this case, we can't call dispatch_next() after the frame is
  1967     // popped, but instead must save the incoming arguments and restore
  1968     // them after deoptimization has occurred.
  1969     //
  1970     // Note that we don't compare the return PC against the
  1971     // deoptimization blob's unpack entry because of the presence of
  1972     // adapter frames in C2.
  1973     Label caller_not_deoptimized;
  1974     __ ld(A0, FP, frame::return_addr_offset * wordSize);
  1975     __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::interpreter_contains), A0);
  1976     __ bne(V0, R0, caller_not_deoptimized);
  1977     __ delayed()->nop();
  1979     // Compute size of arguments for saving when returning to deoptimized caller
  1980     __ get_method(A1);
  1981     __ verify_oop(A1);
  1982     __ ld(A1,A1,in_bytes(Method::const_offset()));
  1983     __ lhu(A1, A1, in_bytes(ConstMethod::size_of_parameters_offset()));
  1984     __ shl(A1, Interpreter::logStackElementSize);
  1985     __ restore_locals();
  1986     __ dsub(A2, LVP, T0);
  1987     __ daddiu(A2, A2, wordSize);
  1988     // Save these arguments
  1989 #ifndef OPT_THREAD
  1990     __ get_thread(A0);
  1991 #else
  1992     __ move(A0, TREG);
  1993 #endif
  1994     __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, Deoptimization::popframe_preserve_args), A0, A1, A2);
  1996     __ remove_activation(vtos, T9, false, false, false);
  1998     // Inform deoptimization that it is responsible for restoring these arguments
  1999 #ifndef OPT_THREAD
  2000     __ get_thread(thread);
  2001 #endif
  2002     __ move(AT, JavaThread::popframe_force_deopt_reexecution_bit);
  2003     __ sw(AT, thread, in_bytes(JavaThread::popframe_condition_offset()));
  2004     // Continue in deoptimization handler
  2005     __ jr(T9);
  2006     __ delayed()->nop();
  2008     __ bind(caller_not_deoptimized);
  2010 #endif /* !CORE */
  2012   __ remove_activation(vtos, T3,
  2013                        /* throw_monitor_exception */ false,
  2014                        /* install_monitor_exception */ false,
  2015                        /* notify_jvmdi */ false);
  2017   // Clear the popframe condition flag
  2018   // Finish with popframe handling
  2019   // A previous I2C followed by a deoptimization might have moved the
  2020   // outgoing arguments further up the stack. PopFrame expects the
  2021   // mutations to those outgoing arguments to be preserved and other
  2022   // constraints basically require this frame to look exactly as
  2023   // though it had previously invoked an interpreted activation with
  2024   // no space between the top of the expression stack (current
  2025   // last_sp) and the top of stack. Rather than force deopt to
  2026   // maintain this kind of invariant all the time we call a small
  2027   // fixup routine to move the mutated arguments onto the top of our
  2028   // expression stack if necessary.
  2029   __ move(T8, SP);
  2030   __ ld(A2, FP, frame::interpreter_frame_last_sp_offset * wordSize);
  2031 #ifndef OPT_THREAD
  2032   __ get_thread(thread);
  2033 #endif
  2034   // PC must point into interpreter here
  2035   __ set_last_Java_frame(thread, noreg, FP, __ pc());
  2036   __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::popframe_move_outgoing_args), thread, T8, A2);
  2037   __ reset_last_Java_frame(thread, true, true);
  2038   // Restore the last_sp and null it out
  2039   __ ld(SP, FP, frame::interpreter_frame_last_sp_offset * wordSize);
  2040   __ sd(R0, FP, frame::interpreter_frame_last_sp_offset * wordSize);
  2044   __ move(AT, JavaThread::popframe_inactive);
  2045   __ sw(AT, thread, in_bytes(JavaThread::popframe_condition_offset()));
  2047   // Finish with popframe handling
  2048   __ restore_bcp();
  2049   __ restore_locals();
  2050 #ifndef CORE
  2051   // The method data pointer was incremented already during
  2052   // call profiling. We have to restore the mdp for the current bcp.
  2053   if (ProfileInterpreter) {
  2054     __ set_method_data_pointer_for_bcp();
  2056 #endif // !CORE
  2057   // Clear the popframe condition flag
  2058 #ifndef OPT_THREAD
  2059   __ get_thread(thread);
  2060 #endif
  2061   __ move(AT, JavaThread::popframe_inactive);
  2062   __ sw(AT, thread, in_bytes(JavaThread::popframe_condition_offset()));
  2063   __ dispatch_next(vtos);
  2064   // end of PopFrame support
  2066   Interpreter::_remove_activation_entry = __ pc();
  2068   // preserve exception over this code sequence
  2069   __ ld(T0, SP, 0);
  2070   __ daddi(SP, SP, wordSize);
  2071 #ifndef OPT_THREAD
  2072   __ get_thread(thread);
  2073 #endif
  2074   __ sd(T0, thread, in_bytes(JavaThread::vm_result_offset()));
  2075   // remove the activation (without doing throws on illegalMonitorExceptions)
  2076   __ remove_activation(vtos, T3, false, true, false);
  2077   // restore exception
  2078   __ get_vm_result(T0, thread);
  2079   __ verify_oop(T0);
  2081   // Inbetween activations - previous activation type unknown yet
  2082   // compute continuation point - the continuation point expects
  2083   // the following registers set up:
  2084   //
  2085   // T0: exception                                eax
  2086   // T1: return address/pc that threw exception    edx
  2087   // SP: expression stack of caller      esp
  2088   // FP: ebp of caller          ebp
  2089   __ daddi(SP, SP, (-2) * wordSize);
  2090   __ sd(T0, SP, wordSize);      // save exception
  2091   __ sd(T3, SP, 0);                               // save return address
  2092   __ move(A1, T3);
  2093   __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address), thread, A1);
  2094   __ move(T9, V0);                             // save exception handler
  2095   __ ld(V0, SP, wordSize);        // restore exception
  2096   __ ld(V1, SP, 0);                               // restore return address
  2097   __ daddi(SP, SP, 2 * wordSize);
  2099   // Note that an "issuing PC" is actually the next PC after the call
  2100   __ jr(T9);                                   // jump to exception handler of caller
  2101   __ delayed()->nop();
  2105 //
  2106 // JVMTI ForceEarlyReturn support
  2107 //
  2108 address TemplateInterpreterGenerator::generate_earlyret_entry_for(TosState state) {
  2109   address entry = __ pc();
  2110   __ restore_bcp();
  2111   __ restore_locals();
  2112   __ empty_expression_stack();
  2113   __ empty_FPU_stack();
  2114   __ load_earlyret_value(state);
  2116 #ifndef OPT_THREAD
  2117   __ get_thread(TREG);
  2118 #endif
  2119    __ ld_ptr(T9, TREG, in_bytes(JavaThread::jvmti_thread_state_offset()));
  2120   //const Address cond_addr(ecx, JvmtiThreadState::earlyret_state_offset());
  2121   const Address cond_addr(T9, in_bytes(JvmtiThreadState::earlyret_state_offset()));
  2122   // Clear the earlyret state
  2123     __ move(AT,JvmtiThreadState::earlyret_inactive);
  2124     __ sw(AT,cond_addr);
  2125     __ sync();
  2128     __ remove_activation(state, T0,
  2129                          false, /* throw_monitor_exception */
  2130                          false, /* install_monitor_exception */
  2131                          true); /* notify_jvmdi */
  2132     __ sync();
  2133     __ jr(T0);
  2134     __ delayed()->nop();
  2135   return entry;
  2136 } // end of ForceEarlyReturn support
  2139 //-----------------------------------------------------------------------------
  2140 // Helper for vtos entry point generation
  2142 void TemplateInterpreterGenerator::set_vtos_entry_points(Template* t,
  2143                                                          address& bep,
  2144                                                          address& cep,
  2145                                                          address& sep,
  2146                                                          address& aep,
  2147                                                          address& iep,
  2148                                                          address& lep,
  2149                                                          address& fep,
  2150                                                          address& dep,
  2151                                                          address& vep) {
  2152   assert(t->is_valid() && t->tos_in() == vtos, "illegal template");
  2153   Label L;
  2154   fep = __ pc(); __ push(ftos); __ b(L); __ delayed()->nop();
  2155   dep = __ pc(); __ push(dtos); __ b(L); __ delayed()->nop();
  2156   lep = __ pc(); __ push(ltos); __ b(L); __ delayed()->nop();
  2157   aep  =__ pc(); __ push(atos); __ b(L); __ delayed()->nop();
  2158   bep = cep = sep =
  2159   iep = __ pc(); __ push(itos);
  2160   vep = __ pc();
  2161   __ bind(L);
  2162   generate_and_dispatch(t);
  2166 //-----------------------------------------------------------------------------
  2167 // Generation of individual instructions
  2169 // helpers for generate_and_dispatch
  2172 InterpreterGenerator::InterpreterGenerator(StubQueue* code)
  2173   : TemplateInterpreterGenerator(code) {
  2174    generate_all(); // down here so it can be "virtual"
  2177 //-----------------------------------------------------------------------------
  2179 // Non-product code
  2180 #ifndef PRODUCT
  2181 address TemplateInterpreterGenerator::generate_trace_code(TosState state) {
  2182   address entry = __ pc();
  2184   // prepare expression stack
  2185   __ push(state);       // save tosca
  2187   // tos & tos2, added by yjl 7/15/2005
  2188   // trace_bytecode need actually 4 args, the last two is tos&tos2
  2189   // this work fine for x86. but mips o32 call convention will store A2-A3
  2190   // to the stack position it think is the tos&tos2
  2191   // when the expression stack have no more than 2 data, error occur.
  2192   __ ld(A2, SP, 0);
  2193   __ ld(A3, SP, 1 * wordSize);
  2195   // pass arguments & call tracer
  2196   __ call_VM(noreg, CAST_FROM_FN_PTR(address, SharedRuntime::trace_bytecode), RA, A2, A3);
  2197   __ move(RA, V0);    // make sure return address is not destroyed by pop(state)
  2199   // restore expression stack
  2200   __ pop(state);        // restore tosca
  2202   // return
  2203   __ jr(RA);
  2204   __ delayed()->nop();
  2206   return entry;
  2209 void TemplateInterpreterGenerator::count_bytecode() {
  2210   __ li(T8, (long)&BytecodeCounter::_counter_value);
  2211   __ lw(AT, T8, 0);
  2212   __ daddi(AT, AT, 1);
  2213   __ sw(AT, T8, 0);
  2216 void TemplateInterpreterGenerator::histogram_bytecode(Template* t) {
  2217   __ li(T8, (long)&BytecodeHistogram::_counters[t->bytecode()]);
  2218   __ lw(AT, T8, 0);
  2219   __ daddi(AT, AT, 1);
  2220   __ sw(AT, T8, 0);
  2223 void TemplateInterpreterGenerator::histogram_bytecode_pair(Template* t) {
  2224   __ li(T8, (long)&BytecodePairHistogram::_index);
  2225   __ lw(T9, T8, 0);
  2226   __ dsrl(T9, T9, BytecodePairHistogram::log2_number_of_codes);
  2227   __ li(T8, ((long)t->bytecode()) << BytecodePairHistogram::log2_number_of_codes);
  2228   __ orr(T9, T9, T8);
  2229   __ li(T8, (long)&BytecodePairHistogram::_index);
  2230   __ sw(T9, T8, 0);
  2231   __ dsll(T9, T9, 2);
  2232   __ li(T8, (long)BytecodePairHistogram::_counters);
  2233   __ dadd(T8, T8, T9);
  2234   __ lw(AT, T8, 0);
  2235   __ daddi(AT, AT, 1);
  2236   __ sw(AT, T8, 0);
  2240 void TemplateInterpreterGenerator::trace_bytecode(Template* t) {
  2241   // Call a little run-time stub to avoid blow-up for each bytecode.
  2242   // The run-time runtime saves the right registers, depending on
  2243   // the tosca in-state for the given template.
  2245   address entry = Interpreter::trace_code(t->tos_in());
  2246   assert(entry != NULL, "entry must have been generated");
  2247   __ call(entry, relocInfo::none);
  2248   __ delayed()->nop();
  2249   //add for compressedoops
  2250   __ reinit_heapbase();
  2254 void TemplateInterpreterGenerator::stop_interpreter_at() {
  2255   Label L;
  2256   __ li(T8, long(&BytecodeCounter::_counter_value));
  2257   __ lw(T8, T8, 0);
  2258   __ move(AT, StopInterpreterAt);
  2259   __ bne(T8, AT, L);
  2260   __ delayed()->nop();
  2261   __ call(CAST_FROM_FN_PTR(address, os::breakpoint), relocInfo::runtime_call_type);
  2262   __ delayed()->nop();
  2263   __ bind(L);
  2265 #endif // !PRODUCT
  2266 #endif // ! CC_INTERP

mercurial