src/cpu/mips/vm/templateInterpreter_mips_64.cpp

Tue, 26 Sep 2017 11:18:59 +0800

author
fujie
date
Tue, 26 Sep 2017 11:18:59 +0800
changeset 6894
c3f0dbba118a
parent 6880
52ea28d233d2
child 6895
34448c1bea2d
permissions
-rw-r--r--

[Interpreter] Replace b*_far in method entry point.

This patch is used to fix the following bad case in method entry point.
----------------------------------------------------------------------
method entry point (kind = empty) [0x0000000000029440, 0x0000000000029de0] 2464 bytes

0x00000000000298b4: beqz at,0x00000000000298e0
0x00000000000298b8: nop
0x00000000000298bc: b 0x0000000000029938
0x00000000000298c0: nop
0x00000000000298c4: nop
0x00000000000298c8: nop
0x00000000000298cc: nop
0x00000000000298d0: nop
0x00000000000298d4: nop
0x00000000000298d8: nop
0x00000000000298dc: nop
0x00000000000298e0: nop
0x00000000000298e4: ld v0,-40(s8)
0x00000000000298e8: beqz v0,0x0000000000029af0
0x00000000000298ec: nop

     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())  //Fu:20130814  Wang:Rmethod --> FSR
   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     __ li(AT, (long)&InvocationCounter::InterpreterProfileLimit);
   343     __ lw(AT, AT, 0);
   344     __ slt(AT, T3, AT);
   345     __ bne(AT, R0, *profile_method_continue);
   346     __ delayed()->nop();
   348     // if no method data exists, go to profile_method
   349     __ test_method_data_pointer(FSR, *profile_method);
   350   }
   352   __ li(AT, (long)&InvocationCounter::InterpreterInvocationLimit);
   353   __ lw(AT, AT, 0);
   354   __ slt(AT, T3, AT);
   355   __ beq(AT, R0, *overflow);
   356   __ delayed()->nop();
   357   __ bind(done);
   358 }
   360 void InterpreterGenerator::generate_counter_overflow(Label* do_continue) {
   362   // Asm interpreter on entry
   363   // S7 - locals
   364   // S0 - bcp
   365   // Rmethod - method
   366   // FP - interpreter frame
   368   // On return (i.e. jump to entry_point)
   369   // Rmethod - method
   370   // RA - return address of interpreter caller
   371   // tos - the last parameter to Java method
   372   // SP - sender_sp
   374   //const Address size_of_parameters(Rmethod,in_bytes( Method::size_of_parameters_offset()));
   376   // the bcp is valid if and only if it's not null
   377   __ call_VM(NOREG, CAST_FROM_FN_PTR(address,
   378       InterpreterRuntime::frequency_counter_overflow), R0);
   379   __ ld(Rmethod, FP, method_offset);
   380   // Preserve invariant that esi/edi contain bcp/locals of sender frame
   381   __ beq(R0, R0, *do_continue);
   382   __ delayed()->nop();
   383 }
   385 // See if we've got enough room on the stack for locals plus overhead.
   386 // The expression stack grows down incrementally, so the normal guard
   387 // page mechanism will work for that.
   388 //
   389 // NOTE: Since the additional locals are also always pushed (wasn't
   390 // obvious in generate_method_entry) so the guard should work for them
   391 // too.
   392 //
   393 // Args:
   394 //      rdx: number of additional locals this frame needs (what we must check)
   395 //      rbx: Method*
   396 //
   397 // Kills:
   398 //      rax
   399 void InterpreterGenerator::generate_stack_overflow_check(void) {
   400   // see if we've got enough room on the stack for locals plus overhead.
   401   // the expression stack grows down incrementally, so the normal guard
   402   // page mechanism will work for that.
   403   //
   404   // Registers live on entry:
   405   //
   406   // T0: Method*
   407   // T2: number of additional locals this frame needs (what we must check)
   409   // NOTE:  since the additional locals are also always pushed (wasn't obvious in
   410   // generate_method_entry) so the guard should work for them too.
   411   //
   413   // monitor entry size: see picture of stack set (generate_method_entry) and frame_i486.hpp
   414   const int entry_size    = frame::interpreter_frame_monitor_size() * wordSize;
   416   // total overhead size: entry_size + (saved ebp thru expr stack bottom).
   417   // be sure to change this if you add/subtract anything to/from the overhead area
   418   const int overhead_size = -(frame::interpreter_frame_initial_sp_offset*wordSize)
   419     + entry_size;
   421   const int page_size = os::vm_page_size();
   423   Label after_frame_check;
   425   // see if the frame is greater than one page in size. If so,
   426   // then we need to verify there is enough stack space remaining
   427   // for the additional locals.
   428   __ move(AT, (page_size - overhead_size) / Interpreter::stackElementSize);
   429   __ slt(AT, AT, T2);
   430   __ beq(AT, R0, after_frame_check);
   431   __ delayed()->nop();
   433   // compute sp as if this were going to be the last frame on
   434   // the stack before the red zone
   435 #ifndef OPT_THREAD
   436   Register thread = T1;
   437   __ get_thread(thread);
   438 #else
   439   Register thread = TREG;
   440 #endif
   442   // locals + overhead, in bytes
   443   //FIXME aoqi
   444   __ dsll(T3, T2, Interpreter::stackElementScale());
   445   __ daddiu(T3, T3, overhead_size);   // locals * 4 + overhead_size --> T3
   447 #ifdef ASSERT
   448   Label stack_base_okay, stack_size_okay;
   449   // verify that thread stack base is non-zero
   450   __ ld(AT, thread, in_bytes(Thread::stack_base_offset()));
   451   __ bne(AT, R0, stack_base_okay);
   452   __ delayed()->nop();
   453   __ stop("stack base is zero");
   454   __ bind(stack_base_okay);
   455   // verify that thread stack size is non-zero
   456   __ ld(AT, thread, in_bytes(Thread::stack_size_offset()));
   457   __ bne(AT, R0, stack_size_okay);
   458   __ delayed()->nop();
   459   __ stop("stack size is zero");
   460   __ bind(stack_size_okay);
   461 #endif
   463   // Add stack base to locals and subtract stack size
   464   __ ld(AT, thread, in_bytes(Thread::stack_base_offset())); // stack_base --> AT
   465   __ dadd(T3, T3, AT);   // locals * 4 + overhead_size + stack_base--> T3
   466   __ ld(AT, thread, in_bytes(Thread::stack_size_offset()));  // stack_size --> AT
   467   __ dsub(T3, T3, AT);  // locals * 4 + overhead_size + stack_base - stack_size --> T3
   470   // add in the redzone and yellow size
   471   __ move(AT, (StackRedPages+StackYellowPages) * page_size);
   472   __ add(T3, T3, AT);
   474   // check against the current stack bottom
   475   __ slt(AT, T3, SP);
   476   __ bne(AT, R0, after_frame_check);
   477   __ delayed()->nop();
   479   // Note: the restored frame is not necessarily interpreted.
   480   // Use the shared runtime version of the StackOverflowError.
   481   __ move(SP, Rsender);
   482   assert(StubRoutines::throw_StackOverflowError_entry() != NULL, "stub not yet generated");
   483   __ jmp(StubRoutines::throw_StackOverflowError_entry(), relocInfo::runtime_call_type);
   484   __ delayed()->nop();
   486   // all done with frame size check
   487   __ bind(after_frame_check);
   488 }
   490 // Allocate monitor and lock method (asm interpreter)
   491 // Rmethod - Method*
   492 void InterpreterGenerator::lock_method(void) {
   493   // synchronize method
   494   const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
   496 #ifdef ASSERT
   497   { Label L;
   498     __ lw(T0, Rmethod, in_bytes(Method::access_flags_offset()));
   499     __ andi(T0, T0, JVM_ACC_SYNCHRONIZED);
   500     __ bne(T0, R0, L);
   501     __ delayed()->nop();
   502     __ stop("method doesn't need synchronization");
   503     __ bind(L);
   504   }
   505 #endif // ASSERT
   506   // get synchronization object
   507   {
   508     Label done;
   509     const int mirror_offset = in_bytes(Klass::java_mirror_offset());
   510     __ lw(T0, Rmethod, in_bytes(Method::access_flags_offset()));
   511     __ andi(T2, T0, JVM_ACC_STATIC);
   512     __ ld(T0, LVP, Interpreter::local_offset_in_bytes(0));
   513     __ beq(T2, R0, done);
   514     __ delayed()->nop();
   515     __ ld(T0, Rmethod, in_bytes(Method::const_offset()));
   516     __ ld(T0, T0, in_bytes(ConstMethod::constants_offset()));
   517     __ ld(T0, T0, ConstantPool::pool_holder_offset_in_bytes());
   518     __ ld(T0, T0, mirror_offset);
   519     __ bind(done);
   520   }
   521   // add space for monitor & lock
   522   __ daddi(SP, SP, (-1) * entry_size);           // add space for a monitor entry
   523   __ sd(SP, FP, frame::interpreter_frame_monitor_block_top_offset * wordSize);
   524   // set new monitor block top
   525   __ sd(T0, SP, BasicObjectLock::obj_offset_in_bytes());   // store object
   526   // FIXME: I do not know what lock_object will do and what it will need
   527   __ move(c_rarg0, SP);      // object address
   528   __ lock_object(c_rarg0);
   529 }
   531 // Generate a fixed interpreter frame. This is identical setup for
   532 // interpreted methods and for native methods hence the shared code.
   533 void TemplateInterpreterGenerator::generate_fixed_frame(bool native_call) {
   535   // [ local var m-1      ] <--- sp
   536   //   ...
   537   // [ local var 0        ]
   538   // [ argumnet word n-1  ] <--- T0(sender's sp)
   539   //   ...
   540   // [ argument word 0    ] <--- S7
   542   // initialize fixed part of activation frame
   543   // sender's sp in Rsender
   544   int i = 0;
   545   __ sd(RA, SP, (-1) * wordSize);   // save return address
   546   __ sd(FP, SP, (-2) * wordSize);  // save sender's fp
   547   __ daddiu(FP, SP, (-2) * wordSize);
   548   __ sd(Rsender, FP, (-++i) * wordSize);  // save sender's sp
   549   __ sd(R0, FP,(-++i)*wordSize);       //save last_sp as null, FIXME aoqi
   550   __ sd(LVP, FP, (-++i) * wordSize);  // save locals offset
   551   __ ld(BCP, Rmethod, in_bytes(Method::const_offset())); // get constMethodOop
   552   __ daddiu(BCP, BCP, in_bytes(ConstMethod::codes_offset())); // get codebase
   553   __ sd(Rmethod, FP, (-++i) * wordSize);                              // save Method*
   554 #ifndef CORE
   555   if (ProfileInterpreter) {
   556     Label method_data_continue;
   557     __ ld(AT, Rmethod,  in_bytes(Method::method_data_offset()));
   558     __ beq(AT, R0, method_data_continue);
   559     __ delayed()->nop();
   560     __ daddi(AT, AT, in_bytes(MethodData::data_offset()));
   561     __ bind(method_data_continue);
   562     __ sd(AT, FP,  (-++i) * wordSize);
   563   } else {
   564     __ sd(R0, FP, (-++i) * wordSize);
   565   }
   566 #endif // !CORE
   568   __ ld(T2, Rmethod, in_bytes(Method::const_offset()));
   569   __ ld(T2, T2, in_bytes(ConstMethod::constants_offset()));
   570   __ ld(T2, T2, ConstantPool::cache_offset_in_bytes());
   571   __ sd(T2, FP, (-++i) * wordSize);                    // set constant pool cache
   572   if (native_call) {
   573     __ sd(R0, FP, (-++i) * wordSize);          // no bcp
   574   } else {
   575     __ sd(BCP, FP, (-++i) * wordSize);          // set bcp
   576   }
   577   __ daddiu(SP, FP, (-++i) * wordSize);
   578   __ sd(SP, FP, (-i) * wordSize);               // reserve word for pointer to expression stack bottom
   579 }
   581 // End of helpers
   583 // Various method entries
   584 //------------------------------------------------------------------------------------------------------------------------
   585 //
   586 //
   588 // Call an accessor method (assuming it is resolved, otherwise drop
   589 // into vanilla (slow path) entry
   590 address InterpreterGenerator::generate_accessor_entry(void) {
   592   // Rmethod: Method*
   593   // V0: receiver (preserve for slow entry into asm interpreter)
   594   //  Rsender: senderSP must preserved for slow path, set SP to it on fast path
   596   address entry_point = __ pc();
   597   Label xreturn_path;
   598   // do fastpath for resolved accessor methods
   599   if (UseFastAccessorMethods) {
   600     Label slow_path;
   601     __ li(T2, SafepointSynchronize::address_of_state());
   602     __ lw(AT, T2, 0);
   603     __ daddi(AT, AT, -(SafepointSynchronize::_not_synchronized));
   604     __ bne(AT, R0, slow_path);
   605     __ delayed()->nop();
   606     // Code: _aload_0, _(i|a)getfield, _(i|a)return or any rewrites thereof;
   607     // parameter size = 1
   608     // Note: We can only use this code if the getfield has been resolved
   609     //       and if we don't have a null-pointer exception => check for
   610     //       these conditions first and use slow path if necessary.
   611     // Rmethod: method
   612     // V0: receiver
   614     // [ receiver  ] <-- sp
   615     __ ld(T0, SP, 0);
   617     // check if local 0 != NULL and read field
   618     __ beq(T0, R0, slow_path);
   619     __ delayed()->nop();
   620     __ ld(T2, Rmethod, in_bytes(Method::const_offset()));
   621     __ ld(T2, T2, in_bytes(ConstMethod::constants_offset()));
   622     // read first instruction word and extract bytecode @ 1 and index @ 2
   623     __ ld(T3, Rmethod, in_bytes(Method::const_offset()));
   624     __ lw(T3, T3, in_bytes(ConstMethod::codes_offset()));
   625     // Shift codes right to get the index on the right.
   626     // The bytecode fetched looks like <index><0xb4><0x2a>
   627     __ dsrl(T3, T3, 2 * BitsPerByte);
   628     // FIXME: maybe it's wrong
   629     __ dsll(T3, T3, exact_log2(in_words(ConstantPoolCacheEntry::size())));
   630     __ ld(T2, T2, ConstantPool::cache_offset_in_bytes());
   632     // T0: local 0 eax
   633     // Rmethod: method ebx
   634     // V0: receiver - do not destroy since it is needed for slow path! ecx
   635     // ecx: scratch use which register instead ?
   636     // T1: scratch use which register instead ?
   637     // T3: constant pool cache index  edx
   638     // T2: constant pool cache  edi
   639     // esi: send's sp
   640     // Rsender: send's sp
   641     // check if getfield has been resolved and read constant pool cache entry
   642     // check the validity of the cache entry by testing whether _indices field
   643     // contains Bytecode::_getfield in b1 byte.
   644     assert(in_words(ConstantPoolCacheEntry::size()) == 4, "adjust shift below");
   645     //    __ movl(esi,
   646     //      Address(edi,
   647     //        edx,
   648     //        Address::times_4, ConstantPoolCache::base_offset()
   649     //        + ConstantPoolCacheEntry::indices_offset()));
   652     __ dsll(T8, T3, Address::times_8);
   653     __ move(T1, in_bytes(ConstantPoolCache::base_offset()
   654     + ConstantPoolCacheEntry::indices_offset()));
   655     __ dadd(T1, T8, T1);
   656     __ dadd(T1, T1, T2);
   657     __ lw(T1, T1, 0);
   658     __ dsrl(T1, T1, 2 * BitsPerByte);
   659     __ andi(T1, T1, 0xFF);
   660     __ daddi(T1, T1, (-1) * Bytecodes::_getfield);
   661     __ bne(T1, R0, slow_path);
   662     __ delayed()->nop();
   664     // Note: constant pool entry is not valid before bytecode is resolved
   666     __ move(T1, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::f2_offset()));
   667     __ dadd(T1, T1, T8);
   668     __ dadd(T1, T1, T2);
   669     __ lw(AT, T1, 0);
   671     __ move(T1, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::flags_offset()));
   672     __ dadd(T1, T1, T8);
   673     __ dadd(T1, T1, T2);
   674     __ lw(T3, T1, 0);
   676     Label notByte, notShort, notChar, notObj;
   677     //    const Address field_address (eax, esi, Address::times_1);
   679     // Need to differentiate between igetfield, agetfield, bgetfield etc.
   680     // because they are different sizes.
   681     // Use the type from the constant pool cache
   682     __ dsrl(T3, T3, ConstantPoolCacheEntry::tos_state_shift);
   683     // Make sure we don't need to mask edx for tosBits after the above shift
   684     ConstantPoolCacheEntry::verify_tos_state_shift();
   685     // btos = 0
   686     __ bne(T3, R0, notByte);
   687     __ delayed()->dadd(T0, T0, AT);
   689     __ lb(V0, T0, 0);
   690     __ b(xreturn_path);
   691     __ delayed()->nop();
   693     //stos
   694     __ bind(notByte);
   695     __ daddi(T1, T3, (-1) * stos);
   696     __ bne(T1, R0, notShort);
   697     __ delayed()->nop();
   698     __ lh(V0, T0, 0);
   699     __ b(xreturn_path);
   700     __ delayed()->nop();
   702     //ctos
   703     __ bind(notShort);
   704     __ daddi(T1, T3, (-1) * ctos);
   705     __ bne(T1, R0, notChar);
   706     __ delayed()->nop();
   707     __ lhu(V0, T0, 0);
   708     __ b(xreturn_path);
   709     __ delayed()->nop();
   711     //atos
   712     __ bind(notChar);
   713     __ daddi(T1, T3, (-1) * atos);
   714     __ bne(T1, R0, notObj);
   715     __ delayed()->nop();
   716     //add for compressedoops
   717     __ load_heap_oop(V0, Address(T0, 0));
   718     __ b(xreturn_path);
   719     __ delayed()->nop();
   721     //itos
   722     __ bind(notObj);
   723 #ifdef ASSERT
   724     Label okay;
   725     __ daddi(T1, T3, (-1) * itos);
   726     __ beq(T1, R0, okay);
   727     __ delayed()->nop();
   728     __ stop("what type is this?");
   729     __ bind(okay);
   730 #endif // ASSERT
   731     __ lw(V0, T0, 0);
   733     __ bind(xreturn_path);
   735     // _ireturn/_areturn
   736     //FIXME
   737     __ move(SP, Rsender);//FIXME, set sender's fp to SP
   738     __ jr(RA);
   739     __ delayed()->nop();
   741     // generate a vanilla interpreter entry as the slow path
   742     __ bind(slow_path);
   743     (void) generate_normal_entry(false);
   744   } else {
   745     (void) generate_normal_entry(false);
   746   }
   748   return entry_point;
   749 }
   751 // Method entry for java.lang.ref.Reference.get.
   752 address InterpreterGenerator::generate_Reference_get_entry(void) {
   753 #if INCLUDE_ALL_GCS
   754   // Code: _aload_0, _getfield, _areturn
   755   // parameter size = 1
   756   //
   757   // The code that gets generated by this routine is split into 2 parts:
   758   //    1. The "intrinsified" code for G1 (or any SATB based GC),
   759   //    2. The slow path - which is an expansion of the regular method entry.
   760   //
   761   // Notes:-
   762   // * In the G1 code we do not check whether we need to block for
   763   //   a safepoint. If G1 is enabled then we must execute the specialized
   764   //   code for Reference.get (except when the Reference object is null)
   765   //   so that we can log the value in the referent field with an SATB
   766   //   update buffer.
   767   //   If the code for the getfield template is modified so that the
   768   //   G1 pre-barrier code is executed when the current method is
   769   //   Reference.get() then going through the normal method entry
   770   //   will be fine.
   771   // * The G1 code can, however, check the receiver object (the instance
   772   //   of java.lang.Reference) and jump to the slow path if null. If the
   773   //   Reference object is null then we obviously cannot fetch the referent
   774   //   and so we don't need to call the G1 pre-barrier. Thus we can use the
   775   //   regular method entry code to generate the NPE.
   776   //
   777   // This code is based on generate_accessor_enty.
   778   //
   779   // rbx: Method*
   781   // r13: senderSP must preserve for slow path, set SP to it on fast path
   783   address entry = __ pc();
   785   const int referent_offset = java_lang_ref_Reference::referent_offset;
   786   guarantee(referent_offset > 0, "referent offset not initialized");
   788   if (UseG1GC) {
   789     Unimplemented();
   790     Label slow_path;
   791     // rbx: method
   793     // Check if local 0 != NULL
   794     // If the receiver is null then it is OK to jump to the slow path.
   796     // rax: local 0
   797     // rbx: method (but can be used as scratch now)
   798     // rdx: scratch
   799     // rdi: scratch
   801     // Generate the G1 pre-barrier code to log the value of
   802     // the referent field in an SATB buffer.
   804     // Load the value of the referent field.
   806     return entry;
   807   }
   808 #endif // INCLUDE_ALL_GCS
   810   // If G1 is not enabled then attempt to go through the accessor entry point
   811   // Reference.get is an accessor
   812   return generate_accessor_entry();
   813 }
   814 // Interpreter stub for calling a native method. (asm interpreter)
   815 // This sets up a somewhat different looking stack for calling the
   816 // native method than the typical interpreter frame setup.
   817 address InterpreterGenerator::generate_native_entry(bool synchronized) {
   818   // determine code generation flags
   819   bool inc_counter  = UseCompiler || CountCompiledCalls;
   820   // Rsender: sender's sp
   821   // Rmethod: Method*
   822   address entry_point = __ pc();
   824 #ifndef CORE
   825   const Address invocation_counter(Rmethod,in_bytes(MethodCounters::invocation_counter_offset() +   // Fu: 20130814
   826   InvocationCounter::counter_offset()));
   827 #endif
   829   // get parameter size (always needed)
   830   // the size in the java stack
   831   __ ld(V0, Rmethod, in_bytes(Method::const_offset()));
   832   __ lhu(V0, V0, in_bytes(ConstMethod::size_of_parameters_offset()));   // Fu: 20130814
   834   // native calls don't need the stack size check since they have no expression stack
   835   // and the arguments are already on the stack and we only add a handful of words
   836   // to the stack
   838   // Rmethod: Method*
   839   // V0: size of parameters
   840   // Layout of frame at this point
   841   //
   842   // [ argument word n-1  ] <--- sp
   843   //   ...
   844   // [ argument word 0    ]
   846   // for natives the size of locals is zero
   848   // compute beginning of parameters (S7)
   849   __ dsll(LVP, V0, Address::times_8);
   850   __ daddiu(LVP, LVP, (-1) * wordSize);
   851   __ dadd(LVP, LVP, SP);
   854   // add 2 zero-initialized slots for native calls
   855   __ daddi(SP, SP, (-2) * wordSize);
   856   __ sd(R0, SP, 1 * wordSize);  // slot for native oop temp offset (setup via runtime)
   857   __ sd(R0, SP, 0 * wordSize);  // slot for static native result handler3 (setup via runtime)
   859   // Layout of frame at this point
   860   // [ method holder mirror  ] <--- sp
   861   // [ result type info      ]
   862   // [ argument word n-1     ] <--- T0
   863   //   ...
   864   // [ argument word 0      ] <--- LVP
   867 #ifndef CORE
   868   if (inc_counter) __ lw(T3, invocation_counter);  // (pre-)fetch invocation count
   869 #endif
   871   // initialize fixed part of activation frame
   872   generate_fixed_frame(true);
   873   // after this function, the layout of frame is as following
   874   //
   875   // [ monitor block top        ] <--- sp ( the top monitor entry )
   876   // [ byte code pointer (0)    ] (if native, bcp = 0)
   877   // [ constant pool cache      ]
   878   // [ Method*                ]
   879   // [ locals offset            ]
   880   // [ sender's sp              ]
   881   // [ sender's fp              ]
   882   // [ return address           ] <--- fp
   883   // [ method holder mirror     ]
   884   // [ result type info         ]
   885   // [ argumnet word n-1        ] <--- sender's sp
   886   //   ...
   887   // [ argument word 0          ] <--- S7
   890   // make sure method is native & not abstract
   891 #ifdef ASSERT
   892   __ lw(T0, Rmethod, in_bytes(Method::access_flags_offset()));
   893   {
   894     Label L;
   895     __ andi(AT, T0, JVM_ACC_NATIVE);
   896     __ bne(AT, R0, L);
   897     __ delayed()->nop();
   898     __ stop("tried to execute native method as non-native");
   899     __ bind(L);
   900   }
   901   {
   902     Label L;
   903     __ andi(AT, T0, JVM_ACC_ABSTRACT);
   904     __ beq(AT, R0, L);
   905     __ delayed()->nop();
   906     __ stop("tried to execute abstract method in interpreter");
   907     __ bind(L);
   908   }
   909 #endif
   911   // Since at this point in the method invocation the exception handler
   912   // would try to exit the monitor of synchronized methods which hasn't
   913   // been entered yet, we set the thread local variable
   914   // _do_not_unlock_if_synchronized to true. The remove_activation will
   915   // check this flag.
   916   Register thread = TREG;
   917 #ifndef OPT_THREAD
   918   __ get_thread(thread);
   919 #endif
   920   __ move(AT, (int)true);
   921   __ sb(AT, thread, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
   923 #ifndef CORE
   924   // increment invocation count & check for overflow
   925   Label invocation_counter_overflow;
   926   if (inc_counter) {
   927     generate_counter_incr(&invocation_counter_overflow, NULL, NULL);
   928   }
   930   Label continue_after_compile;
   931   __ bind(continue_after_compile);
   932 #endif // CORE
   934   bang_stack_shadow_pages(true);
   936   // reset the _do_not_unlock_if_synchronized flag
   937 #ifndef OPT_THREAD
   938   __ get_thread(thread);
   939 #endif
   940   __ sb(R0, thread, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
   942   // check for synchronized methods
   943   // Must happen AFTER invocation_counter check and stack overflow check,
   944   // so method is not locked if overflows.
   945   if (synchronized) {
   946     lock_method();
   947   } else {
   948     // no synchronization necessary
   949 #ifdef ASSERT
   950     {
   951       Label L;
   952       __ lw(T0, Rmethod, in_bytes(Method::access_flags_offset()));
   953       __ andi(AT, T0, JVM_ACC_SYNCHRONIZED);
   954       __ beq(AT, R0, L);
   955       __ delayed()->nop();
   956       __ stop("method needs synchronization");
   957       __ bind(L);
   958     }
   959 #endif
   960   }
   962   // after method_lock, the layout of frame is as following
   963   //
   964   // [ monitor entry            ] <--- sp
   965   //   ...
   966   // [ monitor entry            ]
   967   // [ monitor block top        ] ( the top monitor entry )
   968   // [ byte code pointer (0)    ] (if native, bcp = 0)
   969   // [ constant pool cache      ]
   970   // [ Method*                ]
   971   // [ locals offset        ]
   972   // [ sender's sp              ]
   973   // [ sender's fp              ]
   974   // [ return address           ] <--- fp
   975   // [ method holder mirror     ]
   976   // [ result type info         ]
   977   // [ argumnet word n-1        ] <--- ( sender's sp )
   978   //   ...
   979   // [ argument word 0          ] <--- S7
   981   // start execution
   982 #ifdef ASSERT
   983   {
   984     Label L;
   985     __ ld(AT, FP, frame::interpreter_frame_monitor_block_top_offset * wordSize);
   986     __ beq(AT, SP, L);
   987     __ delayed()->nop();
   988     __ stop("broken stack frame setup in interpreter in asm");
   989     __ bind(L);
   990   }
   991 #endif
   993   // jvmti/jvmpi support
   994   __ notify_method_entry();
   996   // work registers
   997   const Register method = Rmethod;
   998   //const Register thread = T2;
   999   const Register t      = RT4;
  1001   __ get_method(method);
  1002   __ verify_oop(method);
  1004     Label L, Lstatic;
  1005     __ ld(t,method,in_bytes(Method::const_offset()));
  1006     __ lhu(t, t, in_bytes(ConstMethod::size_of_parameters_offset()));  // Fu: 20130814
  1007     // MIPS n64 ABI: caller does not reserve space for the register auguments.
  1008     //FIXME, aoqi: A1?
  1009     // A0 and A1(if needed)
  1010     __ lw(AT, Rmethod, in_bytes(Method::access_flags_offset()));
  1011     __ andi(AT, AT, JVM_ACC_STATIC);
  1012     __ beq(AT, R0, Lstatic);
  1013     __ delayed()->nop();
  1014     __ daddiu(t, t, 1);
  1015     __ bind(Lstatic);
  1016     __ daddiu(t, t, -7);
  1017     __ blez(t, L);
  1018     __ delayed()->nop();
  1019     __ dsll(t, t, Address::times_8);
  1020     __ dsub(SP, SP, t);
  1021     __ bind(L);
  1023   __ move(AT, -(StackAlignmentInBytes));
  1024   __ andr(SP, SP, AT);
  1025   __ move(AT, SP);
  1026   // [        ] <--- sp
  1027   //   ...                        (size of parameters - 8 )
  1028   // [ monitor entry            ]
  1029   //   ...
  1030   // [ monitor entry            ]
  1031   // [ monitor block top        ] ( the top monitor entry )
  1032   // [ byte code pointer (0)    ] (if native, bcp = 0)
  1033   // [ constant pool cache      ]
  1034   // [ Method*                ]
  1035   // [ locals offset            ]
  1036   // [ sender's sp              ]
  1037   // [ sender's fp              ]
  1038   // [ return address           ] <--- fp
  1039   // [ method holder mirror     ]
  1040   // [ result type info         ]
  1041   // [ argumnet word n-1        ] <--- ( sender's sp )
  1042   //   ...
  1043   // [ argument word 0          ] <--- LVP
  1045   // get signature handler
  1047     Label L;
  1048     __ ld(T9, method, in_bytes(Method::signature_handler_offset()));
  1049     __ bne(T9, R0, L);
  1050     __ delayed()->nop();
  1051     __ call_VM(NOREG, CAST_FROM_FN_PTR(address,
  1052                InterpreterRuntime::prepare_native_call), method);
  1053     __ get_method(method);
  1054     __ ld(T9, method, in_bytes(Method::signature_handler_offset()));
  1055     __ bind(L);
  1058   // call signature handler
  1059   // FIXME: when change codes in InterpreterRuntime, note this point
  1060   // from: begin of parameters
  1061   assert(InterpreterRuntime::SignatureHandlerGenerator::from() == LVP, "adjust this code");
  1062   // to: current sp
  1063   assert(InterpreterRuntime::SignatureHandlerGenerator::to  () == SP, "adjust this code");
  1064   // temp: T3
  1065   assert(InterpreterRuntime::SignatureHandlerGenerator::temp() == t  , "adjust this code");
  1067   __ jalr(T9);
  1068   __ delayed()->nop();
  1069   __ get_method(method);  // slow path call blows EBX on DevStudio 5.0
  1071   /*
  1072      if native function is static, and its second parameter has type length of double word,
  1073      and first parameter has type length of word, we have to reserve one word
  1074      for the first parameter, according to mips o32 abi.
  1075      if native function is not static, and its third parameter has type length of double word,
  1076      and second parameter has type length of word, we have to reserve one word for the second
  1077      parameter.
  1078    */
  1081   // result handler is in V0
  1082   // set result handler
  1083   __ sd(V0, FP, (frame::interpreter_frame_result_handler_offset)*wordSize);
  1085 #define FIRSTPARA_SHIFT_COUNT 5
  1086 #define SECONDPARA_SHIFT_COUNT 9
  1087 #define THIRDPARA_SHIFT_COUNT 13
  1088 #define PARA_MASK  0xf
  1090   // pass mirror handle if static call
  1092     Label L;
  1093     const int mirror_offset = in_bytes(Klass::java_mirror_offset());
  1094     __ lw(t, method, in_bytes(Method::access_flags_offset()));
  1095     __ andi(AT, t, JVM_ACC_STATIC);
  1096     __ beq(AT, R0, L);
  1097     __ delayed()->nop();
  1099     // get mirror
  1100     __ ld(t, method, in_bytes(Method:: const_offset()));
  1101     __ ld(t, t, in_bytes(ConstMethod::constants_offset())); //??
  1102     __ ld(t, t, ConstantPool::pool_holder_offset_in_bytes());
  1103     __ ld(t, t, mirror_offset);
  1104     // copy mirror into activation frame
  1105     //__ sw(t, FP, frame::interpreter_frame_oop_temp_offset * wordSize);
  1106     // pass handle to mirror
  1107     __ sd(t, FP, frame::interpreter_frame_oop_temp_offset * wordSize);
  1108     __ daddi(t, FP, frame::interpreter_frame_oop_temp_offset * wordSize);
  1109     __ move(A1, t);
  1110     __ bind(L);
  1113   // [ mthd holder mirror ptr   ] <--- sp  --------------------| (only for static method)
  1114   // [                          ]                              |
  1115   //   ...                        size of parameters(or +1)    |
  1116   // [ monitor entry            ]                              |
  1117   //   ...                                                     |
  1118   // [ monitor entry            ]                              |
  1119   // [ monitor block top        ] ( the top monitor entry )    |
  1120   // [ byte code pointer (0)    ] (if native, bcp = 0)         |
  1121   // [ constant pool cache      ]                              |
  1122   // [ Method*                ]                              |
  1123   // [ locals offset            ]                              |
  1124   // [ sender's sp              ]                              |
  1125   // [ sender's fp              ]                              |
  1126   // [ return address           ] <--- fp                      |
  1127   // [ method holder mirror     ] <----------------------------|
  1128   // [ result type info         ]
  1129   // [ argumnet word n-1        ] <--- ( sender's sp )
  1130   //   ...
  1131   // [ argument word 0          ] <--- S7
  1133   // get native function entry point
  1134   { Label L;
  1135     __ ld(T9, method, in_bytes(Method::native_function_offset()));
  1136     __ li(V1, SharedRuntime::native_method_throw_unsatisfied_link_error_entry());
  1137     __ bne(V1, T9, L);
  1138     __ delayed()->nop();
  1139     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), method);
  1140     __ get_method(method);
  1141     __ verify_oop(method);
  1142     __ ld(T9, method, in_bytes(Method::native_function_offset()));
  1143     __ bind(L);
  1145   /*
  1146   __ pushad();
  1147   __ move(A0, T9);
  1148   __ call(CAST_FROM_FN_PTR(address, SharedRuntime::func_debug),relocInfo::runtime_call_type);
  1149   __ popad();
  1150   */
  1152   // pass JNIEnv
  1153   // native function in T9
  1154 #ifndef OPT_THREAD
  1155   __ get_thread(thread);
  1156 #endif
  1157   __ daddi(t, thread, in_bytes(JavaThread::jni_environment_offset()));
  1158   // stack,but I think it won't work when pass float,double etc @jerome,10/17,2006
  1159   __ move(A0, t);
  1160   // [ jni environment          ] <--- sp
  1161   // [ mthd holder mirror ptr   ] ---------------------------->| (only for static method)
  1162   // [                          ]                              |
  1163   //   ...                        size of parameters           |
  1164   // [ monitor entry            ]                              |
  1165   //   ...                                                     |
  1166   // [ monitor entry            ]                              |
  1167   // [ monitor block top        ] ( the top monitor entry )    |
  1168   // [ byte code pointer (0)    ] (if native, bcp = 0)         |
  1169   // [ constant pool cache      ]                              |
  1170   // [ Method*                ]                              |
  1171   // [ locals offset            ]                              |
  1172   // [ sender's sp              ]                              |
  1173   // [ sender's fp              ]                              |
  1174   // [ return address           ] <--- fp                      |
  1175   // [ method holder mirror     ] <----------------------------|
  1176   // [ result type info         ]
  1177   // [ argumnet word n-1        ] <--- ( sender's sp )
  1178   //   ...
  1179   // [ argument word 0          ] <--- S7
  1181   // set_last_Java_frame_before_call
  1182   __ sd(FP, thread, in_bytes(JavaThread::last_Java_fp_offset()));
  1183   // Change state to native (we save the return address in the thread, since it might not
  1184   // be pushed on the stack when we do a a stack traversal). It is enough that the pc()
  1185   // points into the right code segment. It does not have to be the correct return pc.
  1186   __ li(t, __ pc());
  1187   __ sd(t, thread, in_bytes(JavaThread::last_Java_pc_offset()));
  1188   __ sd(SP, thread, in_bytes(JavaThread::last_Java_sp_offset()));
  1190   // change thread state
  1191 #ifdef ASSERT
  1193     Label L;
  1194     __ lw(t, thread, in_bytes(JavaThread::thread_state_offset()));
  1195     __ daddi(t, t, (-1) * _thread_in_Java);
  1196     __ beq(t, R0, L);
  1197     __ delayed()->nop();
  1198     __ stop("Wrong thread state in native stub");
  1199     __ bind(L);
  1201 #endif
  1203   __ move(t, _thread_in_native);
  1204   __ sw(t, thread, in_bytes(JavaThread::thread_state_offset()));
  1206   // call native method
  1207   __ jalr(T9);
  1208   __ delayed()->nop();
  1209   // result potentially in V2:V1 or F0:F1
  1212   // via _last_native_pc and not via _last_jave_sp
  1213   // NOTE: the order of theses push(es) is known to frame::interpreter_frame_result.
  1214   //  If the order changes or anything else is added to the stack the code in
  1215   // interpreter_frame_result will have to be changed.
  1216   //FIXME, should modify here
  1217   // save return value to keep the value from being destroyed by other calls
  1218   __ move(S1, V0);
  1219   __ move(S3, V1);
  1220   __ dmfc1(S4, F0);
  1221   __ dmfc1(S2, F1);
  1223   // change thread state
  1224   __ get_thread(thread);
  1225   __ move(t, _thread_in_native_trans);
  1226   __ sw(t, thread, in_bytes(JavaThread::thread_state_offset()));
  1228   if( os::is_MP() ) __ sync(); // Force this write out before the read below
  1230   // check for safepoint operation in progress and/or pending suspend requests
  1231   { Label Continue;
  1233     // Don't use call_VM as it will see a possible pending exception and forward it
  1234     // and never return here preventing us from clearing _last_native_pc down below.
  1235     // Also can't use call_VM_leaf either as it will check to see if esi & edi are
  1236     // preserved and correspond to the bcp/locals pointers. So we do a runtime call
  1237     // by hand.
  1238     //
  1239     Label L;
  1240     __ li(AT, SafepointSynchronize::address_of_state());
  1241     __ lw(AT, AT, 0);
  1242     __ bne(AT, R0, L);
  1243     __ delayed()->nop();
  1244     __ lw(AT, thread, in_bytes(JavaThread::suspend_flags_offset()));
  1245     __ beq(AT, R0, Continue);
  1246     __ delayed()->nop();
  1247     __ bind(L);
  1248     __ move(A0, thread);
  1249     __ call(CAST_FROM_FN_PTR(address,
  1250     JavaThread::check_special_condition_for_native_trans),
  1251   relocInfo::runtime_call_type);
  1252     __ delayed()->nop();
  1254 #ifndef OPT_THREAD
  1255     __ get_thread(thread);
  1256 #endif
  1257     //add for compressedoops
  1258     __ reinit_heapbase();
  1259     __ bind(Continue);
  1262   // change thread state
  1263   __ move(t, _thread_in_Java);
  1264   __ sw(t, thread, in_bytes(JavaThread::thread_state_offset()));
  1265   __ reset_last_Java_frame(thread, true, true);
  1267   // reset handle block
  1268   __ ld(t, thread, in_bytes(JavaThread::active_handles_offset()));
  1269   __ sw(R0, t, JNIHandleBlock::top_offset_in_bytes());
  1271   // If result was an oop then unbox and save it in the frame
  1272   { Label L;
  1273     Label no_oop, store_result;
  1274     //FIXME, addi only support 16-bit imeditate
  1275     __ ld(AT, FP, frame::interpreter_frame_result_handler_offset*wordSize);
  1276     __ li(T0, AbstractInterpreter::result_handler(T_OBJECT));
  1277     __ bne(AT, T0, no_oop);
  1278     __ delayed()->nop();
  1279     __ move(V0, S1);
  1280     __ beq(V0, R0, store_result);
  1281     __ delayed()->nop();
  1282     // unbox
  1283     __ ld(V0, V0, 0);
  1284     __ bind(store_result);
  1285     __ sd(V0, FP, (frame::interpreter_frame_oop_temp_offset)*wordSize);
  1286     // keep stack depth as expected by pushing oop which will eventually be discarded
  1287     __ bind(no_oop);
  1290     Label no_reguard;
  1291     __ lw(t, thread, in_bytes(JavaThread::stack_guard_state_offset()));
  1292     __ move(AT,(int) JavaThread::stack_guard_yellow_disabled);
  1293     __ bne(t, AT, no_reguard);
  1294     __ delayed()->nop();
  1295     __ pushad();
  1296     __ call(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages), relocInfo::runtime_call_type);
  1297     __ delayed()->nop();
  1298     __ popad();
  1299     //add for compressedoops
  1300     __ reinit_heapbase();
  1301     __ bind(no_reguard);
  1303   // restore esi to have legal interpreter frame,
  1304   // i.e., bci == 0 <=> esi == code_base()
  1305   // Can't call_VM until bcp is within reasonable.
  1306   __ get_method(method);      // method is junk from thread_in_native to now.
  1307   __ verify_oop(method);
  1308   __ ld(BCP, method, in_bytes(Method::const_offset()));
  1309   __ lea(BCP, Address(BCP, in_bytes(ConstMethod::codes_offset())));
  1310   // handle exceptions (exception handling will handle unlocking!)
  1312     Label L;
  1313     __ lw(t, thread, in_bytes(Thread::pending_exception_offset()));
  1314     __ beq(t, R0, L);
  1315     __ delayed()->nop();
  1316     // Note: At some point we may want to unify this with the code used in
  1317     // call_VM_base();
  1318     // i.e., we should use the StubRoutines::forward_exception code. For now this
  1319     // doesn't work here because the esp is not correctly set at this point.
  1320     __ MacroAssembler::call_VM(noreg, CAST_FROM_FN_PTR(address,
  1321     InterpreterRuntime::throw_pending_exception));
  1322     __ should_not_reach_here();
  1323     __ bind(L);
  1326   // do unlocking if necessary
  1328     Label L;
  1329     __ lw(t, method, in_bytes(Method::access_flags_offset()));
  1330     __ andi(t, t, JVM_ACC_SYNCHRONIZED);
  1331     __ beq(t, R0, L);
  1332     // the code below should be shared with interpreter macro assembler implementation
  1334       Label unlock;
  1335       // BasicObjectLock will be first in list,
  1336       // since this is a synchronized method. However, need
  1337       // to check that the object has not been unlocked by
  1338       // an explicit monitorexit bytecode.
  1339       __ delayed()->daddi(c_rarg0, FP, frame::interpreter_frame_initial_sp_offset * wordSize - (int)sizeof(BasicObjectLock));
  1340       // address of first monitor
  1342       __ ld(t, c_rarg0, BasicObjectLock::obj_offset_in_bytes());
  1343       __ bne(t, R0, unlock);
  1344       __ delayed()->nop();
  1346       // Entry already unlocked, need to throw exception
  1347       __ MacroAssembler::call_VM(NOREG, CAST_FROM_FN_PTR(address,
  1348       InterpreterRuntime::throw_illegal_monitor_state_exception));
  1349       __ should_not_reach_here();
  1351       __ bind(unlock);
  1352       __ unlock_object(c_rarg0);
  1354     __ bind(L);
  1357   // jvmti/jvmpi support
  1358   // Note: This must happen _after_ handling/throwing any exceptions since
  1359   //       the exception handler code notifies the runtime of method exits
  1360   //       too. If this happens before, method entry/exit notifications are
  1361   //       not properly paired (was bug - gri 11/22/99).
  1362   __ notify_method_exit(false, vtos, InterpreterMacroAssembler::NotifyJVMTI );
  1364   // restore potential result in V0:V1,
  1365   // call result handler to restore potential result in ST0 & handle result
  1366   //__ lw(V0, SP, 3 * wordSize);
  1367   //__ lw(V1, SP, 2 * wordSize);
  1368   //__ lwc1(F0, SP, 1 * wordSize);
  1369   //__ lwc1(F1, SP, 0 * wordSize);
  1370   //__ addi(SP, SP, 4 * wordSize);
  1371   __ move(V0, S1);
  1372   __ move(V1, S3);
  1373   __ dmtc1(S4, F0);
  1374   __ dmtc1(S2, F1);
  1375   __ ld(t, FP, (frame::interpreter_frame_result_handler_offset) * wordSize);
  1376   __ jalr(t);
  1377   __ delayed()->nop();
  1380   // remove activation
  1381   __ ld(SP, FP, frame::interpreter_frame_sender_sp_offset * wordSize); // get sender sp
  1382   __ ld(RA, FP, frame::interpreter_frame_return_addr_offset * wordSize); // get return address
  1383   __ ld(FP, FP, frame::interpreter_frame_sender_fp_offset * wordSize); // restore sender's fp
  1384   __ jr(RA);
  1385   __ delayed()->nop();
  1387 #ifndef CORE
  1388   if (inc_counter) {
  1389     // Handle overflow of counter and compile method
  1390     __ bind(invocation_counter_overflow);
  1391     generate_counter_overflow(&continue_after_compile);
  1392     // entry_point is the beginning of this
  1393     // function and checks again for compiled code
  1395 #endif
  1396   return entry_point;
  1399 //
  1400 // Generic interpreted method entry to (asm) interpreter
  1401 //
  1402 // Layout of frame just at the entry
  1403 //
  1404 //   [ argument word n-1  ] <--- sp
  1405 //     ...
  1406 //   [ argument word 0    ]
  1407 // assume Method* in Rmethod before call this method.
  1408 // prerequisites to the generated stub : the callee Method* in Rmethod
  1409 // note you must save the caller bcp before call the generated stub
  1410 //
  1411 address InterpreterGenerator::generate_normal_entry(bool synchronized) {
  1412   // determine code generation flags
  1413   bool inc_counter  = UseCompiler || CountCompiledCalls;
  1415   // Rmethod: Method*
  1416   // Rsender: sender 's sp
  1417   address entry_point = __ pc();
  1418   /*
  1419 #ifndef CORE
  1420   // check if compiled code exists
  1421   Label run_compiled_code;
  1422   if (!CompileTheWorld) {
  1423   check_for_compiled_code(run_compiled_code);
  1425 #endif
  1426    */
  1427 #ifndef CORE
  1428   const Address invocation_counter(Rmethod,
  1429       in_bytes(MethodCounters::invocation_counter_offset() + InvocationCounter::counter_offset()));
  1430 #endif
  1432   // get parameter size (always needed)
  1433   __ ld(T3, Rmethod, in_bytes(Method::const_offset()));  //T3 --> Rmethod._constMethod
  1434   __ lhu(V0, T3, in_bytes(ConstMethod::size_of_parameters_offset()));
  1436   // Rmethod: Method*
  1437   // V0: size of parameters
  1438   // Rsender: sender 's sp ,could be different frome sp+ wordSize if we call via c2i
  1439   // get size of locals in words to T2
  1440   __ lhu(T2, T3, in_bytes(ConstMethod::size_of_locals_offset()));
  1441   // T2 = no. of additional locals, locals include parameters
  1442   __ dsub(T2, T2, V0);
  1444   // see if we've got enough room on the stack for locals plus overhead.
  1445   // Layout of frame at this point
  1446   //
  1447   // [ argument word n-1  ] <--- sp
  1448   //   ...
  1449   // [ argument word 0    ]
  1450   generate_stack_overflow_check();
  1451   // after this function, the layout of frame does not change
  1453   // compute beginning of parameters (LVP)
  1454   __ dsll(LVP, V0, LogBytesPerWord);
  1455   __ daddiu(LVP, LVP, (-1) * wordSize);
  1456   __ dadd(LVP, LVP, SP);
  1458   // T2 - # of additional locals
  1459   // allocate space for locals
  1460   // explicitly initialize locals
  1462     Label exit, loop;
  1463     __ beq(T2, R0, exit);
  1464     __ delayed()->nop();
  1465     __ bind(loop);
  1466     __ sd(R0, SP, -1 * wordSize);     // initialize local variables
  1467     __ daddiu(T2, T2, -1);               // until everything initialized
  1468     __ bne(T2, R0, loop);
  1469     __ delayed();
  1470     __ daddiu(SP, SP, (-1) * wordSize); //fill delay slot
  1471     __ bind(exit);
  1474 #ifndef CORE
  1475   if (inc_counter) __ lw(T3, invocation_counter);  // (pre-)fetch invocation count
  1476 #endif
  1477   //
  1478   // [ local var m-1  ] <--- sp
  1479   //   ...
  1480   // [ local var 0  ]
  1481   // [ argument word n-1  ] <--- T0?
  1482   //   ...
  1483   // [ argument word 0    ] <--- LVP
  1485   // initialize fixed part of activation frame
  1487   generate_fixed_frame(false);
  1490   // after this function, the layout of frame is as following
  1491   //
  1492   // [ monitor block top        ] <--- sp ( the top monitor entry )
  1493   // [ byte code pointer        ] (if native, bcp = 0)
  1494   // [ constant pool cache      ]
  1495   // [ Method*                ]
  1496   // [ locals offset    ]
  1497   // [ sender's sp              ]
  1498   // [ sender's fp              ] <--- fp
  1499   // [ return address           ]
  1500   // [ local var m-1            ]
  1501   //   ...
  1502   // [ local var 0              ]
  1503   // [ argumnet word n-1        ] <--- ( sender's sp )
  1504   //   ...
  1505   // [ argument word 0          ] <--- LVP
  1508   // make sure method is not native & not abstract
  1509 #ifdef ASSERT
  1510   __ ld(AT, Rmethod, in_bytes(Method::access_flags_offset()));
  1512     Label L;
  1513     __ andi(T2, AT, JVM_ACC_NATIVE);
  1514     __ beq(T2, R0, L);
  1515     __ delayed()->nop();
  1516     __ stop("tried to execute native method as non-native");
  1517     __ bind(L);
  1520     Label L;
  1521     __ andi(T2, AT, JVM_ACC_ABSTRACT);
  1522     __ beq(T2, R0, L);
  1523     __ delayed()->nop();
  1524     __ stop("tried to execute abstract method in interpreter");
  1525     __ bind(L);
  1527 #endif
  1529   // Since at this point in the method invocation the exception handler
  1530   // would try to exit the monitor of synchronized methods which hasn't
  1531   // been entered yet, we set the thread local variable
  1532   // _do_not_unlock_if_synchronized to true. The remove_activation will
  1533   // check this flag.
  1535 #ifndef OPT_THREAD
  1536   Register thread = T8;
  1537   __ get_thread(thread);
  1538 #else
  1539   Register thread = TREG;
  1540 #endif
  1541   __ move(AT, (int)true);
  1542   __ sb(AT, thread, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
  1544 #ifndef CORE
  1546   // 2014/11/24 Fu
  1547   // mdp : T8
  1548   // tmp1: T9
  1549   // tmp2: T2
  1550    __ profile_parameters_type(T8, T9, T2);
  1552   // increment invocation count & check for overflow
  1553   Label invocation_counter_overflow;
  1554   Label profile_method;
  1555   Label profile_method_continue;
  1556   if (inc_counter) {
  1557     generate_counter_incr(&invocation_counter_overflow,
  1558                           &profile_method,
  1559                           &profile_method_continue);
  1560     if (ProfileInterpreter) {
  1561       __ bind(profile_method_continue);
  1565   Label continue_after_compile;
  1566   __ bind(continue_after_compile);
  1568 #endif // CORE
  1570   bang_stack_shadow_pages(false);
  1572   // reset the _do_not_unlock_if_synchronized flag
  1573 #ifndef OPT_THREAD
  1574   __ get_thread(thread);
  1575 #endif
  1576   __ sb(R0, thread, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
  1578   // check for synchronized methods
  1579   // Must happen AFTER invocation_counter check and stack overflow check,
  1580   // so method is not locked if overflows.
  1581   //
  1582   if (synchronized) {
  1583     // Allocate monitor and lock method
  1584     lock_method();
  1585   } else {
  1586     // no synchronization necessary
  1587 #ifdef ASSERT
  1588     { Label L;
  1589       __ lw(AT, Rmethod, in_bytes(Method::access_flags_offset()));
  1590       __ andi(T2, AT, JVM_ACC_SYNCHRONIZED);
  1591       __ beq(T2, R0, L);
  1592       __ delayed()->nop();
  1593       __ stop("method needs synchronization");
  1594       __ bind(L);
  1596 #endif
  1599   // layout of frame after lock_method
  1600   // [ monitor entry        ] <--- sp
  1601   //   ...
  1602   // [ monitor entry        ]
  1603   // [ monitor block top        ] ( the top monitor entry )
  1604   // [ byte code pointer        ] (if native, bcp = 0)
  1605   // [ constant pool cache      ]
  1606   // [ Method*                ]
  1607   // [ locals offset        ]
  1608   // [ sender's sp              ]
  1609   // [ sender's fp              ]
  1610   // [ return address           ] <--- fp
  1611   // [ local var m-1            ]
  1612   //   ...
  1613   // [ local var 0              ]
  1614   // [ argumnet word n-1        ] <--- ( sender's sp )
  1615   //   ...
  1616   // [ argument word 0          ] <--- LVP
  1619   // start execution
  1620 #ifdef ASSERT
  1622     Label L;
  1623     __ ld(AT, FP, frame::interpreter_frame_monitor_block_top_offset * wordSize);
  1624     __ beq(AT, SP, L);
  1625     __ delayed()->nop();
  1626     __ stop("broken stack frame setup in interpreter in native");
  1627     __ bind(L);
  1629 #endif
  1631   // jvmti/jvmpi support
  1632   __ notify_method_entry();
  1634   __ dispatch_next(vtos);
  1636 #ifndef CORE
  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 #endif
  1655   return entry_point;
  1658 // Entry points
  1659 //
  1660 // Here we generate the various kind of entries into the interpreter.
  1661 // The two main entry type are generic bytecode methods and native
  1662 // call method.  These both come in synchronized and non-synchronized
  1663 // versions but the frame layout they create is very similar. The
  1664 // other method entry types are really just special purpose entries
  1665 // that are really entry and interpretation all in one. These are for
  1666 // trivial methods like accessor, empty, or special math methods.
  1667 //
  1668 // When control flow reaches any of the entry types for the interpreter
  1669 // the following holds ->
  1670 //
  1671 // Arguments:
  1672 //
  1673 // Rmethod: Method*
  1674 // V0: receiver
  1675 //
  1676 //
  1677 // Stack layout immediately at entry
  1678 //
  1679 // [ parameter n-1      ] <--- sp
  1680 //   ...
  1681 // [ parameter 0        ]
  1682 // [ expression stack   ] (caller's java expression stack)
  1684 // Assuming that we don't go to one of the trivial specialized entries
  1685 // the stack will look like below when we are ready to execute the
  1686 // first bytecode (or call the native routine). The register usage
  1687 // will be as the template based interpreter expects (see
  1688 // interpreter_amd64.hpp).
  1689 //
  1690 // local variables follow incoming parameters immediately; i.e.
  1691 // the return address is moved to the end of the locals).
  1692 //
  1693 // [ monitor entry        ] <--- sp
  1694 //   ...
  1695 // [ monitor entry        ]
  1696 // [ monitor block top        ] ( the top monitor entry )
  1697 // [ byte code pointer        ] (if native, bcp = 0)
  1698 // [ constant pool cache      ]
  1699 // [ Method*                ]
  1700 // [ locals offset        ]
  1701 // [ sender's sp              ]
  1702 // [ sender's fp              ]
  1703 // [ return address           ] <--- fp
  1704 // [ local var m-1            ]
  1705 //   ...
  1706 // [ local var 0              ]
  1707 // [ argumnet word n-1        ] <--- ( sender's sp )
  1708 //   ...
  1709 // [ argument word 0          ] <--- S7
  1711 address AbstractInterpreterGenerator::generate_method_entry(
  1712                                         AbstractInterpreter::MethodKind kind) {
  1713   // determine code generation flags
  1714   bool synchronized = false;
  1715   address entry_point = NULL;
  1716   switch (kind) {
  1717     case Interpreter::zerolocals             :
  1718       break;
  1719     case Interpreter::zerolocals_synchronized:
  1720       synchronized = true;
  1721       break;
  1722     case Interpreter::native                 :
  1723       entry_point = ((InterpreterGenerator*)this)->generate_native_entry(false);
  1724       break;
  1725     case Interpreter::native_synchronized    :
  1726       entry_point = ((InterpreterGenerator*)this)->generate_native_entry(true);
  1727       break;
  1728     case Interpreter::empty                  :
  1729       entry_point = ((InterpreterGenerator*)this)->generate_empty_entry();
  1730       break;
  1731     case Interpreter::accessor               :
  1732       entry_point = ((InterpreterGenerator*)this)->generate_accessor_entry();
  1733       break;
  1734     case Interpreter::abstract               :
  1735       entry_point = ((InterpreterGenerator*)this)->generate_abstract_entry();
  1736       break;
  1738     case Interpreter::java_lang_math_sin     : // fall thru
  1739     case Interpreter::java_lang_math_cos     : // fall thru
  1740     case Interpreter::java_lang_math_tan     : // fall thru
  1741     case Interpreter::java_lang_math_log     : // fall thru
  1742     case Interpreter::java_lang_math_log10   : // fall thru
  1743     case Interpreter::java_lang_math_pow     : // fall thru
  1744     case Interpreter::java_lang_math_exp     : break;
  1745     case Interpreter::java_lang_math_abs     : // fall thru
  1746     case Interpreter::java_lang_math_sqrt    :
  1747       entry_point = ((InterpreterGenerator*)this)->generate_math_entry(kind);    break;
  1748     case Interpreter::java_lang_ref_reference_get:
  1749       entry_point = ((InterpreterGenerator*)this)->generate_Reference_get_entry(); break;
  1750     default:
  1751       fatal(err_msg("unexpected method kind: %d", kind));
  1752       break;
  1754   if (entry_point) return entry_point;
  1756   return ((InterpreterGenerator*)this)->generate_normal_entry(synchronized);
  1759 // These should never be compiled since the interpreter will prefer
  1760 // the compiled version to the intrinsic version.
  1761 bool AbstractInterpreter::can_be_compiled(methodHandle m) {
  1762   switch (method_kind(m)) {
  1763     case Interpreter::java_lang_math_sin     : // fall thru
  1764     case Interpreter::java_lang_math_cos     : // fall thru
  1765     case Interpreter::java_lang_math_tan     : // fall thru
  1766     case Interpreter::java_lang_math_abs     : // fall thru
  1767     case Interpreter::java_lang_math_log     : // fall thru
  1768     case Interpreter::java_lang_math_log10   : // fall thru
  1769     case Interpreter::java_lang_math_sqrt    : // fall thru
  1770     case Interpreter::java_lang_math_pow     : // fall thru
  1771     case Interpreter::java_lang_math_exp     :
  1772       return false;
  1773     default:
  1774       return true;
  1778 // How much stack a method activation needs in words.
  1779 int AbstractInterpreter::size_top_interpreter_activation(Method* method) {
  1781   const int entry_size    = frame::interpreter_frame_monitor_size();
  1783   // total overhead size: entry_size + (saved ebp thru expr stack bottom).
  1784   // be sure to change this if you add/subtract anything to/from the overhead area
  1785   const int overhead_size = -(frame::interpreter_frame_initial_sp_offset) + entry_size;
  1787   const int stub_code = 6;  // see generate_call_stub
  1788   // return overhead_size + method->max_locals() + method->max_stack() + stub_code;
  1789   const int method_stack = (method->max_locals() + method->max_stack()) *
  1790           Interpreter::stackElementWords;
  1791   return overhead_size + method_stack + stub_code;
  1794 void AbstractInterpreter::layout_activation(Method* method,
  1795                                            int tempcount,
  1796                                            int popframe_extra_args,
  1797                                            int moncount,
  1798                                            int caller_actual_parameters,
  1799                                            int callee_param_count,
  1800                                            int callee_locals,
  1801                                            frame* caller,
  1802                                            frame* interpreter_frame,
  1803                                            bool is_top_frame,
  1804                                            bool is_bottom_frame) {
  1805   // Note: This calculation must exactly parallel the frame setup
  1806   // in AbstractInterpreterGenerator::generate_method_entry.
  1807   // If interpreter_frame!=NULL, set up the method, locals, and monitors.
  1808   // The frame interpreter_frame, if not NULL, is guaranteed to be the
  1809   // right size, as determined by a previous call to this method.
  1810   // It is also guaranteed to be walkable even though it is in a skeletal state
  1812   // fixed size of an interpreter frame:
  1814   int max_locals = method->max_locals() * Interpreter::stackElementWords;
  1815   int extra_locals = (method->max_locals() - method->size_of_parameters()) * Interpreter::stackElementWords;
  1817 #ifdef ASSERT
  1818   if (!EnableInvokeDynamic) {
  1819     // @@@ FIXME: Should we correct interpreter_frame_sender_sp in the calling sequences?
  1820     // Probably, since deoptimization doesn't work yet.
  1821     assert(caller->unextended_sp() == interpreter_frame->interpreter_frame_sender_sp(), "Frame not properly walkable");
  1823   assert(caller->sp() == interpreter_frame->interpreter_frame_sender_sp(), "Frame not properly walkable(2)");
  1824 #endif
  1826     interpreter_frame->interpreter_frame_set_method(method);
  1827     // NOTE the difference in using sender_sp and interpreter_frame_sender_sp
  1828     // interpreter_frame_sender_sp is the original sp of the caller (the unextended_sp)
  1829     // and sender_sp is fp+8
  1830     intptr_t* locals = interpreter_frame->sender_sp() + max_locals - 1;
  1832 #ifdef ASSERT
  1833   if (caller->is_interpreted_frame()) {
  1834     assert(locals < caller->fp() + frame::interpreter_frame_initial_sp_offset, "bad placement");
  1836 #endif
  1838   interpreter_frame->interpreter_frame_set_locals(locals);
  1839   BasicObjectLock* montop = interpreter_frame->interpreter_frame_monitor_begin();
  1840   BasicObjectLock* monbot = montop - moncount;
  1841   interpreter_frame->interpreter_frame_set_monitor_end(montop - moncount);
  1843   //set last sp;
  1844   intptr_t*  esp = (intptr_t*) monbot - tempcount*Interpreter::stackElementWords -
  1845                       popframe_extra_args;
  1846   interpreter_frame->interpreter_frame_set_last_sp(esp);
  1847   // All frames but the initial interpreter frame we fill in have a
  1848   // value for sender_sp that allows walking the stack but isn't
  1849   // truly correct. Correct the value here.
  1850   //
  1851     if (extra_locals != 0 &&
  1852         interpreter_frame->sender_sp() == interpreter_frame->interpreter_frame_sender_sp() ) {
  1853       interpreter_frame->set_interpreter_frame_sender_sp(caller->sp() + extra_locals);
  1855     *interpreter_frame->interpreter_frame_cache_addr() = method->constants()->cache();
  1858 //-----------------------------------------------------------------------------
  1859 // Exceptions
  1861 void TemplateInterpreterGenerator::generate_throw_exception() {
  1862   // Entry point in previous activation (i.e., if the caller was
  1863   // interpreted)
  1864   Interpreter::_rethrow_exception_entry = __ pc();
  1865   // Restore sp to interpreter_frame_last_sp even though we are going
  1866   // to empty the expression stack for the exception processing.
  1867   __ sd(R0,FP, frame::interpreter_frame_last_sp_offset * wordSize);
  1869   // V0: exception
  1870   // V1: return address/pc that threw exception
  1871   __ restore_bcp();                              // esi points to call/send
  1872   __ restore_locals();
  1874   //add for compressedoops
  1875   __ reinit_heapbase();
  1876   // Entry point for exceptions thrown within interpreter code
  1877   Interpreter::_throw_exception_entry = __ pc();
  1878   // expression stack is undefined here
  1879   // V0: exception
  1880   // BCP: exception bcp
  1881   __ verify_oop(V0);
  1883   // expression stack must be empty before entering the VM in case of an exception
  1884   __ empty_expression_stack();
  1885   // find exception handler address and preserve exception oop
  1886   __ move(A1, V0);
  1887   __ call_VM(V1, CAST_FROM_FN_PTR(address, InterpreterRuntime::exception_handler_for_exception), A1);
  1888   // V0: exception handler entry point
  1889   // V1: preserved exception oop
  1890   // S0: bcp for exception handler
  1891   __ daddi(SP, SP, (-1) * wordSize);
  1892   __ sd(V1, SP, 0);                              // push exception which is now the only value on the stack
  1893   __ jr(V0);                                   // jump to exception handler (may be _remove_activation_entry!)
  1894   __ delayed()->nop();
  1896   // If the exception is not handled in the current frame the frame is removed and
  1897   // the exception is rethrown (i.e. exception continuation is _rethrow_exception).
  1898   //
  1899   // Note: At this point the bci is still the bxi for the instruction which caused
  1900   //       the exception and the expression stack is empty. Thus, for any VM calls
  1901   //       at this point, GC will find a legal oop map (with empty expression stack).
  1903   // In current activation
  1904   // V0: exception
  1905   // BCP: exception bcp
  1907   //
  1908   // JVMTI PopFrame support
  1909   //
  1911   Interpreter::_remove_activation_preserving_args_entry = __ pc();
  1912   __ empty_expression_stack();
  1913   // Set the popframe_processing bit in pending_popframe_condition indicating that we are
  1914   // currently handling popframe, so that call_VMs that may happen later do not trigger new
  1915   // popframe handling cycles.
  1916 #ifndef OPT_THREAD
  1917   Register thread = T2;
  1918   __ get_thread(T2);
  1919 #else
  1920   Register thread = TREG;
  1921 #endif
  1922   __ lw(T3, thread, in_bytes(JavaThread::popframe_condition_offset()));
  1923   __ ori(T3, T3, JavaThread::popframe_processing_bit);
  1924   __ sw(T3, thread, in_bytes(JavaThread::popframe_condition_offset()));
  1926 #ifndef CORE
  1928     // Check to see whether we are returning to a deoptimized frame.
  1929     // (The PopFrame call ensures that the caller of the popped frame is
  1930     // either interpreted or compiled and deoptimizes it if compiled.)
  1931     // In this case, we can't call dispatch_next() after the frame is
  1932     // popped, but instead must save the incoming arguments and restore
  1933     // them after deoptimization has occurred.
  1934     //
  1935     // Note that we don't compare the return PC against the
  1936     // deoptimization blob's unpack entry because of the presence of
  1937     // adapter frames in C2.
  1938     Label caller_not_deoptimized;
  1939     __ ld(A0, FP, frame::return_addr_offset * wordSize);
  1940     __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::interpreter_contains), A0);
  1941     __ bne(V0, R0, caller_not_deoptimized);
  1942     __ delayed()->nop();
  1944     // Compute size of arguments for saving when returning to deoptimized caller
  1945     __ get_method(A1);
  1946     __ verify_oop(A1);
  1947     __ ld(A1,A1,in_bytes(Method::const_offset()));
  1948     __ lhu(A1, A1, in_bytes(ConstMethod::size_of_parameters_offset()));
  1949     __ shl(A1, Interpreter::logStackElementSize);
  1950     __ restore_locals();
  1951     __ dsub(A2, LVP, T0);
  1952     __ daddiu(A2, A2, wordSize);
  1953     // Save these arguments
  1954 #ifndef OPT_THREAD
  1955     __ get_thread(A0);
  1956 #else
  1957     __ move(A0, TREG);
  1958 #endif
  1959     __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, Deoptimization::popframe_preserve_args), A0, A1, A2);
  1961     __ remove_activation(vtos, T9, false, false, false);
  1963     // Inform deoptimization that it is responsible for restoring these arguments
  1964 #ifndef OPT_THREAD
  1965     __ get_thread(thread);
  1966 #endif
  1967     __ move(AT, JavaThread::popframe_force_deopt_reexecution_bit);
  1968     __ sw(AT, thread, in_bytes(JavaThread::popframe_condition_offset()));
  1969     // Continue in deoptimization handler
  1970     __ jr(T9);
  1971     __ delayed()->nop();
  1973     __ bind(caller_not_deoptimized);
  1975 #endif /* !CORE */
  1977   __ remove_activation(vtos, T3,
  1978                        /* throw_monitor_exception */ false,
  1979                        /* install_monitor_exception */ false,
  1980                        /* notify_jvmdi */ false);
  1982   // Clear the popframe condition flag
  1983   // Finish with popframe handling
  1984   // A previous I2C followed by a deoptimization might have moved the
  1985   // outgoing arguments further up the stack. PopFrame expects the
  1986   // mutations to those outgoing arguments to be preserved and other
  1987   // constraints basically require this frame to look exactly as
  1988   // though it had previously invoked an interpreted activation with
  1989   // no space between the top of the expression stack (current
  1990   // last_sp) and the top of stack. Rather than force deopt to
  1991   // maintain this kind of invariant all the time we call a small
  1992   // fixup routine to move the mutated arguments onto the top of our
  1993   // expression stack if necessary.
  1994   __ move(T8, SP);
  1995   __ ld(A2, FP, frame::interpreter_frame_last_sp_offset * wordSize);
  1996 #ifndef OPT_THREAD
  1997   __ get_thread(thread);
  1998 #endif
  1999   // PC must point into interpreter here
  2000   __ set_last_Java_frame(thread, noreg, FP, __ pc());
  2001   __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::popframe_move_outgoing_args), thread, T8, A2);
  2002   __ reset_last_Java_frame(thread, true, true);
  2003   // Restore the last_sp and null it out
  2004   __ ld(SP, FP, frame::interpreter_frame_last_sp_offset * wordSize);
  2005   __ sd(R0, FP, frame::interpreter_frame_last_sp_offset * wordSize);
  2009   __ move(AT, JavaThread::popframe_inactive);
  2010   __ sw(AT, thread, in_bytes(JavaThread::popframe_condition_offset()));
  2012   // Finish with popframe handling
  2013   __ restore_bcp();
  2014   __ restore_locals();
  2015 #ifndef CORE
  2016   // The method data pointer was incremented already during
  2017   // call profiling. We have to restore the mdp for the current bcp.
  2018   if (ProfileInterpreter) {
  2019     __ set_method_data_pointer_for_bcp();
  2021 #endif // !CORE
  2022   // Clear the popframe condition flag
  2023 #ifndef OPT_THREAD
  2024   __ get_thread(thread);
  2025 #endif
  2026   __ move(AT, JavaThread::popframe_inactive);
  2027   __ sw(AT, thread, in_bytes(JavaThread::popframe_condition_offset()));
  2028   __ dispatch_next(vtos);
  2029   // end of PopFrame support
  2031   Interpreter::_remove_activation_entry = __ pc();
  2033   // preserve exception over this code sequence
  2034   __ ld(T0, SP, 0);
  2035   __ daddi(SP, SP, wordSize);
  2036 #ifndef OPT_THREAD
  2037   __ get_thread(thread);
  2038 #endif
  2039   __ sd(T0, thread, in_bytes(JavaThread::vm_result_offset()));
  2040   // remove the activation (without doing throws on illegalMonitorExceptions)
  2041   __ remove_activation(vtos, T3, false, true, false);
  2042   // restore exception
  2043   __ get_vm_result(T0, thread);
  2044   __ verify_oop(T0);
  2046   // Inbetween activations - previous activation type unknown yet
  2047   // compute continuation point - the continuation point expects
  2048   // the following registers set up:
  2049   //
  2050   // T0: exception                                eax
  2051   // T1: return address/pc that threw exception    edx
  2052   // SP: expression stack of caller      esp
  2053   // FP: ebp of caller          ebp
  2054   __ daddi(SP, SP, (-2) * wordSize);
  2055   __ sd(T0, SP, wordSize);      // save exception
  2056   __ sd(T3, SP, 0);                               // save return address
  2057   __ move(A1, T3);
  2058   __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address), thread, A1);
  2059   __ move(T9, V0);                             // save exception handler
  2060   __ ld(V0, SP, wordSize);        // restore exception
  2061   __ ld(V1, SP, 0);                               // restore return address
  2062   __ daddi(SP, SP, 2 * wordSize);
  2064   // Note that an "issuing PC" is actually the next PC after the call
  2065   __ jr(T9);                                   // jump to exception handler of caller
  2066   __ delayed()->nop();
  2070 //
  2071 // JVMTI ForceEarlyReturn support
  2072 //
  2073 address TemplateInterpreterGenerator::generate_earlyret_entry_for(TosState state) {
  2074   address entry = __ pc();
  2075   __ restore_bcp();
  2076   __ restore_locals();
  2077   __ empty_expression_stack();
  2078   __ empty_FPU_stack();
  2079   __ load_earlyret_value(state);
  2081 #ifndef OPT_THREAD
  2082   __ get_thread(TREG);
  2083 #endif
  2084    __ ld_ptr(T9, TREG, in_bytes(JavaThread::jvmti_thread_state_offset()));
  2085   //const Address cond_addr(ecx, JvmtiThreadState::earlyret_state_offset());
  2086   const Address cond_addr(T9, in_bytes(JvmtiThreadState::earlyret_state_offset()));
  2087   // Clear the earlyret state
  2088     __ move(AT,JvmtiThreadState::earlyret_inactive);
  2089     __ sw(AT,cond_addr);
  2090     __ sync();
  2093     __ remove_activation(state, T0,
  2094                          false, /* throw_monitor_exception */
  2095                          false, /* install_monitor_exception */
  2096                          true); /* notify_jvmdi */
  2097     __ sync();
  2098     __ jr(T0);
  2099     __ delayed()->nop();
  2100   return entry;
  2101 } // end of ForceEarlyReturn support
  2104 //-----------------------------------------------------------------------------
  2105 // Helper for vtos entry point generation
  2107 void TemplateInterpreterGenerator::set_vtos_entry_points(Template* t,
  2108                                                          address& bep,
  2109                                                          address& cep,
  2110                                                          address& sep,
  2111                                                          address& aep,
  2112                                                          address& iep,
  2113                                                          address& lep,
  2114                                                          address& fep,
  2115                                                          address& dep,
  2116                                                          address& vep) {
  2117   assert(t->is_valid() && t->tos_in() == vtos, "illegal template");
  2118   Label L;
  2119   fep = __ pc(); __ push(ftos); __ b(L); __ delayed()->nop();
  2120   dep = __ pc(); __ push(dtos); __ b(L); __ delayed()->nop();
  2121   lep = __ pc(); __ push(ltos); __ b(L); __ delayed()->nop();
  2122   aep  =__ pc(); __ push(atos); __ b(L); __ delayed()->nop();
  2123   bep = cep = sep =
  2124   iep = __ pc(); __ push(itos);
  2125   vep = __ pc();
  2126   __ bind(L);
  2127   generate_and_dispatch(t);
  2131 //-----------------------------------------------------------------------------
  2132 // Generation of individual instructions
  2134 // helpers for generate_and_dispatch
  2137 InterpreterGenerator::InterpreterGenerator(StubQueue* code)
  2138   : TemplateInterpreterGenerator(code) {
  2139    generate_all(); // down here so it can be "virtual"
  2142 //-----------------------------------------------------------------------------
  2144 // Non-product code
  2145 #ifndef PRODUCT
  2146 address TemplateInterpreterGenerator::generate_trace_code(TosState state) {
  2147   address entry = __ pc();
  2149   // prepare expression stack
  2150   __ push(state);       // save tosca
  2152   // tos & tos2, added by yjl 7/15/2005
  2153   // trace_bytecode need actually 4 args, the last two is tos&tos2
  2154   // this work fine for x86. but mips o32 call convention will store A2-A3
  2155   // to the stack position it think is the tos&tos2
  2156   // when the expression stack have no more than 2 data, error occur.
  2157   __ ld(A2, SP, 0);
  2158   __ ld(A3, SP, 1 * wordSize);
  2160   // pass arguments & call tracer
  2161   __ call_VM(noreg, CAST_FROM_FN_PTR(address, SharedRuntime::trace_bytecode), RA, A2, A3);
  2162   __ move(RA, V0);    // make sure return address is not destroyed by pop(state)
  2164   // restore expression stack
  2165   __ pop(state);        // restore tosca
  2167   // return
  2168   __ jr(RA);
  2169   __ delayed()->nop();
  2171   return entry;
  2174 void TemplateInterpreterGenerator::count_bytecode() {
  2175   __ li(T8, (long)&BytecodeCounter::_counter_value);
  2176   __ lw(AT, T8, 0);
  2177   __ daddi(AT, AT, 1);
  2178   __ sw(AT, T8, 0);
  2181 void TemplateInterpreterGenerator::histogram_bytecode(Template* t) {
  2182   __ li(T8, (long)&BytecodeHistogram::_counters[t->bytecode()]);
  2183   __ lw(AT, T8, 0);
  2184   __ daddi(AT, AT, 1);
  2185   __ sw(AT, T8, 0);
  2188 void TemplateInterpreterGenerator::histogram_bytecode_pair(Template* t) {
  2189   __ li(T8, (long)&BytecodePairHistogram::_index);
  2190   __ lw(T9, T8, 0);
  2191   __ dsrl(T9, T9, BytecodePairHistogram::log2_number_of_codes);
  2192   __ li(T8, ((long)t->bytecode()) << BytecodePairHistogram::log2_number_of_codes);
  2193   __ orr(T9, T9, T8);
  2194   __ li(T8, (long)&BytecodePairHistogram::_index);
  2195   __ sw(T9, T8, 0);
  2196   __ dsll(T9, T9, 2);
  2197   __ li(T8, (long)BytecodePairHistogram::_counters);
  2198   __ dadd(T8, T8, T9);
  2199   __ lw(AT, T8, 0);
  2200   __ daddi(AT, AT, 1);
  2201   __ sw(AT, T8, 0);
  2205 void TemplateInterpreterGenerator::trace_bytecode(Template* t) {
  2206   // Call a little run-time stub to avoid blow-up for each bytecode.
  2207   // The run-time runtime saves the right registers, depending on
  2208   // the tosca in-state for the given template.
  2210   address entry = Interpreter::trace_code(t->tos_in());
  2211   assert(entry != NULL, "entry must have been generated");
  2212   __ call(entry, relocInfo::none);
  2213   __ delayed()->nop();
  2214   //add for compressedoops
  2215   __ reinit_heapbase();
  2219 void TemplateInterpreterGenerator::stop_interpreter_at() {
  2220   Label L;
  2221   __ li(T8, long(&BytecodeCounter::_counter_value));
  2222   __ lw(T8, T8, 0);
  2223   __ move(AT, StopInterpreterAt);
  2224   __ bne(T8, AT, L);
  2225   __ delayed()->nop();
  2226   __ call(CAST_FROM_FN_PTR(address, os::breakpoint), relocInfo::runtime_call_type);
  2227   __ delayed()->nop();
  2228   __ bind(L);
  2230 #endif // !PRODUCT
  2231 #endif // ! CC_INTERP

mercurial