src/cpu/mips/vm/templateInterpreter_mips_64.cpp

Thu, 10 Nov 2016 10:14:33 +0800

author
fujie
date
Thu, 10 Nov 2016 10:14:33 +0800
changeset 189
60510c4e1f11
parent 33
52672a450193
child 407
16eef9733183
permissions
-rw-r--r--

[Interpreter] Remove redundant sync operations.

     1 /*
     2  * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * Copyright (c) 2015, 2016, Loongson Technology. All rights reserved.
     4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5  *
     6  * This code is free software; you can redistribute it and/or modify it
     7  * under the terms of the GNU General Public License version 2 only, as
     8  * published by the Free Software Foundation.
     9  *
    10  * This code is distributed in the hope that it will be useful, but WITHOUT
    11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    13  * version 2 for more details (a copy is included in the LICENSE file that
    14  * accompanied this code).
    15  *
    16  * You should have received a copy of the GNU General Public License version
    17  * 2 along with this work; if not, write to the Free Software Foundation,
    18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    19  *
    20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    21  * or visit www.oracle.com if you need additional information or have any
    22  * questions.
    23  *
    24  */
    26 #include "precompiled.hpp"
    27 #include "asm/macroAssembler.hpp"
    28 #include "interpreter/bytecodeHistogram.hpp"
    29 #include "interpreter/interpreter.hpp"
    30 #include "interpreter/interpreterGenerator.hpp"
    31 #include "interpreter/interpreterRuntime.hpp"
    32 #include "interpreter/templateTable.hpp"
    33 #include "oops/arrayOop.hpp"
    34 #include "oops/methodData.hpp"
    35 #include "oops/method.hpp"
    36 #include "oops/oop.inline.hpp"
    37 #include "prims/jvmtiExport.hpp"
    38 #include "prims/jvmtiThreadState.hpp"
    39 #include "runtime/arguments.hpp"
    40 #include "runtime/deoptimization.hpp"
    41 #include "runtime/frame.inline.hpp"
    42 #include "runtime/sharedRuntime.hpp"
    43 #include "runtime/stubRoutines.hpp"
    44 #include "runtime/synchronizer.hpp"
    45 #include "runtime/timer.hpp"
    46 #include "runtime/vframeArray.hpp"
    47 #include "utilities/debug.hpp"
    49 #define __ _masm->
    51 #ifndef CC_INTERP
    53 // asm based interpreter deoptimization helpers
    54 int AbstractInterpreter::size_activation(int max_stack,
    55                                          int temps,
    56                                          int extra_args,
    57                                          int monitors,
    58                                          int callee_params,
    59                                          int callee_locals,
    60                                          bool is_top_frame) {
    61   // Note: This calculation must exactly parallel the frame setup
    62   // in AbstractInterpreterGenerator::generate_method_entry.
    64   // fixed size of an interpreter frame:
    65   int overhead = frame::sender_sp_offset -
    66                  frame::interpreter_frame_initial_sp_offset;
    67   // Our locals were accounted for by the caller (or last_frame_adjust
    68   // on the transistion) Since the callee parameters already account
    69   // for the callee's params we only need to account for the extra
    70   // locals.
    71   int size = overhead +
    72          (callee_locals - callee_params)*Interpreter::stackElementWords +
    73          monitors * frame::interpreter_frame_monitor_size() +
    74          temps* Interpreter::stackElementWords + extra_args;
    76   return size;
    77 }
    80 const int Interpreter::return_sentinel = 0xfeedbeed;
    81 const int method_offset = frame::interpreter_frame_method_offset * wordSize;
    82 const int bci_offset    = frame::interpreter_frame_bcx_offset    * wordSize;
    83 const int locals_offset = frame::interpreter_frame_locals_offset * wordSize;
    85 //-----------------------------------------------------------------------------
    87 address TemplateInterpreterGenerator::generate_StackOverflowError_handler() {
    88   address entry = __ pc();
    90 #ifdef ASSERT
    91   {
    92     Label L;
    93 		__ addi(T1, FP, frame::interpreter_frame_monitor_block_top_offset * wordSize);
    94 		__ sub(T1, T1, SP); // T1 = maximal sp for current fp
    95 		__ bgez(T1, L);     // check if frame is complete
    96 		__ delayed()->nop();
    97 		__ stop("interpreter frame not set up");
    98 		__ bind(L);
    99   }
   100 #endif // ASSERT
   101   // Restore bcp under the assumption that the current frame is still
   102   // interpreted
   103 	// FIXME: please change the func restore_bcp
   104 	// S0 is the conventional register for bcp
   105   __ restore_bcp();
   107   // expression stack must be empty before entering the VM if an
   108   // exception happened
   109   __ empty_expression_stack();
   110   // throw exception
   111   //__ call_VM(noreg,
   112   //           CAST_FROM_FN_PTR(address,
   113   //                            InterpreterRuntime::throw_StackOverflowError));
   114 	// FIXME: why do not pass parameter thread ? 
   115 	__ call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_StackOverflowError));
   116   return entry;
   117 }
   119 address TemplateInterpreterGenerator::generate_ArrayIndexOutOfBounds_handler(
   120         const char* name) {
   121   address entry = __ pc();
   122   // expression stack must be empty before entering the VM if an
   123   // exception happened
   124   __ empty_expression_stack();
   125   __ li(A1, (long)name);
   126   __ call_VM(noreg, CAST_FROM_FN_PTR(address, 
   127 	InterpreterRuntime::throw_ArrayIndexOutOfBoundsException), A1, A2);
   128   return entry;
   129 }
   131 address TemplateInterpreterGenerator::generate_ClassCastException_handler() {
   132   address entry = __ pc();
   134   // object is at TOS
   135 //FIXME, I am not sure if the object is at TOS as x86 do now @jerome, 04/20,2007
   136   //__ pop(c_rarg1);
   138   // expression stack must be empty before entering the VM if an
   139   // exception happened
   140   __ empty_expression_stack();
   141   __ empty_FPU_stack();
   142   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_ClassCastException),  FSR);
   143   return entry;
   144 }
   146 address TemplateInterpreterGenerator::generate_exception_handler_common(
   147         const char* name, const char* message, bool pass_oop) {
   148 	assert(!pass_oop || message == NULL, "either oop or message but not both");
   149 	address entry = __ pc();
   151 	// expression stack must be empty before entering the VM if an exception happened
   152 	__ empty_expression_stack();
   153 	// setup parameters
   154 	__ li(A1, (long)name);
   155 	if (pass_oop) {
   156 		__ call_VM(V0, 
   157 		CAST_FROM_FN_PTR(address, InterpreterRuntime::create_klass_exception), A1, FSR);
   158 	} else {
   159 		__ li(A2, (long)message);
   160 		__ call_VM(V0, 
   161 		CAST_FROM_FN_PTR(address, InterpreterRuntime::create_exception), A1, A2);
   162 	}
   163 	// throw exception
   164 	__ jmp(Interpreter::throw_exception_entry(), relocInfo::none);
   165 	__ delayed()->nop();
   166 	return entry;
   167 }
   170 address TemplateInterpreterGenerator::generate_continuation_for(TosState state) {
   171   address entry = __ pc();
   172   // NULL last_sp until next java call
   173 	__ sd(R0,Address(FP, frame::interpreter_frame_last_sp_offset * wordSize)); 
   174 	__ dispatch_next(state);
   175   return entry;
   176 }
   179 address TemplateInterpreterGenerator::generate_return_entry_for(TosState state, int step, size_t index_size) {
   181   address entry = __ pc();
   183   // Restore stack bottom in case i2c adjusted stack
   184 //  __ movptr(rsp, Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize));
   185   __ ld(SP, Address(FP, frame::interpreter_frame_last_sp_offset * wordSize));
   186   // and NULL it as marker that esp is now tos until next java call
   187 //  __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
   188   __ sd(R0, FP, frame::interpreter_frame_last_sp_offset * wordSize);
   190   __ restore_bcp();
   191   __ restore_locals();
   193   // 2014/11/24 Fu
   194   // mdp: T8
   195   // ret: FSR 
   196   // tmp: T9
   197   if (state == atos) {
   198     Register mdp = T8;
   199     Register tmp = T9;
   200     __ profile_return_type(mdp, FSR, tmp);
   201   }
   204   const Register cache = T9;
   205   const Register index = T3;
   206   __ get_cache_and_index_at_bcp(cache, index, 1, index_size);
   208   const Register flags = cache;
   209 //  __ movl(flags, Address(cache, index, Address::times_ptr, ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::flags_offset()));
   210   __ dsll(AT, index, Address::times_ptr);
   211   __ daddu(AT, cache, AT);
   212   __ lw(flags, AT, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::flags_offset()));
   213 //  __ andl(flags, ConstantPoolCacheEntry::parameter_size_mask);
   214   __ andi(flags, flags, ConstantPoolCacheEntry::parameter_size_mask);
   215 //  __ lea(rsp, Address(rsp, flags, Interpreter::stackElementScale()));
   216   __ dsll(AT, flags, Interpreter::stackElementScale());
   217   __ daddu(SP, SP, AT);
   219   __ dispatch_next(state, step);
   221   return entry;
   222 }
   225 address TemplateInterpreterGenerator::generate_deopt_entry_for(TosState state,
   226                                                                int step) {
   227   address entry = __ pc();
   228   // NULL last_sp until next java call
   229   //__ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
   230   __ sd(R0, FP, frame::interpreter_frame_last_sp_offset * wordSize);
   231   __ restore_bcp();
   232   __ restore_locals();
   233   // handle exceptions
   234   {
   235     Label L;
   236 		const Register thread = TREG;
   237 #ifndef OPT_THREAD
   238 		__ get_thread(thread);
   239 #endif
   240 		__ lw(AT, thread, in_bytes(Thread::pending_exception_offset()));
   241 		__ beq(AT, R0, L);
   242 		__ delayed()->nop();
   243 		__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_pending_exception));
   244 		__ should_not_reach_here();
   245 		__ bind(L);
   246   }
   247   __ dispatch_next(state, step);
   248   return entry;
   249 }
   251 int AbstractInterpreter::BasicType_as_index(BasicType type) {
   252   int i = 0;
   253 /*
   254   switch (type) {
   255     case T_BOOLEAN: i = 0; break;
   256     case T_CHAR   : i = 1; break;
   257     case T_BYTE   : i = 2; break;
   258     case T_SHORT  : i = 3; break;
   259     case T_INT    : i = 4; break;
   260     case T_LONG   : i = 5; break;
   261     case T_VOID   : i = 6; break;
   262     case T_FLOAT  : i = 7; break;
   263     case T_DOUBLE : i = 8; break;
   264     case T_OBJECT : i = 9; break;
   265     case T_ARRAY  : i = 9; break;
   266     default       : ShouldNotReachHere();
   267   }
   268 */
   269 	switch (type) {
   270 		case T_BOOLEAN: i = 0; break;
   271 		case T_CHAR   : i = 1; break;
   272 		case T_BYTE   : i = 2; break;
   273 		case T_SHORT  : i = 3; break;
   274 		case T_INT    : // fall through
   275 		case T_LONG   : // fall through
   276 		case T_VOID   : i = 4; break;
   277 		case T_FLOAT  : i = 5; break;
   278 		case T_DOUBLE : i = 6; break;
   279 		case T_OBJECT : // fall through
   280 		case T_ARRAY  : i = 7; break;
   281 		default       : ShouldNotReachHere();
   282 	}
   283   assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers,
   284          "index out of bounds");
   285   return i;
   286 }
   289 // why do not consider float and double , @jerome, 12/27,06, @jerome
   290 //FIXME, aoqi
   291 address TemplateInterpreterGenerator::generate_result_handler_for(
   292         BasicType type) {
   293 	address entry = __ pc();
   294 	switch (type) {
   295 		case T_BOOLEAN: __ c2bool(V0);             break;
   296 		case T_CHAR   : __ andi(V0, V0, 0xFFFF);   break;
   297 		case T_BYTE   : __ sign_extend_byte (V0);  break;
   298 		case T_SHORT  : __ sign_extend_short(V0);  break;
   299 		case T_INT    : /* nothing to do */        break;
   300 		case T_FLOAT  : /* nothing to do */        break;
   301 		case T_DOUBLE : /* nothing to do */        break;
   302 		case T_OBJECT :
   303 		{
   304 		//	__ beq(V0, R0, L);       // test if NULL handle
   305 		//	__ delayed()->nop();       // if not then
   306 		//	__ lw(V0, V0, 0);          // unbox result
   307 	 		__ ld(V0, FP, frame::interpreter_frame_oop_temp_offset * wordSize);	
   308 			__ verify_oop(V0);         // and verify it
   309 		}
   310 							   break;
   311 		default       : ShouldNotReachHere();
   312 	}
   313 	__ jr(RA);                                  // return from result handler
   314 	__ delayed()->nop();
   315 	return entry;
   316 }
   318 address TemplateInterpreterGenerator::generate_safept_entry_for(
   319         TosState state,
   320         address runtime_entry) {
   321   address entry = __ pc();
   322   __ push(state);
   323   __ call_VM(noreg, runtime_entry);
   324   __ dispatch_via(vtos, Interpreter::_normal_table.table_for(vtos));
   325   return entry;
   326 }
   330 // Helpers for commoning out cases in the various type of method entries.
   331 //
   334 // increment invocation count & check for overflow
   335 //
   336 // Note: checking for negative value instead of overflow
   337 //       so we have a 'sticky' overflow test
   338 //
   339 // prerequisites : method in T0, invocation counter in T3
   340 void InterpreterGenerator::generate_counter_incr(
   341         Label* overflow,
   342         Label* profile_method,
   343 	Label* profile_method_continue) {
   344   Label done;
   345   const Address invocation_counter(FSR, in_bytes(MethodCounters::invocation_counter_offset())  //Fu:20130814  Wang:Rmethod --> FSR
   346       + in_bytes(InvocationCounter::counter_offset()));
   347   const Address backedge_counter  (FSR, in_bytes(MethodCounters::backedge_counter_offset()) 
   348       + in_bytes(InvocationCounter::counter_offset()));
   350   __ get_method_counters(Rmethod, FSR, done);
   352   if (ProfileInterpreter) { // %%% Merge this into methodDataOop
   353     __ lw(T9, FSR, in_bytes(MethodCounters::interpreter_invocation_counter_offset()));
   354     __ incrementl(T9, 1);
   355     __ sw(T9, FSR, in_bytes(MethodCounters::interpreter_invocation_counter_offset()));
   356   }
   357   // Update standard invocation counters
   358   __ lw(T3, invocation_counter);
   359   __ increment(T3, InvocationCounter::count_increment);
   360   __ sw(T3, invocation_counter);  // save invocation count
   362   __ lw(FSR, backedge_counter);  // load backedge counter
   363   __ li(AT, InvocationCounter::count_mask_value);   // mask out the status bits
   364   __ andr(FSR, FSR, AT);
   366   __ dadd(T3, T3, FSR);          // add both counters
   368   // profile_method is non-null only for interpreted method so
   369   // profile_method != NULL == !native_call
   371   if (ProfileInterpreter && profile_method != NULL) {
   372     // Test to see if we should create a method data oop
   373     /*
   374        __ lui(AT, Assembler::split_high(
   375        int(&InvocationCounter::InterpreterProfileLimit)));
   376        __ ld(AT, AT, Assembler::split_low(
   377        int(&InvocationCounter::InterpreterProfileLimit)));
   378      */
   379     __ li(AT, (long)&InvocationCounter::InterpreterProfileLimit);
   380     __ lw(AT, AT, 0);
   381     __ slt(AT, T3, AT);
   382     __ bne_far(AT, R0, *profile_method_continue);
   383     __ delayed()->nop();
   385     // if no method data exists, go to profile_method
   386     __ test_method_data_pointer(FSR, *profile_method);
   387   }
   389   //__ lui(AT, Assembler::split_high(intptr_t(&InvocationCounter::InterpreterInvocationLimit)));
   390   //__ ld(AT, AT, Assembler::split_low(intptr_t(&InvocationCounter::InterpreterInvocationLimit)));
   391   __ li(AT, (long)&InvocationCounter::InterpreterInvocationLimit);
   392   __ lw(AT, AT, 0);
   393   __ slt(AT, T3, AT);
   394   __ beq_far(AT, R0, *overflow);
   395   __ delayed()->nop();
   396   __ bind(done);
   397 }
   399 void InterpreterGenerator::generate_counter_overflow(Label* do_continue) {
   401 	// Asm interpreter on entry
   402 	// S7 - locals
   403 	// S0 - bcp
   404 	// Rmethod - method
   405 	// FP - interpreter frame
   407 	// On return (i.e. jump to entry_point)
   408 	// Rmethod - method
   409 	// RA - return address of interpreter caller
   410 	// tos - the last parameter to Java method 
   411 	// SP - sender_sp
   413 	//const Address size_of_parameters(Rmethod,in_bytes( Method::size_of_parameters_offset()));
   415 	// the bcp is valid if and only if it's not null
   416 	__ call_VM(NOREG, CAST_FROM_FN_PTR(address, 
   417 		  InterpreterRuntime::frequency_counter_overflow), R0);
   418 	__ ld(Rmethod, FP, method_offset);
   419 /*
   420   // method has been compiled - remove activation frame
   421   // (leave return address on stack) and continue at
   422   // verified entry point (eax). (eax in some past life maybe, seems to use methodoop these days)
   423   //
   424   // Note: continuation at verified entry point works if the method that has been
   425   //       compiled is the right one (in case of virtual calls); i.e., the inline
   426   //       cache check must have happened before the invocation counter overflow
   427   //       check.
   428 	__ lhu(V0, size_of_parameters);
   429 	__ move(SP, FP);
   430 	__ lw(FP, SP, frame::interpreter_frame_sender_fp_offset * wordSize);
   431 	__ lw(RA, SP, frame::interpreter_frame_return_addr_offset * wordSize);
   432 	__ sll(V0, V0, 2);
   433 	__ addi(V0, V0, - 1 * wordSize);
   434 	__ sub(SP, LVP, V0);
   435 //	__ lw(T0, LVP, 0);
   436 */
   437   // Preserve invariant that esi/edi contain bcp/locals of sender frame  
   438 	__ b_far(*do_continue);
   439 	__ delayed()->nop();
   440 }
   442 // See if we've got enough room on the stack for locals plus overhead.
   443 // The expression stack grows down incrementally, so the normal guard
   444 // page mechanism will work for that.
   445 //
   446 // NOTE: Since the additional locals are also always pushed (wasn't
   447 // obvious in generate_method_entry) so the guard should work for them
   448 // too.
   449 //
   450 // Args:
   451 //      rdx: number of additional locals this frame needs (what we must check)
   452 //      rbx: Method*
   453 //
   454 // Kills:
   455 //      rax
   456 void InterpreterGenerator::generate_stack_overflow_check(void) {
   457   // see if we've got enough room on the stack for locals plus overhead.
   458   // the expression stack grows down incrementally, so the normal guard
   459   // page mechanism will work for that.
   460   //
   461   // Registers live on entry:
   462   //
   463   // T0: Method*
   464   // T2: number of additional locals this frame needs (what we must check)
   466   // NOTE:  since the additional locals are also always pushed (wasn't obvious in
   467   // generate_method_entry) so the guard should work for them too. 
   468   //
   470   // monitor entry size: see picture of stack set (generate_method_entry) and frame_i486.hpp
   471   const int entry_size    = frame::interpreter_frame_monitor_size() * wordSize;
   473   // total overhead size: entry_size + (saved ebp thru expr stack bottom).
   474   // be sure to change this if you add/subtract anything to/from the overhead area
   475   const int overhead_size = -(frame::interpreter_frame_initial_sp_offset*wordSize) 
   476     + entry_size;
   478   const int page_size = os::vm_page_size();
   480   Label after_frame_check;
   482   // see if the frame is greater than one page in size. If so,
   483   // then we need to verify there is enough stack space remaining
   484   // for the additional locals.
   485   __ move(AT, (page_size - overhead_size) / Interpreter::stackElementSize);
   486   __ slt(AT, AT, T2);
   487   __ beq(AT, R0, after_frame_check);
   488   __ delayed()->nop();
   490   // compute sp as if this were going to be the last frame on
   491   // the stack before the red zone
   492 #ifndef OPT_THREAD
   493   Register thread = T1;
   494   __ get_thread(thread);
   495 #else
   496   Register thread = TREG;
   497 #endif
   499   // locals + overhead, in bytes
   500   //FIXME aoqi
   501   __ dsll(T3, T2, Interpreter::stackElementScale());  
   502   //__ dsll(T9, T9, Address::times_8);
   503   __ daddiu(T3, T3, overhead_size); 	// locals * 4 + overhead_size --> T3
   505 #ifdef ASSERT
   506   Label stack_base_okay, stack_size_okay;
   507   // verify that thread stack base is non-zero
   508   __ ld(AT, thread, in_bytes(Thread::stack_base_offset()));
   509   __ bne(AT, R0, stack_base_okay);
   510   __ delayed()->nop();
   511   __ stop("stack base is zero");
   512   __ bind(stack_base_okay);
   513   // verify that thread stack size is non-zero
   514   __ ld(AT, thread, in_bytes(Thread::stack_size_offset()));
   515   __ bne(AT, R0, stack_size_okay);
   516   __ delayed()->nop();
   517   __ stop("stack size is zero");
   518   __ bind(stack_size_okay);
   519 #endif
   521   // Add stack base to locals and subtract stack size
   522   __ ld(AT, thread, in_bytes(Thread::stack_base_offset())); // stack_base --> AT
   523   __ dadd(T3, T3, AT); 	// locals * 4 + overhead_size + stack_base--> T3
   524   __ ld(AT, thread, in_bytes(Thread::stack_size_offset()));  // stack_size --> AT
   525   __ dsub(T3, T3, AT);	// locals * 4 + overhead_size + stack_base - stack_size --> T3
   528   // add in the redzone and yellow size
   529   __ move(AT, (StackRedPages+StackYellowPages) * page_size);
   530   __ add(T3, T3, AT);
   532   // check against the current stack bottom
   533   __ slt(AT, T3, SP);
   534   __ bne(AT, R0, after_frame_check);
   535   __ delayed()->nop();
   536   // x86 version pop saved bcp and return address here, FIXME
   537   __ jmp(Interpreter::throw_StackOverflowError_entry(), relocInfo::runtime_call_type);
   538   __ delayed()->nop();
   540   // all done with frame size check
   541   __ bind(after_frame_check);
   542 }
   544 // Allocate monitor and lock method (asm interpreter)
   545 // Rmethod - Method*
   546 void InterpreterGenerator::lock_method(void) {
   547   // synchronize method
   548   const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
   550 #ifdef ASSERT
   551   { Label L;
   552     __ lw(T0, Rmethod, in_bytes(Method::access_flags_offset()));
   553     __ andi(T0, T0, JVM_ACC_SYNCHRONIZED);
   554     __ bne(T0, R0, L);
   555     __ delayed()->nop();
   556     __ stop("method doesn't need synchronization");
   557     __ bind(L);
   558   }
   559 #endif // ASSERT
   560   // get synchronization object
   561   { Label done;
   562     const int mirror_offset = in_bytes(Klass::java_mirror_offset());
   563     __ lw(T0, Rmethod, in_bytes(Method::access_flags_offset()));
   564     __ andi(T2, T0, JVM_ACC_STATIC);
   565     __ ld(T0, LVP, Interpreter::local_offset_in_bytes(0));         
   566     __ beq(T2, R0, done);
   567     __ delayed()->nop();
   568     __ ld(T0, Rmethod, in_bytes(Method::const_offset()));
   569     __ ld(T0, T0, in_bytes(ConstMethod::constants_offset()));
   570     __ ld(T0, T0, ConstantPool::pool_holder_offset_in_bytes());
   571     __ ld(T0, T0, mirror_offset);
   572     __ bind(done);
   573   }
   574   // add space for monitor & lock
   575   __ daddi(SP, SP, (-1) * entry_size);           // add space for a monitor entry
   576   __ sd(SP, FP, frame::interpreter_frame_monitor_block_top_offset * wordSize);
   577   // set new monitor block top
   578   __ sd(T0, SP, BasicObjectLock::obj_offset_in_bytes());   // store object
   579   // FIXME: I do not know what lock_object will do and what it will need
   580   __ move(c_rarg0, SP);      // object address
   581   __ lock_object(c_rarg0);          
   582 }
   584 // Generate a fixed interpreter frame. This is identical setup for
   585 // interpreted methods and for native methods hence the shared code.
   586 void TemplateInterpreterGenerator::generate_fixed_frame(bool native_call) {
   588   // [ local var m-1      ] <--- sp
   589   //   ...
   590   // [ local var 0        ]				
   591   // [ argumnet word n-1  ] <--- T0(sender's sp)
   592   //   ...
   593   // [ argument word 0    ] <--- S7
   595   // initialize fixed part of activation frame
   596   // sender's sp in Rsender
   597   int i = 0;
   598   __ sd(RA, SP, (-1) * wordSize); 	// save return address
   599   __ sd(FP, SP, (-2) * wordSize);	// save sender's fp
   600   __ daddiu(FP, SP, (-2) * wordSize);
   601   __ sd(Rsender, FP, (-++i) * wordSize);	// save sender's sp
   602   __ sd(R0, FP,(-++i)*wordSize);       //save last_sp as null, FIXME aoqi 
   603   __ sd(LVP, FP, (-++i) * wordSize);	// save locals offset
   604   __ ld(BCP, Rmethod, in_bytes(Method::const_offset())); // get constMethodOop
   605   __ daddiu(BCP, BCP, in_bytes(ConstMethod::codes_offset())); // get codebase
   606   __ sd(Rmethod, FP, (-++i) * wordSize);                              // save Method*
   607 #ifndef CORE
   608   if (ProfileInterpreter) {
   609     Label method_data_continue;
   610     __ ld(AT, Rmethod,  in_bytes(Method::method_data_offset())); 
   611     __ beq(AT, R0, method_data_continue); 
   612     __ delayed()->nop(); 
   613     __ daddi(AT, AT, in_bytes(MethodData::data_offset()));  
   614     __ bind(method_data_continue);
   615     __ sd(AT, FP,  (-++i) * wordSize);
   616   } else {
   617     __ sd(R0, FP, (-++i) * wordSize);
   618   }
   619 #endif // !CORE
   621   __ ld(T2, Rmethod, in_bytes(Method::const_offset()));
   622   __ ld(T2, T2, in_bytes(ConstMethod::constants_offset()));
   623   __ ld(T2, T2, ConstantPool::cache_offset_in_bytes());
   624   __ sd(T2, FP, (-++i) * wordSize);                    // set constant pool cache
   625   if (native_call) {
   626     __ sd(R0, FP, (-++i) * wordSize);					// no bcp
   627   } else {
   628     __ sd(BCP, FP, (-++i) * wordSize);					// set bcp
   629   }
   630   __ daddiu(SP, FP, (-++i) * wordSize);
   631   __ sd(SP, FP, (-i) * wordSize);               // reserve word for pointer to expression stack bottom	
   632 }
   634 // End of helpers
   636 // Various method entries
   637 //------------------------------------------------------------------------------------------------------------------------
   638 //
   639 //
   641 // Call an accessor method (assuming it is resolved, otherwise drop
   642 // into vanilla (slow path) entry
   643 address InterpreterGenerator::generate_accessor_entry(void) {
   645   // Rmethod: Method*
   646   // V0: receiver (preserve for slow entry into asm interpreter)
   647   //  Rsender: senderSP must preserved for slow path, set SP to it on fast path
   649   address entry_point = __ pc();
   650   Label xreturn_path;
   651   // do fastpath for resolved accessor methods
   652   if (UseFastAccessorMethods) {
   653     Label slow_path;
   654     __ li(T2, SafepointSynchronize::address_of_state()); 
   655     __ lw(AT, T2, 0);
   656     __ daddi(AT, AT, -(SafepointSynchronize::_not_synchronized));
   657     __ bne(AT, R0, slow_path); 
   658     __ delayed()->nop();	
   659     // Code: _aload_0, _(i|a)getfield, _(i|a)return or any rewrites thereof; 
   660     // parameter size = 1
   661     // Note: We can only use this code if the getfield has been resolved
   662     //       and if we don't have a null-pointer exception => check for
   663     //       these conditions first and use slow path if necessary.
   664     // Rmethod: method
   665     // V0: receiver
   667     // [ receiver  ] <-- sp
   668     __ ld(T0, SP, 0);
   670     // check if local 0 != NULL and read field
   671     __ beq(T0, R0, slow_path);
   672     __ delayed()->nop();
   673     __ ld(T2, Rmethod, in_bytes(Method::const_offset()));
   674 //    __ movptr(rdi, Address(rdx, ConstMethod::constants_offset()));
   675     __ ld(T2, T2, in_bytes(ConstMethod::constants_offset()));
   676     // read first instruction word and extract bytecode @ 1 and index @ 2
   677     __ ld(T3, Rmethod, in_bytes(Method::const_offset()));
   678     __ lw(T3, T3, in_bytes(ConstMethod::codes_offset()));
   679     // Shift codes right to get the index on the right.
   680     // The bytecode fetched looks like <index><0xb4><0x2a>
   681     __ dsrl(T3, T3, 2 * BitsPerByte);
   682     // FIXME: maybe it's wrong
   683     __ dsll(T3, T3, exact_log2(in_words(ConstantPoolCacheEntry::size())));
   684     __ ld(T2, T2, ConstantPool::cache_offset_in_bytes());
   686     // T0: local 0 eax
   687     // Rmethod: method ebx
   688     // V0: receiver - do not destroy since it is needed for slow path! ecx
   689     // ecx: scratch use which register instead ?     
   690     // T1: scratch use which register instead ?     
   691     // T3: constant pool cache index	edx
   692     // T2: constant pool cache	edi
   693     // esi: send's sp
   694     // Rsender: send's sp
   695     // check if getfield has been resolved and read constant pool cache entry
   696     // check the validity of the cache entry by testing whether _indices field
   697     // contains Bytecode::_getfield in b1 byte.
   698     assert(in_words(ConstantPoolCacheEntry::size()) == 4, "adjust shift below");
   699     //    __ movl(esi, 
   700     //	    Address(edi, 
   701     //		    edx, 
   702     //		    Address::times_4, ConstantPoolCache::base_offset() 
   703     //		    + ConstantPoolCacheEntry::indices_offset()));
   706     __ dsll(T8, T3, Address::times_8);
   707     __ move(T1, in_bytes(ConstantPoolCache::base_offset() 
   708 	  + ConstantPoolCacheEntry::indices_offset()));
   709     __ dadd(T1, T8, T1);
   710     __ dadd(T1, T1, T2);
   711     __ lw(T1, T1, 0);
   712     __ dsrl(T1, T1, 2 * BitsPerByte);
   713     __ andi(T1, T1, 0xFF);
   714     __ daddi(T1, T1, (-1) * Bytecodes::_getfield);
   715     __ bne(T1, R0, slow_path);
   716     __ delayed()->nop();
   718     //    __ shrl(esi, 2*BitsPerByte);
   719     //    __ andl(esi, 0xFF);
   720     //    __ cmpl(esi, Bytecodes::_getfield);
   721     //    __ jcc(Assembler::notEqual, slow_path);
   723     // Note: constant pool entry is not valid before bytecode is resolved
   725     //    __ movl(esi, 
   726     //	    Address(edi, 
   727     //		    edx, 
   728     //		    Address::times_4, ConstantPoolCache::base_offset() 
   729     //		    + ConstantPoolCacheEntry::f2_offset()));
   730     __ move(T1, in_bytes(ConstantPoolCache::base_offset() 
   731 	  + ConstantPoolCacheEntry::f2_offset()));
   732     __ dadd(T1, T1, T8);
   733     __ dadd(T1, T1, T2);
   734     __ lw(AT, T1, 0);
   735     //    __ movl(edx, 
   736     //	    Address(edi, 
   737     //		    edx, 
   738     //		    Address::times_4, ConstantPoolCache::base_offset() 
   739     //		    + ConstantPoolCacheEntry::flags_offset()));
   742     __ move(T1, in_bytes(ConstantPoolCache::base_offset() 
   743 	  + ConstantPoolCacheEntry::flags_offset()));
   744     __ dadd(T1, T1, T8);
   745     __ dadd(T1, T1, T2);
   746     __ lw(T3, T1, 0);
   748     Label notByte, notShort, notChar, notObj;
   749     //    const Address field_address (eax, esi, Address::times_1);
   751     // Need to differentiate between igetfield, agetfield, bgetfield etc.
   752     // because they are different sizes.
   753     // Use the type from the constant pool cache
   754     __ dsrl(T3, T3, ConstantPoolCacheEntry::tos_state_shift);
   755     // Make sure we don't need to mask edx for tosBits after the above shift
   756     ConstantPoolCacheEntry::verify_tos_state_shift();
   757     // btos = 0
   758     __ bne(T3, R0, notByte);
   759     __ delayed()->dadd(T0, T0, AT);
   761     __ lb(V0, T0, 0);
   762     __ b(xreturn_path);
   763     __ delayed()->nop();
   765     //stos
   766     __ bind(notByte);
   767     __ daddi(T1, T3, (-1) * stos);
   768     __ bne(T1, R0, notShort);
   769     __ delayed()->nop();
   770     __ lh(V0, T0, 0);
   771     __ b(xreturn_path);
   772     __ delayed()->nop();
   774     //ctos
   775     __ bind(notShort);
   776     __ daddi(T1, T3, (-1) * ctos);
   777     __ bne(T1, R0, notChar);
   778     __ delayed()->nop();
   779     __ lhu(V0, T0, 0);
   780     __ b(xreturn_path);
   781     __ delayed()->nop();
   783     //atos
   784     __ bind(notChar);
   785     __ daddi(T1, T3, (-1) * atos);
   786     __ bne(T1, R0, notObj);
   787     __ delayed()->nop();
   788     //add for compressedoops
   789     __ load_heap_oop(V0, Address(T0, 0));
   790     __ b(xreturn_path);
   791     __ delayed()->nop();
   793     //itos
   794     __ bind(notObj);
   795 #ifdef ASSERT
   796     Label okay;
   797     __ daddi(T1, T3, (-1) * itos);
   798     __ beq(T1, R0, okay);
   799     __ delayed()->nop();
   800     __ stop("what type is this?");
   801     __ bind(okay);
   802 #endif // ASSERT
   803     __ lw(V0, T0, 0);
   805     __ bind(xreturn_path);
   807     // _ireturn/_areturn
   808     //FIXME 
   809     __ move(SP, Rsender);//FIXME, set sender's fp to SP	
   810     __ jr(RA);
   811     __ delayed()->nop();
   813     // generate a vanilla interpreter entry as the slow path
   814     __ bind(slow_path);
   815     (void) generate_normal_entry(false);
   816   } else {
   817     (void) generate_normal_entry(false);
   818   }
   820   return entry_point;
   821 }
   823 // Method entry for java.lang.ref.Reference.get.
   824 address InterpreterGenerator::generate_Reference_get_entry(void) {
   825 #ifndef SERIALGC
   826   // Code: _aload_0, _getfield, _areturn
   827   // parameter size = 1
   828   //
   829   // The code that gets generated by this routine is split into 2 parts:
   830   //    1. The "intrinsified" code for G1 (or any SATB based GC),
   831   //    2. The slow path - which is an expansion of the regular method entry.
   832   //
   833   // Notes:-
   834   // * In the G1 code we do not check whether we need to block for
   835   //   a safepoint. If G1 is enabled then we must execute the specialized
   836   //   code for Reference.get (except when the Reference object is null)
   837   //   so that we can log the value in the referent field with an SATB
   838   //   update buffer.
   839   //   If the code for the getfield template is modified so that the
   840   //   G1 pre-barrier code is executed when the current method is
   841   //   Reference.get() then going through the normal method entry
   842   //   will be fine.
   843   // * The G1 code can, however, check the receiver object (the instance
   844   //   of java.lang.Reference) and jump to the slow path if null. If the
   845   //   Reference object is null then we obviously cannot fetch the referent
   846   //   and so we don't need to call the G1 pre-barrier. Thus we can use the
   847   //   regular method entry code to generate the NPE.
   848   //
   849   // This code is based on generate_accessor_enty.
   850   //
   851   // rbx: Method*
   853   // r13: senderSP must preserve for slow path, set SP to it on fast path
   855   address entry = __ pc();
   857   const int referent_offset = java_lang_ref_Reference::referent_offset;
   858   guarantee(referent_offset > 0, "referent offset not initialized");
   860   if (UseG1GC) {
   861     Label slow_path;
   862     // rbx: method
   864     // Check if local 0 != NULL
   865     // If the receiver is null then it is OK to jump to the slow path.
   866   /*  __ movptr(rax, Address(rsp, wordSize));
   868     __ testptr(rax, rax);
   869     __ jcc(Assembler::zero, slow_path);*/
   871     // rax: local 0
   872     // rbx: method (but can be used as scratch now)
   873     // rdx: scratch
   874     // rdi: scratch
   876     // Generate the G1 pre-barrier code to log the value of
   877     // the referent field in an SATB buffer.
   879     // Load the value of the referent field.
   880     //const Address field_address(rax, referent_offset);
   881 //    __ load_heap_oop(rax, field_address);
   883     // Generate the G1 pre-barrier code to log the value of
   884     // the referent field in an SATB buffer.
   885 //    __ g1_write_barrier_pre(noreg /* obj */,
   886 //                            rax /* pre_val */,
   887 //                            r15_thread /* thread */,
   888 //                            rbx /* tmp */,
   889  //                           true /* tosca_live */,
   890  //                           true /* expand_call */);
   892     // _areturn
   893  /*   __ pop(rdi);                // get return address
   894     __ mov(rsp, r13);           // set sp to sender sp
   895     __ jmp(rdi);
   896     __ ret(0);
   898     // generate a vanilla interpreter entry as the slow path
   899     __ bind(slow_path);
   900     (void) generate_normal_entry(false);
   901 */
   902     return entry;
   903   }
   904 #endif // SERIALGC
   906   // If G1 is not enabled then attempt to go through the accessor entry point
   907   // Reference.get is an accessor
   908   return generate_accessor_entry();
   909 }
   910 // Interpreter stub for calling a native method. (asm interpreter)
   911 // This sets up a somewhat different looking stack for calling the
   912 // native method than the typical interpreter frame setup.
   913 address InterpreterGenerator::generate_native_entry(bool synchronized) {
   914   // determine code generation flags
   915   bool inc_counter  = UseCompiler || CountCompiledCalls;
   916   // Rsender: sender's sp
   917   // Rmethod: Method*
   918   address entry_point = __ pc();
   920 #ifndef CORE
   921   const Address invocation_counter(Rmethod,in_bytes(MethodCounters::invocation_counter_offset() +   // Fu: 20130814
   922 	InvocationCounter::counter_offset()));
   923 #endif
   925   // get parameter size (always needed)
   926   // the size in the java stack
   927   //__ lhu(V0, Rmethod, in_bytes(Method::size_of_parameters_offset()));
   928   __ ld(V0, Rmethod, in_bytes(Method::const_offset()));    
   929   __ lhu(V0, V0, in_bytes(ConstMethod::size_of_parameters_offset()));   // Fu: 20130814
   931   // native calls don't need the stack size check since they have no expression stack
   932   // and the arguments are already on the stack and we only add a handful of words
   933   // to the stack 
   935   // Rmethod: Method*
   936   // V0: size of parameters
   937   // Layout of frame at this point
   938   //
   939   // [ argument word n-1  ] <--- sp
   940   //   ...
   941   // [ argument word 0    ]
   943   // for natives the size of locals is zero
   945   // compute beginning of parameters (S7)
   946   __ dsll(LVP, V0, Address::times_8);
   947   __ daddiu(LVP, LVP, (-1) * wordSize);
   948   __ dadd(LVP, LVP, SP);
   950   //__ move(T0, SP);               // remember sender sp for generate_fixed_frame
   953   // add 2 zero-initialized slots for native calls
   954   __ daddi(SP, SP, (-2) * wordSize);
   955   __ sd(R0, SP, 1 * wordSize);	// slot for native oop temp offset (setup via runtime)
   956   __ sd(R0, SP, 0 * wordSize);	// slot for static native result handler3 (setup via runtime)
   958   // Layout of frame at this point
   959   // [ method holder mirror	] <--- sp
   960   // [ result type info			] 
   961   // [ argument word n-1   	] <--- T0
   962   //   ...
   963   // [ argument word 0    	] <--- LVP
   966 #ifndef CORE
   967   if (inc_counter) __ lw(T3, invocation_counter);  // (pre-)fetch invocation count
   968 #endif
   970   // initialize fixed part of activation frame
   971   generate_fixed_frame(true);
   972   // after this function, the layout of frame is as following
   973   //
   974   // [ monitor block top        ] <--- sp ( the top monitor entry )
   975   // [ byte code pointer (0)    ] (if native, bcp = 0)
   976   // [ constant pool cache      ]
   977   // [ Method*                ]
   978   // [ locals offset            ]
   979   // [ sender's sp              ]
   980   // [ sender's fp              ]
   981   // [ return address           ] <--- fp
   982   // [ method holder mirror     ]
   983   // [ result type info         ]
   984   // [ argumnet word n-1        ] <--- sender's sp 
   985   //	 ...
   986   // [ argument word 0          ] <--- S7
   989   // make sure method is native & not abstract
   990 #ifdef ASSERT
   991   __ lw(T0, Rmethod, in_bytes(Method::access_flags_offset()));
   992   {
   993     Label L;
   994     __ andi(AT, T0, JVM_ACC_NATIVE);
   995     __ bne(AT, R0, L);
   996     __ delayed()->nop();
   997     __ stop("tried to execute native method as non-native");
   998     __ bind(L);
   999   }
  1000   { Label L;
  1001     __ andi(AT, T0, JVM_ACC_ABSTRACT);
  1002     __ beq(AT, R0, L);
  1003     __ delayed()->nop();
  1004     __ stop("tried to execute abstract method in interpreter");
  1005     __ bind(L);
  1007 #endif
  1009   // Since at this point in the method invocation the exception handler
  1010   // would try to exit the monitor of synchronized methods which hasn't
  1011   // been entered yet, we set the thread local variable
  1012   // _do_not_unlock_if_synchronized to true. The remove_activation will
  1013   // check this flag.
  1014   Register thread = TREG;
  1015 #ifndef OPT_THREAD
  1016   __ get_thread(thread);
  1017 #endif
  1018   __ move(AT, (int)true);
  1019   __ sb(AT, thread, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
  1021 #ifndef CORE
  1022   // increment invocation count & check for overflow
  1023   Label invocation_counter_overflow;
  1024   if (inc_counter) {
  1025     generate_counter_incr(&invocation_counter_overflow, NULL, NULL);
  1027   Label continue_after_compile;
  1028   __ bind(continue_after_compile);
  1029 #endif // CORE
  1031   bang_stack_shadow_pages(true);
  1033   // reset the _do_not_unlock_if_synchronized flag
  1034 #ifndef OPT_THREAD
  1035   __ get_thread(thread);
  1036 #endif
  1037   __ sb(R0, thread, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
  1039   // check for synchronized methods
  1040   // Must happen AFTER invocation_counter check and stack overflow check,
  1041   // so method is not locked if overflows.
  1042   if (synchronized) {
  1043     lock_method();
  1044   } else {
  1045     // no synchronization necessary
  1046 #ifdef ASSERT
  1048       Label L;
  1049       __ lw(T0, Rmethod, in_bytes(Method::access_flags_offset()));
  1050       __ andi(AT, T0, JVM_ACC_SYNCHRONIZED);
  1051       __ beq(AT, R0, L);
  1052       __ delayed()->nop();
  1053       __ stop("method needs synchronization");
  1054       __ bind(L);
  1056 #endif
  1059   // after method_lock, the layout of frame is as following
  1060   //
  1061   // [ monitor entry            ] <--- sp
  1062   //   ...
  1063   // [ monitor entry            ]
  1064   // [ monitor block top        ] ( the top monitor entry ) 
  1065   // [ byte code pointer (0)    ] (if native, bcp = 0)
  1066   // [ constant pool cache      ]
  1067   // [ Method*                ]
  1068   // [ locals offset	      ]
  1069   // [ sender's sp              ]
  1070   // [ sender's fp              ]
  1071   // [ return address           ] <--- fp
  1072   // [ method holder mirror     ]
  1073   // [ result type info         ]
  1074   // [ argumnet word n-1        ] <--- ( sender's sp )
  1075   //	 ...
  1076   // [ argument word 0          ] <--- S7
  1078   // start execution
  1079 #ifdef ASSERT
  1080   { Label L;
  1081     __ ld(AT, FP, frame::interpreter_frame_monitor_block_top_offset * wordSize);
  1082     __ beq(AT, SP, L);
  1083     __ delayed()->nop();
  1084     __ stop("broken stack frame setup in interpreter in asm");
  1085     __ bind(L);
  1087 #endif
  1089   // jvmti/jvmpi support
  1090   __ notify_method_entry();
  1092   // work registers
  1093   const Register method = Rmethod;
  1094   //const Register thread = T2;
  1095   const Register t      = RT4;    
  1097   __ get_method(method);
  1098   __ verify_oop(method);
  1099   { Label L, Lstatic;
  1100     __ ld(t,method,in_bytes(Method::const_offset()));  
  1101     __ lhu(t, t, in_bytes(ConstMethod::size_of_parameters_offset()));  // Fu: 20130814
  1102 	{//aoqi_test
  1103 	Label L;
  1104 	__ daddi(AT, t, -8);
  1105 	__ blez(AT, L);
  1106 	__ delayed()->nop();
  1107 	__ bind(L);
  1109     // MIPS n64 ABI: caller does not reserve space for the register auguments.
  1110     //FIXME, aoqi: A1?
  1111     // A0 and A1(if needed)
  1112     __ lw(AT, Rmethod, in_bytes(Method::access_flags_offset()));
  1113     __ andi(AT, AT, JVM_ACC_STATIC);
  1114     __ beq(AT, R0, Lstatic);
  1115     __ delayed()->nop();
  1116     __ daddiu(t, t, 1);
  1117     __ bind(Lstatic);
  1118     __ daddiu(t, t, -7);
  1119     __ blez(t, L);
  1120     __ delayed()->nop();
  1121     __ dsll(t, t, Address::times_8);
  1122     __ dsub(SP, SP, t);
  1123     __ bind(L);
  1125   __ move(AT, -(StackAlignmentInBytes));
  1126   __ andr(SP, SP, AT);	
  1127   __ move(AT, SP);
  1128   // [				] <--- sp
  1129   //   ...                        (size of parameters - 8 )
  1130   // [ monitor entry            ] 
  1131   //   ...
  1132   // [ monitor entry            ]
  1133   // [ monitor block top        ] ( the top monitor entry ) 
  1134   // [ byte code pointer (0)    ] (if native, bcp = 0)
  1135   // [ constant pool cache      ]
  1136   // [ Method*                ]
  1137   // [ locals offset            ]
  1138   // [ sender's sp              ]
  1139   // [ sender's fp              ]
  1140   // [ return address           ] <--- fp
  1141   // [ method holder mirror     ]
  1142   // [ result type info         ]
  1143   // [ argumnet word n-1        ] <--- ( sender's sp )
  1144   //	 ...
  1145   // [ argument word 0          ] <--- LVP
  1147   // get signature handler
  1149     Label L;
  1150     __ ld(T9, method, in_bytes(Method::signature_handler_offset()));
  1151     __ bne(T9, R0, L);
  1152     __ delayed()->nop();
  1153     __ call_VM(NOREG, CAST_FROM_FN_PTR(address, 
  1154 	  InterpreterRuntime::prepare_native_call), method);
  1155     __ get_method(method);
  1156     __ ld(T9, method, in_bytes(Method::signature_handler_offset()));
  1157     __ bind(L);
  1160   // call signature handler
  1161   // FIXME: when change codes in InterpreterRuntime, note this point
  1162   // from: begin of parameters
  1163   assert(InterpreterRuntime::SignatureHandlerGenerator::from() == LVP, "adjust this code");
  1164   // to: current sp
  1165   assert(InterpreterRuntime::SignatureHandlerGenerator::to  () == SP, "adjust this code");
  1166   // temp: T3
  1167   assert(InterpreterRuntime::SignatureHandlerGenerator::temp() == t  , "adjust this code");
  1169   __ jalr(T9);
  1170   __ delayed()->nop();
  1171   __ get_method(method);	// slow path call blows EBX on DevStudio 5.0
  1173   /* 
  1174      if native function is static, and its second parameter has type length of double word,
  1175      and first parameter has type length of word, we have to reserve one word
  1176      for the first parameter, according to mips o32 abi.
  1177      if native function is not static, and its third parameter has type length of double word,
  1178      and second parameter has type length of word, we have to reserve one word for the second
  1179      parameter.
  1180    */
  1183   // result handler is in V0
  1184   // set result handler
  1185   __ sd(V0, FP, (frame::interpreter_frame_result_handler_offset)*wordSize);
  1187 #define FIRSTPARA_SHIFT_COUNT 5
  1188 #define SECONDPARA_SHIFT_COUNT 9
  1189 #define THIRDPARA_SHIFT_COUNT 13
  1190 #define PARA_MASK	0xf
  1192   // pass mirror handle if static call
  1194     Label L;
  1195     const int mirror_offset = in_bytes(Klass::java_mirror_offset());
  1196     __ lw(t, method, in_bytes(Method::access_flags_offset()));
  1197     __ andi(AT, t, JVM_ACC_STATIC);
  1198     __ beq(AT, R0, L);
  1199     __ delayed()->nop();
  1201     // get mirror
  1202     __ ld(t, method, in_bytes(Method:: const_offset()));
  1203     __ ld(t, t, in_bytes(ConstMethod::constants_offset())); //??
  1204     __ ld(t, t, ConstantPool::pool_holder_offset_in_bytes());
  1205     __ ld(t, t, mirror_offset);
  1206     // copy mirror into activation frame
  1207     //__ sw(t, FP, frame::interpreter_frame_oop_temp_offset * wordSize);
  1208     // pass handle to mirror
  1209     __ sd(t, FP, frame::interpreter_frame_oop_temp_offset * wordSize);
  1210     __ daddi(t, FP, frame::interpreter_frame_oop_temp_offset * wordSize);
  1211     //		__ ld_ptr(t,Address(SP ,wordSize));	
  1212     //FIXME, aoqi
  1213     //__ st_ptr(t, Address(SP, wordSize));
  1214     __ move(A1, t);
  1215     __ bind(L);
  1218   // [ mthd holder mirror ptr   ] <--- sp  --------------------| (only for static method)
  1219   // [                          ]                              |
  1220   //   ...                        size of parameters(or +1)    |
  1221   // [ monitor entry            ]                              |
  1222   //   ...                                                     |
  1223   // [ monitor entry            ]                              |
  1224   // [ monitor block top        ] ( the top monitor entry )    |
  1225   // [ byte code pointer (0)    ] (if native, bcp = 0)         |
  1226   // [ constant pool cache      ]                              |
  1227   // [ Method*                ]                              |
  1228   // [ locals offset            ]                              |
  1229   // [ sender's sp              ]                              |
  1230   // [ sender's fp              ]                              |
  1231   // [ return address           ] <--- fp                      |
  1232   // [ method holder mirror     ] <----------------------------|                             
  1233   // [ result type info         ]
  1234   // [ argumnet word n-1        ] <--- ( sender's sp )
  1235   //	 ...
  1236   // [ argument word 0          ] <--- S7
  1238   // get native function entry point
  1239   { Label L;
  1240     __ ld(T9, method, in_bytes(Method::native_function_offset()));
  1241     __ li(V1, SharedRuntime::native_method_throw_unsatisfied_link_error_entry());
  1242     __ bne(V1, T9, L);
  1243     __ delayed()->nop();
  1244     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), method);
  1245     __ get_method(method);
  1246     __ verify_oop(method);
  1247     __ ld(T9, method, in_bytes(Method::native_function_offset()));
  1248     __ bind(L);
  1250   /*
  1251   __ pushad();
  1252   __ move(A0, T9);
  1253   __ call(CAST_FROM_FN_PTR(address, SharedRuntime::func_debug),relocInfo::runtime_call_type);
  1254   __ popad();
  1255   */
  1257   // pass JNIEnv
  1258   // native function in T9
  1259 #ifndef OPT_THREAD
  1260   __ get_thread(thread);
  1261 #endif
  1262   __ daddi(t, thread, in_bytes(JavaThread::jni_environment_offset()));
  1263   //__ addi(SP, SP, (-1) * wordSize);
  1264   //__ sw(t, SP, 0);
  1265   // stack,but I think it won't work when pass float,double etc @jerome,10/17,2006
  1266   __ move(A0, t);
  1267   // [ jni environment          ] <--- sp
  1268   // [ mthd holder mirror ptr   ] ---------------------------->| (only for static method)
  1269   // [                          ]                              |
  1270   //   ...                        size of parameters           |
  1271   // [ monitor entry            ]                              |
  1272   //   ...                                                     |
  1273   // [ monitor entry            ]                              |
  1274   // [ monitor block top        ] ( the top monitor entry )    |
  1275   // [ byte code pointer (0)    ] (if native, bcp = 0)         |
  1276   // [ constant pool cache      ]                              |
  1277   // [ Method*                ]                              |
  1278   // [ locals offset            ]                              |
  1279   // [ sender's sp              ]                              |
  1280   // [ sender's fp              ]                              |
  1281   // [ return address           ] <--- fp                      |
  1282   // [ method holder mirror     ] <----------------------------|                             
  1283   // [ result type info         ]
  1284   // [ argumnet word n-1        ] <--- ( sender's sp )
  1285   //	 ...
  1286   // [ argument word 0          ] <--- S7
  1288   /*
  1289   // reset handle block
  1290   __ lw(t, thread, in_bytes(JavaThread::active_handles_offset()));
  1291   __ sw(R0, t, JNIHandleBlock::top_offset_in_bytes());
  1293    */
  1294   // set_last_Java_frame_before_call
  1295   __ sd(FP, thread, in_bytes(JavaThread::last_Java_fp_offset()));
  1296   // Change state to native (we save the return address in the thread, since it might not
  1297   // be pushed on the stack when we do a a stack traversal). It is enough that the pc()
  1298   // points into the right code segment. It does not have to be the correct return pc.
  1299   __ li(t, __ pc());
  1300   //	__ sw(t, thread, in_bytes(JavaThread::frame_anchor_offset() 
  1301   //			+ JavaFrameAnchor::last_Java_pc_offset()));
  1302   __ sd(t, thread, in_bytes(JavaThread::last_Java_pc_offset())); 
  1303   __ sd(SP, thread, in_bytes(JavaThread::last_Java_sp_offset()));
  1305   // change thread state
  1306 #ifdef ASSERT
  1307   { Label L;
  1308     __ lw(t, thread, in_bytes(JavaThread::thread_state_offset()));
  1309     __ daddi(t, t, (-1) * _thread_in_Java);
  1310     __ beq(t, R0, L);
  1311     __ delayed()->nop();
  1312     __ stop("Wrong thread state in native stub");
  1313     __ bind(L);
  1315 #endif
  1317   __ move(t, _thread_in_native);
  1318   __ sw(t, thread, in_bytes(JavaThread::thread_state_offset()));
  1320   // call native method
  1321   __ jalr(T9);
  1322   __ delayed()->nop();
  1323   // result potentially in V2:V1 or F0:F1
  1326   if (CheckJNICalls) {
  1327     //FIXME	
  1328     //	 __ call(StubRoutines::gs2::verify_fpu_cntrl_wrd_entry(), 
  1329     //	 relocInfo::runtime_call_type);
  1332   // restore S0 to have legal interpreter frame, i.e., bci == 0 <=> S0 == code_base()
  1333   //__ lw(BCP, method, in_bytes(Method::const_offset())); // get constMethodOop
  1334   //__ addi(BCP, BCP, in_bytes(ConstMethod::codes_offset()));    // get codebase
  1336   // via _last_native_pc and not via _last_jave_sp
  1337   // NOTE: the order of theses push(es) is known to frame::interpreter_frame_result.
  1338   //  If the order changes or anything else is added to the stack the code in
  1339   // interpreter_frame_result will have to be changed.
  1340   //FIXME, should modify here
  1341   // save return value to keep the value from being destroyed by other calls
  1342   //__ addi(SP, SP, (-4) * wordSize);
  1343   //__ sw(V0, SP, 3 * wordSize);
  1344   //__ sw(V1, SP, 2 * wordSize);
  1345   //__ swc1(F0, SP, 1 * wordSize);
  1346   //__ swc1(F1, SP, 0 * wordSize);
  1347   __ move(S1, V0);
  1348   __ move(S3, V1);
  1349   __ dmfc1(S4, F0);
  1350   __ dmfc1(S2, F1);
  1352   // change thread state
  1353   __ get_thread(thread); 
  1354   __ move(t, _thread_in_native_trans);
  1355   __ sw(t, thread, in_bytes(JavaThread::thread_state_offset()));
  1357   if( os::is_MP() ) __ sync(); // Force this write out before the read below
  1359   // check for safepoint operation in progress and/or pending suspend requests
  1360   { Label Continue;
  1362     // Don't use call_VM as it will see a possible pending exception and forward it
  1363     // and never return here preventing us from clearing _last_native_pc down below.
  1364     // Also can't use call_VM_leaf either as it will check to see if esi & edi are
  1365     // preserved and correspond to the bcp/locals pointers. So we do a runtime call
  1366     // by hand.
  1367     //
  1368     Label L;
  1369     __ li(AT, SafepointSynchronize::address_of_state());
  1370     __ lw(AT, AT, 0);
  1371     __ bne(AT, R0, L);
  1372     __ delayed()->nop();
  1373     __ lw(AT, thread, in_bytes(JavaThread::suspend_flags_offset()));
  1374     __ beq(AT, R0, Continue);
  1375     __ delayed()->nop();
  1376     __ bind(L);
  1377   //  __ addi(SP, SP, (-1) * wordSize);
  1378     __ move(A0, thread);
  1379     __ call(CAST_FROM_FN_PTR(address, 
  1380 	  JavaThread::check_special_condition_for_native_trans), 
  1381 	relocInfo::runtime_call_type);
  1382     __ delayed()->nop();
  1383    // __ addi(SP, SP, wordSize);
  1385     //	__ get_method(method);
  1386 #ifndef OPT_THREAD
  1387     __ get_thread(thread);
  1388 #endif
  1389     //add for compressedoops
  1390     __ reinit_heapbase();
  1391     __ bind(Continue);
  1394   // change thread state
  1395   __ move(t, _thread_in_Java);
  1396   __ sw(t, thread, in_bytes(JavaThread::thread_state_offset()));
  1397   __ reset_last_Java_frame(thread, true, true);
  1399   // reset handle block
  1400   __ ld(t, thread, in_bytes(JavaThread::active_handles_offset())); 
  1401   __ sw(R0, t, JNIHandleBlock::top_offset_in_bytes());
  1403   // If result was an oop then unbox and save it in the frame
  1404   { Label L;
  1405     Label no_oop, store_result;
  1406     //FIXME, addi only support 16-bit imeditate  
  1407     __ ld(AT, FP, frame::interpreter_frame_result_handler_offset*wordSize); 
  1408     // __ addi(AT,AT,-(int)AbstractInterpreter::result_handler(T_OBJECT)); 
  1409     __ li(T0, AbstractInterpreter::result_handler(T_OBJECT)); 
  1410     __ bne(AT, T0, no_oop); 
  1411     __ delayed()->nop(); 
  1412     //__ cmpl(Address(esp), NULL_WORD);
  1413     //FIXME, do we need pop here ? @jerome	
  1414     //__ pop(ltos);
  1415     //__ testl(eax, eax);
  1416     //__ jcc(Assembler::zero, store_result);
  1417     __ move(V0, S1);	
  1418     __ beq(V0, R0, store_result); 
  1419     __ delayed()->nop();	
  1420     // unbox
  1421     __ ld(V0, V0, 0); 
  1422     __ bind(store_result);
  1423     __ sd(V0, FP, (frame::interpreter_frame_oop_temp_offset)*wordSize);  
  1424     // keep stack depth as expected by pushing oop which will eventually be discarded
  1425     __ bind(no_oop);
  1428     Label no_reguard;
  1429     __ lw(t, thread, in_bytes(JavaThread::stack_guard_state_offset()));
  1430     //__ bne(t, JavaThread::stack_guard_yellow_disabled, no_reguard);
  1431     __ move(AT,(int) JavaThread::stack_guard_yellow_disabled);	
  1432     __ bne(t, AT, no_reguard);
  1433     __ delayed()->nop();
  1434     __ pushad();	
  1435     __ call(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages), 
  1436 	relocInfo::runtime_call_type);
  1437     __ delayed()->nop();
  1438     __ popad();	
  1439     //add for compressedoops
  1440     __ reinit_heapbase();
  1441     __ bind(no_reguard);
  1443   // restore esi to have legal interpreter frame, 
  1444   // i.e., bci == 0 <=> esi == code_base()
  1445   // Can't call_VM until bcp is within reasonable.
  1446   __ get_method(method);      // method is junk from thread_in_native to now.
  1447   __ verify_oop(method);
  1448   //  __ movl(esi, Address(method,Method::const_offset())); // get constMethodOop
  1449   __ ld(BCP, method, in_bytes(Method::const_offset())); 
  1450   // __ leal(esi, Address(esi,ConstMethod::codes_offset()));    // get codebase
  1451   __ lea(BCP, Address(BCP, in_bytes(ConstMethod::codes_offset())));
  1452   // handle exceptions (exception handling will handle unlocking!)
  1454     Label L;
  1455     __ lw(t, thread, in_bytes(Thread::pending_exception_offset()));
  1456     __ beq(t, R0, L);
  1457     __ delayed()->nop();
  1458     // Note: At some point we may want to unify this with the code used in 
  1459     // call_VM_base();
  1460     // i.e., we should use the StubRoutines::forward_exception code. For now this
  1461     // doesn't work here because the esp is not correctly set at this point.
  1462     __ MacroAssembler::call_VM(noreg, CAST_FROM_FN_PTR(address, 
  1463 	  InterpreterRuntime::throw_pending_exception));
  1464     __ should_not_reach_here();
  1465     __ bind(L);
  1468   // do unlocking if necessary
  1469   { Label L;
  1470     __ lw(t, method, in_bytes(Method::access_flags_offset()));
  1471     __ andi(t, t, JVM_ACC_SYNCHRONIZED);
  1472     __ beq(t, R0, L);
  1473     // the code below should be shared with interpreter macro assembler implementation
  1474     { Label unlock;
  1475       // BasicObjectLock will be first in list,
  1476       // since this is a synchronized method. However, need
  1477       // to check that the object has not been unlocked by 
  1478       // an explicit monitorexit bytecode.        
  1479       __ delayed()->daddi(c_rarg0, FP, frame::interpreter_frame_initial_sp_offset 
  1480 	  * wordSize - (int)sizeof(BasicObjectLock));
  1481       // address of first monitor
  1483       __ ld(t, c_rarg0, BasicObjectLock::obj_offset_in_bytes());
  1484       __ bne(t, R0, unlock);
  1485       __ delayed()->nop();
  1487       // Entry already unlocked, need to throw exception
  1488       __ MacroAssembler::call_VM(NOREG, CAST_FROM_FN_PTR(address, 
  1489 	    InterpreterRuntime::throw_illegal_monitor_state_exception));
  1490       __ should_not_reach_here();
  1492       __ bind(unlock);        
  1493       __ unlock_object(c_rarg0);             
  1495     __ bind(L);
  1498   // jvmti/jvmpi support
  1499   // Note: This must happen _after_ handling/throwing any exceptions since
  1500   //       the exception handler code notifies the runtime of method exits
  1501   //       too. If this happens before, method entry/exit notifications are
  1502   //       not properly paired (was bug - gri 11/22/99).
  1503   __ notify_method_exit(false, vtos, InterpreterMacroAssembler::NotifyJVMTI );
  1505   // restore potential result in V0:V1, 
  1506   // call result handler to restore potential result in ST0 & handle result
  1507   //__ lw(V0, SP, 3 * wordSize);
  1508   //__ lw(V1, SP, 2 * wordSize);
  1509   //__ lwc1(F0, SP, 1 * wordSize);
  1510   //__ lwc1(F1, SP, 0 * wordSize);
  1511   //__ addi(SP, SP, 4 * wordSize);
  1512   __ move(V0, S1);
  1513   __ move(V1, S3);
  1514   __ dmtc1(S4, F0);
  1515   __ dmtc1(S2, F1);
  1516   __ ld(t, FP, (frame::interpreter_frame_result_handler_offset) * wordSize);
  1517   __ jalr(t);
  1518   __ delayed()->nop();
  1519   //jerome_for_debug 
  1520   //__ move(AT, (int)(&jerome4)); 
  1521   //__ sw(FP, AT, 0);  
  1524   // remove activation
  1525   __ ld(SP, FP, frame::interpreter_frame_sender_sp_offset * wordSize); // get sender sp
  1526   __ ld(RA, FP, frame::interpreter_frame_return_addr_offset * wordSize); // get return address
  1527   __ ld(FP, FP, frame::interpreter_frame_sender_fp_offset * wordSize); // restore sender's fp
  1528   __ jr(RA);
  1529   __ delayed()->nop();
  1531 #ifndef CORE
  1532   if (inc_counter) {
  1533     // Handle overflow of counter and compile method
  1534     __ bind(invocation_counter_overflow);
  1535     generate_counter_overflow(&continue_after_compile);
  1536     // entry_point is the beginning of this
  1537     // function and checks again for compiled code
  1539 #endif
  1540   return entry_point;
  1543 //
  1544 // Generic interpreted method entry to (asm) interpreter
  1545 //
  1546 // Layout of frame just at the entry
  1547 //
  1548 //   [ argument word n-1	] <--- sp
  1549 //     ...
  1550 //   [ argument word 0  	]
  1551 // assume Method* in Rmethod before call this method. 
  1552 // prerequisites to the generated stub : the callee Method* in Rmethod
  1553 // note you must save the caller bcp before call the generated stub
  1554 //
  1555 address InterpreterGenerator::generate_normal_entry(bool synchronized) {
  1556   // determine code generation flags
  1557   bool inc_counter  = UseCompiler || CountCompiledCalls;
  1559   // Rmethod: Method*
  1560   // Rsender: sender 's sp	
  1561   address entry_point = __ pc();
  1562   /*
  1563 #ifndef CORE
  1564   // check if compiled code exists
  1565   Label run_compiled_code;
  1566   if (!CompileTheWorld) {
  1567   check_for_compiled_code(run_compiled_code);
  1569 #endif
  1570    */
  1571 #ifndef CORE
  1572   const Address invocation_counter(Rmethod, 
  1573       in_bytes(MethodCounters::invocation_counter_offset() + InvocationCounter::counter_offset()));  
  1574 #endif
  1576   // get parameter size (always needed)
  1577   __ ld(T3, Rmethod, in_bytes(Method::const_offset()));  //T3 --> Rmethod._constMethod 
  1578   __ lhu(V0, T3, in_bytes(ConstMethod::size_of_parameters_offset()));
  1580   // Rmethod: Method*
  1581   // V0: size of parameters
  1582   // Rsender: sender 's sp ,could be different frome sp+ wordSize if we call via c2i 
  1583   // get size of locals in words to T2
  1584   __ lhu(T2, T3, in_bytes(ConstMethod::size_of_locals_offset()));   	
  1585   // T2 = no. of additional locals, locals include parameters
  1586   __ dsub(T2, T2, V0);                                
  1588   // see if we've got enough room on the stack for locals plus overhead.
  1589   // Layout of frame at this point
  1590   //
  1591   // [ argument word n-1  ] <--- sp
  1592   //   ...
  1593   // [ argument word 0  	]
  1594   generate_stack_overflow_check();
  1595   // after this function, the layout of frame does not change
  1597   // compute beginning of parameters (LVP)
  1598   __ dsll(LVP, V0, LogBytesPerWord);
  1599   __ daddiu(LVP, LVP, (-1) * wordSize);
  1600   __ dadd(LVP, LVP, SP);
  1602   // T2 - # of additional locals
  1603   // allocate space for locals
  1604   // explicitly initialize locals
  1606     Label exit, loop;
  1607     // for test
  1608     //	__ slt(AT, R0, T2);
  1609     //	__ beq(AT, R0, exit);
  1610     __ beq(T2, R0, exit);
  1611     __ delayed()->nop();
  1612     __ bind(loop);
  1613  //   if(TaggedStackInterpreter)__ daddi(SP, SP, -1 * wordSize);  
  1614     __ sd(R0, SP, -1 * wordSize);     // initialize local variables
  1615     __ daddiu(T2, T2, -1);               // until everything initialized
  1616     __ bne(T2, R0, loop);
  1617     //	__ slt(AT, R0, T2);
  1618     //	__ bne(AT, R0, loop);
  1619     __ delayed();
  1620     __ daddiu(SP, SP, (-1) * wordSize); //fill delay slot
  1621     __ bind(exit);
  1624 #ifndef CORE
  1625   if (inc_counter) __ lw(T3, invocation_counter);  // (pre-)fetch invocation count
  1626 #endif
  1627   // 				
  1628   // [ local var m-1	] <--- sp
  1629   //   ...
  1630   // [ local var 0	]
  1631   // [ argument word n-1	] <--- T0?
  1632   //   ...
  1633   // [ argument word 0  	] <--- LVP
  1635   // initialize fixed part of activation frame
  1637   generate_fixed_frame(false);
  1640   // after this function, the layout of frame is as following
  1641   //                           
  1642   // [ monitor block top        ] <--- sp ( the top monitor entry )
  1643   // [ byte code pointer        ] (if native, bcp = 0)
  1644   // [ constant pool cache      ]
  1645   // [ Method*                ]
  1646   // [ locals offset		]
  1647   // [ sender's sp              ]
  1648   // [ sender's fp              ] <--- fp
  1649   // [ return address           ] 
  1650   // [ local var m-1            ]
  1651   //   ...
  1652   // [ local var 0              ]
  1653   // [ argumnet word n-1        ] <--- ( sender's sp )
  1654   //   ...
  1655   // [ argument word 0          ] <--- LVP
  1658   // make sure method is not native & not abstract
  1659 #ifdef ASSERT
  1660   __ ld(AT, Rmethod, in_bytes(Method::access_flags_offset()));
  1662     Label L;
  1663     __ andi(T2, AT, JVM_ACC_NATIVE);
  1664     __ beq(T2, R0, L);
  1665     __ delayed()->nop();
  1666     __ stop("tried to execute native method as non-native");
  1667     __ bind(L);
  1669   { Label L;
  1670     __ andi(T2, AT, JVM_ACC_ABSTRACT);
  1671     __ beq(T2, R0, L);
  1672     __ delayed()->nop();
  1673     __ stop("tried to execute abstract method in interpreter");
  1674     __ bind(L);
  1676 #endif
  1678   // Since at this point in the method invocation the exception handler
  1679   // would try to exit the monitor of synchronized methods which hasn't
  1680   // been entered yet, we set the thread local variable
  1681   // _do_not_unlock_if_synchronized to true. The remove_activation will
  1682   // check this flag.
  1684 #ifndef OPT_THREAD
  1685   Register thread = T8;
  1686   __ get_thread(thread);
  1687 #else
  1688   Register thread = TREG;
  1689 #endif
  1690   __ move(AT, (int)true);
  1691   __ sb(AT, thread, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
  1693 #ifndef CORE
  1695   // 2014/11/24 Fu
  1696   // mdp : T8
  1697   // tmp1: T9
  1698   // tmp2: T2 
  1699    __ profile_parameters_type(T8, T9, T2);
  1701   // increment invocation count & check for overflow
  1702   Label invocation_counter_overflow;
  1703   Label profile_method;
  1704   Label profile_method_continue;
  1705   if (inc_counter) {
  1706     generate_counter_incr(&invocation_counter_overflow, &profile_method, 
  1707 	&profile_method_continue);
  1708     if (ProfileInterpreter) {
  1709       __ bind(profile_method_continue);
  1713   Label continue_after_compile;
  1714   __ bind(continue_after_compile);
  1716 #endif // CORE
  1718   bang_stack_shadow_pages(false);
  1720   // reset the _do_not_unlock_if_synchronized flag
  1721 #ifndef OPT_THREAD
  1722   __ get_thread(thread);
  1723 #endif
  1724   __ sb(R0, thread, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
  1726   // check for synchronized methods
  1727   // Must happen AFTER invocation_counter check and stack overflow check,
  1728   // so method is not locked if overflows.
  1729   //
  1730   if (synchronized) {
  1731     // Allocate monitor and lock method
  1732     lock_method();
  1733   } else {
  1734     // no synchronization necessary
  1735 #ifdef ASSERT
  1736     { Label L;
  1737       __ lw(AT, Rmethod, in_bytes(Method::access_flags_offset()));
  1738       __ andi(T2, AT, JVM_ACC_SYNCHRONIZED);
  1739       __ beq(T2, R0, L);
  1740       __ delayed()->nop();
  1741       __ stop("method needs synchronization");
  1742       __ bind(L);
  1744 #endif
  1747   // layout of frame after lock_method
  1748   // [ monitor entry	      ] <--- sp
  1749   //   ...
  1750   // [ monitor entry	      ] 
  1751   // [ monitor block top        ] ( the top monitor entry )
  1752   // [ byte code pointer        ] (if native, bcp = 0)
  1753   // [ constant pool cache      ]
  1754   // [ Method*                ]
  1755   // [ locals offset	      ]
  1756   // [ sender's sp              ]
  1757   // [ sender's fp              ]
  1758   // [ return address           ] <--- fp
  1759   // [ local var m-1            ]
  1760   //   ...
  1761   // [ local var 0              ]
  1762   // [ argumnet word n-1        ] <--- ( sender's sp )
  1763   //   ...
  1764   // [ argument word 0          ] <--- LVP
  1767   // start execution
  1768 #ifdef ASSERT
  1769   { Label L;
  1770     __ ld(AT, FP, frame::interpreter_frame_monitor_block_top_offset * wordSize);
  1771     __ beq(AT, SP, L);
  1772     __ delayed()->nop();
  1773     __ stop("broken stack frame setup in interpreter in native");
  1774     __ bind(L);
  1776 #endif
  1778   // jvmti/jvmpi support
  1779   __ notify_method_entry();
  1781   __ dispatch_next(vtos);
  1783 #ifndef CORE
  1784   // invocation counter overflow
  1785   if (inc_counter) {
  1786     if (ProfileInterpreter) {
  1787       // We have decided to profile this method in the interpreter
  1788       __ bind(profile_method);
  1789       __ call_VM(noreg, CAST_FROM_FN_PTR(address, 
  1790            InterpreterRuntime::profile_method));
  1791       __ set_method_data_pointer_for_bcp();
  1792       __ get_method(Rmethod);
  1793       __ b(profile_method_continue);
  1794       __ delayed()->nop();
  1796     // Handle overflow of counter and compile method
  1797     __ bind(invocation_counter_overflow);
  1798     generate_counter_overflow(&continue_after_compile); 
  1801 #endif
  1802   return entry_point;
  1805 // Entry points
  1806 //
  1807 // Here we generate the various kind of entries into the interpreter.
  1808 // The two main entry type are generic bytecode methods and native
  1809 // call method.  These both come in synchronized and non-synchronized
  1810 // versions but the frame layout they create is very similar. The
  1811 // other method entry types are really just special purpose entries
  1812 // that are really entry and interpretation all in one. These are for
  1813 // trivial methods like accessor, empty, or special math methods.
  1814 //
  1815 // When control flow reaches any of the entry types for the interpreter
  1816 // the following holds ->
  1817 //
  1818 // Arguments:
  1819 //
  1820 // Rmethod: Method*
  1821 // V0: receiver
  1822 //
  1823 //
  1824 // Stack layout immediately at entry
  1825 //
  1826 // [ parameter n-1      ] <--- sp
  1827 //   ...
  1828 // [ parameter 0        ]
  1829 // [ expression stack   ] (caller's java expression stack)
  1831 // Assuming that we don't go to one of the trivial specialized entries
  1832 // the stack will look like below when we are ready to execute the
  1833 // first bytecode (or call the native routine). The register usage
  1834 // will be as the template based interpreter expects (see
  1835 // interpreter_amd64.hpp).
  1836 //
  1837 // local variables follow incoming parameters immediately; i.e.
  1838 // the return address is moved to the end of the locals).
  1839 //
  1840 // [ monitor entry	      ] <--- sp
  1841 //   ...
  1842 // [ monitor entry	      ] 
  1843 // [ monitor block top        ] ( the top monitor entry )
  1844 // [ byte code pointer        ] (if native, bcp = 0)
  1845 // [ constant pool cache      ]
  1846 // [ Method*                ]
  1847 // [ locals offset	      ]
  1848 // [ sender's sp              ]
  1849 // [ sender's fp              ]
  1850 // [ return address           ] <--- fp
  1851 // [ local var m-1            ]
  1852 //   ...
  1853 // [ local var 0              ]
  1854 // [ argumnet word n-1        ] <--- ( sender's sp )
  1855 //   ...
  1856 // [ argument word 0          ] <--- S7
  1858 address AbstractInterpreterGenerator::generate_method_entry(
  1859                                         AbstractInterpreter::MethodKind kind) {
  1860   // determine code generation flags
  1861   bool synchronized = false;
  1862   address entry_point = NULL;
  1863 	switch (kind) {    
  1864 		case Interpreter::zerolocals             :                                                                             break;
  1865 		case Interpreter::zerolocals_synchronized: synchronized = true;                                                        break;
  1866 		case Interpreter::native                 : 
  1867 		entry_point = ((InterpreterGenerator*)this)->generate_native_entry(false);  
  1868 				   break;
  1869 		case Interpreter::native_synchronized    : 
  1870 		entry_point = ((InterpreterGenerator*)this)->generate_native_entry(true);   
  1871 				   break;
  1872 		case Interpreter::empty                  : 
  1873 		entry_point = ((InterpreterGenerator*)this)->generate_empty_entry();        
  1874 				  break;
  1875 		case Interpreter::accessor               : 
  1876 		entry_point = ((InterpreterGenerator*)this)->generate_accessor_entry();     
  1877 				  break;
  1878 		case Interpreter::abstract               : 
  1879 		entry_point = ((InterpreterGenerator*)this)->generate_abstract_entry();     
  1880 				  break;
  1882 		case Interpreter::java_lang_math_sin     : // fall thru
  1883 		case Interpreter::java_lang_math_cos     : // fall thru
  1884 		case Interpreter::java_lang_math_tan     : // fall thru
  1885 		case Interpreter::java_lang_math_log     : // fall thru 
  1886 		case Interpreter::java_lang_math_log10   : // fall thru
  1887 	        case Interpreter::java_lang_math_pow     : // fall thru
  1888 	        case Interpreter::java_lang_math_exp     : break;
  1889 		case Interpreter::java_lang_math_abs     : // fall thru
  1890 		case Interpreter::java_lang_math_sqrt    : 
  1891                 entry_point = ((InterpreterGenerator*)this)->generate_math_entry(kind);    break;
  1892                 case Interpreter::java_lang_ref_reference_get: 
  1893                 entry_point = ((InterpreterGenerator*)this)->generate_Reference_get_entry(); break;
  1894                 default:
  1895                 fatal(err_msg("unexpected method kind: %d", kind));
  1896     break;
  1898 	if (entry_point) return entry_point;
  1900 	return ((InterpreterGenerator*)this)->generate_normal_entry(synchronized);
  1903 // These should never be compiled since the interpreter will prefer
  1904 // // the compiled version to the intrinsic version.
  1905 bool AbstractInterpreter::can_be_compiled(methodHandle m) {
  1906   switch (method_kind(m)) {
  1907     case Interpreter::java_lang_math_sin     : // fall thru
  1908     case Interpreter::java_lang_math_cos     : // fall thru
  1909     case Interpreter::java_lang_math_tan     : // fall thru
  1910     case Interpreter::java_lang_math_abs     : // fall thru
  1911     case Interpreter::java_lang_math_log     : // fall thru
  1912     case Interpreter::java_lang_math_log10   : // fall thru
  1913     case Interpreter::java_lang_math_sqrt    : // fall thru
  1914     case Interpreter::java_lang_math_pow     : // fall thru
  1915     case Interpreter::java_lang_math_exp     :
  1916       return false;
  1917     default:
  1918       return true;
  1922 // How much stack a method activation needs in words.
  1923 int AbstractInterpreter::size_top_interpreter_activation(Method* method) {
  1925 	const int entry_size    = frame::interpreter_frame_monitor_size();
  1927 	// total overhead size: entry_size + (saved ebp thru expr stack bottom).
  1928 	// be sure to change this if you add/subtract anything to/from the overhead area
  1929 	const int overhead_size = -(frame::interpreter_frame_initial_sp_offset) + entry_size;
  1931 	const int stub_code = 6;  // see generate_call_stub
  1932 	// return overhead_size + method->max_locals() + method->max_stack() + stub_code;
  1933 	const int method_stack = (method->max_locals() + method->max_stack()) *
  1934 					Interpreter::stackElementWords;
  1935 	return overhead_size + method_stack + stub_code;
  1938 void AbstractInterpreter::layout_activation(Method* method,
  1939                                            int tempcount,
  1940                                            int popframe_extra_args,
  1941                                            int moncount,
  1942                                            int caller_actual_parameters,
  1943                                            int callee_param_count,
  1944                                            int callee_locals,
  1945                                            frame* caller,
  1946                                            frame* interpreter_frame,
  1947                                            bool is_top_frame,
  1948                                            bool is_bottom_frame) {
  1949   // Note: This calculation must exactly parallel the frame setup
  1950   // in AbstractInterpreterGenerator::generate_method_entry.
  1951   // If interpreter_frame!=NULL, set up the method, locals, and monitors.
  1952   // The frame interpreter_frame, if not NULL, is guaranteed to be the
  1953   // right size, as determined by a previous call to this method.
  1954   // It is also guaranteed to be walkable even though it is in a skeletal state
  1956   // fixed size of an interpreter frame:
  1957  // int max_locals = method->max_locals();
  1959  int max_locals = method->max_locals() * Interpreter::stackElementWords;
  1960  int extra_locals = (method->max_locals() - method->size_of_parameters()) * Interpreter::stackElementWords;
  1962 #ifdef ASSERT
  1963   if (!EnableInvokeDynamic) {
  1964     // @@@ FIXME: Should we correct interpreter_frame_sender_sp in the calling sequences?
  1965     // Probably, since deoptimization doesn't work yet.
  1966     assert(caller->unextended_sp() == interpreter_frame->interpreter_frame_sender_sp(), "Frame not properly walkable");
  1968   assert(caller->sp() == interpreter_frame->interpreter_frame_sender_sp(), "Frame not properly walkable(2)");
  1969 #endif
  1971     interpreter_frame->interpreter_frame_set_method(method);
  1972     // NOTE the difference in using sender_sp and interpreter_frame_sender_sp
  1973     // interpreter_frame_sender_sp is the original sp of the caller (the unextended_sp)
  1974     // and sender_sp is fp+8
  1975     intptr_t* locals = interpreter_frame->sender_sp() + max_locals - 1;
  1977 #ifdef ASSERT
  1978   if (caller->is_interpreted_frame()) {
  1979     assert(locals < caller->fp() + frame::interpreter_frame_initial_sp_offset, "bad placement");
  1981 #endif
  1983     interpreter_frame->interpreter_frame_set_locals(locals);
  1984     BasicObjectLock* montop = interpreter_frame->interpreter_frame_monitor_begin();
  1985     BasicObjectLock* monbot = montop - moncount;
  1986     interpreter_frame->interpreter_frame_set_monitor_end(montop - moncount);
  1988 //set last sp;
  1989     intptr_t*  esp = (intptr_t*) monbot - tempcount*Interpreter::stackElementWords -
  1990 			                popframe_extra_args;
  1991      interpreter_frame->interpreter_frame_set_last_sp(esp);
  1992     // All frames but the initial interpreter frame we fill in have a
  1993     // value for sender_sp that allows walking the stack but isn't
  1994     // truly correct. Correct the value here.
  1995     // 
  1996    // int extra_locals = method->max_locals() - method->size_of_parameters();
  1997     if (extra_locals != 0 && 
  1998 	interpreter_frame->sender_sp() == interpreter_frame->interpreter_frame_sender_sp() ) {
  1999       interpreter_frame->set_interpreter_frame_sender_sp(caller->sp() + extra_locals);
  2001     *interpreter_frame->interpreter_frame_cache_addr() = 
  2002       method->constants()->cache();
  2005 //-----------------------------------------------------------------------------
  2006 // Exceptions
  2008 void TemplateInterpreterGenerator::generate_throw_exception() {
  2009   // Entry point in previous activation (i.e., if the caller was
  2010   // interpreted)
  2011   Interpreter::_rethrow_exception_entry = __ pc();
  2013   // Restore sp to interpreter_frame_last_sp even though we are going
  2014   // to empty the expression stack for the exception processing.
  2015   __ sd(R0,FP, frame::interpreter_frame_last_sp_offset * wordSize); 
  2017   // V0: exception
  2018   // V1: return address/pc that threw exception
  2019   __ restore_bcp();                              // esi points to call/send
  2020   __ restore_locals();
  2022   //add for compressedoops
  2023   __ reinit_heapbase();
  2024   // Entry point for exceptions thrown within interpreter code
  2025   Interpreter::_throw_exception_entry = __ pc();  
  2026   // expression stack is undefined here
  2027   // V0: exception
  2028   // BCP: exception bcp
  2029   __ verify_oop(V0);
  2031   // expression stack must be empty before entering the VM in case of an exception
  2032   __ empty_expression_stack();
  2033   // find exception handler address and preserve exception oop
  2034   __ move(A1, V0);
  2035   __ call_VM(V1, CAST_FROM_FN_PTR(address, InterpreterRuntime::exception_handler_for_exception), A1);
  2036   // V0: exception handler entry point
  2037   // V1: preserved exception oop
  2038   // S0: bcp for exception handler
  2039   __ daddi(SP, SP, (-1) * wordSize);
  2040   __ sd(V1, SP, 0);                              // push exception which is now the only value on the stack
  2041   __ jr(V0);                                   // jump to exception handler (may be _remove_activation_entry!)
  2042   __ delayed()->nop();
  2044   // If the exception is not handled in the current frame the frame is removed and
  2045   // the exception is rethrown (i.e. exception continuation is _rethrow_exception).
  2046   //
  2047   // Note: At this point the bci is still the bxi for the instruction which caused
  2048   //       the exception and the expression stack is empty. Thus, for any VM calls
  2049   //       at this point, GC will find a legal oop map (with empty expression stack).
  2051   // In current activation
  2052   // V0: exception
  2053   // BCP: exception bcp
  2055   //
  2056   // JVMTI PopFrame support
  2057   //
  2059   Interpreter::_remove_activation_preserving_args_entry = __ pc();
  2060   __ empty_expression_stack();
  2061   // Set the popframe_processing bit in pending_popframe_condition indicating that we are
  2062   // currently handling popframe, so that call_VMs that may happen later do not trigger new
  2063   // popframe handling cycles.
  2064 #ifndef OPT_THREAD
  2065   Register thread = T2;
  2066   __ get_thread(T2);
  2067 #else
  2068   Register thread = TREG;
  2069 #endif
  2070   __ lw(T3, thread, in_bytes(JavaThread::popframe_condition_offset()));
  2071   __ ori(T3, T3, JavaThread::popframe_processing_bit);
  2072   __ sw(T3, thread, in_bytes(JavaThread::popframe_condition_offset()));
  2074 #ifndef CORE
  2076     // Check to see whether we are returning to a deoptimized frame.
  2077     // (The PopFrame call ensures that the caller of the popped frame is
  2078     // either interpreted or compiled and deoptimizes it if compiled.)
  2079     // In this case, we can't call dispatch_next() after the frame is
  2080     // popped, but instead must save the incoming arguments and restore
  2081     // them after deoptimization has occurred.
  2082     //
  2083     // Note that we don't compare the return PC against the
  2084     // deoptimization blob's unpack entry because of the presence of
  2085     // adapter frames in C2.
  2086     Label caller_not_deoptimized;
  2087     __ ld(A0, FP, frame::return_addr_offset * wordSize);
  2088     __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::interpreter_contains), A0);
  2089     __ bne(V0, R0, caller_not_deoptimized);
  2090     __ delayed()->nop();
  2092     // Compute size of arguments for saving when returning to deoptimized caller
  2093     __ get_method(A1);
  2094     __ verify_oop(A1);	
  2095     __ ld(A1,A1,in_bytes(Method::const_offset()));   
  2096     __ lhu(A1, A1, in_bytes(ConstMethod::size_of_parameters_offset()));
  2097     __ shl(A1, Interpreter::logStackElementSize);
  2098     __ restore_locals();
  2099     __ dsub(A2, LVP, T0);
  2100     __ daddiu(A2, A2, wordSize);
  2101     // Save these arguments
  2102 #ifndef OPT_THREAD
  2103     __ get_thread(A0);
  2104 #else
  2105     __ move(A0, TREG);
  2106 #endif
  2107     __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, Deoptimization::popframe_preserve_args), A0, A1, A2);
  2111     __ remove_activation(vtos, T9, false, false, false);
  2113     // Inform deoptimization that it is responsible for restoring these arguments
  2114 #ifndef OPT_THREAD
  2115     __ get_thread(thread);
  2116 #endif
  2117     __ move(AT, JavaThread::popframe_force_deopt_reexecution_bit);
  2118     __ sw(AT, thread, in_bytes(JavaThread::popframe_condition_offset()));
  2119     // Continue in deoptimization handler
  2120     ///__ jmp(edx);
  2121     __ jr(T9);
  2122     __ delayed()->nop();
  2124     __ bind(caller_not_deoptimized);
  2126 #endif /* !CORE */
  2129   __ remove_activation(vtos, T3, 
  2130       /* throw_monitor_exception */ false, 
  2131       /* install_monitor_exception */ false,
  2132       /* notify_jvmdi */ false);
  2134   // Clear the popframe condition flag
  2135   // Finish with popframe handling
  2136   // A previous I2C followed by a deoptimization might have moved the
  2137   // outgoing arguments further up the stack. PopFrame expects the
  2138   // mutations to those outgoing arguments to be preserved and other
  2139   // constraints basically require this frame to look exactly as
  2140   // though it had previously invoked an interpreted activation with
  2141   // no space between the top of the expression stack (current
  2142   // last_sp) and the top of stack. Rather than force deopt to
  2143   // maintain this kind of invariant all the time we call a small
  2144   // fixup routine to move the mutated arguments onto the top of our
  2145   // expression stack if necessary.
  2146   //why x86 write this , i think it is no use ,@jerome 
  2147   //__ movl(eax, esp);
  2148   //__ movl(ebx, Address(ebp, frame::interpreter_frame_last_sp_offset * wordSize));
  2149   __ move(T8, SP);
  2150   __ ld(A2, FP, frame::interpreter_frame_last_sp_offset * wordSize);
  2151 #ifndef OPT_THREAD
  2152   __ get_thread(thread);
  2153 #endif
  2154   // PC must point into interpreter here
  2155   //__ set_last_Java_frame(ecx, noreg, ebp, __ pc());
  2156   __ set_last_Java_frame(thread, noreg, FP, __ pc());
  2157   // __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::popframe_move_outgoing_args), ecx, eax, ebx);
  2158   __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::popframe_move_outgoing_args), thread, T8, A2);
  2159   __ reset_last_Java_frame(thread, true, true);
  2160   // Restore the last_sp and null it out
  2161   __ ld(SP, FP, frame::interpreter_frame_last_sp_offset * wordSize);
  2162   __ sd(R0, FP, frame::interpreter_frame_last_sp_offset * wordSize);
  2166   __ move(AT, JavaThread::popframe_inactive);	
  2167   __ sw(AT, thread, in_bytes(JavaThread::popframe_condition_offset()));
  2169   // Finish with popframe handling
  2170   __ restore_bcp();
  2171   __ restore_locals();
  2172 #ifndef CORE
  2173   // The method data pointer was incremented already during
  2174   // call profiling. We have to restore the mdp for the current bcp.
  2175   if (ProfileInterpreter) {
  2176     __ set_method_data_pointer_for_bcp();
  2178 #endif // !CORE
  2179   // Clear the popframe condition flag
  2180   // __ get_thread(ecx);
  2181   // __ movl(Address(ecx, JavaThread::popframe_condition_offset()), JavaThread::popframe_inactive);
  2182 #ifndef OPT_THREAD
  2183   __ get_thread(thread);
  2184 #endif 
  2185   __ move(AT, JavaThread::popframe_inactive); 
  2186   __ sw(AT, thread, in_bytes(JavaThread::popframe_condition_offset())); 
  2187   __ dispatch_next(vtos);
  2188   // end of PopFrame support
  2190   Interpreter::_remove_activation_entry = __ pc();
  2192   // preserve exception over this code sequence
  2193   __ ld(T0, SP, 0);
  2194   __ daddi(SP, SP, wordSize);
  2195 #ifndef OPT_THREAD
  2196   __ get_thread(thread);
  2197 #endif
  2198   __ sd(T0, thread, in_bytes(JavaThread::vm_result_offset()));
  2199   // remove the activation (without doing throws on illegalMonitorExceptions)
  2200   __ remove_activation(vtos, T3, false, true, false);
  2201   // restore exception
  2202   __ get_vm_result(T0, thread);
  2203   __ verify_oop(T0);
  2205   // Inbetween activations - previous activation type unknown yet
  2206   // compute continuation point - the continuation point expects
  2207   // the following registers set up:
  2208   //
  2209   // T0: exception																eax
  2210   // T1: return address/pc that threw exception		edx
  2211   // SP: expression stack of caller			esp
  2212   // FP: ebp of caller					ebp
  2213   __ daddi(SP, SP, (-2) * wordSize);
  2214   __ sd(T0, SP, wordSize);			// save exception
  2215   __ sd(T3, SP, 0);                               // save return address
  2216   __ move(A1, T3);
  2217   __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address), thread, A1);
  2218   __ move(T9, V0);                             // save exception handler
  2219   __ ld(V0, SP, wordSize);			  // restore exception
  2220   __ ld(V1, SP, 0);                               // restore return address
  2221   __ daddi(SP, SP, 2 * wordSize);
  2223   // Note that an "issuing PC" is actually the next PC after the call
  2224   __ jr(T9);                                   // jump to exception handler of caller
  2225   __ delayed()->nop();
  2229 //
  2230 // JVMTI ForceEarlyReturn support
  2231 //
  2232 address TemplateInterpreterGenerator::generate_earlyret_entry_for(TosState state) {
  2233   address entry = __ pc();
  2234   __ restore_bcp();
  2235   __ restore_locals();
  2236   __ empty_expression_stack();
  2237   __ empty_FPU_stack();
  2238   __ load_earlyret_value(state);
  2240 //__ get_thread(ecx);
  2241 #ifndef OPT_THREAD
  2242   __ get_thread(TREG);
  2243 #endif
  2244 //  __ movl(TREG, Address(TREG, JavaThread::jvmti_thread_state_offset()));
  2245    __ ld_ptr(T9, TREG, in_bytes(JavaThread::jvmti_thread_state_offset()));
  2246   //const Address cond_addr(ecx, JvmtiThreadState::earlyret_state_offset());
  2247   const Address cond_addr(T9, in_bytes(JvmtiThreadState::earlyret_state_offset()));
  2248   // Clear the earlyret state
  2249  // __ movl(cond_addr, JvmtiThreadState::earlyret_inactive);
  2250     __ move(AT,JvmtiThreadState::earlyret_inactive);
  2251     __ sw(AT,cond_addr); 
  2252     __ sync();
  2253     //__ remove_activation(state, esi,
  2257     __ remove_activation(state, T0,
  2258 		       false, /* throw_monitor_exception */
  2259                        false, /* install_monitor_exception */
  2260                        true); /* notify_jvmdi */
  2261     __ sync();
  2262  // __ jmp(esi);
  2263   //__ jmp(T0);
  2264     __ jr(T0); 
  2265     __ delayed()->nop(); 
  2266   return entry;
  2267 } // end of ForceEarlyReturn support
  2270 //-----------------------------------------------------------------------------
  2271 // Helper for vtos entry point generation
  2273 void TemplateInterpreterGenerator::set_vtos_entry_points(Template* t,
  2274                                                          address& bep,
  2275                                                          address& cep,
  2276                                                          address& sep,
  2277                                                          address& aep,
  2278                                                          address& iep,
  2279                                                          address& lep,
  2280                                                          address& fep,
  2281                                                          address& dep,
  2282                                                          address& vep) {
  2283   assert(t->is_valid() && t->tos_in() == vtos, "illegal template");
  2284   Label L;
  2285   fep = __ pc(); __ push(ftos); __ b(L); __ delayed()->nop();
  2286   dep = __ pc(); __ push(dtos); __ b(L); __ delayed()->nop();
  2287   lep = __ pc(); __ push(ltos); __ b(L); __ delayed()->nop();
  2288   aep  =__ pc(); __ push(atos); __ b(L); __ delayed()->nop();
  2289   bep = cep = sep = iep = __ pc(); __ push(itos); 
  2290   vep = __ pc(); __ bind(L);    // fall through
  2291   generate_and_dispatch(t);
  2295 //-----------------------------------------------------------------------------
  2296 // Generation of individual instructions
  2298 // helpers for generate_and_dispatch
  2301 InterpreterGenerator::InterpreterGenerator(StubQueue* code)
  2302   : TemplateInterpreterGenerator(code) {
  2303    generate_all(); // down here so it can be "virtual"
  2306 //-----------------------------------------------------------------------------
  2308 // Non-product code
  2309 #ifndef PRODUCT
  2310 address TemplateInterpreterGenerator::generate_trace_code(TosState state) {
  2311   address entry = __ pc();
  2313   // prepare expression stack
  2314   __ push(state);       // save tosca
  2316   // tos & tos2, added by yjl 7/15/2005
  2317   // trace_bytecode need actually 4 args, the last two is tos&tos2
  2318   // this work fine for x86. but mips o32 call convention will store A2-A3
  2319   // to the stack position it think is the tos&tos2
  2320   // when the expression stack have no more than 2 data, error occur.
  2321   __ ld(A2, SP, 0);
  2322   __ ld(A3, SP, 1 * wordSize);
  2324   //aoqi_test
  2325   /*
  2326    __ pushad();
  2327     __ li(A0, (long)0);
  2328    __ call(CAST_FROM_FN_PTR(address, SharedRuntime::func_debug),relocInfo::runtime_call_type);
  2329     __ popad();
  2330 */
  2333   // pass arguments & call tracer
  2334   __ call_VM(noreg, CAST_FROM_FN_PTR(address, SharedRuntime::trace_bytecode), RA, A2, A3);
  2335   __ move(RA, V0);    // make sure return address is not destroyed by pop(state)
  2337   // restore expression stack
  2338   __ pop(state);        // restore tosca
  2340   // return
  2341   __ jr(RA);
  2342   __ delayed()->nop();
  2344   return entry;
  2347 void TemplateInterpreterGenerator::count_bytecode() {
  2348   __ li(T8, (long)&BytecodeCounter::_counter_value);
  2349   __ lw(AT, T8, 0);
  2350   __ daddi(AT, AT, 1);
  2351   __ sw(AT, T8, 0);
  2354 void TemplateInterpreterGenerator::histogram_bytecode(Template* t) {
  2355 	__ li(T8, (long)&BytecodeHistogram::_counters[t->bytecode()]);
  2356 	__ lw(AT, T8, 0);
  2357 	__ daddi(AT, AT, 1);
  2358 	__ sw(AT, T8, 0);
  2361 void TemplateInterpreterGenerator::histogram_bytecode_pair(Template* t) {
  2362 	__ li(T8, (long)&BytecodePairHistogram::_index);
  2363 	__ lw(T9, T8, 0);
  2364 	__ dsrl(T9, T9, BytecodePairHistogram::log2_number_of_codes);
  2365 	__ li(T8, ((long)t->bytecode()) << BytecodePairHistogram::log2_number_of_codes);
  2366 	__ orr(T9, T9, T8);
  2367 	__ li(T8, (long)&BytecodePairHistogram::_index);
  2368 	__ sw(T9, T8, 0);
  2369 	__ dsll(T9, T9, 2);
  2370 	__ li(T8, (long)BytecodePairHistogram::_counters);
  2371 	__ dadd(T8, T8, T9);
  2372 	__ lw(AT, T8, 0);
  2373 	__ daddi(AT, AT, 1);
  2374 	__ sw(AT, T8, 0);
  2378 void TemplateInterpreterGenerator::trace_bytecode(Template* t) {
  2379   // Call a little run-time stub to avoid blow-up for each bytecode.
  2380   // The run-time runtime saves the right registers, depending on
  2381   // the tosca in-state for the given template.
  2383 	address entry = Interpreter::trace_code(t->tos_in());
  2384 	assert(entry != NULL, "entry must have been generated");
  2385 	__ call(entry, relocInfo::none);
  2386 	__ delayed()->nop();
  2387 	//add for compressedoops
  2388 	__ reinit_heapbase();
  2392 void TemplateInterpreterGenerator::stop_interpreter_at() {
  2393   Label L;
  2394 	__ li(T8, long(&BytecodeCounter::_counter_value));
  2395 	__ lw(T8, T8, 0);
  2396 	__ move(AT, StopInterpreterAt);
  2397 	__ bne(T8, AT, L);
  2398 	__ delayed()->nop();
  2399 	__ call(CAST_FROM_FN_PTR(address, os::breakpoint), relocInfo::runtime_call_type);
  2400 	__ delayed()->nop();
  2401 	__ bind(L);
  2403 #endif // !PRODUCT
  2404 #endif // ! CC_INTERP

mercurial