src/cpu/mips/vm/templateTable_mips_64.cpp

Wed, 20 Sep 2017 09:24:48 +0800

author
fujie
date
Wed, 20 Sep 2017 09:24:48 +0800
changeset 6886
2fa8027581f6
parent 6885
75ee8543b584
child 6887
59aca571c8d0
permissions
-rw-r--r--

[Interpreter] Remove redundant andi for shift operations.

     1 /*
     2  * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * Copyright (c) 2015, 2016, Loongson Technology. All rights reserved.
     4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5  *
     6  * This code is free software; you can redistribute it and/or modify it
     7  * under the terms of the GNU General Public License version 2 only, as
     8  * published by the Free Software Foundation.
     9  *
    10  * This code is distributed in the hope that it will be useful, but WITHOUT
    11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    13  * version 2 for more details (a copy is included in the LICENSE file that
    14  * accompanied this code).
    15  *
    16  * You should have received a copy of the GNU General Public License version
    17  * 2 along with this work; if not, write to the Free Software Foundation,
    18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    19  *
    20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    21  * or visit www.oracle.com if you need additional information or have any
    22  * questions.
    23  *
    24  */
    26 #include "precompiled.hpp"
    27 #include "asm/macroAssembler.hpp"
    28 #include "interpreter/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
    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); }
    75 static inline Address at_sp()             {  return Address(SP,   0); }
    76 static inline Address at_sp_p1()          { return Address(SP,  1 * wordSize); }
    77 static inline Address at_sp_p2()          { return Address(SP,  2 * wordSize); }
    79 // At top of Java expression stack which may be different than esp().  It
    80 // isn't for category 1 objects.
    81 static inline Address at_tos   () {
    82   Address tos = Address(SP,  Interpreter::expr_offset_in_bytes(0));
    83   return tos;
    84 }
    86 static inline Address at_tos_p1() {
    87   return Address(SP,  Interpreter::expr_offset_in_bytes(1));
    88 }
    90 static inline Address at_tos_p2() {
    91   return Address(SP,  Interpreter::expr_offset_in_bytes(2));
    92 }
    94 static inline Address at_tos_p3() {
    95   return Address(SP,  Interpreter::expr_offset_in_bytes(3));
    96 }
    98 // we use S0 as bcp, be sure you have bcp in S0 before you call any of the Template generator
    99 Address TemplateTable::at_bcp(int offset) {
   100   assert(_desc->uses_bcp(), "inconsistent uses_bcp information");
   101   return Address(BCP, offset);
   102 }
   104 // bytecode folding
   105 void TemplateTable::patch_bytecode(Bytecodes::Code bc, Register bc_reg,
   106                                    Register tmp_reg, bool load_bc_into_bc_reg/*=true*/,
   107                                    int byte_no) {
   108   if (!RewriteBytecodes)  return;
   109   Label L_patch_done;
   111   switch (bc) {
   112   case Bytecodes::_fast_aputfield:
   113   case Bytecodes::_fast_bputfield:
   114   case Bytecodes::_fast_cputfield:
   115   case Bytecodes::_fast_dputfield:
   116   case Bytecodes::_fast_fputfield:
   117   case Bytecodes::_fast_iputfield:
   118   case Bytecodes::_fast_lputfield:
   119   case Bytecodes::_fast_sputfield:
   120     {
   121       // We skip bytecode quickening for putfield instructions when
   122       // the put_code written to the constant pool cache is zero.
   123       // This is required so that every execution of this instruction
   124       // calls out to InterpreterRuntime::resolve_get_put to do
   125       // additional, required work.
   126       assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
   127       assert(load_bc_into_bc_reg, "we use bc_reg as temp");
   128       __ get_cache_and_index_and_bytecode_at_bcp(tmp_reg, bc_reg, tmp_reg, byte_no, 1);
   129       __ daddi(bc_reg, R0, bc);
   130       __ beq(tmp_reg, R0, L_patch_done);
   131       __ delayed()->nop();
   132     }
   133     break;
   134   default:
   135     assert(byte_no == -1, "sanity");
   136     // the pair bytecodes have already done the load.
   137     if (load_bc_into_bc_reg) {
   138       __ move(bc_reg, bc);
   139     }
   140   }
   142   if (JvmtiExport::can_post_breakpoint()) {
   143     Label L_fast_patch;
   144     // if a breakpoint is present we can't rewrite the stream directly
   145     __ lbu(tmp_reg, at_bcp(0));
   146     __ move(AT, Bytecodes::_breakpoint);
   147     __ bne(tmp_reg, AT, L_fast_patch);
   148     __ delayed()->nop();
   150     __ get_method(tmp_reg);
   151     // Let breakpoint table handling rewrite to quicker bytecode
   152     __ call_VM(NOREG, CAST_FROM_FN_PTR(address,
   153     InterpreterRuntime::set_original_bytecode_at), tmp_reg, BCP, bc_reg);
   155     __ b(L_patch_done);
   156     __ delayed()->nop();
   157     __ bind(L_fast_patch);
   158   }
   160 #ifdef ASSERT
   161   Label L_okay;
   162   __ lbu(tmp_reg, at_bcp(0));
   163   __ move(AT, (int)Bytecodes::java_code(bc));
   164   __ beq(tmp_reg, AT, L_okay);
   165   __ delayed()->nop();
   166   __ beq(tmp_reg, bc_reg, L_patch_done);
   167   __ delayed()->nop();
   168   __ stop("patching the wrong bytecode");
   169   __ bind(L_okay);
   170 #endif
   172   // patch bytecode
   173   __ sb(bc_reg, at_bcp(0));
   174   __ bind(L_patch_done);
   175 }
   178 // Individual instructions
   180 void TemplateTable::nop() {
   181   transition(vtos, vtos);
   182   // nothing to do
   183 }
   185 void TemplateTable::shouldnotreachhere() {
   186   transition(vtos, vtos);
   187   __ stop("shouldnotreachhere bytecode");
   188 }
   190 void TemplateTable::aconst_null() {
   191   transition(vtos, atos);
   192   __ move(FSR, R0);
   193 }
   195 void TemplateTable::iconst(int value) {
   196   transition(vtos, itos);
   197   if (value == 0) {
   198     __ move(FSR, R0);
   199   } else {
   200     __ move(FSR, value);
   201   }
   202 }
   204 void TemplateTable::lconst(int value) {
   205   transition(vtos, ltos);
   206   if (value == 0) {
   207     __ move(FSR, R0);
   208   } else {
   209     __ move(FSR, value);
   210   }
   211 }
   213 void TemplateTable::fconst(int value) {
   214   static float  _f1 = 1.0, _f2 = 2.0;
   215   transition(vtos, ftos);
   216   float* p;
   217   switch( value ) {
   218     default: ShouldNotReachHere();
   219     case 0:  __ dmtc1(R0, FSF);  return;
   220     case 1:  p = &_f1;   break;
   221     case 2:  p = &_f2;   break;
   222   }
   223   __ li(AT, (address)p);
   224   __ lwc1(FSF, AT, 0);
   225 }
   227 void TemplateTable::dconst(int value) {
   228   static double _d1 = 1.0;
   229   transition(vtos, dtos);
   230   double* p;
   231   switch( value ) {
   232     default: ShouldNotReachHere();
   233     case 0:  __ dmtc1(R0, FSF);  return;
   234     case 1:  p = &_d1;   break;
   235   }
   236   __ li(AT, (address)p);
   237   __ ldc1(FSF, AT, 0);
   238 }
   240 void TemplateTable::bipush() {
   241   transition(vtos, itos);
   242   __ lb(FSR, at_bcp(1));
   243 }
   245 void TemplateTable::sipush() {
   246   transition(vtos, itos);
   247   __ get_2_byte_integer_at_bcp(FSR, AT, 1);
   248   __ hswap(FSR);
   249 }
   251 // T1 : tags
   252 // T2 : index
   253 // T3 : cpool
   254 // T8 : tag
   255 void TemplateTable::ldc(bool wide) {
   256   transition(vtos, vtos);
   257   Label call_ldc, notFloat, notClass, Done;
   258   // get index in cpool
   259   if (wide) {
   260     __ get_unsigned_2_byte_index_at_bcp(T2, 1);
   261   } else {
   262     __ lbu(T2, at_bcp(1));
   263   }
   265   __ get_cpool_and_tags(T3, T1);
   267   const int base_offset = ConstantPool::header_size() * wordSize;
   268   const int tags_offset = Array<u1>::base_offset_in_bytes();
   270   // get type
   271   if (UseLoongsonISA && Assembler::is_simm(sizeof(tags_offset), 8)) {
   272     __ gslbx(T1, T1, T2, tags_offset);
   273   } else {
   274     __ dadd(AT, T1, T2);
   275     __ lb(T1, AT, tags_offset);
   276   }
   277   //now T1 is the tag
   279   // unresolved class - get the resolved class
   280   __ daddiu(AT, T1, - JVM_CONSTANT_UnresolvedClass);
   281   __ beq(AT, R0, call_ldc);
   282   __ delayed()->nop();
   284   // unresolved class in error (resolution failed) - call into runtime
   285   // so that the same error from first resolution attempt is thrown.
   286   __ daddiu(AT, T1, -JVM_CONSTANT_UnresolvedClassInError);
   287   __ beq(AT, R0, call_ldc);
   288   __ delayed()->nop();
   290   // resolved class - need to call vm to get java mirror of the class
   291   __ daddiu(AT, T1, - JVM_CONSTANT_Class);
   292   __ bne(AT, R0, notClass);
   293   __ delayed()->dsll(T2, T2, Address::times_8);
   295   __ bind(call_ldc);
   296   __ move(A1, wide);
   297   call_VM(FSR, CAST_FROM_FN_PTR(address, InterpreterRuntime::ldc), A1);
   298   //__ push(atos);
   299   __ sd(FSR, SP, - Interpreter::stackElementSize);
   300   __ b(Done);
   301   __ delayed()->daddiu(SP, SP, - Interpreter::stackElementSize);
   302   __ nop(); // added for performance issue
   304   __ bind(notClass);
   305   __ daddiu(AT, T1, -JVM_CONSTANT_Float);
   306   __ bne(AT, R0, notFloat);
   307   __ delayed()->nop();
   308   // ftos
   309   if (UseLoongsonISA && Assembler::is_simm(sizeof(base_offset), 8)) {
   310     __ gslwxc1(FSF, T3, T2, base_offset);
   311   } else {
   312     __ dadd(AT, T3, T2);
   313     __ lwc1(FSF, AT, base_offset);
   314   }
   315   //__ push_f();
   316   __ swc1(FSF, SP, - Interpreter::stackElementSize);
   317   __ b(Done);
   318   __ delayed()->daddiu(SP, SP, - Interpreter::stackElementSize);
   320   __ bind(notFloat);
   321 #ifdef ASSERT
   322   {
   323     Label L;
   324     __ daddiu(AT, T1, -JVM_CONSTANT_Integer);
   325     __ beq(AT, R0, L);
   326     __ delayed()->nop();
   327     __ stop("unexpected tag type in ldc");
   328     __ bind(L);
   329   }
   330 #endif
   331   // itos JVM_CONSTANT_Integer only
   332   if (UseLoongsonISA && Assembler::is_simm(sizeof(base_offset), 8)) {
   333     __ gslwx(FSR, T3, T2, base_offset);
   334   } else {
   335     __ dadd(T0, T3, T2);
   336     __ lw(FSR, T0, base_offset);
   337   }
   338   __ push(itos);
   339   __ bind(Done);
   340 }
   342 // Fast path for caching oop constants.
   343 void TemplateTable::fast_aldc(bool wide) {
   344   transition(vtos, atos);
   346   Register result = FSR;
   347   Register tmp = SSR;
   348   int index_size = wide ? sizeof(u2) : sizeof(u1);
   350   Label resolved;
   352   // We are resolved if the resolved reference cache entry contains a
   353   // non-null object (String, MethodType, etc.)
   354   assert_different_registers(result, tmp);
   355   __ get_cache_index_at_bcp(tmp, 1, index_size);
   356   __ load_resolved_reference_at_index(result, tmp);
   357   __ bne(result, R0, resolved);
   358   __ delayed()->nop();
   360   address entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_ldc);
   361   // first time invocation - must resolve first
   362   int i = (int)bytecode();
   363   __ move(tmp, i);
   364   __ call_VM(result, entry, tmp);
   366   __ bind(resolved);
   368   if (VerifyOops) {
   369     __ verify_oop(result);
   370   }
   371 }
   374 // used register: T2, T3, T1
   375 // T2 : index
   376 // T3 : cpool
   377 // T1 : tag
   378 void TemplateTable::ldc2_w() {
   379   transition(vtos, vtos);
   380   Label Long, Done;
   382   // get index in cpool
   383   __ get_2_byte_integer_at_bcp(T2, AT, 1);
   384   __ huswap(T2);
   386   __ get_cpool_and_tags(T3, T1);
   388   const int base_offset = ConstantPool::header_size() * wordSize;
   389   const int tags_offset = Array<u1>::base_offset_in_bytes();
   391   // get type in T1
   392   __ dadd(AT, T1, T2);
   393   __ lb(T1, AT, tags_offset);
   395   __ daddiu(AT, T1, - JVM_CONSTANT_Double);
   396   __ bne(AT, R0, Long);
   397   __ delayed()->dsll(T2, T2, Address::times_8);
   398   // dtos
   399   __ daddu(AT, T3, T2);
   400   __ ldc1(FSF, AT, base_offset + 0 * wordSize);
   401   __ sdc1(FSF, SP, - 2 * wordSize);
   402   __ b(Done);
   403   __ delayed()->daddi(SP, SP, - 2 * wordSize);
   405   // ltos
   406   __ bind(Long);
   407   __ dadd(AT, T3, T2);
   408   __ ld(FSR, AT, base_offset + 0 * wordSize);
   409   __ push(ltos);
   411   __ bind(Done);
   412 }
   414 // we compute the actual local variable address here
   415 // the x86 dont do so for it has scaled index memory access model, we dont have, so do here
   416 void TemplateTable::locals_index(Register reg, int offset) {
   417   __ lbu(reg, at_bcp(offset));
   418   __ dsll(reg, reg, Address::times_8);
   419   __ dsub(reg, LVP, reg);
   420 }
   422 // this method will do bytecode folding of the two form:
   423 // iload iload      iload caload
   424 // used register : T2, T3
   425 // T2 : bytecode
   426 // T3 : folded code
   427 void TemplateTable::iload() {
   428   transition(vtos, itos);
   429   if (RewriteFrequentPairs) {
   430     Label rewrite, done;
   431     // get the next bytecode in T2
   432     __ lbu(T2, at_bcp(Bytecodes::length_for(Bytecodes::_iload)));
   433     // if _iload, wait to rewrite to iload2.  We only want to rewrite the
   434     // last two iloads in a pair.  Comparing against fast_iload means that
   435     // the next bytecode is neither an iload or a caload, and therefore
   436     // an iload pair.
   437     __ move(AT, Bytecodes::_iload);
   438     __ beq(AT, T2, done);
   439     __ delayed()->nop();
   441     __ move(T3, Bytecodes::_fast_iload2);
   442     __ move(AT, Bytecodes::_fast_iload);
   443     __ beq(AT, T2, rewrite);
   444     __ delayed()->nop();
   446     // if _caload, rewrite to fast_icaload
   447     __ move(T3, Bytecodes::_fast_icaload);
   448     __ move(AT, Bytecodes::_caload);
   449     __ beq(AT, T2, rewrite);
   450     __ delayed()->nop();
   452     // rewrite so iload doesn't check again.
   453     __ move(T3, Bytecodes::_fast_iload);
   455     // rewrite
   456     // T3 : fast bytecode
   457     __ bind(rewrite);
   458     patch_bytecode(Bytecodes::_iload, T3, T2, false);
   459     __ bind(done);
   460   }
   462   // Get the local value into tos
   463   locals_index(T2);
   464   __ lw(FSR, T2, 0);
   465 }
   467 // used register T2
   468 // T2 : index
   469 void TemplateTable::fast_iload2() {
   470   transition(vtos, itos);
   471   locals_index(T2);
   472   __ lw(FSR, T2, 0);
   473   __ push(itos);
   474   locals_index(T2, 3);
   475   __ lw(FSR, T2, 0);
   476 }
   478 // used register T2
   479 // T2 : index
   480 void TemplateTable::fast_iload() {
   481   transition(vtos, itos);
   482   locals_index(T2);
   483   __ lw(FSR, T2, 0);
   484 }
   486 // used register T2
   487 // T2 : index
   488 void TemplateTable::lload() {
   489   transition(vtos, ltos);
   490   locals_index(T2);
   491   __ ld(FSR, T2, -wordSize);
   492   __ ld(SSR, T2, 0);
   493 }
   495 // used register T2
   496 // T2 : index
   497 void TemplateTable::fload() {
   498   transition(vtos, ftos);
   499   locals_index(T2);
   500   __ lwc1(FSF, T2, 0);
   501 }
   503 // used register T2
   504 // T2 : index
   505 void TemplateTable::dload() {
   506   transition(vtos, dtos);
   507   locals_index(T2);
   508   __ ldc1(FSF, T2, -wordSize);
   509   __ ldc1(SSF, T2, 0);
   510 }
   512 // used register T2
   513 // T2 : index
   514 void TemplateTable::aload() {
   515   transition(vtos, atos);
   516   locals_index(T2);
   517   __ ld(FSR, T2, 0);
   518 }
   520 void TemplateTable::locals_index_wide(Register reg) {
   521   __ get_2_byte_integer_at_bcp(reg, AT, 2);
   522   __ huswap(reg);
   523   __ dsll(reg, reg, Address::times_8);
   524   __ dsub(reg, LVP, reg);
   525 }
   527 // used register T2
   528 // T2 : index
   529 void TemplateTable::wide_iload() {
   530   transition(vtos, itos);
   531   locals_index_wide(T2);
   532   __ ld(FSR, T2, 0);
   533 }
   535 // used register T2
   536 // T2 : index
   537 void TemplateTable::wide_lload() {
   538   transition(vtos, ltos);
   539   locals_index_wide(T2);
   540   __ ld(FSR, T2, -wordSize);
   541 }
   543 // used register T2
   544 // T2 : index
   545 void TemplateTable::wide_fload() {
   546   transition(vtos, ftos);
   547   locals_index_wide(T2);
   548   __ lwc1(FSF, T2, 0);
   549 }
   551 // used register T2
   552 // T2 : index
   553 void TemplateTable::wide_dload() {
   554   transition(vtos, dtos);
   555   locals_index_wide(T2);
   556   __ ldc1(FSF, T2, -wordSize);
   557 }
   559 // used register T2
   560 // T2 : index
   561 void TemplateTable::wide_aload() {
   562   transition(vtos, atos);
   563   locals_index_wide(T2);
   564   __ ld(FSR, T2, 0);
   565 }
   567 // we use A2 as the regiser for index, BE CAREFUL!
   568 // we dont use our tge 29 now, for later optimization
   569 void TemplateTable::index_check(Register array, Register index) {
   570   // Pop ptr into array
   571   __ pop_ptr(array);
   572   index_check_without_pop(array, index);
   573 }
   575 void TemplateTable::index_check_without_pop(Register array, Register index) {
   576   // destroys ebx
   577   // check array
   578   __ null_check(array, arrayOopDesc::length_offset_in_bytes());
   580 #ifdef _LP64
   581   // sign extend since tos (index) might contain garbage in upper bits
   582   __ sll(index, index, 0);
   583 #endif // _LP64
   585   // check index
   586   Label ok;
   587   __ lw(AT, array, arrayOopDesc::length_offset_in_bytes());
   588 #ifndef OPT_RANGECHECK
   589   __ sltu(AT, index, AT);
   590   __ bne(AT, R0, ok);
   591   __ delayed()->nop();
   593   //throw_ArrayIndexOutOfBoundsException assume abberrant index in A2
   594   if (A2 != index) __ move(A2, index);
   595   __ jmp(Interpreter::_throw_ArrayIndexOutOfBoundsException_entry);
   596   __ delayed()->nop();
   597   __ bind(ok);
   598 #else
   599   __ lw(AT, array, arrayOopDesc::length_offset_in_bytes());
   600   __ move(A2, index);
   601   __ tgeu(A2, AT, 29);
   602 #endif
   603 }
   605 void TemplateTable::iaload() {
   606   transition(itos, itos);
   607   if(UseBoundCheckInstruction) {
   608     __ pop(SSR); //SSR:array    FSR: index
   609     __ dsll(FSR, FSR, 2);
   610     __ dadd(FSR, SSR, FSR);
   611     __ addi(FSR, FSR, arrayOopDesc::base_offset_in_bytes(T_INT));
   613     __ lw(AT, SSR, arrayOopDesc::length_offset_in_bytes());  //bound
   614     __ dsll(AT, AT, 2);
   615     __ dadd(AT, SSR, AT);
   616     __ addi(AT, AT, arrayOopDesc::base_offset_in_bytes(T_INT));
   618     __ gslwle(FSR, FSR, AT);
   619   } else {
   620     index_check(SSR, FSR);
   621     __ dsll(FSR, FSR, 2);
   622     __ dadd(FSR, SSR, FSR);
   623     //FSR: index
   624     __ lw(FSR, FSR, arrayOopDesc::base_offset_in_bytes(T_INT));
   625   }
   626 }
   628 void TemplateTable::laload() {
   629   transition(itos, ltos);
   630   if(UseBoundCheckInstruction) {
   631     __ pop(SSR); //SSR:array    FSR: index
   632     __ dsll(FSR, FSR, Address::times_8);
   633     __ dadd(FSR, SSR, FSR);
   634     __ addi(FSR, FSR, arrayOopDesc::base_offset_in_bytes(T_LONG) + 0 * wordSize);
   636     __ lw(AT, SSR, arrayOopDesc::length_offset_in_bytes());  //bound
   637     __ dsll(AT, AT, Address::times_8);
   638     __ dadd(AT, SSR, AT);
   639     __ addi(AT, AT, arrayOopDesc::base_offset_in_bytes(T_LONG) + 0 * wordSize);
   641     __ gsldle(FSR, FSR, AT);
   642   } else {
   643     index_check(SSR, FSR);
   644     __ dsll(AT, FSR, Address::times_8);
   645     __ dadd(AT, SSR, AT);
   646     __ ld(FSR, AT, arrayOopDesc::base_offset_in_bytes(T_LONG) + 0 * wordSize);
   647   }
   648 }
   650 void TemplateTable::faload() {
   651   transition(itos, ftos);
   652   if(UseBoundCheckInstruction) {
   653     __ pop(SSR); //SSR:array    FSR: index
   654     __ shl(FSR, 2);
   655     __ dadd(FSR, SSR, FSR);
   656     __ addi(FSR, FSR, arrayOopDesc::base_offset_in_bytes(T_FLOAT));
   658     __ lw(AT, SSR, arrayOopDesc::length_offset_in_bytes());  //bound
   659     __ shl(AT, 2);
   660     __ dadd(AT, SSR, AT);
   661     __ addi(AT, AT, arrayOopDesc::base_offset_in_bytes(T_FLOAT));
   663     __ gslwlec1(FSF, FSR, AT);
   664   } else {
   665     index_check(SSR, FSR);
   666     __ shl(FSR, 2);
   667     __ dadd(FSR, SSR, FSR);
   668     __ lwc1(FSF, FSR, arrayOopDesc::base_offset_in_bytes(T_FLOAT));
   669   }
   670 }
   672 void TemplateTable::daload() {
   673   transition(itos, dtos);
   674   if(UseBoundCheckInstruction) {
   675     __ pop(SSR); //SSR:array    FSR: index
   676     __ dsll(FSR, FSR, 3);
   677     __ dadd(FSR, SSR, FSR);
   678     __ addi(FSR, FSR, arrayOopDesc::base_offset_in_bytes(T_DOUBLE) + 0 * wordSize);
   680     __ lw(AT, SSR, arrayOopDesc::length_offset_in_bytes());  //bound
   681     __ dsll(AT, AT, 3);
   682     __ dadd(AT, SSR, AT);
   683     __ addi(AT, AT, arrayOopDesc::base_offset_in_bytes(T_DOUBLE) + 0 * wordSize);
   685     __ gsldlec1(FSF, FSR, AT);
   686   } else {
   687     index_check(SSR, FSR);
   688     __ dsll(AT, FSR, 3);
   689     __ dadd(AT, SSR, AT);
   690     __ ldc1(FSF, AT, arrayOopDesc::base_offset_in_bytes(T_DOUBLE) + 0 * wordSize);
   691   }
   692 }
   694 void TemplateTable::aaload() {
   695   transition(itos, atos);
   696   index_check(SSR, FSR);
   697   __ dsll(FSR, FSR, UseCompressedOops ? Address::times_4 : Address::times_8);
   698   __ dadd(FSR, SSR, FSR);
   699   //add for compressedoops
   700   __ load_heap_oop(FSR, Address(FSR, arrayOopDesc::base_offset_in_bytes(T_OBJECT)));
   701 }
   703 void TemplateTable::baload() {
   704   transition(itos, itos);
   705   if(UseBoundCheckInstruction) {
   706     __ pop(SSR); //SSR:array   FSR:index
   707     __ dadd(FSR, SSR, FSR);
   708     __ addi(FSR, FSR, arrayOopDesc::base_offset_in_bytes(T_BYTE)); //base
   710     __ lw(AT, SSR, arrayOopDesc::length_offset_in_bytes());
   711     __ dadd(AT, SSR, AT);
   712     __ addi(AT, AT, arrayOopDesc::base_offset_in_bytes(T_BYTE)); //bound
   714     __ gslble(FSR, FSR, AT);
   715   } else {
   716     index_check(SSR, FSR);
   717     __ dadd(FSR, SSR, FSR);
   718     __ lb(FSR, FSR, arrayOopDesc::base_offset_in_bytes(T_BYTE));
   719   }
   720 }
   722 void TemplateTable::caload() {
   723   transition(itos, itos);
   724   index_check(SSR, FSR);
   725   __ dsll(FSR, FSR, Address::times_2);
   726   __ dadd(FSR, SSR, FSR);
   727   __ lhu(FSR, FSR,  arrayOopDesc::base_offset_in_bytes(T_CHAR));
   728 }
   730 // iload followed by caload frequent pair
   731 // used register : T2
   732 // T2 : index
   733 void TemplateTable::fast_icaload() {
   734   transition(vtos, itos);
   735   // load index out of locals
   736   locals_index(T2);
   737   __ lw(FSR, T2, 0);
   738   index_check(SSR, FSR);
   739   __ dsll(FSR, FSR, 1);
   740   __ dadd(FSR, SSR, FSR);
   741   __ lhu(FSR, FSR,  arrayOopDesc::base_offset_in_bytes(T_CHAR));
   742 }
   744 void TemplateTable::saload() {
   745   transition(itos, itos);
   746   if(UseBoundCheckInstruction) {
   747     __ pop(SSR); //SSR:array    FSR: index
   748     __ dsll(FSR, FSR, Address::times_2);
   749     __ dadd(FSR, SSR, FSR);
   750     __ addi(FSR, FSR, arrayOopDesc::base_offset_in_bytes(T_SHORT));
   752     __ lw(AT, SSR, arrayOopDesc::length_offset_in_bytes());  //bound
   753     __ dsll(AT, AT, Address::times_2);
   754     __ dadd(AT, SSR, AT);
   755     __ addi(AT, AT, arrayOopDesc::base_offset_in_bytes(T_SHORT));
   757     __ gslhle(FSR, FSR, AT);
   758   } else {
   759     index_check(SSR, FSR);
   760     __ dsll(FSR, FSR, Address::times_2);
   761     __ dadd(FSR, SSR, FSR);
   762     __ lh(FSR, FSR,  arrayOopDesc::base_offset_in_bytes(T_SHORT));
   763   }
   764 }
   766 void TemplateTable::iload(int n) {
   767   transition(vtos, itos);
   768   __ lw(FSR, iaddress(n));
   769 }
   771 void TemplateTable::lload(int n) {
   772   transition(vtos, ltos);
   773   __ ld(FSR, laddress(n));
   774 }
   776 void TemplateTable::fload(int n) {
   777   transition(vtos, ftos);
   778   __ lwc1(FSF, faddress(n));
   779 }
   781 void TemplateTable::dload(int n) {
   782   transition(vtos, dtos);
   783   __ ldc1(FSF, laddress(n));
   784 }
   786 void TemplateTable::aload(int n) {
   787   transition(vtos, atos);
   788   __ ld(FSR, aaddress(n));
   789 }
   791 // used register : T2, T3
   792 // T2 : bytecode
   793 // T3 : folded code
   794 void TemplateTable::aload_0() {
   795   transition(vtos, atos);
   796   // According to bytecode histograms, the pairs:
   797   //
   798   // _aload_0, _fast_igetfield
   799   // _aload_0, _fast_agetfield
   800   // _aload_0, _fast_fgetfield
   801   //
   802   // occur frequently. If RewriteFrequentPairs is set, the (slow)
   803   // _aload_0 bytecode checks if the next bytecode is either
   804   // _fast_igetfield, _fast_agetfield or _fast_fgetfield and then
   805   // rewrites the current bytecode into a pair bytecode; otherwise it
   806   // rewrites the current bytecode into _fast_aload_0 that doesn't do
   807   // the pair check anymore.
   808   //
   809   // Note: If the next bytecode is _getfield, the rewrite must be
   810   //       delayed, otherwise we may miss an opportunity for a pair.
   811   //
   812   // Also rewrite frequent pairs
   813   //   aload_0, aload_1
   814   //   aload_0, iload_1
   815   // These bytecodes with a small amount of code are most profitable
   816   // to rewrite
   817   if (RewriteFrequentPairs) {
   818     Label rewrite, done;
   819     // get the next bytecode in T2
   820     __ lbu(T2, at_bcp(Bytecodes::length_for(Bytecodes::_aload_0)));
   822     // do actual aload_0
   823     aload(0);
   825     // if _getfield then wait with rewrite
   826     __ move(AT, Bytecodes::_getfield);
   827     __ beq(AT, T2, done);
   828     __ delayed()->nop();
   830     // if _igetfield then reqrite to _fast_iaccess_0
   831     assert(Bytecodes::java_code(Bytecodes::_fast_iaccess_0) ==
   832         Bytecodes::_aload_0,
   833         "fix bytecode definition");
   834     __ move(T3, Bytecodes::_fast_iaccess_0);
   835     __ move(AT, Bytecodes::_fast_igetfield);
   836     __ beq(AT, T2, rewrite);
   837     __ delayed()->nop();
   839     // if _agetfield then reqrite to _fast_aaccess_0
   840     assert(Bytecodes::java_code(Bytecodes::_fast_aaccess_0) ==
   841         Bytecodes::_aload_0,
   842         "fix bytecode definition");
   843     __ move(T3, Bytecodes::_fast_aaccess_0);
   844     __ move(AT, Bytecodes::_fast_agetfield);
   845     __ beq(AT, T2, rewrite);
   846     __ delayed()->nop();
   848     // if _fgetfield then reqrite to _fast_faccess_0
   849     assert(Bytecodes::java_code(Bytecodes::_fast_faccess_0) ==
   850         Bytecodes::_aload_0,
   851         "fix bytecode definition");
   852     __ move(T3, Bytecodes::_fast_faccess_0);
   853     __ move(AT, Bytecodes::_fast_fgetfield);
   854     __ beq(AT, T2, rewrite);
   855     __ delayed()->nop();
   857     // else rewrite to _fast_aload0
   858     assert(Bytecodes::java_code(Bytecodes::_fast_aload_0) ==
   859         Bytecodes::_aload_0,
   860         "fix bytecode definition");
   861     __ move(T3, Bytecodes::_fast_aload_0);
   863     // rewrite
   864     __ bind(rewrite);
   865     patch_bytecode(Bytecodes::_aload_0, T3, T2, false);
   867     __ bind(done);
   868   } else {
   869     aload(0);
   870   }
   871 }
   873 void TemplateTable::istore() {
   874   transition(itos, vtos);
   875   locals_index(T2);
   876   __ sw(FSR, T2, 0);
   877 }
   879 void TemplateTable::lstore() {
   880   transition(ltos, vtos);
   881   locals_index(T2);
   882   __ sd(FSR, T2, -wordSize);
   883 }
   885 void TemplateTable::fstore() {
   886   transition(ftos, vtos);
   887   locals_index(T2);
   888   __ swc1(FSF, T2, 0);
   889 }
   891 void TemplateTable::dstore() {
   892   transition(dtos, vtos);
   893   locals_index(T2);
   894   __ sdc1(FSF, T2, -wordSize);
   895 }
   897 void TemplateTable::astore() {
   898   transition(vtos, vtos);
   899   __ pop_ptr(FSR);
   900   locals_index(T2);
   901   __ sd(FSR, T2, 0);
   902 }
   904 void TemplateTable::wide_istore() {
   905   transition(vtos, vtos);
   906   __ pop_i(FSR);
   907   locals_index_wide(T2);
   908   __ sd(FSR, T2, 0);
   909 }
   911 void TemplateTable::wide_lstore() {
   912   transition(vtos, vtos);
   913   __ pop_l(FSR);
   914   locals_index_wide(T2);
   915   __ sd(FSR, T2, -wordSize);
   916 }
   918 void TemplateTable::wide_fstore() {
   919   wide_istore();
   920 }
   922 void TemplateTable::wide_dstore() {
   923   wide_lstore();
   924 }
   926 void TemplateTable::wide_astore() {
   927   transition(vtos, vtos);
   928   __ pop_ptr(FSR);
   929   locals_index_wide(T2);
   930   __ sd(FSR, T2, 0);
   931 }
   933 // used register : T2
   934 void TemplateTable::iastore() {
   935   transition(itos, vtos);
   936   __ pop_i(SSR);   // T2: array  SSR: index
   937   if(UseBoundCheckInstruction) {
   938     __ pop_ptr(T2);
   939     __ dsll(SSR, SSR, Address::times_4);
   940     __ dadd(SSR, T2, SSR);
   941     __ addi(SSR, SSR, arrayOopDesc::base_offset_in_bytes(T_INT));  // base
   943     __ lw(AT, T2, arrayOopDesc::length_offset_in_bytes());
   944     __ dsll(AT, AT, Address::times_4);
   945     __ dadd(AT, T2, AT);
   946     __ addi(AT, AT, arrayOopDesc::base_offset_in_bytes(T_INT));  //bound
   948     __ gsswle(FSR, SSR, AT);
   949   } else {
   950     index_check(T2, SSR);  // prefer index in ebx
   951     __ dsll(SSR, SSR, Address::times_4);
   952     __ dadd(T2, T2, SSR);
   953     __ sw(FSR, T2, arrayOopDesc::base_offset_in_bytes(T_INT));
   954   }
   955 }
   959 // used register T2, T3
   960 void TemplateTable::lastore() {
   961   transition(ltos, vtos);
   962   __ pop_i (T2);
   963   if(UseBoundCheckInstruction) {
   964     __ pop_ptr(T3);
   965     __ dsll(T2, T2, Address::times_8);
   966     __ dadd(T2, T3, T2);
   967     __ addi(T2, T2, arrayOopDesc::base_offset_in_bytes(T_LONG) + 0 * wordSize);  // base
   969     __ lw(AT, T3, arrayOopDesc::length_offset_in_bytes());
   970     __ dsll(AT, AT, Address::times_8);
   971     __ dadd(AT, T3, AT);
   972     __ addi(AT, AT, arrayOopDesc::base_offset_in_bytes(T_LONG) + 0 * wordSize);  //bound
   974     __ gssdle(FSR, T2, AT);
   975   } else {
   976     index_check(T3, T2);
   977     __ dsll(T2, T2, Address::times_8);
   978     __ dadd(T3, T3, T2);
   979     __ sd(FSR, T3, arrayOopDesc::base_offset_in_bytes(T_LONG) + 0 * wordSize);
   980   }
   981 }
   983 // used register T2
   984 void TemplateTable::fastore() {
   985   transition(ftos, vtos);
   986   __ pop_i(SSR);
   987   if(UseBoundCheckInstruction) {
   988     __ pop_ptr(T2);
   989     __ dsll(SSR, SSR, Address::times_4);
   990     __ dadd(SSR, T2, SSR);
   991     __ addi(SSR, SSR, arrayOopDesc::base_offset_in_bytes(T_FLOAT));  // base
   993     __ lw(AT, T2, arrayOopDesc::length_offset_in_bytes());
   994     __ dsll(AT, AT, Address::times_4);
   995     __ dadd(AT, T2, AT);
   996     __ addi(AT, AT, arrayOopDesc::base_offset_in_bytes(T_FLOAT));  //bound
   998     __ gsswlec1(FSF, SSR, AT);
   999   } else {
  1000     index_check(T2, SSR);
  1001     __ dsll(SSR, SSR, Address::times_4);
  1002     __ dadd(T2, T2, SSR);
  1003     __ swc1(FSF, T2, arrayOopDesc::base_offset_in_bytes(T_FLOAT));
  1007 // used register T2, T3
  1008 void TemplateTable::dastore() {
  1009   transition(dtos, vtos);
  1010   __ pop_i (T2);
  1011   if(UseBoundCheckInstruction) {
  1012     __ pop_ptr(T3);
  1013     __ dsll(T2, T2, Address::times_8);
  1014     __ dadd(T2, T3, T2);
  1015     __ addi(T2, T2, arrayOopDesc::base_offset_in_bytes(T_DOUBLE) + 0 * wordSize);  // base
  1017     __ lw(AT, T3, arrayOopDesc::length_offset_in_bytes());
  1018     __ dsll(AT, AT, Address::times_8);
  1019     __ dadd(AT, T3, AT);
  1020     __ addi(AT, AT, arrayOopDesc::base_offset_in_bytes(T_DOUBLE) + 0 * wordSize);  //bound
  1022     __ gssdlec1(FSF, T2, AT);
  1023   } else {
  1024     index_check(T3, T2);
  1025     __ dsll(T2, T2, Address::times_8);
  1026     __ daddu(T3, T3, T2);
  1027     __ sdc1(FSF, T3, arrayOopDesc::base_offset_in_bytes(T_DOUBLE) + 0 * wordSize);
  1031 // used register : T2, T3, T8
  1032 // T2 : array
  1033 // T3 : subklass
  1034 // T8 : supklass
  1035 void TemplateTable::aastore() {
  1036   Label is_null, ok_is_subtype, done;
  1037   transition(vtos, vtos);
  1038   // stack: ..., array, index, value
  1039   __ ld(FSR, at_tos());     // Value
  1040   __ lw(SSR, at_tos_p1());  // Index
  1041   __ ld(T2, at_tos_p2());  // Array
  1043   // index_check(T2, SSR);
  1044   index_check_without_pop(T2, SSR);
  1045   // do array store check - check for NULL value first
  1046   __ beq(FSR, R0, is_null);
  1047   __ delayed()->nop();
  1049   // Move subklass into T3
  1050   //add for compressedoops
  1051   __ load_klass(T3, FSR);
  1052   // Move superklass into T8
  1053   //add for compressedoops
  1054   __ load_klass(T8, T2);
  1055   __ ld(T8, Address(T8,  ObjArrayKlass::element_klass_offset()));
  1056   // Compress array+index*4+12 into a single register. T2
  1057   __ dsll(AT, SSR, UseCompressedOops? Address::times_4 : Address::times_8);
  1058   __ dadd(T2, T2, AT);
  1059   __ daddi(T2, T2, arrayOopDesc::base_offset_in_bytes(T_OBJECT));
  1061   // Generate subtype check.
  1062   // Superklass in T8.  Subklass in T3.
  1063   __ gen_subtype_check(T8, T3, ok_is_subtype);        // <-- Jin
  1064   // Come here on failure
  1065   // object is at FSR
  1066   __ jmp(Interpreter::_throw_ArrayStoreException_entry);    // <-- Jin
  1067   __ delayed()->nop();
  1068   // Come here on success
  1069   __ bind(ok_is_subtype);
  1070   //replace with do_oop_store->store_heap_oop
  1071   __ store_heap_oop(Address(T2, 0), FSR);          // <-- Jin
  1072   __ store_check(T2);
  1073   __ b(done);
  1074   __ delayed()->nop();
  1076   // Have a NULL in FSR, EDX=T2, SSR=index.  Store NULL at ary[idx]
  1077   __ bind(is_null);
  1078   __ profile_null_seen(T9);
  1079   __ dsll(AT, SSR, UseCompressedOops? Address::times_4 : Address::times_8);
  1080   __ dadd(T2, T2, AT);
  1081   __ store_heap_oop(Address(T2, arrayOopDesc::base_offset_in_bytes(T_OBJECT)), FSR);  /* FSR is null here */
  1083   __ bind(done);
  1084   __ daddi(SP, SP, 3 * Interpreter::stackElementSize);
  1087 void TemplateTable::bastore() {
  1088   transition(itos, vtos);
  1089   __ pop_i(SSR);
  1090   if(UseBoundCheckInstruction) {
  1091     __ pop_ptr(T2);
  1092     __ dadd(SSR, T2, SSR);
  1093     __ addi(SSR, SSR, arrayOopDesc::base_offset_in_bytes(T_BYTE));  // base
  1095     __ lw(AT, T2, arrayOopDesc::length_offset_in_bytes());
  1096     __ dadd(AT, T2, AT);
  1097     __ addi(AT, AT, arrayOopDesc::base_offset_in_bytes(T_BYTE));  //bound
  1099     __ gssble(FSR, SSR, AT);
  1100   } else {
  1101     index_check(T2, SSR);
  1102     __ dadd(SSR, T2, SSR);
  1103     __ sb(FSR, SSR, arrayOopDesc::base_offset_in_bytes(T_BYTE));
  1107 void TemplateTable::castore() {
  1108   transition(itos, vtos);
  1109   __ pop_i(SSR);
  1110   if(UseBoundCheckInstruction) {
  1111     __ pop_ptr(T2);
  1112     __ dsll(SSR, SSR, Address::times_2);
  1113     __ dadd(SSR, T2, SSR);
  1114     __ addi(SSR, SSR, arrayOopDesc::base_offset_in_bytes(T_CHAR));  // base
  1116     __ lw(AT, T2, arrayOopDesc::length_offset_in_bytes());
  1117     __ dsll(AT, AT, Address::times_2);
  1118     __ dadd(AT, T2, AT);
  1119     __ addi(AT, AT, arrayOopDesc::base_offset_in_bytes(T_CHAR));  //bound
  1121     __ gsshle(FSR, SSR, AT);
  1122   } else {
  1123     index_check(T2, SSR);
  1124     __ dsll(SSR, SSR, Address::times_2);
  1125     __ dadd(SSR, T2, SSR);
  1126     __ sh(FSR, SSR, arrayOopDesc::base_offset_in_bytes(T_CHAR));
  1130 void TemplateTable::sastore() {
  1131   castore();
  1134 void TemplateTable::istore(int n) {
  1135   transition(itos, vtos);
  1136   __ sw(FSR, iaddress(n));
  1139 void TemplateTable::lstore(int n) {
  1140   transition(ltos, vtos);
  1141   __ sd(FSR, laddress(n));
  1144 void TemplateTable::fstore(int n) {
  1145   transition(ftos, vtos);
  1146   __ swc1(FSF, faddress(n));
  1149 void TemplateTable::dstore(int n) {
  1150   transition(dtos, vtos);
  1151   __ sdc1(FSF, laddress(n));
  1154 void TemplateTable::astore(int n) {
  1155   transition(vtos, vtos);
  1156   __ pop_ptr(FSR);
  1157   __ sd(FSR, aaddress(n));
  1160 void TemplateTable::pop() {
  1161   transition(vtos, vtos);
  1162   __ daddi(SP, SP, Interpreter::stackElementSize);
  1165 void TemplateTable::pop2() {
  1166   transition(vtos, vtos);
  1167   __ daddi(SP, SP, 2 * Interpreter::stackElementSize);
  1170 void TemplateTable::dup() {
  1171   transition(vtos, vtos);
  1172   // stack: ..., a
  1173   __ load_ptr(0, FSR);
  1174   __ push_ptr(FSR);
  1175   // stack: ..., a, a
  1178 // blows FSR
  1179 void TemplateTable::dup_x1() {
  1180   transition(vtos, vtos);
  1181   // stack: ..., a, b
  1182   __ load_ptr(0, FSR);  // load b
  1183   __ load_ptr(1, A5);  // load a
  1184   __ store_ptr(1, FSR); // store b
  1185   __ store_ptr(0, A5); // store a
  1186   __ push_ptr(FSR);             // push b
  1187   // stack: ..., b, a, b
  1190 // blows FSR
  1191 void TemplateTable::dup_x2() {
  1192   transition(vtos, vtos);
  1193   // stack: ..., a, b, c
  1194   __ load_ptr(0, FSR);  // load c
  1195   __ load_ptr(2, A5);  // load a
  1196   __ store_ptr(2, FSR); // store c in a
  1197   __ push_ptr(FSR);             // push c
  1198   // stack: ..., c, b, c, c
  1199   __ load_ptr(2, FSR);  // load b
  1200   __ store_ptr(2, A5); // store a in b
  1201   // stack: ..., c, a, c, c
  1202   __ store_ptr(1, FSR); // store b in c
  1203   // stack: ..., c, a, b, c
  1206 // blows FSR
  1207 void TemplateTable::dup2() {
  1208   transition(vtos, vtos);
  1209   // stack: ..., a, b
  1210   __ load_ptr(1, FSR);  // load a
  1211   __ push_ptr(FSR);             // push a
  1212   __ load_ptr(1, FSR);  // load b
  1213   __ push_ptr(FSR);             // push b
  1214   // stack: ..., a, b, a, b
  1217 // blows FSR
  1218 void TemplateTable::dup2_x1() {
  1219   transition(vtos, vtos);
  1220   // stack: ..., a, b, c
  1221   __ load_ptr(0, T2);  // load c
  1222   __ load_ptr(1, FSR);  // load b
  1223   __ push_ptr(FSR);             // push b
  1224   __ push_ptr(T2);             // push c
  1225   // stack: ..., a, b, c, b, c
  1226   __ store_ptr(3, T2); // store c in b
  1227   // stack: ..., a, c, c, b, c
  1228   __ load_ptr(4, T2);  // load a
  1229   __ store_ptr(2, T2); // store a in 2nd c
  1230   // stack: ..., a, c, a, b, c
  1231   __ store_ptr(4, FSR); // store b in a
  1232   // stack: ..., b, c, a, b, c
  1234   // stack: ..., b, c, a, b, c
  1237 // blows FSR, SSR
  1238 void TemplateTable::dup2_x2() {
  1239   transition(vtos, vtos);
  1240   // stack: ..., a, b, c, d
  1241   // stack: ..., a, b, c, d
  1242   __ load_ptr(0, T2);  // load d
  1243   __ load_ptr(1, FSR);  // load c
  1244   __ push_ptr(FSR);             // push c
  1245   __ push_ptr(T2);             // push d
  1246   // stack: ..., a, b, c, d, c, d
  1247   __ load_ptr(4, FSR);  // load b
  1248   __ store_ptr(2, FSR); // store b in d
  1249   __ store_ptr(4, T2); // store d in b
  1250   // stack: ..., a, d, c, b, c, d
  1251   __ load_ptr(5, T2);  // load a
  1252   __ load_ptr(3, FSR);  // load c
  1253   __ store_ptr(3, T2); // store a in c
  1254   __ store_ptr(5, FSR); // store c in a
  1255   // stack: ..., c, d, a, b, c, d
  1257   // stack: ..., c, d, a, b, c, d
  1260 // blows FSR
  1261 void TemplateTable::swap() {
  1262   transition(vtos, vtos);
  1263   // stack: ..., a, b
  1265   __ load_ptr(1, A5);  // load a
  1266   __ load_ptr(0, FSR);  // load b
  1267   __ store_ptr(0, A5); // store a in b
  1268   __ store_ptr(1, FSR); // store b in a
  1270   // stack: ..., b, a
  1273 void TemplateTable::iop2(Operation op) {
  1274   transition(itos, itos);
  1275   switch (op) {
  1276     case add  :
  1277       __ pop_i(SSR);
  1278       __ addu32(FSR, SSR, FSR);
  1279       break;
  1280     case sub  :
  1281       __ pop_i(SSR);
  1282       __ subu32(FSR, SSR, FSR);
  1283       break;
  1284     case mul  :
  1285       __ lw(SSR, SP, 0);
  1286       __ daddi(SP, SP, wordSize);
  1287                         __ mul(FSR, SSR, FSR);
  1288       break;
  1289     case _and :
  1290       __ pop_i(SSR);
  1291       __ andr(FSR, SSR, FSR);
  1292       break;
  1293     case _or  :
  1294       __ pop_i(SSR);
  1295       __ orr(FSR, SSR, FSR);
  1296       break;
  1297     case _xor :
  1298       __ pop_i(SSR);
  1299       __ xorr(FSR, SSR, FSR);
  1300       break;
  1301     case shl  :
  1302       __ pop_i(SSR);
  1303       __ sllv(FSR, SSR, FSR);
  1304       break; // implicit masking of lower 5 bits by Intel shift instr. mips also
  1305     case shr  :
  1306       __ pop_i(SSR);
  1307       __ srav(FSR, SSR, FSR);
  1308       break; // implicit masking of lower 5 bits by Intel shift instr. mips also
  1309     case ushr :
  1310       __ pop_i(SSR);
  1311       __ srlv(FSR, SSR, FSR);
  1312       break; // implicit masking of lower 5 bits by Intel shift instr. mips also
  1313     default   : ShouldNotReachHere();
  1317 // the result stored in FSR, SSR,
  1318 // used registers : T2, T3
  1319 void TemplateTable::lop2(Operation op) {
  1320   transition(ltos, ltos);
  1321   __ pop_l(T2, T3);
  1322 #ifdef ASSERT
  1324     Label  L;
  1325     __ beq(T3, R0, L);
  1326     __ delayed()->nop();
  1327     __ bind(L);
  1329 #endif
  1330   switch (op) {
  1331     case add :
  1332       __ daddu(FSR, T2, FSR);
  1333       break;
  1334     case sub :
  1335       __ dsubu(FSR, T2, FSR);
  1336       break;
  1337     case _and:
  1338       __ andr(FSR, T2, FSR);
  1339       break;
  1340     case _or :
  1341       __ orr(FSR, T2, FSR);
  1342       break;
  1343     case _xor:
  1344       __ xorr(FSR, T2, FSR);
  1345       break;
  1346     default : ShouldNotReachHere();
  1350 // java require this bytecode could handle 0x80000000/-1, dont cause a overflow exception,
  1351 // the result is 0x80000000
  1352 // the godson2 cpu do the same, so we need not handle this specially like x86
  1353 void TemplateTable::idiv() {
  1354   transition(itos, itos);
  1355   Label not_zero;
  1357   __ bne(FSR, R0, not_zero);
  1358   __ delayed()->nop();
  1359   __ jmp(Interpreter::_throw_ArithmeticException_entry);
  1360   __ delayed()->nop();
  1361   __ bind(not_zero);
  1363   __ pop_i(SSR);
  1364   if (UseLoongsonISA) {
  1365     __ gsdiv(FSR, SSR, FSR);
  1366   } else {
  1367     __ div(SSR, FSR);
  1368     __ mflo(FSR);
  1372 void TemplateTable::irem() {
  1373   transition(itos, itos);
  1374   Label not_zero;
  1375   __ pop_i(SSR);
  1376   __ div(SSR, FSR);
  1378   __ bne(FSR, R0, not_zero);
  1379   __ delayed()->nop();
  1380   //__ brk(7);
  1381   __ jmp(Interpreter::_throw_ArithmeticException_entry);
  1382   __ delayed()->nop();
  1384   __ bind(not_zero);
  1385   __ mfhi(FSR);
  1388 void TemplateTable::lmul() {
  1389   transition(ltos, ltos);
  1390   __ pop_l(T2);
  1391   if(UseLoongsonISA){
  1392     __ gsdmult(FSR, T2, FSR);
  1393   } else {
  1394     __ dmult(T2, FSR);
  1395     __ mflo(FSR);
  1399 // NOTE: i DONT use the Interpreter::_throw_ArithmeticException_entry
  1400 void TemplateTable::ldiv() {
  1401   transition(ltos, ltos);
  1402   Label normal;
  1404   __ bne(FSR, R0, normal);
  1405   __ delayed()->nop();
  1407   //__ brk(7);    //generate FPE
  1408   __ jmp(Interpreter::_throw_ArithmeticException_entry);
  1409   __ delayed()->nop();
  1411   __ bind(normal);
  1412   __ pop_l(A2, A3);
  1413   if (UseLoongsonISA) {
  1414     __ gsddiv(FSR, A2, FSR);
  1415   } else {
  1416     __ ddiv(A2, FSR);
  1417     __ mflo(FSR);
  1421 // NOTE: i DONT use the Interpreter::_throw_ArithmeticException_entry
  1422 void TemplateTable::lrem() {
  1423   transition(ltos, ltos);
  1424   Label normal;
  1426   __ bne(FSR, R0, normal);
  1427   __ delayed()->nop();
  1429   __ jmp(Interpreter::_throw_ArithmeticException_entry);
  1430   __ delayed()->nop();
  1432   __ bind(normal);
  1433   __ pop_l (A2, A3);
  1435   if(UseLoongsonISA){
  1436     __ gsdmod(FSR, A2, FSR);
  1437   } else {
  1438     __ ddiv(A2, FSR);
  1439     __ mfhi(FSR);
  1443 // result in FSR
  1444 // used registers : T0
  1445 void TemplateTable::lshl() {
  1446   transition(itos, ltos);
  1447   __ pop_l(T0, T1);
  1448 #ifdef ASSERT
  1450     Label  L;
  1451     __ beq(T1, R0, L);
  1452     __ delayed()->nop();
  1453     //__ stop("lshl, wrong stack");  // <-- Fu 20130930
  1454     __ bind(L);
  1456 #endif
  1457   __ dsllv(FSR, T0, FSR);
  1460 // used registers : T0
  1461 void TemplateTable::lshr() {
  1462   transition(itos, ltos);
  1463   __ pop_l(T0, T1);
  1464 #ifdef ASSERT
  1466     Label  L;
  1467     __ beq(T1, R0, L);
  1468     __ delayed()->nop();
  1469     __ stop("lshr, wrong stack");
  1470     __ bind(L);
  1472 #endif
  1473   __ dsrav(FSR, T0, FSR);
  1476 // used registers : T0
  1477 void TemplateTable::lushr() {
  1478   transition(itos, ltos);
  1479   __ pop_l(T0, T1);
  1480 #ifdef ASSERT
  1482     Label  L;
  1483     __ beq(T1, R0, L);
  1484     __ delayed()->nop();
  1485     __ stop("lushr, wrong stack");
  1486     __ bind(L);
  1488 #endif
  1489   __ dsrlv(FSR, T0, FSR);
  1492 // result in FSF
  1493 void TemplateTable::fop2(Operation op) {
  1494   transition(ftos, ftos);
  1495   switch (op) {
  1496     case add:
  1497       __ lwc1(FTF, at_sp());
  1498       __ add_s(FSF, FTF, FSF);
  1499       break;
  1500     case sub:
  1501       __ lwc1(FTF, at_sp());
  1502       __ sub_s(FSF, FTF, FSF);
  1503       break;
  1504     case mul:
  1505       __ lwc1(FTF, at_sp());
  1506       __ mul_s(FSF, FTF, FSF);
  1507       break;
  1508     case div:
  1509       __ lwc1(FTF, at_sp());
  1510       __ div_s(FSF, FTF, FSF);
  1511       break;
  1512     case rem:
  1513       __ mov_s(F13, FSF);
  1514       __ lwc1(F12, at_sp());
  1515        __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::frem), 2);
  1516       break;
  1517     default : ShouldNotReachHere();
  1520   __ daddi(SP, SP, 1 * wordSize);
  1523 // result in SSF||FSF
  1524 // i dont handle the strict flags
  1525 void TemplateTable::dop2(Operation op) {
  1526   transition(dtos, dtos);
  1527   switch (op) {
  1528     case add:
  1529       __ ldc1(FTF, at_sp());
  1530       __ add_d(FSF, FTF, FSF);
  1531       break;
  1532     case sub:
  1533       __ ldc1(FTF, at_sp());
  1534       __ sub_d(FSF, FTF, FSF);
  1535       break;
  1536     case mul:
  1537       __ ldc1(FTF, at_sp());
  1538       __ mul_d(FSF, FTF, FSF);
  1539       break;
  1540     case div:
  1541       __ ldc1(FTF, at_sp());
  1542       __ div_d(FSF, FTF, FSF);
  1543       break;
  1544     case rem:
  1545       __ mov_d(F13, FSF);
  1546       __ ldc1(F12, at_sp());
  1547       __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::drem), 2);
  1548       break;
  1549     default : ShouldNotReachHere();
  1552   __ daddi(SP, SP, 2 * wordSize);
  1555 void TemplateTable::ineg() {
  1556   transition(itos, itos);
  1557   __ neg(FSR);
  1560 void TemplateTable::lneg() {
  1561   transition(ltos, ltos);
  1562   __ dsubu(FSR, R0, FSR);
  1565 void TemplateTable::fneg() {
  1566   transition(ftos, ftos);
  1567   __ neg_s(FSF, FSF);
  1570 void TemplateTable::dneg() {
  1571   transition(dtos, dtos);
  1572   __ neg_d(FSF, FSF);
  1575 // used registers : T2
  1576 void TemplateTable::iinc() {
  1577   transition(vtos, vtos);
  1578   locals_index(T2);
  1579   __ lw(FSR, T2, 0);
  1580   __ lb(AT, at_bcp(2));           // get constant
  1581   __ daddu(FSR, FSR, AT);
  1582   __ sw(FSR, T2, 0);
  1585 // used register : T2
  1586 void TemplateTable::wide_iinc() {
  1587   transition(vtos, vtos);
  1588   locals_index_wide(T2);
  1589   __ get_2_byte_integer_at_bcp(FSR, AT, 4);
  1590   __ hswap(FSR);
  1591   __ lw(AT, T2, 0);
  1592   __ daddu(FSR, AT, FSR);
  1593   __ sw(FSR, T2, 0);
  1596 void TemplateTable::convert() {
  1597   // Checking
  1598 #ifdef ASSERT
  1600     TosState tos_in  = ilgl;
  1601     TosState tos_out = ilgl;
  1602     switch (bytecode()) {
  1603       case Bytecodes::_i2l: // fall through
  1604       case Bytecodes::_i2f: // fall through
  1605       case Bytecodes::_i2d: // fall through
  1606       case Bytecodes::_i2b: // fall through
  1607       case Bytecodes::_i2c: // fall through
  1608       case Bytecodes::_i2s: tos_in = itos; break;
  1609       case Bytecodes::_l2i: // fall through
  1610       case Bytecodes::_l2f: // fall through
  1611       case Bytecodes::_l2d: tos_in = ltos; break;
  1612       case Bytecodes::_f2i: // fall through
  1613       case Bytecodes::_f2l: // fall through
  1614       case Bytecodes::_f2d: tos_in = ftos; break;
  1615       case Bytecodes::_d2i: // fall through
  1616       case Bytecodes::_d2l: // fall through
  1617       case Bytecodes::_d2f: tos_in = dtos; break;
  1618       default             : ShouldNotReachHere();
  1620     switch (bytecode()) {
  1621       case Bytecodes::_l2i: // fall through
  1622       case Bytecodes::_f2i: // fall through
  1623       case Bytecodes::_d2i: // fall through
  1624       case Bytecodes::_i2b: // fall through
  1625       case Bytecodes::_i2c: // fall through
  1626       case Bytecodes::_i2s: tos_out = itos; break;
  1627       case Bytecodes::_i2l: // fall through
  1628       case Bytecodes::_f2l: // fall through
  1629       case Bytecodes::_d2l: tos_out = ltos; break;
  1630       case Bytecodes::_i2f: // fall through
  1631       case Bytecodes::_l2f: // fall through
  1632       case Bytecodes::_d2f: tos_out = ftos; break;
  1633       case Bytecodes::_i2d: // fall through
  1634       case Bytecodes::_l2d: // fall through
  1635       case Bytecodes::_f2d: tos_out = dtos; break;
  1636       default             : ShouldNotReachHere();
  1638     transition(tos_in, tos_out);
  1640 #endif // ASSERT
  1642   // Conversion
  1643   // (Note: use pushl(ecx)/popl(ecx) for 1/2-word stack-ptr manipulation)
  1644   switch (bytecode()) {
  1645     case Bytecodes::_i2l:
  1646       __ sll(FSR, FSR, 0);
  1647       break;
  1648     case Bytecodes::_i2f:
  1649       __ mtc1(FSR, FSF);
  1650       __ cvt_s_w(FSF, FSF);
  1651       break;
  1652     case Bytecodes::_i2d:
  1653       __ mtc1(FSR, FSF);
  1654       __ cvt_d_w(FSF, FSF);
  1655       break;
  1656     case Bytecodes::_i2b:
  1657       __ seb(FSR, FSR);
  1658       break;
  1659     case Bytecodes::_i2c:
  1660       __ andi(FSR, FSR, 0xFFFF);  // truncate upper 56 bits
  1661       break;
  1662     case Bytecodes::_i2s:
  1663       __ seh(FSR, FSR);
  1664       break;
  1665     case Bytecodes::_l2i:
  1666       __ sll(FSR, FSR, 0);
  1667       break;
  1668     case Bytecodes::_l2f:
  1669       __ dmtc1(FSR, FSF);
  1670       __ cvt_s_l(FSF, FSF);
  1671       break;
  1672     case Bytecodes::_l2d:
  1673       __ dmtc1(FSR, FSF);
  1674       __ cvt_d_l(FSF, FSF);
  1675       break;
  1676     case Bytecodes::_f2i:
  1678       Label L;
  1680       __ trunc_w_s(F12, FSF);
  1681       __ move(AT, 0x7fffffff);
  1682       __ mfc1(FSR, F12);
  1683       __ c_un_s(FSF, FSF);    //NaN?
  1684       __ movt(FSR, R0);
  1686       __ bne(AT, FSR, L);
  1687       __ delayed()->lui(T9, 0x8000);
  1689       __ mfc1(AT, FSF);
  1690       __ andr(AT, AT, T9);
  1692       __ movn(FSR, T9, AT);
  1694       __ bind(L);
  1696       break;
  1697     case Bytecodes::_f2l:
  1699       Label L;
  1701       __ trunc_l_s(F12, FSF);
  1702       __ daddiu(AT, R0, -1);
  1703       __ dsrl(AT, AT, 1);
  1704       __ dmfc1(FSR, F12);
  1705       __ c_un_s(FSF, FSF);    //NaN?
  1706       __ movt(FSR, R0);
  1708       __ bne(AT, FSR, L);
  1709       __ delayed()->lui(T9, 0x8000);
  1711       __ mfc1(AT, FSF);
  1712       __ andr(AT, AT, T9);
  1714       __ dsll32(T9, T9, 0);
  1715       __ movn(FSR, T9, AT);
  1717       __ bind(L);
  1719       break;
  1720     case Bytecodes::_f2d:
  1721       __ cvt_d_s(FSF, FSF);
  1722       break;
  1723     case Bytecodes::_d2i:
  1725       Label L;
  1727       __ trunc_w_d(F12, FSF);
  1728       __ move(AT, 0x7fffffff);
  1729       __ mfc1(FSR, F12);
  1731       __ bne(FSR, AT, L);
  1732       __ delayed()->mtc1(R0, F12);
  1734       __ cvt_d_w(F12, F12);
  1735       __ c_ult_d(FSF, F12);
  1736       __ bc1f(L);
  1737       __ delayed()->addiu(T9, R0, -1);
  1739       __ c_un_d(FSF, FSF);    //NaN?
  1740       __ subu32(FSR, T9, AT);
  1741       __ movt(FSR, R0);
  1743       __ bind(L);
  1745       break;
  1746     case Bytecodes::_d2l:
  1748       Label L;
  1750       __ trunc_l_d(F12, FSF);
  1751       __ daddiu(AT, R0, -1);
  1752       __ dsrl(AT, AT, 1);
  1753       __ dmfc1(FSR, F12);
  1755       __ bne(FSR, AT, L);
  1756       __ delayed()->mtc1(R0, F12);
  1758       __ cvt_d_w(F12, F12);
  1759       __ c_ult_d(FSF, F12);
  1760       __ bc1f(L);
  1761       __ delayed()->daddiu(T9, R0, -1);
  1763       __ c_un_d(FSF, FSF);    //NaN?
  1764       __ subu(FSR, T9, AT);
  1765       __ movt(FSR, R0);
  1767     __ bind(L);
  1769       break;
  1770     case Bytecodes::_d2f:
  1771       __ cvt_s_d(FSF, FSF);
  1772       break;
  1773     default             :
  1774       ShouldNotReachHere();
  1778 void TemplateTable::lcmp() {
  1779   transition(ltos, itos);
  1781   Label low, high, done;
  1782   __ pop(T0);
  1783   __ pop(R0);
  1784   __ slt(AT, T0, FSR);
  1785   __ bne(AT, R0, low);
  1786   __ delayed()->nop();
  1788   __ bne(T0, FSR, high);
  1789   __ delayed()->nop();
  1791   __ li(FSR, (long)0);
  1792   __ b(done);
  1793   __ delayed()->nop();
  1795   __ bind(low);
  1796   __ li(FSR, (long)-1);
  1797   __ b(done);
  1798   __ delayed()->nop();
  1800   __ bind(high);
  1801   __ li(FSR, (long)1);
  1802   __ b(done);
  1803   __ delayed()->nop();
  1805   __ bind(done);
  1808 void TemplateTable::float_cmp(bool is_float, int unordered_result) {
  1809   Label less, done;
  1811   __ move(FSR, R0);
  1813   if (is_float) {
  1814     __ lwc1(FTF, at_sp());
  1815     __ c_eq_s(FTF, FSF);
  1816     __ bc1t(done);
  1817     __ delayed()->daddi(SP, SP, 1 * wordSize);
  1819     if (unordered_result<0)
  1820       __ c_ult_s(FTF, FSF);
  1821     else
  1822       __ c_olt_s(FTF, FSF);
  1823   } else {
  1824     __ ldc1(FTF, at_sp());
  1825     __ c_eq_d(FTF, FSF);
  1826     __ bc1t(done);
  1827     __ delayed()->daddi(SP, SP, 2 * wordSize);
  1829     if (unordered_result<0)
  1830       __ c_ult_d(FTF, FSF);
  1831     else
  1832       __ c_olt_d(FTF, FSF);
  1834   __ bc1t(less);
  1835   __ delayed()->nop();
  1836   __ move(FSR, 1);
  1837   __ b(done);
  1838   __ delayed()->nop();
  1839   __ bind(less);
  1840   __ move(FSR, -1);
  1841   __ bind(done);
  1845 // used registers : T3, A7, Rnext
  1846 // FSR : return bci, this is defined by the vm specification
  1847 // T2 : MDO taken count
  1848 // T3 : method
  1849 // A7 : offset
  1850 // Rnext : next bytecode, this is required by dispatch_base
  1851 void TemplateTable::branch(bool is_jsr, bool is_wide) {
  1852   __ get_method(T3);
  1853   __ profile_taken_branch(A7, T2);    // only C2 meaningful
  1855 #ifndef CORE
  1856   const ByteSize be_offset = MethodCounters::backedge_counter_offset() +
  1857                              InvocationCounter::counter_offset();
  1858   const ByteSize inv_offset = MethodCounters::invocation_counter_offset() +
  1859                               InvocationCounter::counter_offset();
  1860 #endif // CORE
  1862   // Load up T4 with the branch displacement
  1863   if (!is_wide) {
  1864     __ get_2_byte_integer_at_bcp(A7, AT, 1);
  1865     __ hswap(A7);
  1866   } else {
  1867     __ get_4_byte_integer_at_bcp(A7, AT, 1);
  1868     __ swap(A7);
  1871   // Handle all the JSR stuff here, then exit.
  1872   // It's much shorter and cleaner than intermingling with the non-JSR
  1873   // normal-branch stuff occuring below.
  1874   if (is_jsr) {
  1875     // Pre-load the next target bytecode into Rnext
  1876     __ dadd(AT, BCP, A7);
  1877     __ lbu(Rnext, AT, 0);
  1879     // compute return address as bci in FSR
  1880     __ daddi(FSR, BCP, (is_wide?5:3) - in_bytes(ConstMethod::codes_offset()));
  1881     __ ld(AT, T3, in_bytes(Method::const_offset()));
  1882     __ dsub(FSR, FSR, AT);
  1883     // Adjust the bcp in BCP by the displacement in A7
  1884     __ dadd(BCP, BCP, A7);
  1885     // jsr returns atos that is not an oop
  1886     // Push return address
  1887     __ push_i(FSR);
  1888     // jsr returns vtos
  1889     __ dispatch_only_noverify(vtos);
  1891     return;
  1894   // Normal (non-jsr) branch handling
  1896   // Adjust the bcp in S0 by the displacement in T4
  1897   __ dadd(BCP, BCP, A7);
  1899 #ifdef CORE
  1900   // Pre-load the next target bytecode into EBX
  1901   __ lbu(Rnext, BCP, 0);
  1902   // continue with the bytecode @ target
  1903   __ dispatch_only(vtos);
  1904 #else
  1905   assert(UseLoopCounter || !UseOnStackReplacement, "on-stack-replacement requires loop counters");
  1906   Label backedge_counter_overflow;
  1907   Label profile_method;
  1908   Label dispatch;
  1909   if (UseLoopCounter) {
  1910     // increment backedge counter for backward branches
  1911     // eax: MDO
  1912     // ebx: MDO bumped taken-count
  1913     // T3: method
  1914     // T4: target offset
  1915     // BCP: target bcp
  1916     // LVP: locals pointer
  1917     __ bgtz(A7, dispatch);  // check if forward or backward branch
  1918     __ delayed()->nop();
  1920     // check if MethodCounters exists
  1921     Label has_counters;
  1922     __ ld(AT, T3, in_bytes(Method::method_counters_offset()));  // use AT as MDO, TEMP
  1923     __ bne(AT, R0, has_counters);
  1924     __ nop();
  1925     __ push(T3);
  1926     //__ push(A7);
  1927     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::build_method_counters),
  1928                T3);
  1929     //__ pop(A7);
  1930     __ pop(T3);
  1931     __ ld(AT, T3, in_bytes(Method::method_counters_offset()));  // use AT as MDO, TEMP
  1932     __ beq(AT, R0, dispatch);
  1933     __ nop();
  1934     __ bind(has_counters);
  1936     // increment back edge counter
  1937     __ ld(T1, T3, in_bytes(Method::method_counters_offset()));
  1938     __ lw(T0, T1, in_bytes(be_offset));
  1939     __ increment(T0, InvocationCounter::count_increment);
  1940     __ sw(T0, T1, in_bytes(be_offset));
  1942     // load invocation counter
  1943     __ lw(T1, T1, in_bytes(inv_offset));
  1944     // buffer bit added, mask no needed
  1946     // dadd backedge counter & invocation counter
  1947     __ dadd(T1, T1, T0);
  1949     if (ProfileInterpreter) {
  1950       // Test to see if we should create a method data oop
  1951       //__ lui(AT, Assembler::split_high(int(&InvocationCounter::InterpreterProfileLimit)));
  1952       //__ lw(AT, AT, Assembler::split_low(int(&InvocationCounter::InterpreterProfileLimit)));
  1953       // T1 : backedge counter & invocation counter
  1954       __ li(AT, (long)&InvocationCounter::InterpreterProfileLimit);
  1955       __ lw(AT, AT, 0);
  1956       __ slt(AT, T1, AT);
  1957       __ bne(AT, R0, dispatch);
  1958       __ delayed()->nop();
  1960       // if no method data exists, go to profile method
  1961       __ test_method_data_pointer(T1, profile_method);
  1963       if (UseOnStackReplacement) {
  1964         // check for overflow against ebx which is the MDO taken count
  1965         __ li(AT, (long)&InvocationCounter::InterpreterBackwardBranchLimit);
  1966         __ lw(AT, AT, 0);
  1967         // the value Rnext Is get from the beginning profile_taken_branch
  1968         __ slt(AT, T2, AT);
  1969         __ bne(AT, R0, dispatch);
  1970         __ delayed()->nop();
  1972         // When ProfileInterpreter is on, the backedge_count comes
  1973         // from the methodDataOop, which value does not get reset on
  1974         // the call to  frequency_counter_overflow().
  1975         // To avoid excessive calls to the overflow routine while
  1976         // the method is being compiled, dadd a second test to make
  1977         // sure the overflow function is called only once every
  1978         // overflow_frequency.
  1979         const int overflow_frequency = 1024;
  1980         __ andi(AT, T2, overflow_frequency-1);
  1981         __ beq(AT, R0, backedge_counter_overflow);
  1982         __ delayed()->nop();
  1984     } else {
  1985       if (UseOnStackReplacement) {
  1986         // check for overflow against eax, which is the sum of the counters
  1987         __ li(AT, (long)&InvocationCounter::InterpreterBackwardBranchLimit);
  1988         __ lw(AT, AT, 0);
  1989         __ slt(AT, T1, AT);
  1990         __ beq(AT, R0, backedge_counter_overflow);
  1991         __ delayed()->nop();
  1994     __ bind(dispatch);
  1997   // Pre-load the next target bytecode into Rnext
  1998   __ lbu(Rnext, BCP, 0);
  2000   // continue with the bytecode @ target
  2001   // FSR: return bci for jsr's, unused otherwise
  2002   // Rnext: target bytecode
  2003   // BCP: target bcp
  2004   __ dispatch_only(vtos);
  2006   if (UseLoopCounter) {
  2007     if (ProfileInterpreter) {
  2008       // Out-of-line code to allocate method data oop.
  2009       __ bind(profile_method);
  2010       __ call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::profile_method));
  2011       __ lbu(Rnext, BCP, 0);
  2012       __ set_method_data_pointer_for_bcp();
  2013       __ b(dispatch);
  2014       __ delayed()->nop();
  2017     if (UseOnStackReplacement) {
  2018       // invocation counter overflow
  2019       __ bind(backedge_counter_overflow);
  2020       __ sub(A7, BCP, A7);  // branch bcp
  2021       call_VM(NOREG, CAST_FROM_FN_PTR(address,
  2022       InterpreterRuntime::frequency_counter_overflow), A7);
  2023       __ lbu(Rnext, BCP, 0);
  2025       // V0: osr nmethod (osr ok) or NULL (osr not possible)
  2026       // V1: osr adapter frame return address
  2027       // Rnext: target bytecode
  2028       // LVP: locals pointer
  2029       // BCP: bcp
  2030       __ beq(V0, R0, dispatch);
  2031       __ delayed()->nop();
  2032       // nmethod may have been invalidated (VM may block upon call_VM return)
  2033       __ lw(T3, V0, nmethod::entry_bci_offset());
  2034       __ move(AT, InvalidOSREntryBci);
  2035       __ beq(AT, T3, dispatch);
  2036       __ delayed()->nop();
  2037       // We need to prepare to execute the OSR method. First we must
  2038       // migrate the locals and monitors off of the stack.
  2039       //eax V0: osr nmethod (osr ok) or NULL (osr not possible)
  2040       //ebx V1: osr adapter frame return address
  2041       //edx  Rnext: target bytecode
  2042       //edi  LVP: locals pointer
  2043       //esi  BCP: bcp
  2044       __ move(BCP, V0);
  2045       // const Register thread = ecx;
  2046       const Register thread = TREG;
  2047 #ifndef OPT_THREAD
  2048       __ get_thread(thread);
  2049 #endif
  2050       call_VM(noreg, CAST_FROM_FN_PTR(address,
  2051       SharedRuntime::OSR_migration_begin));
  2052       // eax is OSR buffer, move it to expected parameter location
  2053       //refer to osrBufferPointer in c1_LIRAssembler_mips.cpp
  2054       __ move(T0, V0);
  2056       // pop the interpreter frame
  2057       __ ld(A7, Address(FP, frame::interpreter_frame_sender_sp_offset * wordSize));
  2058       //FIXME, shall we keep the return address on the stack?
  2059       __ leave();                                // remove frame anchor
  2060       __ move(LVP, RA);
  2061       __ move(SP, A7);
  2063       __ move(AT, -(StackAlignmentInBytes));
  2064       __ andr(SP , SP , AT);
  2066       // push the (possibly adjusted) return address
  2067       //refer to osr_entry in c1_LIRAssembler_mips.cpp
  2068       __ ld(AT, BCP, nmethod::osr_entry_point_offset());
  2069       __ jr(AT);
  2070       __ delayed()->nop();
  2073 #endif // not CORE
  2077 void TemplateTable::if_0cmp(Condition cc) {
  2078   transition(itos, vtos);
  2079   // assume branch is more often taken than not (loops use backward branches)
  2080   Label not_taken;
  2081   switch(cc) {
  2082     case not_equal:
  2083       __ beq(FSR, R0, not_taken);
  2084       break;
  2085     case equal:
  2086       __ bne(FSR, R0, not_taken);
  2087       break;
  2088     case less:
  2089       __ bgez(FSR, not_taken);
  2090       break;
  2091     case less_equal:
  2092       __ bgtz(FSR, not_taken);
  2093       break;
  2094     case greater:
  2095       __ blez(FSR, not_taken);
  2096       break;
  2097     case greater_equal:
  2098       __ bltz(FSR, not_taken);
  2099       break;
  2101   __ delayed()->nop();
  2103   branch(false, false);
  2105   __ bind(not_taken);
  2106   __ profile_not_taken_branch(FSR);
  2109 void TemplateTable::if_icmp(Condition cc) {
  2110   transition(itos, vtos);
  2111   // assume branch is more often taken than not (loops use backward branches)
  2112   Label not_taken;
  2114   __ pop_i(SSR);
  2115   switch(cc) {
  2116     case not_equal:
  2117       __ beq(SSR, FSR, not_taken);
  2118       break;
  2119     case equal:
  2120       __ bne(SSR, FSR, not_taken);
  2121       break;
  2122     case less:
  2123       __ slt(AT, SSR, FSR);
  2124       __ beq(AT, R0, not_taken);
  2125       break;
  2126     case less_equal:
  2127       __ slt(AT, FSR, SSR);
  2128       __ bne(AT, R0, not_taken);
  2129       break;
  2130     case greater:
  2131       __ slt(AT, FSR, SSR);
  2132       __ beq(AT, R0, not_taken);
  2133       break;
  2134     case greater_equal:
  2135       __ slt(AT, SSR, FSR);
  2136       __ bne(AT, R0, not_taken);
  2137       break;
  2139   __ delayed()->nop();
  2141   branch(false, false);
  2142   __ bind(not_taken);
  2143   __ profile_not_taken_branch(FSR);
  2146 void TemplateTable::if_nullcmp(Condition cc) {
  2147   transition(atos, vtos);
  2148   // assume branch is more often taken than not (loops use backward branches)
  2149   Label not_taken;
  2150   switch(cc) {
  2151     case not_equal:
  2152       __ beq(FSR, R0, not_taken);
  2153       break;
  2154     case equal:
  2155       __ bne(FSR, R0, not_taken);
  2156       break;
  2157     default:
  2158       ShouldNotReachHere();
  2160   __ delayed()->nop();
  2162   branch(false, false);
  2163   __ bind(not_taken);
  2164   __ profile_not_taken_branch(FSR);
  2168 void TemplateTable::if_acmp(Condition cc) {
  2169   transition(atos, vtos);
  2170   // assume branch is more often taken than not (loops use backward branches)
  2171   Label not_taken;
  2172   //  __ lw(SSR, SP, 0);
  2173   __ pop_ptr(SSR);
  2174   switch(cc) {
  2175     case not_equal:
  2176       __ beq(SSR, FSR, not_taken);
  2177       break;
  2178     case equal:
  2179       __ bne(SSR, FSR, not_taken);
  2180       break;
  2181     default:
  2182       ShouldNotReachHere();
  2184   __ delayed()->nop();
  2186   branch(false, false);
  2188   __ bind(not_taken);
  2189   __ profile_not_taken_branch(FSR);
  2192 // used registers : T1, T2, T3
  2193 // T1 : method
  2194 // T2 : returb bci
  2195 void TemplateTable::ret() {
  2196   transition(vtos, vtos);
  2198   locals_index(T2);
  2199   __ ld(T2, T2, 0);
  2200   __ profile_ret(T2, T3);
  2202   __ get_method(T1);
  2203   __ ld(BCP, T1, in_bytes(Method::const_offset()));
  2204   __ dadd(BCP, BCP, T2);
  2205   __ daddi(BCP, BCP, in_bytes(ConstMethod::codes_offset()));
  2207   __ dispatch_next(vtos);
  2210 // used registers : T1, T2, T3
  2211 // T1 : method
  2212 // T2 : returb bci
  2213 void TemplateTable::wide_ret() {
  2214   transition(vtos, vtos);
  2216   locals_index_wide(T2);
  2217   __ ld(T2, T2, 0);                   // get return bci, compute return bcp
  2218   __ profile_ret(T2, T3);
  2220   __ get_method(T1);
  2221   __ ld(BCP, T1, in_bytes(Method::const_offset()));
  2222   __ dadd(BCP, BCP, T2);
  2223   __ daddi(BCP, BCP, in_bytes(ConstMethod::codes_offset()));
  2225   __ dispatch_next(vtos);
  2228 // used register T2, T3, A7, Rnext
  2229 // T2 : bytecode pointer
  2230 // T3 : low
  2231 // A7 : high
  2232 // Rnext : dest bytecode, required by dispatch_base
  2233 void TemplateTable::tableswitch() {
  2234   Label default_case, continue_execution;
  2235   transition(itos, vtos);
  2237   // align BCP
  2238   __ daddi(T2, BCP, BytesPerInt);
  2239   __ li(AT, -BytesPerInt);
  2240   __ andr(T2, T2, AT);
  2242   // load lo & hi
  2243   __ lw(T3, T2, 1 * BytesPerInt);
  2244   __ swap(T3);
  2245   __ lw(A7, T2, 2 * BytesPerInt);
  2246   __ swap(A7);
  2248   // check against lo & hi
  2249   __ slt(AT, FSR, T3);
  2250   __ bne(AT, R0, default_case);
  2251   __ delayed()->nop();
  2253   __ slt(AT, A7, FSR);
  2254   __ bne(AT, R0, default_case);
  2255   __ delayed()->nop();
  2257   // lookup dispatch offset, in A7 big endian
  2258   __ dsub(FSR, FSR, T3);
  2259   __ dsll(AT, FSR, Address::times_4);
  2260   __ dadd(AT, T2, AT);
  2261   __ lw(A7, AT, 3 * BytesPerInt);
  2262   __ profile_switch_case(FSR, T9, T3);
  2264   __ bind(continue_execution);
  2265   __ swap(A7);
  2266   __ dadd(BCP, BCP, A7);
  2267   __ lbu(Rnext, BCP, 0);
  2268   __ dispatch_only(vtos);
  2270   // handle default
  2271   __ bind(default_case);
  2272   __ profile_switch_default(FSR);
  2273   __ lw(A7, T2, 0);
  2274   __ b(continue_execution);
  2275   __ delayed()->nop();
  2278 void TemplateTable::lookupswitch() {
  2279   transition(itos, itos);
  2280   __ stop("lookupswitch bytecode should have been rewritten");
  2283 // used registers : T2, T3, A7, Rnext
  2284 // T2 : bytecode pointer
  2285 // T3 : pair index
  2286 // A7 : offset
  2287 // Rnext : dest bytecode
  2288 // the data after the opcode is the same as lookupswitch
  2289 // see Rewriter::rewrite_method for more information
  2290 void TemplateTable::fast_linearswitch() {
  2291   transition(itos, vtos);
  2292   Label loop_entry, loop, found, continue_execution;
  2294   // swap eax so we can avoid swapping the table entries
  2295   __ swap(FSR);
  2297   // align BCP
  2298   __ daddi(T2, BCP, BytesPerInt);
  2299   __ li(AT, -BytesPerInt);
  2300   __ andr(T2, T2, AT);
  2302   // set counter
  2303   __ lw(T3, T2, BytesPerInt);
  2304   __ swap(T3);
  2305   __ b(loop_entry);
  2306   __ delayed()->nop();
  2308   // table search
  2309   __ bind(loop);
  2310   // get the entry value
  2311   __ dsll(AT, T3, Address::times_8);
  2312   __ dadd(AT, T2, AT);
  2313   __ lw(AT, AT, 2 * BytesPerInt);
  2315   // found?
  2316   __ beq(FSR, AT, found);
  2317   __ delayed()->nop();
  2319   __ bind(loop_entry);
  2320   __ bgtz(T3, loop);
  2321   __ delayed()->daddiu(T3, T3, -1);
  2323   // default case
  2324   __ profile_switch_default(FSR);
  2325   __ lw(A7, T2, 0);
  2326   __ b(continue_execution);
  2327   __ delayed()->nop();
  2329   // entry found -> get offset
  2330   __ bind(found);
  2331   __ dsll(AT, T3, Address::times_8);
  2332   __ dadd(AT, T2, AT);
  2333   __ lw(A7, AT, 3 * BytesPerInt);
  2334   __ profile_switch_case(T3, FSR, T2);
  2336   // continue execution
  2337   __ bind(continue_execution);
  2338   __ swap(A7);
  2339   __ dadd(BCP, BCP, A7);
  2340   __ lbu(Rnext, BCP, 0);
  2341   __ dispatch_only(vtos);
  2344 // used registers : T0, T1, T2, T3, A7, Rnext
  2345 // T2 : pairs address(array)
  2346 // Rnext : dest bytecode
  2347 // the data after the opcode is the same as lookupswitch
  2348 // see Rewriter::rewrite_method for more information
  2349 void TemplateTable::fast_binaryswitch() {
  2350   transition(itos, vtos);
  2351   // Implementation using the following core algorithm:
  2352   //
  2353   // int binary_search(int key, LookupswitchPair* array, int n) {
  2354   //   // Binary search according to "Methodik des Programmierens" by
  2355   //   // Edsger W. Dijkstra and W.H.J. Feijen, Addison Wesley Germany 1985.
  2356   //   int i = 0;
  2357   //   int j = n;
  2358   //   while (i+1 < j) {
  2359   //     // invariant P: 0 <= i < j <= n and (a[i] <= key < a[j] or Q)
  2360   //     // with      Q: for all i: 0 <= i < n: key < a[i]
  2361   //     // where a stands for the array and assuming that the (inexisting)
  2362   //     // element a[n] is infinitely big.
  2363   //     int h = (i + j) >> 1;
  2364   //     // i < h < j
  2365   //     if (key < array[h].fast_match()) {
  2366   //       j = h;
  2367   //     } else {
  2368   //       i = h;
  2369   //     }
  2370   //   }
  2371   //   // R: a[i] <= key < a[i+1] or Q
  2372   //   // (i.e., if key is within array, i is the correct index)
  2373   //   return i;
  2374   // }
  2376   // register allocation
  2377   const Register array = T2;
  2378   const Register i = T3, j = A7;
  2379   const Register h = T1;
  2380   const Register temp = T0;
  2381   const Register key = FSR;
  2383   // setup array
  2384   __ daddi(array, BCP, 3*BytesPerInt);
  2385   __ li(AT, -BytesPerInt);
  2386   __ andr(array, array, AT);
  2388   // initialize i & j
  2389   __ move(i, R0);
  2390   __ lw(j, array, - 1 * BytesPerInt);
  2391   // Convert j into native byteordering
  2392   __ swap(j);
  2394   // and start
  2395   Label entry;
  2396   __ b(entry);
  2397   __ delayed()->nop();
  2399   // binary search loop
  2401     Label loop;
  2402     __ bind(loop);
  2403     // int h = (i + j) >> 1;
  2404     __ dadd(h, i, j);
  2405     __ dsrl(h, h, 1);
  2406     // if (key < array[h].fast_match()) {
  2407     //   j = h;
  2408     // } else {
  2409     //   i = h;
  2410     // }
  2411     // Convert array[h].match to native byte-ordering before compare
  2412     __ dsll(AT, h, Address::times_8);
  2413     __ dadd(AT, array, AT);
  2414     __ lw(temp, AT, 0 * BytesPerInt);
  2415     __ swap(temp);
  2418       Label set_i, end_of_if;
  2419       __ slt(AT, key, temp);
  2420       __ beq(AT, R0, set_i);
  2421       __ delayed()->nop();
  2423       __ b(end_of_if);
  2424       __ delayed(); __ move(j, h);
  2426       __ bind(set_i);
  2427       __ move(i, h);
  2429       __ bind(end_of_if);
  2431     // while (i+1 < j)
  2432     __ bind(entry);
  2433     __ daddi(h, i, 1);
  2434     __ slt(AT, h, j);
  2435     __ bne(AT, R0, loop);
  2436     __ delayed()->nop();
  2439   // end of binary search, result index is i (must check again!)
  2440   Label default_case;
  2441   // Convert array[i].match to native byte-ordering before compare
  2442   __ dsll(AT, i, Address::times_8);
  2443   __ dadd(AT, array, AT);
  2444   __ lw(temp, AT, 0 * BytesPerInt);
  2445   __ swap(temp);
  2446   __ bne(key, temp, default_case);
  2447   __ delayed()->nop();
  2449   // entry found -> j = offset
  2450   __ dsll(AT, i, Address::times_8);
  2451   __ dadd(AT, array, AT);
  2452   __ lw(j, AT, 1 * BytesPerInt);
  2453   __ profile_switch_case(i, key, array);
  2454   __ swap(j);
  2456   __ dadd(BCP, BCP, j);
  2457   __ lbu(Rnext, BCP, 0);
  2458   __ dispatch_only(vtos);
  2460   // default case -> j = default offset
  2461   __ bind(default_case);
  2462   __ profile_switch_default(i);
  2463   __ lw(j, array, - 2 * BytesPerInt);
  2464   __ swap(j);
  2465   __ dadd(BCP, BCP, j);
  2466   __ lbu(Rnext, BCP, 0);
  2467   __ dispatch_only(vtos);
  2470 void TemplateTable::_return(TosState state) {
  2471   transition(state, state);
  2472   assert(_desc->calls_vm(),
  2473       "inconsistent calls_vm information"); // call in remove_activation
  2475   if (_desc->bytecode() == Bytecodes::_return_register_finalizer) {
  2476     assert(state == vtos, "only valid state");
  2477     __ ld(T1, aaddress(0));
  2478     __ load_klass(LVP, T1);
  2479     __ lw(LVP, LVP, in_bytes(Klass::access_flags_offset()));
  2480     __ move(AT, JVM_ACC_HAS_FINALIZER);
  2481     __ andr(AT, AT, LVP);//by_css
  2482     Label skip_register_finalizer;
  2483     __ beq(AT, R0, skip_register_finalizer);
  2484     __ delayed()->nop();
  2485     __ call_VM(noreg, CAST_FROM_FN_PTR(address,
  2486     InterpreterRuntime::register_finalizer), T1);
  2487     __ bind(skip_register_finalizer);
  2489   __ remove_activation(state, T9);
  2490   __ sync();
  2492   __ jr(T9);
  2493   __ delayed()->nop();
  2496 // ----------------------------------------------------------------------------
  2497 // Volatile variables demand their effects be made known to all CPU's
  2498 // in order.  Store buffers on most chips allow reads & writes to
  2499 // reorder; the JMM's ReadAfterWrite.java test fails in -Xint mode
  2500 // without some kind of memory barrier (i.e., it's not sufficient that
  2501 // the interpreter does not reorder volatile references, the hardware
  2502 // also must not reorder them).
  2503 //
  2504 // According to the new Java Memory Model (JMM):
  2505 // (1) All volatiles are serialized wrt to each other.  ALSO reads &
  2506 //     writes act as aquire & release, so:
  2507 // (2) A read cannot let unrelated NON-volatile memory refs that
  2508 //     happen after the read float up to before the read.  It's OK for
  2509 //     non-volatile memory refs that happen before the volatile read to
  2510 //     float down below it.
  2511 // (3) Similar a volatile write cannot let unrelated NON-volatile
  2512 //     memory refs that happen BEFORE the write float down to after the
  2513 //     write.  It's OK for non-volatile memory refs that happen after the
  2514 //     volatile write to float up before it.
  2515 //
  2516 // We only put in barriers around volatile refs (they are expensive),
  2517 // not _between_ memory refs (that would require us to track the
  2518 // flavor of the previous memory refs).  Requirements (2) and (3)
  2519 // require some barriers before volatile stores and after volatile
  2520 // loads.  These nearly cover requirement (1) but miss the
  2521 // volatile-store-volatile-load case.  This final case is placed after
  2522 // volatile-stores although it could just as well go before
  2523 // volatile-loads.
  2524 //void TemplateTable::volatile_barrier(Assembler::Membar_mask_bits
  2525 //                                     order_constraint) {
  2526 void TemplateTable::volatile_barrier( ) {
  2527   // Helper function to insert a is-volatile test and memory barrier
  2528   //if (os::is_MP()) { // Not needed on single CPU
  2529   //  __ membar(order_constraint);
  2530   //}
  2531   if( !os::is_MP() ) return;  // Not needed on single CPU
  2532   __ sync();
  2535 // we dont shift left 2 bits in get_cache_and_index_at_bcp
  2536 // for we always need shift the index we use it. the ConstantPoolCacheEntry
  2537 // is 16-byte long, index is the index in
  2538 // ConstantPoolCache, so cache + base_offset() + index * 16 is
  2539 // the corresponding ConstantPoolCacheEntry
  2540 // used registers : T2
  2541 // NOTE : the returned index need also shift left 4 to get the address!
  2542 void TemplateTable::resolve_cache_and_index(int byte_no,
  2543                                             Register Rcache,
  2544                                             Register index,
  2545                                             size_t index_size) {
  2546   assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
  2547   const Register temp = A1;
  2548   assert_different_registers(Rcache, index);
  2550   Label resolved;
  2551   __ get_cache_and_index_and_bytecode_at_bcp(Rcache, index, temp, byte_no, 1, index_size);
  2552   // is resolved?
  2553   int i = (int)bytecode();
  2554   __ addi(temp, temp, -i);
  2555   __ beq(temp, R0, resolved);
  2556   __ delayed()->nop();
  2557   // resolve first time through
  2558   address entry;
  2559   switch (bytecode()) {
  2560     case Bytecodes::_getstatic      : // fall through
  2561     case Bytecodes::_putstatic      : // fall through
  2562     case Bytecodes::_getfield       : // fall through
  2563     case Bytecodes::_putfield       :
  2564       entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_get_put);
  2565       break;
  2566     case Bytecodes::_invokevirtual  : // fall through
  2567     case Bytecodes::_invokespecial  : // fall through
  2568     case Bytecodes::_invokestatic   : // fall through
  2569     case Bytecodes::_invokeinterface:
  2570       entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_invoke);
  2571       break;
  2572     case Bytecodes::_invokehandle:
  2573       entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_invokehandle);
  2574       break;
  2575     case Bytecodes::_invokedynamic:
  2576       entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_invokedynamic);
  2577       break;
  2578     default                          :
  2579       fatal(err_msg("unexpected bytecode: %s", Bytecodes::name(bytecode())));
  2580       break;
  2583   __ move(temp, i);
  2584   __ call_VM(NOREG, entry, temp);
  2586   // Update registers with resolved info
  2587   __ get_cache_and_index_at_bcp(Rcache, index, 1, index_size);
  2588   __ bind(resolved);
  2591 // The Rcache and index registers must be set before call
  2592 void TemplateTable::load_field_cp_cache_entry(Register obj,
  2593                                               Register cache,
  2594                                               Register index,
  2595                                               Register off,
  2596                                               Register flags,
  2597                                               bool is_static = false) {
  2598   assert_different_registers(cache, index, flags, off);
  2600   ByteSize cp_base_offset = ConstantPoolCache::base_offset();
  2601   // Field offset
  2602   __ dsll(AT, index, Address::times_ptr);
  2603   __ dadd(AT, cache, AT);
  2604   __ ld(off, AT, in_bytes(cp_base_offset + ConstantPoolCacheEntry::f2_offset()));
  2605   // Flags
  2606   __ ld(flags, AT, in_bytes(cp_base_offset + ConstantPoolCacheEntry::flags_offset()));
  2608   // klass overwrite register
  2609   if (is_static) {
  2610     __ ld(obj, AT, in_bytes(cp_base_offset + ConstantPoolCacheEntry::f1_offset()));
  2611     const int mirror_offset = in_bytes(Klass::java_mirror_offset());
  2612     __ ld(obj, Address(obj, mirror_offset));
  2614     __ verify_oop(obj);
  2618 // get the method, itable_index and flags of the current invoke
  2619 void TemplateTable::load_invoke_cp_cache_entry(int byte_no,
  2620                                                Register method,
  2621                                                Register itable_index,
  2622                                                Register flags,
  2623                                                bool is_invokevirtual,
  2624                                                bool is_invokevfinal, /*unused*/
  2625                                                bool is_invokedynamic) {
  2626   // setup registers
  2627   const Register cache = T3;
  2628   const Register index = T1;
  2629   assert_different_registers(method, flags);
  2630   assert_different_registers(method, cache, index);
  2631   assert_different_registers(itable_index, flags);
  2632   assert_different_registers(itable_index, cache, index);
  2633   assert(is_invokevirtual == (byte_no == f2_byte), "is invokevirtual flag redundant");
  2634   // determine constant pool cache field offsets
  2635   const int method_offset = in_bytes(
  2636     ConstantPoolCache::base_offset() +
  2637       ((byte_no == f2_byte)
  2638        ? ConstantPoolCacheEntry::f2_offset()
  2639        : ConstantPoolCacheEntry::f1_offset()));
  2640   const int flags_offset = in_bytes(ConstantPoolCache::base_offset() +
  2641                                     ConstantPoolCacheEntry::flags_offset());
  2642   // access constant pool cache fields
  2643   const int index_offset = in_bytes(ConstantPoolCache::base_offset() +
  2644                                     ConstantPoolCacheEntry::f2_offset());
  2646   size_t index_size = (is_invokedynamic ? sizeof(u4): sizeof(u2));
  2647   resolve_cache_and_index(byte_no, cache, index, index_size);
  2649   //assert(wordSize == 8, "adjust code below");
  2650   // note we shift 4 not 2, for we get is the true inde
  2651   // of ConstantPoolCacheEntry, not the shifted 2-bit index as x86 version
  2652   __ dsll(AT, index, Address::times_ptr);
  2653   __ dadd(AT, cache, AT);
  2654   __ ld(method, AT, method_offset);
  2656   if (itable_index != NOREG) {
  2657     __ ld(itable_index, AT, index_offset);
  2659   __ ld(flags, AT, flags_offset);
  2662 // The registers cache and index expected to be set before call.
  2663 // Correct values of the cache and index registers are preserved.
  2664 void TemplateTable::jvmti_post_field_access(Register cache, Register index,
  2665                                             bool is_static, bool has_tos) {
  2666   // do the JVMTI work here to avoid disturbing the register state below
  2667   // We use c_rarg registers here because we want to use the register used in
  2668   // the call to the VM
  2669   if (JvmtiExport::can_post_field_access()) {
  2670     // Check to see if a field access watch has been set before we
  2671     // take the time to call into the VM.
  2672     Label L1;
  2673     // kill FSR
  2674     Register tmp1 = T2;
  2675     Register tmp2 = T1;
  2676     Register tmp3 = T3;
  2677     assert_different_registers(cache, index, AT);
  2678     __ li(AT, (intptr_t)JvmtiExport::get_field_access_count_addr());
  2679     __ lw(AT, AT, 0);
  2680     __ beq(AT, R0, L1);
  2681     __ delayed()->nop();
  2683     __ get_cache_and_index_at_bcp(tmp2, tmp3, 1);
  2685     // cache entry pointer
  2686     __ daddi(tmp2, tmp2, in_bytes(ConstantPoolCache::base_offset()));
  2687     __ shl(tmp3, LogBytesPerWord);
  2688     __ dadd(tmp2, tmp2, tmp3);
  2689     if (is_static) {
  2690       __ move(tmp1, R0);
  2691     } else {
  2692       __ ld(tmp1, SP, 0);
  2693       __ verify_oop(tmp1);
  2695     // tmp1: object pointer or NULL
  2696     // tmp2: cache entry pointer
  2697     // tmp3: jvalue object on the stack
  2698     __ call_VM(NOREG, CAST_FROM_FN_PTR(address,
  2699                                        InterpreterRuntime::post_field_access),
  2700                tmp1, tmp2, tmp3);
  2701     __ get_cache_and_index_at_bcp(cache, index, 1);
  2702     __ bind(L1);
  2706 void TemplateTable::pop_and_check_object(Register r) {
  2707   __ pop_ptr(r);
  2708   __ null_check(r);  // for field access must check obj.
  2709   __ verify_oop(r);
  2712 // used registers : T1, T2, T3, T1
  2713 // T1 : flags
  2714 // T2 : off
  2715 // T3 : obj
  2716 // T1 : field address
  2717 // The flags 31, 30, 29, 28 together build a 4 bit number 0 to 8 with the
  2718 // following mapping to the TosState states:
  2719 // btos: 0
  2720 // ctos: 1
  2721 // stos: 2
  2722 // itos: 3
  2723 // ltos: 4
  2724 // ftos: 5
  2725 // dtos: 6
  2726 // atos: 7
  2727 // vtos: 8
  2728 // see ConstantPoolCacheEntry::set_field for more info
  2729 void TemplateTable::getfield_or_static(int byte_no, bool is_static) {
  2730   transition(vtos, vtos);
  2732   const Register cache = T3;
  2733   const Register index = T0;
  2735   const Register obj   = T3;
  2736   const Register off   = T2;
  2737   const Register flags = T1;
  2738   resolve_cache_and_index(byte_no, cache, index, sizeof(u2));
  2739   jvmti_post_field_access(cache, index, is_static, false);
  2740   load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  2742   if (!is_static) pop_and_check_object(obj);
  2743   __ dadd(index, obj, off);
  2746   Label Done, notByte, notInt, notShort, notChar,
  2747               notLong, notFloat, notObj, notDouble;
  2749   assert(btos == 0, "change code, btos != 0");
  2750   __ dsrl(flags, flags, ConstantPoolCacheEntry::tos_state_shift);
  2751   __ andi(flags, flags, 0xf);
  2752   __ bne(flags, R0, notByte);
  2753   __ delayed()->nop();
  2755   // btos
  2756   __ lb(FSR, index, 0);
  2757   __ sd(FSR, SP, - wordSize);
  2759   // Rewrite bytecode to be faster
  2760   if (!is_static) {
  2761     patch_bytecode(Bytecodes::_fast_bgetfield, T3, T2);
  2763   __ b(Done);
  2764   __ delayed()->daddi(SP, SP, - wordSize);
  2766   __ bind(notByte);
  2767   __ move(AT, itos);
  2768   __ bne(flags, AT, notInt);
  2769   __ delayed()->nop();
  2771   // itos
  2772   __ lw(FSR, index, 0);
  2773   __ sd(FSR, SP, - wordSize);
  2775   // Rewrite bytecode to be faster
  2776   if (!is_static) {
  2777     // patch_bytecode(Bytecodes::_fast_igetfield, T3, T2);
  2778     patch_bytecode(Bytecodes::_fast_igetfield, T3, T2);
  2780   __ b(Done);
  2781   __ delayed()->daddi(SP, SP, - wordSize);
  2783   __ bind(notInt);
  2784   __ move(AT, atos);
  2785   __ bne(flags, AT, notObj);
  2786   __ delayed()->nop();
  2788   // atos
  2789   //add for compressedoops
  2790   __ load_heap_oop(FSR, Address(index, 0));
  2791   __ sd(FSR, SP, - wordSize);
  2793   if (!is_static) {
  2794     //patch_bytecode(Bytecodes::_fast_agetfield, T3, T2);
  2795     patch_bytecode(Bytecodes::_fast_agetfield, T3, T2);
  2797   __ b(Done);
  2798   __ delayed()->daddi(SP, SP, - wordSize);
  2800   __ bind(notObj);
  2801   __ move(AT, ctos);
  2802   __ bne(flags, AT, notChar);
  2803   __ delayed()->nop();
  2805   // ctos
  2806   __ lhu(FSR, index, 0);
  2807   __ sd(FSR, SP, - wordSize);
  2809   if (!is_static) {
  2810     patch_bytecode(Bytecodes::_fast_cgetfield, T3, T2);
  2812   __ b(Done);
  2813   __ delayed()->daddi(SP, SP, - wordSize);
  2815   __ bind(notChar);
  2816   __ move(AT, stos);
  2817   __ bne(flags, AT, notShort);
  2818   __ delayed()->nop();
  2820   // stos
  2821   __ lh(FSR, index, 0);
  2822   __ sd(FSR, SP, - wordSize);
  2824   if (!is_static) {
  2825     patch_bytecode(Bytecodes::_fast_sgetfield, T3, T2);
  2827   __ b(Done);
  2828   __ delayed()->daddi(SP, SP, - wordSize);
  2830   __ bind(notShort);
  2831   __ move(AT, ltos);
  2832   __ bne(flags, AT, notLong);
  2833   __ delayed()->nop();
  2835   // FIXME : the load/store should be atomic, we have no simple method to do this in mips32
  2836   // ltos
  2837   __ ld(FSR, index, 0 * wordSize);
  2838   __ sd(FSR, SP, -2 * wordSize);
  2839   __ sd(R0, SP, -1 * wordSize);
  2841   // Don't rewrite to _fast_lgetfield for potential volatile case.
  2842   __ b(Done);
  2843   __ delayed()->daddi(SP, SP, - 2 * wordSize);
  2845   __ bind(notLong);
  2846   __ move(AT, ftos);
  2847   __ bne(flags, AT, notFloat);
  2848   __ delayed()->nop();
  2850   // ftos
  2851   __ lwc1(FSF, index, 0);
  2852   __ sdc1(FSF, SP, - wordSize);
  2854   if (!is_static) {
  2855     patch_bytecode(Bytecodes::_fast_fgetfield, T3, T2);
  2857   __ b(Done);
  2858   __ delayed()->daddi(SP, SP, - wordSize);
  2860   __ bind(notFloat);
  2861   __ move(AT, dtos);
  2862   __ bne(flags, AT, notDouble);
  2863   __ delayed()->nop();
  2865   // dtos
  2866   __ ldc1(FSF, index, 0 * wordSize);
  2867   __ sdc1(FSF, SP, - 2 * wordSize);
  2868   __ sd(R0, SP, - 1 * wordSize);
  2870   if (!is_static) {
  2871     patch_bytecode(Bytecodes::_fast_dgetfield, T3, T2);
  2873   __ b(Done);
  2874   __ delayed()->daddi(SP, SP, - 2 * wordSize);
  2876   __ bind(notDouble);
  2878   __ stop("Bad state");
  2880   __ bind(Done);
  2884 void TemplateTable::getfield(int byte_no) {
  2885   getfield_or_static(byte_no, false);
  2888 void TemplateTable::getstatic(int byte_no) {
  2889   getfield_or_static(byte_no, true);
  2892 // The registers cache and index expected to be set before call.
  2893 // The function may destroy various registers, just not the cache and index registers.
  2894 void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
  2895   transition(vtos, vtos);
  2897   ByteSize cp_base_offset = ConstantPoolCache::base_offset();
  2899   if (JvmtiExport::can_post_field_modification()) {
  2900     // Check to see if a field modification watch has been set before
  2901     // we take the time to call into the VM.
  2902     Label L1;
  2903     //kill AT, T1, T2, T3, T9
  2904     Register tmp1 = T2;
  2905     Register tmp2 = T1;
  2906     Register tmp3 = T3;
  2907     Register tmp4 = T9;
  2908     assert_different_registers(cache, index, tmp4);
  2910     __ li(AT, JvmtiExport::get_field_modification_count_addr());
  2911     __ lw(AT, AT, 0);
  2912     __ beq(AT, R0, L1);
  2913     __ delayed()->nop();
  2915     __ get_cache_and_index_at_bcp(tmp2, tmp4, 1);
  2917     if (is_static) {
  2918       __ move(tmp1, R0);
  2919     } else {
  2920       // Life is harder. The stack holds the value on top, followed by
  2921       // the object.  We don't know the size of the value, though; it
  2922       // could be one or two words depending on its type. As a result,
  2923       // we must find the type to determine where the object is.
  2924       Label two_word, valsize_known;
  2925       __ dsll(AT, tmp4, Address::times_8);
  2926       __ dadd(AT, tmp2, AT);
  2927       __ ld(tmp3, AT, in_bytes(cp_base_offset +
  2928                                ConstantPoolCacheEntry::flags_offset()));
  2929       __ shr(tmp3, ConstantPoolCacheEntry::tos_state_shift);
  2931       // Make sure we don't need to mask ecx for tos_state_shift
  2932       // after the above shift
  2933       ConstantPoolCacheEntry::verify_tos_state_shift();
  2934       __ move(tmp1, SP);
  2935       __ move(AT, ltos);
  2936       __ beq(tmp3, AT, two_word);
  2937       __ delayed()->nop();
  2938       __ move(AT, dtos);
  2939       __ beq(tmp3, AT, two_word);
  2940       __ delayed()->nop();
  2941       __ b(valsize_known);
  2942       __ delayed()->daddi(tmp1, tmp1, Interpreter::expr_offset_in_bytes(1) );
  2944       __ bind(two_word);
  2945       __ daddi(tmp1, tmp1, Interpreter::expr_offset_in_bytes(2));
  2947       __ bind(valsize_known);
  2948       // setup object pointer
  2949       __ ld(tmp1, tmp1, 0*wordSize);
  2951     // cache entry pointer
  2952     __ daddi(tmp2, tmp2, in_bytes(cp_base_offset));
  2953     __ shl(tmp4, LogBytesPerWord);
  2954     __ daddu(tmp2, tmp2, tmp4);
  2955     // object (tos)
  2956     __ move(tmp3, SP);
  2957     // tmp1: object pointer set up above (NULL if static)
  2958     // tmp2: cache entry pointer
  2959     // tmp3: jvalue object on the stack
  2960     __ call_VM(NOREG,
  2961                CAST_FROM_FN_PTR(address,
  2962                                 InterpreterRuntime::post_field_modification),
  2963                tmp1, tmp2, tmp3);
  2964     __ get_cache_and_index_at_bcp(cache, index, 1);
  2965     __ bind(L1);
  2969 // used registers : T0, T1, T2, T3, T8
  2970 // T1 : flags
  2971 // T2 : off
  2972 // T3 : obj
  2973 // T8 : volatile bit
  2974 // see ConstantPoolCacheEntry::set_field for more info
  2975 void TemplateTable::putfield_or_static(int byte_no, bool is_static) {
  2976   transition(vtos, vtos);
  2978   const Register cache = T3;
  2979   const Register index = T0;
  2980   const Register obj   = T3;
  2981   const Register off   = T2;
  2982   const Register flags = T1;
  2983   const Register bc    = T3;
  2985   resolve_cache_and_index(byte_no, cache, index, sizeof(u2));
  2986   jvmti_post_field_mod(cache, index, is_static);
  2987   load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  2989   Label notVolatile, Done;
  2990   __ move(AT, 1<<ConstantPoolCacheEntry::is_volatile_shift);
  2991   __ andr(T8, flags, AT);
  2993   Label notByte, notInt, notShort, notChar, notLong, notFloat, notObj, notDouble;
  2995   assert(btos == 0, "change code, btos != 0");
  2996   // btos
  2997   __ dsrl(flags, flags, ConstantPoolCacheEntry::tos_state_shift);
  2998   __ andi(flags, flags, ConstantPoolCacheEntry::tos_state_mask);
  2999   __ bne(flags, R0, notByte);
  3000   __ delayed()->nop();
  3002   __ pop(btos);
  3003   if (!is_static) {
  3004     pop_and_check_object(obj);
  3006   __ dadd(AT, obj, off);
  3007   __ sb(FSR, AT, 0);
  3009   if (!is_static) {
  3010     patch_bytecode(Bytecodes::_fast_bputfield, bc, off, true, byte_no);
  3012   __ b(Done);
  3013   __ delayed()->nop();
  3015   __ bind(notByte);
  3016   // itos
  3017   __ move(AT, itos);
  3018   __ bne(flags, AT, notInt);
  3019   __ delayed()->nop();
  3021   __ pop(itos);
  3022   if (!is_static) {
  3023     pop_and_check_object(obj);
  3025   __ dadd(AT, obj, off);
  3026   __ sw(FSR, AT, 0);
  3028   if (!is_static) {
  3029     patch_bytecode(Bytecodes::_fast_iputfield, bc, off, true, byte_no);
  3031   __ b(Done);
  3032   __ delayed()->nop();
  3033   __ bind(notInt);
  3034   // atos
  3035   __ move(AT, atos);
  3036   __ bne(flags, AT, notObj);
  3037   __ delayed()->nop();
  3039   __ pop(atos);
  3040   if (!is_static) {
  3041     pop_and_check_object(obj);
  3044   __ dadd(AT, obj, off);
  3045   __ store_heap_oop(Address(AT, 0), FSR);
  3046   __ store_check(obj);
  3048   if (!is_static) {
  3049     patch_bytecode(Bytecodes::_fast_aputfield, bc, off, true, byte_no);
  3051   __ b(Done);
  3052   __ delayed()->nop();
  3053   __ bind(notObj);
  3054   // ctos
  3055   __ move(AT, ctos);
  3056   __ bne(flags, AT, notChar);
  3057   __ delayed()->nop();
  3059   __ pop(ctos);
  3060   if (!is_static) {
  3061     pop_and_check_object(obj);
  3063   __ dadd(AT, obj, off);
  3064   __ sh(FSR, AT, 0);
  3065   if (!is_static) {
  3066     patch_bytecode(Bytecodes::_fast_cputfield, bc, off, true, byte_no);
  3068   __ b(Done);
  3069   __ delayed()->nop();
  3070   __ bind(notChar);
  3071   // stos
  3072   __ move(AT, stos);
  3073   __ bne(flags, AT, notShort);
  3074   __ delayed()->nop();
  3076   __ pop(stos);
  3077   if (!is_static) {
  3078     pop_and_check_object(obj);
  3080   __ dadd(AT, obj, off);
  3081   __ sh(FSR, AT, 0);
  3082   if (!is_static) {
  3083     patch_bytecode(Bytecodes::_fast_sputfield, bc, off, true, byte_no);
  3085   __ b(Done);
  3086   __ delayed()->nop();
  3087   __ bind(notShort);
  3088   // ltos
  3089   __ move(AT, ltos);
  3090   __ bne(flags, AT, notLong);
  3091   __ delayed()->nop();
  3093   // FIXME: there is no simple method to load/store 64-bit data in a atomic operation
  3094   // we just ignore the volatile flag.
  3095   //Label notVolatileLong;
  3096   //__ beq(T1, R0, notVolatileLong);
  3097   //__ delayed()->nop();
  3099   //addent = 2 * wordSize;
  3100   // no need
  3101   //__ lw(FSR, SP, 0);
  3102   //__ lw(SSR, SP, 1 * wordSize);
  3103   //if (!is_static) {
  3104   //  __ lw(T3, SP, addent);
  3105   //  addent += 1 * wordSize;
  3106   //  __ verify_oop(T3);
  3107   //}
  3109   //__ daddu(AT, T3, T2);
  3111   // Replace with real volatile test
  3112   // NOTE : we assume that sdc1&ldc1 operate in 32-bit, this is true for Godson2 even in 64-bit kernel
  3113   // last modified by yjl 7/12/2005
  3114   //__ ldc1(FSF, SP, 0);
  3115   //__ sdc1(FSF, AT, 0);
  3116   //volatile_barrier();
  3118   // Don't rewrite volatile version
  3119   //__ b(notVolatile);
  3120   //__ delayed()->addiu(SP, SP, addent);
  3122   //__ bind(notVolatileLong);
  3124   //__ pop(ltos);  // overwrites edx
  3125   //  __ lw(FSR, SP, 0 * wordSize);
  3126   //  __ lw(SSR, SP, 1 * wordSize);
  3127   //  __ daddi(SP, SP, 2*wordSize);
  3128   __ pop(ltos);
  3129   if (!is_static) {
  3130     pop_and_check_object(obj);
  3132   __ dadd(AT, obj, off);
  3133   __ sd(FSR, AT, 0);
  3134   if (!is_static) {
  3135     patch_bytecode(Bytecodes::_fast_lputfield, bc, off, true, byte_no);
  3137   __ b(notVolatile);
  3138   __ delayed()->nop();
  3140   __ bind(notLong);
  3141   // ftos
  3142   __ move(AT, ftos);
  3143   __ bne(flags, AT, notFloat);
  3144   __ delayed()->nop();
  3146   __ pop(ftos);
  3147   if (!is_static) {
  3148     pop_and_check_object(obj);
  3150   __ dadd(AT, obj, off);
  3151   __ swc1(FSF, AT, 0);
  3152   if (!is_static) {
  3153     patch_bytecode(Bytecodes::_fast_fputfield, bc, off, true, byte_no);
  3155   __ b(Done);
  3156   __ delayed()->nop();
  3157   __ bind(notFloat);
  3158   // dtos
  3159   __ move(AT, dtos);
  3160   __ bne(flags, AT, notDouble);
  3161   __ delayed()->nop();
  3163   __ pop(dtos);
  3164   if (!is_static) {
  3165     pop_and_check_object(obj);
  3167   __ dadd(AT, obj, off);
  3168   __ sdc1(FSF, AT, 0);
  3169   if (!is_static) {
  3170     patch_bytecode(Bytecodes::_fast_dputfield, bc, off, true, byte_no);
  3173 #ifdef ASSERT
  3174   __ b(Done);
  3175   __ delayed()->nop();
  3177   __ bind(notDouble);
  3178   __ stop("Bad state");
  3179 #endif
  3181   __ bind(Done);
  3183   // Check for volatile store
  3184   __ beq(T8, R0, notVolatile);
  3185   __ delayed()->nop();
  3186   volatile_barrier( );
  3187   __ bind(notVolatile);
  3190 void TemplateTable::putfield(int byte_no) {
  3191   putfield_or_static(byte_no, false);
  3194 void TemplateTable::putstatic(int byte_no) {
  3195   putfield_or_static(byte_no, true);
  3198 // used registers : T1, T2, T3
  3199 // T1 : cp_entry
  3200 // T2 : obj
  3201 // T3 : value pointer
  3202 void TemplateTable::jvmti_post_fast_field_mod() {
  3203   if (JvmtiExport::can_post_field_modification()) {
  3204     // Check to see if a field modification watch has been set before
  3205     // we take the time to call into the VM.
  3206     Label L2;
  3207     //kill AT, T1, T2, T3, T9
  3208     Register tmp1 = T2;
  3209     Register tmp2 = T1;
  3210     Register tmp3 = T3;
  3211     Register tmp4 = T9;
  3212     __ li(AT, JvmtiExport::get_field_modification_count_addr());
  3213     __ lw(tmp3, AT, 0);
  3214     __ beq(tmp3, R0, L2);
  3215     __ delayed()->nop();
  3216     __ pop_ptr(tmp1);
  3217     __ verify_oop(tmp1);
  3218     __ push_ptr(tmp1);
  3219     switch (bytecode()) {          // load values into the jvalue object
  3220     case Bytecodes::_fast_aputfield: __ push_ptr(FSR); break;
  3221     case Bytecodes::_fast_bputfield: // fall through
  3222     case Bytecodes::_fast_sputfield: // fall through
  3223     case Bytecodes::_fast_cputfield: // fall through
  3224     case Bytecodes::_fast_iputfield: __ push_i(FSR); break;
  3225     case Bytecodes::_fast_dputfield: __ push_d(FSF); break;
  3226     case Bytecodes::_fast_fputfield: __ push_f(); break;
  3227     case Bytecodes::_fast_lputfield: __ push_l(FSR); break;
  3228       default:  ShouldNotReachHere();
  3230     __ move(tmp3, SP);
  3231     // access constant pool cache entry
  3232     __ get_cache_entry_pointer_at_bcp(tmp2, FSR, 1);
  3233     __ verify_oop(tmp1);
  3234     // tmp1: object pointer copied above
  3235     // tmp2: cache entry pointer
  3236     // tmp3: jvalue object on the stack
  3237     __ call_VM(NOREG,
  3238                CAST_FROM_FN_PTR(address,
  3239                                 InterpreterRuntime::post_field_modification),
  3240                tmp1, tmp2, tmp3);
  3242     switch (bytecode()) {             // restore tos values
  3243     case Bytecodes::_fast_aputfield: __ pop_ptr(FSR); break;
  3244     case Bytecodes::_fast_bputfield: // fall through
  3245     case Bytecodes::_fast_sputfield: // fall through
  3246     case Bytecodes::_fast_cputfield: // fall through
  3247     case Bytecodes::_fast_iputfield: __ pop_i(FSR); break;
  3248     case Bytecodes::_fast_dputfield: __ pop_d(); break;
  3249     case Bytecodes::_fast_fputfield: __ pop_f(); break;
  3250     case Bytecodes::_fast_lputfield: __ pop_l(FSR); break;
  3252     __ bind(L2);
  3256 // used registers : T2, T3, T1
  3257 // T2 : index & off & field address
  3258 // T3 : cache & obj
  3259 // T1 : flags
  3260 void TemplateTable::fast_storefield(TosState state) {
  3261   transition(state, vtos);
  3263   ByteSize base = ConstantPoolCache::base_offset();
  3265   jvmti_post_fast_field_mod();
  3267   // access constant pool cache
  3268   __ get_cache_and_index_at_bcp(T3, T2, 1);
  3270   // test for volatile with edx but edx is tos register for lputfield.
  3271   __ dsll(AT, T2, Address::times_8);
  3272   __ dadd(AT, T3, AT);
  3273   __ ld(T1, AT, in_bytes(base + ConstantPoolCacheEntry::flags_offset()));
  3275   // replace index with field offset from cache entry
  3276   __ ld(T2, AT, in_bytes(base + ConstantPoolCacheEntry::f2_offset()));
  3278   // Doug Lea believes this is not needed with current Sparcs (TSO) and Intel (PSO).
  3279   // volatile_barrier( );
  3281   Label notVolatile, Done;
  3282   // Check for volatile store
  3283   __ move(AT, 1<<ConstantPoolCacheEntry::is_volatile_shift);
  3284   __ andr(AT, T1, AT);
  3285   __ beq(AT, R0, notVolatile);
  3286   __ delayed()->nop();
  3289   // Get object from stack
  3290   pop_and_check_object(T3);
  3292   // field address
  3293   __ dadd(T2, T3, T2);
  3295   // access field
  3296   switch (bytecode()) {
  3297     case Bytecodes::_fast_bputfield:
  3298       __ sb(FSR, T2, 0);
  3299       break;
  3300     case Bytecodes::_fast_sputfield: // fall through
  3301     case Bytecodes::_fast_cputfield:
  3302       __ sh(FSR, T2, 0);
  3303       break;
  3304     case Bytecodes::_fast_iputfield:
  3305       __ sw(FSR, T2, 0);
  3306       break;
  3307     case Bytecodes::_fast_lputfield:
  3308       __ sd(FSR, T2, 0 * wordSize);
  3309       break;
  3310     case Bytecodes::_fast_fputfield:
  3311       __ swc1(FSF, T2, 0);
  3312       break;
  3313     case Bytecodes::_fast_dputfield:
  3314       __ sdc1(FSF, T2, 0 * wordSize);
  3315       break;
  3316     case Bytecodes::_fast_aputfield:
  3317       __ store_heap_oop(Address(T2, 0), FSR);
  3318       __ store_check(T3);
  3319       break;
  3320     default:
  3321       ShouldNotReachHere();
  3324   Label done;
  3325   volatile_barrier( );
  3326   __ b(done);
  3327   __ delayed()->nop();
  3329   // Same code as above, but don't need edx to test for volatile.
  3330   __ bind(notVolatile);
  3331   pop_and_check_object(T3);
  3332   //get the field address
  3333   __ dadd(T2, T3, T2);
  3335   // access field
  3336   switch (bytecode()) {
  3337     case Bytecodes::_fast_bputfield:
  3338       __ sb(FSR, T2, 0);
  3339       break;
  3340     case Bytecodes::_fast_sputfield: // fall through
  3341     case Bytecodes::_fast_cputfield:
  3342       __ sh(FSR, T2, 0);
  3343       break;
  3344     case Bytecodes::_fast_iputfield:
  3345       __ sw(FSR, T2, 0);
  3346       break;
  3347     case Bytecodes::_fast_lputfield:
  3348       __ sd(FSR, T2, 0 * wordSize);
  3349       break;
  3350     case Bytecodes::_fast_fputfield:
  3351       __ swc1(FSF, T2, 0);
  3352       break;
  3353     case Bytecodes::_fast_dputfield:
  3354       __ sdc1(FSF, T2, 0 * wordSize);
  3355       break;
  3356     case Bytecodes::_fast_aputfield:
  3357       //add for compressedoops
  3358       __ store_heap_oop(Address(T2, 0), FSR);
  3359       __ store_check(T3);
  3360       break;
  3361     default:
  3362       ShouldNotReachHere();
  3364   __ bind(done);
  3367 // used registers : T2, T3, T1
  3368 // T3 : cp_entry & cache
  3369 // T2 : index & offset
  3370 void TemplateTable::fast_accessfield(TosState state) {
  3371   transition(atos, state);
  3373   // do the JVMTI work here to avoid disturbing the register state below
  3374   if (JvmtiExport::can_post_field_access()) {
  3375     // Check to see if a field access watch has been set before we take
  3376     // the time to call into the VM.
  3377     Label L1;
  3378     __ li(AT, (intptr_t)JvmtiExport::get_field_access_count_addr());
  3379     __ lw(T3, AT, 0);
  3380     __ beq(T3, R0, L1);
  3381     __ delayed()->nop();
  3382     // access constant pool cache entry
  3383     __ get_cache_entry_pointer_at_bcp(T3, T1, 1);
  3384     __ move(TSR, FSR);
  3385     __ verify_oop(FSR);
  3386     // FSR: object pointer copied above
  3387     // T3: cache entry pointer
  3388     __ call_VM(NOREG,
  3389                CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access),
  3390                FSR, T3);
  3391     __ move(FSR, TSR);
  3392     __ bind(L1);
  3395   // access constant pool cache
  3396   __ get_cache_and_index_at_bcp(T3, T2, 1);
  3397   // replace index with field offset from cache entry
  3398   __ dsll(AT, T2, Address::times_8);
  3399   __ dadd(AT, T3, AT);
  3400   __ ld(T2, AT, in_bytes(ConstantPoolCache::base_offset()
  3401                          + ConstantPoolCacheEntry::f2_offset()));
  3403   // eax: object
  3404   __ verify_oop(FSR);
  3405   __ null_check(FSR);
  3406   // field addresses
  3407   __ dadd(FSR, FSR, T2);
  3409   // access field
  3410   switch (bytecode()) {
  3411     case Bytecodes::_fast_bgetfield:
  3412       __ lb(FSR, FSR, 0);
  3413       break;
  3414     case Bytecodes::_fast_sgetfield:
  3415       __ lh(FSR, FSR, 0);
  3416       break;
  3417     case Bytecodes::_fast_cgetfield:
  3418       __ lhu(FSR, FSR, 0);
  3419       break;
  3420     case Bytecodes::_fast_igetfield:
  3421       __ lw(FSR, FSR, 0);
  3422       break;
  3423     case Bytecodes::_fast_lgetfield:
  3424       __ stop("should not be rewritten");
  3425       break;
  3426     case Bytecodes::_fast_fgetfield:
  3427       __ lwc1(FSF, FSR, 0);
  3428       break;
  3429     case Bytecodes::_fast_dgetfield:
  3430       __ ldc1(FSF, FSR, 0);
  3431       break;
  3432     case Bytecodes::_fast_agetfield:
  3433       //add for compressedoops
  3434       __ load_heap_oop(FSR, Address(FSR, 0));
  3435       __ verify_oop(FSR);
  3436       break;
  3437     default:
  3438       ShouldNotReachHere();
  3441   // Doug Lea believes this is not needed with current Sparcs(TSO) and Intel(PSO)
  3442   // volatile_barrier( );
  3445 // generator for _fast_iaccess_0, _fast_aaccess_0, _fast_faccess_0
  3446 // used registers : T1, T2, T3, T1
  3447 // T1 : obj & field address
  3448 // T2 : off
  3449 // T3 : cache
  3450 // T1 : index
  3451 void TemplateTable::fast_xaccess(TosState state) {
  3452   transition(vtos, state);
  3454   // get receiver
  3455   __ ld(T1, aaddress(0));
  3456   // access constant pool cache
  3457   __ get_cache_and_index_at_bcp(T3, T2, 2);
  3458   __ dsll(AT, T2, Address::times_8);
  3459   __ dadd(AT, T3, AT);
  3460   __ ld(T2, AT, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::f2_offset()));
  3462   // make sure exception is reported in correct bcp range (getfield is
  3463   // next instruction)
  3464   __ daddi(BCP, BCP, 1);
  3465   __ null_check(T1);
  3466   __ dadd(T1, T1, T2);
  3468   if (state == itos) {
  3469     __ lw(FSR, T1, 0);
  3470   } else if (state == atos) {
  3471     __ load_heap_oop(FSR, Address(T1, 0));
  3472     __ verify_oop(FSR);
  3473   } else if (state == ftos) {
  3474     __ lwc1(FSF, T1, 0);
  3475   } else {
  3476     ShouldNotReachHere();
  3478   __ daddi(BCP, BCP, -1);
  3483 //-----------------------------------------------------------------------------
  3484 // Calls
  3486 void TemplateTable::count_calls(Register method, Register temp) {
  3487   // implemented elsewhere
  3488   ShouldNotReachHere();
  3491 // method, index, recv, flags: T1, T2, T3, T1
  3492 // byte_no = 2 for _invokevirtual, 1 else
  3493 // T0 : return address
  3494 // get the method & index of the invoke, and push the return address of
  3495 // the invoke(first word in the frame)
  3496 // this address is where the return code jmp to.
  3497 // NOTE : this method will set T3&T1 as recv&flags
  3498 void TemplateTable::prepare_invoke(int byte_no,
  3499                                    Register method,  // linked method (or i-klass)
  3500                                    Register index,   // itable index, MethodType, etc.
  3501                                    Register recv,    // if caller wants to see it
  3502                                    Register flags    // if caller wants to test it
  3503                                    ) {
  3504   // determine flags
  3505   const Bytecodes::Code code = bytecode();
  3506   const bool is_invokeinterface  = code == Bytecodes::_invokeinterface;
  3507   const bool is_invokedynamic    = code == Bytecodes::_invokedynamic;
  3508   const bool is_invokehandle     = code == Bytecodes::_invokehandle;
  3509   const bool is_invokevirtual    = code == Bytecodes::_invokevirtual;
  3510   const bool is_invokespecial    = code == Bytecodes::_invokespecial;
  3511   const bool load_receiver       = (recv  != noreg);
  3512   const bool save_flags          = (flags != noreg);
  3513   assert(load_receiver == (code != Bytecodes::_invokestatic && code != Bytecodes::_invokedynamic),"");
  3514   assert(save_flags    == (is_invokeinterface || is_invokevirtual), "need flags for vfinal");
  3515   assert(flags == noreg || flags == T1, "error flags reg.");
  3516   assert(recv  == noreg || recv  == T3, "error recv reg.");
  3518   // setup registers & access constant pool cache
  3519   if(recv == noreg) recv  = T3;
  3520   if(flags == noreg) flags  = T1;
  3521   assert_different_registers(method, index, recv, flags);
  3523   // save 'interpreter return address'
  3524   __ save_bcp();
  3526   load_invoke_cp_cache_entry(byte_no, method, index, flags, is_invokevirtual, false, is_invokedynamic);
  3528   if (is_invokedynamic || is_invokehandle) {
  3529    Label L_no_push;
  3530      __ move(AT, (1 << ConstantPoolCacheEntry::has_appendix_shift));
  3531      __ andr(AT, AT, flags);
  3532      __ beq(AT, R0, L_no_push);
  3533      __ delayed()->nop();
  3534      // Push the appendix as a trailing parameter.
  3535      // This must be done before we get the receiver,
  3536      // since the parameter_size includes it.
  3537      Register tmp = SSR;
  3538      __ push(tmp);
  3539      __ move(tmp, index);
  3540      assert(ConstantPoolCacheEntry::_indy_resolved_references_appendix_offset == 0, "appendix expected at index+0");
  3541      __ load_resolved_reference_at_index(index, tmp);
  3542      __ pop(tmp);
  3543      __ push(index);  // push appendix (MethodType, CallSite, etc.)
  3544      __ bind(L_no_push);
  3547   // load receiver if needed (after appendix is pushed so parameter size is correct)
  3548   // Note: no return address pushed yet
  3549   if (load_receiver) {
  3550     __ move(AT, ConstantPoolCacheEntry::parameter_size_mask);
  3551     __ andr(recv, flags, AT);
  3552     // 2014/07/31 Fu: Since we won't push RA on stack, no_return_pc_pushed_yet should be 0.
  3553     const int no_return_pc_pushed_yet = 0;  // argument slot correction before we push return address
  3554     const int receiver_is_at_end      = -1;  // back off one slot to get receiver
  3555     Address recv_addr = __ argument_address(recv, no_return_pc_pushed_yet + receiver_is_at_end);
  3556     __ ld(recv, recv_addr);
  3557     __ verify_oop(recv);
  3559   if(save_flags) {
  3560     __ move(BCP, flags);
  3563   // compute return type
  3564   __ dsrl(flags, flags, ConstantPoolCacheEntry::tos_state_shift);
  3565   __ andi(flags, flags, 0xf);
  3567   // Make sure we don't need to mask flags for tos_state_shift after the above shift
  3568   ConstantPoolCacheEntry::verify_tos_state_shift();
  3569   // load return address
  3571     const address table = (address) Interpreter::invoke_return_entry_table_for(code);
  3572     __ li(AT, (long)table);
  3573     __ dsll(flags, flags, LogBytesPerWord);
  3574     __ dadd(AT, AT, flags);
  3575     __ ld(RA, AT, 0);
  3578   if (save_flags) {
  3579     __ move(flags, BCP);
  3580     __ restore_bcp();
  3584 // used registers : T0, T3, T1, T2
  3585 // T3 : recv, this two register using convention is by prepare_invoke
  3586 // T1 : flags, klass
  3587 // Rmethod : method, index must be Rmethod
  3588 void TemplateTable::invokevirtual_helper(Register index,
  3589                                          Register recv,
  3590                                          Register flags) {
  3592   assert_different_registers(index, recv, flags, T2);
  3594   // Test for an invoke of a final method
  3595   Label notFinal;
  3596   __ move(AT, (1 << ConstantPoolCacheEntry::is_vfinal_shift));
  3597   __ andr(AT, flags, AT);
  3598   __ beq(AT, R0, notFinal);
  3599   __ delayed()->nop();
  3601   Register method = index;  // method must be Rmethod
  3602   assert(method == Rmethod, "methodOop must be Rmethod for interpreter calling convention");
  3604   // do the call - the index is actually the method to call
  3605   // the index is indeed methodOop, for this is vfinal,
  3606   // see ConstantPoolCacheEntry::set_method for more info
  3608   __ verify_oop(method);
  3610   // It's final, need a null check here!
  3611   __ null_check(recv);
  3613   // profile this call
  3614   __ profile_final_call(T2);
  3616   // 2014/11/24 Fu
  3617   // T2: tmp, used for mdp
  3618   // method: callee
  3619   // T9: tmp
  3620   // is_virtual: true
  3621   __ profile_arguments_type(T2, method, T9, true);
  3623   __ jump_from_interpreted(method, T2);
  3625   __ bind(notFinal);
  3627   // get receiver klass
  3628   __ null_check(recv, oopDesc::klass_offset_in_bytes());
  3629   __ load_klass(T2, recv);
  3630   __ verify_oop(T2);
  3632   // profile this call
  3633   __ profile_virtual_call(T2, T0, T1);
  3635   // get target methodOop & entry point
  3636   const int base = InstanceKlass::vtable_start_offset() * wordSize;
  3637   assert(vtableEntry::size() * wordSize == wordSize, "adjust the scaling in the code below");
  3638   __ dsll(AT, index, Address::times_ptr);
  3639   // T2: receiver
  3640   __ dadd(AT, T2, AT);
  3641   //this is a ualign read
  3642   __ ld(method, AT, base + vtableEntry::method_offset_in_bytes());
  3643   __ profile_arguments_type(T2, method, T9, true);
  3644   __ jump_from_interpreted(method, T2);
  3648 void TemplateTable::invokevirtual(int byte_no) {
  3649   transition(vtos, vtos);
  3650   assert(byte_no == f2_byte, "use this argument");
  3651   prepare_invoke(byte_no, Rmethod, NOREG, T3, T1);
  3652   // now recv & flags in T3, T1
  3653   invokevirtual_helper(Rmethod, T3, T1);
  3656 // T9 : entry
  3657 // Rmethod : method
  3658 void TemplateTable::invokespecial(int byte_no) {
  3659   transition(vtos, vtos);
  3660   assert(byte_no == f1_byte, "use this argument");
  3661   prepare_invoke(byte_no, Rmethod, NOREG, T3);
  3662   // now recv & flags in T3, T1
  3663   __ verify_oop(T3);
  3664   __ null_check(T3);
  3665   __ profile_call(T9);
  3667   // 2014/11/24 Fu
  3668   // T8: tmp, used for mdp
  3669   // Rmethod: callee
  3670   // T9: tmp
  3671   // is_virtual: false
  3672   __ profile_arguments_type(T8, Rmethod, T9, false);
  3674   __ jump_from_interpreted(Rmethod, T9);
  3675   __ move(T0, T3);//aoqi ?
  3678 void TemplateTable::invokestatic(int byte_no) {
  3679   transition(vtos, vtos);
  3680   assert(byte_no == f1_byte, "use this argument");
  3681   prepare_invoke(byte_no, Rmethod, NOREG);
  3682   __ verify_oop(Rmethod);
  3684   __ profile_call(T9);
  3686   // 2014/11/24 Fu
  3687   // T8: tmp, used for mdp
  3688   // Rmethod: callee
  3689   // T9: tmp
  3690   // is_virtual: false
  3691   __ profile_arguments_type(T8, Rmethod, T9, false);
  3693   __ jump_from_interpreted(Rmethod, T9);
  3696 // i have no idea what to do here, now. for future change. FIXME.
  3697 void TemplateTable::fast_invokevfinal(int byte_no) {
  3698   transition(vtos, vtos);
  3699   assert(byte_no == f2_byte, "use this argument");
  3700   __ stop("fast_invokevfinal not used on mips64");
  3703 // used registers : T0, T1, T2, T3, T1, A7
  3704 // T0 : itable, vtable, entry
  3705 // T1 : interface
  3706 // T3 : receiver
  3707 // T1 : flags, klass
  3708 // Rmethod : index, method, this is required by interpreter_entry
  3709 void TemplateTable::invokeinterface(int byte_no) {
  3710   transition(vtos, vtos);
  3711   //this method will use T1-T4 and T0
  3712   assert(byte_no == f1_byte, "use this argument");
  3713   prepare_invoke(byte_no, T2, Rmethod, T3, T1);
  3714   // T2: Interface
  3715   // Rmethod: index
  3716   // T3: receiver
  3717   // T1: flags
  3719   // Special case of invokeinterface called for virtual method of
  3720   // java.lang.Object.  See cpCacheOop.cpp for details.
  3721   // This code isn't produced by javac, but could be produced by
  3722   // another compliant java compiler.
  3723   Label notMethod;
  3724   __ move(AT, (1 << ConstantPoolCacheEntry::is_forced_virtual_shift));
  3725   __ andr(AT, T1, AT);
  3726   __ beq(AT, R0, notMethod);
  3727   __ delayed()->nop();
  3729   invokevirtual_helper(Rmethod, T3, T1);
  3730   __ bind(notMethod);
  3731   // Get receiver klass into T1 - also a null check
  3732   //add for compressedoops
  3733   __ load_klass(T1, T3);
  3734   __ verify_oop(T1);
  3736   // profile this call
  3737   __ profile_virtual_call(T1, T0, FSR);
  3739   // Compute start of first itableOffsetEntry (which is at the end of the vtable)
  3740   // TODO: x86 add a new method lookup_interface_method  // LEE
  3741   const int base = InstanceKlass::vtable_start_offset() * wordSize;
  3742   assert(vtableEntry::size() * wordSize == 8, "adjust the scaling in the code below");
  3743   __ lw(AT, T1, InstanceKlass::vtable_length_offset() * wordSize);
  3744   __ dsll(AT, AT, Address::times_8);
  3745   __ dadd(T0, T1, AT);
  3746   __ daddi(T0, T0, base);
  3747   if (HeapWordsPerLong > 1) {
  3748     // Round up to align_object_offset boundary
  3749     __ round_to(T0, BytesPerLong);
  3751   // now T0 is the begin of the itable
  3753   Label entry, search, interface_ok;
  3755   ///__ jmp(entry);
  3756   __ b(entry);
  3757   __ delayed()->nop();
  3759   __ bind(search);
  3760   __ increment(T0, itableOffsetEntry::size() * wordSize);
  3762   __ bind(entry);
  3764   // Check that the entry is non-null.  A null entry means that the receiver
  3765   // class doesn't implement the interface, and wasn't the same as the
  3766   // receiver class checked when the interface was resolved.
  3767   __ ld(AT, T0, itableOffsetEntry::interface_offset_in_bytes());
  3768   __ bne(AT, R0, interface_ok);
  3769   __ delayed()->nop();
  3770   // throw exception
  3771   // the call_VM checks for exception, so we should never return here.
  3773   //__ pop();//FIXME here,
  3774   // pop return address (pushed by prepare_invoke).
  3775   // no need now, we just save the value in RA now
  3777   __ call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_IncompatibleClassChangeError));
  3778   __ should_not_reach_here();
  3780   __ bind(interface_ok);
  3781   //NOTICE here, no pop as x86 do
  3782   __ bne(AT, T2, search);
  3783   __ delayed()->nop();
  3785   // now we get vtable of the interface
  3786   __ ld(T0, T0, itableOffsetEntry::offset_offset_in_bytes());
  3787   __ daddu(T0, T1, T0);
  3788   assert(itableMethodEntry::size() * wordSize == 8, "adjust the scaling in the code below");
  3789   __ dsll(AT, Rmethod, Address::times_8);
  3790   __ daddu(AT, T0, AT);
  3791   // now we get the method
  3792   __ ld(Rmethod, AT, 0);
  3793   // Rnext: methodOop to call
  3794   // T3: receiver
  3795   // Check for abstract method error
  3796   // Note: This should be done more efficiently via a throw_abstract_method_error
  3797   //       interpreter entry point and a conditional jump to it in case of a null
  3798   //       method.
  3800     Label L;
  3801     __ bne(Rmethod, R0, L);
  3802     __ delayed()->nop();
  3804     // throw exception
  3805     // note: must restore interpreter registers to canonical
  3806     //       state for exception handling to work correctly!
  3807     ///__ popl(ebx);          // pop return address (pushed by prepare_invoke)
  3808     //__ restore_bcp();      // esi must be correct for exception handler
  3809     //(was destroyed)
  3810     //__ restore_locals();   // make sure locals pointer
  3811     //is correct as well (was destroyed)
  3812     ///__ call_VM(noreg, CAST_FROM_FN_PTR(address,
  3813     //InterpreterRuntime::throw_AbstractMethodError));
  3814     __ call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError));
  3815     // the call_VM checks for exception, so we should never return here.
  3816     __ should_not_reach_here();
  3817     __ bind(L);
  3820   // 2014/11/24 Fu
  3821   // T8: tmp, used for mdp
  3822   // Rmethod: callee
  3823   // T9: tmp
  3824   // is_virtual: true
  3825   __ profile_arguments_type(T8, Rmethod, T9, true);
  3827   __ jump_from_interpreted(Rmethod, T9);
  3831 void TemplateTable::invokehandle(int byte_no) {
  3832   transition(vtos, vtos);
  3833   assert(byte_no == f1_byte, "use this argument");
  3834   const Register T2_method = Rmethod;
  3835   const Register FSR_mtype  = FSR;
  3836   const Register T3_recv   = T3;
  3838   if (!EnableInvokeDynamic) {
  3839      // rewriter does not generate this bytecode
  3840      __ should_not_reach_here();
  3841      return;
  3844    prepare_invoke(byte_no, T2_method, FSR_mtype, T3_recv);
  3845    //??__ verify_method_ptr(T2_method);
  3846    __ verify_oop(T3_recv);
  3847    __ null_check(T3_recv);
  3849    // rax: MethodType object (from cpool->resolved_references[f1], if necessary)
  3850    // rbx: MH.invokeExact_MT method (from f2)
  3852    // Note:  rax_mtype is already pushed (if necessary) by prepare_invoke
  3854    // FIXME: profile the LambdaForm also
  3855    __ profile_final_call(T9);
  3857    // 2014/11/24 Fu
  3858    // T8: tmp, used for mdp
  3859    // T2_method: callee
  3860    // T9: tmp
  3861    // is_virtual: true
  3862    __ profile_arguments_type(T8, T2_method, T9, true);
  3864   __ jump_from_interpreted(T2_method, T9);
  3867  void TemplateTable::invokedynamic(int byte_no) {
  3868    transition(vtos, vtos);
  3869    assert(byte_no == f1_byte, "use this argument");
  3871    if (!EnableInvokeDynamic) {
  3872      // We should not encounter this bytecode if !EnableInvokeDynamic.
  3873      // The verifier will stop it.  However, if we get past the verifier,
  3874      // this will stop the thread in a reasonable way, without crashing the JVM.
  3875      __ call_VM(noreg, CAST_FROM_FN_PTR(address,
  3876                       InterpreterRuntime::throw_IncompatibleClassChangeError));
  3877      // the call_VM checks for exception, so we should never return here.
  3878      __ should_not_reach_here();
  3879      return;
  3882    //const Register Rmethod   = T2;
  3883    const Register T2_callsite = T2;
  3885    prepare_invoke(byte_no, Rmethod, T2_callsite);
  3887    // rax: CallSite object (from cpool->resolved_references[f1])
  3888    // rbx: MH.linkToCallSite method (from f2)
  3890    // Note:  rax_callsite is already pushed by prepare_invoke
  3891    // %%% should make a type profile for any invokedynamic that takes a ref argument
  3892    // profile this call
  3893    __ profile_call(T9);
  3895    // 2014/11/24 Fu
  3896    // T8: tmp, used for mdp
  3897    // Rmethod: callee
  3898    // T9: tmp
  3899    // is_virtual: false
  3900    __ profile_arguments_type(T8, Rmethod, T9, false);
  3902    __ verify_oop(T2_callsite);
  3904    __ jump_from_interpreted(Rmethod, T9);
  3907 //-----------------------------------------------------------------------------
  3908 // Allocation
  3909 // T1 : tags & buffer end & thread
  3910 // T2 : object end
  3911 // T3 : klass
  3912 // T1 : object size
  3913 // A1 : cpool
  3914 // A2 : cp index
  3915 // return object in FSR
  3916 void TemplateTable::_new() {
  3917   transition(vtos, atos);
  3918   __ get_unsigned_2_byte_index_at_bcp(A2, 1);
  3920   Label slow_case;
  3921   Label done;
  3922   Label initialize_header;
  3923   Label initialize_object; // including clearing the fields
  3924   Label allocate_shared;
  3926   // get InstanceKlass in T3
  3927   __ get_cpool_and_tags(A1, T1);
  3929   __ dsll(AT, A2, Address::times_8);
  3930   if (UseLoongsonISA && Assembler::is_simm(sizeof(ConstantPool), 8)) {
  3931     __ gsldx(T3, A1, AT, sizeof(ConstantPool));
  3932   } else {
  3933     __ dadd(AT, A1, AT);
  3934     __ ld(T3, AT, sizeof(ConstantPool));
  3937   // make sure the class we're about to instantiate has been resolved.
  3938   // Note: slow_case does a pop of stack, which is why we loaded class/pushed above
  3939   const int tags_offset = Array<u1>::base_offset_in_bytes();
  3940   if (UseLoongsonISA && Assembler::is_simm(tags_offset, 8)) {
  3941     __ gslbx(AT, T1, A2, tags_offset);
  3942   } else {
  3943     __ dadd(T1, T1, A2);
  3944     __ lb(AT, T1, tags_offset);
  3946   __ daddiu(AT, AT, - (int)JVM_CONSTANT_Class);
  3947   __ bne(AT, R0, slow_case);
  3948   //__ delayed()->nop();
  3951   // make sure klass is initialized & doesn't have finalizer
  3952   // make sure klass is fully initialized
  3953   __ lhu(T1, T3, in_bytes(InstanceKlass::init_state_offset()));
  3954   __ daddiu(AT, T1, - (int)InstanceKlass::fully_initialized);
  3955   __ bne(AT, R0, slow_case);
  3956   //__ delayed()->nop();
  3958   // has_finalizer
  3959   __ lw(T0, T3, in_bytes(Klass::layout_helper_offset()) );
  3960   __ andi(AT, T0, Klass::_lh_instance_slow_path_bit);
  3961   __ bne(AT, R0, slow_case);
  3962   //__ delayed()->nop();
  3964   // Allocate the instance
  3965   // 1) Try to allocate in the TLAB
  3966   // 2) if fail and the object is large allocate in the shared Eden
  3967   // 3) if the above fails (or is not applicable), go to a slow case
  3968   // (creates a new TLAB, etc.)
  3970   const bool allow_shared_alloc =
  3971     Universe::heap()->supports_inline_contig_alloc() && !CMSIncrementalMode;
  3973   if (UseTLAB) {
  3974 #ifndef OPT_THREAD
  3975     const Register thread = T8;
  3976     __ get_thread(thread);
  3977 #else
  3978     const Register thread = TREG;
  3979 #endif
  3980     // get tlab_top
  3981     __ ld(FSR, thread, in_bytes(JavaThread::tlab_top_offset()));
  3982     // get tlab_end
  3983     __ ld(AT, thread, in_bytes(JavaThread::tlab_end_offset()));
  3984     __ dadd(T2, FSR, T0);
  3985     __ slt(AT, AT, T2);
  3986     __ bne(AT, R0, allow_shared_alloc ? allocate_shared : slow_case);
  3987     __ delayed()->nop();
  3988     __ sd(T2, thread, in_bytes(JavaThread::tlab_top_offset()));
  3990     if (ZeroTLAB) {
  3991       // the fields have been already cleared
  3992       __ beq(R0, R0, initialize_header);
  3993     } else {
  3994       // initialize both the header and fields
  3995       __ beq(R0, R0, initialize_object);
  3997     __ delayed()->nop();
  4000   // Allocation in the shared Eden , if allowed
  4001   // T0 : instance size in words
  4002   if(allow_shared_alloc){
  4003     __ bind(allocate_shared);
  4005     Label retry;
  4006     Address heap_top(T1);
  4007     __ set64(T1, (long)Universe::heap()->top_addr());
  4008     __ ld(FSR, heap_top);
  4010     __ bind(retry);
  4011     __ set64(AT, (long)Universe::heap()->end_addr());
  4012     __ ld(AT, AT, 0);
  4013     __ dadd(T2, FSR, T0);
  4014     __ slt(AT, AT, T2);
  4015     __ bne(AT, R0, slow_case);
  4016     __ delayed()->nop();
  4018     // Compare FSR with the top addr, and if still equal, store the new
  4019     // top addr in ebx at the address of the top addr pointer. Sets ZF if was
  4020     // equal, and clears it otherwise. Use lock prefix for atomicity on MPs.
  4021     //
  4022     // FSR: object begin
  4023     // T2: object end
  4024     // T0: instance size in words
  4026     // if someone beat us on the allocation, try again, otherwise continue
  4027     __ cmpxchg(T2, heap_top, FSR);
  4028     __ beq(AT, R0, retry);
  4029     __ delayed()->nop();
  4032   if (UseTLAB || Universe::heap()->supports_inline_contig_alloc()) {
  4033     // The object is initialized before the header.  If the object size is
  4034     // zero, go directly to the header initialization.
  4035     __ bind(initialize_object);
  4036     __ set64(AT, - sizeof(oopDesc));
  4037     __ daddu(T0, T0, AT);
  4038     __ beq(T0, R0, initialize_header);
  4039     __ delayed()->nop();
  4041     // initialize remaining object fields: T0 is a multiple of 2
  4043       Label loop;
  4044       __ dadd(T1, FSR, T0);
  4045       __ daddi(T1, T1, -oopSize);
  4047       __ bind(loop);
  4048       __ sd(R0, T1, sizeof(oopDesc) + 0 * oopSize);
  4049       __ bne(T1, FSR, loop); //dont clear header
  4050       __ delayed()->daddi(T1, T1, -oopSize);
  4053     //klass in T3,
  4054     // initialize object header only.
  4055     __ bind(initialize_header);
  4056     if (UseBiasedLocking) {
  4057       __ ld(AT, T3, in_bytes(Klass::prototype_header_offset()));
  4058       __ sd(AT, FSR, oopDesc::mark_offset_in_bytes ());
  4059     } else {
  4060       __ set64(AT, (long)markOopDesc::prototype());
  4061       __ sd(AT, FSR, oopDesc::mark_offset_in_bytes());
  4064     __ store_klass_gap(FSR, R0);
  4065     __ store_klass(FSR, T3);
  4068       SkipIfEqual skip_if(_masm, &DTraceAllocProbes, 0);
  4069       // Trigger dtrace event for fastpath
  4070       __ push(atos);
  4071       __ call_VM_leaf(
  4072            CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_object_alloc), FSR);
  4073       __ pop(atos);
  4076     __ b(done);
  4077     __ delayed()->nop();
  4080   // slow case
  4081   __ bind(slow_case);
  4082   call_VM(FSR, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), A1, A2);
  4084   // continue
  4085   __ bind(done);
  4086   __ sync();
  4089 void TemplateTable::newarray() {
  4090   transition(itos, atos);
  4091   __ lbu(A1, at_bcp(1));
  4092   //type, count
  4093   call_VM(FSR, CAST_FROM_FN_PTR(address, InterpreterRuntime::newarray), A1, FSR);
  4094   __ sync();
  4097 void TemplateTable::anewarray() {
  4098   transition(itos, atos);
  4099   __ get_2_byte_integer_at_bcp(A2, AT, 1);
  4100   __ huswap(A2);
  4101   __ get_constant_pool(A1);
  4102   // cp, index, count
  4103   call_VM(FSR, CAST_FROM_FN_PTR(address, InterpreterRuntime::anewarray), A1, A2, FSR);
  4104   __ sync();
  4107 void TemplateTable::arraylength() {
  4108   transition(atos, itos);
  4109   __ null_check(FSR, arrayOopDesc::length_offset_in_bytes());
  4110   __ lw(FSR, FSR, arrayOopDesc::length_offset_in_bytes());
  4113 // i use T2 as ebx, T3 as ecx, T1 as edx
  4114 // when invoke gen_subtype_check, super in T3, sub in T2, object in FSR(it's always)
  4115 // T2 : sub klass
  4116 // T3 : cpool
  4117 // T3 : super klass
  4118 void TemplateTable::checkcast() {
  4119   transition(atos, atos);
  4120   Label done, is_null, ok_is_subtype, quicked, resolved;
  4121   __ beq(FSR, R0, is_null);
  4122   __ delayed()->nop();
  4124   // Get cpool & tags index
  4125   __ get_cpool_and_tags(T3, T1);
  4126   __ get_2_byte_integer_at_bcp(T2, AT, 1);
  4127   __ huswap(T2);
  4129   // See if bytecode has already been quicked
  4130   __ dadd(AT, T1, T2);
  4131   __ lb(AT, AT, Array<u1>::base_offset_in_bytes());
  4132   __ daddiu(AT, AT, - (int)JVM_CONSTANT_Class);
  4133   __ beq(AT, R0, quicked);
  4134   __ delayed()->nop();
  4136   /* 2012/6/2 Jin: In InterpreterRuntime::quicken_io_cc, lots of new classes may be loaded.
  4137    *  Then, GC will move the object in V0 to another places in heap.
  4138    *  Therefore, We should never save such an object in register.
  4139    *  Instead, we should save it in the stack. It can be modified automatically by the GC thread.
  4140    *  After GC, the object address in FSR is changed to a new place.
  4141    */
  4142   __ push(atos);
  4143   const Register thread = TREG;
  4144 #ifndef OPT_THREAD
  4145   __ get_thread(thread);
  4146 #endif
  4147   call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc));
  4148   __ get_vm_result_2(T3, thread);
  4149   __ pop_ptr(FSR);
  4150   __ b(resolved);
  4151   __ delayed()->nop();
  4153   // klass already in cp, get superklass in T3
  4154   __ bind(quicked);
  4155   __ dsll(AT, T2, Address::times_8);
  4156   __ dadd(AT, T3, AT);
  4157   __ ld(T3, AT, sizeof(ConstantPool));
  4159   __ bind(resolved);
  4161   // get subklass in T2
  4162   //add for compressedoops
  4163   __ load_klass(T2, FSR);
  4164   // Superklass in T3.  Subklass in T2.
  4165   __ gen_subtype_check(T3, T2, ok_is_subtype);
  4167   // Come here on failure
  4168   // object is at FSR
  4169   __ jmp(Interpreter::_throw_ClassCastException_entry);
  4170   __ delayed()->nop();
  4172   // Come here on success
  4173   __ bind(ok_is_subtype);
  4175   // Collect counts on whether this check-cast sees NULLs a lot or not.
  4176   if (ProfileInterpreter) {
  4177     __ b(done);
  4178     __ delayed()->nop();
  4179     __ bind(is_null);
  4180     __ profile_null_seen(T3);
  4181   } else {
  4182     __ bind(is_null);
  4184   __ bind(done);
  4187 // i use T3 as cpool, T1 as tags, T2 as index
  4188 // object always in FSR, superklass in T3, subklass in T2
  4189 void TemplateTable::instanceof() {
  4190   transition(atos, itos);
  4191   Label done, is_null, ok_is_subtype, quicked, resolved;
  4193   __ beq(FSR, R0, is_null);
  4194   __ delayed()->nop();
  4196   // Get cpool & tags index
  4197   __ get_cpool_and_tags(T3, T1);
  4198   // get index
  4199   __ get_2_byte_integer_at_bcp(T2, AT, 1);
  4200   __ hswap(T2);
  4202   // See if bytecode has already been quicked
  4203   // quicked
  4204   __ daddu(AT, T1, T2);
  4205   __ lb(AT, AT, Array<u1>::base_offset_in_bytes());
  4206   __ daddiu(AT, AT, - (int)JVM_CONSTANT_Class);
  4207   __ beq(AT, R0, quicked);
  4208   __ delayed()->nop();
  4210   __ push(atos);
  4211   const Register thread = TREG;
  4212 #ifndef OPT_THREAD
  4213   __ get_thread(thread);
  4214 #endif
  4215   call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc));
  4216   __ get_vm_result_2(T3, thread);
  4217   __ pop_ptr(FSR);
  4218   __ b(resolved);
  4219   __ delayed()->nop();
  4221   // get superklass in T3, subklass in T2
  4222   __ bind(quicked);
  4223   __ dsll(AT, T2, Address::times_8);
  4224   __ daddu(AT, T3, AT);
  4225   __ ld(T3, AT, sizeof(ConstantPool));
  4227   __ bind(resolved);
  4228   // get subklass in T2
  4229   //add for compressedoops
  4230   __ load_klass(T2, FSR);
  4232   // Superklass in T3.  Subklass in T2.
  4233   __ gen_subtype_check(T3, T2, ok_is_subtype);
  4234   // Come here on failure
  4235   __ b(done);
  4236   __ delayed(); __ move(FSR, R0);
  4238   // Come here on success
  4239   __ bind(ok_is_subtype);
  4240   __ move(FSR, 1);
  4242   // Collect counts on whether this test sees NULLs a lot or not.
  4243   if (ProfileInterpreter) {
  4244     __ beq(R0, R0, done);
  4245     __ nop();
  4246     __ bind(is_null);
  4247     __ profile_null_seen(T3);
  4248   } else {
  4249     __ bind(is_null);   // same as 'done'
  4251   __ bind(done);
  4252   // FSR = 0: obj == NULL or  obj is not an instanceof the specified klass
  4253   // FSR = 1: obj != NULL and obj is     an instanceof the specified klass
  4256 //--------------------------------------------------------
  4257 //--------------------------------------------
  4258 // Breakpoints
  4259 void TemplateTable::_breakpoint() {
  4260   // Note: We get here even if we are single stepping..
  4261   // jbug inists on setting breakpoints at every bytecode
  4262   // even if we are in single step mode.
  4264   transition(vtos, vtos);
  4266   // get the unpatched byte code
  4267   __ get_method(A1);
  4268   __ call_VM(NOREG,
  4269              CAST_FROM_FN_PTR(address,
  4270                               InterpreterRuntime::get_original_bytecode_at),
  4271              A1, BCP);
  4272   __ move(Rnext, V0); // Jin: Rnext will be used in dispatch_only_normal
  4274   // post the breakpoint event
  4275   __ get_method(A1);
  4276   __ call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::_breakpoint), A1, BCP);
  4278   // complete the execution of original bytecode
  4279   __ dispatch_only_normal(vtos);
  4282 //-----------------------------------------------------------------------------
  4283 // Exceptions
  4285 void TemplateTable::athrow() {
  4286   transition(atos, vtos);
  4287   __ null_check(FSR);
  4288   __ jmp(Interpreter::throw_exception_entry());
  4289   __ delayed()->nop();
  4292 //-----------------------------------------------------------------------------
  4293 // Synchronization
  4294 //
  4295 // Note: monitorenter & exit are symmetric routines; which is reflected
  4296 //       in the assembly code structure as well
  4297 //
  4298 // Stack layout:
  4299 //
  4300 // [expressions  ] <--- SP               = expression stack top
  4301 // ..
  4302 // [expressions  ]
  4303 // [monitor entry] <--- monitor block top = expression stack bot
  4304 // ..
  4305 // [monitor entry]
  4306 // [frame data   ] <--- monitor block bot
  4307 // ...
  4308 // [return addr  ] <--- FP
  4310 // we use T2 as monitor entry pointer, T3 as monitor top pointer, c_rarg0 as free slot pointer
  4311 // object always in FSR
  4312 void TemplateTable::monitorenter() {
  4313   transition(atos, vtos);
  4315   // check for NULL object
  4316   __ null_check(FSR);
  4318   const Address monitor_block_top(FP, frame::interpreter_frame_monitor_block_top_offset
  4319       * wordSize);
  4320   const int entry_size = (frame::interpreter_frame_monitor_size()* wordSize);
  4321   Label allocated;
  4323   // initialize entry pointer
  4324   __ move(c_rarg0, R0);
  4326   // find a free slot in the monitor block (result in edx)
  4328     Label entry, loop, exit, next;
  4329     __ ld(T2, monitor_block_top);
  4330     __ b(entry);
  4331     __ delayed()->daddi(T3, FP, frame::interpreter_frame_initial_sp_offset * wordSize);
  4333     // free slot?
  4334     __ bind(loop);
  4335     __ ld(AT, T2, BasicObjectLock::obj_offset_in_bytes());
  4336     __ bne(AT, R0, next);
  4337     __ delayed()->nop();
  4338     __ move(c_rarg0, T2);
  4340     __ bind(next);
  4341     __ beq(FSR, AT, exit);
  4342     __ delayed()->nop();
  4343     __ daddi(T2, T2, entry_size);
  4345     __ bind(entry);
  4346     __ bne(T3, T2, loop);
  4347     __ delayed()->nop();
  4348     __ bind(exit);
  4351   __ bne(c_rarg0, R0, allocated);
  4352   __ delayed()->nop();
  4354   // allocate one if there's no free slot
  4356     Label entry, loop;
  4357     // 1. compute new pointers                   // SP: old expression stack top
  4358     __ ld(c_rarg0, monitor_block_top);
  4359     __ daddi(SP, SP, - entry_size);
  4360     __ daddi(c_rarg0, c_rarg0, - entry_size);
  4361     __ sd(c_rarg0, monitor_block_top);
  4362     __ b(entry);
  4363     __ delayed(); __ move(T3, SP);
  4365     // 2. move expression stack contents
  4366     __ bind(loop);
  4367     __ ld(AT, T3, entry_size);
  4368     __ sd(AT, T3, 0);
  4369     __ daddi(T3, T3, wordSize);
  4370     __ bind(entry);
  4371     __ bne(T3, c_rarg0, loop);
  4372     __ delayed()->nop();
  4375   __ bind(allocated);
  4376   // Increment bcp to point to the next bytecode,
  4377   // so exception handling for async. exceptions work correctly.
  4378   // The object has already been poped from the stack, so the
  4379   // expression stack looks correct.
  4380   __ daddi(BCP, BCP, 1);
  4381   __ sd(FSR, c_rarg0, BasicObjectLock::obj_offset_in_bytes());
  4382   __ lock_object(c_rarg0);
  4383   // check to make sure this monitor doesn't cause stack overflow after locking
  4384   __ save_bcp();  // in case of exception
  4385   __ generate_stack_overflow_check(0);
  4386   // The bcp has already been incremented. Just need to dispatch to next instruction.
  4388   __ dispatch_next(vtos);
  4391 // T2 : top
  4392 // c_rarg0 : entry
  4393 void TemplateTable::monitorexit() {
  4394   transition(atos, vtos);
  4396   __ null_check(FSR);
  4398   const int entry_size =(frame::interpreter_frame_monitor_size()* wordSize);
  4399   Label found;
  4401   // find matching slot
  4403     Label entry, loop;
  4404     __ ld(c_rarg0, FP, frame::interpreter_frame_monitor_block_top_offset * wordSize);
  4405     __ b(entry);
  4406     __ delayed()->daddiu(T2, FP, frame::interpreter_frame_initial_sp_offset * wordSize);
  4408     __ bind(loop);
  4409     __ ld(AT, c_rarg0, BasicObjectLock::obj_offset_in_bytes());
  4410     __ beq(FSR, AT, found);
  4411     __ delayed()->nop();
  4412     __ daddiu(c_rarg0, c_rarg0, entry_size);
  4413     __ bind(entry);
  4414     __ bne(T2, c_rarg0, loop);
  4415     __ delayed()->nop();
  4418   // error handling. Unlocking was not block-structured
  4419   Label end;
  4420   __ call_VM(NOREG, CAST_FROM_FN_PTR(address,
  4421   InterpreterRuntime::throw_illegal_monitor_state_exception));
  4422   __ should_not_reach_here();
  4424   // call run-time routine
  4425   // c_rarg0: points to monitor entry
  4426   __ bind(found);
  4427   __ move(TSR, FSR);
  4428   __ unlock_object(c_rarg0);
  4429   __ move(FSR, TSR);
  4430   __ bind(end);
  4434 // Wide instructions
  4435 void TemplateTable::wide() {
  4436   transition(vtos, vtos);
  4437   // Note: the esi increment step is part of the individual wide bytecode implementations
  4438   __ lbu(Rnext, at_bcp(1));
  4439   __ dsll(T9, Rnext, Address::times_8);
  4440   __ li(AT, (long)Interpreter::_wentry_point);
  4441   __ dadd(AT, T9, AT);
  4442   __ ld(T9, AT, 0);
  4443   __ jr(T9);
  4444   __ delayed()->nop();
  4448 void TemplateTable::multianewarray() {
  4449   transition(vtos, atos);
  4450   // last dim is on top of stack; we want address of first one:
  4451   // first_addr = last_addr + (ndims - 1) * wordSize
  4452   __ lbu(A1, at_bcp(3));  // dimension
  4453   __ daddi(A1, A1, -1);
  4454   __ dsll(A1, A1, Address::times_8);
  4455   __ dadd(A1, SP, A1);    // now A1 pointer to the count array on the stack
  4456   call_VM(FSR, CAST_FROM_FN_PTR(address, InterpreterRuntime::multianewarray), A1);
  4457   __ lbu(AT, at_bcp(3));
  4458   __ dsll(AT, AT, Address::times_8);
  4459   __ dadd(SP, SP, AT);
  4460   __ sync();
  4462 #endif // !CC_INTERP

mercurial