src/cpu/mips/vm/templateInterpreter_mips_64.cpp

Tue, 16 Jun 2020 18:24:46 +0800

author
wangxue
date
Tue, 16 Jun 2020 18:24:46 +0800
changeset 9854
0bada3286229
parent 9760
8b305ff8f6b6
child 9932
86ea9a02a717
permissions
-rw-r--r--

#13346 Backport of #10019 SP must be decremented first.
Reviewed-by: aoqi

     1 /*
     2  * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * Copyright (c) 2015, 2020, 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   // expression stack must be empty before entering the VM if an
   132   // exception happened
   133   __ empty_expression_stack();
   134   __ empty_FPU_stack();
   135   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_ClassCastException),  FSR);
   136   return entry;
   137 }
   139 address TemplateInterpreterGenerator::generate_exception_handler_common(
   140         const char* name, const char* message, bool pass_oop) {
   141   assert(!pass_oop || message == NULL, "either oop or message but not both");
   142   address entry = __ pc();
   144   // expression stack must be empty before entering the VM if an exception happened
   145   __ empty_expression_stack();
   146   // setup parameters
   147   __ li(A1, (long)name);
   148   if (pass_oop) {
   149     __ call_VM(V0,
   150     CAST_FROM_FN_PTR(address, InterpreterRuntime::create_klass_exception), A1, FSR);
   151   } else {
   152     __ li(A2, (long)message);
   153     __ call_VM(V0,
   154     CAST_FROM_FN_PTR(address, InterpreterRuntime::create_exception), A1, A2);
   155   }
   156   // throw exception
   157   __ jmp(Interpreter::throw_exception_entry(), relocInfo::none);
   158   __ delayed()->nop();
   159   return entry;
   160 }
   163 address TemplateInterpreterGenerator::generate_continuation_for(TosState state) {
   164   address entry = __ pc();
   165   // NULL last_sp until next java call
   166   __ sd(R0,Address(FP, frame::interpreter_frame_last_sp_offset * wordSize));
   167   __ dispatch_next(state);
   168   return entry;
   169 }
   172 address TemplateInterpreterGenerator::generate_return_entry_for(TosState state, int step, size_t index_size) {
   174   address entry = __ pc();
   176   // Restore stack bottom in case i2c adjusted stack
   177   __ ld(SP, Address(FP, frame::interpreter_frame_last_sp_offset * wordSize));
   178   // and NULL it as marker that sp is now tos until next java call
   179   __ sd(R0, FP, frame::interpreter_frame_last_sp_offset * wordSize);
   181   __ restore_bcp();
   182   __ restore_locals();
   184   // mdp: T8
   185   // ret: FSR
   186   // tmp: T9
   187   if (state == atos) {
   188     Register mdp = T8;
   189     Register tmp = T9;
   190     __ profile_return_type(mdp, FSR, tmp);
   191   }
   194   const Register cache = T9;
   195   const Register index = T3;
   196   __ get_cache_and_index_at_bcp(cache, index, 1, index_size);
   198   const Register flags = cache;
   199   __ dsll(AT, index, Address::times_ptr);
   200   __ daddu(AT, cache, AT);
   201   __ lw(flags, AT, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::flags_offset()));
   202   __ andi(flags, flags, ConstantPoolCacheEntry::parameter_size_mask);
   203   __ dsll(AT, flags, Interpreter::stackElementScale());
   204   __ daddu(SP, SP, AT);
   206   __ dispatch_next(state, step);
   208   return entry;
   209 }
   212 address TemplateInterpreterGenerator::generate_deopt_entry_for(TosState state,
   213                                                                int step) {
   214   address entry = __ pc();
   215   // NULL last_sp until next java call
   216   __ sd(R0, FP, frame::interpreter_frame_last_sp_offset * wordSize);
   217   __ restore_bcp();
   218   __ restore_locals();
   219   // handle exceptions
   220   {
   221     Label L;
   222     const Register thread = TREG;
   223 #ifndef OPT_THREAD
   224     __ get_thread(thread);
   225 #endif
   226     __ lw(AT, thread, in_bytes(Thread::pending_exception_offset()));
   227     __ beq(AT, R0, L);
   228     __ delayed()->nop();
   229     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_pending_exception));
   230     __ should_not_reach_here();
   231     __ bind(L);
   232   }
   233   __ dispatch_next(state, step);
   234   return entry;
   235 }
   237 int AbstractInterpreter::BasicType_as_index(BasicType type) {
   238   int i = 0;
   239   switch (type) {
   240     case T_BOOLEAN: i = 0; break;
   241     case T_CHAR   : i = 1; break;
   242     case T_BYTE   : i = 2; break;
   243     case T_SHORT  : i = 3; break;
   244     case T_INT    : // fall through
   245     case T_LONG   : // fall through
   246     case T_VOID   : i = 4; break;
   247     case T_FLOAT  : i = 5; break;
   248     case T_DOUBLE : i = 6; break;
   249     case T_OBJECT : // fall through
   250     case T_ARRAY  : i = 7; break;
   251     default       : ShouldNotReachHere();
   252   }
   253   assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers,
   254          "index out of bounds");
   255   return i;
   256 }
   259 address TemplateInterpreterGenerator::generate_result_handler_for(
   260         BasicType type) {
   261   address entry = __ pc();
   262   switch (type) {
   263     case T_BOOLEAN: __ c2bool(V0);             break;
   264     case T_CHAR   : __ andi(V0, V0, 0xFFFF);   break;
   265     case T_BYTE   : __ sign_extend_byte (V0);  break;
   266     case T_SHORT  : __ sign_extend_short(V0);  break;
   267     case T_INT    : /* nothing to do */        break;
   268     case T_FLOAT  : /* nothing to do */        break;
   269     case T_DOUBLE : /* nothing to do */        break;
   270     case T_OBJECT :
   271     {
   272        __ ld(V0, FP, frame::interpreter_frame_oop_temp_offset * wordSize);
   273       __ verify_oop(V0);         // and verify it
   274     }
   275                  break;
   276     default       : ShouldNotReachHere();
   277   }
   278   __ jr(RA);                                  // return from result handler
   279   __ delayed()->nop();
   280   return entry;
   281 }
   283 address TemplateInterpreterGenerator::generate_safept_entry_for(
   284         TosState state,
   285         address runtime_entry) {
   286   address entry = __ pc();
   287   __ push(state);
   288   __ call_VM(noreg, runtime_entry);
   289   __ dispatch_via(vtos, Interpreter::_normal_table.table_for(vtos));
   290   return entry;
   291 }
   295 // Helpers for commoning out cases in the various type of method entries.
   296 //
   299 // increment invocation count & check for overflow
   300 //
   301 // Note: checking for negative value instead of overflow
   302 //       so we have a 'sticky' overflow test
   303 //
   304 // Rmethod: method
   305 // T3     : invocation counter
   306 //
   307 void InterpreterGenerator::generate_counter_incr(
   308         Label* overflow,
   309         Label* profile_method,
   310         Label* profile_method_continue) {
   311   Label done;
   312   if (TieredCompilation) {
   313     int increment = InvocationCounter::count_increment;
   314     int mask = ((1 << Tier0InvokeNotifyFreqLog)  - 1) << InvocationCounter::count_shift;
   315     Label no_mdo;
   316     if (ProfileInterpreter) {
   317       // Are we profiling?
   318       __ ld(FSR, Address(Rmethod, Method::method_data_offset()));
   319       __ beq(FSR, R0, no_mdo);
   320       __ delayed()->nop();
   321       // Increment counter in the MDO
   322       const Address mdo_invocation_counter(FSR, in_bytes(MethodData::invocation_counter_offset()) +
   323                                                 in_bytes(InvocationCounter::counter_offset()));
   324       __ increment_mask_and_jump(mdo_invocation_counter, increment, mask, T3, false, Assembler::zero, overflow);
   325       __ beq(R0, R0, done);
   326       __ delayed()->nop();
   327     }
   328     __ bind(no_mdo);
   329     // Increment counter in MethodCounters
   330     const Address invocation_counter(FSR,
   331                   MethodCounters::invocation_counter_offset() +
   332                   InvocationCounter::counter_offset());
   333     __ get_method_counters(Rmethod, FSR, done);
   334     __ increment_mask_and_jump(invocation_counter, increment, mask, T3, false, Assembler::zero, overflow);
   335     __ bind(done);
   336   } else {
   337     const Address invocation_counter(FSR, in_bytes(MethodCounters::invocation_counter_offset())
   338         + in_bytes(InvocationCounter::counter_offset()));
   339     const Address backedge_counter  (FSR, in_bytes(MethodCounters::backedge_counter_offset())
   340         + in_bytes(InvocationCounter::counter_offset()));
   342     __ get_method_counters(Rmethod, FSR, done);
   344     if (ProfileInterpreter) { // %%% Merge this into methodDataOop
   345       __ lw(T9, FSR, in_bytes(MethodCounters::interpreter_invocation_counter_offset()));
   346       __ incrementl(T9, 1);
   347       __ sw(T9, FSR, in_bytes(MethodCounters::interpreter_invocation_counter_offset()));
   348     }
   349     // Update standard invocation counters
   350     __ lw(T3, invocation_counter);
   351     __ increment(T3, InvocationCounter::count_increment);
   352     __ sw(T3, invocation_counter);  // save invocation count
   354     __ lw(FSR, backedge_counter);  // load backedge counter
   355     __ li(AT, InvocationCounter::count_mask_value);   // mask out the status bits
   356     __ andr(FSR, FSR, AT);
   358     __ dadd(T3, T3, FSR);          // add both counters
   360     if (ProfileInterpreter && profile_method != NULL) {
   361       // Test to see if we should create a method data oop
   362       if (Assembler::is_simm16(InvocationCounter::InterpreterProfileLimit)) {
   363         __ slti(AT, T3, InvocationCounter::InterpreterProfileLimit);
   364       } else {
   365         __ li(AT, (long)&InvocationCounter::InterpreterProfileLimit);
   366         __ lw(AT, AT, 0);
   367         __ slt(AT, T3, AT);
   368       }
   370       __ bne_far(AT, R0, *profile_method_continue);
   371       __ delayed()->nop();
   373       // if no method data exists, go to profile_method
   374       __ test_method_data_pointer(FSR, *profile_method);
   375     }
   377     if (Assembler::is_simm16(CompileThreshold)) {
   378       __ srl(AT, T3, InvocationCounter::count_shift);
   379       __ slti(AT, AT, CompileThreshold);
   380     } else {
   381       __ li(AT, (long)&InvocationCounter::InterpreterInvocationLimit);
   382       __ lw(AT, AT, 0);
   383       __ slt(AT, T3, AT);
   384     }
   386     __ beq_far(AT, R0, *overflow);
   387     __ delayed()->nop();
   388     __ bind(done);
   389   }
   390 }
   392 void InterpreterGenerator::generate_counter_overflow(Label* do_continue) {
   394   // Asm interpreter on entry
   395   // S7 - locals
   396   // S0 - bcp
   397   // Rmethod - method
   398   // FP - interpreter frame
   400   // On return (i.e. jump to entry_point)
   401   // Rmethod - method
   402   // RA - return address of interpreter caller
   403   // tos - the last parameter to Java method
   404   // SP - sender_sp
   407   // the bcp is valid if and only if it's not null
   408   __ call_VM(NOREG, CAST_FROM_FN_PTR(address,
   409       InterpreterRuntime::frequency_counter_overflow), R0);
   410   __ ld(Rmethod, FP, method_offset);
   411   // Preserve invariant that S0/S7 contain bcp/locals of sender frame
   412   __ b_far(*do_continue);
   413   __ delayed()->nop();
   414 }
   416 // See if we've got enough room on the stack for locals plus overhead.
   417 // The expression stack grows down incrementally, so the normal guard
   418 // page mechanism will work for that.
   419 //
   420 // NOTE: Since the additional locals are also always pushed (wasn't
   421 // obvious in generate_method_entry) so the guard should work for them
   422 // too.
   423 //
   424 // Args:
   425 //      T2: number of additional locals this frame needs (what we must check)
   426 //      T0: Method*
   427 //
   428 void InterpreterGenerator::generate_stack_overflow_check(void) {
   429   // see if we've got enough room on the stack for locals plus overhead.
   430   // the expression stack grows down incrementally, so the normal guard
   431   // page mechanism will work for that.
   432   //
   433   // Registers live on entry:
   434   //
   435   // T0: Method*
   436   // T2: number of additional locals this frame needs (what we must check)
   438   // NOTE:  since the additional locals are also always pushed (wasn't obvious in
   439   // generate_method_entry) so the guard should work for them too.
   440   //
   442   const int entry_size    = frame::interpreter_frame_monitor_size() * wordSize;
   444   // total overhead size: entry_size + (saved fp thru expr stack bottom).
   445   // be sure to change this if you add/subtract anything to/from the overhead area
   446   const int overhead_size = -(frame::interpreter_frame_initial_sp_offset*wordSize)
   447     + entry_size;
   449   const int page_size = os::vm_page_size();
   451   Label after_frame_check;
   453   // see if the frame is greater than one page in size. If so,
   454   // then we need to verify there is enough stack space remaining
   455   // for the additional locals.
   456   __ move(AT, (page_size - overhead_size) / Interpreter::stackElementSize);
   457   __ slt(AT, AT, T2);
   458   __ beq(AT, R0, after_frame_check);
   459   __ delayed()->nop();
   461   // compute sp as if this were going to be the last frame on
   462   // the stack before the red zone
   463 #ifndef OPT_THREAD
   464   Register thread = T1;
   465   __ get_thread(thread);
   466 #else
   467   Register thread = TREG;
   468 #endif
   470   // locals + overhead, in bytes
   471   __ dsll(T3, T2, Interpreter::stackElementScale());
   472   __ daddiu(T3, T3, overhead_size);   // locals * 4 + overhead_size --> T3
   474 #ifdef ASSERT
   475   Label stack_base_okay, stack_size_okay;
   476   // verify that thread stack base is non-zero
   477   __ ld(AT, thread, in_bytes(Thread::stack_base_offset()));
   478   __ bne(AT, R0, stack_base_okay);
   479   __ delayed()->nop();
   480   __ stop("stack base is zero");
   481   __ bind(stack_base_okay);
   482   // verify that thread stack size is non-zero
   483   __ ld(AT, thread, in_bytes(Thread::stack_size_offset()));
   484   __ bne(AT, R0, stack_size_okay);
   485   __ delayed()->nop();
   486   __ stop("stack size is zero");
   487   __ bind(stack_size_okay);
   488 #endif
   490   // Add stack base to locals and subtract stack size
   491   __ ld(AT, thread, in_bytes(Thread::stack_base_offset())); // stack_base --> AT
   492   __ dadd(T3, T3, AT);   // locals * 4 + overhead_size + stack_base--> T3
   493   __ ld(AT, thread, in_bytes(Thread::stack_size_offset()));  // stack_size --> AT
   494   __ dsub(T3, T3, AT);  // locals * 4 + overhead_size + stack_base - stack_size --> T3
   497   // add in the redzone and yellow size
   498   __ move(AT, (StackRedPages+StackYellowPages) * page_size);
   499   __ add(T3, T3, AT);
   501   // check against the current stack bottom
   502   __ slt(AT, T3, SP);
   503   __ bne(AT, R0, after_frame_check);
   504   __ delayed()->nop();
   506   // Note: the restored frame is not necessarily interpreted.
   507   // Use the shared runtime version of the StackOverflowError.
   508   __ move(SP, Rsender);
   509   assert(StubRoutines::throw_StackOverflowError_entry() != NULL, "stub not yet generated");
   510   __ jmp(StubRoutines::throw_StackOverflowError_entry(), relocInfo::runtime_call_type);
   511   __ delayed()->nop();
   513   // all done with frame size check
   514   __ bind(after_frame_check);
   515 }
   517 // Allocate monitor and lock method (asm interpreter)
   518 // Rmethod - Method*
   519 void InterpreterGenerator::lock_method(void) {
   520   // synchronize method
   521   const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
   523 #ifdef ASSERT
   524   { Label L;
   525     __ lw(T0, Rmethod, in_bytes(Method::access_flags_offset()));
   526     __ andi(T0, T0, JVM_ACC_SYNCHRONIZED);
   527     __ bne(T0, R0, L);
   528     __ delayed()->nop();
   529     __ stop("method doesn't need synchronization");
   530     __ bind(L);
   531   }
   532 #endif // ASSERT
   533   // get synchronization object
   534   {
   535     Label done;
   536     const int mirror_offset = in_bytes(Klass::java_mirror_offset());
   537     __ lw(T0, Rmethod, in_bytes(Method::access_flags_offset()));
   538     __ andi(T2, T0, JVM_ACC_STATIC);
   539     __ ld(T0, LVP, Interpreter::local_offset_in_bytes(0));
   540     __ beq(T2, R0, done);
   541     __ delayed()->nop();
   542     __ ld(T0, Rmethod, in_bytes(Method::const_offset()));
   543     __ ld(T0, T0, in_bytes(ConstMethod::constants_offset()));
   544     __ ld(T0, T0, ConstantPool::pool_holder_offset_in_bytes());
   545     __ ld(T0, T0, mirror_offset);
   546     __ bind(done);
   547   }
   548   // add space for monitor & lock
   549   __ daddi(SP, SP, (-1) * entry_size);           // add space for a monitor entry
   550   __ sd(SP, FP, frame::interpreter_frame_monitor_block_top_offset * wordSize);
   551   // set new monitor block top
   552   __ sd(T0, SP, BasicObjectLock::obj_offset_in_bytes());   // store object
   553   // FIXME: I do not know what lock_object will do and what it will need
   554   __ move(c_rarg0, SP);      // object address
   555   __ lock_object(c_rarg0);
   556 }
   558 // Generate a fixed interpreter frame. This is identical setup for
   559 // interpreted methods and for native methods hence the shared code.
   560 void TemplateInterpreterGenerator::generate_fixed_frame(bool native_call) {
   562   // [ local var m-1      ] <--- sp
   563   //   ...
   564   // [ local var 0        ]
   565   // [ argumnet word n-1  ] <--- T0(sender's sp)
   566   //   ...
   567   // [ argument word 0    ] <--- S7
   569   // initialize fixed part of activation frame
   570   // sender's sp in Rsender
   571   int i = 0;
   572   int frame_size = 9;
   573 #ifndef CORE
   574   ++frame_size;
   575 #endif
   576   __ daddiu(SP, SP, (-frame_size) * wordSize);
   577   __ sd(RA, SP, (frame_size - 1) * wordSize);   // save return address
   578   __ sd(FP, SP, (frame_size - 2) * wordSize);  // save sender's fp
   579   __ daddiu(FP, SP, (frame_size - 2) * wordSize);
   580   __ sd(Rsender, FP, (-++i) * wordSize);  // save sender's sp
   581   __ sd(R0, FP,(-++i) * wordSize);       //save last_sp as null
   582   __ sd(LVP, FP, (-++i) * wordSize);  // save locals offset
   583   __ ld(BCP, Rmethod, in_bytes(Method::const_offset())); // get constMethodOop
   584   __ daddiu(BCP, BCP, in_bytes(ConstMethod::codes_offset())); // get codebase
   585   __ sd(Rmethod, FP, (-++i) * wordSize);                              // save Method*
   586 #ifndef CORE
   587   if (ProfileInterpreter) {
   588     Label method_data_continue;
   589     __ ld(AT, Rmethod,  in_bytes(Method::method_data_offset()));
   590     __ beq(AT, R0, method_data_continue);
   591     __ delayed()->nop();
   592     __ daddi(AT, AT, in_bytes(MethodData::data_offset()));
   593     __ bind(method_data_continue);
   594     __ sd(AT, FP,  (-++i) * wordSize);
   595   } else {
   596     __ sd(R0, FP, (-++i) * wordSize);
   597   }
   598 #endif // !CORE
   600   __ ld(T2, Rmethod, in_bytes(Method::const_offset()));
   601   __ ld(T2, T2, in_bytes(ConstMethod::constants_offset()));
   602   __ ld(T2, T2, ConstantPool::cache_offset_in_bytes());
   603   __ sd(T2, FP, (-++i) * wordSize);                    // set constant pool cache
   604   if (native_call) {
   605     __ sd(R0, FP, (-++i) * wordSize);          // no bcp
   606   } else {
   607     __ sd(BCP, FP, (-++i) * wordSize);          // set bcp
   608   }
   609   __ sd(SP, FP, (-++i) * wordSize);               // reserve word for pointer to expression stack bottom
   610   assert(i + 2 == frame_size, "i + 2 should be equal to frame_size");
   611 }
   613 // End of helpers
   615 // Various method entries
   616 //------------------------------------------------------------------------------------------------------------------------
   617 //
   618 //
   620 // Call an accessor method (assuming it is resolved, otherwise drop
   621 // into vanilla (slow path) entry
   622 address InterpreterGenerator::generate_accessor_entry(void) {
   624   // Rmethod: Method*
   625   // V0: receiver (preserve for slow entry into asm interpreter)
   626   //  Rsender: senderSP must preserved for slow path, set SP to it on fast path
   628   address entry_point = __ pc();
   629   Label xreturn_path;
   630   // do fastpath for resolved accessor methods
   631   if (UseFastAccessorMethods) {
   632     Label slow_path;
   633     __ li(T2, SafepointSynchronize::address_of_state());
   634     __ lw(AT, T2, 0);
   635     __ daddi(AT, AT, -(SafepointSynchronize::_not_synchronized));
   636     __ bne(AT, R0, slow_path);
   637     __ delayed()->nop();
   638     // Code: _aload_0, _(i|a)getfield, _(i|a)return or any rewrites thereof;
   639     // parameter size = 1
   640     // Note: We can only use this code if the getfield has been resolved
   641     //       and if we don't have a null-pointer exception => check for
   642     //       these conditions first and use slow path if necessary.
   643     // Rmethod: method
   644     // V0: receiver
   646     // [ receiver  ] <-- sp
   647     __ ld(T0, SP, 0);
   649     // check if local 0 != NULL and read field
   650     __ beq(T0, R0, slow_path);
   651     __ delayed()->nop();
   652     __ ld(T2, Rmethod, in_bytes(Method::const_offset()));
   653     __ ld(T2, T2, in_bytes(ConstMethod::constants_offset()));
   654     // read first instruction word and extract bytecode @ 1 and index @ 2
   655     __ ld(T3, Rmethod, in_bytes(Method::const_offset()));
   656     __ lw(T3, T3, in_bytes(ConstMethod::codes_offset()));
   657     // Shift codes right to get the index on the right.
   658     // The bytecode fetched looks like <index><0xb4><0x2a>
   659     __ dsrl(T3, T3, 2 * BitsPerByte);
   660     // FIXME: maybe it's wrong
   661     __ dsll(T3, T3, exact_log2(in_words(ConstantPoolCacheEntry::size())));
   662     __ ld(T2, T2, ConstantPool::cache_offset_in_bytes());
   664     // T0: local 0
   665     // Rmethod: method
   666     // V0: receiver - do not destroy since it is needed for slow path!
   667     // T1: scratch use which register instead ?
   668     // T3: constant pool cache index
   669     // T2: constant pool cache
   670     // Rsender: send's sp
   671     // check if getfield has been resolved and read constant pool cache entry
   672     // check the validity of the cache entry by testing whether _indices field
   673     // contains Bytecode::_getfield in b1 byte.
   674     assert(in_words(ConstantPoolCacheEntry::size()) == 4, "adjust shift below");
   676     __ dsll(T8, T3, Address::times_8);
   677     __ move(T1, in_bytes(ConstantPoolCache::base_offset()
   678     + ConstantPoolCacheEntry::indices_offset()));
   679     __ dadd(T1, T8, T1);
   680     __ dadd(T1, T1, T2);
   681     __ lw(T1, T1, 0);
   682     __ dsrl(T1, T1, 2 * BitsPerByte);
   683     __ andi(T1, T1, 0xFF);
   684     __ daddi(T1, T1, (-1) * Bytecodes::_getfield);
   685     __ bne(T1, R0, slow_path);
   686     __ delayed()->nop();
   688     // Note: constant pool entry is not valid before bytecode is resolved
   690     __ move(T1, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::f2_offset()));
   691     __ dadd(T1, T1, T8);
   692     __ dadd(T1, T1, T2);
   693     __ lw(AT, T1, 0);
   695     __ move(T1, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::flags_offset()));
   696     __ dadd(T1, T1, T8);
   697     __ dadd(T1, T1, T2);
   698     __ lw(T3, T1, 0);
   700     Label notByte, notBool, notShort, notChar, notObj;
   702     // Need to differentiate between igetfield, agetfield, bgetfield etc.
   703     // because they are different sizes.
   704     // Use the type from the constant pool cache
   705     __ srl(T3, T3, ConstantPoolCacheEntry::tos_state_shift);
   706     // Make sure we don't need to mask T3 for tosBits after the above shift
   707     ConstantPoolCacheEntry::verify_tos_state_shift();
   708     // btos = 0
   709     __ bne(T3, R0, notByte);
   710     __ delayed()->dadd(T0, T0, AT);
   712     __ lb(V0, T0, 0);
   713     __ b(xreturn_path);
   714     __ delayed()->nop();
   716     //ztos
   717     __ bind(notByte);
   718     __ daddi(T1, T3, (-1) * ztos);
   719     __ bne(T1, R0, notBool);
   720     __ delayed()->nop();
   721     __ lb(V0, T0, 0);
   722     __ b(xreturn_path);
   723     __ delayed()->nop();
   725     //stos
   726     __ bind(notBool);
   727     __ daddi(T1, T3, (-1) * stos);
   728     __ bne(T1, R0, notShort);
   729     __ delayed()->nop();
   730     __ lh(V0, T0, 0);
   731     __ b(xreturn_path);
   732     __ delayed()->nop();
   734     //ctos
   735     __ bind(notShort);
   736     __ daddi(T1, T3, (-1) * ctos);
   737     __ bne(T1, R0, notChar);
   738     __ delayed()->nop();
   739     __ lhu(V0, T0, 0);
   740     __ b(xreturn_path);
   741     __ delayed()->nop();
   743     //atos
   744     __ bind(notChar);
   745     __ daddi(T1, T3, (-1) * atos);
   746     __ bne(T1, R0, notObj);
   747     __ delayed()->nop();
   748     //add for compressedoops
   749     __ load_heap_oop(V0, Address(T0, 0));
   750     __ b(xreturn_path);
   751     __ delayed()->nop();
   753     //itos
   754     __ bind(notObj);
   755 #ifdef ASSERT
   756     Label okay;
   757     __ daddi(T1, T3, (-1) * itos);
   758     __ beq(T1, R0, okay);
   759     __ delayed()->nop();
   760     __ stop("what type is this?");
   761     __ bind(okay);
   762 #endif // ASSERT
   763     __ lw(V0, T0, 0);
   765     __ bind(xreturn_path);
   767     // _ireturn/_areturn
   768     //FIXME
   769     __ move(SP, Rsender);//FIXME, set sender's fp to SP
   770     __ jr(RA);
   771     __ delayed()->nop();
   773     // generate a vanilla interpreter entry as the slow path
   774     __ bind(slow_path);
   775     (void) generate_normal_entry(false);
   776   } else {
   777     (void) generate_normal_entry(false);
   778   }
   780   return entry_point;
   781 }
   783 // Method entry for java.lang.ref.Reference.get.
   784 address InterpreterGenerator::generate_Reference_get_entry(void) {
   785 #if INCLUDE_ALL_GCS
   786   // Code: _aload_0, _getfield, _areturn
   787   // parameter size = 1
   788   //
   789   // The code that gets generated by this routine is split into 2 parts:
   790   //    1. The "intrinsified" code for G1 (or any SATB based GC),
   791   //    2. The slow path - which is an expansion of the regular method entry.
   792   //
   793   // Notes:-
   794   // * In the G1 code we do not check whether we need to block for
   795   //   a safepoint. If G1 is enabled then we must execute the specialized
   796   //   code for Reference.get (except when the Reference object is null)
   797   //   so that we can log the value in the referent field with an SATB
   798   //   update buffer.
   799   //   If the code for the getfield template is modified so that the
   800   //   G1 pre-barrier code is executed when the current method is
   801   //   Reference.get() then going through the normal method entry
   802   //   will be fine.
   803   // * The G1 code can, however, check the receiver object (the instance
   804   //   of java.lang.Reference) and jump to the slow path if null. If the
   805   //   Reference object is null then we obviously cannot fetch the referent
   806   //   and so we don't need to call the G1 pre-barrier. Thus we can use the
   807   //   regular method entry code to generate the NPE.
   808   //
   809   // This code is based on generate_accessor_enty.
   810   //
   811   // Rmethod: Method*
   813   // Rsender: senderSP must preserve for slow path, set SP to it on fast path (Rsender)
   815   address entry = __ pc();
   817   const int referent_offset = java_lang_ref_Reference::referent_offset;
   818   guarantee(referent_offset > 0, "referent offset not initialized");
   820   if (UseG1GC) {
   821     Label slow_path;
   823     // Check if local 0 != NULL
   824     // If the receiver is null then it is OK to jump to the slow path.
   825     __ ld(V0, SP, 0);
   827     __ beq(V0, R0, slow_path);
   828     __ delayed()->nop();
   830     // Generate the G1 pre-barrier code to log the value of
   831     // the referent field in an SATB buffer.
   833     // Load the value of the referent field.
   834     const Address field_address(V0, referent_offset);
   835     __ load_heap_oop(V0, field_address);
   837     __ push(RA);
   838     // Generate the G1 pre-barrier code to log the value of
   839     // the referent field in an SATB buffer.
   840     __ g1_write_barrier_pre(noreg /* obj */,
   841                             V0 /* pre_val */,
   842                             TREG /* thread */,
   843                             Rmethod /* tmp */,
   844                             true /* tosca_live */,
   845                             true /* expand_call */);
   846     __ pop(RA);
   848     __ jr(RA);
   849     __ delayed()->daddu(SP, Rsender, R0);      // set sp to sender sp
   851     // generate a vanilla interpreter entry as the slow path
   852     __ bind(slow_path);
   853     (void) generate_normal_entry(false);
   855     return entry;
   856   }
   857 #endif // INCLUDE_ALL_GCS
   859   // If G1 is not enabled then attempt to go through the accessor entry point
   860   // Reference.get is an accessor
   861   return generate_accessor_entry();
   862 }
   864 // Interpreter stub for calling a native method. (asm interpreter)
   865 // This sets up a somewhat different looking stack for calling the
   866 // native method than the typical interpreter frame setup.
   867 address InterpreterGenerator::generate_native_entry(bool synchronized) {
   868   // determine code generation flags
   869   bool inc_counter  = UseCompiler || CountCompiledCalls;
   870   // Rsender: sender's sp
   871   // Rmethod: Method*
   872   address entry_point = __ pc();
   874 #ifndef CORE
   875   const Address invocation_counter(Rmethod,in_bytes(MethodCounters::invocation_counter_offset() +
   876   InvocationCounter::counter_offset()));
   877 #endif
   879   // get parameter size (always needed)
   880   // the size in the java stack
   881   __ ld(V0, Rmethod, in_bytes(Method::const_offset()));
   882   __ lhu(V0, V0, in_bytes(ConstMethod::size_of_parameters_offset()));
   884   // native calls don't need the stack size check since they have no expression stack
   885   // and the arguments are already on the stack and we only add a handful of words
   886   // to the stack
   888   // Rmethod: Method*
   889   // V0: size of parameters
   890   // Layout of frame at this point
   891   //
   892   // [ argument word n-1  ] <--- sp
   893   //   ...
   894   // [ argument word 0    ]
   896   // for natives the size of locals is zero
   898   // compute beginning of parameters (S7)
   899   __ dsll(LVP, V0, Address::times_8);
   900   __ daddiu(LVP, LVP, (-1) * wordSize);
   901   __ dadd(LVP, LVP, SP);
   904   // add 2 zero-initialized slots for native calls
   905   __ daddi(SP, SP, (-2) * wordSize);
   906   __ sd(R0, SP, 1 * wordSize);  // slot for native oop temp offset (setup via runtime)
   907   __ sd(R0, SP, 0 * wordSize);  // slot for static native result handler3 (setup via runtime)
   909   // Layout of frame at this point
   910   // [ method holder mirror  ] <--- sp
   911   // [ result type info      ]
   912   // [ argument word n-1     ] <--- T0
   913   //   ...
   914   // [ argument word 0       ] <--- LVP
   917 #ifndef CORE
   918   if (inc_counter) __ lw(T3, invocation_counter);  // (pre-)fetch invocation count
   919 #endif
   921   // initialize fixed part of activation frame
   922   generate_fixed_frame(true);
   923   // after this function, the layout of frame is as following
   924   //
   925   // [ monitor block top        ] <--- sp ( the top monitor entry )
   926   // [ byte code pointer (0)    ] (if native, bcp = 0)
   927   // [ constant pool cache      ]
   928   // [ Method*                  ]
   929   // [ locals offset            ]
   930   // [ sender's sp              ]
   931   // [ sender's fp              ]
   932   // [ return address           ] <--- fp
   933   // [ method holder mirror     ]
   934   // [ result type info         ]
   935   // [ argumnet word n-1        ] <--- sender's sp
   936   //   ...
   937   // [ argument word 0          ] <--- S7
   940   // make sure method is native & not abstract
   941 #ifdef ASSERT
   942   __ lw(T0, Rmethod, in_bytes(Method::access_flags_offset()));
   943   {
   944     Label L;
   945     __ andi(AT, T0, JVM_ACC_NATIVE);
   946     __ bne(AT, R0, L);
   947     __ delayed()->nop();
   948     __ stop("tried to execute native method as non-native");
   949     __ bind(L);
   950   }
   951   {
   952     Label L;
   953     __ andi(AT, T0, JVM_ACC_ABSTRACT);
   954     __ beq(AT, R0, L);
   955     __ delayed()->nop();
   956     __ stop("tried to execute abstract method in interpreter");
   957     __ bind(L);
   958   }
   959 #endif
   961   // Since at this point in the method invocation the exception handler
   962   // would try to exit the monitor of synchronized methods which hasn't
   963   // been entered yet, we set the thread local variable
   964   // _do_not_unlock_if_synchronized to true. The remove_activation will
   965   // check this flag.
   966   Register thread = TREG;
   967 #ifndef OPT_THREAD
   968   __ get_thread(thread);
   969 #endif
   970   __ move(AT, (int)true);
   971   __ sb(AT, thread, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
   973 #ifndef CORE
   974   // increment invocation count & check for overflow
   975   Label invocation_counter_overflow;
   976   if (inc_counter) {
   977     generate_counter_incr(&invocation_counter_overflow, NULL, NULL);
   978   }
   980   Label continue_after_compile;
   981   __ bind(continue_after_compile);
   982 #endif // CORE
   984   bang_stack_shadow_pages(true);
   986   // reset the _do_not_unlock_if_synchronized flag
   987 #ifndef OPT_THREAD
   988   __ get_thread(thread);
   989 #endif
   990   __ sb(R0, thread, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
   992   // check for synchronized methods
   993   // Must happen AFTER invocation_counter check and stack overflow check,
   994   // so method is not locked if overflows.
   995   if (synchronized) {
   996     lock_method();
   997   } else {
   998     // no synchronization necessary
   999 #ifdef ASSERT
  1001       Label L;
  1002       __ lw(T0, Rmethod, in_bytes(Method::access_flags_offset()));
  1003       __ andi(AT, T0, JVM_ACC_SYNCHRONIZED);
  1004       __ beq(AT, R0, L);
  1005       __ delayed()->nop();
  1006       __ stop("method needs synchronization");
  1007       __ bind(L);
  1009 #endif
  1012   // after method_lock, the layout of frame is as following
  1013   //
  1014   // [ monitor entry            ] <--- sp
  1015   //   ...
  1016   // [ monitor entry            ]
  1017   // [ monitor block top        ] ( the top monitor entry )
  1018   // [ byte code pointer (0)    ] (if native, bcp = 0)
  1019   // [ constant pool cache      ]
  1020   // [ Method*                  ]
  1021   // [ locals offset            ]
  1022   // [ sender's sp              ]
  1023   // [ sender's fp              ]
  1024   // [ return address           ] <--- fp
  1025   // [ method holder mirror     ]
  1026   // [ result type info         ]
  1027   // [ argumnet word n-1        ] <--- ( sender's sp )
  1028   //   ...
  1029   // [ argument word 0          ] <--- S7
  1031   // start execution
  1032 #ifdef ASSERT
  1034     Label L;
  1035     __ ld(AT, FP, frame::interpreter_frame_monitor_block_top_offset * wordSize);
  1036     __ beq(AT, SP, L);
  1037     __ delayed()->nop();
  1038     __ stop("broken stack frame setup in interpreter in asm");
  1039     __ bind(L);
  1041 #endif
  1043   // jvmti/jvmpi support
  1044   __ notify_method_entry();
  1046   // work registers
  1047   const Register method = Rmethod;
  1048   //const Register thread = T2;
  1049   const Register t      = RT4;
  1051   __ get_method(method);
  1052   __ verify_oop(method);
  1054     Label L, Lstatic;
  1055     __ ld(t,method,in_bytes(Method::const_offset()));
  1056     __ lhu(t, t, in_bytes(ConstMethod::size_of_parameters_offset()));
  1057     // MIPS n64 ABI: caller does not reserve space for the register auguments.
  1058     // A0 and A1(if needed)
  1059     __ lw(AT, Rmethod, in_bytes(Method::access_flags_offset()));
  1060     __ andi(AT, AT, JVM_ACC_STATIC);
  1061     __ beq(AT, R0, Lstatic);
  1062     __ delayed()->nop();
  1063     __ daddiu(t, t, 1);
  1064     __ bind(Lstatic);
  1065     __ daddiu(t, t, -7);
  1066     __ blez(t, L);
  1067     __ delayed()->nop();
  1068     __ dsll(t, t, Address::times_8);
  1069     __ dsub(SP, SP, t);
  1070     __ bind(L);
  1072   __ move(AT, -(StackAlignmentInBytes));
  1073   __ andr(SP, SP, AT);
  1074   __ move(AT, SP);
  1075   // [                          ] <--- sp
  1076   //   ...                        (size of parameters - 8 )
  1077   // [ monitor entry            ]
  1078   //   ...
  1079   // [ monitor entry            ]
  1080   // [ monitor block top        ] ( the top monitor entry )
  1081   // [ byte code pointer (0)    ] (if native, bcp = 0)
  1082   // [ constant pool cache      ]
  1083   // [ Method*                  ]
  1084   // [ locals offset            ]
  1085   // [ sender's sp              ]
  1086   // [ sender's fp              ]
  1087   // [ return address           ] <--- fp
  1088   // [ method holder mirror     ]
  1089   // [ result type info         ]
  1090   // [ argumnet word n-1        ] <--- ( sender's sp )
  1091   //   ...
  1092   // [ argument word 0          ] <--- LVP
  1094   // get signature handler
  1096     Label L;
  1097     __ ld(T9, method, in_bytes(Method::signature_handler_offset()));
  1098     __ bne(T9, R0, L);
  1099     __ delayed()->nop();
  1100     __ call_VM(NOREG, CAST_FROM_FN_PTR(address,
  1101                InterpreterRuntime::prepare_native_call), method);
  1102     __ get_method(method);
  1103     __ ld(T9, method, in_bytes(Method::signature_handler_offset()));
  1104     __ bind(L);
  1107   // call signature handler
  1108   // FIXME: when change codes in InterpreterRuntime, note this point
  1109   // from: begin of parameters
  1110   assert(InterpreterRuntime::SignatureHandlerGenerator::from() == LVP, "adjust this code");
  1111   // to: current sp
  1112   assert(InterpreterRuntime::SignatureHandlerGenerator::to  () == SP, "adjust this code");
  1113   // temp: T3
  1114   assert(InterpreterRuntime::SignatureHandlerGenerator::temp() == t  , "adjust this code");
  1116   __ jalr(T9);
  1117   __ delayed()->nop();
  1118   __ get_method(method);
  1120   //
  1121   // if native function is static, and its second parameter has type length of double word,
  1122   // and first parameter has type length of word, we have to reserve one word
  1123   // for the first parameter, according to mips o32 abi.
  1124   // if native function is not static, and its third parameter has type length of double word,
  1125   // and second parameter has type length of word, we have to reserve one word for the second
  1126   // parameter.
  1127   //
  1130   // result handler is in V0
  1131   // set result handler
  1132   __ sd(V0, FP, (frame::interpreter_frame_result_handler_offset)*wordSize);
  1134 #define FIRSTPARA_SHIFT_COUNT 5
  1135 #define SECONDPARA_SHIFT_COUNT 9
  1136 #define THIRDPARA_SHIFT_COUNT 13
  1137 #define PARA_MASK  0xf
  1139   // pass mirror handle if static call
  1141     Label L;
  1142     const int mirror_offset = in_bytes(Klass::java_mirror_offset());
  1143     __ lw(t, method, in_bytes(Method::access_flags_offset()));
  1144     __ andi(AT, t, JVM_ACC_STATIC);
  1145     __ beq(AT, R0, L);
  1146     __ delayed()->nop();
  1148     // get mirror
  1149     __ ld(t, method, in_bytes(Method:: const_offset()));
  1150     __ ld(t, t, in_bytes(ConstMethod::constants_offset())); //??
  1151     __ ld(t, t, ConstantPool::pool_holder_offset_in_bytes());
  1152     __ ld(t, t, mirror_offset);
  1153     // copy mirror into activation frame
  1154     //__ sw(t, FP, frame::interpreter_frame_oop_temp_offset * wordSize);
  1155     // pass handle to mirror
  1156     __ sd(t, FP, frame::interpreter_frame_oop_temp_offset * wordSize);
  1157     __ daddi(t, FP, frame::interpreter_frame_oop_temp_offset * wordSize);
  1158     __ move(A1, t);
  1159     __ bind(L);
  1162   // [ mthd holder mirror ptr   ] <--- sp  --------------------| (only for static method)
  1163   // [                          ]                              |
  1164   //   ...                        size of parameters(or +1)    |
  1165   // [ monitor entry            ]                              |
  1166   //   ...                                                     |
  1167   // [ monitor entry            ]                              |
  1168   // [ monitor block top        ] ( the top monitor entry )    |
  1169   // [ byte code pointer (0)    ] (if native, bcp = 0)         |
  1170   // [ constant pool cache      ]                              |
  1171   // [ Method*                  ]                              |
  1172   // [ locals offset            ]                              |
  1173   // [ sender's sp              ]                              |
  1174   // [ sender's fp              ]                              |
  1175   // [ return address           ] <--- fp                      |
  1176   // [ method holder mirror     ] <----------------------------|
  1177   // [ result type info         ]
  1178   // [ argumnet word n-1        ] <--- ( sender's sp )
  1179   //   ...
  1180   // [ argument word 0          ] <--- S7
  1182   // get native function entry point
  1183   { Label L;
  1184     __ ld(T9, method, in_bytes(Method::native_function_offset()));
  1185     __ li(V1, SharedRuntime::native_method_throw_unsatisfied_link_error_entry());
  1186     __ bne(V1, T9, L);
  1187     __ delayed()->nop();
  1188     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), method);
  1189     __ get_method(method);
  1190     __ verify_oop(method);
  1191     __ ld(T9, method, in_bytes(Method::native_function_offset()));
  1192     __ bind(L);
  1195   // pass JNIEnv
  1196   // native function in T9
  1197 #ifndef OPT_THREAD
  1198   __ get_thread(thread);
  1199 #endif
  1200   __ daddi(t, thread, in_bytes(JavaThread::jni_environment_offset()));
  1201   __ move(A0, t);
  1202   // [ jni environment          ] <--- sp
  1203   // [ mthd holder mirror ptr   ] ---------------------------->| (only for static method)
  1204   // [                          ]                              |
  1205   //   ...                        size of parameters           |
  1206   // [ monitor entry            ]                              |
  1207   //   ...                                                     |
  1208   // [ monitor entry            ]                              |
  1209   // [ monitor block top        ] ( the top monitor entry )    |
  1210   // [ byte code pointer (0)    ] (if native, bcp = 0)         |
  1211   // [ constant pool cache      ]                              |
  1212   // [ Method*                  ]                              |
  1213   // [ locals offset            ]                              |
  1214   // [ sender's sp              ]                              |
  1215   // [ sender's fp              ]                              |
  1216   // [ return address           ] <--- fp                      |
  1217   // [ method holder mirror     ] <----------------------------|
  1218   // [ result type info         ]
  1219   // [ argumnet word n-1        ] <--- ( sender's sp )
  1220   //   ...
  1221   // [ argument word 0          ] <--- S7
  1223   // set_last_Java_frame_before_call
  1224   __ sd(FP, thread, in_bytes(JavaThread::last_Java_fp_offset()));
  1225   // Change state to native (we save the return address in the thread, since it might not
  1226   // be pushed on the stack when we do a a stack traversal). It is enough that the pc()
  1227   // points into the right code segment. It does not have to be the correct return pc.
  1228   __ li(t, __ pc());
  1229   __ sd(t, thread, in_bytes(JavaThread::last_Java_pc_offset()));
  1230   __ sd(SP, thread, in_bytes(JavaThread::last_Java_sp_offset()));
  1232   // change thread state
  1233 #ifdef ASSERT
  1235     Label L;
  1236     __ lw(t, thread, in_bytes(JavaThread::thread_state_offset()));
  1237     __ daddi(t, t, (-1) * _thread_in_Java);
  1238     __ beq(t, R0, L);
  1239     __ delayed()->nop();
  1240     __ stop("Wrong thread state in native stub");
  1241     __ bind(L);
  1243 #endif
  1245   __ move(t, _thread_in_native);
  1246   __ sw(t, thread, in_bytes(JavaThread::thread_state_offset()));
  1248   // call native method
  1249   __ jalr(T9);
  1250   __ delayed()->nop();
  1251   // result potentially in V0 or F0
  1254   // via _last_native_pc and not via _last_jave_sp
  1255   // NOTE: the order of theses push(es) is known to frame::interpreter_frame_result.
  1256   //  If the order changes or anything else is added to the stack the code in
  1257   // interpreter_frame_result will have to be changed.
  1258   //FIXME, should modify here
  1259   // save return value to keep the value from being destroyed by other calls
  1260   __ push(dtos);
  1261   __ push(ltos);
  1263   // change thread state
  1264   __ get_thread(thread);
  1265   __ move(t, _thread_in_native_trans);
  1266   __ sw(t, thread, in_bytes(JavaThread::thread_state_offset()));
  1268   if( os::is_MP() ) __ sync(); // Force this write out before the read below
  1270   // check for safepoint operation in progress and/or pending suspend requests
  1271   { Label Continue;
  1273     // Don't use call_VM as it will see a possible pending exception and forward it
  1274     // and never return here preventing us from clearing _last_native_pc down below.
  1275     // Also can't use call_VM_leaf either as it will check to see if BCP & LVP are
  1276     // preserved and correspond to the bcp/locals pointers. So we do a runtime call
  1277     // by hand.
  1278     //
  1279     Label L;
  1280     __ li(AT, SafepointSynchronize::address_of_state());
  1281     __ lw(AT, AT, 0);
  1282     __ bne(AT, R0, L);
  1283     __ delayed()->nop();
  1284     __ lw(AT, thread, in_bytes(JavaThread::suspend_flags_offset()));
  1285     __ beq(AT, R0, Continue);
  1286     __ delayed()->nop();
  1287     __ bind(L);
  1288     __ move(A0, thread);
  1289     __ call(CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans),
  1290                              relocInfo::runtime_call_type);
  1291     __ delayed()->nop();
  1293 #ifndef OPT_THREAD
  1294     __ get_thread(thread);
  1295 #endif
  1296     //add for compressedoops
  1297     __ reinit_heapbase();
  1298     __ bind(Continue);
  1301   // change thread state
  1302   __ move(t, _thread_in_Java);
  1303   __ sw(t, thread, in_bytes(JavaThread::thread_state_offset()));
  1304   __ reset_last_Java_frame(thread, true);
  1306   // reset handle block
  1307   __ ld(t, thread, in_bytes(JavaThread::active_handles_offset()));
  1308   __ sw(R0, t, JNIHandleBlock::top_offset_in_bytes());
  1310   // If result was an oop then unbox and save it in the frame
  1312     Label no_oop;
  1313     //FIXME, addi only support 16-bit imeditate
  1314     __ ld(AT, FP, frame::interpreter_frame_result_handler_offset*wordSize);
  1315     __ li(T0, AbstractInterpreter::result_handler(T_OBJECT));
  1316     __ bne(AT, T0, no_oop);
  1317     __ delayed()->nop();
  1318     __ pop(ltos);
  1319     // Unbox oop result, e.g. JNIHandles::resolve value.
  1320     __ resolve_jobject(V0, thread, T9);
  1321     __ sd(V0, FP, (frame::interpreter_frame_oop_temp_offset)*wordSize);
  1322     // keep stack depth as expected by pushing oop which will eventually be discarded
  1323     __ push(ltos);
  1324     __ bind(no_oop);
  1327     Label no_reguard;
  1328     __ lw(t, thread, in_bytes(JavaThread::stack_guard_state_offset()));
  1329     __ move(AT,(int) JavaThread::stack_guard_yellow_disabled);
  1330     __ bne(t, AT, no_reguard);
  1331     __ delayed()->nop();
  1332     __ pushad();
  1333     __ move(S5_heapbase, SP);
  1334     __ move(AT, -StackAlignmentInBytes);
  1335     __ andr(SP, SP, AT);
  1336     __ call(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages), relocInfo::runtime_call_type);
  1337     __ delayed()->nop();
  1338     __ move(SP, S5_heapbase);
  1339     __ popad();
  1340     //add for compressedoops
  1341     __ reinit_heapbase();
  1342     __ bind(no_reguard);
  1344   // restore BCP to have legal interpreter frame,
  1345   // i.e., bci == 0 <=> BCP == code_base()
  1346   // Can't call_VM until bcp is within reasonable.
  1347   __ get_method(method);      // method is junk from thread_in_native to now.
  1348   __ verify_oop(method);
  1349   __ ld(BCP, method, in_bytes(Method::const_offset()));
  1350   __ lea(BCP, Address(BCP, in_bytes(ConstMethod::codes_offset())));
  1351   // handle exceptions (exception handling will handle unlocking!)
  1353     Label L;
  1354     __ lw(t, thread, in_bytes(Thread::pending_exception_offset()));
  1355     __ beq(t, R0, L);
  1356     __ delayed()->nop();
  1357     // Note: At some point we may want to unify this with the code used in
  1358     // call_VM_base();
  1359     // i.e., we should use the StubRoutines::forward_exception code. For now this
  1360     // doesn't work here because the sp is not correctly set at this point.
  1361     __ MacroAssembler::call_VM(noreg,
  1362                                CAST_FROM_FN_PTR(address,
  1363                                InterpreterRuntime::throw_pending_exception));
  1364     __ should_not_reach_here();
  1365     __ bind(L);
  1368   // do unlocking if necessary
  1370     Label L;
  1371     __ lw(t, method, in_bytes(Method::access_flags_offset()));
  1372     __ andi(t, t, JVM_ACC_SYNCHRONIZED);
  1373     __ beq(t, R0, L);
  1374     // the code below should be shared with interpreter macro assembler implementation
  1376       Label unlock;
  1377       // BasicObjectLock will be first in list,
  1378       // since this is a synchronized method. However, need
  1379       // to check that the object has not been unlocked by
  1380       // an explicit monitorexit bytecode.
  1381       __ delayed()->daddi(c_rarg0, FP, frame::interpreter_frame_initial_sp_offset * wordSize - (int)sizeof(BasicObjectLock));
  1382       // address of first monitor
  1384       __ ld(t, c_rarg0, BasicObjectLock::obj_offset_in_bytes());
  1385       __ bne(t, R0, unlock);
  1386       __ delayed()->nop();
  1388       // Entry already unlocked, need to throw exception
  1389       __ MacroAssembler::call_VM(NOREG, CAST_FROM_FN_PTR(address,
  1390       InterpreterRuntime::throw_illegal_monitor_state_exception));
  1391       __ should_not_reach_here();
  1393       __ bind(unlock);
  1394       __ unlock_object(c_rarg0);
  1396     __ bind(L);
  1399   // jvmti/jvmpi support
  1400   // Note: This must happen _after_ handling/throwing any exceptions since
  1401   //       the exception handler code notifies the runtime of method exits
  1402   //       too. If this happens before, method entry/exit notifications are
  1403   //       not properly paired (was bug - gri 11/22/99).
  1404   __ notify_method_exit(false, vtos, InterpreterMacroAssembler::NotifyJVMTI);
  1406   // restore potential result in V0,
  1407   // call result handler to restore potential result in ST0 & handle result
  1409   __ pop(ltos);
  1410   __ pop(dtos);
  1412   __ ld(t, FP, (frame::interpreter_frame_result_handler_offset) * wordSize);
  1413   __ jalr(t);
  1414   __ delayed()->nop();
  1417   // remove activation
  1418   __ ld(SP, FP, frame::interpreter_frame_sender_sp_offset * wordSize); // get sender sp
  1419   __ ld(RA, FP, frame::interpreter_frame_return_addr_offset * wordSize); // get return address
  1420   __ ld(FP, FP, frame::interpreter_frame_sender_fp_offset * wordSize); // restore sender's fp
  1421   __ jr(RA);
  1422   __ delayed()->nop();
  1424 #ifndef CORE
  1425   if (inc_counter) {
  1426     // Handle overflow of counter and compile method
  1427     __ bind(invocation_counter_overflow);
  1428     generate_counter_overflow(&continue_after_compile);
  1429     // entry_point is the beginning of this
  1430     // function and checks again for compiled code
  1432 #endif
  1433   return entry_point;
  1436 //
  1437 // Generic interpreted method entry to (asm) interpreter
  1438 //
  1439 // Layout of frame just at the entry
  1440 //
  1441 //   [ argument word n-1  ] <--- sp
  1442 //     ...
  1443 //   [ argument word 0    ]
  1444 // assume Method* in Rmethod before call this method.
  1445 // prerequisites to the generated stub : the callee Method* in Rmethod
  1446 // note you must save the caller bcp before call the generated stub
  1447 //
  1448 address InterpreterGenerator::generate_normal_entry(bool synchronized) {
  1449   // determine code generation flags
  1450   bool inc_counter  = UseCompiler || CountCompiledCalls;
  1452   // Rmethod: Method*
  1453   // Rsender: sender 's sp
  1454   address entry_point = __ pc();
  1456   const Address invocation_counter(Rmethod,
  1457       in_bytes(MethodCounters::invocation_counter_offset() + InvocationCounter::counter_offset()));
  1459   // get parameter size (always needed)
  1460   __ ld(T3, Rmethod, in_bytes(Method::const_offset()));  //T3 --> Rmethod._constMethod
  1461   __ lhu(V0, T3, in_bytes(ConstMethod::size_of_parameters_offset()));
  1463   // Rmethod: Method*
  1464   // V0: size of parameters
  1465   // Rsender: sender 's sp ,could be different frome sp+ wordSize if we call via c2i
  1466   // get size of locals in words to T2
  1467   __ lhu(T2, T3, in_bytes(ConstMethod::size_of_locals_offset()));
  1468   // T2 = no. of additional locals, locals include parameters
  1469   __ dsub(T2, T2, V0);
  1471   // see if we've got enough room on the stack for locals plus overhead.
  1472   // Layout of frame at this point
  1473   //
  1474   // [ argument word n-1  ] <--- sp
  1475   //   ...
  1476   // [ argument word 0    ]
  1477   generate_stack_overflow_check();
  1478   // after this function, the layout of frame does not change
  1480   // compute beginning of parameters (LVP)
  1481   __ dsll(LVP, V0, LogBytesPerWord);
  1482   __ daddiu(LVP, LVP, (-1) * wordSize);
  1483   __ dadd(LVP, LVP, SP);
  1485   // T2 - # of additional locals
  1486   // allocate space for locals
  1487   // explicitly initialize locals
  1489     Label exit, loop;
  1490     __ beq(T2, R0, exit);
  1491     __ delayed()->nop();
  1493     __ bind(loop);
  1494     __ sd(R0, SP, -1 * wordSize);     // initialize local variables
  1495     __ daddiu(T2, T2, -1);               // until everything initialized
  1496     __ bne(T2, R0, loop);
  1497     __ delayed();
  1499     __ daddiu(SP, SP, (-1) * wordSize); //fill delay slot
  1501     __ bind(exit);
  1504   //
  1505   // [ local var m-1      ] <--- sp
  1506   //   ...
  1507   // [ local var 0        ]
  1508   // [ argument word n-1  ] <--- T0?
  1509   //   ...
  1510   // [ argument word 0    ] <--- LVP
  1512   // initialize fixed part of activation frame
  1514   generate_fixed_frame(false);
  1517   // after this function, the layout of frame is as following
  1518   //
  1519   // [ monitor block top        ] <--- sp ( the top monitor entry )
  1520   // [ byte code pointer        ] (if native, bcp = 0)
  1521   // [ constant pool cache      ]
  1522   // [ Method*                  ]
  1523   // [ locals offset            ]
  1524   // [ sender's sp              ]
  1525   // [ sender's fp              ] <--- fp
  1526   // [ return address           ]
  1527   // [ local var m-1            ]
  1528   //   ...
  1529   // [ local var 0              ]
  1530   // [ argumnet word n-1        ] <--- ( sender's sp )
  1531   //   ...
  1532   // [ argument word 0          ] <--- LVP
  1535   // make sure method is not native & not abstract
  1536 #ifdef ASSERT
  1537   __ ld(AT, Rmethod, in_bytes(Method::access_flags_offset()));
  1539     Label L;
  1540     __ andi(T2, AT, JVM_ACC_NATIVE);
  1541     __ beq(T2, R0, L);
  1542     __ delayed()->nop();
  1543     __ stop("tried to execute native method as non-native");
  1544     __ bind(L);
  1547     Label L;
  1548     __ andi(T2, AT, JVM_ACC_ABSTRACT);
  1549     __ beq(T2, R0, L);
  1550     __ delayed()->nop();
  1551     __ stop("tried to execute abstract method in interpreter");
  1552     __ bind(L);
  1554 #endif
  1556   // Since at this point in the method invocation the exception handler
  1557   // would try to exit the monitor of synchronized methods which hasn't
  1558   // been entered yet, we set the thread local variable
  1559   // _do_not_unlock_if_synchronized to true. The remove_activation will
  1560   // check this flag.
  1562 #ifndef OPT_THREAD
  1563   Register thread = T8;
  1564   __ get_thread(thread);
  1565 #else
  1566   Register thread = TREG;
  1567 #endif
  1568   __ move(AT, (int)true);
  1569   __ sb(AT, thread, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
  1571 #ifndef CORE
  1573   // mdp : T8
  1574   // tmp1: T9
  1575   // tmp2: T2
  1576    __ profile_parameters_type(T8, T9, T2);
  1578   // increment invocation count & check for overflow
  1579   Label invocation_counter_overflow;
  1580   Label profile_method;
  1581   Label profile_method_continue;
  1582   if (inc_counter) {
  1583     generate_counter_incr(&invocation_counter_overflow,
  1584                           &profile_method,
  1585                           &profile_method_continue);
  1586     if (ProfileInterpreter) {
  1587       __ bind(profile_method_continue);
  1591   Label continue_after_compile;
  1592   __ bind(continue_after_compile);
  1594 #endif // CORE
  1596   bang_stack_shadow_pages(false);
  1598   // reset the _do_not_unlock_if_synchronized flag
  1599 #ifndef OPT_THREAD
  1600   __ get_thread(thread);
  1601 #endif
  1602   __ sb(R0, thread, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
  1604   // check for synchronized methods
  1605   // Must happen AFTER invocation_counter check and stack overflow check,
  1606   // so method is not locked if overflows.
  1607   //
  1608   if (synchronized) {
  1609     // Allocate monitor and lock method
  1610     lock_method();
  1611   } else {
  1612     // no synchronization necessary
  1613 #ifdef ASSERT
  1614     { Label L;
  1615       __ lw(AT, Rmethod, in_bytes(Method::access_flags_offset()));
  1616       __ andi(T2, AT, JVM_ACC_SYNCHRONIZED);
  1617       __ beq(T2, R0, L);
  1618       __ delayed()->nop();
  1619       __ stop("method needs synchronization");
  1620       __ bind(L);
  1622 #endif
  1625   // layout of frame after lock_method
  1626   // [ monitor entry            ] <--- sp
  1627   //   ...
  1628   // [ monitor entry            ]
  1629   // [ monitor block top        ] ( the top monitor entry )
  1630   // [ byte code pointer        ] (if native, bcp = 0)
  1631   // [ constant pool cache      ]
  1632   // [ Method*                  ]
  1633   // [ locals offset            ]
  1634   // [ sender's sp              ]
  1635   // [ sender's fp              ]
  1636   // [ return address           ] <--- fp
  1637   // [ local var m-1            ]
  1638   //   ...
  1639   // [ local var 0              ]
  1640   // [ argumnet word n-1        ] <--- ( sender's sp )
  1641   //   ...
  1642   // [ argument word 0          ] <--- LVP
  1645   // start execution
  1646 #ifdef ASSERT
  1648     Label L;
  1649     __ ld(AT, FP, frame::interpreter_frame_monitor_block_top_offset * wordSize);
  1650     __ beq(AT, SP, L);
  1651     __ delayed()->nop();
  1652     __ stop("broken stack frame setup in interpreter in native");
  1653     __ bind(L);
  1655 #endif
  1657   // jvmti/jvmpi support
  1658   __ notify_method_entry();
  1660   __ dispatch_next(vtos);
  1662   // invocation counter overflow
  1663   if (inc_counter) {
  1664     if (ProfileInterpreter) {
  1665       // We have decided to profile this method in the interpreter
  1666       __ bind(profile_method);
  1667       __ call_VM(noreg, CAST_FROM_FN_PTR(address,
  1668                  InterpreterRuntime::profile_method));
  1669       __ set_method_data_pointer_for_bcp();
  1670       __ get_method(Rmethod);
  1671       __ b(profile_method_continue);
  1672       __ delayed()->nop();
  1674     // Handle overflow of counter and compile method
  1675     __ bind(invocation_counter_overflow);
  1676     generate_counter_overflow(&continue_after_compile);
  1679   return entry_point;
  1682 // Entry points
  1683 //
  1684 // Here we generate the various kind of entries into the interpreter.
  1685 // The two main entry type are generic bytecode methods and native
  1686 // call method.  These both come in synchronized and non-synchronized
  1687 // versions but the frame layout they create is very similar. The
  1688 // other method entry types are really just special purpose entries
  1689 // that are really entry and interpretation all in one. These are for
  1690 // trivial methods like accessor, empty, or special math methods.
  1691 //
  1692 // When control flow reaches any of the entry types for the interpreter
  1693 // the following holds ->
  1694 //
  1695 // Arguments:
  1696 //
  1697 // Rmethod: Method*
  1698 // V0: receiver
  1699 //
  1700 //
  1701 // Stack layout immediately at entry
  1702 //
  1703 // [ parameter n-1            ] <--- sp
  1704 //   ...
  1705 // [ parameter 0              ]
  1706 // [ expression stack         ] (caller's java expression stack)
  1708 // Assuming that we don't go to one of the trivial specialized entries
  1709 // the stack will look like below when we are ready to execute the
  1710 // first bytecode (or call the native routine). The register usage
  1711 // will be as the template based interpreter expects (see
  1712 // interpreter_mips_64.hpp).
  1713 //
  1714 // local variables follow incoming parameters immediately; i.e.
  1715 // the return address is moved to the end of the locals).
  1716 //
  1717 // [ monitor entry            ] <--- sp
  1718 //   ...
  1719 // [ monitor entry            ]
  1720 // [ monitor block top        ] ( the top monitor entry )
  1721 // [ byte code pointer        ] (if native, bcp = 0)
  1722 // [ constant pool cache      ]
  1723 // [ Method*                  ]
  1724 // [ locals offset            ]
  1725 // [ sender's sp              ]
  1726 // [ sender's fp              ]
  1727 // [ return address           ] <--- fp
  1728 // [ local var m-1            ]
  1729 //   ...
  1730 // [ local var 0              ]
  1731 // [ argumnet word n-1        ] <--- ( sender's sp )
  1732 //   ...
  1733 // [ argument word 0          ] <--- S7
  1735 address AbstractInterpreterGenerator::generate_method_entry(
  1736                                         AbstractInterpreter::MethodKind kind) {
  1737   // determine code generation flags
  1738   bool synchronized = false;
  1739   address entry_point = NULL;
  1740   switch (kind) {
  1741     case Interpreter::zerolocals             :
  1742       break;
  1743     case Interpreter::zerolocals_synchronized:
  1744       synchronized = true;
  1745       break;
  1746     case Interpreter::native                 :
  1747       entry_point = ((InterpreterGenerator*)this)->generate_native_entry(false);
  1748       break;
  1749     case Interpreter::native_synchronized    :
  1750       entry_point = ((InterpreterGenerator*)this)->generate_native_entry(true);
  1751       break;
  1752     case Interpreter::empty                  :
  1753       entry_point = ((InterpreterGenerator*)this)->generate_empty_entry();
  1754       break;
  1755     case Interpreter::accessor               :
  1756       entry_point = ((InterpreterGenerator*)this)->generate_accessor_entry();
  1757       break;
  1758     case Interpreter::abstract               :
  1759       entry_point = ((InterpreterGenerator*)this)->generate_abstract_entry();
  1760       break;
  1762     case Interpreter::java_lang_math_sin     : // fall thru
  1763     case Interpreter::java_lang_math_cos     : // fall thru
  1764     case Interpreter::java_lang_math_tan     : // fall thru
  1765     case Interpreter::java_lang_math_log     : // fall thru
  1766     case Interpreter::java_lang_math_log10   : // fall thru
  1767     case Interpreter::java_lang_math_pow     : // fall thru
  1768     case Interpreter::java_lang_math_exp     : break;
  1769     case Interpreter::java_lang_math_abs     : // fall thru
  1770     case Interpreter::java_lang_math_sqrt    :
  1771       entry_point = ((InterpreterGenerator*)this)->generate_math_entry(kind);    break;
  1772     case Interpreter::java_lang_ref_reference_get:
  1773       entry_point = ((InterpreterGenerator*)this)->generate_Reference_get_entry(); break;
  1774     default:
  1775       fatal(err_msg("unexpected method kind: %d", kind));
  1776       break;
  1778   if (entry_point) return entry_point;
  1780   return ((InterpreterGenerator*)this)->generate_normal_entry(synchronized);
  1783 // These should never be compiled since the interpreter will prefer
  1784 // the compiled version to the intrinsic version.
  1785 bool AbstractInterpreter::can_be_compiled(methodHandle m) {
  1786   switch (method_kind(m)) {
  1787     case Interpreter::java_lang_math_sin     : // fall thru
  1788     case Interpreter::java_lang_math_cos     : // fall thru
  1789     case Interpreter::java_lang_math_tan     : // fall thru
  1790     case Interpreter::java_lang_math_abs     : // fall thru
  1791     case Interpreter::java_lang_math_log     : // fall thru
  1792     case Interpreter::java_lang_math_log10   : // fall thru
  1793     case Interpreter::java_lang_math_sqrt    : // fall thru
  1794     case Interpreter::java_lang_math_pow     : // fall thru
  1795     case Interpreter::java_lang_math_exp     :
  1796       return false;
  1797     default:
  1798       return true;
  1802 // How much stack a method activation needs in words.
  1803 int AbstractInterpreter::size_top_interpreter_activation(Method* method) {
  1805   const int entry_size    = frame::interpreter_frame_monitor_size();
  1807   // total overhead size: entry_size + (saved fp thru expr stack bottom).
  1808   // be sure to change this if you add/subtract anything to/from the overhead area
  1809   const int overhead_size = -(frame::interpreter_frame_initial_sp_offset) + entry_size;
  1811   const int stub_code = 6;  // see generate_call_stub
  1812   // return overhead_size + method->max_locals() + method->max_stack() + stub_code;
  1813   const int method_stack = (method->max_locals() + method->max_stack()) *
  1814           Interpreter::stackElementWords;
  1815   return overhead_size + method_stack + stub_code;
  1818 void AbstractInterpreter::layout_activation(Method* method,
  1819                                            int tempcount,
  1820                                            int popframe_extra_args,
  1821                                            int moncount,
  1822                                            int caller_actual_parameters,
  1823                                            int callee_param_count,
  1824                                            int callee_locals,
  1825                                            frame* caller,
  1826                                            frame* interpreter_frame,
  1827                                            bool is_top_frame,
  1828                                            bool is_bottom_frame) {
  1829   // Note: This calculation must exactly parallel the frame setup
  1830   // in AbstractInterpreterGenerator::generate_method_entry.
  1831   // If interpreter_frame!=NULL, set up the method, locals, and monitors.
  1832   // The frame interpreter_frame, if not NULL, is guaranteed to be the
  1833   // right size, as determined by a previous call to this method.
  1834   // It is also guaranteed to be walkable even though it is in a skeletal state
  1836   // fixed size of an interpreter frame:
  1838   int max_locals = method->max_locals() * Interpreter::stackElementWords;
  1839   int extra_locals = (method->max_locals() - method->size_of_parameters()) * Interpreter::stackElementWords;
  1841 #ifdef ASSERT
  1842   if (!EnableInvokeDynamic) {
  1843     // @@@ FIXME: Should we correct interpreter_frame_sender_sp in the calling sequences?
  1844     // Probably, since deoptimization doesn't work yet.
  1845     assert(caller->unextended_sp() == interpreter_frame->interpreter_frame_sender_sp(), "Frame not properly walkable");
  1847   assert(caller->sp() == interpreter_frame->interpreter_frame_sender_sp(), "Frame not properly walkable(2)");
  1848 #endif
  1850     interpreter_frame->interpreter_frame_set_method(method);
  1851     // NOTE the difference in using sender_sp and interpreter_frame_sender_sp
  1852     // interpreter_frame_sender_sp is the original sp of the caller (the unextended_sp)
  1853     // and sender_sp is fp+8
  1854     intptr_t* locals = interpreter_frame->sender_sp() + max_locals - 1;
  1856 #ifdef ASSERT
  1857   if (caller->is_interpreted_frame()) {
  1858     assert(locals < caller->fp() + frame::interpreter_frame_initial_sp_offset, "bad placement");
  1860 #endif
  1862   interpreter_frame->interpreter_frame_set_locals(locals);
  1863   BasicObjectLock* montop = interpreter_frame->interpreter_frame_monitor_begin();
  1864   BasicObjectLock* monbot = montop - moncount;
  1865   interpreter_frame->interpreter_frame_set_monitor_end(montop - moncount);
  1867   //set last sp;
  1868   intptr_t*  sp = (intptr_t*) monbot - tempcount*Interpreter::stackElementWords -
  1869                       popframe_extra_args;
  1870   interpreter_frame->interpreter_frame_set_last_sp(sp);
  1871   // All frames but the initial interpreter frame we fill in have a
  1872   // value for sender_sp that allows walking the stack but isn't
  1873   // truly correct. Correct the value here.
  1874   //
  1875     if (extra_locals != 0 &&
  1876         interpreter_frame->sender_sp() == interpreter_frame->interpreter_frame_sender_sp() ) {
  1877       interpreter_frame->set_interpreter_frame_sender_sp(caller->sp() + extra_locals);
  1879     *interpreter_frame->interpreter_frame_cache_addr() = method->constants()->cache();
  1882 //-----------------------------------------------------------------------------
  1883 // Exceptions
  1885 void TemplateInterpreterGenerator::generate_throw_exception() {
  1886   // Entry point in previous activation (i.e., if the caller was
  1887   // interpreted)
  1888   Interpreter::_rethrow_exception_entry = __ pc();
  1889   // Restore sp to interpreter_frame_last_sp even though we are going
  1890   // to empty the expression stack for the exception processing.
  1891   __ sd(R0,FP, frame::interpreter_frame_last_sp_offset * wordSize);
  1893   // V0: exception
  1894   // V1: return address/pc that threw exception
  1895   __ restore_bcp();                              // BCP points to call/send
  1896   __ restore_locals();
  1898   //add for compressedoops
  1899   __ reinit_heapbase();
  1900   // Entry point for exceptions thrown within interpreter code
  1901   Interpreter::_throw_exception_entry = __ pc();
  1902   // expression stack is undefined here
  1903   // V0: exception
  1904   // BCP: exception bcp
  1905   __ verify_oop(V0);
  1907   // expression stack must be empty before entering the VM in case of an exception
  1908   __ empty_expression_stack();
  1909   // find exception handler address and preserve exception oop
  1910   __ move(A1, V0);
  1911   __ call_VM(V1, CAST_FROM_FN_PTR(address, InterpreterRuntime::exception_handler_for_exception), A1);
  1912   // V0: exception handler entry point
  1913   // V1: preserved exception oop
  1914   // S0: bcp for exception handler
  1915   __ daddi(SP, SP, (-1) * wordSize);
  1916   __ sd(V1, SP, 0);                              // push exception which is now the only value on the stack
  1917   __ jr(V0);                                   // jump to exception handler (may be _remove_activation_entry!)
  1918   __ delayed()->nop();
  1920   // If the exception is not handled in the current frame the frame is removed and
  1921   // the exception is rethrown (i.e. exception continuation is _rethrow_exception).
  1922   //
  1923   // Note: At this point the bci is still the bxi for the instruction which caused
  1924   //       the exception and the expression stack is empty. Thus, for any VM calls
  1925   //       at this point, GC will find a legal oop map (with empty expression stack).
  1927   // In current activation
  1928   // V0: exception
  1929   // BCP: exception bcp
  1931   //
  1932   // JVMTI PopFrame support
  1933   //
  1935   Interpreter::_remove_activation_preserving_args_entry = __ pc();
  1936   __ empty_expression_stack();
  1937   // Set the popframe_processing bit in pending_popframe_condition indicating that we are
  1938   // currently handling popframe, so that call_VMs that may happen later do not trigger new
  1939   // popframe handling cycles.
  1940 #ifndef OPT_THREAD
  1941   Register thread = T2;
  1942   __ get_thread(T2);
  1943 #else
  1944   Register thread = TREG;
  1945 #endif
  1946   __ lw(T3, thread, in_bytes(JavaThread::popframe_condition_offset()));
  1947   __ ori(T3, T3, JavaThread::popframe_processing_bit);
  1948   __ sw(T3, thread, in_bytes(JavaThread::popframe_condition_offset()));
  1950 #ifndef CORE
  1952     // Check to see whether we are returning to a deoptimized frame.
  1953     // (The PopFrame call ensures that the caller of the popped frame is
  1954     // either interpreted or compiled and deoptimizes it if compiled.)
  1955     // In this case, we can't call dispatch_next() after the frame is
  1956     // popped, but instead must save the incoming arguments and restore
  1957     // them after deoptimization has occurred.
  1958     //
  1959     // Note that we don't compare the return PC against the
  1960     // deoptimization blob's unpack entry because of the presence of
  1961     // adapter frames in C2.
  1962     Label caller_not_deoptimized;
  1963     __ ld(A0, FP, frame::return_addr_offset * wordSize);
  1964     __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::interpreter_contains), A0);
  1965     __ bne(V0, R0, caller_not_deoptimized);
  1966     __ delayed()->nop();
  1968     // Compute size of arguments for saving when returning to deoptimized caller
  1969     __ get_method(A1);
  1970     __ verify_oop(A1);
  1971     __ ld(A1, A1, in_bytes(Method::const_offset()));
  1972     __ lhu(A1, A1, in_bytes(ConstMethod::size_of_parameters_offset()));
  1973     __ shl(A1, Interpreter::logStackElementSize);
  1974     __ restore_locals();
  1975     __ dsub(A2, LVP, A1);
  1976     __ daddiu(A2, A2, wordSize);
  1977     // Save these arguments
  1978 #ifndef OPT_THREAD
  1979     __ get_thread(A0);
  1980 #else
  1981     __ move(A0, TREG);
  1982 #endif
  1983     __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, Deoptimization::popframe_preserve_args), A0, A1, A2);
  1985     __ remove_activation(vtos, T9, false, false, false);
  1987     // Inform deoptimization that it is responsible for restoring these arguments
  1988 #ifndef OPT_THREAD
  1989     __ get_thread(thread);
  1990 #endif
  1991     __ move(AT, JavaThread::popframe_force_deopt_reexecution_bit);
  1992     __ sw(AT, thread, in_bytes(JavaThread::popframe_condition_offset()));
  1993     // Continue in deoptimization handler
  1994     __ jr(T9);
  1995     __ delayed()->nop();
  1997     __ bind(caller_not_deoptimized);
  1999 #endif /* !CORE */
  2001   __ remove_activation(vtos, T3,
  2002                        /* throw_monitor_exception */ false,
  2003                        /* install_monitor_exception */ false,
  2004                        /* notify_jvmdi */ false);
  2006   // Clear the popframe condition flag
  2007   // Finish with popframe handling
  2008   // A previous I2C followed by a deoptimization might have moved the
  2009   // outgoing arguments further up the stack. PopFrame expects the
  2010   // mutations to those outgoing arguments to be preserved and other
  2011   // constraints basically require this frame to look exactly as
  2012   // though it had previously invoked an interpreted activation with
  2013   // no space between the top of the expression stack (current
  2014   // last_sp) and the top of stack. Rather than force deopt to
  2015   // maintain this kind of invariant all the time we call a small
  2016   // fixup routine to move the mutated arguments onto the top of our
  2017   // expression stack if necessary.
  2018   __ move(T8, SP);
  2019   __ ld(A2, FP, frame::interpreter_frame_last_sp_offset * wordSize);
  2020 #ifndef OPT_THREAD
  2021   __ get_thread(thread);
  2022 #endif
  2023   // PC must point into interpreter here
  2024   __ set_last_Java_frame(thread, noreg, FP, __ pc());
  2025   __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::popframe_move_outgoing_args), thread, T8, A2);
  2026   __ reset_last_Java_frame(thread, true);
  2027   // Restore the last_sp and null it out
  2028   __ ld(SP, FP, frame::interpreter_frame_last_sp_offset * wordSize);
  2029   __ sd(R0, FP, frame::interpreter_frame_last_sp_offset * wordSize);
  2033   __ move(AT, JavaThread::popframe_inactive);
  2034   __ sw(AT, thread, in_bytes(JavaThread::popframe_condition_offset()));
  2036   // Finish with popframe handling
  2037   __ restore_bcp();
  2038   __ restore_locals();
  2039 #ifndef CORE
  2040   // The method data pointer was incremented already during
  2041   // call profiling. We have to restore the mdp for the current bcp.
  2042   if (ProfileInterpreter) {
  2043     __ set_method_data_pointer_for_bcp();
  2045 #endif // !CORE
  2046   // Clear the popframe condition flag
  2047 #ifndef OPT_THREAD
  2048   __ get_thread(thread);
  2049 #endif
  2050   __ move(AT, JavaThread::popframe_inactive);
  2051   __ sw(AT, thread, in_bytes(JavaThread::popframe_condition_offset()));
  2053 #if INCLUDE_JVMTI
  2055     Label L_done;
  2057     __ lbu(AT, BCP, 0);
  2058     __ daddiu(AT, AT, -1 * Bytecodes::_invokestatic);
  2059     __ bne(AT, R0, L_done);
  2060     __ delayed()->nop();
  2062     // The member name argument must be restored if _invokestatic is re-executed after a PopFrame call.
  2063     // Detect such a case in the InterpreterRuntime function and return the member name argument, or NULL.
  2065     __ get_method(T9);
  2066     __ ld(T8, LVP, 0);
  2067     __ call_VM(T8, CAST_FROM_FN_PTR(address, InterpreterRuntime::member_name_arg_or_null), T8, T9, BCP);
  2069     __ beq(T8, R0, L_done);
  2070     __ delayed()->nop();
  2072     __ sd(T8, SP, 0);
  2073     __ bind(L_done);
  2075 #endif // INCLUDE_JVMTI
  2077   __ dispatch_next(vtos);
  2078   // end of PopFrame support
  2080   Interpreter::_remove_activation_entry = __ pc();
  2082   // preserve exception over this code sequence
  2083   __ ld(T0, SP, 0);
  2084   __ daddi(SP, SP, wordSize);
  2085 #ifndef OPT_THREAD
  2086   __ get_thread(thread);
  2087 #endif
  2088   __ sd(T0, thread, in_bytes(JavaThread::vm_result_offset()));
  2089   // remove the activation (without doing throws on illegalMonitorExceptions)
  2090   __ remove_activation(vtos, T3, false, true, false);
  2091   // restore exception
  2092   __ get_vm_result(T0, thread);
  2093   __ verify_oop(T0);
  2095   // In between activations - previous activation type unknown yet
  2096   // compute continuation point - the continuation point expects
  2097   // the following registers set up:
  2098   //
  2099   // T0: exception
  2100   // T1: return address/pc that threw exception
  2101   // SP: expression stack of caller
  2102   // FP: fp of caller
  2103   __ daddi(SP, SP, (-2) * wordSize);
  2104   __ sd(T0, SP, wordSize);      // save exception
  2105   __ sd(T3, SP, 0);                               // save return address
  2106   __ move(A1, T3);
  2107   __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address), thread, A1);
  2108   __ move(T9, V0);                             // save exception handler
  2109   __ ld(V0, SP, wordSize);        // restore exception
  2110   __ ld(V1, SP, 0);                               // restore return address
  2111   __ daddi(SP, SP, 2 * wordSize);
  2113   // Note that an "issuing PC" is actually the next PC after the call
  2114   __ jr(T9);                                   // jump to exception handler of caller
  2115   __ delayed()->nop();
  2119 //
  2120 // JVMTI ForceEarlyReturn support
  2121 //
  2122 address TemplateInterpreterGenerator::generate_earlyret_entry_for(TosState state) {
  2123   address entry = __ pc();
  2124   __ restore_bcp();
  2125   __ restore_locals();
  2126   __ empty_expression_stack();
  2127   __ empty_FPU_stack();
  2128   __ load_earlyret_value(state);
  2130 #ifndef OPT_THREAD
  2131   __ get_thread(TREG);
  2132 #endif
  2133   __ ld_ptr(T9, TREG, in_bytes(JavaThread::jvmti_thread_state_offset()));
  2134   const Address cond_addr(T9, in_bytes(JvmtiThreadState::earlyret_state_offset()));
  2135   // Clear the earlyret state
  2136   __ move(AT, JvmtiThreadState::earlyret_inactive);
  2137   __ sw(AT, cond_addr);
  2138   __ sync();
  2141   __ remove_activation(state, T0,
  2142                          false, /* throw_monitor_exception */
  2143                          false, /* install_monitor_exception */
  2144                          true); /* notify_jvmdi */
  2145   __ sync();
  2146   __ jr(T0);
  2147   __ delayed()->nop();
  2148   return entry;
  2149 } // end of ForceEarlyReturn support
  2152 //-----------------------------------------------------------------------------
  2153 // Helper for vtos entry point generation
  2155 void TemplateInterpreterGenerator::set_vtos_entry_points(Template* t,
  2156                                                          address& bep,
  2157                                                          address& cep,
  2158                                                          address& sep,
  2159                                                          address& aep,
  2160                                                          address& iep,
  2161                                                          address& lep,
  2162                                                          address& fep,
  2163                                                          address& dep,
  2164                                                          address& vep) {
  2165   assert(t->is_valid() && t->tos_in() == vtos, "illegal template");
  2166   Label L;
  2167   fep = __ pc(); __ push(ftos); __ b(L); __ delayed()->nop();
  2168   dep = __ pc(); __ push(dtos); __ b(L); __ delayed()->nop();
  2169   lep = __ pc(); __ push(ltos); __ b(L); __ delayed()->nop();
  2170   aep  =__ pc(); __ push(atos); __ b(L); __ delayed()->nop();
  2171   bep = cep = sep =
  2172   iep = __ pc(); __ push(itos);
  2173   vep = __ pc();
  2174   __ bind(L);
  2175   generate_and_dispatch(t);
  2179 //-----------------------------------------------------------------------------
  2180 // Generation of individual instructions
  2182 // helpers for generate_and_dispatch
  2185 InterpreterGenerator::InterpreterGenerator(StubQueue* code)
  2186   : TemplateInterpreterGenerator(code) {
  2187    generate_all(); // down here so it can be "virtual"
  2190 //-----------------------------------------------------------------------------
  2192 // Non-product code
  2193 #ifndef PRODUCT
  2194 address TemplateInterpreterGenerator::generate_trace_code(TosState state) {
  2195   address entry = __ pc();
  2197   // prepare expression stack
  2198   __ push(state);       // save tosca
  2200   // tos & tos2
  2201   // trace_bytecode need actually 4 args, the last two is tos&tos2
  2202   // this work fine for x86. but mips o32 call convention will store A2-A3
  2203   // to the stack position it think is the tos&tos2
  2204   // when the expression stack have no more than 2 data, error occur.
  2205   __ ld(A2, SP, 0);
  2206   __ ld(A3, SP, 1 * wordSize);
  2208   // pass arguments & call tracer
  2209   __ call_VM(noreg, CAST_FROM_FN_PTR(address, SharedRuntime::trace_bytecode), RA, A2, A3);
  2210   __ move(RA, V0);    // make sure return address is not destroyed by pop(state)
  2212   // restore expression stack
  2213   __ pop(state);        // restore tosca
  2215   // return
  2216   __ jr(RA);
  2217   __ delayed()->nop();
  2219   return entry;
  2222 void TemplateInterpreterGenerator::count_bytecode() {
  2223   __ li(T8, (long)&BytecodeCounter::_counter_value);
  2224   __ lw(AT, T8, 0);
  2225   __ daddi(AT, AT, 1);
  2226   __ sw(AT, T8, 0);
  2229 void TemplateInterpreterGenerator::histogram_bytecode(Template* t) {
  2230   __ li(T8, (long)&BytecodeHistogram::_counters[t->bytecode()]);
  2231   __ lw(AT, T8, 0);
  2232   __ daddi(AT, AT, 1);
  2233   __ sw(AT, T8, 0);
  2236 void TemplateInterpreterGenerator::histogram_bytecode_pair(Template* t) {
  2237   __ li(T8, (long)&BytecodePairHistogram::_index);
  2238   __ lw(T9, T8, 0);
  2239   __ dsrl(T9, T9, BytecodePairHistogram::log2_number_of_codes);
  2240   __ li(T8, ((long)t->bytecode()) << BytecodePairHistogram::log2_number_of_codes);
  2241   __ orr(T9, T9, T8);
  2242   __ li(T8, (long)&BytecodePairHistogram::_index);
  2243   __ sw(T9, T8, 0);
  2244   __ dsll(T9, T9, 2);
  2245   __ li(T8, (long)BytecodePairHistogram::_counters);
  2246   __ dadd(T8, T8, T9);
  2247   __ lw(AT, T8, 0);
  2248   __ daddi(AT, AT, 1);
  2249   __ sw(AT, T8, 0);
  2253 void TemplateInterpreterGenerator::trace_bytecode(Template* t) {
  2254   // Call a little run-time stub to avoid blow-up for each bytecode.
  2255   // The run-time runtime saves the right registers, depending on
  2256   // the tosca in-state for the given template.
  2258   address entry = Interpreter::trace_code(t->tos_in());
  2259   assert(entry != NULL, "entry must have been generated");
  2260   __ call(entry, relocInfo::none);
  2261   __ delayed()->nop();
  2262   //add for compressedoops
  2263   __ reinit_heapbase();
  2267 void TemplateInterpreterGenerator::stop_interpreter_at() {
  2268   Label L;
  2269   __ li(T8, long(&BytecodeCounter::_counter_value));
  2270   __ lw(T8, T8, 0);
  2271   __ move(AT, StopInterpreterAt);
  2272   __ bne(T8, AT, L);
  2273   __ delayed()->nop();
  2274   __ call(CAST_FROM_FN_PTR(address, os::breakpoint), relocInfo::runtime_call_type);
  2275   __ delayed()->nop();
  2276   __ bind(L);
  2278 #endif // !PRODUCT
  2279 #endif // ! CC_INTERP

mercurial