src/cpu/mips/vm/templateInterpreter_mips_64.cpp

Tue, 26 Sep 2017 15:22:25 +0800

author
fujie
date
Tue, 26 Sep 2017 15:22:25 +0800
changeset 6895
34448c1bea2d
parent 6894
c3f0dbba118a
child 6896
ada5000bdb38
permissions
-rw-r--r--

[Interpreter] Optimize method entry point and TemplateTable::branch(...)

     1 /*
     2  * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * Copyright (c) 2015, 2016, Loongson Technology. All rights reserved.
     4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5  *
     6  * This code is free software; you can redistribute it and/or modify it
     7  * under the terms of the GNU General Public License version 2 only, as
     8  * published by the Free Software Foundation.
     9  *
    10  * This code is distributed in the hope that it will be useful, but WITHOUT
    11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    13  * version 2 for more details (a copy is included in the LICENSE file that
    14  * accompanied this code).
    15  *
    16  * You should have received a copy of the GNU General Public License version
    17  * 2 along with this work; if not, write to the Free Software Foundation,
    18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    19  *
    20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    21  * or visit www.oracle.com if you need additional information or have any
    22  * questions.
    23  *
    24  */
    26 #include "precompiled.hpp"
    27 #include "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(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(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   __ beq(R0, R0, *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, 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     __ dsrl(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     //stos
   705     __ bind(notByte);
   706     __ daddi(T1, T3, (-1) * stos);
   707     __ bne(T1, R0, notShort);
   708     __ delayed()->nop();
   709     __ lh(V0, T0, 0);
   710     __ b(xreturn_path);
   711     __ delayed()->nop();
   713     //ctos
   714     __ bind(notShort);
   715     __ daddi(T1, T3, (-1) * ctos);
   716     __ bne(T1, R0, notChar);
   717     __ delayed()->nop();
   718     __ lhu(V0, T0, 0);
   719     __ b(xreturn_path);
   720     __ delayed()->nop();
   722     //atos
   723     __ bind(notChar);
   724     __ daddi(T1, T3, (-1) * atos);
   725     __ bne(T1, R0, notObj);
   726     __ delayed()->nop();
   727     //add for compressedoops
   728     __ load_heap_oop(V0, Address(T0, 0));
   729     __ b(xreturn_path);
   730     __ delayed()->nop();
   732     //itos
   733     __ bind(notObj);
   734 #ifdef ASSERT
   735     Label okay;
   736     __ daddi(T1, T3, (-1) * itos);
   737     __ beq(T1, R0, okay);
   738     __ delayed()->nop();
   739     __ stop("what type is this?");
   740     __ bind(okay);
   741 #endif // ASSERT
   742     __ lw(V0, T0, 0);
   744     __ bind(xreturn_path);
   746     // _ireturn/_areturn
   747     //FIXME
   748     __ move(SP, Rsender);//FIXME, set sender's fp to SP
   749     __ jr(RA);
   750     __ delayed()->nop();
   752     // generate a vanilla interpreter entry as the slow path
   753     __ bind(slow_path);
   754     (void) generate_normal_entry(false);
   755   } else {
   756     (void) generate_normal_entry(false);
   757   }
   759   return entry_point;
   760 }
   762 // Method entry for java.lang.ref.Reference.get.
   763 address InterpreterGenerator::generate_Reference_get_entry(void) {
   764 #if INCLUDE_ALL_GCS
   765   // Code: _aload_0, _getfield, _areturn
   766   // parameter size = 1
   767   //
   768   // The code that gets generated by this routine is split into 2 parts:
   769   //    1. The "intrinsified" code for G1 (or any SATB based GC),
   770   //    2. The slow path - which is an expansion of the regular method entry.
   771   //
   772   // Notes:-
   773   // * In the G1 code we do not check whether we need to block for
   774   //   a safepoint. If G1 is enabled then we must execute the specialized
   775   //   code for Reference.get (except when the Reference object is null)
   776   //   so that we can log the value in the referent field with an SATB
   777   //   update buffer.
   778   //   If the code for the getfield template is modified so that the
   779   //   G1 pre-barrier code is executed when the current method is
   780   //   Reference.get() then going through the normal method entry
   781   //   will be fine.
   782   // * The G1 code can, however, check the receiver object (the instance
   783   //   of java.lang.Reference) and jump to the slow path if null. If the
   784   //   Reference object is null then we obviously cannot fetch the referent
   785   //   and so we don't need to call the G1 pre-barrier. Thus we can use the
   786   //   regular method entry code to generate the NPE.
   787   //
   788   // This code is based on generate_accessor_enty.
   789   //
   790   // rbx: Method*
   792   // r13: senderSP must preserve for slow path, set SP to it on fast path
   794   address entry = __ pc();
   796   const int referent_offset = java_lang_ref_Reference::referent_offset;
   797   guarantee(referent_offset > 0, "referent offset not initialized");
   799   if (UseG1GC) {
   800     Unimplemented();
   801     Label slow_path;
   802     // rbx: method
   804     // Check if local 0 != NULL
   805     // If the receiver is null then it is OK to jump to the slow path.
   807     // rax: local 0
   808     // rbx: method (but can be used as scratch now)
   809     // rdx: scratch
   810     // rdi: scratch
   812     // Generate the G1 pre-barrier code to log the value of
   813     // the referent field in an SATB buffer.
   815     // Load the value of the referent field.
   817     return entry;
   818   }
   819 #endif // INCLUDE_ALL_GCS
   821   // If G1 is not enabled then attempt to go through the accessor entry point
   822   // Reference.get is an accessor
   823   return generate_accessor_entry();
   824 }
   825 // Interpreter stub for calling a native method. (asm interpreter)
   826 // This sets up a somewhat different looking stack for calling the
   827 // native method than the typical interpreter frame setup.
   828 address InterpreterGenerator::generate_native_entry(bool synchronized) {
   829   // determine code generation flags
   830   bool inc_counter  = UseCompiler || CountCompiledCalls;
   831   // Rsender: sender's sp
   832   // Rmethod: Method*
   833   address entry_point = __ pc();
   835 #ifndef CORE
   836   const Address invocation_counter(Rmethod,in_bytes(MethodCounters::invocation_counter_offset() +   // Fu: 20130814
   837   InvocationCounter::counter_offset()));
   838 #endif
   840   // get parameter size (always needed)
   841   // the size in the java stack
   842   __ ld(V0, Rmethod, in_bytes(Method::const_offset()));
   843   __ lhu(V0, V0, in_bytes(ConstMethod::size_of_parameters_offset()));   // Fu: 20130814
   845   // native calls don't need the stack size check since they have no expression stack
   846   // and the arguments are already on the stack and we only add a handful of words
   847   // to the stack
   849   // Rmethod: Method*
   850   // V0: size of parameters
   851   // Layout of frame at this point
   852   //
   853   // [ argument word n-1  ] <--- sp
   854   //   ...
   855   // [ argument word 0    ]
   857   // for natives the size of locals is zero
   859   // compute beginning of parameters (S7)
   860   __ dsll(LVP, V0, Address::times_8);
   861   __ daddiu(LVP, LVP, (-1) * wordSize);
   862   __ dadd(LVP, LVP, SP);
   865   // add 2 zero-initialized slots for native calls
   866   __ daddi(SP, SP, (-2) * wordSize);
   867   __ sd(R0, SP, 1 * wordSize);  // slot for native oop temp offset (setup via runtime)
   868   __ sd(R0, SP, 0 * wordSize);  // slot for static native result handler3 (setup via runtime)
   870   // Layout of frame at this point
   871   // [ method holder mirror  ] <--- sp
   872   // [ result type info      ]
   873   // [ argument word n-1     ] <--- T0
   874   //   ...
   875   // [ argument word 0      ] <--- LVP
   878 #ifndef CORE
   879   if (inc_counter) __ lw(T3, invocation_counter);  // (pre-)fetch invocation count
   880 #endif
   882   // initialize fixed part of activation frame
   883   generate_fixed_frame(true);
   884   // after this function, the layout of frame is as following
   885   //
   886   // [ monitor block top        ] <--- sp ( the top monitor entry )
   887   // [ byte code pointer (0)    ] (if native, bcp = 0)
   888   // [ constant pool cache      ]
   889   // [ Method*                ]
   890   // [ locals offset            ]
   891   // [ sender's sp              ]
   892   // [ sender's fp              ]
   893   // [ return address           ] <--- fp
   894   // [ method holder mirror     ]
   895   // [ result type info         ]
   896   // [ argumnet word n-1        ] <--- sender's sp
   897   //   ...
   898   // [ argument word 0          ] <--- S7
   901   // make sure method is native & not abstract
   902 #ifdef ASSERT
   903   __ lw(T0, Rmethod, in_bytes(Method::access_flags_offset()));
   904   {
   905     Label L;
   906     __ andi(AT, T0, JVM_ACC_NATIVE);
   907     __ bne(AT, R0, L);
   908     __ delayed()->nop();
   909     __ stop("tried to execute native method as non-native");
   910     __ bind(L);
   911   }
   912   {
   913     Label L;
   914     __ andi(AT, T0, JVM_ACC_ABSTRACT);
   915     __ beq(AT, R0, L);
   916     __ delayed()->nop();
   917     __ stop("tried to execute abstract method in interpreter");
   918     __ bind(L);
   919   }
   920 #endif
   922   // Since at this point in the method invocation the exception handler
   923   // would try to exit the monitor of synchronized methods which hasn't
   924   // been entered yet, we set the thread local variable
   925   // _do_not_unlock_if_synchronized to true. The remove_activation will
   926   // check this flag.
   927   Register thread = TREG;
   928 #ifndef OPT_THREAD
   929   __ get_thread(thread);
   930 #endif
   931   __ move(AT, (int)true);
   932   __ sb(AT, thread, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
   934 #ifndef CORE
   935   // increment invocation count & check for overflow
   936   Label invocation_counter_overflow;
   937   if (inc_counter) {
   938     generate_counter_incr(&invocation_counter_overflow, NULL, NULL);
   939   }
   941   Label continue_after_compile;
   942   __ bind(continue_after_compile);
   943 #endif // CORE
   945   bang_stack_shadow_pages(true);
   947   // reset the _do_not_unlock_if_synchronized flag
   948 #ifndef OPT_THREAD
   949   __ get_thread(thread);
   950 #endif
   951   __ sb(R0, thread, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
   953   // check for synchronized methods
   954   // Must happen AFTER invocation_counter check and stack overflow check,
   955   // so method is not locked if overflows.
   956   if (synchronized) {
   957     lock_method();
   958   } else {
   959     // no synchronization necessary
   960 #ifdef ASSERT
   961     {
   962       Label L;
   963       __ lw(T0, Rmethod, in_bytes(Method::access_flags_offset()));
   964       __ andi(AT, T0, JVM_ACC_SYNCHRONIZED);
   965       __ beq(AT, R0, L);
   966       __ delayed()->nop();
   967       __ stop("method needs synchronization");
   968       __ bind(L);
   969     }
   970 #endif
   971   }
   973   // after method_lock, the layout of frame is as following
   974   //
   975   // [ monitor entry            ] <--- sp
   976   //   ...
   977   // [ monitor entry            ]
   978   // [ monitor block top        ] ( the top monitor entry )
   979   // [ byte code pointer (0)    ] (if native, bcp = 0)
   980   // [ constant pool cache      ]
   981   // [ Method*                ]
   982   // [ locals offset        ]
   983   // [ sender's sp              ]
   984   // [ sender's fp              ]
   985   // [ return address           ] <--- fp
   986   // [ method holder mirror     ]
   987   // [ result type info         ]
   988   // [ argumnet word n-1        ] <--- ( sender's sp )
   989   //   ...
   990   // [ argument word 0          ] <--- S7
   992   // start execution
   993 #ifdef ASSERT
   994   {
   995     Label L;
   996     __ ld(AT, FP, frame::interpreter_frame_monitor_block_top_offset * wordSize);
   997     __ beq(AT, SP, L);
   998     __ delayed()->nop();
   999     __ stop("broken stack frame setup in interpreter in asm");
  1000     __ bind(L);
  1002 #endif
  1004   // jvmti/jvmpi support
  1005   __ notify_method_entry();
  1007   // work registers
  1008   const Register method = Rmethod;
  1009   //const Register thread = T2;
  1010   const Register t      = RT4;
  1012   __ get_method(method);
  1013   __ verify_oop(method);
  1015     Label L, Lstatic;
  1016     __ ld(t,method,in_bytes(Method::const_offset()));
  1017     __ lhu(t, t, in_bytes(ConstMethod::size_of_parameters_offset()));  // Fu: 20130814
  1018     // MIPS n64 ABI: caller does not reserve space for the register auguments.
  1019     //FIXME, aoqi: A1?
  1020     // A0 and A1(if needed)
  1021     __ lw(AT, Rmethod, in_bytes(Method::access_flags_offset()));
  1022     __ andi(AT, AT, JVM_ACC_STATIC);
  1023     __ beq(AT, R0, Lstatic);
  1024     __ delayed()->nop();
  1025     __ daddiu(t, t, 1);
  1026     __ bind(Lstatic);
  1027     __ daddiu(t, t, -7);
  1028     __ blez(t, L);
  1029     __ delayed()->nop();
  1030     __ dsll(t, t, Address::times_8);
  1031     __ dsub(SP, SP, t);
  1032     __ bind(L);
  1034   __ move(AT, -(StackAlignmentInBytes));
  1035   __ andr(SP, SP, AT);
  1036   __ move(AT, SP);
  1037   // [        ] <--- sp
  1038   //   ...                        (size of parameters - 8 )
  1039   // [ monitor entry            ]
  1040   //   ...
  1041   // [ monitor entry            ]
  1042   // [ monitor block top        ] ( the top monitor entry )
  1043   // [ byte code pointer (0)    ] (if native, bcp = 0)
  1044   // [ constant pool cache      ]
  1045   // [ Method*                ]
  1046   // [ locals offset            ]
  1047   // [ sender's sp              ]
  1048   // [ sender's fp              ]
  1049   // [ return address           ] <--- fp
  1050   // [ method holder mirror     ]
  1051   // [ result type info         ]
  1052   // [ argumnet word n-1        ] <--- ( sender's sp )
  1053   //   ...
  1054   // [ argument word 0          ] <--- LVP
  1056   // get signature handler
  1058     Label L;
  1059     __ ld(T9, method, in_bytes(Method::signature_handler_offset()));
  1060     __ bne(T9, R0, L);
  1061     __ delayed()->nop();
  1062     __ call_VM(NOREG, CAST_FROM_FN_PTR(address,
  1063                InterpreterRuntime::prepare_native_call), method);
  1064     __ get_method(method);
  1065     __ ld(T9, method, in_bytes(Method::signature_handler_offset()));
  1066     __ bind(L);
  1069   // call signature handler
  1070   // FIXME: when change codes in InterpreterRuntime, note this point
  1071   // from: begin of parameters
  1072   assert(InterpreterRuntime::SignatureHandlerGenerator::from() == LVP, "adjust this code");
  1073   // to: current sp
  1074   assert(InterpreterRuntime::SignatureHandlerGenerator::to  () == SP, "adjust this code");
  1075   // temp: T3
  1076   assert(InterpreterRuntime::SignatureHandlerGenerator::temp() == t  , "adjust this code");
  1078   __ jalr(T9);
  1079   __ delayed()->nop();
  1080   __ get_method(method);  // slow path call blows EBX on DevStudio 5.0
  1082   /*
  1083      if native function is static, and its second parameter has type length of double word,
  1084      and first parameter has type length of word, we have to reserve one word
  1085      for the first parameter, according to mips o32 abi.
  1086      if native function is not static, and its third parameter has type length of double word,
  1087      and second parameter has type length of word, we have to reserve one word for the second
  1088      parameter.
  1089    */
  1092   // result handler is in V0
  1093   // set result handler
  1094   __ sd(V0, FP, (frame::interpreter_frame_result_handler_offset)*wordSize);
  1096 #define FIRSTPARA_SHIFT_COUNT 5
  1097 #define SECONDPARA_SHIFT_COUNT 9
  1098 #define THIRDPARA_SHIFT_COUNT 13
  1099 #define PARA_MASK  0xf
  1101   // pass mirror handle if static call
  1103     Label L;
  1104     const int mirror_offset = in_bytes(Klass::java_mirror_offset());
  1105     __ lw(t, method, in_bytes(Method::access_flags_offset()));
  1106     __ andi(AT, t, JVM_ACC_STATIC);
  1107     __ beq(AT, R0, L);
  1108     __ delayed()->nop();
  1110     // get mirror
  1111     __ ld(t, method, in_bytes(Method:: const_offset()));
  1112     __ ld(t, t, in_bytes(ConstMethod::constants_offset())); //??
  1113     __ ld(t, t, ConstantPool::pool_holder_offset_in_bytes());
  1114     __ ld(t, t, mirror_offset);
  1115     // copy mirror into activation frame
  1116     //__ sw(t, FP, frame::interpreter_frame_oop_temp_offset * wordSize);
  1117     // pass handle to mirror
  1118     __ sd(t, FP, frame::interpreter_frame_oop_temp_offset * wordSize);
  1119     __ daddi(t, FP, frame::interpreter_frame_oop_temp_offset * wordSize);
  1120     __ move(A1, t);
  1121     __ bind(L);
  1124   // [ mthd holder mirror ptr   ] <--- sp  --------------------| (only for static method)
  1125   // [                          ]                              |
  1126   //   ...                        size of parameters(or +1)    |
  1127   // [ monitor entry            ]                              |
  1128   //   ...                                                     |
  1129   // [ monitor entry            ]                              |
  1130   // [ monitor block top        ] ( the top monitor entry )    |
  1131   // [ byte code pointer (0)    ] (if native, bcp = 0)         |
  1132   // [ constant pool cache      ]                              |
  1133   // [ Method*                ]                              |
  1134   // [ locals offset            ]                              |
  1135   // [ sender's sp              ]                              |
  1136   // [ sender's fp              ]                              |
  1137   // [ return address           ] <--- fp                      |
  1138   // [ method holder mirror     ] <----------------------------|
  1139   // [ result type info         ]
  1140   // [ argumnet word n-1        ] <--- ( sender's sp )
  1141   //   ...
  1142   // [ argument word 0          ] <--- S7
  1144   // get native function entry point
  1145   { Label L;
  1146     __ ld(T9, method, in_bytes(Method::native_function_offset()));
  1147     __ li(V1, SharedRuntime::native_method_throw_unsatisfied_link_error_entry());
  1148     __ bne(V1, T9, L);
  1149     __ delayed()->nop();
  1150     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), method);
  1151     __ get_method(method);
  1152     __ verify_oop(method);
  1153     __ ld(T9, method, in_bytes(Method::native_function_offset()));
  1154     __ bind(L);
  1156   /*
  1157   __ pushad();
  1158   __ move(A0, T9);
  1159   __ call(CAST_FROM_FN_PTR(address, SharedRuntime::func_debug),relocInfo::runtime_call_type);
  1160   __ popad();
  1161   */
  1163   // pass JNIEnv
  1164   // native function in T9
  1165 #ifndef OPT_THREAD
  1166   __ get_thread(thread);
  1167 #endif
  1168   __ daddi(t, thread, in_bytes(JavaThread::jni_environment_offset()));
  1169   // stack,but I think it won't work when pass float,double etc @jerome,10/17,2006
  1170   __ move(A0, t);
  1171   // [ jni environment          ] <--- sp
  1172   // [ mthd holder mirror ptr   ] ---------------------------->| (only for static method)
  1173   // [                          ]                              |
  1174   //   ...                        size of parameters           |
  1175   // [ monitor entry            ]                              |
  1176   //   ...                                                     |
  1177   // [ monitor entry            ]                              |
  1178   // [ monitor block top        ] ( the top monitor entry )    |
  1179   // [ byte code pointer (0)    ] (if native, bcp = 0)         |
  1180   // [ constant pool cache      ]                              |
  1181   // [ Method*                ]                              |
  1182   // [ locals offset            ]                              |
  1183   // [ sender's sp              ]                              |
  1184   // [ sender's fp              ]                              |
  1185   // [ return address           ] <--- fp                      |
  1186   // [ method holder mirror     ] <----------------------------|
  1187   // [ result type info         ]
  1188   // [ argumnet word n-1        ] <--- ( sender's sp )
  1189   //   ...
  1190   // [ argument word 0          ] <--- S7
  1192   // set_last_Java_frame_before_call
  1193   __ sd(FP, thread, in_bytes(JavaThread::last_Java_fp_offset()));
  1194   // Change state to native (we save the return address in the thread, since it might not
  1195   // be pushed on the stack when we do a a stack traversal). It is enough that the pc()
  1196   // points into the right code segment. It does not have to be the correct return pc.
  1197   __ li(t, __ pc());
  1198   __ sd(t, thread, in_bytes(JavaThread::last_Java_pc_offset()));
  1199   __ sd(SP, thread, in_bytes(JavaThread::last_Java_sp_offset()));
  1201   // change thread state
  1202 #ifdef ASSERT
  1204     Label L;
  1205     __ lw(t, thread, in_bytes(JavaThread::thread_state_offset()));
  1206     __ daddi(t, t, (-1) * _thread_in_Java);
  1207     __ beq(t, R0, L);
  1208     __ delayed()->nop();
  1209     __ stop("Wrong thread state in native stub");
  1210     __ bind(L);
  1212 #endif
  1214   __ move(t, _thread_in_native);
  1215   __ sw(t, thread, in_bytes(JavaThread::thread_state_offset()));
  1217   // call native method
  1218   __ jalr(T9);
  1219   __ delayed()->nop();
  1220   // result potentially in V2:V1 or F0:F1
  1223   // via _last_native_pc and not via _last_jave_sp
  1224   // NOTE: the order of theses push(es) is known to frame::interpreter_frame_result.
  1225   //  If the order changes or anything else is added to the stack the code in
  1226   // interpreter_frame_result will have to be changed.
  1227   //FIXME, should modify here
  1228   // save return value to keep the value from being destroyed by other calls
  1229   __ move(S1, V0);
  1230   __ move(S3, V1);
  1231   __ dmfc1(S4, F0);
  1232   __ dmfc1(S2, F1);
  1234   // change thread state
  1235   __ get_thread(thread);
  1236   __ move(t, _thread_in_native_trans);
  1237   __ sw(t, thread, in_bytes(JavaThread::thread_state_offset()));
  1239   if( os::is_MP() ) __ sync(); // Force this write out before the read below
  1241   // check for safepoint operation in progress and/or pending suspend requests
  1242   { Label Continue;
  1244     // Don't use call_VM as it will see a possible pending exception and forward it
  1245     // and never return here preventing us from clearing _last_native_pc down below.
  1246     // Also can't use call_VM_leaf either as it will check to see if esi & edi are
  1247     // preserved and correspond to the bcp/locals pointers. So we do a runtime call
  1248     // by hand.
  1249     //
  1250     Label L;
  1251     __ li(AT, SafepointSynchronize::address_of_state());
  1252     __ lw(AT, AT, 0);
  1253     __ bne(AT, R0, L);
  1254     __ delayed()->nop();
  1255     __ lw(AT, thread, in_bytes(JavaThread::suspend_flags_offset()));
  1256     __ beq(AT, R0, Continue);
  1257     __ delayed()->nop();
  1258     __ bind(L);
  1259     __ move(A0, thread);
  1260     __ call(CAST_FROM_FN_PTR(address,
  1261     JavaThread::check_special_condition_for_native_trans),
  1262   relocInfo::runtime_call_type);
  1263     __ delayed()->nop();
  1265 #ifndef OPT_THREAD
  1266     __ get_thread(thread);
  1267 #endif
  1268     //add for compressedoops
  1269     __ reinit_heapbase();
  1270     __ bind(Continue);
  1273   // change thread state
  1274   __ move(t, _thread_in_Java);
  1275   __ sw(t, thread, in_bytes(JavaThread::thread_state_offset()));
  1276   __ reset_last_Java_frame(thread, true, true);
  1278   // reset handle block
  1279   __ ld(t, thread, in_bytes(JavaThread::active_handles_offset()));
  1280   __ sw(R0, t, JNIHandleBlock::top_offset_in_bytes());
  1282   // If result was an oop then unbox and save it in the frame
  1283   { Label L;
  1284     Label no_oop, store_result;
  1285     //FIXME, addi only support 16-bit imeditate
  1286     __ ld(AT, FP, frame::interpreter_frame_result_handler_offset*wordSize);
  1287     __ li(T0, AbstractInterpreter::result_handler(T_OBJECT));
  1288     __ bne(AT, T0, no_oop);
  1289     __ delayed()->nop();
  1290     __ move(V0, S1);
  1291     __ beq(V0, R0, store_result);
  1292     __ delayed()->nop();
  1293     // unbox
  1294     __ ld(V0, V0, 0);
  1295     __ bind(store_result);
  1296     __ sd(V0, FP, (frame::interpreter_frame_oop_temp_offset)*wordSize);
  1297     // keep stack depth as expected by pushing oop which will eventually be discarded
  1298     __ bind(no_oop);
  1301     Label no_reguard;
  1302     __ lw(t, thread, in_bytes(JavaThread::stack_guard_state_offset()));
  1303     __ move(AT,(int) JavaThread::stack_guard_yellow_disabled);
  1304     __ bne(t, AT, no_reguard);
  1305     __ delayed()->nop();
  1306     __ pushad();
  1307     __ call(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages), relocInfo::runtime_call_type);
  1308     __ delayed()->nop();
  1309     __ popad();
  1310     //add for compressedoops
  1311     __ reinit_heapbase();
  1312     __ bind(no_reguard);
  1314   // restore esi to have legal interpreter frame,
  1315   // i.e., bci == 0 <=> esi == code_base()
  1316   // Can't call_VM until bcp is within reasonable.
  1317   __ get_method(method);      // method is junk from thread_in_native to now.
  1318   __ verify_oop(method);
  1319   __ ld(BCP, method, in_bytes(Method::const_offset()));
  1320   __ lea(BCP, Address(BCP, in_bytes(ConstMethod::codes_offset())));
  1321   // handle exceptions (exception handling will handle unlocking!)
  1323     Label L;
  1324     __ lw(t, thread, in_bytes(Thread::pending_exception_offset()));
  1325     __ beq(t, R0, L);
  1326     __ delayed()->nop();
  1327     // Note: At some point we may want to unify this with the code used in
  1328     // call_VM_base();
  1329     // i.e., we should use the StubRoutines::forward_exception code. For now this
  1330     // doesn't work here because the esp is not correctly set at this point.
  1331     __ MacroAssembler::call_VM(noreg, CAST_FROM_FN_PTR(address,
  1332     InterpreterRuntime::throw_pending_exception));
  1333     __ should_not_reach_here();
  1334     __ bind(L);
  1337   // do unlocking if necessary
  1339     Label L;
  1340     __ lw(t, method, in_bytes(Method::access_flags_offset()));
  1341     __ andi(t, t, JVM_ACC_SYNCHRONIZED);
  1342     __ beq(t, R0, L);
  1343     // the code below should be shared with interpreter macro assembler implementation
  1345       Label unlock;
  1346       // BasicObjectLock will be first in list,
  1347       // since this is a synchronized method. However, need
  1348       // to check that the object has not been unlocked by
  1349       // an explicit monitorexit bytecode.
  1350       __ delayed()->daddi(c_rarg0, FP, frame::interpreter_frame_initial_sp_offset * wordSize - (int)sizeof(BasicObjectLock));
  1351       // address of first monitor
  1353       __ ld(t, c_rarg0, BasicObjectLock::obj_offset_in_bytes());
  1354       __ bne(t, R0, unlock);
  1355       __ delayed()->nop();
  1357       // Entry already unlocked, need to throw exception
  1358       __ MacroAssembler::call_VM(NOREG, CAST_FROM_FN_PTR(address,
  1359       InterpreterRuntime::throw_illegal_monitor_state_exception));
  1360       __ should_not_reach_here();
  1362       __ bind(unlock);
  1363       __ unlock_object(c_rarg0);
  1365     __ bind(L);
  1368   // jvmti/jvmpi support
  1369   // Note: This must happen _after_ handling/throwing any exceptions since
  1370   //       the exception handler code notifies the runtime of method exits
  1371   //       too. If this happens before, method entry/exit notifications are
  1372   //       not properly paired (was bug - gri 11/22/99).
  1373   __ notify_method_exit(false, vtos, InterpreterMacroAssembler::NotifyJVMTI );
  1375   // restore potential result in V0:V1,
  1376   // call result handler to restore potential result in ST0 & handle result
  1377   //__ lw(V0, SP, 3 * wordSize);
  1378   //__ lw(V1, SP, 2 * wordSize);
  1379   //__ lwc1(F0, SP, 1 * wordSize);
  1380   //__ lwc1(F1, SP, 0 * wordSize);
  1381   //__ addi(SP, SP, 4 * wordSize);
  1382   __ move(V0, S1);
  1383   __ move(V1, S3);
  1384   __ dmtc1(S4, F0);
  1385   __ dmtc1(S2, F1);
  1386   __ ld(t, FP, (frame::interpreter_frame_result_handler_offset) * wordSize);
  1387   __ jalr(t);
  1388   __ delayed()->nop();
  1391   // remove activation
  1392   __ ld(SP, FP, frame::interpreter_frame_sender_sp_offset * wordSize); // get sender sp
  1393   __ ld(RA, FP, frame::interpreter_frame_return_addr_offset * wordSize); // get return address
  1394   __ ld(FP, FP, frame::interpreter_frame_sender_fp_offset * wordSize); // restore sender's fp
  1395   __ jr(RA);
  1396   __ delayed()->nop();
  1398 #ifndef CORE
  1399   if (inc_counter) {
  1400     // Handle overflow of counter and compile method
  1401     __ bind(invocation_counter_overflow);
  1402     generate_counter_overflow(&continue_after_compile);
  1403     // entry_point is the beginning of this
  1404     // function and checks again for compiled code
  1406 #endif
  1407   return entry_point;
  1410 //
  1411 // Generic interpreted method entry to (asm) interpreter
  1412 //
  1413 // Layout of frame just at the entry
  1414 //
  1415 //   [ argument word n-1  ] <--- sp
  1416 //     ...
  1417 //   [ argument word 0    ]
  1418 // assume Method* in Rmethod before call this method.
  1419 // prerequisites to the generated stub : the callee Method* in Rmethod
  1420 // note you must save the caller bcp before call the generated stub
  1421 //
  1422 address InterpreterGenerator::generate_normal_entry(bool synchronized) {
  1423   // determine code generation flags
  1424   bool inc_counter  = UseCompiler || CountCompiledCalls;
  1426   // Rmethod: Method*
  1427   // Rsender: sender 's sp
  1428   address entry_point = __ pc();
  1430   const Address invocation_counter(Rmethod,
  1431       in_bytes(MethodCounters::invocation_counter_offset() + InvocationCounter::counter_offset()));
  1433   // get parameter size (always needed)
  1434   __ ld(T3, Rmethod, in_bytes(Method::const_offset()));  //T3 --> Rmethod._constMethod
  1435   __ lhu(V0, T3, in_bytes(ConstMethod::size_of_parameters_offset()));
  1437   // Rmethod: Method*
  1438   // V0: size of parameters
  1439   // Rsender: sender 's sp ,could be different frome sp+ wordSize if we call via c2i
  1440   // get size of locals in words to T2
  1441   __ lhu(T2, T3, in_bytes(ConstMethod::size_of_locals_offset()));
  1442   // T2 = no. of additional locals, locals include parameters
  1443   __ dsub(T2, T2, V0);
  1445   // see if we've got enough room on the stack for locals plus overhead.
  1446   // Layout of frame at this point
  1447   //
  1448   // [ argument word n-1  ] <--- sp
  1449   //   ...
  1450   // [ argument word 0    ]
  1451   generate_stack_overflow_check();
  1452   // after this function, the layout of frame does not change
  1454   // compute beginning of parameters (LVP)
  1455   __ dsll(LVP, V0, LogBytesPerWord);
  1456   __ daddiu(LVP, LVP, (-1) * wordSize);
  1457   __ dadd(LVP, LVP, SP);
  1459   // T2 - # of additional locals
  1460   // allocate space for locals
  1461   // explicitly initialize locals
  1463     Label exit, loop;
  1464     __ beq(T2, R0, exit);
  1465     __ delayed()->nop();
  1467     __ bind(loop);
  1468     __ sd(R0, SP, -1 * wordSize);     // initialize local variables
  1469     __ daddiu(T2, T2, -1);               // until everything initialized
  1470     __ bne(T2, R0, loop);
  1471     __ delayed();
  1473     __ daddiu(SP, SP, (-1) * wordSize); //fill delay slot
  1475     __ bind(exit);
  1478   //
  1479   // [ local var m-1  ] <--- sp
  1480   //   ...
  1481   // [ local var 0  ]
  1482   // [ argument word n-1  ] <--- T0?
  1483   //   ...
  1484   // [ argument word 0    ] <--- LVP
  1486   // initialize fixed part of activation frame
  1488   generate_fixed_frame(false);
  1491   // after this function, the layout of frame is as following
  1492   //
  1493   // [ monitor block top        ] <--- sp ( the top monitor entry )
  1494   // [ byte code pointer        ] (if native, bcp = 0)
  1495   // [ constant pool cache      ]
  1496   // [ Method*                ]
  1497   // [ locals offset    ]
  1498   // [ sender's sp              ]
  1499   // [ sender's fp              ] <--- fp
  1500   // [ return address           ]
  1501   // [ local var m-1            ]
  1502   //   ...
  1503   // [ local var 0              ]
  1504   // [ argumnet word n-1        ] <--- ( sender's sp )
  1505   //   ...
  1506   // [ argument word 0          ] <--- LVP
  1509   // make sure method is not native & not abstract
  1510 #ifdef ASSERT
  1511   __ ld(AT, Rmethod, in_bytes(Method::access_flags_offset()));
  1513     Label L;
  1514     __ andi(T2, AT, JVM_ACC_NATIVE);
  1515     __ beq(T2, R0, L);
  1516     __ delayed()->nop();
  1517     __ stop("tried to execute native method as non-native");
  1518     __ bind(L);
  1521     Label L;
  1522     __ andi(T2, AT, JVM_ACC_ABSTRACT);
  1523     __ beq(T2, R0, L);
  1524     __ delayed()->nop();
  1525     __ stop("tried to execute abstract method in interpreter");
  1526     __ bind(L);
  1528 #endif
  1530   // Since at this point in the method invocation the exception handler
  1531   // would try to exit the monitor of synchronized methods which hasn't
  1532   // been entered yet, we set the thread local variable
  1533   // _do_not_unlock_if_synchronized to true. The remove_activation will
  1534   // check this flag.
  1536 #ifndef OPT_THREAD
  1537   Register thread = T8;
  1538   __ get_thread(thread);
  1539 #else
  1540   Register thread = TREG;
  1541 #endif
  1542   __ move(AT, (int)true);
  1543   __ sb(AT, thread, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
  1545 #ifndef CORE
  1547   // 2014/11/24 Fu
  1548   // mdp : T8
  1549   // tmp1: T9
  1550   // tmp2: T2
  1551    __ profile_parameters_type(T8, T9, T2);
  1553   // increment invocation count & check for overflow
  1554   Label invocation_counter_overflow;
  1555   Label profile_method;
  1556   Label profile_method_continue;
  1557   if (inc_counter) {
  1558     generate_counter_incr(&invocation_counter_overflow,
  1559                           &profile_method,
  1560                           &profile_method_continue);
  1561     if (ProfileInterpreter) {
  1562       __ bind(profile_method_continue);
  1566   Label continue_after_compile;
  1567   __ bind(continue_after_compile);
  1569 #endif // CORE
  1571   bang_stack_shadow_pages(false);
  1573   // reset the _do_not_unlock_if_synchronized flag
  1574 #ifndef OPT_THREAD
  1575   __ get_thread(thread);
  1576 #endif
  1577   __ sb(R0, thread, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
  1579   // check for synchronized methods
  1580   // Must happen AFTER invocation_counter check and stack overflow check,
  1581   // so method is not locked if overflows.
  1582   //
  1583   if (synchronized) {
  1584     // Allocate monitor and lock method
  1585     lock_method();
  1586   } else {
  1587     // no synchronization necessary
  1588 #ifdef ASSERT
  1589     { Label L;
  1590       __ lw(AT, Rmethod, in_bytes(Method::access_flags_offset()));
  1591       __ andi(T2, AT, JVM_ACC_SYNCHRONIZED);
  1592       __ beq(T2, R0, L);
  1593       __ delayed()->nop();
  1594       __ stop("method needs synchronization");
  1595       __ bind(L);
  1597 #endif
  1600   // layout of frame after lock_method
  1601   // [ monitor entry        ] <--- sp
  1602   //   ...
  1603   // [ monitor entry        ]
  1604   // [ monitor block top        ] ( the top monitor entry )
  1605   // [ byte code pointer        ] (if native, bcp = 0)
  1606   // [ constant pool cache      ]
  1607   // [ Method*                ]
  1608   // [ locals offset        ]
  1609   // [ sender's sp              ]
  1610   // [ sender's fp              ]
  1611   // [ return address           ] <--- fp
  1612   // [ local var m-1            ]
  1613   //   ...
  1614   // [ local var 0              ]
  1615   // [ argumnet word n-1        ] <--- ( sender's sp )
  1616   //   ...
  1617   // [ argument word 0          ] <--- LVP
  1620   // start execution
  1621 #ifdef ASSERT
  1623     Label L;
  1624     __ ld(AT, FP, frame::interpreter_frame_monitor_block_top_offset * wordSize);
  1625     __ beq(AT, SP, L);
  1626     __ delayed()->nop();
  1627     __ stop("broken stack frame setup in interpreter in native");
  1628     __ bind(L);
  1630 #endif
  1632   // jvmti/jvmpi support
  1633   __ notify_method_entry();
  1635   __ dispatch_next(vtos);
  1637   // invocation counter overflow
  1638   if (inc_counter) {
  1639     if (ProfileInterpreter) {
  1640       // We have decided to profile this method in the interpreter
  1641       __ bind(profile_method);
  1642       __ call_VM(noreg, CAST_FROM_FN_PTR(address,
  1643                  InterpreterRuntime::profile_method));
  1644       __ set_method_data_pointer_for_bcp();
  1645       __ get_method(Rmethod);
  1646       __ b(profile_method_continue);
  1647       __ delayed()->nop();
  1649     // Handle overflow of counter and compile method
  1650     __ bind(invocation_counter_overflow);
  1651     generate_counter_overflow(&continue_after_compile);
  1654   return entry_point;
  1657 // Entry points
  1658 //
  1659 // Here we generate the various kind of entries into the interpreter.
  1660 // The two main entry type are generic bytecode methods and native
  1661 // call method.  These both come in synchronized and non-synchronized
  1662 // versions but the frame layout they create is very similar. The
  1663 // other method entry types are really just special purpose entries
  1664 // that are really entry and interpretation all in one. These are for
  1665 // trivial methods like accessor, empty, or special math methods.
  1666 //
  1667 // When control flow reaches any of the entry types for the interpreter
  1668 // the following holds ->
  1669 //
  1670 // Arguments:
  1671 //
  1672 // Rmethod: Method*
  1673 // V0: receiver
  1674 //
  1675 //
  1676 // Stack layout immediately at entry
  1677 //
  1678 // [ parameter n-1      ] <--- sp
  1679 //   ...
  1680 // [ parameter 0        ]
  1681 // [ expression stack   ] (caller's java expression stack)
  1683 // Assuming that we don't go to one of the trivial specialized entries
  1684 // the stack will look like below when we are ready to execute the
  1685 // first bytecode (or call the native routine). The register usage
  1686 // will be as the template based interpreter expects (see
  1687 // interpreter_amd64.hpp).
  1688 //
  1689 // local variables follow incoming parameters immediately; i.e.
  1690 // the return address is moved to the end of the locals).
  1691 //
  1692 // [ monitor entry        ] <--- sp
  1693 //   ...
  1694 // [ monitor entry        ]
  1695 // [ monitor block top        ] ( the top monitor entry )
  1696 // [ byte code pointer        ] (if native, bcp = 0)
  1697 // [ constant pool cache      ]
  1698 // [ Method*                ]
  1699 // [ locals offset        ]
  1700 // [ sender's sp              ]
  1701 // [ sender's fp              ]
  1702 // [ return address           ] <--- fp
  1703 // [ local var m-1            ]
  1704 //   ...
  1705 // [ local var 0              ]
  1706 // [ argumnet word n-1        ] <--- ( sender's sp )
  1707 //   ...
  1708 // [ argument word 0          ] <--- S7
  1710 address AbstractInterpreterGenerator::generate_method_entry(
  1711                                         AbstractInterpreter::MethodKind kind) {
  1712   // determine code generation flags
  1713   bool synchronized = false;
  1714   address entry_point = NULL;
  1715   switch (kind) {
  1716     case Interpreter::zerolocals             :
  1717       break;
  1718     case Interpreter::zerolocals_synchronized:
  1719       synchronized = true;
  1720       break;
  1721     case Interpreter::native                 :
  1722       entry_point = ((InterpreterGenerator*)this)->generate_native_entry(false);
  1723       break;
  1724     case Interpreter::native_synchronized    :
  1725       entry_point = ((InterpreterGenerator*)this)->generate_native_entry(true);
  1726       break;
  1727     case Interpreter::empty                  :
  1728       entry_point = ((InterpreterGenerator*)this)->generate_empty_entry();
  1729       break;
  1730     case Interpreter::accessor               :
  1731       entry_point = ((InterpreterGenerator*)this)->generate_accessor_entry();
  1732       break;
  1733     case Interpreter::abstract               :
  1734       entry_point = ((InterpreterGenerator*)this)->generate_abstract_entry();
  1735       break;
  1737     case Interpreter::java_lang_math_sin     : // fall thru
  1738     case Interpreter::java_lang_math_cos     : // fall thru
  1739     case Interpreter::java_lang_math_tan     : // fall thru
  1740     case Interpreter::java_lang_math_log     : // fall thru
  1741     case Interpreter::java_lang_math_log10   : // fall thru
  1742     case Interpreter::java_lang_math_pow     : // fall thru
  1743     case Interpreter::java_lang_math_exp     : break;
  1744     case Interpreter::java_lang_math_abs     : // fall thru
  1745     case Interpreter::java_lang_math_sqrt    :
  1746       entry_point = ((InterpreterGenerator*)this)->generate_math_entry(kind);    break;
  1747     case Interpreter::java_lang_ref_reference_get:
  1748       entry_point = ((InterpreterGenerator*)this)->generate_Reference_get_entry(); break;
  1749     default:
  1750       fatal(err_msg("unexpected method kind: %d", kind));
  1751       break;
  1753   if (entry_point) return entry_point;
  1755   return ((InterpreterGenerator*)this)->generate_normal_entry(synchronized);
  1758 // These should never be compiled since the interpreter will prefer
  1759 // the compiled version to the intrinsic version.
  1760 bool AbstractInterpreter::can_be_compiled(methodHandle m) {
  1761   switch (method_kind(m)) {
  1762     case Interpreter::java_lang_math_sin     : // fall thru
  1763     case Interpreter::java_lang_math_cos     : // fall thru
  1764     case Interpreter::java_lang_math_tan     : // fall thru
  1765     case Interpreter::java_lang_math_abs     : // fall thru
  1766     case Interpreter::java_lang_math_log     : // fall thru
  1767     case Interpreter::java_lang_math_log10   : // fall thru
  1768     case Interpreter::java_lang_math_sqrt    : // fall thru
  1769     case Interpreter::java_lang_math_pow     : // fall thru
  1770     case Interpreter::java_lang_math_exp     :
  1771       return false;
  1772     default:
  1773       return true;
  1777 // How much stack a method activation needs in words.
  1778 int AbstractInterpreter::size_top_interpreter_activation(Method* method) {
  1780   const int entry_size    = frame::interpreter_frame_monitor_size();
  1782   // total overhead size: entry_size + (saved ebp thru expr stack bottom).
  1783   // be sure to change this if you add/subtract anything to/from the overhead area
  1784   const int overhead_size = -(frame::interpreter_frame_initial_sp_offset) + entry_size;
  1786   const int stub_code = 6;  // see generate_call_stub
  1787   // return overhead_size + method->max_locals() + method->max_stack() + stub_code;
  1788   const int method_stack = (method->max_locals() + method->max_stack()) *
  1789           Interpreter::stackElementWords;
  1790   return overhead_size + method_stack + stub_code;
  1793 void AbstractInterpreter::layout_activation(Method* method,
  1794                                            int tempcount,
  1795                                            int popframe_extra_args,
  1796                                            int moncount,
  1797                                            int caller_actual_parameters,
  1798                                            int callee_param_count,
  1799                                            int callee_locals,
  1800                                            frame* caller,
  1801                                            frame* interpreter_frame,
  1802                                            bool is_top_frame,
  1803                                            bool is_bottom_frame) {
  1804   // Note: This calculation must exactly parallel the frame setup
  1805   // in AbstractInterpreterGenerator::generate_method_entry.
  1806   // If interpreter_frame!=NULL, set up the method, locals, and monitors.
  1807   // The frame interpreter_frame, if not NULL, is guaranteed to be the
  1808   // right size, as determined by a previous call to this method.
  1809   // It is also guaranteed to be walkable even though it is in a skeletal state
  1811   // fixed size of an interpreter frame:
  1813   int max_locals = method->max_locals() * Interpreter::stackElementWords;
  1814   int extra_locals = (method->max_locals() - method->size_of_parameters()) * Interpreter::stackElementWords;
  1816 #ifdef ASSERT
  1817   if (!EnableInvokeDynamic) {
  1818     // @@@ FIXME: Should we correct interpreter_frame_sender_sp in the calling sequences?
  1819     // Probably, since deoptimization doesn't work yet.
  1820     assert(caller->unextended_sp() == interpreter_frame->interpreter_frame_sender_sp(), "Frame not properly walkable");
  1822   assert(caller->sp() == interpreter_frame->interpreter_frame_sender_sp(), "Frame not properly walkable(2)");
  1823 #endif
  1825     interpreter_frame->interpreter_frame_set_method(method);
  1826     // NOTE the difference in using sender_sp and interpreter_frame_sender_sp
  1827     // interpreter_frame_sender_sp is the original sp of the caller (the unextended_sp)
  1828     // and sender_sp is fp+8
  1829     intptr_t* locals = interpreter_frame->sender_sp() + max_locals - 1;
  1831 #ifdef ASSERT
  1832   if (caller->is_interpreted_frame()) {
  1833     assert(locals < caller->fp() + frame::interpreter_frame_initial_sp_offset, "bad placement");
  1835 #endif
  1837   interpreter_frame->interpreter_frame_set_locals(locals);
  1838   BasicObjectLock* montop = interpreter_frame->interpreter_frame_monitor_begin();
  1839   BasicObjectLock* monbot = montop - moncount;
  1840   interpreter_frame->interpreter_frame_set_monitor_end(montop - moncount);
  1842   //set last sp;
  1843   intptr_t*  esp = (intptr_t*) monbot - tempcount*Interpreter::stackElementWords -
  1844                       popframe_extra_args;
  1845   interpreter_frame->interpreter_frame_set_last_sp(esp);
  1846   // All frames but the initial interpreter frame we fill in have a
  1847   // value for sender_sp that allows walking the stack but isn't
  1848   // truly correct. Correct the value here.
  1849   //
  1850     if (extra_locals != 0 &&
  1851         interpreter_frame->sender_sp() == interpreter_frame->interpreter_frame_sender_sp() ) {
  1852       interpreter_frame->set_interpreter_frame_sender_sp(caller->sp() + extra_locals);
  1854     *interpreter_frame->interpreter_frame_cache_addr() = method->constants()->cache();
  1857 //-----------------------------------------------------------------------------
  1858 // Exceptions
  1860 void TemplateInterpreterGenerator::generate_throw_exception() {
  1861   // Entry point in previous activation (i.e., if the caller was
  1862   // interpreted)
  1863   Interpreter::_rethrow_exception_entry = __ pc();
  1864   // Restore sp to interpreter_frame_last_sp even though we are going
  1865   // to empty the expression stack for the exception processing.
  1866   __ sd(R0,FP, frame::interpreter_frame_last_sp_offset * wordSize);
  1868   // V0: exception
  1869   // V1: return address/pc that threw exception
  1870   __ restore_bcp();                              // esi points to call/send
  1871   __ restore_locals();
  1873   //add for compressedoops
  1874   __ reinit_heapbase();
  1875   // Entry point for exceptions thrown within interpreter code
  1876   Interpreter::_throw_exception_entry = __ pc();
  1877   // expression stack is undefined here
  1878   // V0: exception
  1879   // BCP: exception bcp
  1880   __ verify_oop(V0);
  1882   // expression stack must be empty before entering the VM in case of an exception
  1883   __ empty_expression_stack();
  1884   // find exception handler address and preserve exception oop
  1885   __ move(A1, V0);
  1886   __ call_VM(V1, CAST_FROM_FN_PTR(address, InterpreterRuntime::exception_handler_for_exception), A1);
  1887   // V0: exception handler entry point
  1888   // V1: preserved exception oop
  1889   // S0: bcp for exception handler
  1890   __ daddi(SP, SP, (-1) * wordSize);
  1891   __ sd(V1, SP, 0);                              // push exception which is now the only value on the stack
  1892   __ jr(V0);                                   // jump to exception handler (may be _remove_activation_entry!)
  1893   __ delayed()->nop();
  1895   // If the exception is not handled in the current frame the frame is removed and
  1896   // the exception is rethrown (i.e. exception continuation is _rethrow_exception).
  1897   //
  1898   // Note: At this point the bci is still the bxi for the instruction which caused
  1899   //       the exception and the expression stack is empty. Thus, for any VM calls
  1900   //       at this point, GC will find a legal oop map (with empty expression stack).
  1902   // In current activation
  1903   // V0: exception
  1904   // BCP: exception bcp
  1906   //
  1907   // JVMTI PopFrame support
  1908   //
  1910   Interpreter::_remove_activation_preserving_args_entry = __ pc();
  1911   __ empty_expression_stack();
  1912   // Set the popframe_processing bit in pending_popframe_condition indicating that we are
  1913   // currently handling popframe, so that call_VMs that may happen later do not trigger new
  1914   // popframe handling cycles.
  1915 #ifndef OPT_THREAD
  1916   Register thread = T2;
  1917   __ get_thread(T2);
  1918 #else
  1919   Register thread = TREG;
  1920 #endif
  1921   __ lw(T3, thread, in_bytes(JavaThread::popframe_condition_offset()));
  1922   __ ori(T3, T3, JavaThread::popframe_processing_bit);
  1923   __ sw(T3, thread, in_bytes(JavaThread::popframe_condition_offset()));
  1925 #ifndef CORE
  1927     // Check to see whether we are returning to a deoptimized frame.
  1928     // (The PopFrame call ensures that the caller of the popped frame is
  1929     // either interpreted or compiled and deoptimizes it if compiled.)
  1930     // In this case, we can't call dispatch_next() after the frame is
  1931     // popped, but instead must save the incoming arguments and restore
  1932     // them after deoptimization has occurred.
  1933     //
  1934     // Note that we don't compare the return PC against the
  1935     // deoptimization blob's unpack entry because of the presence of
  1936     // adapter frames in C2.
  1937     Label caller_not_deoptimized;
  1938     __ ld(A0, FP, frame::return_addr_offset * wordSize);
  1939     __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::interpreter_contains), A0);
  1940     __ bne(V0, R0, caller_not_deoptimized);
  1941     __ delayed()->nop();
  1943     // Compute size of arguments for saving when returning to deoptimized caller
  1944     __ get_method(A1);
  1945     __ verify_oop(A1);
  1946     __ ld(A1,A1,in_bytes(Method::const_offset()));
  1947     __ lhu(A1, A1, in_bytes(ConstMethod::size_of_parameters_offset()));
  1948     __ shl(A1, Interpreter::logStackElementSize);
  1949     __ restore_locals();
  1950     __ dsub(A2, LVP, T0);
  1951     __ daddiu(A2, A2, wordSize);
  1952     // Save these arguments
  1953 #ifndef OPT_THREAD
  1954     __ get_thread(A0);
  1955 #else
  1956     __ move(A0, TREG);
  1957 #endif
  1958     __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, Deoptimization::popframe_preserve_args), A0, A1, A2);
  1960     __ remove_activation(vtos, T9, false, false, false);
  1962     // Inform deoptimization that it is responsible for restoring these arguments
  1963 #ifndef OPT_THREAD
  1964     __ get_thread(thread);
  1965 #endif
  1966     __ move(AT, JavaThread::popframe_force_deopt_reexecution_bit);
  1967     __ sw(AT, thread, in_bytes(JavaThread::popframe_condition_offset()));
  1968     // Continue in deoptimization handler
  1969     __ jr(T9);
  1970     __ delayed()->nop();
  1972     __ bind(caller_not_deoptimized);
  1974 #endif /* !CORE */
  1976   __ remove_activation(vtos, T3,
  1977                        /* throw_monitor_exception */ false,
  1978                        /* install_monitor_exception */ false,
  1979                        /* notify_jvmdi */ false);
  1981   // Clear the popframe condition flag
  1982   // Finish with popframe handling
  1983   // A previous I2C followed by a deoptimization might have moved the
  1984   // outgoing arguments further up the stack. PopFrame expects the
  1985   // mutations to those outgoing arguments to be preserved and other
  1986   // constraints basically require this frame to look exactly as
  1987   // though it had previously invoked an interpreted activation with
  1988   // no space between the top of the expression stack (current
  1989   // last_sp) and the top of stack. Rather than force deopt to
  1990   // maintain this kind of invariant all the time we call a small
  1991   // fixup routine to move the mutated arguments onto the top of our
  1992   // expression stack if necessary.
  1993   __ move(T8, SP);
  1994   __ ld(A2, FP, frame::interpreter_frame_last_sp_offset * wordSize);
  1995 #ifndef OPT_THREAD
  1996   __ get_thread(thread);
  1997 #endif
  1998   // PC must point into interpreter here
  1999   __ set_last_Java_frame(thread, noreg, FP, __ pc());
  2000   __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::popframe_move_outgoing_args), thread, T8, A2);
  2001   __ reset_last_Java_frame(thread, true, true);
  2002   // Restore the last_sp and null it out
  2003   __ ld(SP, FP, frame::interpreter_frame_last_sp_offset * wordSize);
  2004   __ sd(R0, FP, frame::interpreter_frame_last_sp_offset * wordSize);
  2008   __ move(AT, JavaThread::popframe_inactive);
  2009   __ sw(AT, thread, in_bytes(JavaThread::popframe_condition_offset()));
  2011   // Finish with popframe handling
  2012   __ restore_bcp();
  2013   __ restore_locals();
  2014 #ifndef CORE
  2015   // The method data pointer was incremented already during
  2016   // call profiling. We have to restore the mdp for the current bcp.
  2017   if (ProfileInterpreter) {
  2018     __ set_method_data_pointer_for_bcp();
  2020 #endif // !CORE
  2021   // Clear the popframe condition flag
  2022 #ifndef OPT_THREAD
  2023   __ get_thread(thread);
  2024 #endif
  2025   __ move(AT, JavaThread::popframe_inactive);
  2026   __ sw(AT, thread, in_bytes(JavaThread::popframe_condition_offset()));
  2027   __ dispatch_next(vtos);
  2028   // end of PopFrame support
  2030   Interpreter::_remove_activation_entry = __ pc();
  2032   // preserve exception over this code sequence
  2033   __ ld(T0, SP, 0);
  2034   __ daddi(SP, SP, wordSize);
  2035 #ifndef OPT_THREAD
  2036   __ get_thread(thread);
  2037 #endif
  2038   __ sd(T0, thread, in_bytes(JavaThread::vm_result_offset()));
  2039   // remove the activation (without doing throws on illegalMonitorExceptions)
  2040   __ remove_activation(vtos, T3, false, true, false);
  2041   // restore exception
  2042   __ get_vm_result(T0, thread);
  2043   __ verify_oop(T0);
  2045   // Inbetween activations - previous activation type unknown yet
  2046   // compute continuation point - the continuation point expects
  2047   // the following registers set up:
  2048   //
  2049   // T0: exception                                eax
  2050   // T1: return address/pc that threw exception    edx
  2051   // SP: expression stack of caller      esp
  2052   // FP: ebp of caller          ebp
  2053   __ daddi(SP, SP, (-2) * wordSize);
  2054   __ sd(T0, SP, wordSize);      // save exception
  2055   __ sd(T3, SP, 0);                               // save return address
  2056   __ move(A1, T3);
  2057   __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address), thread, A1);
  2058   __ move(T9, V0);                             // save exception handler
  2059   __ ld(V0, SP, wordSize);        // restore exception
  2060   __ ld(V1, SP, 0);                               // restore return address
  2061   __ daddi(SP, SP, 2 * wordSize);
  2063   // Note that an "issuing PC" is actually the next PC after the call
  2064   __ jr(T9);                                   // jump to exception handler of caller
  2065   __ delayed()->nop();
  2069 //
  2070 // JVMTI ForceEarlyReturn support
  2071 //
  2072 address TemplateInterpreterGenerator::generate_earlyret_entry_for(TosState state) {
  2073   address entry = __ pc();
  2074   __ restore_bcp();
  2075   __ restore_locals();
  2076   __ empty_expression_stack();
  2077   __ empty_FPU_stack();
  2078   __ load_earlyret_value(state);
  2080 #ifndef OPT_THREAD
  2081   __ get_thread(TREG);
  2082 #endif
  2083    __ ld_ptr(T9, TREG, in_bytes(JavaThread::jvmti_thread_state_offset()));
  2084   //const Address cond_addr(ecx, JvmtiThreadState::earlyret_state_offset());
  2085   const Address cond_addr(T9, in_bytes(JvmtiThreadState::earlyret_state_offset()));
  2086   // Clear the earlyret state
  2087     __ move(AT,JvmtiThreadState::earlyret_inactive);
  2088     __ sw(AT,cond_addr);
  2089     __ sync();
  2092     __ remove_activation(state, T0,
  2093                          false, /* throw_monitor_exception */
  2094                          false, /* install_monitor_exception */
  2095                          true); /* notify_jvmdi */
  2096     __ sync();
  2097     __ jr(T0);
  2098     __ delayed()->nop();
  2099   return entry;
  2100 } // end of ForceEarlyReturn support
  2103 //-----------------------------------------------------------------------------
  2104 // Helper for vtos entry point generation
  2106 void TemplateInterpreterGenerator::set_vtos_entry_points(Template* t,
  2107                                                          address& bep,
  2108                                                          address& cep,
  2109                                                          address& sep,
  2110                                                          address& aep,
  2111                                                          address& iep,
  2112                                                          address& lep,
  2113                                                          address& fep,
  2114                                                          address& dep,
  2115                                                          address& vep) {
  2116   assert(t->is_valid() && t->tos_in() == vtos, "illegal template");
  2117   Label L;
  2118   fep = __ pc(); __ push(ftos); __ b(L); __ delayed()->nop();
  2119   dep = __ pc(); __ push(dtos); __ b(L); __ delayed()->nop();
  2120   lep = __ pc(); __ push(ltos); __ b(L); __ delayed()->nop();
  2121   aep  =__ pc(); __ push(atos); __ b(L); __ delayed()->nop();
  2122   bep = cep = sep =
  2123   iep = __ pc(); __ push(itos);
  2124   vep = __ pc();
  2125   __ bind(L);
  2126   generate_and_dispatch(t);
  2130 //-----------------------------------------------------------------------------
  2131 // Generation of individual instructions
  2133 // helpers for generate_and_dispatch
  2136 InterpreterGenerator::InterpreterGenerator(StubQueue* code)
  2137   : TemplateInterpreterGenerator(code) {
  2138    generate_all(); // down here so it can be "virtual"
  2141 //-----------------------------------------------------------------------------
  2143 // Non-product code
  2144 #ifndef PRODUCT
  2145 address TemplateInterpreterGenerator::generate_trace_code(TosState state) {
  2146   address entry = __ pc();
  2148   // prepare expression stack
  2149   __ push(state);       // save tosca
  2151   // tos & tos2, added by yjl 7/15/2005
  2152   // trace_bytecode need actually 4 args, the last two is tos&tos2
  2153   // this work fine for x86. but mips o32 call convention will store A2-A3
  2154   // to the stack position it think is the tos&tos2
  2155   // when the expression stack have no more than 2 data, error occur.
  2156   __ ld(A2, SP, 0);
  2157   __ ld(A3, SP, 1 * wordSize);
  2159   // pass arguments & call tracer
  2160   __ call_VM(noreg, CAST_FROM_FN_PTR(address, SharedRuntime::trace_bytecode), RA, A2, A3);
  2161   __ move(RA, V0);    // make sure return address is not destroyed by pop(state)
  2163   // restore expression stack
  2164   __ pop(state);        // restore tosca
  2166   // return
  2167   __ jr(RA);
  2168   __ delayed()->nop();
  2170   return entry;
  2173 void TemplateInterpreterGenerator::count_bytecode() {
  2174   __ li(T8, (long)&BytecodeCounter::_counter_value);
  2175   __ lw(AT, T8, 0);
  2176   __ daddi(AT, AT, 1);
  2177   __ sw(AT, T8, 0);
  2180 void TemplateInterpreterGenerator::histogram_bytecode(Template* t) {
  2181   __ li(T8, (long)&BytecodeHistogram::_counters[t->bytecode()]);
  2182   __ lw(AT, T8, 0);
  2183   __ daddi(AT, AT, 1);
  2184   __ sw(AT, T8, 0);
  2187 void TemplateInterpreterGenerator::histogram_bytecode_pair(Template* t) {
  2188   __ li(T8, (long)&BytecodePairHistogram::_index);
  2189   __ lw(T9, T8, 0);
  2190   __ dsrl(T9, T9, BytecodePairHistogram::log2_number_of_codes);
  2191   __ li(T8, ((long)t->bytecode()) << BytecodePairHistogram::log2_number_of_codes);
  2192   __ orr(T9, T9, T8);
  2193   __ li(T8, (long)&BytecodePairHistogram::_index);
  2194   __ sw(T9, T8, 0);
  2195   __ dsll(T9, T9, 2);
  2196   __ li(T8, (long)BytecodePairHistogram::_counters);
  2197   __ dadd(T8, T8, T9);
  2198   __ lw(AT, T8, 0);
  2199   __ daddi(AT, AT, 1);
  2200   __ sw(AT, T8, 0);
  2204 void TemplateInterpreterGenerator::trace_bytecode(Template* t) {
  2205   // Call a little run-time stub to avoid blow-up for each bytecode.
  2206   // The run-time runtime saves the right registers, depending on
  2207   // the tosca in-state for the given template.
  2209   address entry = Interpreter::trace_code(t->tos_in());
  2210   assert(entry != NULL, "entry must have been generated");
  2211   __ call(entry, relocInfo::none);
  2212   __ delayed()->nop();
  2213   //add for compressedoops
  2214   __ reinit_heapbase();
  2218 void TemplateInterpreterGenerator::stop_interpreter_at() {
  2219   Label L;
  2220   __ li(T8, long(&BytecodeCounter::_counter_value));
  2221   __ lw(T8, T8, 0);
  2222   __ move(AT, StopInterpreterAt);
  2223   __ bne(T8, AT, L);
  2224   __ delayed()->nop();
  2225   __ call(CAST_FROM_FN_PTR(address, os::breakpoint), relocInfo::runtime_call_type);
  2226   __ delayed()->nop();
  2227   __ bind(L);
  2229 #endif // !PRODUCT
  2230 #endif // ! CC_INTERP

mercurial