src/cpu/mips/vm/templateTable_mips_64.cpp

Thu, 25 Aug 2016 22:31:58 +0800

author
jiangshaofeng
date
Thu, 25 Aug 2016 22:31:58 +0800
changeset 89
179d203c9b2b
parent 88
02ae7081a1a7
child 104
36f7453a6977
permissions
-rw-r--r--

#4428: Use gsdmult to optimize the lmul template of the interpreter.
I have run the test program on 3A2000 computer

Effects:
[loongson@localhost project]$ ./LmulTest.sh
before
time:3225ms
after
time:3115ms

The test java program:
public class LmulTest{
public static void main(String args[]){
int count = 10000000;
long startTime = System.currentTimeMillis();
//long startTime = System.nanoTime();
for(int i = 0; i < count; i++){
long a, b, c;
a = 12345678;
a++;
b = 87654321;
b++;
c = a * b;
//System.out.println(c);
}
long endTime = System.currentTimeMillis();
//long endTime = System.nanoTime();
System.out.println("time:" + (endTime - startTime) + "ms");
}
}

     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/interpreter.hpp"
    29 #include "interpreter/interpreterRuntime.hpp"
    30 #include "interpreter/templateTable.hpp"
    31 #include "memory/universe.inline.hpp"
    32 #include "oops/methodData.hpp"
    33 #include "oops/objArrayKlass.hpp"
    34 #include "oops/oop.inline.hpp"
    35 #include "prims/methodHandles.hpp"
    36 #include "runtime/sharedRuntime.hpp"
    37 #include "runtime/stubRoutines.hpp"
    38 #include "runtime/synchronizer.hpp"
    41 #ifndef CC_INTERP
    43 #define __ _masm->
    45 // Platform-dependent initialization
    47 void TemplateTable::pd_initialize() {
    48   // No mips specific initialization
    49 }
    51 // Address computation: local variables
    52 // we use t8 as the local variables pointer register, by yjl 6/27/2005
    53 static inline Address iaddress(int n) {
    54   return Address(LVP, Interpreter::local_offset_in_bytes(n));
    55 }
    57 static inline Address laddress(int n) {
    58   return iaddress(n + 1);
    59 }
    61 static inline Address faddress(int n) {
    62   return iaddress(n);
    63 }
    65 static inline Address daddress(int n) {
    66   return laddress(n);
    67 }
    69 static inline Address aaddress(int n) {
    70   return iaddress(n);
    71 }
    72 static inline Address haddress(int n)            { return iaddress(n + 0); }
    74 //FIXME , can not use dadd and dsll
    75 /*
    76 static inline Address iaddress(Register r) {
    77   return Address(r14, r, Address::times_8, Interpreter::value_offset_in_bytes());
    78 }
    80 static inline Address laddress(Register r) {
    81   return Address(r14, r, Address::times_8, Interpreter::local_offset_in_bytes(1));
    82 }
    84 static inline Address faddress(Register r) {
    85   return iaddress(r);
    86 }
    88 static inline Address daddress(Register r) {
    89   return laddress(r);
    90 }
    92 static inline Address aaddress(Register r) {
    93   return iaddress(r);
    94 }
    95 */
    97 static inline Address at_sp() 						{	return Address(SP, 	0); }					
    98 static inline Address at_sp_p1()          { return Address(SP,  1 * wordSize); }
    99 static inline Address at_sp_p2()          { return Address(SP,  2 * wordSize); }
   101 // At top of Java expression stack which may be different than esp().  It
   102 // isn't for category 1 objects.
   103 static inline Address at_tos   () {
   104   Address tos = Address(SP,  Interpreter::expr_offset_in_bytes(0));
   105   return tos;
   106 }
   108 static inline Address at_tos_p1() {
   109   return Address(SP,  Interpreter::expr_offset_in_bytes(1));
   110 }
   112 static inline Address at_tos_p2() {
   113   return Address(SP,  Interpreter::expr_offset_in_bytes(2));
   114 }
   116 static inline Address at_tos_p3() {
   117   return Address(SP,  Interpreter::expr_offset_in_bytes(3));
   118 }
   120 // we use S0 as bcp, be sure you have bcp in S0 before you call any of the Template generator 
   121 Address TemplateTable::at_bcp(int offset) {
   122   assert(_desc->uses_bcp(), "inconsistent uses_bcp information");
   123   return Address(BCP, offset);
   124 }
   126 #define callee_saved_register(R) assert((R>=S0 && R<=S7), "should use callee saved registers!")
   128 // bytecode folding
   129 void TemplateTable::patch_bytecode(Bytecodes::Code bc, Register bc_reg,
   130                                    Register tmp_reg, 
   131                                    bool load_bc_into_bc_reg,/*=true*/
   132                                    int byte_no) {
   133   if (!RewriteBytecodes) {
   134     return;
   135   }
   137   Label L_patch_done;
   138   switch (bc) {
   139   case Bytecodes::_fast_aputfield:
   140   case Bytecodes::_fast_bputfield:
   141   case Bytecodes::_fast_cputfield:
   142   case Bytecodes::_fast_dputfield:
   143   case Bytecodes::_fast_fputfield:
   144   case Bytecodes::_fast_iputfield:
   145   case Bytecodes::_fast_lputfield:
   146   case Bytecodes::_fast_sputfield:
   147     {
   148     // We skip bytecode quickening for putfield instructions when the put_code written to the constant pool cache
   149     // is zero. This is required so that every execution of this instruction calls out to 
   150     // InterpreterRuntime::resolve_get_put to do additional, required work.
   151     assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
   152     assert(load_bc_into_bc_reg, "we use bc_reg as temp");
   153     __ get_cache_and_index_and_bytecode_at_bcp(tmp_reg, bc_reg, tmp_reg, byte_no, 1);
   154     __ daddi(bc_reg, R0, bc);
   155     __ beq(tmp_reg, R0, L_patch_done);
   156     __ delayed()->nop();
   157     }
   158     break;
   159   default:
   160     assert(byte_no == -1, "sanity");
   161  // the pair bytecodes have already done the load.
   162   if (load_bc_into_bc_reg) {
   163     __ move(bc_reg, bc);
   164   }
   166   }
   167   if (JvmtiExport::can_post_breakpoint()) {
   168     Label L_fast_patch;
   169     // if a breakpoint is present we can't rewrite the stream directly
   170     __ lbu(tmp_reg, at_bcp(0));
   171     __ move(AT, Bytecodes::_breakpoint);
   172     __ bne(tmp_reg, AT, L_fast_patch);
   173     __ delayed()->nop();
   175     __ get_method(tmp_reg);
   176     // Let breakpoint table handling rewrite to quicker bytecode 
   177     __ call_VM(NOREG, CAST_FROM_FN_PTR(address, 
   178 	  InterpreterRuntime::set_original_bytecode_at), tmp_reg, BCP, bc_reg);
   180     __ b(L_patch_done);
   181     __ delayed()->nop();
   182     __ bind(L_fast_patch);
   183   }
   185 #ifdef ASSERT
   186   Label L_okay;
   187   __ lbu(tmp_reg, at_bcp(0));
   188   __ move(AT, (int)Bytecodes::java_code(bc));
   189   __ beq(tmp_reg, AT, L_okay);
   190   __ delayed()->nop();
   191   __ beq(tmp_reg, bc_reg, L_patch_done);
   192   __ delayed()->nop();
   193   __ stop("patching the wrong bytecode");
   194   __ bind(L_okay);
   195 #endif
   197   // patch bytecode
   198   __ sb(bc_reg, at_bcp(0));
   199   __ bind(L_patch_done);
   200 }
   203 // Individual instructions
   205 void TemplateTable::nop() {
   206   transition(vtos, vtos);
   207   // nothing to do
   208 }
   210 void TemplateTable::shouldnotreachhere() {
   211   transition(vtos, vtos);
   212   __ stop("shouldnotreachhere bytecode");
   213 }
   215 void TemplateTable::aconst_null() {
   216   transition(vtos, atos);
   217   __ move(FSR, R0);
   218 }
   220 void TemplateTable::iconst(int value) {
   221   transition(vtos, itos);
   222   if (value == 0) {
   223     __ move(FSR, R0);
   224   } else {
   225     __ move(FSR, value);
   226   }
   227 }
   229 void TemplateTable::lconst(int value) {
   230   transition(vtos, ltos);
   231   if (value == 0) {
   232     __ move(FSR, R0);
   233   } else {
   234     __ move(FSR, value);
   235   }
   236   assert(value >= 0, "check this code");
   237   //__ move(SSR, R0);
   238 }
   240 void TemplateTable::fconst(int value) {
   241   static float  _f1 = 1.0, _f2 = 2.0;
   242   transition(vtos, ftos);
   243   float* p;
   244   switch( value ) {
   245     default: ShouldNotReachHere();
   246     case 0:  __ dmtc1(R0, FSF);  return;
   247     case 1:  p = &_f1;   break;
   248     case 2:  p = &_f2;   break;
   249   }
   250   __ li(AT, (address)p);
   251   __ lwc1(FSF, AT, 0);
   252 }
   254 void TemplateTable::dconst(int value) {
   255   static double _d1 = 1.0;
   256   transition(vtos, dtos);
   257   double* p;
   258   switch( value ) {
   259     default: ShouldNotReachHere();
   260     case 0:  __ dmtc1(R0, FSF);  return;
   261     case 1:  p = &_d1;   break;
   262   }
   263   __ li(AT, (address)p);
   264   __ ldc1(FSF, AT, 0);
   265 }
   267 void TemplateTable::bipush() {
   268   transition(vtos, itos);
   269   __ lb(FSR, at_bcp(1));
   270 }
   272 void TemplateTable::sipush() {
   273 	transition(vtos, itos);
   274 	__ get_2_byte_integer_at_bcp(FSR, AT, 1);
   275 	__ hswap(FSR);
   276 }
   278 // T1 : tags
   279 // T2 : index
   280 // T3 : cpool
   281 // T8 : tag
   282 void TemplateTable::ldc(bool wide) {
   283   transition(vtos, vtos);
   284   Label call_ldc, notFloat, notClass, Done;
   285   // get index in cpool
   286   if (wide) {
   287     __ get_2_byte_integer_at_bcp(T2, AT, 1);
   288     __ huswap(T2);
   289   } else {
   290     __ lbu(T2, at_bcp(1));
   291   }
   293   __ get_cpool_and_tags(T3, T1);
   295   const int base_offset = ConstantPool::header_size() * wordSize;
   296   const int tags_offset = Array<u1>::base_offset_in_bytes();
   298   // get type
   299   __ dadd(AT, T1, T2);
   300   __ lb(T1, AT, tags_offset);
   301   //now T1 is the tag
   303   // unresolved string - get the resolved string
   304   /*__ daddiu(AT, T1, - JVM_CONSTANT_UnresolvedString);
   305   __ beq(AT, R0, call_ldc);
   306   __ delayed()->nop();*/
   308   // unresolved class - get the resolved class
   309   __ daddiu(AT, T1, - JVM_CONSTANT_UnresolvedClass);
   310   __ beq(AT, R0, call_ldc);
   311   __ delayed()->nop();
   313   // unresolved class in error (resolution failed) - call into runtime
   314   // so that the same error from first resolution attempt is thrown.
   315   __ daddiu(AT, T1, -JVM_CONSTANT_UnresolvedClassInError); 
   316   __ beq(AT, R0, call_ldc);
   317   __ delayed()->nop();
   319   // resolved class - need to call vm to get java mirror of the class
   320   __ daddiu(AT, T1, - JVM_CONSTANT_Class);
   321   __ bne(AT, R0, notClass);
   322   __ delayed()->dsll(T2, T2, Address::times_8);
   324   __ bind(call_ldc);
   326   __ move(A1, wide);
   327   call_VM(FSR, CAST_FROM_FN_PTR(address, InterpreterRuntime::ldc), A1);
   328   //	__ sw(FSR, SP, - 1 * wordSize);
   329   __ push(atos);	
   330   __ b(Done);
   331   //	__ delayed()->daddi(SP, SP, - 1 * wordSize);
   332   __ delayed()->nop();
   333   __ bind(notClass);
   335   __ daddiu(AT, T1, -JVM_CONSTANT_Float);
   336   __ bne(AT, R0, notFloat);
   337   __ delayed()->nop();
   338   // ftos
   339   __ dadd(AT, T3, T2);
   340   __ lwc1(FSF, AT, base_offset);
   341   __ push_f();
   342   __ b(Done);
   343   __ delayed()->nop();
   345   __ bind(notFloat);
   346 #ifdef ASSERT
   347   { 
   348     Label L;
   349     __ daddiu(AT, T1, -JVM_CONSTANT_Integer);
   350     __ beq(AT, R0, L);
   351     __ delayed()->nop();
   352     __ stop("unexpected tag type in ldc");
   353     __ bind(L);
   354   }
   355 #endif
   356   // atos and itos
   357   __ dadd(T0, T3, T2);
   358   __ lw(FSR, T0, base_offset);
   359   __ push(itos);
   360   __ b(Done);
   361   __ delayed()->nop(); 
   364   if (VerifyOops) {
   365     __ verify_oop(FSR);
   366   }
   368   __ bind(Done);
   369 }
   371 // Fast path for caching oop constants.
   372 void TemplateTable::fast_aldc(bool wide) {
   373   transition(vtos, atos);
   375   Register result = FSR;
   376   Register tmp = SSR;
   377   int index_size = wide ? sizeof(u2) : sizeof(u1);
   379   Label resolved;
   380  // We are resolved if the resolved reference cache entry contains a
   381  // non-null object (String, MethodType, etc.)
   382   assert_different_registers(result, tmp);
   383   __ get_cache_index_at_bcp(tmp, 1, index_size);
   384   __ load_resolved_reference_at_index(result, tmp);
   385   __ bne(result, R0, resolved);
   386   __ delayed()->nop();
   388   address entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_ldc);
   389   // first time invocation - must resolve first
   390   int i = (int)bytecode();
   391   __ move(tmp, i);
   392   __ call_VM(result, entry, tmp);
   394   __ bind(resolved);
   396   if (VerifyOops) {
   397     __ verify_oop(result);
   398   }
   399 }
   402 // used register: T2, T3, T1
   403 // T2 : index
   404 // T3 : cpool
   405 // T1 : tag
   406 void TemplateTable::ldc2_w() {
   407   transition(vtos, vtos);
   408   Label Long, Done;
   410   // get index in cpool
   411   __ get_2_byte_integer_at_bcp(T2, AT, 1);
   412   __ huswap(T2);
   414   __ get_cpool_and_tags(T3, T1);
   416   const int base_offset = ConstantPool::header_size() * wordSize;
   417   const int tags_offset = Array<u1>::base_offset_in_bytes();
   419   // get type in T1
   420   __ dadd(AT, T1, T2);
   421   __ lb(T1, AT, tags_offset);
   423   __ daddiu(AT, T1, - JVM_CONSTANT_Double);
   424   __ bne(AT, R0, Long);
   425   __ delayed()->dsll(T2, T2, Address::times_8);
   426   // dtos	
   427   __ daddu(AT, T3, T2);
   428   __ ldc1(FSF, AT, base_offset + 0 * wordSize);
   429   __ sdc1(FSF, SP, - 2 * wordSize);
   430   __ b(Done);
   431   __ delayed()->daddi(SP, SP, - 2 * wordSize);
   433   // ltos
   434   __ bind(Long);
   435   __ dadd(AT, T3, T2);	
   436   __ ld(FSR, AT, base_offset + 0 * wordSize);
   437   __ push(ltos);
   439   __ bind(Done);
   440 }
   442 // we compute the actual local variable address here
   443 // the x86 dont do so for it has scaled index memory access model, we dont have, so do here
   444 void TemplateTable::locals_index(Register reg, int offset) {
   445   __ lbu(reg, at_bcp(offset));
   446   __ dsll(reg, reg, Address::times_8);
   447   __ dsub(reg, LVP, reg);
   448 }
   450 // this method will do bytecode folding of the two form:
   451 // iload iload			iload caload
   452 // used register : T2, T3
   453 // T2 : bytecode
   454 // T3 : folded code
   455 void TemplateTable::iload() {
   456   transition(vtos, itos);
   457   if (RewriteFrequentPairs) { 
   458     Label rewrite, done;
   459     // get the next bytecode in T2
   460     __ lbu(T2, at_bcp(Bytecodes::length_for(Bytecodes::_iload)));
   461     // if _iload, wait to rewrite to iload2.  We only want to rewrite the
   462     // last two iloads in a pair.  Comparing against fast_iload means that
   463     // the next bytecode is neither an iload or a caload, and therefore
   464     // an iload pair.
   465     __ move(AT, Bytecodes::_iload);
   466     __ beq(AT, T2, done);
   467     __ delayed()->nop();
   469     __ move(T3, Bytecodes::_fast_iload2);
   470     __ move(AT, Bytecodes::_fast_iload);
   471     __ beq(AT, T2, rewrite);
   472     __ delayed()->nop();
   474     // if _caload, rewrite to fast_icaload
   475     __ move(T3, Bytecodes::_fast_icaload);
   476     __ move(AT, Bytecodes::_caload);
   477     __ beq(AT, T2, rewrite);
   478     __ delayed()->nop();
   480     // rewrite so iload doesn't check again.
   481     __ move(T3, Bytecodes::_fast_iload);
   483     // rewrite
   484     // T3 : fast bytecode
   485     __ bind(rewrite);
   486     patch_bytecode(Bytecodes::_iload, T3, T2, false);
   487     __ bind(done);
   488   }
   490   // Get the local value into tos
   491   locals_index(T2);
   492   __ lw(FSR, T2, 0);
   493 }
   495 // used register T2
   496 // T2 : index
   497 void TemplateTable::fast_iload2() {
   498 	transition(vtos, itos);
   499 	locals_index(T2);
   500 	__ lw(FSR, T2, 0);
   501 	__ push(itos);
   502 	locals_index(T2, 3);
   503 	__ lw(FSR, T2, 0);
   504 }
   506 // used register T2
   507 // T2 : index
   508 void TemplateTable::fast_iload() {
   509   transition(vtos, itos);
   510   locals_index(T2);
   511   __ lw(FSR, T2, 0);
   512 }
   514 // used register T2
   515 // T2 : index
   516 void TemplateTable::lload() {
   518   transition(vtos, ltos);
   519   locals_index(T2);
   520   __ ld(FSR, T2, -wordSize);
   521   __ ld(SSR, T2, 0);
   522 }
   524 // used register T2
   525 // T2 : index
   526 void TemplateTable::fload() {
   527   transition(vtos, ftos);
   528   locals_index(T2);
   529 //FIXME, aoqi. How should the high 32bits be when store a single float into a 64bits register. 
   530   //__ mtc1(R0, FSF);
   531   __ lwc1(FSF, T2, 0);
   532 }
   534 // used register T2
   535 // T2 : index
   536 void TemplateTable::dload() {
   538   transition(vtos, dtos);
   539   locals_index(T2);
   540 /*  if (TaggedStackInterpreter) {
   541     // Get double out of locals array, onto temp stack and load with
   542     // float instruction into ST0
   543     __ dsll(AT,T2,Interpreter::stackElementScale());
   544     __ dadd(AT, LVP, AT);
   545     __ ldc1(FSF, AT, Interpreter::local_offset_in_bytes(1)); 
   546   } else {*/
   547     __ ldc1(FSF, T2, -wordSize);
   548     __ ldc1(SSF, T2, 0);
   549  // }
   550 }
   552 // used register T2
   553 // T2 : index
   554 void TemplateTable::aload() 
   555 {
   556   transition(vtos, atos);
   557   locals_index(T2);
   558   __ ld(FSR, T2, 0);
   559 }
   561 void TemplateTable::locals_index_wide(Register reg) {
   562   __ get_2_byte_integer_at_bcp(reg, AT, 2);
   563   __ huswap(reg);
   564   __ dsll(reg, reg, Address::times_8);
   565   __ dsub(reg, LVP, reg);
   566 }
   568 // used register T2
   569 // T2 : index
   570 void TemplateTable::wide_iload() {
   571 	transition(vtos, itos);
   572 	locals_index_wide(T2);
   573 	__ ld(FSR, T2, 0);
   574 }
   576 // used register T2
   577 // T2 : index
   578 void TemplateTable::wide_lload() {
   579 	transition(vtos, ltos);
   580 	locals_index_wide(T2);
   581 	__ ld(FSR, T2, -4);
   582 }
   584 // used register T2
   585 // T2 : index
   586 void TemplateTable::wide_fload() {
   587 	transition(vtos, ftos);
   588 	locals_index_wide(T2);
   589 	__ lwc1(FSF, T2, 0);
   590 }
   592 // used register T2
   593 // T2 : index
   594 void TemplateTable::wide_dload() {
   595 	transition(vtos, dtos);
   596 	locals_index_wide(T2);
   597 /*	if (TaggedStackInterpreter) {
   598 		// Get double out of locals array, onto temp stack and load with
   599 		// float instruction into ST0
   600 		//   __ movl(eax, laddress(ebx));
   601 		//  __ movl(edx, haddress(ebx));
   602 		__ dsll(AT,T2,Interpreter::stackElementScale());
   603 		__ dadd(AT, LVP, AT);
   604 		__ ldc1(FSF, AT, Interpreter::local_offset_in_bytes(1)); 
   606 		//  __ pushl(edx);  // push hi first
   607 		//  __ pushl(eax);
   608 		//  __ fld_d(Address(esp));
   609 		//  __ addl(esp, 2*wordSize);
   610 	} else {*/
   611 		__ ldc1(FSF, T2, -4);
   612 	//}
   613 }
   615 // used register T2
   616 // T2 : index
   617 void TemplateTable::wide_aload() {
   618 	transition(vtos, atos);
   619 	locals_index_wide(T2);
   620 	__ ld(FSR, T2, 0);
   621 }
   623 // we use A2 as the regiser for index, BE CAREFUL!
   624 // we dont use our tge 29 now, for later optimization
   625 void TemplateTable::index_check(Register array, Register index) {
   626   // Pop ptr into array
   627   __ pop_ptr(array);
   628   index_check_without_pop(array, index);
   629 }
   631 void TemplateTable::index_check_without_pop(Register array, Register index) {
   632   // destroys ebx
   633   // check array
   634   __ null_check(array, arrayOopDesc::length_offset_in_bytes());
   636   // check index
   637   Label ok;
   638   __ lw(AT, array, arrayOopDesc::length_offset_in_bytes());
   639 #ifndef OPT_RANGECHECK
   640   __ sltu(AT, index, AT);
   641   __ bne(AT, R0, ok);
   642   __ delayed()->nop(); 
   644   //throw_ArrayIndexOutOfBoundsException assume abberrant index in A2
   645   if (A2 != index) __ move(A2, index);		
   646   __ jmp(Interpreter::_throw_ArrayIndexOutOfBoundsException_entry);
   647   __ delayed()->nop();
   648   __ bind(ok);
   649 #else
   650   __ lw(AT, array, arrayOopDesc::length_offset_in_bytes());
   651   __ move(A2, index);
   652   __ tgeu(A2, AT, 29);
   653 #endif
   654 }
   656 void TemplateTable::iaload() {
   657   transition(itos, itos);
   658   //  __ pop(SSR);
   659   index_check(SSR, FSR);
   660   __ dsll(FSR, FSR, 2);
   661   __ dadd(FSR, SSR, FSR);
   662   //FSR: index
   663   __ lw(FSR, FSR, arrayOopDesc::base_offset_in_bytes(T_INT));
   664 }
   667 void TemplateTable::laload() {
   668   transition(itos, ltos);
   669   //  __ pop(SSR);
   670   index_check(SSR, FSR);
   671   __ dsll(AT, FSR, Address::times_8);
   672   __ dadd(AT, SSR, AT);
   673   __ ld(FSR, AT, arrayOopDesc::base_offset_in_bytes(T_LONG) + 0 * wordSize);
   674 }
   676 void TemplateTable::faload() {
   677 	transition(itos, ftos);
   678 	// __ pop(SSR);
   679 	index_check(SSR, FSR);  
   680 	__ shl(FSR, 2);
   681 	__ dadd(FSR, SSR, FSR);
   682 	__ lwc1(FSF, FSR, arrayOopDesc::base_offset_in_bytes(T_FLOAT));
   683 }
   685 void TemplateTable::daload() {
   686 	transition(itos, dtos);
   687 	//__ pop(SSR);
   688 	index_check(SSR, FSR);  
   689 	__ dsll(AT, FSR, 3);
   690 	__ dadd(AT, SSR, AT);
   691 	__ ldc1(FSF, AT, arrayOopDesc::base_offset_in_bytes(T_DOUBLE) + 0 * wordSize);
   692 }
   694 void TemplateTable::aaload() {
   695   transition(itos, atos);
   696   //__ pop(SSR);
   697   index_check(SSR, FSR);
   698   __ dsll(FSR, FSR, UseCompressedOops ? Address::times_4 : Address::times_8);
   699   __ dadd(FSR, SSR, FSR);
   700   //add for compressedoops
   701   __ load_heap_oop(FSR, Address(FSR, arrayOopDesc::base_offset_in_bytes(T_OBJECT)));
   702 }
   704 void TemplateTable::baload() {
   705   transition(itos, itos);
   706   //__ pop(SSR);
   707   index_check(SSR, FSR); 
   708   __ dadd(FSR, SSR, FSR);
   709   __ lb(FSR, FSR, arrayOopDesc::base_offset_in_bytes(T_BYTE));
   710 }
   712 void TemplateTable::caload() {
   713   transition(itos, itos);
   714   // __ pop(SSR);
   715   index_check(SSR, FSR);
   716   __ dsll(FSR, FSR, Address::times_2);
   717   __ dadd(FSR, SSR, FSR);
   718   __ lhu(FSR, FSR,  arrayOopDesc::base_offset_in_bytes(T_CHAR));
   719 }
   721 // iload followed by caload frequent pair
   722 // used register : T2
   723 // T2 : index
   724 void TemplateTable::fast_icaload() {
   725   transition(vtos, itos);
   726   // load index out of locals
   727   locals_index(T2);
   728   __ lw(FSR, T2, 0);
   729   //	__ pop(SSR);
   730   index_check(SSR, FSR);
   731   __ dsll(FSR, FSR, 1);
   732   __ dadd(FSR, SSR, FSR);
   733   __ lhu(FSR, FSR,  arrayOopDesc::base_offset_in_bytes(T_CHAR));
   734 }
   736 void TemplateTable::saload() {
   737   transition(itos, itos);
   738   // __ pop(SSR);
   739   index_check(SSR, FSR);  
   740   __ dsll(FSR, FSR, Address::times_2);
   741   __ dadd(FSR, SSR, FSR);
   742   __ lh(FSR, FSR,  arrayOopDesc::base_offset_in_bytes(T_SHORT));
   743 }
   745 void TemplateTable::iload(int n) {
   746 	transition(vtos, itos);
   747 	__ lw(FSR, iaddress(n));
   748 }
   750 void TemplateTable::lload(int n) {
   751 	transition(vtos, ltos);
   752 	__ ld(FSR, laddress(n));
   753 }
   755 void TemplateTable::fload(int n) {
   756   transition(vtos, ftos);
   757   //__ mtc1(R0, FSF);
   758   __ lwc1(FSF, faddress(n));
   759 }
   760 //FIXME here
   761 void TemplateTable::dload(int n) {
   762 	transition(vtos, dtos);
   763 	__ ldc1(FSF, laddress(n));
   764 }
   766 void TemplateTable::aload(int n) {
   767   transition(vtos, atos);
   768   __ ld(FSR, aaddress(n));
   769 }
   771 // used register : T2, T3
   772 // T2 : bytecode
   773 // T3 : folded code
   774 void TemplateTable::aload_0() {
   775 	transition(vtos, atos);
   776 	// According to bytecode histograms, the pairs:
   777 	//
   778 	// _aload_0, _fast_igetfield
   779 	// _aload_0, _fast_agetfield
   780 	// _aload_0, _fast_fgetfield
   781 	//
   782 	// occur frequently. If RewriteFrequentPairs is set, the (slow) _aload_0
   783 	// bytecode checks if the next bytecode is either _fast_igetfield, 
   784 	// _fast_agetfield or _fast_fgetfield and then rewrites the
   785 	// current bytecode into a pair bytecode; otherwise it rewrites the current
   786 	// bytecode into _fast_aload_0 that doesn't do the pair check anymore.
   787 	//
   788 	// Note: If the next bytecode is _getfield, the rewrite must be delayed,
   789 	//       otherwise we may miss an opportunity for a pair.
   790 	//
   791 	// Also rewrite frequent pairs
   792 	//   aload_0, aload_1
   793 	//   aload_0, iload_1
   794 	// These bytecodes with a small amount of code are most profitable to rewrite
   795 	if (RewriteFrequentPairs) {
   796 		Label rewrite, done;
   797 		// get the next bytecode in T2
   798 		__ lbu(T2, at_bcp(Bytecodes::length_for(Bytecodes::_aload_0)));
   800 		// do actual aload_0
   801 		aload(0);
   803 		// if _getfield then wait with rewrite
   804 		__ move(AT, Bytecodes::_getfield);
   805 		__ beq(AT, T2, done);
   806 		__ delayed()->nop();
   808 		// if _igetfield then reqrite to _fast_iaccess_0
   809 		assert(Bytecodes::java_code(Bytecodes::_fast_iaccess_0) == 
   810 				Bytecodes::_aload_0, "fix bytecode definition");
   811 		__ move(T3, Bytecodes::_fast_iaccess_0);
   812 		__ move(AT, Bytecodes::_fast_igetfield);
   813 		__ beq(AT, T2, rewrite);
   814 		__ delayed()->nop();
   816 		// if _agetfield then reqrite to _fast_aaccess_0
   817 		assert(Bytecodes::java_code(Bytecodes::_fast_aaccess_0) == 
   818 				Bytecodes::_aload_0, "fix bytecode definition");
   819 		__ move(T3, Bytecodes::_fast_aaccess_0);
   820 		__ move(AT, Bytecodes::_fast_agetfield);
   821 		__ beq(AT, T2, rewrite);
   822 		__ delayed()->nop();
   824 		// if _fgetfield then reqrite to _fast_faccess_0
   825 		assert(Bytecodes::java_code(Bytecodes::_fast_faccess_0) == 
   826 				Bytecodes::_aload_0, "fix bytecode definition");
   827 		__ move(T3, Bytecodes::_fast_faccess_0);
   828 		__ move(AT, Bytecodes::_fast_fgetfield);
   829 		__ beq(AT, T2, rewrite);
   830 		__ delayed()->nop();
   832 		// else rewrite to _fast_aload0
   833 		assert(Bytecodes::java_code(Bytecodes::_fast_aload_0) == 
   834 				Bytecodes::_aload_0, "fix bytecode definition");
   835 		__ move(T3, Bytecodes::_fast_aload_0);
   837 		// rewrite
   838 		__ bind(rewrite);
   839 		patch_bytecode(Bytecodes::_aload_0, T3, T2, false);
   841 		__ bind(done);
   842 	} else {
   843 		aload(0);
   844 	}
   845 }
   847 void TemplateTable::istore() {
   848 	transition(itos, vtos);
   849 	locals_index(T2);
   850 	__ sw(FSR, T2, 0);
   851 }
   853 void TemplateTable::lstore() {
   854   transition(ltos, vtos);
   855   locals_index(T2);
   856   __ sd(FSR, T2, -wordSize);
   857 }
   859 void TemplateTable::fstore() {
   860 	transition(ftos, vtos);
   861 	locals_index(T2);
   862 	__ swc1(FSF, T2, 0);
   863 }
   865 void TemplateTable::dstore() {
   866   transition(dtos, vtos);
   867   locals_index(T2);
   868   __ sdc1(FSF, T2, -wordSize);
   869 }
   871 void TemplateTable::astore() {
   872   transition(vtos, vtos);
   873   //  __ pop(FSR);
   874   __ pop_ptr(FSR);
   875   locals_index(T2);
   876   __ sd(FSR, T2, 0);
   877 }
   879 void TemplateTable::wide_istore() {
   880 	transition(vtos, vtos);
   881 	//  __ pop(FSR);
   882 	__ pop_i(FSR);
   883 	locals_index_wide(T2);
   884 	__ sd(FSR, T2, 0);
   885 }
   887 void TemplateTable::wide_lstore() {
   888 	transition(vtos, vtos);
   889 	//__ pop2(FSR, SSR);
   890 	//__ pop_l(FSR, SSR); 
   891 	__ pop_l(FSR); //aoqi:FIXME Is this right?
   892 	locals_index_wide(T2);
   893 	__ sd(FSR, T2, -4);
   894 }
   896 void TemplateTable::wide_fstore() {
   897 	wide_istore();
   898 }
   900 void TemplateTable::wide_dstore() {
   901 	wide_lstore();
   902 }
   904 void TemplateTable::wide_astore() {
   905 	transition(vtos, vtos);
   906 	__ pop_ptr(FSR);
   907 	locals_index_wide(T2);
   908 	__ sd(FSR, T2, 0);
   909 }
   911 // used register : T2
   912 void TemplateTable::iastore() {
   913   transition(itos, vtos);
   914   __ pop_i(SSR);
   915   index_check(T2, SSR);  // prefer index in ebx
   916   __ dsll(SSR, SSR, Address::times_4);
   917   __ dadd(T2, T2, SSR);
   918   __ sw(FSR, T2, arrayOopDesc::base_offset_in_bytes(T_INT));
   919 }
   923 // used register T2, T3
   924 void TemplateTable::lastore() {
   925   transition(ltos, vtos);
   926   __ pop_i (T2);
   927   index_check(T3, T2);
   928   __ dsll(T2, T2, Address::times_8);
   929   __ dadd(T3, T3, T2);
   930   __ sd(FSR, T3, arrayOopDesc::base_offset_in_bytes(T_LONG) + 0 * wordSize);
   931 }
   933 // used register T2
   934 void TemplateTable::fastore() {
   935   transition(ftos, vtos);
   936   __ pop_i(SSR);	
   937   index_check(T2, SSR); 
   938   __ dsll(SSR, SSR, Address::times_4);
   939   __ dadd(T2, T2, SSR);
   940   __ swc1(FSF, T2, arrayOopDesc::base_offset_in_bytes(T_FLOAT));
   941 }
   943 // used register T2, T3
   944 void TemplateTable::dastore() {
   945   transition(dtos, vtos);
   946   __ pop_i (T2); 
   947   index_check(T3, T2);  
   948   __ dsll(T2, T2, Address::times_8);
   949   __ daddu(T3, T3, T2);
   950   __ sdc1(FSF, T3, arrayOopDesc::base_offset_in_bytes(T_DOUBLE) + 0 * wordSize);
   952 }
   954 // used register : T2, T3, T8
   955 // T2 : array
   956 // T3 : subklass
   957 // T8 : supklass
   958 void TemplateTable::aastore() {
   959   Label is_null, ok_is_subtype, done;
   960   transition(vtos, vtos);
   961   // stack: ..., array, index, value
   962   __ ld(FSR, at_tos());     // Value
   963   __ lw(SSR, at_tos_p1());  // Index
   964   __ ld(T2, at_tos_p2());  // Array
   966   // index_check(T2, SSR);
   967   index_check_without_pop(T2, SSR);
   968   // do array store check - check for NULL value first
   969   __ beq(FSR, R0, is_null);
   970   __ delayed()->nop();
   972   // Move subklass into T3
   973   //__ ld(T3,  Address(FSR, oopDesc::klass_offset_in_bytes()));
   974   //add for compressedoops
   975   __ load_klass(T3, FSR);
   976   // Move superklass into T8
   977   //__ ld(T8, Address(T2, oopDesc::klass_offset_in_bytes()));
   978   //add for compressedoops
   979   __ load_klass(T8, T2);
   980   __ ld(T8, Address(T8,  ObjArrayKlass::element_klass_offset()));
   981   // Compress array+index*4+12 into a single register. T2
   982   __ dsll(AT, SSR, UseCompressedOops? Address::times_4 : Address::times_8);
   983   __ dadd(T2, T2, AT);
   984   __ daddi(T2, T2, arrayOopDesc::base_offset_in_bytes(T_OBJECT));
   986   // Generate subtype check.
   987   // Superklass in T8.  Subklass in T3.
   988   __ gen_subtype_check(T8, T3, ok_is_subtype);				// <-- Jin
   989   // Come here on failure
   990   // object is at FSR
   991   __ jmp(Interpreter::_throw_ArrayStoreException_entry);    // <-- Jin
   992   __ delayed()->nop();
   993   // Come here on success
   994   __ bind(ok_is_subtype);
   995   //replace with do_oop_store->store_heap_oop
   996   //__ sd(FSR, T2, 0);
   997   __ store_heap_oop(Address(T2, 0), FSR);					// <-- Jin
   998   __ sync();
   999   __ store_check(T2);
  1000   __ b(done);
  1001   __ delayed()->nop();
  1003   // Have a NULL in FSR, EDX=T2, SSR=index.  Store NULL at ary[idx]
  1004   __ bind(is_null);
  1005   __ profile_null_seen(T9);
  1006   __ dsll(AT, SSR, UseCompressedOops? Address::times_4 : Address::times_8);
  1007   __ dadd(T2, T2, AT);
  1008   //__ sd(FSR, T2, arrayOopDesc::base_offset_in_bytes(T_OBJECT));
  1009   __ store_heap_oop(Address(T2, arrayOopDesc::base_offset_in_bytes(T_OBJECT)), FSR);	/* FSR is null here */
  1010   __ sync();
  1012   __ bind(done);
  1013   __ daddi(SP, SP, 3 * Interpreter::stackElementSize);
  1016 void TemplateTable::bastore() {
  1017   transition(itos, vtos);
  1018   __ pop_i (SSR); 
  1019   index_check(T2, SSR);
  1020   __ dadd(SSR, T2, SSR);
  1021   __ sb(FSR, SSR, arrayOopDesc::base_offset_in_bytes(T_BYTE));
  1024 void TemplateTable::castore() {
  1025   transition(itos, vtos);
  1026   __ pop_i(SSR); 
  1027   index_check(T2, SSR); 
  1028   __ dsll(SSR, SSR, Address::times_2);
  1029   __ dadd(SSR, T2, SSR);
  1030   __ sh(FSR, SSR, arrayOopDesc::base_offset_in_bytes(T_CHAR));
  1033 void TemplateTable::sastore() {
  1034   castore();
  1037 void TemplateTable::istore(int n) {
  1038   transition(itos, vtos);
  1039   __ sw(FSR, iaddress(n));
  1042 void TemplateTable::lstore(int n) {
  1043   transition(ltos, vtos);
  1044   __ sd(FSR, laddress(n));
  1047 void TemplateTable::fstore(int n) {
  1048   transition(ftos, vtos);
  1049   __ swc1(FSF, faddress(n));
  1052 void TemplateTable::dstore(int n) {
  1053   transition(dtos, vtos);
  1054   __ sdc1(FSF, laddress(n));
  1057 void TemplateTable::astore(int n) {
  1058   transition(vtos, vtos);
  1059   __ pop_ptr(FSR);
  1060   __ sd(FSR, aaddress(n));
  1063 void TemplateTable::pop() {
  1064   transition(vtos, vtos);
  1065   __ daddi(SP, SP, Interpreter::stackElementSize);
  1068 void TemplateTable::pop2() {
  1069   transition(vtos, vtos);
  1070   __ daddi(SP, SP, 2 * Interpreter::stackElementSize);
  1073 void TemplateTable::dup() {
  1074   transition(vtos, vtos);
  1075   // stack: ..., a
  1076   __ load_ptr(0, FSR);
  1077   __ push_ptr(FSR);
  1078   // stack: ..., a, a
  1081 // blows FSR
  1082 void TemplateTable::dup_x1() {
  1083 	transition(vtos, vtos);
  1084 	// stack: ..., a, b
  1085 	__ load_ptr(0, FSR);  // load b
  1086 	__ load_ptr(1, A5);  // load a
  1087 	__ store_ptr(1, FSR); // store b
  1088 	__ store_ptr(0, A5); // store a
  1089 	__ push_ptr(FSR);             // push b
  1090 	// stack: ..., b, a, b
  1093 // blows FSR
  1094 void TemplateTable::dup_x2() {
  1095 	transition(vtos, vtos);
  1096 	// stack: ..., a, b, c
  1097 	__ load_ptr(0, FSR);  // load c
  1098 	__ load_ptr(2, A5);  // load a
  1099 	__ store_ptr(2, FSR); // store c in a
  1100 	__ push_ptr(FSR);             // push c
  1101 	// stack: ..., c, b, c, c
  1102 	__ load_ptr(2, FSR);  // load b
  1103 	__ store_ptr(2, A5); // store a in b
  1104 	// stack: ..., c, a, c, c
  1105 	__ store_ptr(1, FSR); // store b in c
  1106 	// stack: ..., c, a, b, c
  1109 // blows FSR
  1110 void TemplateTable::dup2() {
  1111 	transition(vtos, vtos);
  1112 	// stack: ..., a, b
  1113 	__ load_ptr(1, FSR);  // load a
  1114 	__ push_ptr(FSR);             // push a
  1115 	__ load_ptr(1, FSR);  // load b
  1116 	__ push_ptr(FSR);             // push b
  1117 	// stack: ..., a, b, a, b
  1120 // blows FSR
  1121 void TemplateTable::dup2_x1() {
  1122 	transition(vtos, vtos);
  1123 	// stack: ..., a, b, c
  1124 	__ load_ptr(0, T2);  // load c
  1125 	__ load_ptr(1, FSR);  // load b
  1126 	__ push_ptr(FSR);             // push b
  1127 	__ push_ptr(T2);             // push c
  1128 	// stack: ..., a, b, c, b, c
  1129 	__ store_ptr(3, T2); // store c in b
  1130 	// stack: ..., a, c, c, b, c
  1131 	__ load_ptr(4, T2);  // load a
  1132 	__ store_ptr(2, T2); // store a in 2nd c
  1133 	// stack: ..., a, c, a, b, c
  1134 	__ store_ptr(4, FSR); // store b in a
  1135 	// stack: ..., b, c, a, b, c
  1137 	// stack: ..., b, c, a, b, c
  1140 // blows FSR, SSR
  1141 void TemplateTable::dup2_x2() {
  1142 	transition(vtos, vtos);
  1143 	// stack: ..., a, b, c, d
  1144 	// stack: ..., a, b, c, d
  1145 	__ load_ptr(0, T2);  // load d
  1146 	__ load_ptr(1, FSR);  // load c
  1147 	__ push_ptr(FSR);             // push c
  1148 	__ push_ptr(T2);             // push d
  1149 	// stack: ..., a, b, c, d, c, d
  1150 	__ load_ptr(4, FSR);  // load b
  1151 	__ store_ptr(2, FSR); // store b in d
  1152 	__ store_ptr(4, T2); // store d in b
  1153 	// stack: ..., a, d, c, b, c, d
  1154 	__ load_ptr(5, T2);  // load a
  1155 	__ load_ptr(3, FSR);  // load c
  1156 	__ store_ptr(3, T2); // store a in c
  1157 	__ store_ptr(5, FSR); // store c in a
  1158 	// stack: ..., c, d, a, b, c, d
  1160 	// stack: ..., c, d, a, b, c, d
  1163 // blows FSR
  1164 void TemplateTable::swap() {
  1165 	transition(vtos, vtos);
  1166 	// stack: ..., a, b
  1168 	__ load_ptr(1, A5);  // load a
  1169 	__ load_ptr(0, FSR);  // load b
  1170 	__ store_ptr(0, A5); // store a in b
  1171 	__ store_ptr(1, FSR); // store b in a
  1173 	// stack: ..., b, a
  1176 void TemplateTable::iop2(Operation op) {
  1177 	transition(itos, itos);
  1178 	switch (op) {
  1179 		case add  :                    
  1180 			__ pop_i(SSR); 
  1181 			__ addu32(FSR, SSR, FSR); 
  1182 			break;
  1183 		case sub  :  
  1184 			__ pop_i(SSR); 
  1185 			__ subu32(FSR, SSR, FSR); 
  1186 			break;
  1187 		case mul  :                    
  1188 			__ lw(SSR, SP, 0);
  1189 			__ daddi(SP, SP, wordSize);
  1190                         __ mul(FSR, SSR, FSR);
  1191 			break;
  1192 		case _and :                    
  1193 			__ pop_i(SSR); 
  1194 			__ andr(FSR, SSR, FSR); 
  1195 			break;
  1196 		case _or  :                    
  1197 			__ pop_i(SSR); 
  1198 			__ orr(FSR, SSR, FSR); 
  1199 			break;
  1200 		case _xor :                    
  1201 			__ pop_i(SSR); 
  1202 			__ xorr(FSR, SSR, FSR); 
  1203 			break;
  1204 		case shl  : 
  1205 			__ pop_i(SSR); 
  1206 			__ sllv(FSR, SSR, FSR);      
  1207 			break; // implicit masking of lower 5 bits by Intel shift instr. mips also
  1208 		case shr  : 
  1209 			__ pop_i(SSR); 
  1210 			__ srav(FSR, SSR, FSR);      
  1211 			break; // implicit masking of lower 5 bits by Intel shift instr. mips also
  1212 		case ushr : 
  1213 			__ pop_i(SSR); 
  1214 			__ srlv(FSR, SSR, FSR);     
  1215 			break; // implicit masking of lower 5 bits by Intel shift instr. mips also
  1216 		default   : ShouldNotReachHere();
  1220 // the result stored in FSR, SSR,
  1221 // used registers : T2, T3
  1222 //FIXME, aoqi
  1223 void TemplateTable::lop2(Operation op) {
  1224   transition(ltos, ltos);
  1225   //__ pop2(T2, T3);
  1226   __ pop_l(T2, T3);
  1227 #ifdef ASSERT
  1229     Label  L;
  1230     __ beq(T3, R0, L);
  1231     __ delayed()->nop();
  1232     // FIXME: stack verification required
  1233 //    __ stop("lop2, wrong stack");  // <--- Fu 20130930
  1234     __ bind(L);
  1236 #endif
  1237   switch (op) {
  1238     case add : 
  1239       __ daddu(FSR, T2, FSR);
  1240       //__ sltu(AT, FSR, T2);
  1241       //__ daddu(SSR, T3, SSR);
  1242       //__ daddu(SSR, SSR, AT); 
  1243       break;
  1244     case sub :
  1245       __ dsubu(FSR, T2, FSR);
  1246       //__ sltu(AT, T2, FSR);
  1247       //__ dsubu(SSR, T3, SSR);
  1248       //__ dsubu(SSR, SSR, AT);
  1249       break;
  1250     case _and: 
  1251       __ andr(FSR, T2, FSR); 
  1252       //__ andr(SSR, T3, SSR); 
  1253       break;
  1254     case _or : 
  1255       __ orr(FSR, T2, FSR); 
  1256       //__ orr(SSR, T3, SSR); 
  1257       break;
  1258     case _xor: 
  1259       __ xorr(FSR, T2, FSR); 
  1260       //__ xorr(SSR, T3, SSR); 
  1261       break;
  1262     default : ShouldNotReachHere();
  1266 // java require this bytecode could handle 0x80000000/-1, dont cause a overflow exception, 
  1267 // the result is 0x80000000
  1268 // the godson2 cpu do the same, so we need not handle this specially like x86
  1269 void TemplateTable::idiv() {
  1270 	transition(itos, itos);
  1271 	Label not_zero;
  1273 	__ bne(FSR, R0, not_zero);
  1274 	__ delayed()->nop();
  1275 	__ jmp(Interpreter::_throw_ArithmeticException_entry); 
  1276 	__ delayed()->nop();
  1277 	__ bind(not_zero);
  1279 	__ pop_i(SSR);
  1280         if (UseLoongsonISA) {
  1281           __ gsdiv(FSR, SSR, FSR);
  1282         } else {
  1283 	  __ div(SSR, FSR);
  1284 	  __ mflo(FSR);
  1288 void TemplateTable::irem() {
  1289 	transition(itos, itos);
  1290 	Label not_zero;
  1291 	//__ pop(SSR);
  1292 	__ pop_i(SSR);
  1293 	__ div(SSR, FSR);
  1295 	__ bne(FSR, R0, not_zero);
  1296 	__ delayed()->nop();
  1297 	//__ brk(7);
  1298 	__ jmp(Interpreter::_throw_ArithmeticException_entry);
  1299 	__ delayed()->nop();
  1301 	__ bind(not_zero);
  1302 	__ mfhi(FSR);
  1305 void TemplateTable::lmul() {
  1306   transition(ltos, ltos);
  1307   __ pop_l(T2);
  1308   if(UseLoongsonISA){
  1309     __ gsdmult(FSR, T2, FSR);
  1310   } else {
  1311       __ dmult(T2, FSR);
  1312       __ mflo(FSR);
  1316 // NOTE: i DONT use the Interpreter::_throw_ArithmeticException_entry
  1317 void TemplateTable::ldiv() {
  1318   transition(ltos, ltos);
  1319   Label normal;
  1321   __ bne(FSR, R0, normal);
  1322   __ delayed()->nop();
  1324   //__ brk(7);		//generate FPE
  1325   __ jmp(Interpreter::_throw_ArithmeticException_entry);
  1326   __ delayed()->nop();
  1328   __ bind(normal);
  1329   __ pop_l(A2, A3);
  1330   if (UseLoongsonISA) {
  1331     __ gsddiv(FSR, A2, FSR);	
  1332   } else {
  1333     __ ddiv(A2, FSR);
  1334     __ mflo(FSR);
  1338 // NOTE: i DONT use the Interpreter::_throw_ArithmeticException_entry
  1339 void TemplateTable::lrem() {
  1340   transition(ltos, ltos);
  1341   Label normal;
  1343   __ bne(FSR, R0, normal);
  1344   __ delayed()->nop();
  1346   __ jmp(Interpreter::_throw_ArithmeticException_entry);
  1347   __ delayed()->nop();
  1349   __ bind(normal);
  1350   __ pop_l (A2, A3); 
  1352   if(UseLoongsonISA){
  1353     __ gsdmod(FSR, A2, FSR);
  1354   } else { 
  1355     __ ddiv(A2, FSR);
  1356     __ mfhi(FSR);
  1360 // result in FSR
  1361 // used registers : T0
  1362 void TemplateTable::lshl() {
  1363   transition(itos, ltos);
  1364   __ pop_l(T0, T1);	
  1365 #ifdef ASSERT
  1367     Label  L;
  1368     __ beq(T1, R0, L);
  1369     __ delayed()->nop();
  1370     //__ stop("lshl, wrong stack");  // <-- Fu 20130930 
  1371     __ bind(L);
  1373 #endif
  1374   __ andi(FSR, FSR, 0x3f);	      // the bit to be shifted
  1375   __ dsllv(FSR, T0, FSR);
  1378 // used registers : T0
  1379 void TemplateTable::lshr() {
  1380   transition(itos, ltos);
  1381   __ pop_l(T0, T1);	
  1382 #ifdef ASSERT
  1384     Label  L;
  1385     __ beq(T1, R0, L);
  1386     __ delayed()->nop();
  1387     __ stop("lshr, wrong stack");
  1388     __ bind(L);
  1390 #endif
  1391   __ andi(FSR, FSR, 0x3f);				// the bit to be shifted
  1392   __ dsrav(FSR, T0, FSR);
  1395 // used registers : T0
  1396 void TemplateTable::lushr() {
  1397   transition(itos, ltos);
  1398   __ pop_l(T0, T1);	
  1399 #ifdef ASSERT
  1401     Label  L;
  1402     __ beq(T1, R0, L);
  1403     __ delayed()->nop();
  1404     __ stop("lushr, wrong stack");
  1405     __ bind(L);
  1407 #endif
  1408   __ andi(FSR, FSR, 0x3f);				// the bit to be shifted
  1409   __ dsrlv(FSR, T0, FSR);
  1412 // result in FSF
  1413 void TemplateTable::fop2(Operation op) {
  1414 	transition(ftos, ftos);
  1415 	__ pop_ftos_to_esp();  // pop ftos into esp
  1416 	switch (op) {
  1417 		case add:
  1418 			__ lwc1(FTF, at_sp());
  1419 			__ add_s(FSF, FTF, FSF);
  1420 			break;
  1421 		case sub: 
  1422 			__ lwc1(FTF, at_sp());
  1423 			__ sub_s(FSF, FTF, FSF);
  1424 			break;
  1425 		case mul: 
  1426 			__ lwc1(FTF, at_sp());
  1427 			__ mul_s(FSF, FTF, FSF);
  1428 			break;
  1429 		case div: 
  1430 			__ lwc1(FTF, at_sp());
  1431 			__ div_s(FSF, FTF, FSF);
  1432 			break;
  1433 		case rem: 
  1434 			__ mfc1(FSR, FSF);
  1435 			__ mtc1(FSR, F12);
  1436 			__ lwc1(FTF, at_sp());
  1437 			__ rem_s(FSF, FTF, F12, FSF);
  1438 			break;
  1439 		default : ShouldNotReachHere();
  1442 	__ daddi(SP, SP, 1 * wordSize);
  1445 // result in SSF||FSF
  1446 // i dont handle the strict flags
  1447 void TemplateTable::dop2(Operation op) {
  1448 	transition(dtos, dtos);
  1449 	__ pop_dtos_to_esp();  // pop dtos into esp
  1450 	switch (op) {
  1451 		case add: 
  1452 			__ ldc1(FTF, at_sp());
  1453 			__ add_d(FSF, FTF, FSF);
  1454 			break;
  1455 		case sub: 
  1456 			__ ldc1(FTF, at_sp());
  1457 			__ sub_d(FSF, FTF, FSF);
  1458 			break;
  1459 		case mul: 
  1460 			__ ldc1(FTF, at_sp());
  1461 			__ mul_d(FSF, FTF, FSF);
  1462 			break;
  1463 		case div:
  1464 			__ ldc1(FTF, at_sp());
  1465 			__ div_d(FSF, FTF, FSF);
  1466 			break;
  1467 		case rem:
  1468 			__ dmfc1(FSR, FSF);
  1469 			__ dmtc1(FSR, F12);
  1470 			__ ldc1(FTF, at_sp());
  1471 			__ rem_d(FSF, FTF, F12, FSF);
  1472 			break;
  1473 		default : ShouldNotReachHere();
  1476 	__ daddi(SP, SP, 2 * wordSize);
  1479 void TemplateTable::ineg() {
  1480 	transition(itos, itos);
  1481 	__ neg(FSR);
  1484 void TemplateTable::lneg() {
  1485 	transition(ltos, ltos);
  1486 	__ dsubu(FSR, R0, FSR);
  1488 /*
  1489 // Note: 'double' and 'long long' have 32-bits alignment on x86.
  1490 static jlong* double_quadword(jlong *adr, jlong lo, jlong hi) {
  1491   // Use the expression (adr)&(~0xF) to provide 128-bits aligned address
  1492   // of 128-bits operands for SSE instructions.
  1493   jlong *operand = (jlong*)(((intptr_t)adr)&((intptr_t)(~0xF)));
  1494   // Store the value to a 128-bits operand.
  1495   operand[0] = lo;
  1496   operand[1] = hi;
  1497   return operand;
  1500 // Buffer for 128-bits masks used by SSE instructions.
  1501 static jlong float_signflip_pool[2*2];
  1502 static jlong double_signflip_pool[2*2];
  1503 */
  1504 void TemplateTable::fneg() {
  1505 	transition(ftos, ftos);
  1506 	__ neg_s(FSF, FSF);
  1509 void TemplateTable::dneg() {
  1510 	transition(dtos, dtos);
  1511 	__ neg_d(FSF, FSF);
  1514 // used registers : T2
  1515 void TemplateTable::iinc() {
  1516 	transition(vtos, vtos);
  1517 	locals_index(T2);
  1518 	__ lw(FSR, T2, 0);
  1519 	__ lb(AT, at_bcp(2));           // get constant
  1520 	__ daddu(FSR, FSR, AT);
  1521 	__ sw(FSR, T2, 0);
  1524 // used register : T2
  1525 void TemplateTable::wide_iinc() {
  1526 	transition(vtos, vtos);
  1527 	locals_index_wide(T2);
  1528 	__ get_2_byte_integer_at_bcp(FSR, AT, 4);
  1529 	__ hswap(FSR);
  1530 	__ lw(AT, T2, 0);
  1531 	__ daddu(FSR, AT, FSR);
  1532 	__ sw(FSR, T2, 0);
  1535 void TemplateTable::convert() {
  1536   // Checking
  1537 #ifdef ASSERT
  1538   { TosState tos_in  = ilgl;
  1539     TosState tos_out = ilgl;
  1540     switch (bytecode()) {
  1541       case Bytecodes::_i2l: // fall through
  1542       case Bytecodes::_i2f: // fall through
  1543       case Bytecodes::_i2d: // fall through
  1544       case Bytecodes::_i2b: // fall through
  1545       case Bytecodes::_i2c: // fall through
  1546       case Bytecodes::_i2s: tos_in = itos; break;
  1547       case Bytecodes::_l2i: // fall through
  1548       case Bytecodes::_l2f: // fall through
  1549       case Bytecodes::_l2d: tos_in = ltos; break;
  1550       case Bytecodes::_f2i: // fall through
  1551       case Bytecodes::_f2l: // fall through
  1552       case Bytecodes::_f2d: tos_in = ftos; break;
  1553       case Bytecodes::_d2i: // fall through
  1554       case Bytecodes::_d2l: // fall through
  1555       case Bytecodes::_d2f: tos_in = dtos; break;
  1556       default             : ShouldNotReachHere();
  1558     switch (bytecode()) {
  1559       case Bytecodes::_l2i: // fall through
  1560       case Bytecodes::_f2i: // fall through
  1561       case Bytecodes::_d2i: // fall through
  1562       case Bytecodes::_i2b: // fall through
  1563       case Bytecodes::_i2c: // fall through
  1564       case Bytecodes::_i2s: tos_out = itos; break;
  1565       case Bytecodes::_i2l: // fall through
  1566       case Bytecodes::_f2l: // fall through
  1567       case Bytecodes::_d2l: tos_out = ltos; break;
  1568       case Bytecodes::_i2f: // fall through
  1569       case Bytecodes::_l2f: // fall through
  1570       case Bytecodes::_d2f: tos_out = ftos; break;
  1571       case Bytecodes::_i2d: // fall through
  1572       case Bytecodes::_l2d: // fall through
  1573       case Bytecodes::_f2d: tos_out = dtos; break;
  1574       default             : ShouldNotReachHere();
  1576     transition(tos_in, tos_out);
  1578 #endif // ASSERT
  1580   // Conversion
  1581   // (Note: use pushl(ecx)/popl(ecx) for 1/2-word stack-ptr manipulation)
  1582   switch (bytecode()) {
  1583     case Bytecodes::_i2l:
  1584       //__ extend_sign(SSR, FSR);
  1585       __ sll(FSR, FSR, 0);
  1586       break;
  1587     case Bytecodes::_i2f:
  1588       __ mtc1(FSR, FSF);
  1589       __ cvt_s_w(FSF, FSF);
  1590       break;
  1591     case Bytecodes::_i2d:
  1592       __ mtc1(FSR, FSF);
  1593       __ cvt_d_w(FSF, FSF);
  1594       break;
  1595     case Bytecodes::_i2b:
  1596       __ dsll32(FSR, FSR, 24);
  1597       __ dsra32(FSR, FSR, 24);
  1598       break;
  1599     case Bytecodes::_i2c:
  1600       __ andi(FSR, FSR, 0xFFFF);  // truncate upper 56 bits
  1601       break;
  1602     case Bytecodes::_i2s:
  1603       __ dsll32(FSR, FSR, 16);
  1604       __ dsra32(FSR, FSR, 16);
  1605       break;
  1606     case Bytecodes::_l2i:
  1607       __ dsll32(FSR, FSR, 0);
  1608       __ dsra32(FSR, FSR, 0);
  1609       break;
  1610     case Bytecodes::_l2f:
  1611       __ dmtc1(FSR, FSF);
  1612       //__ mtc1(SSR, SSF);
  1613       __ cvt_s_l(FSF, FSF);
  1614       break;
  1615     case Bytecodes::_l2d:
  1616       __ dmtc1(FSR, FSF);
  1617       //__ mtc1(SSR, SSF);
  1618       __ cvt_d_l(FSF, FSF);
  1619       break;
  1620     case Bytecodes::_f2i:
  1622 	Label L;
  1623 	/*
  1624 	__ c_un_s(FSF, FSF);		//NaN?
  1625 	__ bc1t(L);
  1626 	__ delayed(); __ move(FSR, R0);
  1627 	*/
  1628 	__ trunc_w_s(F12, FSF);
  1629 	__ cfc1(AT, 31);
  1630 	__ li(T0, 0x10000);
  1631 	__ andr(AT, AT, T0);
  1632 	__ beq(AT, R0, L);
  1633 	__ delayed()->mfc1(FSR, F12);
  1635 	__ mov_s(F12, FSF);
  1636 	__ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::f2i), 1);
  1637 	__ bind(L);
  1639       break;
  1640     case Bytecodes::_f2l:
  1642 	Label L;
  1643 	/*
  1644 	__ move(SSR, R0);
  1645 	__ c_un_s(FSF, FSF);		//NaN?
  1646 	__ bc1t(L);
  1647 	__ delayed();
  1648 	__ move(FSR, R0);
  1649 	*/
  1650 	__ trunc_l_s(F12, FSF);
  1651 	__ cfc1(AT, 31);
  1652 	__ li(T0, 0x10000);
  1653 	__ andr(AT, AT, T0);
  1654 	__ beq(AT, R0, L);
  1655 	__ delayed()->dmfc1(FSR, F12);
  1657 	__ mov_s(F12, FSF);
  1658 	__ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::f2l), 1);
  1659 	__ bind(L);
  1661       break;
  1662     case Bytecodes::_f2d:
  1663       __ cvt_d_s(FSF, FSF);
  1664       break;
  1665     case Bytecodes::_d2i:
  1667 	Label L;
  1668 	/*
  1669 	__ c_un_d(FSF, FSF);		//NaN?
  1670 	__ bc1t(L);
  1671 	__ delayed(); __ move(FSR, R0);
  1672 	*/
  1673 	__ trunc_w_d(F12, FSF);
  1674 	__ cfc1(AT, 31);
  1675 	__ li(T0, 0x10000);
  1676 	__ andr(AT, AT, T0);
  1677 	__ beq(AT, R0, L);
  1678 	__ delayed()->mfc1(FSR, F12);
  1680 	__ mov_d(F12, FSF);
  1681 	__ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::d2i), 1);
  1682 	__ bind(L);
  1684       break;
  1685     case Bytecodes::_d2l:
  1687 	Label L;
  1688 	/*
  1689 	__ move(SSR, R0);
  1690 	__ c_un_d(FSF, FSF);		//NaN?
  1691 	__ bc1t(L);
  1692 	__ delayed(); __ move(FSR, R0);
  1693 	*/
  1694 	__ trunc_l_d(F12, FSF);
  1695 	__ cfc1(AT, 31);
  1696 	__ li(T0, 0x10000);
  1697 	__ andr(AT, AT, T0);
  1698 	__ beq(AT, R0, L);
  1699 	__ delayed()->dmfc1(FSR, F12);
  1701 	__ mov_d(F12, FSF);
  1702 	__ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::d2l), 1);
  1703 	__ bind(L);
  1705       break;
  1706     case Bytecodes::_d2f:
  1707       __ cvt_s_d(FSF, FSF);
  1708       break;
  1709     default             :
  1710       ShouldNotReachHere();
  1714 void TemplateTable::lcmp() {
  1715   transition(ltos, itos);
  1717   Label low, high, done;
  1718   __ pop(T0);
  1719   __ pop(R0);
  1720   __ slt(AT, T0, FSR);
  1721   __ bne(AT, R0, low);
  1722   __ delayed()->nop();
  1724   __ bne(T0, FSR, high);
  1725   __ delayed()->nop();
  1727   __ li(FSR, (long)0);
  1728   __ b(done);
  1729   __ delayed()->nop();
  1731   __ bind(low);
  1732   __ li(FSR, (long)-1);
  1733   __ b(done);
  1734   __ delayed()->nop();
  1736   __ bind(high);
  1737   __ li(FSR, (long)1);
  1738   __ b(done);
  1739   __ delayed()->nop();
  1741   __ bind(done);
  1744 void TemplateTable::float_cmp(bool is_float, int unordered_result) {
  1745 	Label less, done;
  1747 	__ move(FSR, R0);
  1749 	if (is_float) {
  1750 		__ pop_ftos_to_esp();
  1751 		__ lwc1(FTF, at_sp());
  1752 		__ c_eq_s(FTF, FSF);
  1753 		__ bc1t(done);
  1754 		__ delayed()->daddi(SP, SP, 1 * wordSize);
  1756 		if (unordered_result<0)
  1757 			__ c_ult_s(FTF, FSF);
  1758 		else
  1759 			__ c_olt_s(FTF, FSF);
  1760 	} else {
  1761 		__ pop_dtos_to_esp();
  1762 		__ ldc1(FTF, at_sp());
  1763 		__ c_eq_d(FTF, FSF);
  1764 		__ bc1t(done);
  1765 		__ delayed()->daddi(SP, SP, 2 * wordSize);
  1767 		if (unordered_result<0)
  1768 			__ c_ult_d(FTF, FSF);
  1769 		else
  1770 			__ c_olt_d(FTF, FSF);
  1772 	__ bc1t(less);
  1773 	__ delayed()->nop();
  1774 	__ move(FSR, 1);
  1775 	__ b(done);
  1776 	__ delayed()->nop();
  1777 	__ bind(less);
  1778 	__ move(FSR, -1);
  1779 	__ bind(done);
  1783 // used registers : T3, A7, Rnext
  1784 // FSR : return bci, this is defined by the vm specification
  1785 // T2 : MDO taken count
  1786 // T3 : method
  1787 // A7 : offset
  1788 // Rnext : next bytecode, this is required by dispatch_base
  1789 void TemplateTable::branch(bool is_jsr, bool is_wide) {
  1790   __ get_method(T3);
  1791   __ profile_taken_branch(A7, T2);		// only C2 meaningful 
  1793 #ifndef CORE
  1794   const ByteSize be_offset = MethodCounters::backedge_counter_offset() 
  1795     + InvocationCounter::counter_offset();
  1796   const ByteSize inv_offset = MethodCounters::invocation_counter_offset() 
  1797     + InvocationCounter::counter_offset();
  1798   const int method_offset = frame::interpreter_frame_method_offset * wordSize;
  1799 #endif // CORE
  1801   // Load up T4 with the branch displacement
  1802   if (!is_wide) {
  1803     __ get_2_byte_integer_at_bcp(A7, AT, 1);
  1804     __ hswap(A7);
  1805   } else {
  1806     __ get_4_byte_integer_at_bcp(A7, AT, 1);
  1807     __ swap(A7);
  1810   // Handle all the JSR stuff here, then exit.
  1811   // It's much shorter and cleaner than intermingling with the
  1812   // non-JSR normal-branch stuff occuring below.
  1813   if (is_jsr) {
  1814     // Pre-load the next target bytecode into Rnext
  1815     __ dadd(AT, BCP, A7);
  1816     __ lbu(Rnext, AT, 0);
  1818     // compute return address as bci in FSR
  1819     __ daddi(FSR, BCP, (is_wide?5:3) - in_bytes(ConstMethod::codes_offset()));
  1820     __ ld(AT, T3, in_bytes(Method::const_offset()));
  1821     __ dsub(FSR, FSR, AT);
  1822     // Adjust the bcp in BCP by the displacement in A7
  1823     __ dadd(BCP, BCP, A7);
  1824     // jsr returns atos that is not an oop
  1825     // __ dispatch_only_noverify(atos);
  1826     // Push return address
  1827     __ push_i(FSR);
  1828     // jsr returns vtos
  1829     __ dispatch_only_noverify(vtos);
  1831     return;
  1834   // Normal (non-jsr) branch handling
  1836   // Adjust the bcp in S0 by the displacement in T4
  1837   __ dadd(BCP, BCP, A7);
  1839 #ifdef CORE
  1840   // Pre-load the next target bytecode into EBX
  1841   __ lbu(Rnext, BCP, 0);
  1842   // continue with the bytecode @ target
  1843   __ dispatch_only(vtos);
  1844 #else
  1845   assert(UseLoopCounter || !UseOnStackReplacement, "on-stack-replacement requires loop counters");
  1846   Label backedge_counter_overflow;
  1847   Label profile_method;
  1848   Label dispatch;
  1849   if (UseLoopCounter) {
  1850     // increment backedge counter for backward branches
  1851     // eax: MDO
  1852     // ebx: MDO bumped taken-count
  1853     // T3: method
  1854     // T4: target offset
  1855     // BCP: target bcp
  1856     // LVP: locals pointer
  1857     __ bgtz(A7, dispatch);	// check if forward or backward branch
  1858     __ delayed()->nop();
  1860     // check if MethodCounters exists
  1861     Label has_counters;
  1862     __ ld(AT, T3, in_bytes(Method::method_counters_offset()));  // use AT as MDO, TEMP 
  1863     __ bne(AT, R0, has_counters);
  1864     __ nop();
  1865     //__ push(T3);
  1866     //__ push(A7);
  1867     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::build_method_counters),
  1868                T3);
  1869     //__ pop(A7);
  1870     //__ pop(T3);
  1871     __ ld(AT, T3, in_bytes(Method::method_counters_offset()));  // use AT as MDO, TEMP
  1872     __ beq(AT, R0, dispatch);
  1873     __ nop();
  1874     __ bind(has_counters);
  1876     // increment back edge counter 
  1877     __ ld(T1, T3, in_bytes(Method::method_counters_offset()));
  1878     __ lw(T0, T1, in_bytes(be_offset));
  1879     __ increment(T0, InvocationCounter::count_increment);
  1880     __ sw(T0, T1, in_bytes(be_offset));
  1882     // load invocation counter
  1883     __ lw(T1, T1, in_bytes(inv_offset));
  1884     // buffer bit added, mask no needed
  1885     // by yjl 10/24/2005
  1886     //__ move(AT, InvocationCounter::count_mask_value);
  1887     //__ andr(T1, T1, AT);
  1889     // dadd backedge counter & invocation counter
  1890     __ dadd(T1, T1, T0);
  1892     if (ProfileInterpreter) {
  1893       // Test to see if we should create a method data oop
  1894       //__ lui(AT, Assembler::split_high(int(&InvocationCounter::InterpreterProfileLimit)));
  1895       //__ lw(AT, AT, Assembler::split_low(int(&InvocationCounter::InterpreterProfileLimit)));
  1896       // T1 : backedge counter & invocation counter
  1897       __ li(AT, (long)&InvocationCounter::InterpreterProfileLimit);
  1898       __ lw(AT, AT, 0);
  1899       __ slt(AT, T1, AT);
  1900       __ bne(AT, R0, dispatch);
  1901       __ delayed()->nop();
  1903       // if no method data exists, go to profile method
  1904       __ test_method_data_pointer(T1, profile_method);
  1906       if (UseOnStackReplacement) {
  1907 	// check for overflow against ebx which is the MDO taken count
  1908 	//__ lui(AT, Assembler::split_high(int(&InvocationCounter::InterpreterBackwardBranchLimit)));
  1909 	//__ lw(AT, AT, Assembler::split_low(int(&InvocationCounter::InterpreterBackwardBranchLimit)));
  1910 	__ li(AT, (long)&InvocationCounter::InterpreterBackwardBranchLimit);
  1911 	__ lw(AT, AT, 0);
  1912 	// the value Rnext Is get from the beginning profile_taken_branch
  1913 	__ slt(AT, T2, AT);
  1914 	__ bne(AT, R0, dispatch);
  1915 	__ delayed()->nop();
  1917 	// When ProfileInterpreter is on, the backedge_count comes 
  1918 	// from the methodDataOop, which value does not get reset on 
  1919 	// the call to  frequency_counter_overflow().  
  1920 	// To avoid excessive calls to the overflow routine while 
  1921 	// the method is being compiled, dadd a second test to make 
  1922 	// sure the overflow function is called only once every 
  1923 	// overflow_frequency.
  1924 	const int overflow_frequency = 1024;
  1925 	__ andi(AT, T2, overflow_frequency-1);
  1926 	__ beq(AT, R0, backedge_counter_overflow);
  1927 	__ delayed()->nop();
  1929     } else {
  1930       if (UseOnStackReplacement) {
  1931 	// check for overflow against eax, which is the sum of the counters
  1932 	//__ lui(AT, Assembler::split_high(int(&InvocationCounter::InterpreterBackwardBranchLimit)));
  1933 	//__ lw(AT, AT, Assembler::split_low(int(&InvocationCounter::InterpreterBackwardBranchLimit)));
  1934 	__ li(AT, (long)&InvocationCounter::InterpreterBackwardBranchLimit);
  1935 	__ lw(AT, AT, 0);
  1936 	__ slt(AT, T1, AT);
  1937 	__ beq(AT, R0, backedge_counter_overflow);
  1938 	__ delayed()->nop();
  1941     __ bind(dispatch);
  1944   // Pre-load the next target bytecode into Rnext
  1945   __ lbu(Rnext, BCP, 0);
  1947   // continue with the bytecode @ target
  1948   // FSR: return bci for jsr's, unused otherwise
  1949   // Rnext: target bytecode
  1950   // BCP: target bcp
  1951   __ dispatch_only(vtos);
  1953   if (UseLoopCounter) {
  1954     if (ProfileInterpreter) {
  1955       // Out-of-line code to allocate method data oop.
  1956       __ bind(profile_method);
  1957       __ call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::profile_method));
  1958       __ lbu(Rnext, BCP, 0);
  1960       __ set_method_data_pointer_for_bcp();
  1961 /*
  1962       __ ld(T3, FP, method_offset);
  1963       __ lw(T3, T3, in_bytes(Method::method_data_offset()));
  1964       __ sw(T3, FP, frame::interpreter_frame_mdx_offset * wordSize);
  1965       __ test_method_data_pointer(T3, dispatch);
  1966       // offset non-null mdp by MDO::data_offset() + IR::profile_method()
  1967       __ daddi(T3, T3, in_bytes(MethodData::data_offset()));
  1968       __ dadd(T3, T3, T1);
  1969       __ sw(T3, FP, frame::interpreter_frame_mdx_offset * wordSize);
  1970 */
  1971       __ b(dispatch);
  1972       __ delayed()->nop();
  1975     if (UseOnStackReplacement) {
  1976       // invocation counter overflow
  1977       __ bind(backedge_counter_overflow);
  1978       __ sub(A7, BCP, A7);	// branch bcp
  1979       call_VM(NOREG, CAST_FROM_FN_PTR(address, 
  1980 	    InterpreterRuntime::frequency_counter_overflow), A7);
  1981       __ lbu(Rnext, BCP, 0);
  1983       // V0: osr nmethod (osr ok) or NULL (osr not possible)
  1984       // V1: osr adapter frame return address
  1985       // Rnext: target bytecode
  1986       // LVP: locals pointer
  1987       // BCP: bcp
  1988       __ beq(V0, R0, dispatch);
  1989       __ delayed()->nop();
  1990       // nmethod may have been invalidated (VM may block upon call_VM return)
  1991       __ lw(T3, V0, nmethod::entry_bci_offset());
  1992       __ move(AT, InvalidOSREntryBci);
  1993       __ beq(AT, T3, dispatch);
  1994       __ delayed()->nop();
  1995       // We need to prepare to execute the OSR method. First we must
  1996       // migrate the locals and monitors off of the stack.
  1997       //eax V0: osr nmethod (osr ok) or NULL (osr not possible)
  1998       //ebx V1: osr adapter frame return address
  1999       //edx  Rnext: target bytecode
  2000       //edi  LVP: locals pointer
  2001       //esi  BCP: bcp
  2002       __ move(BCP, V0); 
  2003       // const Register thread = ecx;
  2004       const Register thread = TREG;
  2005 #ifndef OPT_THREAD
  2006       __ get_thread(thread);
  2007 #endif
  2008       call_VM(noreg, CAST_FROM_FN_PTR(address, 
  2009 	    SharedRuntime::OSR_migration_begin));
  2010       // eax is OSR buffer, move it to expected parameter location
  2011       //refer to osrBufferPointer in c1_LIRAssembler_mips.cpp	
  2012       __ move(T0, V0);
  2014       // pop the interpreter frame
  2015       //  __ movl(edx, Address(ebp, frame::interpreter_frame_sender_sp_offset 
  2016       //  * wordSize)); // get sender sp
  2017       __ ld(A7, Address(FP, 
  2018 	    frame::interpreter_frame_sender_sp_offset * wordSize)); 
  2019       //FIXME, shall we keep the return address on the stack?	
  2020       __ leave();                                // remove frame anchor
  2021       // __ popl(edi);                         // get return address
  2022       //__ daddi(SP, SP, wordSize);               // get return address
  2023       //   __ pop(LVP);	
  2024       __ move(LVP, RA);	
  2025       // __ movl(esp, edx);                         // set sp to sender sp
  2026       __ move(SP, A7);
  2028       Label skip;
  2029       Label chkint;
  2031       // The interpreter frame we have removed may be returning to
  2032       // either the callstub or the interpreter. Since we will
  2033       // now be returning from a compiled (OSR) nmethod we must
  2034       // adjust the return to the return were it can handler compiled
  2035       // results and clean the fpu stack. This is very similar to
  2036       // what a i2c adapter must do.
  2038       // Are we returning to the call stub?
  2039 #if 0	
  2040       // __ cmpl(edi, (int)StubRoutines::_call_stub_return_address);
  2041       __ daddi(AT, LVP, -(int)StubRoutines::_call_stub_return_address); 
  2042       //  __ jcc(Assembler::notEqual, chkint);
  2043       __ bne(AT, R0, chkint);
  2044       __ delayed()->nop();      
  2045       // yes adjust to the specialized call stub  return.
  2046       // assert(StubRoutines::i486::get_call_stub_compiled_return() != NULL,
  2047       // "must be set");
  2048       assert(StubRoutines::gs2::get_call_stub_compiled_return() != NULL, 
  2049 	  "must be set");
  2050       // __ movl(edi, (intptr_t) StubRoutines::i486::get_call_stub_compiled_return());
  2051       __ move(LVP, (intptr_t) StubRoutines::gs2::get_call_stub_compiled_return()); 
  2052       //  __ jmp(skip);
  2053       __ b(skip);
  2054       __ delayed()->nop();
  2055       __ bind(chkint);
  2057       // Are we returning to the interpreter? Look for sentinel
  2059       //__ cmpl(Address(edi, -8), Interpreter::return_sentinel);
  2060       __ lw(AT, LVP , -8); 
  2061       __ daddi(AT, AT, -Interpreter::return_sentinel); 
  2062       //__ jcc(Assembler::notEqual, skip);
  2063       __ bne(AT, R0, skip);
  2064       __ delayed()->nop(); 
  2065       // Adjust to compiled return back to interpreter
  2067       // __ movl(edi, Address(edi, -4));
  2068       __ lw(LVP, LVP, -4); 
  2070       __ bind(skip);
  2071 #endif
  2072       // Align stack pointer for compiled code (note that caller is
  2073       // responsible for undoing this fixup by remembering the old SP
  2074       // in an ebp-relative location)
  2075       //  __ andl(esp, -(StackAlignmentInBytes));
  2076       __ move(AT, -(StackAlignmentInBytes));	
  2077       __ andr(SP , SP , AT);
  2078       // push the (possibly adjusted) return address
  2079       //  __ pushl(edi);
  2080       //__ push(LVP);
  2081       //			__ move(RA, LVP);	
  2082       // and begin the OSR nmethod
  2083       //  __ jmp(Address(esi, nmethod::osr_entry_point_offset()));
  2084       //refer to osr_entry in c1_LIRAssembler_mips.cpp	
  2085       __ ld(AT, BCP, nmethod::osr_entry_point_offset()); 
  2086       __ jr(AT); 
  2087       __ delayed()->nop(); 
  2090 #endif // not CORE
  2093 void TemplateTable::if_0cmp(Condition cc) {
  2094   transition(itos, vtos);
  2095   // assume branch is more often taken than not (loops use backward branches)
  2096   Label not_taken;
  2097   switch(cc) {
  2098     case not_equal:
  2099       __ beq(FSR, R0, not_taken);
  2100       break;
  2101     case equal:
  2102       __ bne(FSR, R0, not_taken);
  2103       break;
  2104     case less:
  2105       __ bgez(FSR, not_taken);
  2106       break;
  2107     case less_equal:
  2108       __ bgtz(FSR, not_taken);
  2109       break;
  2110     case greater:
  2111       __ blez(FSR, not_taken);
  2112       break;
  2113     case greater_equal:
  2114       __ bltz(FSR, not_taken);
  2115       break;
  2117   __ delayed()->nop();
  2119   branch(false, false);
  2121   __ bind(not_taken);
  2122   __ profile_not_taken_branch(FSR);
  2126 void TemplateTable::if_icmp(Condition cc) {
  2127   transition(itos, vtos);
  2128   // assume branch is more often taken than not (loops use backward branches)
  2129   Label not_taken;
  2131   __ pop_i(SSR);	
  2132   switch(cc) {
  2133     case not_equal:
  2134       __ beq(SSR, FSR, not_taken);
  2135       break;
  2136     case equal:
  2137       __ bne(SSR, FSR, not_taken);
  2138       break;
  2139     case less:
  2140       __ slt(AT, SSR, FSR);
  2141       __ beq(AT, R0, not_taken);
  2142       break;
  2143     case less_equal:
  2144       __ slt(AT, FSR, SSR);
  2145       __ bne(AT, R0, not_taken);
  2146       break;
  2147     case greater:
  2148       __ slt(AT, FSR, SSR);
  2149       __ beq(AT, R0, not_taken);
  2150       break;
  2151     case greater_equal:
  2152       __ slt(AT, SSR, FSR);
  2153       __ bne(AT, R0, not_taken);
  2154       break;
  2156   __ delayed()->nop();
  2158   branch(false, false);
  2160   __ bind(not_taken);
  2161   __ profile_not_taken_branch(FSR);
  2165 void TemplateTable::if_nullcmp(Condition cc) {
  2166   transition(atos, vtos);
  2167   // assume branch is more often taken than not (loops use backward branches)
  2168   Label not_taken;
  2169   switch(cc) {
  2170     case not_equal:
  2171       __ beq(FSR, R0, not_taken);
  2172       break;
  2173     case equal:
  2174       __ bne(FSR, R0, not_taken);
  2175       break;
  2176     default:
  2177       ShouldNotReachHere();
  2179   __ delayed()->nop();
  2181   branch(false, false);
  2183   __ bind(not_taken);
  2184   __ profile_not_taken_branch(FSR);
  2188 void TemplateTable::if_acmp(Condition cc) {
  2189 	transition(atos, vtos);
  2190 	// assume branch is more often taken than not (loops use backward branches)
  2191 	Label not_taken;
  2192 	//	__ lw(SSR, SP, 0);
  2193 	__ pop_ptr(SSR);
  2194 	switch(cc) {
  2195 		case not_equal:
  2196 			__ beq(SSR, FSR, not_taken);
  2197 			break;
  2198 		case equal:
  2199 			__ bne(SSR, FSR, not_taken);
  2200 			break;
  2201 		default:
  2202 			ShouldNotReachHere();
  2204 	//	__ delayed()->daddi(SP, SP, 4);
  2205 	__ delayed()->nop();
  2207 	branch(false, false);
  2209 	__ bind(not_taken);
  2210 	__ profile_not_taken_branch(FSR);
  2213 // used registers : T1, T2, T3
  2214 // T1 : method
  2215 // T2 : returb bci
  2216 void TemplateTable::ret() {
  2217 	transition(vtos, vtos);
  2219 	locals_index(T2);
  2220 	__ ld(T2, T2, 0);
  2221 	__ profile_ret(T2, T3);
  2223 	__ get_method(T1);
  2224 	__ ld(BCP, T1, in_bytes(Method::const_offset()));
  2225 	__ dadd(BCP, BCP, T2);
  2226 	__ daddi(BCP, BCP, in_bytes(ConstMethod::codes_offset()));
  2228 	__ dispatch_next(vtos);
  2231 // used registers : T1, T2, T3
  2232 // T1 : method
  2233 // T2 : returb bci
  2234 void TemplateTable::wide_ret() {
  2235 	transition(vtos, vtos);
  2237 	locals_index_wide(T2);
  2238 	__ ld(T2, T2, 0);                   // get return bci, compute return bcp
  2239 	__ profile_ret(T2, T3);
  2241 	__ get_method(T1);
  2242 	__ ld(BCP, T1, in_bytes(Method::const_offset()));
  2243 	__ dadd(BCP, BCP, T2);
  2244 	__ daddi(BCP, BCP, in_bytes(ConstMethod::codes_offset()));
  2246 	__ dispatch_next(vtos);
  2249 // used register T2, T3, A7, Rnext
  2250 // T2 : bytecode pointer
  2251 // T3 : low
  2252 // A7 : high
  2253 // Rnext : dest bytecode, required by dispatch_base
  2254 void TemplateTable::tableswitch() {
  2255 	Label default_case, continue_execution;
  2256 	transition(itos, vtos);
  2258 	// align BCP
  2259 	__ daddi(T2, BCP, BytesPerInt);
  2260 	__ li(AT, -BytesPerInt);
  2261 	__ andr(T2, T2, AT);
  2263 	// load lo & hi
  2264 	__ lw(T3, T2, 1 * BytesPerInt);
  2265 	__ swap(T3);
  2266 	__ lw(A7, T2, 2 * BytesPerInt);
  2267 	__ swap(A7);
  2269 	// check against lo & hi
  2270 	__ slt(AT, FSR, T3);
  2271 	__ bne(AT, R0, default_case);
  2272 	__ delayed()->nop();
  2274 	__ slt(AT, A7, FSR);
  2275 	__ bne(AT, R0, default_case);
  2276 	__ delayed()->nop();
  2278 	// lookup dispatch offset, in A7 big endian
  2279 	__ dsub(FSR, FSR, T3);
  2280 	__ dsll(AT, FSR, Address::times_4);
  2281 	__ dadd(AT, T2, AT);
  2282 	__ lw(A7, AT, 3 * BytesPerInt);
  2283 	__ profile_switch_case(FSR, T9, T3);
  2285 	__ bind(continue_execution);
  2286 	__ swap(A7);
  2287 	__ dadd(BCP, BCP, A7);
  2288 	__ lbu(Rnext, BCP, 0);
  2289 	__ dispatch_only(vtos);
  2291 	// handle default
  2292 	__ bind(default_case);
  2293 	__ profile_switch_default(FSR);
  2294 	__ lw(A7, T2, 0);
  2295 	__ b(continue_execution);
  2296 	__ delayed()->nop();
  2299 void TemplateTable::lookupswitch() {
  2300 	transition(itos, itos);
  2301 	__ stop("lookupswitch bytecode should have been rewritten");
  2304 // used registers : T2, T3, A7, Rnext
  2305 // T2 : bytecode pointer
  2306 // T3 : pair index
  2307 // A7 : offset
  2308 // Rnext : dest bytecode
  2309 // the data after the opcode is the same as lookupswitch
  2310 // see Rewriter::rewrite_method for more information
  2311 void TemplateTable::fast_linearswitch() {
  2312   transition(itos, vtos);
  2313   Label loop_entry, loop, found, continue_execution;  
  2315   // swap eax so we can avoid swapping the table entries
  2316   __ swap(FSR);
  2318   // align BCP
  2319   __ daddi(T2, BCP, BytesPerInt);
  2320   __ li(AT, -BytesPerInt);
  2321   __ andr(T2, T2, AT);
  2323   // set counter
  2324   __ lw(T3, T2, BytesPerInt);
  2325   __ swap(T3);
  2326   __ b(loop_entry);
  2327   __ delayed()->nop();
  2329   // table search
  2330   __ bind(loop);
  2331   // get the entry value
  2332   __ dsll(AT, T3, Address::times_8);
  2333   __ dadd(AT, T2, AT);
  2334   __ lw(AT, AT, 2 * BytesPerInt);
  2336   // found?
  2337   __ beq(FSR, AT, found);
  2338   __ delayed()->nop();
  2340   __ bind(loop_entry);
  2341   __ bgtz(T3, loop);
  2342   __ delayed()->daddiu(T3, T3, -1);
  2344   // default case
  2345   __ profile_switch_default(FSR);
  2346   __ lw(A7, T2, 0);
  2347   __ b(continue_execution);
  2348   __ delayed()->nop();
  2350   // entry found -> get offset
  2351   __ bind(found);
  2352   __ dsll(AT, T3, Address::times_8);
  2353   __ dadd(AT, T2, AT);
  2354   __ lw(A7, AT, 3 * BytesPerInt);
  2355   __ profile_switch_case(T3, FSR, T2);
  2357   // continue execution
  2358   __ bind(continue_execution);  
  2359   __ swap(A7);
  2360   __ dadd(BCP, BCP, A7);
  2361   __ lbu(Rnext, BCP, 0);
  2362   __ dispatch_only(vtos);
  2365 // used registers : T0, T1, T2, T3, A7, Rnext
  2366 // T2 : pairs address(array)
  2367 // Rnext : dest bytecode
  2368 // the data after the opcode is the same as lookupswitch
  2369 // see Rewriter::rewrite_method for more information
  2370 void TemplateTable::fast_binaryswitch() {
  2371   transition(itos, vtos);
  2372   // Implementation using the following core algorithm:
  2373   //
  2374   // int binary_search(int key, LookupswitchPair* array, int n) {
  2375   //   // Binary search according to "Methodik des Programmierens" by
  2376   //   // Edsger W. Dijkstra and W.H.J. Feijen, Addison Wesley Germany 1985.
  2377   //   int i = 0;
  2378   //   int j = n;
  2379   //   while (i+1 < j) {
  2380   //     // invariant P: 0 <= i < j <= n and (a[i] <= key < a[j] or Q)
  2381   //     // with      Q: for all i: 0 <= i < n: key < a[i]
  2382   //     // where a stands for the array and assuming that the (inexisting)
  2383   //     // element a[n] is infinitely big.
  2384   //     int h = (i + j) >> 1;
  2385   //     // i < h < j
  2386   //     if (key < array[h].fast_match()) {
  2387   //       j = h;
  2388   //     } else {
  2389   //       i = h;
  2390   //     }
  2391   //   }
  2392   //   // R: a[i] <= key < a[i+1] or Q
  2393   //   // (i.e., if key is within array, i is the correct index)
  2394   //   return i;
  2395   // }
  2397   // register allocation
  2398   const Register array = T2;
  2399   const Register i = T3, j = A7;
  2400   const Register h = T1;
  2401   const Register temp = T0;
  2402   const Register key = FSR;
  2404   // setup array
  2405   __ daddi(array, BCP, 3*BytesPerInt);
  2406   __ li(AT, -BytesPerInt);
  2407   __ andr(array, array, AT);
  2409   // initialize i & j
  2410   __ move(i, R0);
  2411   __ lw(j, array, - 1 * BytesPerInt);
  2412   // Convert j into native byteordering  
  2413   __ swap(j);
  2415   // and start
  2416   Label entry;
  2417   __ b(entry);
  2418   __ delayed()->nop();
  2420   // binary search loop
  2422     Label loop;
  2423     __ bind(loop);
  2424     // int h = (i + j) >> 1;
  2425     __ dadd(h, i, j);
  2426     __ dsrl(h, h, 1);
  2427     // if (key < array[h].fast_match()) {
  2428     //   j = h;
  2429     // } else {
  2430     //   i = h;
  2431     // }
  2432     // Convert array[h].match to native byte-ordering before compare
  2433     __ dsll(AT, h, Address::times_8);
  2434     __ dadd(AT, array, AT);
  2435     __ lw(temp, AT, 0 * BytesPerInt);
  2436     __ swap(temp);
  2439       Label set_i, end_of_if;
  2440       __ slt(AT, key, temp);
  2441       __ beq(AT, R0, set_i);
  2442       __ delayed()->nop(); 
  2444       __ b(end_of_if);
  2445       __ delayed(); __ move(j, h);
  2447       __ bind(set_i);
  2448       __ move(i, h);
  2450       __ bind(end_of_if);
  2452     // while (i+1 < j)
  2453     __ bind(entry);
  2454     __ daddi(h, i, 1);
  2455     __ slt(AT, h, j);
  2456     __ bne(AT, R0, loop);
  2457     __ delayed()->nop();
  2460   // end of binary search, result index is i (must check again!)
  2461   Label default_case;
  2462   // Convert array[i].match to native byte-ordering before compare
  2463   __ dsll(AT, i, Address::times_8);
  2464   __ dadd(AT, array, AT);
  2465   __ lw(temp, AT, 0 * BytesPerInt);
  2466   __ swap(temp);
  2467   __ bne(key, temp, default_case);
  2468   __ delayed()->nop();
  2470   // entry found -> j = offset
  2471   __ dsll(AT, i, Address::times_8);
  2472   __ dadd(AT, array, AT);
  2473   __ lw(j, AT, 1 * BytesPerInt);
  2474   __ profile_switch_case(i, key, array);
  2475   __ swap(j);
  2477   __ dadd(BCP, BCP, j);
  2478   __ lbu(Rnext, BCP, 0);
  2479   __ dispatch_only(vtos);
  2481   // default case -> j = default offset
  2482   __ bind(default_case);
  2483   __ profile_switch_default(i);
  2484   __ lw(j, array, - 2 * BytesPerInt);
  2485   __ swap(j);
  2486   __ dadd(BCP, BCP, j);
  2487   __ lbu(Rnext, BCP, 0);
  2488   __ dispatch_only(vtos);
  2491 void TemplateTable::_return(TosState state) {
  2492   transition(state, state);
  2493   assert(_desc->calls_vm(), "inconsistent calls_vm information"); // call in remove_activation
  2494   if (_desc->bytecode() == Bytecodes::_return_register_finalizer) {
  2495     assert(state == vtos, "only valid state");
  2496     __ ld(T1, aaddress(0));
  2497     //__ ld(LVP, T1, oopDesc::klass_offset_in_bytes());
  2498     __ load_klass(LVP, T1);
  2499     __ lw(LVP, LVP, in_bytes(Klass::access_flags_offset()));
  2500     __ move(AT, JVM_ACC_HAS_FINALIZER); 
  2501     __ andr(AT, AT, LVP);//by_css
  2502     Label skip_register_finalizer;
  2503     __ beq(AT, R0, skip_register_finalizer);
  2504     __ delayed()->nop(); 
  2505     __ call_VM(noreg, CAST_FROM_FN_PTR(address, 
  2506 	  InterpreterRuntime::register_finalizer), T1);
  2507     __ bind(skip_register_finalizer);
  2509   __ remove_activation(state, T9);
  2510   __ sync();
  2512   __ jr(T9);
  2513   __ delayed()->nop();
  2516 // ----------------------------------------------------------------------------
  2517 // Volatile variables demand their effects be made known to all CPU's
  2518 // in order.  Store buffers on most chips allow reads & writes to
  2519 // reorder; the JMM's ReadAfterWrite.java test fails in -Xint mode
  2520 // without some kind of memory barrier (i.e., it's not sufficient that
  2521 // the interpreter does not reorder volatile references, the hardware
  2522 // also must not reorder them).
  2523 //
  2524 // According to the new Java Memory Model (JMM):
  2525 // (1) All volatiles are serialized wrt to each other.  ALSO reads &
  2526 //     writes act as aquire & release, so:
  2527 // (2) A read cannot let unrelated NON-volatile memory refs that
  2528 //     happen after the read float up to before the read.  It's OK for
  2529 //     non-volatile memory refs that happen before the volatile read to
  2530 //     float down below it.
  2531 // (3) Similar a volatile write cannot let unrelated NON-volatile
  2532 //     memory refs that happen BEFORE the write float down to after the
  2533 //     write.  It's OK for non-volatile memory refs that happen after the
  2534 //     volatile write to float up before it.
  2535 //
  2536 // We only put in barriers around volatile refs (they are expensive),
  2537 // not _between_ memory refs (that would require us to track the
  2538 // flavor of the previous memory refs).  Requirements (2) and (3)
  2539 // require some barriers before volatile stores and after volatile
  2540 // loads.  These nearly cover requirement (1) but miss the
  2541 // volatile-store-volatile-load case.  This final case is placed after
  2542 // volatile-stores although it could just as well go before
  2543 // volatile-loads.
  2544 //void TemplateTable::volatile_barrier(Assembler::Membar_mask_bits
  2545 //                                     order_constraint) {
  2546 void TemplateTable::volatile_barrier( ) {
  2547   // Helper function to insert a is-volatile test and memory barrier
  2548   //if (os::is_MP()) { // Not needed on single CPU
  2549   //  __ membar(order_constraint);
  2550   //}
  2551 	if( !os::is_MP() ) return;	// Not needed on single CPU
  2552 	__ sync();
  2555 // we dont shift left 2 bits in get_cache_and_index_at_bcp
  2556 // for we always need shift the index we use it. the ConstantPoolCacheEntry 
  2557 // is 16-byte long, index is the index in 
  2558 // ConstantPoolCache, so cache + base_offset() + index * 16 is 
  2559 // the corresponding ConstantPoolCacheEntry
  2560 // used registers : T2
  2561 // NOTE : the returned index need also shift left 4 to get the address!
  2562 void TemplateTable::resolve_cache_and_index(int byte_no,
  2563                                             Register Rcache,
  2564 					    Register index,
  2565                                             size_t index_size) {
  2566   assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
  2567   const Register temp = A1;
  2568   assert_different_registers(Rcache, index);
  2569   const int shift_count = (1 + byte_no)*BitsPerByte;
  2570   Label resolved;
  2571   __ get_cache_and_index_and_bytecode_at_bcp(Rcache, index, temp, byte_no, 1, index_size);
  2572   // is resolved?
  2573   int i = (int)bytecode();
  2574   __ addi(temp, temp, -i);
  2575   __ beq(temp, R0, resolved);
  2576   __ delayed()->nop();
  2577   // resolve first time through
  2578   address entry;
  2579   switch (bytecode()) {
  2580     case Bytecodes::_getstatic      : // fall through
  2581     case Bytecodes::_putstatic      : // fall through
  2582     case Bytecodes::_getfield       : // fall through
  2583     case Bytecodes::_putfield       : 
  2584       entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_get_put); 
  2585       break;
  2586     case Bytecodes::_invokevirtual  : // fall through
  2587     case Bytecodes::_invokespecial  : // fall through
  2588     case Bytecodes::_invokestatic   : // fall through
  2589     case Bytecodes::_invokeinterface: 
  2590       entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_invoke);  
  2591       break;
  2592     case Bytecodes::_invokehandle:
  2593       entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_invokehandle);
  2594       break;
  2595     case Bytecodes::_invokedynamic:
  2596       entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_invokedynamic);
  2597       break;
  2598     default                      		: 
  2599       fatal(err_msg("unexpected bytecode: %s", Bytecodes::name(bytecode())));
  2602   __ move(temp, i);
  2603   __ call_VM(NOREG, entry, temp);
  2605   // Update registers with resolved info
  2606   __ get_cache_and_index_at_bcp(Rcache, index, 1, index_size);
  2607   __ bind(resolved);
  2610 // The Rcache and index registers must be set before call
  2611 void TemplateTable::load_field_cp_cache_entry(Register obj,
  2612                                               Register cache,
  2613                                               Register index,
  2614                                               Register off,
  2615                                               Register flags,
  2616                                               bool is_static = false) {
  2617   assert_different_registers(cache, index, flags, off);
  2618   ByteSize cp_base_offset = ConstantPoolCache::base_offset();
  2619   // Field offset
  2620   __ dsll(AT, index, Address::times_ptr);
  2621   __ dadd(AT, cache, AT);
  2622   __ ld(off, AT, in_bytes(cp_base_offset + ConstantPoolCacheEntry::f2_offset()));
  2623   // Flags    
  2624   __ ld(flags, AT, in_bytes(cp_base_offset + ConstantPoolCacheEntry::flags_offset()));
  2626   // klass     overwrite register
  2627   if (is_static) {
  2628     __ ld(obj, AT, in_bytes(cp_base_offset + ConstantPoolCacheEntry::f1_offset())); 
  2629     const int mirror_offset = in_bytes(Klass::java_mirror_offset());
  2630     __ ld(obj, Address(obj, mirror_offset));
  2632     __ verify_oop(obj);	
  2636 // get the method, itable_index and flags of the current invoke
  2637 void TemplateTable::load_invoke_cp_cache_entry(int byte_no,
  2638                                                Register method,
  2639                                                Register itable_index,
  2640                                                Register flags,
  2641                                                bool is_invokevirtual,
  2642                                                bool is_invokevfinal, /*unused*/
  2643                                                bool is_invokedynamic) {
  2644   // setup registers
  2645   const Register cache = T3;
  2646   const Register index = T1;
  2647   assert_different_registers(method, flags);
  2648   assert_different_registers(method, cache, index);
  2649   assert_different_registers(itable_index, flags);
  2650   assert_different_registers(itable_index, cache, index);
  2651   assert(is_invokevirtual == (byte_no == f2_byte), "is invokevirtual flag redundant");
  2652   // determine constant pool cache field offsets
  2653   const int method_offset = in_bytes(
  2654       ConstantPoolCache::base_offset() +
  2655       ((byte_no == f2_byte)
  2656        ? ConstantPoolCacheEntry::f2_offset()
  2657        : ConstantPoolCacheEntry::f1_offset()
  2659       );
  2660   const int flags_offset = in_bytes(ConstantPoolCache::base_offset() +
  2661       ConstantPoolCacheEntry::flags_offset());
  2662   // access constant pool cache fields
  2663   const int index_offset = in_bytes(ConstantPoolCache::base_offset() +
  2664       ConstantPoolCacheEntry::f2_offset());
  2665   size_t index_size = (is_invokedynamic ? sizeof(u4): sizeof(u2));
  2666   resolve_cache_and_index(byte_no, cache, index, index_size);
  2668   //assert(wordSize == 8, "adjust code below");
  2669   // note we shift 4 not 2, for we get is the true inde 
  2670   // of ConstantPoolCacheEntry, not the shifted 2-bit index as x86 version
  2671   __ dsll(AT, index, Address::times_ptr);
  2672   __ dadd(AT, cache, AT);
  2673   __ ld(method, AT, method_offset);
  2676   if (itable_index != NOREG) {
  2677     __ ld(itable_index, AT, index_offset);
  2679   __ ld(flags, AT, flags_offset);
  2683 // The registers cache and index expected to be set before call.
  2684 // Correct values of the cache and index registers are preserved.
  2685 void TemplateTable::jvmti_post_field_access(Register cache, Register index,
  2686                                             bool is_static, bool has_tos) {
  2687   // do the JVMTI work here to avoid disturbing the register state below
  2688   // We use c_rarg registers here because we want to use the register used in
  2689   // the call to the VM
  2690 	if (JvmtiExport::can_post_field_access()) {
  2691 		// Check to see if a field access watch has been set before we take
  2692 		// the time to call into the VM.
  2693 		Label L1;
  2694 		assert_different_registers(cache, index, FSR);
  2695 		__ li(AT, (intptr_t)JvmtiExport::get_field_access_count_addr());
  2696 		__ lw(FSR, AT, 0);
  2697 		__ beq(FSR, R0, L1);
  2698 		__ delayed()->nop();
  2700 		// We rely on the bytecode being resolved and the cpCache entry filled in.
  2701 		// cache entry pointer
  2702 		//__ get_cache_and_index_at_bcp(c_rarg2, c_rarg3, 1);
  2703 		__ daddi(cache, cache, in_bytes(ConstantPoolCache::base_offset()));
  2704 		__ shl(index, 4);
  2705 		__ dadd(cache, cache, index);
  2706 		if (is_static) {
  2707 			__ move(FSR, R0);
  2708 		} else {
  2709 			__ lw(FSR, SP, 0);
  2710 			__ verify_oop(FSR);
  2712 		// FSR: object pointer or NULL
  2713 		// cache: cache entry pointer
  2714 		__ call_VM(NOREG, CAST_FROM_FN_PTR(address, 
  2715 					InterpreterRuntime::post_field_access), FSR, cache);
  2716 		__ get_cache_and_index_at_bcp(cache, index, 1);
  2717 		__ bind(L1);
  2721 void TemplateTable::pop_and_check_object(Register r) {
  2722   __ pop_ptr(r);
  2723   __ null_check(r);  // for field access must check obj.
  2724   __ verify_oop(r);
  2727 // used registers : T1, T2, T3, T1
  2728 // T1 : flags
  2729 // T2 : off
  2730 // T3 : obj
  2731 // T1 : field address
  2732 // The flags 31, 30, 29, 28 together build a 4 bit number 0 to 8 with the
  2733 // following mapping to the TosState states:
  2734 // btos: 0
  2735 // ctos: 1
  2736 // stos: 2
  2737 // itos: 3
  2738 // ltos: 4
  2739 // ftos: 5
  2740 // dtos: 6
  2741 // atos: 7
  2742 // vtos: 8
  2743 // see ConstantPoolCacheEntry::set_field for more info
  2744 void TemplateTable::getfield_or_static(int byte_no, bool is_static) {
  2745   transition(vtos, vtos);
  2747   const Register cache = T3;
  2748   const Register index = T0;
  2750   const Register obj   = T3;
  2751   const Register off   = T2;
  2752   const Register flags = T1;
  2753   resolve_cache_and_index(byte_no, cache, index, sizeof(u2));
  2754   //jvmti_post_field_access(cache, index, is_static, false);
  2756   load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  2758   if (!is_static) pop_and_check_object(obj);
  2759   __ dadd(index, obj, off);
  2762   Label Done, notByte, notInt, notShort, notChar, notLong, notFloat, notObj, notDouble;
  2764   assert(btos == 0, "change code, btos != 0");
  2765   __ dsrl(flags, flags, ConstantPoolCacheEntry::tos_state_shift);
  2766   __ andi(flags, flags, 0xf);
  2767   __ bne(flags, R0, notByte);
  2768   __ delayed()->nop();
  2770   // btos
  2771   __ sync();
  2772   __ lb(FSR, index, 0);	
  2773   __ sd(FSR, SP, - wordSize);
  2775   // Rewrite bytecode to be faster
  2776   if (!is_static) {
  2777     patch_bytecode(Bytecodes::_fast_bgetfield, T3, T2);
  2779   __ b(Done);
  2780   __ delayed()->daddi(SP, SP, - wordSize);
  2782   __ bind(notByte);
  2783   __ move(AT, itos);
  2784   __ bne(flags, AT, notInt);
  2785   __ delayed()->nop();
  2787   // itos
  2788   __ sync();
  2789   __ lw(FSR, index, 0);
  2790   __ sd(FSR, SP, - wordSize);
  2792   // Rewrite bytecode to be faster
  2793   if (!is_static) {
  2794     // patch_bytecode(Bytecodes::_fast_igetfield, T3, T2);
  2795     patch_bytecode(Bytecodes::_fast_igetfield, T3, T2);
  2797   __ b(Done);
  2798   __ delayed()->daddi(SP, SP, - wordSize);
  2800   __ bind(notInt);
  2801   __ move(AT, atos);
  2802   __ bne(flags, AT, notObj);
  2803   __ delayed()->nop();
  2805   // atos
  2806   //add for compressedoops
  2807   __ sync();
  2808   __ load_heap_oop(FSR, Address(index, 0));
  2809   __ sd(FSR, SP, - wordSize);
  2811   if (!is_static) {
  2812     //patch_bytecode(Bytecodes::_fast_agetfield, T3, T2);
  2813     patch_bytecode(Bytecodes::_fast_agetfield, T3, T2);
  2815   __ b(Done);
  2816   __ delayed()->daddi(SP, SP, - wordSize);
  2818   __ bind(notObj);
  2819   __ move(AT, ctos);
  2820   __ bne(flags, AT, notChar);
  2821   __ delayed()->nop();
  2823   // ctos
  2824   __ sync();
  2825   __ lhu(FSR, index, 0);
  2826   __ sd(FSR, SP, - wordSize);
  2828   if (!is_static) {
  2829     patch_bytecode(Bytecodes::_fast_cgetfield, T3, T2);
  2831   __ b(Done);
  2832   __ delayed()->daddi(SP, SP, - wordSize);
  2834   __ bind(notChar);
  2835   __ move(AT, stos);
  2836   __ bne(flags, AT, notShort);
  2837   __ delayed()->nop();
  2839   // stos
  2840   __ sync();
  2841   __ lh(FSR, index, 0);
  2842   __ sd(FSR, SP, - wordSize);
  2844   if (!is_static) {
  2845     // patch_bytecode(Bytecodes::_fast_sgetfield, T3, T2);
  2846     patch_bytecode(Bytecodes::_fast_sgetfield, T3, T2);
  2848   __ b(Done);
  2849   __ delayed()->daddi(SP, SP, - wordSize);
  2851   __ bind(notShort);
  2852   __ move(AT, ltos);
  2853   __ bne(flags, AT, notLong);
  2854   __ delayed()->nop();
  2856   // FIXME : the load/store should be atomic, we have no simple method to do this in mips32
  2857   // ltos
  2858   __ sync();
  2859   __ ld(FSR, index, 0 * wordSize);
  2860   __ sd(FSR, SP, -2 * wordSize);
  2861   __ sd(R0, SP, -1 * wordSize);
  2863   // Don't rewrite to _fast_lgetfield for potential volatile case.
  2864   __ b(Done);
  2865   __ delayed()->daddi(SP, SP, - 2 * wordSize);
  2867   __ bind(notLong);
  2868   __ move(AT, ftos);
  2869   __ bne(flags, AT, notFloat);
  2870   __ delayed()->nop();
  2872   // ftos
  2873   __ sync();
  2874   __ lwc1(FSF, index, 0);
  2875   __ sdc1(FSF, SP, - wordSize);
  2877   if (!is_static) {
  2878     patch_bytecode(Bytecodes::_fast_fgetfield, T3, T2);
  2880   __ b(Done);
  2881   __ delayed()->daddi(SP, SP, - wordSize);
  2883   __ bind(notFloat);
  2884   __ move(AT, dtos);
  2885   __ bne(flags, AT, notDouble);
  2886   __ delayed()->nop();
  2888   // dtos
  2889   __ sync();
  2890   __ ldc1(FSF, index, 0 * wordSize);
  2891   __ sdc1(FSF, SP, - 2 * wordSize);
  2892   __ sd(R0, SP, - 1 * wordSize);
  2894   if (!is_static) {
  2895     patch_bytecode(Bytecodes::_fast_dgetfield, T3, T2);
  2897   __ b(Done);
  2898   __ delayed()->daddi(SP, SP, - 2 * wordSize);
  2900   __ bind(notDouble);
  2902   __ stop("Bad state");
  2904   __ bind(Done);
  2907 void TemplateTable::getfield(int byte_no) {
  2908   getfield_or_static(byte_no, false);
  2911 void TemplateTable::getstatic(int byte_no) {
  2912   getfield_or_static(byte_no, true);
  2914 /*
  2915 // used registers : T1, T2, T3, T1
  2916 // T1 : cache & cp entry
  2917 // T2 : obj
  2918 // T3 : flags & value pointer
  2919 // T1 : index
  2920 // see ConstantPoolCacheEntry::set_field for more info
  2921 void TemplateTable::jvmti_post_field_mod(int byte_no, bool is_static) {
  2922  */
  2924 // The registers cache and index expected to be set before call.
  2925 // The function may destroy various registers, just not the cache and index registers.
  2926 void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
  2927 	ByteSize cp_base_offset = ConstantPoolCache::base_offset();
  2929 	if (JvmtiExport::can_post_field_modification()) {
  2930 		// Check to see if a field modification watch has been set before we take
  2931 		// the time to call into the VM.
  2932 		Label L1;
  2933 		assert_different_registers(cache, index, AT);
  2935 		//__ lui(AT, Assembler::split_high((int)JvmtiExport::get_field_modification_count_addr()));
  2936 		//__ lw(FSR, AT, Assembler::split_low((int)JvmtiExport::get_field_modification_count_addr()));
  2937 		__ li(AT, JvmtiExport::get_field_modification_count_addr());
  2938 		__ lw(FSR, AT, 0);
  2939 		__ beq(FSR, R0, L1);
  2940 		__ delayed()->nop();
  2942 		/* // We rely on the bytecode being resolved and the cpCache entry filled in.
  2943 		   resolve_cache_and_index(byte_no, T1, T1);
  2944 		   */
  2945 		// The cache and index registers have been already set.
  2946 		// This allows to eliminate this call but the cache and index
  2947 		// registers have to be correspondingly used after this line.
  2948 		// __ get_cache_and_index_at_bcp(eax, edx, 1);
  2949 		__ get_cache_and_index_at_bcp(T1, T9, 1);
  2951 		if (is_static) {
  2952 			__ move(T2, R0);
  2953 		} else {
  2954 			// Life is harder. The stack holds the value on top, 
  2955 			// followed by the object.
  2956 			// We don't know the size of the value, though; 
  2957 			// it could be one or two words
  2958 			// depending on its type. As a result, we must find 
  2959 			// the type to determine where the object is.
  2960 			Label two_word, valsize_known;
  2961 			__ dsll(AT, T1, 4); 
  2962 			__ dadd(AT, T1, AT);
  2963 			__ lw(T3, AT, in_bytes(cp_base_offset 
  2964 						+ ConstantPoolCacheEntry::flags_offset()));
  2965 			__ move(T2, SP);
  2966 			__ shr(T3, ConstantPoolCacheEntry::tos_state_shift);
  2968 			// Make sure we don't need to mask ecx for tos_state_shift 
  2969 			// after the above shift
  2970 			ConstantPoolCacheEntry::verify_tos_state_shift();
  2971 			__ move(AT, ltos);
  2972 			__ beq(T3, AT, two_word);
  2973 			__ delayed()->nop();
  2974 			__ move(AT, dtos);
  2975 			__ beq(T3, AT, two_word);
  2976 			__ delayed()->nop();
  2977 			__ b(valsize_known);
  2978 			//__ delayed()->daddi(T2, T2, wordSize*1);
  2979 			__ delayed()->daddi(T2, T2,Interpreter::expr_offset_in_bytes(1) );
  2981 			__ bind(two_word);
  2982 			//	__ daddi(T2, T2, wordSize*2);
  2983 			__ daddi(T2, T2,Interpreter::expr_offset_in_bytes(2));
  2985 			__ bind(valsize_known);
  2986 			// setup object pointer
  2987 			__ lw(T2, T2, 0*wordSize);
  2989 		// cache entry pointer
  2990 		__ daddi(T1, T1, in_bytes(cp_base_offset));
  2991 		__ shl(T1, 4); 
  2992 		__ daddu(T1, T1, T1);
  2993 		// object (tos)
  2994 		__ move(T3, SP);
  2995 		// T2: object pointer set up above (NULL if static)
  2996 		// T1: cache entry pointer
  2997 		// T3: jvalue object on the stack
  2998 		__ call_VM(NOREG, CAST_FROM_FN_PTR(address, 
  2999 				InterpreterRuntime::post_field_modification), T2, T1, T3);
  3000 		__ get_cache_and_index_at_bcp(cache, index, 1);
  3001 		__ bind(L1);
  3005 // used registers : T0, T1, T2, T3, T8
  3006 // T1 : flags
  3007 // T2 : off
  3008 // T3 : obj
  3009 // T8 : volatile bit
  3010 // see ConstantPoolCacheEntry::set_field for more info
  3011 void TemplateTable::putfield_or_static(int byte_no, bool is_static) {
  3012   transition(vtos, vtos);
  3014   const Register cache = T3;
  3015   const Register index = T0;
  3016   const Register obj   = T3;
  3017   const Register off   = T2;
  3018   const Register flags = T1;
  3019   const Register bc    = T3;
  3021   resolve_cache_and_index(byte_no, cache, index, sizeof(u2));
  3022   //TODO: LEE
  3023   //jvmti_post_field_mod(cache, index, is_static);
  3024   load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  3025   // Doug Lea believes this is not needed with current Sparcs (TSO) and Intel (PSO).
  3026   // volatile_barrier( );
  3028   Label notVolatile, Done;
  3029   __ move(AT, 1<<ConstantPoolCacheEntry::is_volatile_shift);
  3030   __ andr(T8, flags, AT);
  3032   Label notByte, notInt, notShort, notChar, notLong, notFloat, notObj, notDouble;
  3034   assert(btos == 0, "change code, btos != 0");
  3035   // btos
  3036   __ dsrl(flags, flags, ConstantPoolCacheEntry::tos_state_shift);
  3037   __ andi(flags, flags, ConstantPoolCacheEntry::tos_state_mask);
  3038   __ bne(flags, R0, notByte);
  3039   __ delayed()->nop();
  3041   __ pop(btos);
  3042   if (!is_static) {
  3043     pop_and_check_object(obj); 
  3045   __ dadd(AT, obj, off);
  3046   __ sb(FSR, AT, 0);
  3048   if (!is_static) {
  3049     patch_bytecode(Bytecodes::_fast_bputfield, bc, off, true, byte_no);
  3051   __ b(Done);
  3052   __ delayed()->nop();
  3054   __ bind(notByte);
  3055   // itos
  3056   __ move(AT, itos);
  3057   __ bne(flags, AT, notInt);
  3058   __ delayed()->nop();
  3060   __ pop(itos);
  3061   if (!is_static) {
  3062     pop_and_check_object(obj); 
  3064   __ dadd(AT, obj, off);
  3065   __ sw(FSR, AT, 0);
  3067   if (!is_static) {
  3068     patch_bytecode(Bytecodes::_fast_iputfield, bc, off, true, byte_no);
  3070   __ b(Done);
  3071   __ delayed()->nop();  
  3072   __ bind(notInt);
  3073   // atos
  3074   __ move(AT, atos);
  3075   __ bne(flags, AT, notObj);
  3076   __ delayed()->nop();
  3078   __ pop(atos);
  3079   if (!is_static) {
  3080     pop_and_check_object(obj); 
  3083   __ dadd(AT, obj, off);
  3084   //__ sd(FSR, AT, 0);
  3085   __ store_heap_oop(Address(AT, 0), FSR);
  3086   __ sync();
  3087   __ store_check(obj);
  3089   if (!is_static) {
  3090     patch_bytecode(Bytecodes::_fast_aputfield, bc, off, true, byte_no);
  3092   __ b(Done);
  3093   __ delayed()->nop();
  3094   __ bind(notObj);
  3095   // ctos
  3096   __ move(AT, ctos);
  3097   __ bne(flags, AT, notChar);
  3098   __ delayed()->nop();
  3100   __ pop(ctos);
  3101   if (!is_static) {
  3102     pop_and_check_object(obj); 
  3104   __ dadd(AT, obj, off);
  3105   __ sh(FSR, AT, 0);
  3106   if (!is_static) {
  3107     patch_bytecode(Bytecodes::_fast_cputfield, bc, off, true, byte_no);
  3109   __ b(Done);
  3110   __ delayed()->nop();
  3111   __ bind(notChar);
  3112   // stos
  3113   __ move(AT, stos);
  3114   __ bne(flags, AT, notShort);
  3115   __ delayed()->nop();
  3117   __ pop(stos);
  3118   if (!is_static) {
  3119     pop_and_check_object(obj); 
  3121   __ dadd(AT, obj, off);
  3122   __ sh(FSR, AT, 0);
  3123   if (!is_static) {
  3124     patch_bytecode(Bytecodes::_fast_sputfield, bc, off, true, byte_no);
  3126   __ b(Done);
  3127   __ delayed()->nop();
  3128   __ bind(notShort);
  3129   // ltos
  3130   __ move(AT, ltos);
  3131   __ bne(flags, AT, notLong);
  3132   __ delayed()->nop();
  3134   // FIXME: there is no simple method to load/store 64-bit data in a atomic operation
  3135   // we just ignore the volatile flag.
  3136   //Label notVolatileLong;
  3137   //__ beq(T1, R0, notVolatileLong);
  3138   //__ delayed()->nop();
  3140   //addent = 2 * wordSize;
  3141   // no need
  3142   //__ lw(FSR, SP, 0);
  3143   //__ lw(SSR, SP, 1 * wordSize);
  3144   //if (!is_static) {
  3145   //	__ lw(T3, SP, addent);
  3146   //	addent += 1 * wordSize;
  3147   //	__ verify_oop(T3);
  3148   //}
  3150   //__ daddu(AT, T3, T2);
  3152   // Replace with real volatile test
  3153   // NOTE : we assume that sdc1&ldc1 operate in 32-bit, this is true for Godson2 even in 64-bit kernel
  3154   // last modified by yjl 7/12/2005
  3155   //__ ldc1(FSF, SP, 0); 
  3156   //__ sdc1(FSF, AT, 0);
  3157   //volatile_barrier();
  3159   // Don't rewrite volatile version
  3160   //__ b(notVolatile);
  3161   //__ delayed()->addiu(SP, SP, addent);
  3163   //__ bind(notVolatileLong);
  3165   //__ pop(ltos);  // overwrites edx
  3166   //	__ lw(FSR, SP, 0 * wordSize);
  3167   //	__ lw(SSR, SP, 1 * wordSize);
  3168   //	__ daddi(SP, SP, 2*wordSize);
  3169   __ pop(ltos);
  3170   if (!is_static) {
  3171     pop_and_check_object(obj); 
  3173   __ dadd(AT, obj, off);
  3174   __ sd(FSR, AT, 0);
  3175   if (!is_static) {
  3176     patch_bytecode(Bytecodes::_fast_lputfield, bc, off, true, byte_no);
  3178   __ b(notVolatile);
  3179   __ delayed()->nop();
  3181   __ bind(notLong);
  3182   // ftos
  3183   __ move(AT, ftos);
  3184   __ bne(flags, AT, notFloat);
  3185   __ delayed()->nop();
  3187   __ pop(ftos);
  3188   if (!is_static) {
  3189     pop_and_check_object(obj); 
  3191   __ dadd(AT, obj, off);
  3192   __ swc1(FSF, AT, 0);
  3193   if (!is_static) {
  3194     patch_bytecode(Bytecodes::_fast_fputfield, bc, off, true, byte_no);
  3196   __ b(Done);
  3197   __ delayed()->nop();
  3198   __ bind(notFloat);
  3199   // dtos
  3200   __ move(AT, dtos);
  3201   __ bne(flags, AT, notDouble);
  3202   __ delayed()->nop();
  3204   __ pop(dtos);
  3205   if (!is_static) {
  3206     pop_and_check_object(obj); 
  3208   __ dadd(AT, obj, off);
  3209   __ sdc1(FSF, AT, 0);
  3210   if (!is_static) {
  3211     patch_bytecode(Bytecodes::_fast_dputfield, bc, off, true, byte_no);
  3213   __ b(Done);
  3214   __ delayed()->nop();
  3215   __ bind(notDouble);
  3217   __ stop("Bad state");
  3219   __ bind(Done);
  3221   // Check for volatile store
  3222   __ beq(T8, R0, notVolatile);
  3223   __ delayed()->nop();
  3224   volatile_barrier( );
  3225   __ bind(notVolatile);
  3228 void TemplateTable::putfield(int byte_no) {
  3229   putfield_or_static(byte_no, false);
  3232 void TemplateTable::putstatic(int byte_no) {
  3233   putfield_or_static(byte_no, true);
  3236 // used registers : T1, T2, T3
  3237 // T1 : cp_entry
  3238 // T2 : obj
  3239 // T3 : value pointer
  3240 void TemplateTable::jvmti_post_fast_field_mod() {
  3241 	if (JvmtiExport::can_post_field_modification()) {
  3242 		// Check to see if a field modification watch has been set before we take
  3243 		// the time to call into the VM.
  3244 		Label L2;
  3245 		//__ lui(AT, Assembler::split_high((intptr_t)JvmtiExport::get_field_modification_count_addr()));
  3246 		//__ lw(T3, AT, Assembler::split_low((intptr_t)JvmtiExport::get_field_modification_count_addr()));
  3247 		__ li(AT, JvmtiExport::get_field_modification_count_addr());
  3248 		__ lw(T3, AT, 0);
  3249 		__ beq(T3, R0, L2);
  3250 		__ delayed()->nop();
  3251 		//__ pop(T2);
  3252 		__ pop_ptr(T2);
  3253 		//__ lw(T2, SP, 0);
  3254 		__ verify_oop(T2);
  3255 		__ push_ptr(T2);	
  3256 		__ li(AT, -sizeof(jvalue));
  3257 		__ daddu(SP, SP, AT);
  3258 		__ move(T3, SP);
  3259 		//__ push(T2);
  3260 		//__ move(T2, R0);
  3262 		switch (bytecode()) {          // load values into the jvalue object
  3263 			case Bytecodes::_fast_bputfield: 
  3264 				__ sb(FSR, SP, 0); 
  3265 				break;
  3266 			case Bytecodes::_fast_sputfield: 
  3267 				__ sh(FSR, SP, 0);
  3268 				break;
  3269 			case Bytecodes::_fast_cputfield: 
  3270 				__ sh(FSR, SP, 0);
  3271 				break;
  3272 			case Bytecodes::_fast_iputfield: 
  3273 				__ sw(FSR, SP, 0);
  3274 				break;							 
  3275 			case Bytecodes::_fast_lputfield: 
  3276 				__ sd(FSR, SP, 0);
  3277 				break;
  3278 			case Bytecodes::_fast_fputfield: 
  3279 				__ swc1(FSF, SP, 0);
  3280 				break;
  3281 			case Bytecodes::_fast_dputfield: 
  3282 				__ sdc1(FSF, SP, 0);
  3283 				break;
  3284 			case Bytecodes::_fast_aputfield: 
  3285 				__ sd(FSR, SP, 0);
  3286 				break;
  3287 			default:  ShouldNotReachHere();
  3290 		//__ pop(T2);  // restore copy of object pointer
  3292 		// Save eax and sometimes edx because call_VM() will clobber them,
  3293 		// then use them for JVM/DI purposes
  3294 		__ push(FSR);
  3295 		if (bytecode() == Bytecodes::_fast_lputfield) __ push(SSR);
  3296 		// access constant pool cache entry
  3297 		__ get_cache_entry_pointer_at_bcp(T1, T2, 1);
  3298 		// no need, verified ahead
  3299 		__ verify_oop(T2);
  3301 		// ebx: object pointer copied above
  3302 		// eax: cache entry pointer
  3303 		// ecx: jvalue object on the stack
  3304 		__ call_VM(NOREG, CAST_FROM_FN_PTR(address, 
  3305 					InterpreterRuntime::post_field_modification), T2, T1, T3);
  3306 		if (bytecode() == Bytecodes::_fast_lputfield) __ pop(SSR);  // restore high value
  3307 		//__ pop(FSR);     // restore lower value   
  3308 		//__ daddi(SP, SP, sizeof(jvalue));  // release jvalue object space
  3309 		__ lw(FSR, SP, 0);
  3310 		__ daddiu(SP, SP, sizeof(jvalue) + 1 * wordSize);
  3311 		__ bind(L2);
  3315 // used registers : T2, T3, T1
  3316 // T2 : index & off & field address
  3317 // T3 : cache & obj
  3318 // T1 : flags
  3319 void TemplateTable::fast_storefield(TosState state) {
  3320   transition(state, vtos);
  3322   ByteSize base = ConstantPoolCache::base_offset();
  3324   jvmti_post_fast_field_mod();
  3326   // access constant pool cache
  3327   __ get_cache_and_index_at_bcp(T3, T2, 1);
  3329   // test for volatile with edx but edx is tos register for lputfield.
  3330   __ dsll(AT, T2, Address::times_8); 
  3331   __ dadd(AT, T3, AT);
  3332   __ ld(T1, AT, in_bytes(base + ConstantPoolCacheEntry::flags_offset()));
  3334   // replace index with field offset from cache entry
  3335   __ ld(T2, AT, in_bytes(base + ConstantPoolCacheEntry::f2_offset()));
  3337   // Doug Lea believes this is not needed with current Sparcs (TSO) and Intel (PSO).
  3338   // volatile_barrier( );
  3340   Label notVolatile, Done;
  3341   // Check for volatile store
  3342   __ move(AT, 1<<ConstantPoolCacheEntry::is_volatile_shift);
  3343   __ andr(AT, T1, AT);
  3344   __ beq(AT, R0, notVolatile);
  3345   __ delayed()->nop();
  3348   // Get object from stack
  3349   // NOTE : the value in FSR/FSF now
  3350   //	__ pop(T3);
  3351   //	__ verify_oop(T3);
  3352   pop_and_check_object(T3);
  3353   // field addresses
  3354   __ dadd(T2, T3, T2);
  3356   // access field
  3357   switch (bytecode()) {
  3358     case Bytecodes::_fast_bputfield: 
  3359       __ sb(FSR, T2, 0);
  3360       break;
  3361     case Bytecodes::_fast_sputfield: // fall through
  3362     case Bytecodes::_fast_cputfield: 
  3363       __ sh(FSR, T2, 0);
  3364       break;
  3365     case Bytecodes::_fast_iputfield: 
  3366       __ sw(FSR, T2, 0);
  3367       break;
  3368     case Bytecodes::_fast_lputfield: 
  3369       __ sd(FSR, T2, 0 * wordSize);
  3370       break;
  3371     case Bytecodes::_fast_fputfield: 
  3372       __ swc1(FSF, T2, 0);
  3373       break;
  3374     case Bytecodes::_fast_dputfield: 
  3375       __ sdc1(FSF, T2, 0 * wordSize);
  3376       break;
  3377     case Bytecodes::_fast_aputfield: 
  3378       __ store_heap_oop(Address(T2, 0), FSR);
  3379       __ sync();
  3380       __ store_check(T3);
  3381       break;
  3382     default:
  3383       ShouldNotReachHere();
  3386   Label done;
  3387   volatile_barrier( );
  3388   __ b(done);
  3389   __ delayed()->nop();
  3391   // Same code as above, but don't need edx to test for volatile.
  3392   __ bind(notVolatile);
  3394   // Get object from stack
  3395   //	__ pop(T3);
  3396   //	__ verify_oop(T3);
  3397   pop_and_check_object(T3);
  3398   //get the field address
  3399   __ dadd(T2, T3, T2);
  3401   // access field
  3402   switch (bytecode()) {
  3403     case Bytecodes::_fast_bputfield: 
  3404       __ sb(FSR, T2, 0); 
  3405       break;
  3406     case Bytecodes::_fast_sputfield: // fall through
  3407     case Bytecodes::_fast_cputfield: 
  3408       __ sh(FSR, T2, 0);
  3409       break;
  3410     case Bytecodes::_fast_iputfield: 
  3411       __ sw(FSR, T2, 0);
  3412       break;
  3413     case Bytecodes::_fast_lputfield: 
  3414       __ sd(FSR, T2, 0 * wordSize);
  3415       break;
  3416     case Bytecodes::_fast_fputfield: 
  3417       __ swc1(FSF, T2, 0);
  3418       break;
  3419     case Bytecodes::_fast_dputfield: 
  3420       __ sdc1(FSF, T2, 0 * wordSize);
  3421       break;
  3422     case Bytecodes::_fast_aputfield: 
  3423       //add for compressedoops
  3424       __ store_heap_oop(Address(T2, 0), FSR);
  3425       __ sync();
  3426       __ store_check(T3);
  3427       break;
  3428     default:
  3429       ShouldNotReachHere();
  3431   __ bind(done);
  3434 // used registers : T2, T3, T1
  3435 // T3 : cp_entry & cache
  3436 // T2 : index & offset
  3437 void TemplateTable::fast_accessfield(TosState state) {
  3438   transition(atos, state);
  3440   // do the JVMTI work here to avoid disturbing the register state below
  3441   if (JvmtiExport::can_post_field_access()) {
  3442     // Check to see if a field access watch has been set before we take
  3443     // the time to call into the VM.
  3444     Label L1;
  3445     __ li(AT, (intptr_t)JvmtiExport::get_field_access_count_addr());
  3446     __ lw(T3, AT, 0);
  3447     __ beq(T3, R0, L1);
  3448     __ delayed()->nop();
  3449     // access constant pool cache entry
  3450     __ get_cache_entry_pointer_at_bcp(T3, T1, 1);
  3451     __ move(TSR, FSR);
  3452     __ verify_oop(FSR);
  3453     // FSR: object pointer copied above
  3454     // T3: cache entry pointer
  3455     __ call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access),
  3456 	FSR, T3);
  3457     __ move(FSR, TSR);
  3458     __ bind(L1);
  3461   // access constant pool cache
  3462   __ get_cache_and_index_at_bcp(T3, T2, 1);
  3463   // replace index with field offset from cache entry
  3464   __ dsll(AT, T2, Address::times_8);
  3465   //__ dsll(AT, T2, 4);
  3466   __ dadd(AT, T3, AT);
  3467   __ ld(T2, AT, in_bytes(ConstantPoolCache::base_offset() 
  3468 	+ ConstantPoolCacheEntry::f2_offset()));
  3470   // eax: object
  3471   __ verify_oop(FSR);
  3472   // __ null_check(FSR, 0);
  3473   __ null_check(FSR);
  3474   // field addresses
  3475   __ dadd(FSR, FSR, T2);
  3477   // access field
  3478   switch (bytecode()) {
  3479     case Bytecodes::_fast_bgetfield: 
  3480       __ lb(FSR, FSR, 0);
  3481       break;
  3482     case Bytecodes::_fast_sgetfield: 
  3483       __ lh(FSR, FSR, 0);
  3484       break;
  3485     case Bytecodes::_fast_cgetfield: 
  3486       __ lhu(FSR, FSR, 0);
  3487       break;
  3488     case Bytecodes::_fast_igetfield:
  3489       __ lw(FSR, FSR, 0);
  3490       break;
  3491     case Bytecodes::_fast_lgetfield: 
  3492       __ stop("should not be rewritten");  
  3493       break;
  3494     case Bytecodes::_fast_fgetfield: 
  3495       __ lwc1(FSF, FSR, 0);
  3496       break;
  3497     case Bytecodes::_fast_dgetfield: 
  3498       __ ldc1(FSF, FSR, 0);
  3499       break;
  3500     case Bytecodes::_fast_agetfield:
  3501       //add for compressedoops
  3502       __ load_heap_oop(FSR, Address(FSR, 0));
  3503       __ verify_oop(FSR);
  3504       break;
  3505     default:
  3506       ShouldNotReachHere();
  3509   // Doug Lea believes this is not needed with current Sparcs(TSO) and Intel(PSO)
  3510   // volatile_barrier( );
  3513 // generator for _fast_iaccess_0, _fast_aaccess_0, _fast_faccess_0
  3514 // used registers : T1, T2, T3, T1
  3515 // T1 : obj & field address
  3516 // T2 : off
  3517 // T3 : cache
  3518 // T1 : index
  3519 void TemplateTable::fast_xaccess(TosState state) {
  3520   transition(vtos, state);
  3521   // get receiver
  3522   __ ld(T1, aaddress(0));
  3523   // access constant pool cache
  3524   __ get_cache_and_index_at_bcp(T3, T2, 2);
  3525   __ dsll(AT, T2, Address::times_8);
  3526   __ dadd(AT, T3, AT);
  3527   __ ld(T2, AT, in_bytes(ConstantPoolCache::base_offset() 
  3528 	+ ConstantPoolCacheEntry::f2_offset()));
  3530   // make sure exception is reported in correct bcp range (getfield is next instruction)
  3531   __ daddi(BCP, BCP, 1);
  3532   //	__ null_check(T1, 0);
  3533   __ null_check(T1);
  3534   __ dadd(T1, T1, T2);
  3536   if (state == itos) {
  3537     __ lw(FSR, T1, 0);
  3538   } else if (state == atos) {
  3539     //__ ld(FSR, T1, 0);
  3540     __ load_heap_oop(FSR, Address(T1, 0));
  3541     __ verify_oop(FSR);
  3542   } else if (state == ftos) {
  3543     __ lwc1(FSF, T1, 0);
  3544   } else {
  3545     ShouldNotReachHere();
  3547   __ daddi(BCP, BCP, -1);
  3550 //---------------------------------------------------
  3551 //-------------------------------------------------
  3552 // Calls
  3554 void TemplateTable::count_calls(Register method, Register temp) {  
  3555 	// implemented elsewhere
  3556 	ShouldNotReachHere();
  3559 // method, index, recv, flags: T1, T2, T3, T1
  3560 // byte_no = 2 for _invokevirtual, 1 else
  3561 // T0 : return address
  3562 // get the method & index of the invoke, and push the return address of 
  3563 // the invoke(first word in the frame)
  3564 // this address is where the return code jmp to.
  3565 // NOTE : this method will set T3&T1 as recv&flags
  3566 void TemplateTable::prepare_invoke(int byte_no,
  3567                                    Register method, //linked method (or i-klass)
  3568                                    Register index, //itable index, MethodType ,etc.
  3569                                    Register recv, // if caller wants to see it
  3570                                    Register flags // if caller wants to test it
  3571 		                   ) {
  3572   // determine flags
  3573   const Bytecodes::Code code = bytecode();
  3574   const bool is_invokeinterface  = code == Bytecodes::_invokeinterface;
  3575   const bool is_invokedynamic    = code == Bytecodes::_invokedynamic;
  3576   const bool is_invokehandle     = code == Bytecodes::_invokehandle;
  3577   const bool is_invokevirtual    = code == Bytecodes::_invokevirtual;
  3578   const bool is_invokespecial    = code == Bytecodes::_invokespecial;
  3579   const bool load_receiver       = (recv  != noreg);
  3580   const bool save_flags          = (flags != noreg);
  3581   assert(load_receiver == (code != Bytecodes::_invokestatic && code != Bytecodes::_invokedynamic),"");
  3582   assert(save_flags    == (is_invokeinterface || is_invokevirtual), "need flags for vfinal");
  3583   assert(flags == noreg || flags == T1, "error flags reg.");
  3584   assert(recv  == noreg || recv  == T3, "error recv reg.");
  3585   // setup registers & access constant pool cache
  3586   if(recv == noreg) recv  = T3;
  3587   if(flags == noreg) flags  = T1;
  3589   assert_different_registers(method, index, recv, flags);
  3591   // save 'interpreter return address'
  3592   __ save_bcp();
  3594   load_invoke_cp_cache_entry(byte_no, method, index, flags, is_invokevirtual, false, is_invokedynamic);
  3595   if (is_invokedynamic || is_invokehandle) {
  3596    Label L_no_push;
  3597      __ move(AT, (1 << ConstantPoolCacheEntry::has_appendix_shift));
  3598      __ andr(AT, AT, flags);
  3599      __ beq(AT, R0, L_no_push);
  3600      __ delayed()->nop();
  3601      // Push the appendix as a trailing parameter.
  3602      // This must be done before we get the receiver,
  3603      // since the parameter_size includes it.
  3604      Register tmp = SSR;
  3605      __ push(tmp);
  3606      __ move(tmp, index);
  3607      assert(ConstantPoolCacheEntry::_indy_resolved_references_appendix_offset == 0, "appendix expected at index+0");
  3608      __ load_resolved_reference_at_index(index, tmp);
  3609      __ pop(tmp);
  3610      __ push(index);  // push appendix (MethodType, CallSite, etc.)
  3611      __ bind(L_no_push);
  3615 // load receiver if needed (after appendix is pushed so parameter size is correct)
  3616 // Note: no return address pushed yet
  3617   if (load_receiver) {
  3618 	 __ move(AT, ConstantPoolCacheEntry::parameter_size_mask);
  3619 	 __ andr(recv, flags, AT);
  3620          // 2014/07/31 Fu: Since we won't push RA on stack, no_return_pc_pushed_yet should be 0.
  3621 	 const int no_return_pc_pushed_yet = 0;  // argument slot correction before we push return address
  3622 	 const int receiver_is_at_end      = -1;  // back off one slot to get receiver
  3623 	 Address recv_addr = __ argument_address(recv, no_return_pc_pushed_yet + receiver_is_at_end);
  3625 	 __ ld(recv, recv_addr);
  3626 	 __ verify_oop(recv);	
  3628   if(save_flags) {
  3629     //__ movl(r13, flags);
  3630     __ move(BCP, flags);
  3632   // compute return type
  3633   __ dsrl(flags, flags, ConstantPoolCacheEntry::tos_state_shift);
  3634   __ andi(flags, flags, 0xf);
  3636   // Make sure we don't need to mask flags for tos_state_shift after the above shift
  3637   ConstantPoolCacheEntry::verify_tos_state_shift();
  3638   // load return address
  3640     const address table = (address) Interpreter::invoke_return_entry_table_for(code);
  3641     __ li(AT, (long)table);
  3642     __ dsll(flags, flags, LogBytesPerWord);
  3643     __ dadd(AT, AT, flags);
  3644     __ ld(RA, AT, 0);
  3647   if (save_flags) {
  3648     __ move(flags, BCP);
  3649     __ restore_bcp();
  3653 // used registers : T0, T3, T1, T2
  3654 // T3 : recv, this two register using convention is by prepare_invoke
  3655 // T1 : flags, klass
  3656 // Rmethod : method, index must be Rmethod
  3657 void TemplateTable::invokevirtual_helper(Register index, Register recv,
  3658 		Register flags) {
  3660   assert_different_registers(index, recv, flags, T2);
  3662   // Test for an invoke of a final method
  3663   Label notFinal;
  3664   __ move(AT, (1 << ConstantPoolCacheEntry::is_vfinal_shift));
  3665   __ andr(AT, flags, AT);
  3666   __ beq(AT, R0, notFinal);
  3667   __ delayed()->nop();
  3669   Register method = index;  // method must be Rmethod
  3670   assert(method == Rmethod, "methodOop must be Rmethod for interpreter calling convention");
  3672   // do the call - the index is actually the method to call
  3673   // the index is indeed methodOop, for this is vfinal, 
  3674   // see ConstantPoolCacheEntry::set_method for more info
  3676   __ verify_oop(method);
  3678   // It's final, need a null check here!
  3679   __ null_check(recv);
  3681   // profile this call
  3682   __ profile_final_call(T2);
  3684   // 2014/11/24 Fu 
  3685   // T2: tmp, used for mdp
  3686   // method: callee
  3687   // T9: tmp
  3688   // is_virtual: true 
  3689   __ profile_arguments_type(T2, method, T9, true);
  3691 //  __ move(T0, recv);
  3692   __ jump_from_interpreted(method, T2);
  3694   __ bind(notFinal);
  3696   // get receiver klass
  3697   __ null_check(recv, oopDesc::klass_offset_in_bytes());
  3698   // Keep recv in ecx for callee expects it there
  3699   __ load_klass(T2, recv);
  3700   __ verify_oop(T2);
  3701   // profile this call
  3702   __ profile_virtual_call(T2, T0, T1);
  3704   // get target methodOop & entry point
  3705   const int base = InstanceKlass::vtable_start_offset() * wordSize;    
  3706   assert(vtableEntry::size() * wordSize == 8, "adjust the scaling in the code below");
  3707   __ dsll(AT, index, Address::times_8);
  3708   __ dadd(AT, T2, AT);
  3709   //this is a ualign read 
  3710   __ ld(method, AT, base + vtableEntry::method_offset_in_bytes());
  3711   __ jump_from_interpreted(method, T2);
  3715 void TemplateTable::invokevirtual(int byte_no) {
  3716   transition(vtos, vtos);
  3717   assert(byte_no == f2_byte, "use this argument");
  3718   prepare_invoke(byte_no, Rmethod, NOREG, T3, T1);
  3719   // now recv & flags in T3, T1
  3720   invokevirtual_helper(Rmethod, T3, T1);
  3723 // T9 : entry
  3724 // Rmethod : method
  3725 void TemplateTable::invokespecial(int byte_no) {
  3726   transition(vtos, vtos);
  3727   assert(byte_no == f1_byte, "use this argument");
  3728   prepare_invoke(byte_no, Rmethod, NOREG, T3);
  3729   // now recv & flags in T3, T1
  3730   __ verify_oop(T3);
  3731   __ null_check(T3);
  3732   __ profile_call(T9);
  3734   // 2014/11/24 Fu 
  3735   // T8: tmp, used for mdp
  3736   // Rmethod: callee
  3737   // T9: tmp
  3738   // is_virtual: false 
  3739   __ profile_arguments_type(T8, Rmethod, T9, false);
  3741   __ jump_from_interpreted(Rmethod, T9);
  3742   __ move(T0, T3);//aoqi ?
  3745 void TemplateTable::invokestatic(int byte_no) {
  3746   transition(vtos, vtos);
  3747   assert(byte_no == f1_byte, "use this argument");
  3748   prepare_invoke(byte_no, Rmethod, NOREG);
  3749   __ verify_oop(Rmethod);
  3751   __ profile_call(T9);
  3753   // 2014/11/24 Fu 
  3754   // T8: tmp, used for mdp
  3755   // Rmethod: callee
  3756   // T9: tmp
  3757   // is_virtual: false 
  3758   __ profile_arguments_type(T8, Rmethod, T9, false);
  3760   __ jump_from_interpreted(Rmethod, T9);
  3763 // i have no idea what to do here, now. for future change. FIXME. 
  3764 void TemplateTable::fast_invokevfinal(int byte_no) {
  3765 	transition(vtos, vtos);
  3766 	assert(byte_no == f2_byte, "use this argument");
  3767 	__ stop("fast_invokevfinal not used on x86");
  3770 // used registers : T0, T1, T2, T3, T1, A7
  3771 // T0 : itable, vtable, entry
  3772 // T1 : interface
  3773 // T3 : receiver
  3774 // T1 : flags, klass
  3775 // Rmethod : index, method, this is required by interpreter_entry
  3776 void TemplateTable::invokeinterface(int byte_no) {
  3777   transition(vtos, vtos);
  3778   //this method will use T1-T4 and T0
  3779   assert(byte_no == f1_byte, "use this argument");
  3780   prepare_invoke(byte_no, T2, Rmethod, T3, T1);
  3781   // T2: Interface
  3782   // Rmethod: index
  3783   // T3: receiver    
  3784   // T1: flags
  3785   Label notMethod;
  3786   __ move(AT, (1 << ConstantPoolCacheEntry::is_forced_virtual_shift));
  3787   __ andr(AT, T1, AT);
  3788   __ beq(AT, R0, notMethod);
  3789   __ delayed()->nop();
  3791   // Special case of invokeinterface called for virtual method of
  3792   // java.lang.Object.  See cpCacheOop.cpp for details.
  3793   // This code isn't produced by javac, but could be produced by
  3794   // another compliant java compiler.
  3795   invokevirtual_helper(Rmethod, T3, T1);
  3797   __ bind(notMethod);
  3798   // Get receiver klass into T1 - also a null check
  3799   //__ ld(T1, T3, oopDesc::klass_offset_in_bytes());
  3800   //add for compressedoops
  3801   //__ restore_locals();
  3802   //__ null_check(T3, oopDesc::klass_offset_in_bytes());
  3803   __ load_klass(T1, T3);
  3804   __ verify_oop(T1);
  3806   // profile this call
  3807   __ profile_virtual_call(T1, T0, FSR);
  3809   // Compute start of first itableOffsetEntry (which is at the end of the vtable)
  3810   // TODO: x86 add a new method lookup_interface_method  // LEE
  3811   const int base = InstanceKlass::vtable_start_offset() * wordSize;    
  3812   assert(vtableEntry::size() * wordSize == 8, "adjust the scaling in the code below");
  3813   __ lw(AT, T1, InstanceKlass::vtable_length_offset() * wordSize);
  3814   __ dsll(AT, AT, Address::times_8);
  3815   __ dadd(T0, T1, AT);
  3816   __ daddi(T0, T0, base);
  3817   if (HeapWordsPerLong > 1) {
  3818     // Round up to align_object_offset boundary
  3819     __ round_to(T0, BytesPerLong);
  3821   // now T0 is the begin of the itable
  3823   Label entry, search, interface_ok;
  3825   ///__ jmp(entry);   
  3826   __ b(entry);
  3827   __ delayed()->nop();
  3829   __ bind(search);
  3830   __ increment(T0, itableOffsetEntry::size() * wordSize);
  3832   __ bind(entry);
  3834   // Check that the entry is non-null.  A null entry means that the receiver
  3835   // class doesn't implement the interface, and wasn't the same as the
  3836   // receiver class checked when the interface was resolved.
  3837   __ ld(AT, T0, itableOffsetEntry::interface_offset_in_bytes());
  3838   __ bne(AT, R0, interface_ok);
  3839   __ delayed()->nop();
  3840   // throw exception
  3841   // the call_VM checks for exception, so we should never return here.
  3843   //__ pop();//FIXME here,			
  3844   // pop return address (pushed by prepare_invoke). 
  3845   // no need now, we just save the value in RA now
  3847   __ call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_IncompatibleClassChangeError));
  3848   __ should_not_reach_here();
  3850   __ bind(interface_ok);
  3851   //NOTICE here, no pop as x86 do	
  3852   //__ lw(AT, T0, itableOffsetEntry::interface_offset_in_bytes());
  3853   __ bne(AT, T2, search);
  3854   __ delayed()->nop();
  3856   // now we get vtable of the interface
  3857   __ ld(T0, T0, itableOffsetEntry::offset_offset_in_bytes());
  3858   __ daddu(T0, T1, T0);
  3859   assert(itableMethodEntry::size() * wordSize == 8, "adjust the scaling in the code below");
  3860   __ dsll(AT, Rmethod, Address::times_8);
  3861   __ daddu(AT, T0, AT);
  3862   // now we get the method
  3863   __ ld(Rmethod, AT, 0);
  3864   // Rnext: methodOop to call
  3865   // T3: receiver
  3866   // Check for abstract method error
  3867   // Note: This should be done more efficiently via a throw_abstract_method_error
  3868   //       interpreter entry point and a conditional jump to it in case of a null
  3869   //       method.
  3871     Label L;
  3872     ///__ testl(ebx, ebx);
  3873     ///__ jcc(Assembler::notZero, L);
  3874     __ bne(Rmethod, R0, L);
  3875     __ delayed()->nop();
  3877     // throw exception
  3878     // note: must restore interpreter registers to canonical
  3879     //       state for exception handling to work correctly!
  3880     ///__ popl(ebx);          // pop return address (pushed by prepare_invoke)
  3881     //__ restore_bcp();      // esi must be correct for exception handler   
  3882     //(was destroyed)
  3883     //__ restore_locals();   // make sure locals pointer 
  3884     //is correct as well (was destroyed)
  3885     ///__ call_VM(noreg, CAST_FROM_FN_PTR(address, 
  3886     //InterpreterRuntime::throw_AbstractMethodError));
  3887     __ call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError));
  3888     // the call_VM checks for exception, so we should never return here.
  3889     __ should_not_reach_here();
  3890     __ bind(L);
  3893   // 2014/11/24 Fu 
  3894   // T8: tmp, used for mdp
  3895   // Rmethod: callee
  3896   // T9: tmp
  3897   // is_virtual: true
  3898   __ profile_arguments_type(T8, Rmethod, T9, true);
  3900   __ jump_from_interpreted(Rmethod, T9);
  3903 void TemplateTable::invokehandle(int byte_no) {
  3904   transition(vtos, vtos);
  3905   assert(byte_no == f1_byte, "use this argument");
  3906   const Register T2_method = Rmethod;
  3907   const Register FSR_mtype  = FSR;
  3908   const Register T3_recv   = T3;
  3910   if (!EnableInvokeDynamic) {
  3911      // rewriter does not generate this bytecode
  3912      __ should_not_reach_here();
  3913      return;
  3916    prepare_invoke(byte_no, T2_method, FSR_mtype, T3_recv);
  3917    //??__ verify_method_ptr(T2_method);
  3918    __ verify_oop(T3_recv);
  3919    __ null_check(T3_recv);
  3921    // rax: MethodType object (from cpool->resolved_references[f1], if necessary)
  3922    // rbx: MH.invokeExact_MT method (from f2)
  3924    // Note:  rax_mtype is already pushed (if necessary) by prepare_invoke
  3926    // FIXME: profile the LambdaForm also
  3927    __ profile_final_call(T9);
  3929    // 2014/11/24 Fu 
  3930    // T8: tmp, used for mdp
  3931    // T2_method: callee
  3932    // T9: tmp
  3933    // is_virtual: true
  3934    __ profile_arguments_type(T8, T2_method, T9, true);
  3936   __ jump_from_interpreted(T2_method, T9);
  3939  void TemplateTable::invokedynamic(int byte_no) {
  3940    transition(vtos, vtos);
  3941    assert(byte_no == f1_byte, "use this argument");
  3943    if (!EnableInvokeDynamic) {
  3944      // We should not encounter this bytecode if !EnableInvokeDynamic.
  3945      // The verifier will stop it.  However, if we get past the verifier,
  3946      // this will stop the thread in a reasonable way, without crashing the JVM.
  3947      __ call_VM(noreg, CAST_FROM_FN_PTR(address,
  3948                       InterpreterRuntime::throw_IncompatibleClassChangeError));
  3949      // the call_VM checks for exception, so we should never return here.
  3950      __ should_not_reach_here();
  3951      return;
  3954    //const Register Rmethod   = T2;
  3955    const Register T2_callsite = T2;
  3957    prepare_invoke(byte_no, Rmethod, T2_callsite);
  3959    // rax: CallSite object (from cpool->resolved_references[f1])
  3960    // rbx: MH.linkToCallSite method (from f2)
  3962    // Note:  rax_callsite is already pushed by prepare_invoke
  3963    // %%% should make a type profile for any invokedynamic that takes a ref argument
  3964    // profile this call
  3965    __ profile_call(T9);
  3967    // 2014/11/24 Fu 
  3968    // T8: tmp, used for mdp
  3969    // Rmethod: callee
  3970    // T9: tmp
  3971    // is_virtual: false 
  3972    __ profile_arguments_type(T8, Rmethod, T9, false);
  3974    __ verify_oop(T2_callsite);
  3976    __ jump_from_interpreted(Rmethod, T9);
  3979 //----------------------------------------------------------------------------------------------------
  3980 // Allocation
  3981 // T1 : tags & buffer end & thread
  3982 // T2 : object end
  3983 // T3 : klass
  3984 // T1 : object size
  3985 // A1 : cpool
  3986 // A2 : cp index
  3987 // return object in FSR
  3988 void TemplateTable::_new() {
  3989   transition(vtos, atos);
  3990   __ get_2_byte_integer_at_bcp(A2, AT, 1);
  3991   __ huswap(A2);
  3993   Label slow_case;
  3994   Label done;
  3995   Label initialize_header;
  3996   Label initialize_object;  // including clearing the fields
  3997   Label allocate_shared;
  3999   // get InstanceKlass in T3
  4000   __ get_cpool_and_tags(A1, T1);
  4001   __ dsll(AT, A2, Address::times_8);
  4002   __ dadd(AT, A1, AT);
  4003   __ ld(T3, AT, sizeof(ConstantPool));
  4005   // make sure the class we're about to instantiate has been resolved. 
  4006   // Note: slow_case does a pop of stack, which is why we loaded class/pushed above
  4007   const int tags_offset = Array<u1>::base_offset_in_bytes();
  4008   __ dadd(T1, T1, A2);
  4009   __ lb(AT, T1, tags_offset);
  4010   //__ addiu(AT, AT, - (int)JVM_CONSTANT_UnresolvedClass);
  4011   __ daddiu(AT, AT, - (int)JVM_CONSTANT_Class);
  4012   //__ beq(AT, R0, slow_case);
  4013   __ bne(AT, R0, slow_case);
  4014   __ delayed()->nop();
  4016   /*make sure klass is initialized & doesn't have finalizer*/
  4018   // make sure klass is fully initialized
  4019   __ lhu(T1, T3, in_bytes(InstanceKlass::init_state_offset()));
  4020   __ daddiu(AT, T1, - (int)InstanceKlass::fully_initialized);
  4021   __ bne(AT, R0, slow_case);
  4022   __ delayed()->nop();
  4024   // has_finalizer
  4025   //__ lw(T1, T3, Klass::access_flags_offset() + sizeof(oopDesc));
  4026   //__ move(AT, JVM_ACC_CAN_BE_FASTPATH_ALLOCATED);
  4027   //__ andr(AT, T1, AT);
  4028   __ lw(T1, T3, in_bytes(Klass::layout_helper_offset()) );
  4029   __ andi(AT, T1, Klass::_lh_instance_slow_path_bit);
  4030   __ bne(AT, R0, slow_case);
  4031   __ delayed()->nop();
  4033   // get instance_size in InstanceKlass (already aligned) in T0, 
  4034   // be sure to preserve this value 
  4035   //__ lw(T0, T3, Klass::size_helper_offset_in_bytes() + sizeof(oopDesc));
  4036   //Klass::_size_helper is renamed Klass::_layout_helper. aoqi 
  4037   __ lw(T0, T3, in_bytes(Klass::layout_helper_offset()) );
  4039   // 
  4040   // Allocate the instance
  4041   // 1) Try to allocate in the TLAB
  4042   // 2) if fail and the object is large allocate in the shared Eden
  4043   // 3) if the above fails (or is not applicable), go to a slow case
  4044   // (creates a new TLAB, etc.)
  4046   const bool allow_shared_alloc =
  4047     Universe::heap()->supports_inline_contig_alloc() && !CMSIncrementalMode;
  4049   if (UseTLAB) {
  4050 #ifndef OPT_THREAD
  4051     const Register thread = T8;
  4052     __ get_thread(thread);
  4053 #else
  4054     const Register thread = TREG;
  4055 #endif
  4056     // get tlab_top
  4057     __ ld(FSR, thread, in_bytes(JavaThread::tlab_top_offset()));
  4058     __ dadd(T2, FSR, T0);
  4059     // get tlab_end
  4060     __ ld(AT, thread, in_bytes(JavaThread::tlab_end_offset()));
  4061     __ slt(AT, AT, T2);
  4062     //		__ bne(AT, R0, allocate_shared);
  4063     __ bne(AT, R0, allow_shared_alloc ? allocate_shared : slow_case);
  4064     __ delayed()->nop();
  4065     __ sd(T2, thread, in_bytes(JavaThread::tlab_top_offset()));
  4067     if (ZeroTLAB) {
  4068       // the fields have been already cleared
  4069       __ b_far(initialize_header);
  4070     } else {
  4071       // initialize both the header and fields
  4072       __ b_far(initialize_object);
  4074     __ delayed()->nop();
  4075     /*
  4077        if (CMSIncrementalMode) {
  4078     // No allocation in shared eden. 
  4079     ///__ jmp(slow_case);
  4080     __ b(slow_case);
  4081     __ delayed()->nop();
  4083      */ 
  4086   // Allocation in the shared Eden , if allowed
  4087   // T0 : instance size in words
  4088   if(allow_shared_alloc){ 
  4089     __ bind(allocate_shared);
  4090     Label retry;
  4091     //Address heap_top(T1, (int)Universe::heap()->top_addr());
  4092     Address heap_top(T1);
  4093     //__ lui(T1, Assembler::split_high((int)Universe::heap()->top_addr()));
  4094     __ li(T1, (long)Universe::heap()->top_addr());
  4096     __ ld(FSR, heap_top);
  4097     __ bind(retry);
  4098     __ dadd(T2, FSR, T0);
  4099     //__ lui(AT, Assembler::split_high((int)Universe::heap()->end_addr()));
  4100     //__ lw(AT, AT, Assembler::split_low((int)Universe::heap()->end_addr()));
  4101     __ li(AT, (long)Universe::heap()->end_addr());
  4102     __ ld(AT, AT, 0);
  4103     __ slt(AT, AT, T2);
  4104     __ bne(AT, R0, slow_case);
  4105     __ delayed()->nop();
  4107     // Compare FSR with the top addr, and if still equal, store the new
  4108     // top addr in ebx at the address of the top addr pointer. Sets ZF if was
  4109     // equal, and clears it otherwise. Use lock prefix for atomicity on MPs.
  4110     //
  4111     // FSR: object begin
  4112     // T2: object end
  4113     // T0: instance size in words
  4115     // if someone beat us on the allocation, try again, otherwise continue 
  4116     //__ lui(T1, Assembler::split_high((int)Universe::heap()->top_addr()));
  4117     __ cmpxchg(T2, heap_top, FSR);
  4118     __ beq(AT, R0, retry);
  4119     __ delayed()->nop();
  4122   if (UseTLAB || Universe::heap()->supports_inline_contig_alloc()) {
  4123     // The object is initialized before the header.  If the object size is
  4124     // zero, go directly to the header initialization.
  4125     __ bind(initialize_object);
  4126     __ li(AT, - sizeof(oopDesc));
  4127     __ daddu(T0, T0, AT);
  4128     __ beq_far(T0, R0, initialize_header);
  4129     __ delayed()->nop();
  4132     // T0 must have been multiple of 2
  4133 #ifdef ASSERT
  4134     // make sure T0 was multiple of 2
  4135     Label L;
  4136     __ andi(AT, T0, 1);
  4137     __ beq(AT, R0, L);
  4138     __ delayed()->nop();
  4139     __ stop("object size is not multiple of 2 - adjust this code");
  4140     __ bind(L);
  4141     // edx must be > 0, no extra check needed here
  4142 #endif
  4144     // initialize remaining object fields: T0 is a multiple of 2
  4146       Label loop;
  4147       __ dadd(T1, FSR, T0);
  4148       __ daddi(T1, T1, -oopSize);
  4150       __ bind(loop);
  4151       __ sd(R0, T1, sizeof(oopDesc) + 0 * oopSize);
  4152 //      __ sd(R0, T1, sizeof(oopDesc) + 1 * oopSize);
  4153       __ bne(T1, FSR, loop); //dont clear header
  4154       __ delayed()->daddi(T1, T1, -oopSize);
  4155       // actually sizeof(oopDesc)==8, so we can move  
  4156       // __ addiu(AT, AT, -8) to delay slot, and compare FSR with T1
  4158     //klass in T3, 
  4159     // initialize object header only.
  4160     __ bind(initialize_header);
  4161     if (UseBiasedLocking) {
  4162       // __ popl(ecx);   // get saved klass back in the register.
  4163       // __ movl(ebx, Address(ecx, Klass::prototype_header_offset_in_bytes() 
  4164       // + klassOopDesc::klass_part_offset_in_bytes()));
  4165       __ ld(AT, T3, in_bytes(Klass::prototype_header_offset())); 
  4166       // __ movl(Address(eax, oopDesc::mark_offset_in_bytes ()), ebx);
  4167       __ sd(AT, FSR, oopDesc::mark_offset_in_bytes ());    
  4168     } else {
  4169       __ li(AT, (long)markOopDesc::prototype());
  4170       __ sd(AT, FSR, oopDesc::mark_offset_in_bytes());
  4173     //__ sd(T3, FSR, oopDesc::klass_offset_in_bytes());
  4174     __ store_klass_gap(FSR, R0);
  4175     __ store_klass(FSR, T3);
  4178       SkipIfEqual skip_if(_masm, &DTraceAllocProbes, 0);
  4179       // Trigger dtrace event for fastpath
  4180       __ push(atos);
  4181       __ call_VM_leaf(
  4182 	  CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_object_alloc), FSR);
  4183       __ pop(atos);
  4185     __ b(done);
  4186     __ delayed()->nop();
  4188   // slow case
  4189   __ bind(slow_case);
  4190   call_VM(FSR, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), A1, A2);
  4192   // continue
  4193   __ bind(done);
  4194   __ sync();
  4197 void TemplateTable::newarray() {
  4198 	transition(itos, atos);
  4199 	__ lbu(A1, at_bcp(1));
  4200 	//type, count
  4201 	call_VM(FSR, CAST_FROM_FN_PTR(address, InterpreterRuntime::newarray), A1, FSR);
  4202         __ sync();
  4205 void TemplateTable::anewarray() {
  4206   transition(itos, atos);
  4207   __ get_2_byte_integer_at_bcp(A2, AT, 1);
  4208   __ huswap(A2);
  4209   __ get_constant_pool(A1);
  4210   // cp, index, count
  4211   call_VM(FSR, CAST_FROM_FN_PTR(address, InterpreterRuntime::anewarray), A1, A2, FSR);
  4212   __ sync();
  4215 void TemplateTable::arraylength() {
  4216   transition(atos, itos);
  4217   __ null_check(FSR, arrayOopDesc::length_offset_in_bytes());
  4218   __ lw(FSR, FSR, arrayOopDesc::length_offset_in_bytes());
  4221 // i use T2 as ebx, T3 as ecx, T1 as edx
  4222 // when invoke gen_subtype_check, super in T3, sub in T2, object in FSR(it's always)
  4223 // T2 : sub klass
  4224 // T3 : cpool
  4225 // T3 : super klass
  4226 void TemplateTable::checkcast() {
  4227   transition(atos, atos);
  4228   Label done, is_null, ok_is_subtype, quicked, resolved;
  4229   __ beq(FSR, R0, is_null);
  4230   __ delayed()->nop();
  4232   // Get cpool & tags index
  4233   __ get_cpool_and_tags(T3, T1);
  4234   __ get_2_byte_integer_at_bcp(T2, AT, 1);
  4235   __ huswap(T2);
  4237   // See if bytecode has already been quicked
  4238   __ dadd(AT, T1, T2);
  4239   __ lb(AT, AT, Array<u1>::base_offset_in_bytes());
  4240   __ daddiu(AT, AT, - (int)JVM_CONSTANT_Class);
  4241   __ beq(AT, R0, quicked);
  4242   __ delayed()->nop();
  4244   /* 2012/6/2 Jin: In InterpreterRuntime::quicken_io_cc, lots of new classes may be loaded.
  4245    *  Then, GC will move the object in V0 to another places in heap.
  4246    *  Therefore, We should never save such an object in register.
  4247    *  Instead, we should save it in the stack. It can be modified automatically by the GC thread.
  4248    *  After GC, the object address in FSR is changed to a new place.
  4249    */
  4250   __ push(atos);
  4251   const Register thread = TREG;
  4252 #ifndef OPT_THREAD
  4253   __ get_thread(thread);
  4254 #endif
  4255   call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc));
  4256   __ get_vm_result_2(T3, thread);
  4257   __ pop_ptr(FSR);
  4258   __ b(resolved);
  4259   __ delayed()->nop();
  4261   // klass already in cp, get superklass in T3
  4262   __ bind(quicked);
  4263   __ dsll(AT, T2, Address::times_8);
  4264   __ dadd(AT, T3, AT);
  4265   __ ld(T3, AT, sizeof(ConstantPool));
  4267   __ bind(resolved);
  4269   // get subklass in T2
  4270   //__ ld(T2, FSR, oopDesc::klass_offset_in_bytes());
  4271   //add for compressedoops
  4272   __ load_klass(T2, FSR);
  4273   // Superklass in T3.  Subklass in T2.
  4274   __ gen_subtype_check(T3, T2, ok_is_subtype);
  4276   // Come here on failure
  4277   // object is at FSR
  4278   __ jmp(Interpreter::_throw_ClassCastException_entry);
  4279   __ delayed()->nop();
  4281   // Come here on success
  4282   __ bind(ok_is_subtype);
  4284   // Collect counts on whether this check-cast sees NULLs a lot or not.
  4285   if (ProfileInterpreter) {
  4286 	__ b(done);
  4287 	__ delayed()->nop();
  4288 	__ bind(is_null);
  4289 	__ profile_null_seen(T3);
  4290   } else {
  4291 	__ bind(is_null);
  4293   __ bind(done);
  4296 // i use T3 as cpool, T1 as tags, T2 as index
  4297 // object always in FSR, superklass in T3, subklass in T2
  4298 void TemplateTable::instanceof() {
  4299   transition(atos, itos);
  4300   Label done, is_null, ok_is_subtype, quicked, resolved;
  4302   __ beq(FSR, R0, is_null);
  4303   __ delayed()->nop();
  4305   // Get cpool & tags index
  4306   __ get_cpool_and_tags(T3, T1);
  4307   // get index
  4308   __ get_2_byte_integer_at_bcp(T2, AT, 1);
  4309   __ hswap(T2);
  4311   // See if bytecode has already been quicked
  4312   // quicked
  4313   __ daddu(AT, T1, T2);
  4314   __ lb(AT, AT, Array<u1>::base_offset_in_bytes());
  4315   __ daddiu(AT, AT, - (int)JVM_CONSTANT_Class);
  4316   __ beq(AT, R0, quicked);
  4317   __ delayed()->nop();
  4319   // get superklass in T3
  4320   //__ move(TSR, FSR);
  4321   // sometimes S2 may be changed during the call, 
  4322   // be careful if u use TSR as a saving place
  4323   //__ push(FSR);
  4324   __ push(atos);
  4325   const Register thread = TREG;
  4326 #ifndef OPT_THREAD
  4327   __ get_thread(thread);
  4328 #endif
  4329   call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc));
  4330   __ get_vm_result_2(T3, thread);
  4331   //__ lw(FSR, SP, 0);
  4332   __ pop_ptr(FSR);	
  4333   __ b(resolved);
  4334   __ delayed()->nop();
  4335   //__ move(FSR, TSR);
  4337   // get superklass in T3, subklass in T2
  4338   __ bind(quicked);
  4339   __ dsll(AT, T2, Address::times_8);
  4340   __ daddu(AT, T3, AT);
  4341   __ ld(T3, AT, sizeof(ConstantPool)); 
  4343   __ bind(resolved);
  4344   // get subklass in T2
  4345   //__ ld(T2, FSR, oopDesc::klass_offset_in_bytes());
  4346   //add for compressedoops
  4347   __ load_klass(T2, FSR);
  4349   // Superklass in T3.  Subklass in T2.
  4350   __ gen_subtype_check(T3, T2, ok_is_subtype);
  4351   // Come here on failure
  4352   __ b(done);
  4353   __ delayed(); __ move(FSR, R0);
  4355   // Come here on success
  4356   __ bind(ok_is_subtype);
  4357   __ move(FSR, 1);
  4359   // Collect counts on whether this test sees NULLs a lot or not.
  4360   if (ProfileInterpreter) {
  4361      __ beq(R0, R0, done);
  4362      __ nop();
  4363      __ bind(is_null);
  4364      __ profile_null_seen(T3);
  4365   } else {
  4366      __ bind(is_null);   // same as 'done'
  4368   __ bind(done);
  4369   // FSR = 0: obj == NULL or  obj is not an instanceof the specified klass
  4370   // FSR = 1: obj != NULL and obj is     an instanceof the specified klass
  4373 //--------------------------------------------------------
  4374 //--------------------------------------------
  4375 // Breakpoints
  4376 void TemplateTable::_breakpoint() {
  4378 	// Note: We get here even if we are single stepping..
  4379 	// jbug inists on setting breakpoints at every bytecode 
  4380 	// even if we are in single step mode.  
  4382 	transition(vtos, vtos);
  4384 	// get the unpatched byte code
  4385 	///__ get_method(ecx);
  4386 	///__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::get_original_bytecode_at)
  4387 	//, ecx, esi);
  4388 	///__ movl(ebx, eax);
  4389 	__ get_method(A1);
  4390 	__ call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::get_original_bytecode_at), 
  4391 			A1, BCP);
  4392 	__ move(Rnext, V0); // Jin: Rnext will be used in dispatch_only_normal
  4394 	// post the breakpoint event
  4395 	///__ get_method(ecx);
  4396 	///__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::_breakpoint), ecx, esi);
  4397 	__ get_method(A1);
  4398 	__ call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::_breakpoint), A1, BCP);
  4400 	// complete the execution of original bytecode
  4401 	__ dispatch_only_normal(vtos);
  4404 //----------------------------------------------------------------------------------------------------
  4405 // Exceptions
  4407 void TemplateTable::athrow() {
  4408 	transition(atos, vtos);
  4409 	__ null_check(FSR);
  4410 	__ jmp(Interpreter::throw_exception_entry());
  4411 	__ delayed()->nop();
  4414 //----------------------------------------------------------------------------------------------------
  4415 // Synchronization
  4416 //
  4417 // Note: monitorenter & exit are symmetric routines; which is reflected
  4418 //       in the assembly code structure as well
  4419 //
  4420 // Stack layout:
  4421 //
  4422 // [expressions  ] <--- SP               = expression stack top
  4423 // ..
  4424 // [expressions  ]
  4425 // [monitor entry] <--- monitor block top = expression stack bot
  4426 // ..
  4427 // [monitor entry]
  4428 // [frame data   ] <--- monitor block bot
  4429 // ...
  4430 // [return addr  ] <--- FP
  4432 // we use T2 as monitor entry pointer, T3 as monitor top pointer, c_rarg0 as free slot pointer
  4433 // object always in FSR
  4434 void TemplateTable::monitorenter() {
  4435   transition(atos, vtos);
  4436   // check for NULL object
  4437   __ null_check(FSR);
  4439   const Address monitor_block_top(FP, frame::interpreter_frame_monitor_block_top_offset 
  4440       * wordSize);
  4441   const int entry_size = (frame::interpreter_frame_monitor_size()* wordSize);
  4442   Label allocated;
  4444   // initialize entry pointer
  4445   __ move(c_rarg0, R0);
  4447   // find a free slot in the monitor block (result in edx)
  4449     Label entry, loop, exit, next;
  4450     __ ld(T2, monitor_block_top);
  4451     __ b(entry);
  4452     __ delayed()->daddi(T3, FP, frame::interpreter_frame_initial_sp_offset * wordSize);
  4454     // free slot?
  4455     __ bind(loop);
  4456     __ ld(AT, T2, BasicObjectLock::obj_offset_in_bytes());
  4457     __ bne(AT, R0, next);
  4458     __ delayed()->nop();
  4459     __ move(c_rarg0, T2);
  4461     __ bind(next);
  4462     __ beq(FSR, AT, exit);
  4463     __ delayed()->nop();
  4464     __ daddi(T2, T2, entry_size);
  4466     __ bind(entry);
  4467     __ bne(T3, T2, loop);
  4468     __ delayed()->nop();
  4469     __ bind(exit);
  4472   __ bne(c_rarg0, R0, allocated);
  4473   __ delayed()->nop();
  4475   // allocate one if there's no free slot
  4477     Label entry, loop;
  4478     // 1. compute new pointers                   // SP: old expression stack top
  4479     __ ld(c_rarg0, monitor_block_top);
  4480     __ daddi(SP, SP, - entry_size);
  4481     __ daddi(c_rarg0, c_rarg0, - entry_size);
  4482     __ sd(c_rarg0, monitor_block_top);
  4483     __ b(entry);
  4484     __ delayed(); __ move(T3, SP);
  4486     // 2. move expression stack contents
  4487     __ bind(loop);
  4488     __ ld(AT, T3, entry_size);
  4489     __ sd(AT, T3, 0);
  4490     __ daddi(T3, T3, wordSize); 
  4491     __ bind(entry);
  4492     __ bne(T3, c_rarg0, loop);
  4493     __ delayed()->nop();
  4496   __ bind(allocated);
  4497   // Increment bcp to point to the next bytecode, 
  4498   // so exception handling for async. exceptions work correctly. 
  4499   // The object has already been poped from the stack, so the 
  4500   // expression stack looks correct.
  4501   __ daddi(BCP, BCP, 1); 
  4502   __ sd(FSR, c_rarg0, BasicObjectLock::obj_offset_in_bytes());
  4503   __ lock_object(c_rarg0);
  4504   // check to make sure this monitor doesn't cause stack overflow after locking
  4505   __ save_bcp();  // in case of exception
  4506   __ generate_stack_overflow_check(0);
  4507   // The bcp has already been incremented. Just need to dispatch to next instruction.
  4509   __ dispatch_next(vtos);
  4512 // T2 : top
  4513 // c_rarg0 : entry
  4514 void TemplateTable::monitorexit() {
  4515   transition(atos, vtos);
  4517   __ null_check(FSR);
  4519   const int entry_size =(frame::interpreter_frame_monitor_size()* wordSize);
  4520   Label found;
  4522   // find matching slot
  4524     Label entry, loop;
  4525     __ ld(c_rarg0, FP, frame::interpreter_frame_monitor_block_top_offset * wordSize);
  4526     __ b(entry);
  4527     __ delayed()->daddiu(T2, FP, frame::interpreter_frame_initial_sp_offset * wordSize);
  4529     __ bind(loop);
  4530     __ ld(AT, c_rarg0, BasicObjectLock::obj_offset_in_bytes());
  4531     __ beq(FSR, AT, found);
  4532     __ delayed()->nop();
  4533     __ daddiu(c_rarg0, c_rarg0, entry_size);
  4534     __ bind(entry);
  4535     __ bne(T2, c_rarg0, loop);
  4536     __ delayed()->nop();
  4539   // error handling. Unlocking was not block-structured
  4540   Label end;
  4541   __ call_VM(NOREG, CAST_FROM_FN_PTR(address, 
  4542 	InterpreterRuntime::throw_illegal_monitor_state_exception));
  4543   __ should_not_reach_here();
  4545   // call run-time routine
  4546   // c_rarg0: points to monitor entry
  4547   __ bind(found);
  4548   __ move(TSR, FSR);
  4549   __ unlock_object(c_rarg0);
  4550   __ move(FSR, TSR);
  4551   __ bind(end);
  4554 //--------------------------------------------------------------------------------------------------// Wide instructions
  4556 void TemplateTable::wide() {
  4557   transition(vtos, vtos);
  4558   // Note: the esi increment step is part of the individual wide bytecode implementations
  4559   __ lbu(Rnext, at_bcp(1));
  4560   __ dsll(T9, Rnext, Address::times_8);
  4561   __ li(AT, (long)Interpreter::_wentry_point);
  4562   __ dadd(AT, T9, AT);
  4563   __ ld(T9, AT, 0);
  4564   __ jr(T9);
  4565   __ delayed()->nop();
  4568 //--------------------------------------------------------------------------------------------------// Multi arrays
  4570 void TemplateTable::multianewarray() {
  4571   transition(vtos, atos);
  4572   // last dim is on top of stack; we want address of first one:
  4573   // first_addr = last_addr + (ndims - 1) * wordSize
  4574   __ lbu(A1, at_bcp(3));	// dimension
  4575   __ daddi(A1, A1, -1);	
  4576   __ dsll(A1, A1, Address::times_8);
  4577   __ dadd(A1, SP, A1);		// now A1 pointer to the count array on the stack
  4578   call_VM(FSR, CAST_FROM_FN_PTR(address, InterpreterRuntime::multianewarray), A1);
  4579   __ lbu(AT, at_bcp(3));
  4580   __ dsll(AT, AT, Address::times_8);
  4581   __ dadd(SP, SP, AT);
  4582   __ sync();
  4585 #endif // !CC_INTERP

mercurial