src/cpu/x86/vm/templateTable_x86_32.cpp

Tue, 24 Jul 2012 10:51:00 -0700

author
twisti
date
Tue, 24 Jul 2012 10:51:00 -0700
changeset 3969
1d7922586cf6
parent 3698
19e197e2a1af
child 4037
da91efe96a93
permissions
-rw-r--r--

7023639: JSR 292 method handle invocation needs a fast path for compiled code
6984705: JSR 292 method handle creation should not go through JNI
Summary: remove assembly code for JDK 7 chained method handles
Reviewed-by: jrose, twisti, kvn, mhaupt
Contributed-by: John Rose <john.r.rose@oracle.com>, Christian Thalinger <christian.thalinger@oracle.com>, Michael Haupt <michael.haupt@oracle.com>

     1 /*
     2  * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 #include "precompiled.hpp"
    26 #include "asm/assembler.hpp"
    27 #include "interpreter/interpreter.hpp"
    28 #include "interpreter/interpreterRuntime.hpp"
    29 #include "interpreter/templateTable.hpp"
    30 #include "memory/universe.inline.hpp"
    31 #include "oops/methodDataOop.hpp"
    32 #include "oops/objArrayKlass.hpp"
    33 #include "oops/oop.inline.hpp"
    34 #include "prims/methodHandles.hpp"
    35 #include "runtime/sharedRuntime.hpp"
    36 #include "runtime/stubRoutines.hpp"
    37 #include "runtime/synchronizer.hpp"
    39 #ifndef CC_INTERP
    40 #define __ _masm->
    42 //----------------------------------------------------------------------------------------------------
    43 // Platform-dependent initialization
    45 void TemplateTable::pd_initialize() {
    46   // No i486 specific initialization
    47 }
    49 //----------------------------------------------------------------------------------------------------
    50 // Address computation
    52 // local variables
    53 static inline Address iaddress(int n)            {
    54   return Address(rdi, Interpreter::local_offset_in_bytes(n));
    55 }
    57 static inline Address laddress(int n)            { return iaddress(n + 1); }
    58 static inline Address haddress(int n)            { return iaddress(n + 0); }
    59 static inline Address faddress(int n)            { return iaddress(n); }
    60 static inline Address daddress(int n)            { return laddress(n); }
    61 static inline Address aaddress(int n)            { return iaddress(n); }
    63 static inline Address iaddress(Register r)       {
    64   return Address(rdi, r, Interpreter::stackElementScale());
    65 }
    66 static inline Address laddress(Register r)       {
    67   return Address(rdi, r, Interpreter::stackElementScale(), Interpreter::local_offset_in_bytes(1));
    68 }
    69 static inline Address haddress(Register r)       {
    70   return Address(rdi, r, Interpreter::stackElementScale(), Interpreter::local_offset_in_bytes(0));
    71 }
    73 static inline Address faddress(Register r)       { return iaddress(r); }
    74 static inline Address daddress(Register r)       { return laddress(r); }
    75 static inline Address aaddress(Register r)       { return iaddress(r); }
    77 // expression stack
    78 // (Note: Must not use symmetric equivalents at_rsp_m1/2 since they store
    79 // data beyond the rsp which is potentially unsafe in an MT environment;
    80 // an interrupt may overwrite that data.)
    81 static inline Address at_rsp   () {
    82   return Address(rsp, 0);
    83 }
    85 // At top of Java expression stack which may be different than rsp().  It
    86 // isn't for category 1 objects.
    87 static inline Address at_tos   () {
    88   Address tos = Address(rsp,  Interpreter::expr_offset_in_bytes(0));
    89   return tos;
    90 }
    92 static inline Address at_tos_p1() {
    93   return Address(rsp,  Interpreter::expr_offset_in_bytes(1));
    94 }
    96 static inline Address at_tos_p2() {
    97   return Address(rsp,  Interpreter::expr_offset_in_bytes(2));
    98 }
   100 // Condition conversion
   101 static Assembler::Condition j_not(TemplateTable::Condition cc) {
   102   switch (cc) {
   103     case TemplateTable::equal        : return Assembler::notEqual;
   104     case TemplateTable::not_equal    : return Assembler::equal;
   105     case TemplateTable::less         : return Assembler::greaterEqual;
   106     case TemplateTable::less_equal   : return Assembler::greater;
   107     case TemplateTable::greater      : return Assembler::lessEqual;
   108     case TemplateTable::greater_equal: return Assembler::less;
   109   }
   110   ShouldNotReachHere();
   111   return Assembler::zero;
   112 }
   115 //----------------------------------------------------------------------------------------------------
   116 // Miscelaneous helper routines
   118 // Store an oop (or NULL) at the address described by obj.
   119 // If val == noreg this means store a NULL
   121 static void do_oop_store(InterpreterMacroAssembler* _masm,
   122                          Address obj,
   123                          Register val,
   124                          BarrierSet::Name barrier,
   125                          bool precise) {
   126   assert(val == noreg || val == rax, "parameter is just for looks");
   127   switch (barrier) {
   128 #ifndef SERIALGC
   129     case BarrierSet::G1SATBCT:
   130     case BarrierSet::G1SATBCTLogging:
   131       {
   132         // flatten object address if needed
   133         // We do it regardless of precise because we need the registers
   134         if (obj.index() == noreg && obj.disp() == 0) {
   135           if (obj.base() != rdx) {
   136             __ movl(rdx, obj.base());
   137           }
   138         } else {
   139           __ leal(rdx, obj);
   140         }
   141         __ get_thread(rcx);
   142         __ save_bcp();
   143         __ g1_write_barrier_pre(rdx /* obj */,
   144                                 rbx /* pre_val */,
   145                                 rcx /* thread */,
   146                                 rsi /* tmp */,
   147                                 val != noreg /* tosca_live */,
   148                                 false /* expand_call */);
   150         // Do the actual store
   151         // noreg means NULL
   152         if (val == noreg) {
   153           __ movptr(Address(rdx, 0), NULL_WORD);
   154           // No post barrier for NULL
   155         } else {
   156           __ movl(Address(rdx, 0), val);
   157           __ g1_write_barrier_post(rdx /* store_adr */,
   158                                    val /* new_val */,
   159                                    rcx /* thread */,
   160                                    rbx /* tmp */,
   161                                    rsi /* tmp2 */);
   162         }
   163         __ restore_bcp();
   165       }
   166       break;
   167 #endif // SERIALGC
   168     case BarrierSet::CardTableModRef:
   169     case BarrierSet::CardTableExtension:
   170       {
   171         if (val == noreg) {
   172           __ movptr(obj, NULL_WORD);
   173         } else {
   174           __ movl(obj, val);
   175           // flatten object address if needed
   176           if (!precise || (obj.index() == noreg && obj.disp() == 0)) {
   177             __ store_check(obj.base());
   178           } else {
   179             __ leal(rdx, obj);
   180             __ store_check(rdx);
   181           }
   182         }
   183       }
   184       break;
   185     case BarrierSet::ModRef:
   186     case BarrierSet::Other:
   187       if (val == noreg) {
   188         __ movptr(obj, NULL_WORD);
   189       } else {
   190         __ movl(obj, val);
   191       }
   192       break;
   193     default      :
   194       ShouldNotReachHere();
   196   }
   197 }
   199 Address TemplateTable::at_bcp(int offset) {
   200   assert(_desc->uses_bcp(), "inconsistent uses_bcp information");
   201   return Address(rsi, offset);
   202 }
   205 void TemplateTable::patch_bytecode(Bytecodes::Code bc, Register bc_reg,
   206                                    Register temp_reg, bool load_bc_into_bc_reg/*=true*/,
   207                                    int byte_no) {
   208   if (!RewriteBytecodes)  return;
   209   Label L_patch_done;
   211   switch (bc) {
   212   case Bytecodes::_fast_aputfield:
   213   case Bytecodes::_fast_bputfield:
   214   case Bytecodes::_fast_cputfield:
   215   case Bytecodes::_fast_dputfield:
   216   case Bytecodes::_fast_fputfield:
   217   case Bytecodes::_fast_iputfield:
   218   case Bytecodes::_fast_lputfield:
   219   case Bytecodes::_fast_sputfield:
   220     {
   221       // We skip bytecode quickening for putfield instructions when
   222       // the put_code written to the constant pool cache is zero.
   223       // This is required so that every execution of this instruction
   224       // calls out to InterpreterRuntime::resolve_get_put to do
   225       // additional, required work.
   226       assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
   227       assert(load_bc_into_bc_reg, "we use bc_reg as temp");
   228       __ get_cache_and_index_and_bytecode_at_bcp(bc_reg, temp_reg, temp_reg, byte_no, 1);
   229       __ movl(bc_reg, bc);
   230       __ cmpl(temp_reg, (int) 0);
   231       __ jcc(Assembler::zero, L_patch_done);  // don't patch
   232     }
   233     break;
   234   default:
   235     assert(byte_no == -1, "sanity");
   236     // the pair bytecodes have already done the load.
   237     if (load_bc_into_bc_reg) {
   238       __ movl(bc_reg, bc);
   239     }
   240   }
   242   if (JvmtiExport::can_post_breakpoint()) {
   243     Label L_fast_patch;
   244     // if a breakpoint is present we can't rewrite the stream directly
   245     __ movzbl(temp_reg, at_bcp(0));
   246     __ cmpl(temp_reg, Bytecodes::_breakpoint);
   247     __ jcc(Assembler::notEqual, L_fast_patch);
   248     __ get_method(temp_reg);
   249     // Let breakpoint table handling rewrite to quicker bytecode
   250     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::set_original_bytecode_at), temp_reg, rsi, bc_reg);
   251 #ifndef ASSERT
   252     __ jmpb(L_patch_done);
   253 #else
   254     __ jmp(L_patch_done);
   255 #endif
   256     __ bind(L_fast_patch);
   257   }
   259 #ifdef ASSERT
   260   Label L_okay;
   261   __ load_unsigned_byte(temp_reg, at_bcp(0));
   262   __ cmpl(temp_reg, (int)Bytecodes::java_code(bc));
   263   __ jccb(Assembler::equal, L_okay);
   264   __ cmpl(temp_reg, bc_reg);
   265   __ jcc(Assembler::equal, L_okay);
   266   __ stop("patching the wrong bytecode");
   267   __ bind(L_okay);
   268 #endif
   270   // patch bytecode
   271   __ movb(at_bcp(0), bc_reg);
   272   __ bind(L_patch_done);
   273 }
   275 //----------------------------------------------------------------------------------------------------
   276 // Individual instructions
   278 void TemplateTable::nop() {
   279   transition(vtos, vtos);
   280   // nothing to do
   281 }
   283 void TemplateTable::shouldnotreachhere() {
   284   transition(vtos, vtos);
   285   __ stop("shouldnotreachhere bytecode");
   286 }
   290 void TemplateTable::aconst_null() {
   291   transition(vtos, atos);
   292   __ xorptr(rax, rax);
   293 }
   296 void TemplateTable::iconst(int value) {
   297   transition(vtos, itos);
   298   if (value == 0) {
   299     __ xorptr(rax, rax);
   300   } else {
   301     __ movptr(rax, value);
   302   }
   303 }
   306 void TemplateTable::lconst(int value) {
   307   transition(vtos, ltos);
   308   if (value == 0) {
   309     __ xorptr(rax, rax);
   310   } else {
   311     __ movptr(rax, value);
   312   }
   313   assert(value >= 0, "check this code");
   314   __ xorptr(rdx, rdx);
   315 }
   318 void TemplateTable::fconst(int value) {
   319   transition(vtos, ftos);
   320          if (value == 0) { __ fldz();
   321   } else if (value == 1) { __ fld1();
   322   } else if (value == 2) { __ fld1(); __ fld1(); __ faddp(); // should do a better solution here
   323   } else                 { ShouldNotReachHere();
   324   }
   325 }
   328 void TemplateTable::dconst(int value) {
   329   transition(vtos, dtos);
   330          if (value == 0) { __ fldz();
   331   } else if (value == 1) { __ fld1();
   332   } else                 { ShouldNotReachHere();
   333   }
   334 }
   337 void TemplateTable::bipush() {
   338   transition(vtos, itos);
   339   __ load_signed_byte(rax, at_bcp(1));
   340 }
   343 void TemplateTable::sipush() {
   344   transition(vtos, itos);
   345   __ load_unsigned_short(rax, at_bcp(1));
   346   __ bswapl(rax);
   347   __ sarl(rax, 16);
   348 }
   350 void TemplateTable::ldc(bool wide) {
   351   transition(vtos, vtos);
   352   Label call_ldc, notFloat, notClass, Done;
   354   if (wide) {
   355     __ get_unsigned_2_byte_index_at_bcp(rbx, 1);
   356   } else {
   357     __ load_unsigned_byte(rbx, at_bcp(1));
   358   }
   359   __ get_cpool_and_tags(rcx, rax);
   360   const int base_offset = constantPoolOopDesc::header_size() * wordSize;
   361   const int tags_offset = typeArrayOopDesc::header_size(T_BYTE) * wordSize;
   363   // get type
   364   __ xorptr(rdx, rdx);
   365   __ movb(rdx, Address(rax, rbx, Address::times_1, tags_offset));
   367   // unresolved string - get the resolved string
   368   __ cmpl(rdx, JVM_CONSTANT_UnresolvedString);
   369   __ jccb(Assembler::equal, call_ldc);
   371   // unresolved class - get the resolved class
   372   __ cmpl(rdx, JVM_CONSTANT_UnresolvedClass);
   373   __ jccb(Assembler::equal, call_ldc);
   375   // unresolved class in error (resolution failed) - call into runtime
   376   // so that the same error from first resolution attempt is thrown.
   377   __ cmpl(rdx, JVM_CONSTANT_UnresolvedClassInError);
   378   __ jccb(Assembler::equal, call_ldc);
   380   // resolved class - need to call vm to get java mirror of the class
   381   __ cmpl(rdx, JVM_CONSTANT_Class);
   382   __ jcc(Assembler::notEqual, notClass);
   384   __ bind(call_ldc);
   385   __ movl(rcx, wide);
   386   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::ldc), rcx);
   387   __ push(atos);
   388   __ jmp(Done);
   390   __ bind(notClass);
   391   __ cmpl(rdx, JVM_CONSTANT_Float);
   392   __ jccb(Assembler::notEqual, notFloat);
   393   // ftos
   394   __ fld_s(    Address(rcx, rbx, Address::times_ptr, base_offset));
   395   __ push(ftos);
   396   __ jmp(Done);
   398   __ bind(notFloat);
   399 #ifdef ASSERT
   400   { Label L;
   401     __ cmpl(rdx, JVM_CONSTANT_Integer);
   402     __ jcc(Assembler::equal, L);
   403     __ cmpl(rdx, JVM_CONSTANT_String);
   404     __ jcc(Assembler::equal, L);
   405     __ cmpl(rdx, JVM_CONSTANT_Object);
   406     __ jcc(Assembler::equal, L);
   407     __ stop("unexpected tag type in ldc");
   408     __ bind(L);
   409   }
   410 #endif
   411   Label isOop;
   412   // atos and itos
   413   // Integer is only non-oop type we will see here
   414   __ cmpl(rdx, JVM_CONSTANT_Integer);
   415   __ jccb(Assembler::notEqual, isOop);
   416   __ movl(rax, Address(rcx, rbx, Address::times_ptr, base_offset));
   417   __ push(itos);
   418   __ jmp(Done);
   419   __ bind(isOop);
   420   __ movptr(rax, Address(rcx, rbx, Address::times_ptr, base_offset));
   421   __ push(atos);
   423   if (VerifyOops) {
   424     __ verify_oop(rax);
   425   }
   426   __ bind(Done);
   427 }
   429 // Fast path for caching oop constants.
   430 // %%% We should use this to handle Class and String constants also.
   431 // %%% It will simplify the ldc/primitive path considerably.
   432 void TemplateTable::fast_aldc(bool wide) {
   433   transition(vtos, atos);
   435   if (!EnableInvokeDynamic) {
   436     // We should not encounter this bytecode if !EnableInvokeDynamic.
   437     // The verifier will stop it.  However, if we get past the verifier,
   438     // this will stop the thread in a reasonable way, without crashing the JVM.
   439     __ call_VM(noreg, CAST_FROM_FN_PTR(address,
   440                      InterpreterRuntime::throw_IncompatibleClassChangeError));
   441     // the call_VM checks for exception, so we should never return here.
   442     __ should_not_reach_here();
   443     return;
   444   }
   446   const Register cache = rcx;
   447   const Register index = rdx;
   449   resolve_cache_and_index(f12_oop, rax, cache, index, wide ? sizeof(u2) : sizeof(u1));
   450   if (VerifyOops) {
   451     __ verify_oop(rax);
   452   }
   454   Label L_done, L_throw_exception;
   455   const Register con_klass_temp = rcx;  // same as cache
   456   __ load_klass(con_klass_temp, rax);
   457   __ cmpptr(con_klass_temp, ExternalAddress((address)Universe::systemObjArrayKlassObj_addr()));
   458   __ jcc(Assembler::notEqual, L_done);
   459   __ cmpl(Address(rax, arrayOopDesc::length_offset_in_bytes()), 0);
   460   __ jcc(Assembler::notEqual, L_throw_exception);
   461   __ xorptr(rax, rax);
   462   __ jmp(L_done);
   464   // Load the exception from the system-array which wraps it:
   465   __ bind(L_throw_exception);
   466   __ load_heap_oop(rax, Address(rax, arrayOopDesc::base_offset_in_bytes(T_OBJECT)));
   467   __ jump(ExternalAddress(Interpreter::throw_exception_entry()));
   469   __ bind(L_done);
   470 }
   472 void TemplateTable::ldc2_w() {
   473   transition(vtos, vtos);
   474   Label Long, Done;
   475   __ get_unsigned_2_byte_index_at_bcp(rbx, 1);
   477   __ get_cpool_and_tags(rcx, rax);
   478   const int base_offset = constantPoolOopDesc::header_size() * wordSize;
   479   const int tags_offset = typeArrayOopDesc::header_size(T_BYTE) * wordSize;
   481   // get type
   482   __ cmpb(Address(rax, rbx, Address::times_1, tags_offset), JVM_CONSTANT_Double);
   483   __ jccb(Assembler::notEqual, Long);
   484   // dtos
   485   __ fld_d(    Address(rcx, rbx, Address::times_ptr, base_offset));
   486   __ push(dtos);
   487   __ jmpb(Done);
   489   __ bind(Long);
   490   // ltos
   491   __ movptr(rax, Address(rcx, rbx, Address::times_ptr, base_offset + 0 * wordSize));
   492   NOT_LP64(__ movptr(rdx, Address(rcx, rbx, Address::times_ptr, base_offset + 1 * wordSize)));
   494   __ push(ltos);
   496   __ bind(Done);
   497 }
   500 void TemplateTable::locals_index(Register reg, int offset) {
   501   __ load_unsigned_byte(reg, at_bcp(offset));
   502   __ negptr(reg);
   503 }
   506 void TemplateTable::iload() {
   507   transition(vtos, itos);
   508   if (RewriteFrequentPairs) {
   509     Label rewrite, done;
   511     // get next byte
   512     __ load_unsigned_byte(rbx, at_bcp(Bytecodes::length_for(Bytecodes::_iload)));
   513     // if _iload, wait to rewrite to iload2.  We only want to rewrite the
   514     // last two iloads in a pair.  Comparing against fast_iload means that
   515     // the next bytecode is neither an iload or a caload, and therefore
   516     // an iload pair.
   517     __ cmpl(rbx, Bytecodes::_iload);
   518     __ jcc(Assembler::equal, done);
   520     __ cmpl(rbx, Bytecodes::_fast_iload);
   521     __ movl(rcx, Bytecodes::_fast_iload2);
   522     __ jccb(Assembler::equal, rewrite);
   524     // if _caload, rewrite to fast_icaload
   525     __ cmpl(rbx, Bytecodes::_caload);
   526     __ movl(rcx, Bytecodes::_fast_icaload);
   527     __ jccb(Assembler::equal, rewrite);
   529     // rewrite so iload doesn't check again.
   530     __ movl(rcx, Bytecodes::_fast_iload);
   532     // rewrite
   533     // rcx: fast bytecode
   534     __ bind(rewrite);
   535     patch_bytecode(Bytecodes::_iload, rcx, rbx, false);
   536     __ bind(done);
   537   }
   539   // Get the local value into tos
   540   locals_index(rbx);
   541   __ movl(rax, iaddress(rbx));
   542 }
   545 void TemplateTable::fast_iload2() {
   546   transition(vtos, itos);
   547   locals_index(rbx);
   548   __ movl(rax, iaddress(rbx));
   549   __ push(itos);
   550   locals_index(rbx, 3);
   551   __ movl(rax, iaddress(rbx));
   552 }
   554 void TemplateTable::fast_iload() {
   555   transition(vtos, itos);
   556   locals_index(rbx);
   557   __ movl(rax, iaddress(rbx));
   558 }
   561 void TemplateTable::lload() {
   562   transition(vtos, ltos);
   563   locals_index(rbx);
   564   __ movptr(rax, laddress(rbx));
   565   NOT_LP64(__ movl(rdx, haddress(rbx)));
   566 }
   569 void TemplateTable::fload() {
   570   transition(vtos, ftos);
   571   locals_index(rbx);
   572   __ fld_s(faddress(rbx));
   573 }
   576 void TemplateTable::dload() {
   577   transition(vtos, dtos);
   578   locals_index(rbx);
   579   __ fld_d(daddress(rbx));
   580 }
   583 void TemplateTable::aload() {
   584   transition(vtos, atos);
   585   locals_index(rbx);
   586   __ movptr(rax, aaddress(rbx));
   587 }
   590 void TemplateTable::locals_index_wide(Register reg) {
   591   __ movl(reg, at_bcp(2));
   592   __ bswapl(reg);
   593   __ shrl(reg, 16);
   594   __ negptr(reg);
   595 }
   598 void TemplateTable::wide_iload() {
   599   transition(vtos, itos);
   600   locals_index_wide(rbx);
   601   __ movl(rax, iaddress(rbx));
   602 }
   605 void TemplateTable::wide_lload() {
   606   transition(vtos, ltos);
   607   locals_index_wide(rbx);
   608   __ movptr(rax, laddress(rbx));
   609   NOT_LP64(__ movl(rdx, haddress(rbx)));
   610 }
   613 void TemplateTable::wide_fload() {
   614   transition(vtos, ftos);
   615   locals_index_wide(rbx);
   616   __ fld_s(faddress(rbx));
   617 }
   620 void TemplateTable::wide_dload() {
   621   transition(vtos, dtos);
   622   locals_index_wide(rbx);
   623   __ fld_d(daddress(rbx));
   624 }
   627 void TemplateTable::wide_aload() {
   628   transition(vtos, atos);
   629   locals_index_wide(rbx);
   630   __ movptr(rax, aaddress(rbx));
   631 }
   633 void TemplateTable::index_check(Register array, Register index) {
   634   // Pop ptr into array
   635   __ pop_ptr(array);
   636   index_check_without_pop(array, index);
   637 }
   639 void TemplateTable::index_check_without_pop(Register array, Register index) {
   640   // destroys rbx,
   641   // check array
   642   __ null_check(array, arrayOopDesc::length_offset_in_bytes());
   643   LP64_ONLY(__ movslq(index, index));
   644   // check index
   645   __ cmpl(index, Address(array, arrayOopDesc::length_offset_in_bytes()));
   646   if (index != rbx) {
   647     // ??? convention: move aberrant index into rbx, for exception message
   648     assert(rbx != array, "different registers");
   649     __ mov(rbx, index);
   650   }
   651   __ jump_cc(Assembler::aboveEqual,
   652              ExternalAddress(Interpreter::_throw_ArrayIndexOutOfBoundsException_entry));
   653 }
   656 void TemplateTable::iaload() {
   657   transition(itos, itos);
   658   // rdx: array
   659   index_check(rdx, rax);  // kills rbx,
   660   // rax,: index
   661   __ movl(rax, Address(rdx, rax, Address::times_4, arrayOopDesc::base_offset_in_bytes(T_INT)));
   662 }
   665 void TemplateTable::laload() {
   666   transition(itos, ltos);
   667   // rax,: index
   668   // rdx: array
   669   index_check(rdx, rax);
   670   __ mov(rbx, rax);
   671   // rbx,: index
   672   __ movptr(rax, Address(rdx, rbx, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_LONG) + 0 * wordSize));
   673   NOT_LP64(__ movl(rdx, Address(rdx, rbx, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_LONG) + 1 * wordSize)));
   674 }
   677 void TemplateTable::faload() {
   678   transition(itos, ftos);
   679   // rdx: array
   680   index_check(rdx, rax);  // kills rbx,
   681   // rax,: index
   682   __ fld_s(Address(rdx, rax, Address::times_4, arrayOopDesc::base_offset_in_bytes(T_FLOAT)));
   683 }
   686 void TemplateTable::daload() {
   687   transition(itos, dtos);
   688   // rdx: array
   689   index_check(rdx, rax);  // kills rbx,
   690   // rax,: index
   691   __ fld_d(Address(rdx, rax, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_DOUBLE)));
   692 }
   695 void TemplateTable::aaload() {
   696   transition(itos, atos);
   697   // rdx: array
   698   index_check(rdx, rax);  // kills rbx,
   699   // rax,: index
   700   __ movptr(rax, Address(rdx, rax, Address::times_ptr, arrayOopDesc::base_offset_in_bytes(T_OBJECT)));
   701 }
   704 void TemplateTable::baload() {
   705   transition(itos, itos);
   706   // rdx: array
   707   index_check(rdx, rax);  // kills rbx,
   708   // rax,: index
   709   // can do better code for P5 - fix this at some point
   710   __ load_signed_byte(rbx, Address(rdx, rax, Address::times_1, arrayOopDesc::base_offset_in_bytes(T_BYTE)));
   711   __ mov(rax, rbx);
   712 }
   715 void TemplateTable::caload() {
   716   transition(itos, itos);
   717   // rdx: array
   718   index_check(rdx, rax);  // kills rbx,
   719   // rax,: index
   720   // can do better code for P5 - may want to improve this at some point
   721   __ load_unsigned_short(rbx, Address(rdx, rax, Address::times_2, arrayOopDesc::base_offset_in_bytes(T_CHAR)));
   722   __ mov(rax, rbx);
   723 }
   725 // iload followed by caload frequent pair
   726 void TemplateTable::fast_icaload() {
   727   transition(vtos, itos);
   728   // load index out of locals
   729   locals_index(rbx);
   730   __ movl(rax, iaddress(rbx));
   732   // rdx: array
   733   index_check(rdx, rax);
   734   // rax,: index
   735   __ load_unsigned_short(rbx, Address(rdx, rax, Address::times_2, arrayOopDesc::base_offset_in_bytes(T_CHAR)));
   736   __ mov(rax, rbx);
   737 }
   739 void TemplateTable::saload() {
   740   transition(itos, itos);
   741   // rdx: array
   742   index_check(rdx, rax);  // kills rbx,
   743   // rax,: index
   744   // can do better code for P5 - may want to improve this at some point
   745   __ load_signed_short(rbx, Address(rdx, rax, Address::times_2, arrayOopDesc::base_offset_in_bytes(T_SHORT)));
   746   __ mov(rax, rbx);
   747 }
   750 void TemplateTable::iload(int n) {
   751   transition(vtos, itos);
   752   __ movl(rax, iaddress(n));
   753 }
   756 void TemplateTable::lload(int n) {
   757   transition(vtos, ltos);
   758   __ movptr(rax, laddress(n));
   759   NOT_LP64(__ movptr(rdx, haddress(n)));
   760 }
   763 void TemplateTable::fload(int n) {
   764   transition(vtos, ftos);
   765   __ fld_s(faddress(n));
   766 }
   769 void TemplateTable::dload(int n) {
   770   transition(vtos, dtos);
   771   __ fld_d(daddress(n));
   772 }
   775 void TemplateTable::aload(int n) {
   776   transition(vtos, atos);
   777   __ movptr(rax, aaddress(n));
   778 }
   781 void TemplateTable::aload_0() {
   782   transition(vtos, atos);
   783   // According to bytecode histograms, the pairs:
   784   //
   785   // _aload_0, _fast_igetfield
   786   // _aload_0, _fast_agetfield
   787   // _aload_0, _fast_fgetfield
   788   //
   789   // occur frequently. If RewriteFrequentPairs is set, the (slow) _aload_0
   790   // bytecode checks if the next bytecode is either _fast_igetfield,
   791   // _fast_agetfield or _fast_fgetfield and then rewrites the
   792   // current bytecode into a pair bytecode; otherwise it rewrites the current
   793   // bytecode into _fast_aload_0 that doesn't do the pair check anymore.
   794   //
   795   // Note: If the next bytecode is _getfield, the rewrite must be delayed,
   796   //       otherwise we may miss an opportunity for a pair.
   797   //
   798   // Also rewrite frequent pairs
   799   //   aload_0, aload_1
   800   //   aload_0, iload_1
   801   // These bytecodes with a small amount of code are most profitable to rewrite
   802   if (RewriteFrequentPairs) {
   803     Label rewrite, done;
   804     // get next byte
   805     __ load_unsigned_byte(rbx, at_bcp(Bytecodes::length_for(Bytecodes::_aload_0)));
   807     // do actual aload_0
   808     aload(0);
   810     // if _getfield then wait with rewrite
   811     __ cmpl(rbx, Bytecodes::_getfield);
   812     __ jcc(Assembler::equal, done);
   814     // if _igetfield then reqrite to _fast_iaccess_0
   815     assert(Bytecodes::java_code(Bytecodes::_fast_iaccess_0) == Bytecodes::_aload_0, "fix bytecode definition");
   816     __ cmpl(rbx, Bytecodes::_fast_igetfield);
   817     __ movl(rcx, Bytecodes::_fast_iaccess_0);
   818     __ jccb(Assembler::equal, rewrite);
   820     // if _agetfield then reqrite to _fast_aaccess_0
   821     assert(Bytecodes::java_code(Bytecodes::_fast_aaccess_0) == Bytecodes::_aload_0, "fix bytecode definition");
   822     __ cmpl(rbx, Bytecodes::_fast_agetfield);
   823     __ movl(rcx, Bytecodes::_fast_aaccess_0);
   824     __ jccb(Assembler::equal, rewrite);
   826     // if _fgetfield then reqrite to _fast_faccess_0
   827     assert(Bytecodes::java_code(Bytecodes::_fast_faccess_0) == Bytecodes::_aload_0, "fix bytecode definition");
   828     __ cmpl(rbx, Bytecodes::_fast_fgetfield);
   829     __ movl(rcx, Bytecodes::_fast_faccess_0);
   830     __ jccb(Assembler::equal, rewrite);
   832     // else rewrite to _fast_aload0
   833     assert(Bytecodes::java_code(Bytecodes::_fast_aload_0) == Bytecodes::_aload_0, "fix bytecode definition");
   834     __ movl(rcx, Bytecodes::_fast_aload_0);
   836     // rewrite
   837     // rcx: fast bytecode
   838     __ bind(rewrite);
   839     patch_bytecode(Bytecodes::_aload_0, rcx, rbx, false);
   841     __ bind(done);
   842   } else {
   843     aload(0);
   844   }
   845 }
   847 void TemplateTable::istore() {
   848   transition(itos, vtos);
   849   locals_index(rbx);
   850   __ movl(iaddress(rbx), rax);
   851 }
   854 void TemplateTable::lstore() {
   855   transition(ltos, vtos);
   856   locals_index(rbx);
   857   __ movptr(laddress(rbx), rax);
   858   NOT_LP64(__ movptr(haddress(rbx), rdx));
   859 }
   862 void TemplateTable::fstore() {
   863   transition(ftos, vtos);
   864   locals_index(rbx);
   865   __ fstp_s(faddress(rbx));
   866 }
   869 void TemplateTable::dstore() {
   870   transition(dtos, vtos);
   871   locals_index(rbx);
   872   __ fstp_d(daddress(rbx));
   873 }
   876 void TemplateTable::astore() {
   877   transition(vtos, vtos);
   878   __ pop_ptr(rax);
   879   locals_index(rbx);
   880   __ movptr(aaddress(rbx), rax);
   881 }
   884 void TemplateTable::wide_istore() {
   885   transition(vtos, vtos);
   886   __ pop_i(rax);
   887   locals_index_wide(rbx);
   888   __ movl(iaddress(rbx), rax);
   889 }
   892 void TemplateTable::wide_lstore() {
   893   transition(vtos, vtos);
   894   __ pop_l(rax, rdx);
   895   locals_index_wide(rbx);
   896   __ movptr(laddress(rbx), rax);
   897   NOT_LP64(__ movl(haddress(rbx), rdx));
   898 }
   901 void TemplateTable::wide_fstore() {
   902   wide_istore();
   903 }
   906 void TemplateTable::wide_dstore() {
   907   wide_lstore();
   908 }
   911 void TemplateTable::wide_astore() {
   912   transition(vtos, vtos);
   913   __ pop_ptr(rax);
   914   locals_index_wide(rbx);
   915   __ movptr(aaddress(rbx), rax);
   916 }
   919 void TemplateTable::iastore() {
   920   transition(itos, vtos);
   921   __ pop_i(rbx);
   922   // rax,: value
   923   // rdx: array
   924   index_check(rdx, rbx);  // prefer index in rbx,
   925   // rbx,: index
   926   __ movl(Address(rdx, rbx, Address::times_4, arrayOopDesc::base_offset_in_bytes(T_INT)), rax);
   927 }
   930 void TemplateTable::lastore() {
   931   transition(ltos, vtos);
   932   __ pop_i(rbx);
   933   // rax,: low(value)
   934   // rcx: array
   935   // rdx: high(value)
   936   index_check(rcx, rbx);  // prefer index in rbx,
   937   // rbx,: index
   938   __ movptr(Address(rcx, rbx, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_LONG) + 0 * wordSize), rax);
   939   NOT_LP64(__ movl(Address(rcx, rbx, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_LONG) + 1 * wordSize), rdx));
   940 }
   943 void TemplateTable::fastore() {
   944   transition(ftos, vtos);
   945   __ pop_i(rbx);
   946   // rdx: array
   947   // st0: value
   948   index_check(rdx, rbx);  // prefer index in rbx,
   949   // rbx,: index
   950   __ fstp_s(Address(rdx, rbx, Address::times_4, arrayOopDesc::base_offset_in_bytes(T_FLOAT)));
   951 }
   954 void TemplateTable::dastore() {
   955   transition(dtos, vtos);
   956   __ pop_i(rbx);
   957   // rdx: array
   958   // st0: value
   959   index_check(rdx, rbx);  // prefer index in rbx,
   960   // rbx,: index
   961   __ fstp_d(Address(rdx, rbx, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_DOUBLE)));
   962 }
   965 void TemplateTable::aastore() {
   966   Label is_null, ok_is_subtype, done;
   967   transition(vtos, vtos);
   968   // stack: ..., array, index, value
   969   __ movptr(rax, at_tos());     // Value
   970   __ movl(rcx, at_tos_p1());  // Index
   971   __ movptr(rdx, at_tos_p2());  // Array
   973   Address element_address(rdx, rcx, Address::times_4, arrayOopDesc::base_offset_in_bytes(T_OBJECT));
   974   index_check_without_pop(rdx, rcx);      // kills rbx,
   975   // do array store check - check for NULL value first
   976   __ testptr(rax, rax);
   977   __ jcc(Assembler::zero, is_null);
   979   // Move subklass into EBX
   980   __ load_klass(rbx, rax);
   981   // Move superklass into EAX
   982   __ load_klass(rax, rdx);
   983   __ movptr(rax, Address(rax, objArrayKlass::element_klass_offset()));
   984   // Compress array+index*wordSize+12 into a single register.  Frees ECX.
   985   __ lea(rdx, element_address);
   987   // Generate subtype check.  Blows ECX.  Resets EDI to locals.
   988   // Superklass in EAX.  Subklass in EBX.
   989   __ gen_subtype_check( rbx, ok_is_subtype );
   991   // Come here on failure
   992   // object is at TOS
   993   __ jump(ExternalAddress(Interpreter::_throw_ArrayStoreException_entry));
   995   // Come here on success
   996   __ bind(ok_is_subtype);
   998   // Get the value to store
   999   __ movptr(rax, at_rsp());
  1000   // and store it with appropriate barrier
  1001   do_oop_store(_masm, Address(rdx, 0), rax, _bs->kind(), true);
  1003   __ jmp(done);
  1005   // Have a NULL in EAX, EDX=array, ECX=index.  Store NULL at ary[idx]
  1006   __ bind(is_null);
  1007   __ profile_null_seen(rbx);
  1009   // Store NULL, (noreg means NULL to do_oop_store)
  1010   do_oop_store(_masm, element_address, noreg, _bs->kind(), true);
  1012   // Pop stack arguments
  1013   __ bind(done);
  1014   __ addptr(rsp, 3 * Interpreter::stackElementSize);
  1018 void TemplateTable::bastore() {
  1019   transition(itos, vtos);
  1020   __ pop_i(rbx);
  1021   // rax,: value
  1022   // rdx: array
  1023   index_check(rdx, rbx);  // prefer index in rbx,
  1024   // rbx,: index
  1025   __ movb(Address(rdx, rbx, Address::times_1, arrayOopDesc::base_offset_in_bytes(T_BYTE)), rax);
  1029 void TemplateTable::castore() {
  1030   transition(itos, vtos);
  1031   __ pop_i(rbx);
  1032   // rax,: value
  1033   // rdx: array
  1034   index_check(rdx, rbx);  // prefer index in rbx,
  1035   // rbx,: index
  1036   __ movw(Address(rdx, rbx, Address::times_2, arrayOopDesc::base_offset_in_bytes(T_CHAR)), rax);
  1040 void TemplateTable::sastore() {
  1041   castore();
  1045 void TemplateTable::istore(int n) {
  1046   transition(itos, vtos);
  1047   __ movl(iaddress(n), rax);
  1051 void TemplateTable::lstore(int n) {
  1052   transition(ltos, vtos);
  1053   __ movptr(laddress(n), rax);
  1054   NOT_LP64(__ movptr(haddress(n), rdx));
  1058 void TemplateTable::fstore(int n) {
  1059   transition(ftos, vtos);
  1060   __ fstp_s(faddress(n));
  1064 void TemplateTable::dstore(int n) {
  1065   transition(dtos, vtos);
  1066   __ fstp_d(daddress(n));
  1070 void TemplateTable::astore(int n) {
  1071   transition(vtos, vtos);
  1072   __ pop_ptr(rax);
  1073   __ movptr(aaddress(n), rax);
  1077 void TemplateTable::pop() {
  1078   transition(vtos, vtos);
  1079   __ addptr(rsp, Interpreter::stackElementSize);
  1083 void TemplateTable::pop2() {
  1084   transition(vtos, vtos);
  1085   __ addptr(rsp, 2*Interpreter::stackElementSize);
  1089 void TemplateTable::dup() {
  1090   transition(vtos, vtos);
  1091   // stack: ..., a
  1092   __ load_ptr(0, rax);
  1093   __ push_ptr(rax);
  1094   // stack: ..., a, a
  1098 void TemplateTable::dup_x1() {
  1099   transition(vtos, vtos);
  1100   // stack: ..., a, b
  1101   __ load_ptr( 0, rax);  // load b
  1102   __ load_ptr( 1, rcx);  // load a
  1103   __ store_ptr(1, rax);  // store b
  1104   __ store_ptr(0, rcx);  // store a
  1105   __ push_ptr(rax);      // push b
  1106   // stack: ..., b, a, b
  1110 void TemplateTable::dup_x2() {
  1111   transition(vtos, vtos);
  1112   // stack: ..., a, b, c
  1113   __ load_ptr( 0, rax);  // load c
  1114   __ load_ptr( 2, rcx);  // load a
  1115   __ store_ptr(2, rax);  // store c in a
  1116   __ push_ptr(rax);      // push c
  1117   // stack: ..., c, b, c, c
  1118   __ load_ptr( 2, rax);  // load b
  1119   __ store_ptr(2, rcx);  // store a in b
  1120   // stack: ..., c, a, c, c
  1121   __ store_ptr(1, rax);  // store b in c
  1122   // stack: ..., c, a, b, c
  1126 void TemplateTable::dup2() {
  1127   transition(vtos, vtos);
  1128   // stack: ..., a, b
  1129   __ load_ptr(1, rax);  // load a
  1130   __ push_ptr(rax);     // push a
  1131   __ load_ptr(1, rax);  // load b
  1132   __ push_ptr(rax);     // push b
  1133   // stack: ..., a, b, a, b
  1137 void TemplateTable::dup2_x1() {
  1138   transition(vtos, vtos);
  1139   // stack: ..., a, b, c
  1140   __ load_ptr( 0, rcx);  // load c
  1141   __ load_ptr( 1, rax);  // load b
  1142   __ push_ptr(rax);      // push b
  1143   __ push_ptr(rcx);      // push c
  1144   // stack: ..., a, b, c, b, c
  1145   __ store_ptr(3, rcx);  // store c in b
  1146   // stack: ..., a, c, c, b, c
  1147   __ load_ptr( 4, rcx);  // load a
  1148   __ store_ptr(2, rcx);  // store a in 2nd c
  1149   // stack: ..., a, c, a, b, c
  1150   __ store_ptr(4, rax);  // store b in a
  1151   // stack: ..., b, c, a, b, c
  1152   // stack: ..., b, c, a, b, c
  1156 void TemplateTable::dup2_x2() {
  1157   transition(vtos, vtos);
  1158   // stack: ..., a, b, c, d
  1159   __ load_ptr( 0, rcx);  // load d
  1160   __ load_ptr( 1, rax);  // load c
  1161   __ push_ptr(rax);      // push c
  1162   __ push_ptr(rcx);      // push d
  1163   // stack: ..., a, b, c, d, c, d
  1164   __ load_ptr( 4, rax);  // load b
  1165   __ store_ptr(2, rax);  // store b in d
  1166   __ store_ptr(4, rcx);  // store d in b
  1167   // stack: ..., a, d, c, b, c, d
  1168   __ load_ptr( 5, rcx);  // load a
  1169   __ load_ptr( 3, rax);  // load c
  1170   __ store_ptr(3, rcx);  // store a in c
  1171   __ store_ptr(5, rax);  // store c in a
  1172   // stack: ..., c, d, a, b, c, d
  1173   // stack: ..., c, d, a, b, c, d
  1177 void TemplateTable::swap() {
  1178   transition(vtos, vtos);
  1179   // stack: ..., a, b
  1180   __ load_ptr( 1, rcx);  // load a
  1181   __ load_ptr( 0, rax);  // load b
  1182   __ store_ptr(0, rcx);  // store a in b
  1183   __ store_ptr(1, rax);  // store b in a
  1184   // stack: ..., b, a
  1188 void TemplateTable::iop2(Operation op) {
  1189   transition(itos, itos);
  1190   switch (op) {
  1191     case add  :                   __ pop_i(rdx); __ addl (rax, rdx); break;
  1192     case sub  : __ mov(rdx, rax); __ pop_i(rax); __ subl (rax, rdx); break;
  1193     case mul  :                   __ pop_i(rdx); __ imull(rax, rdx); break;
  1194     case _and :                   __ pop_i(rdx); __ andl (rax, rdx); break;
  1195     case _or  :                   __ pop_i(rdx); __ orl  (rax, rdx); break;
  1196     case _xor :                   __ pop_i(rdx); __ xorl (rax, rdx); break;
  1197     case shl  : __ mov(rcx, rax); __ pop_i(rax); __ shll (rax);      break; // implicit masking of lower 5 bits by Intel shift instr.
  1198     case shr  : __ mov(rcx, rax); __ pop_i(rax); __ sarl (rax);      break; // implicit masking of lower 5 bits by Intel shift instr.
  1199     case ushr : __ mov(rcx, rax); __ pop_i(rax); __ shrl (rax);      break; // implicit masking of lower 5 bits by Intel shift instr.
  1200     default   : ShouldNotReachHere();
  1205 void TemplateTable::lop2(Operation op) {
  1206   transition(ltos, ltos);
  1207   __ pop_l(rbx, rcx);
  1208   switch (op) {
  1209     case add  : __ addl(rax, rbx); __ adcl(rdx, rcx); break;
  1210     case sub  : __ subl(rbx, rax); __ sbbl(rcx, rdx);
  1211                 __ mov (rax, rbx); __ mov (rdx, rcx); break;
  1212     case _and : __ andl(rax, rbx); __ andl(rdx, rcx); break;
  1213     case _or  : __ orl (rax, rbx); __ orl (rdx, rcx); break;
  1214     case _xor : __ xorl(rax, rbx); __ xorl(rdx, rcx); break;
  1215     default   : ShouldNotReachHere();
  1220 void TemplateTable::idiv() {
  1221   transition(itos, itos);
  1222   __ mov(rcx, rax);
  1223   __ pop_i(rax);
  1224   // Note: could xor rax, and rcx and compare with (-1 ^ min_int). If
  1225   //       they are not equal, one could do a normal division (no correction
  1226   //       needed), which may speed up this implementation for the common case.
  1227   //       (see also JVM spec., p.243 & p.271)
  1228   __ corrected_idivl(rcx);
  1232 void TemplateTable::irem() {
  1233   transition(itos, itos);
  1234   __ mov(rcx, rax);
  1235   __ pop_i(rax);
  1236   // Note: could xor rax, and rcx and compare with (-1 ^ min_int). If
  1237   //       they are not equal, one could do a normal division (no correction
  1238   //       needed), which may speed up this implementation for the common case.
  1239   //       (see also JVM spec., p.243 & p.271)
  1240   __ corrected_idivl(rcx);
  1241   __ mov(rax, rdx);
  1245 void TemplateTable::lmul() {
  1246   transition(ltos, ltos);
  1247   __ pop_l(rbx, rcx);
  1248   __ push(rcx); __ push(rbx);
  1249   __ push(rdx); __ push(rax);
  1250   __ lmul(2 * wordSize, 0);
  1251   __ addptr(rsp, 4 * wordSize);  // take off temporaries
  1255 void TemplateTable::ldiv() {
  1256   transition(ltos, ltos);
  1257   __ pop_l(rbx, rcx);
  1258   __ push(rcx); __ push(rbx);
  1259   __ push(rdx); __ push(rax);
  1260   // check if y = 0
  1261   __ orl(rax, rdx);
  1262   __ jump_cc(Assembler::zero,
  1263              ExternalAddress(Interpreter::_throw_ArithmeticException_entry));
  1264   __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::ldiv));
  1265   __ addptr(rsp, 4 * wordSize);  // take off temporaries
  1269 void TemplateTable::lrem() {
  1270   transition(ltos, ltos);
  1271   __ pop_l(rbx, rcx);
  1272   __ push(rcx); __ push(rbx);
  1273   __ push(rdx); __ push(rax);
  1274   // check if y = 0
  1275   __ orl(rax, rdx);
  1276   __ jump_cc(Assembler::zero,
  1277              ExternalAddress(Interpreter::_throw_ArithmeticException_entry));
  1278   __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::lrem));
  1279   __ addptr(rsp, 4 * wordSize);
  1283 void TemplateTable::lshl() {
  1284   transition(itos, ltos);
  1285   __ movl(rcx, rax);                             // get shift count
  1286   __ pop_l(rax, rdx);                            // get shift value
  1287   __ lshl(rdx, rax);
  1291 void TemplateTable::lshr() {
  1292   transition(itos, ltos);
  1293   __ mov(rcx, rax);                              // get shift count
  1294   __ pop_l(rax, rdx);                            // get shift value
  1295   __ lshr(rdx, rax, true);
  1299 void TemplateTable::lushr() {
  1300   transition(itos, ltos);
  1301   __ mov(rcx, rax);                              // get shift count
  1302   __ pop_l(rax, rdx);                            // get shift value
  1303   __ lshr(rdx, rax);
  1307 void TemplateTable::fop2(Operation op) {
  1308   transition(ftos, ftos);
  1309   switch (op) {
  1310     case add: __ fadd_s (at_rsp());                break;
  1311     case sub: __ fsubr_s(at_rsp());                break;
  1312     case mul: __ fmul_s (at_rsp());                break;
  1313     case div: __ fdivr_s(at_rsp());                break;
  1314     case rem: __ fld_s  (at_rsp()); __ fremr(rax); break;
  1315     default : ShouldNotReachHere();
  1317   __ f2ieee();
  1318   __ pop(rax);  // pop float thing off
  1322 void TemplateTable::dop2(Operation op) {
  1323   transition(dtos, dtos);
  1325   switch (op) {
  1326     case add: __ fadd_d (at_rsp());                break;
  1327     case sub: __ fsubr_d(at_rsp());                break;
  1328     case mul: {
  1329       Label L_strict;
  1330       Label L_join;
  1331       const Address access_flags      (rcx, methodOopDesc::access_flags_offset());
  1332       __ get_method(rcx);
  1333       __ movl(rcx, access_flags);
  1334       __ testl(rcx, JVM_ACC_STRICT);
  1335       __ jccb(Assembler::notZero, L_strict);
  1336       __ fmul_d (at_rsp());
  1337       __ jmpb(L_join);
  1338       __ bind(L_strict);
  1339       __ fld_x(ExternalAddress(StubRoutines::addr_fpu_subnormal_bias1()));
  1340       __ fmulp();
  1341       __ fmul_d (at_rsp());
  1342       __ fld_x(ExternalAddress(StubRoutines::addr_fpu_subnormal_bias2()));
  1343       __ fmulp();
  1344       __ bind(L_join);
  1345       break;
  1347     case div: {
  1348       Label L_strict;
  1349       Label L_join;
  1350       const Address access_flags      (rcx, methodOopDesc::access_flags_offset());
  1351       __ get_method(rcx);
  1352       __ movl(rcx, access_flags);
  1353       __ testl(rcx, JVM_ACC_STRICT);
  1354       __ jccb(Assembler::notZero, L_strict);
  1355       __ fdivr_d(at_rsp());
  1356       __ jmp(L_join);
  1357       __ bind(L_strict);
  1358       __ fld_x(ExternalAddress(StubRoutines::addr_fpu_subnormal_bias1()));
  1359       __ fmul_d (at_rsp());
  1360       __ fdivrp();
  1361       __ fld_x(ExternalAddress(StubRoutines::addr_fpu_subnormal_bias2()));
  1362       __ fmulp();
  1363       __ bind(L_join);
  1364       break;
  1366     case rem: __ fld_d  (at_rsp()); __ fremr(rax); break;
  1367     default : ShouldNotReachHere();
  1369   __ d2ieee();
  1370   // Pop double precision number from rsp.
  1371   __ pop(rax);
  1372   __ pop(rdx);
  1376 void TemplateTable::ineg() {
  1377   transition(itos, itos);
  1378   __ negl(rax);
  1382 void TemplateTable::lneg() {
  1383   transition(ltos, ltos);
  1384   __ lneg(rdx, rax);
  1388 void TemplateTable::fneg() {
  1389   transition(ftos, ftos);
  1390   __ fchs();
  1394 void TemplateTable::dneg() {
  1395   transition(dtos, dtos);
  1396   __ fchs();
  1400 void TemplateTable::iinc() {
  1401   transition(vtos, vtos);
  1402   __ load_signed_byte(rdx, at_bcp(2));           // get constant
  1403   locals_index(rbx);
  1404   __ addl(iaddress(rbx), rdx);
  1408 void TemplateTable::wide_iinc() {
  1409   transition(vtos, vtos);
  1410   __ movl(rdx, at_bcp(4));                       // get constant
  1411   locals_index_wide(rbx);
  1412   __ bswapl(rdx);                                 // swap bytes & sign-extend constant
  1413   __ sarl(rdx, 16);
  1414   __ addl(iaddress(rbx), rdx);
  1415   // Note: should probably use only one movl to get both
  1416   //       the index and the constant -> fix this
  1420 void TemplateTable::convert() {
  1421   // Checking
  1422 #ifdef ASSERT
  1423   { TosState tos_in  = ilgl;
  1424     TosState tos_out = ilgl;
  1425     switch (bytecode()) {
  1426       case Bytecodes::_i2l: // fall through
  1427       case Bytecodes::_i2f: // fall through
  1428       case Bytecodes::_i2d: // fall through
  1429       case Bytecodes::_i2b: // fall through
  1430       case Bytecodes::_i2c: // fall through
  1431       case Bytecodes::_i2s: tos_in = itos; break;
  1432       case Bytecodes::_l2i: // fall through
  1433       case Bytecodes::_l2f: // fall through
  1434       case Bytecodes::_l2d: tos_in = ltos; break;
  1435       case Bytecodes::_f2i: // fall through
  1436       case Bytecodes::_f2l: // fall through
  1437       case Bytecodes::_f2d: tos_in = ftos; break;
  1438       case Bytecodes::_d2i: // fall through
  1439       case Bytecodes::_d2l: // fall through
  1440       case Bytecodes::_d2f: tos_in = dtos; break;
  1441       default             : ShouldNotReachHere();
  1443     switch (bytecode()) {
  1444       case Bytecodes::_l2i: // fall through
  1445       case Bytecodes::_f2i: // fall through
  1446       case Bytecodes::_d2i: // fall through
  1447       case Bytecodes::_i2b: // fall through
  1448       case Bytecodes::_i2c: // fall through
  1449       case Bytecodes::_i2s: tos_out = itos; break;
  1450       case Bytecodes::_i2l: // fall through
  1451       case Bytecodes::_f2l: // fall through
  1452       case Bytecodes::_d2l: tos_out = ltos; break;
  1453       case Bytecodes::_i2f: // fall through
  1454       case Bytecodes::_l2f: // fall through
  1455       case Bytecodes::_d2f: tos_out = ftos; break;
  1456       case Bytecodes::_i2d: // fall through
  1457       case Bytecodes::_l2d: // fall through
  1458       case Bytecodes::_f2d: tos_out = dtos; break;
  1459       default             : ShouldNotReachHere();
  1461     transition(tos_in, tos_out);
  1463 #endif // ASSERT
  1465   // Conversion
  1466   // (Note: use push(rcx)/pop(rcx) for 1/2-word stack-ptr manipulation)
  1467   switch (bytecode()) {
  1468     case Bytecodes::_i2l:
  1469       __ extend_sign(rdx, rax);
  1470       break;
  1471     case Bytecodes::_i2f:
  1472       __ push(rax);          // store int on tos
  1473       __ fild_s(at_rsp());   // load int to ST0
  1474       __ f2ieee();           // truncate to float size
  1475       __ pop(rcx);           // adjust rsp
  1476       break;
  1477     case Bytecodes::_i2d:
  1478       __ push(rax);          // add one slot for d2ieee()
  1479       __ push(rax);          // store int on tos
  1480       __ fild_s(at_rsp());   // load int to ST0
  1481       __ d2ieee();           // truncate to double size
  1482       __ pop(rcx);           // adjust rsp
  1483       __ pop(rcx);
  1484       break;
  1485     case Bytecodes::_i2b:
  1486       __ shll(rax, 24);      // truncate upper 24 bits
  1487       __ sarl(rax, 24);      // and sign-extend byte
  1488       LP64_ONLY(__ movsbl(rax, rax));
  1489       break;
  1490     case Bytecodes::_i2c:
  1491       __ andl(rax, 0xFFFF);  // truncate upper 16 bits
  1492       LP64_ONLY(__ movzwl(rax, rax));
  1493       break;
  1494     case Bytecodes::_i2s:
  1495       __ shll(rax, 16);      // truncate upper 16 bits
  1496       __ sarl(rax, 16);      // and sign-extend short
  1497       LP64_ONLY(__ movswl(rax, rax));
  1498       break;
  1499     case Bytecodes::_l2i:
  1500       /* nothing to do */
  1501       break;
  1502     case Bytecodes::_l2f:
  1503       __ push(rdx);          // store long on tos
  1504       __ push(rax);
  1505       __ fild_d(at_rsp());   // load long to ST0
  1506       __ f2ieee();           // truncate to float size
  1507       __ pop(rcx);           // adjust rsp
  1508       __ pop(rcx);
  1509       break;
  1510     case Bytecodes::_l2d:
  1511       __ push(rdx);          // store long on tos
  1512       __ push(rax);
  1513       __ fild_d(at_rsp());   // load long to ST0
  1514       __ d2ieee();           // truncate to double size
  1515       __ pop(rcx);           // adjust rsp
  1516       __ pop(rcx);
  1517       break;
  1518     case Bytecodes::_f2i:
  1519       __ push(rcx);          // reserve space for argument
  1520       __ fstp_s(at_rsp());   // pass float argument on stack
  1521       __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::f2i), 1);
  1522       break;
  1523     case Bytecodes::_f2l:
  1524       __ push(rcx);          // reserve space for argument
  1525       __ fstp_s(at_rsp());   // pass float argument on stack
  1526       __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::f2l), 1);
  1527       break;
  1528     case Bytecodes::_f2d:
  1529       /* nothing to do */
  1530       break;
  1531     case Bytecodes::_d2i:
  1532       __ push(rcx);          // reserve space for argument
  1533       __ push(rcx);
  1534       __ fstp_d(at_rsp());   // pass double argument on stack
  1535       __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::d2i), 2);
  1536       break;
  1537     case Bytecodes::_d2l:
  1538       __ push(rcx);          // reserve space for argument
  1539       __ push(rcx);
  1540       __ fstp_d(at_rsp());   // pass double argument on stack
  1541       __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::d2l), 2);
  1542       break;
  1543     case Bytecodes::_d2f:
  1544       __ push(rcx);          // reserve space for f2ieee()
  1545       __ f2ieee();           // truncate to float size
  1546       __ pop(rcx);           // adjust rsp
  1547       break;
  1548     default             :
  1549       ShouldNotReachHere();
  1554 void TemplateTable::lcmp() {
  1555   transition(ltos, itos);
  1556   // y = rdx:rax
  1557   __ pop_l(rbx, rcx);             // get x = rcx:rbx
  1558   __ lcmp2int(rcx, rbx, rdx, rax);// rcx := cmp(x, y)
  1559   __ mov(rax, rcx);
  1563 void TemplateTable::float_cmp(bool is_float, int unordered_result) {
  1564   if (is_float) {
  1565     __ fld_s(at_rsp());
  1566   } else {
  1567     __ fld_d(at_rsp());
  1568     __ pop(rdx);
  1570   __ pop(rcx);
  1571   __ fcmp2int(rax, unordered_result < 0);
  1575 void TemplateTable::branch(bool is_jsr, bool is_wide) {
  1576   __ get_method(rcx);           // ECX holds method
  1577   __ profile_taken_branch(rax,rbx); // EAX holds updated MDP, EBX holds bumped taken count
  1579   const ByteSize be_offset = methodOopDesc::backedge_counter_offset() + InvocationCounter::counter_offset();
  1580   const ByteSize inv_offset = methodOopDesc::invocation_counter_offset() + InvocationCounter::counter_offset();
  1581   const int method_offset = frame::interpreter_frame_method_offset * wordSize;
  1583   // Load up EDX with the branch displacement
  1584   __ movl(rdx, at_bcp(1));
  1585   __ bswapl(rdx);
  1586   if (!is_wide) __ sarl(rdx, 16);
  1587   LP64_ONLY(__ movslq(rdx, rdx));
  1590   // Handle all the JSR stuff here, then exit.
  1591   // It's much shorter and cleaner than intermingling with the
  1592   // non-JSR normal-branch stuff occurring below.
  1593   if (is_jsr) {
  1594     // Pre-load the next target bytecode into EBX
  1595     __ load_unsigned_byte(rbx, Address(rsi, rdx, Address::times_1, 0));
  1597     // compute return address as bci in rax,
  1598     __ lea(rax, at_bcp((is_wide ? 5 : 3) - in_bytes(constMethodOopDesc::codes_offset())));
  1599     __ subptr(rax, Address(rcx, methodOopDesc::const_offset()));
  1600     // Adjust the bcp in RSI by the displacement in EDX
  1601     __ addptr(rsi, rdx);
  1602     // Push return address
  1603     __ push_i(rax);
  1604     // jsr returns vtos
  1605     __ dispatch_only_noverify(vtos);
  1606     return;
  1609   // Normal (non-jsr) branch handling
  1611   // Adjust the bcp in RSI by the displacement in EDX
  1612   __ addptr(rsi, rdx);
  1614   assert(UseLoopCounter || !UseOnStackReplacement, "on-stack-replacement requires loop counters");
  1615   Label backedge_counter_overflow;
  1616   Label profile_method;
  1617   Label dispatch;
  1618   if (UseLoopCounter) {
  1619     // increment backedge counter for backward branches
  1620     // rax,: MDO
  1621     // rbx,: MDO bumped taken-count
  1622     // rcx: method
  1623     // rdx: target offset
  1624     // rsi: target bcp
  1625     // rdi: locals pointer
  1626     __ testl(rdx, rdx);             // check if forward or backward branch
  1627     __ jcc(Assembler::positive, dispatch); // count only if backward branch
  1629     if (TieredCompilation) {
  1630       Label no_mdo;
  1631       int increment = InvocationCounter::count_increment;
  1632       int mask = ((1 << Tier0BackedgeNotifyFreqLog) - 1) << InvocationCounter::count_shift;
  1633       if (ProfileInterpreter) {
  1634         // Are we profiling?
  1635         __ movptr(rbx, Address(rcx, in_bytes(methodOopDesc::method_data_offset())));
  1636         __ testptr(rbx, rbx);
  1637         __ jccb(Assembler::zero, no_mdo);
  1638         // Increment the MDO backedge counter
  1639         const Address mdo_backedge_counter(rbx, in_bytes(methodDataOopDesc::backedge_counter_offset()) +
  1640                                                 in_bytes(InvocationCounter::counter_offset()));
  1641         __ increment_mask_and_jump(mdo_backedge_counter, increment, mask,
  1642                                    rax, false, Assembler::zero, &backedge_counter_overflow);
  1643         __ jmp(dispatch);
  1645       __ bind(no_mdo);
  1646       // Increment backedge counter in methodOop
  1647       __ increment_mask_and_jump(Address(rcx, be_offset), increment, mask,
  1648                                  rax, false, Assembler::zero, &backedge_counter_overflow);
  1649     } else {
  1650       // increment counter
  1651       __ movl(rax, Address(rcx, be_offset));        // load backedge counter
  1652       __ incrementl(rax, InvocationCounter::count_increment); // increment counter
  1653       __ movl(Address(rcx, be_offset), rax);        // store counter
  1655       __ movl(rax, Address(rcx, inv_offset));    // load invocation counter
  1656       __ andl(rax, InvocationCounter::count_mask_value);     // and the status bits
  1657       __ addl(rax, Address(rcx, be_offset));        // add both counters
  1659       if (ProfileInterpreter) {
  1660         // Test to see if we should create a method data oop
  1661         __ cmp32(rax,
  1662                  ExternalAddress((address) &InvocationCounter::InterpreterProfileLimit));
  1663         __ jcc(Assembler::less, dispatch);
  1665         // if no method data exists, go to profile method
  1666         __ test_method_data_pointer(rax, profile_method);
  1668         if (UseOnStackReplacement) {
  1669           // check for overflow against rbx, which is the MDO taken count
  1670           __ cmp32(rbx,
  1671                    ExternalAddress((address) &InvocationCounter::InterpreterBackwardBranchLimit));
  1672           __ jcc(Assembler::below, dispatch);
  1674           // When ProfileInterpreter is on, the backedge_count comes from the
  1675           // methodDataOop, which value does not get reset on the call to
  1676           // frequency_counter_overflow().  To avoid excessive calls to the overflow
  1677           // routine while the method is being compiled, add a second test to make
  1678           // sure the overflow function is called only once every overflow_frequency.
  1679           const int overflow_frequency = 1024;
  1680           __ andptr(rbx, overflow_frequency-1);
  1681           __ jcc(Assembler::zero, backedge_counter_overflow);
  1683       } else {
  1684         if (UseOnStackReplacement) {
  1685           // check for overflow against rax, which is the sum of the counters
  1686           __ cmp32(rax,
  1687                    ExternalAddress((address) &InvocationCounter::InterpreterBackwardBranchLimit));
  1688           __ jcc(Assembler::aboveEqual, backedge_counter_overflow);
  1693     __ bind(dispatch);
  1696   // Pre-load the next target bytecode into EBX
  1697   __ load_unsigned_byte(rbx, Address(rsi, 0));
  1699   // continue with the bytecode @ target
  1700   // rax,: return bci for jsr's, unused otherwise
  1701   // rbx,: target bytecode
  1702   // rsi: target bcp
  1703   __ dispatch_only(vtos);
  1705   if (UseLoopCounter) {
  1706     if (ProfileInterpreter) {
  1707       // Out-of-line code to allocate method data oop.
  1708       __ bind(profile_method);
  1709       __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::profile_method));
  1710       __ load_unsigned_byte(rbx, Address(rsi, 0));  // restore target bytecode
  1711       __ set_method_data_pointer_for_bcp();
  1712       __ jmp(dispatch);
  1715     if (UseOnStackReplacement) {
  1717       // invocation counter overflow
  1718       __ bind(backedge_counter_overflow);
  1719       __ negptr(rdx);
  1720       __ addptr(rdx, rsi);        // branch bcp
  1721       call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow), rdx);
  1722       __ load_unsigned_byte(rbx, Address(rsi, 0));  // restore target bytecode
  1724       // rax,: osr nmethod (osr ok) or NULL (osr not possible)
  1725       // rbx,: target bytecode
  1726       // rdx: scratch
  1727       // rdi: locals pointer
  1728       // rsi: bcp
  1729       __ testptr(rax, rax);                      // test result
  1730       __ jcc(Assembler::zero, dispatch);         // no osr if null
  1731       // nmethod may have been invalidated (VM may block upon call_VM return)
  1732       __ movl(rcx, Address(rax, nmethod::entry_bci_offset()));
  1733       __ cmpl(rcx, InvalidOSREntryBci);
  1734       __ jcc(Assembler::equal, dispatch);
  1736       // We have the address of an on stack replacement routine in rax,
  1737       // We need to prepare to execute the OSR method. First we must
  1738       // migrate the locals and monitors off of the stack.
  1740       __ mov(rbx, rax);                             // save the nmethod
  1742       const Register thread = rcx;
  1743       __ get_thread(thread);
  1744       call_VM(noreg, CAST_FROM_FN_PTR(address, SharedRuntime::OSR_migration_begin));
  1745       // rax, is OSR buffer, move it to expected parameter location
  1746       __ mov(rcx, rax);
  1748       // pop the interpreter frame
  1749       __ movptr(rdx, Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize)); // get sender sp
  1750       __ leave();                                // remove frame anchor
  1751       __ pop(rdi);                               // get return address
  1752       __ mov(rsp, rdx);                          // set sp to sender sp
  1754       // Align stack pointer for compiled code (note that caller is
  1755       // responsible for undoing this fixup by remembering the old SP
  1756       // in an rbp,-relative location)
  1757       __ andptr(rsp, -(StackAlignmentInBytes));
  1759       // push the (possibly adjusted) return address
  1760       __ push(rdi);
  1762       // and begin the OSR nmethod
  1763       __ jmp(Address(rbx, nmethod::osr_entry_point_offset()));
  1769 void TemplateTable::if_0cmp(Condition cc) {
  1770   transition(itos, vtos);
  1771   // assume branch is more often taken than not (loops use backward branches)
  1772   Label not_taken;
  1773   __ testl(rax, rax);
  1774   __ jcc(j_not(cc), not_taken);
  1775   branch(false, false);
  1776   __ bind(not_taken);
  1777   __ profile_not_taken_branch(rax);
  1781 void TemplateTable::if_icmp(Condition cc) {
  1782   transition(itos, vtos);
  1783   // assume branch is more often taken than not (loops use backward branches)
  1784   Label not_taken;
  1785   __ pop_i(rdx);
  1786   __ cmpl(rdx, rax);
  1787   __ jcc(j_not(cc), not_taken);
  1788   branch(false, false);
  1789   __ bind(not_taken);
  1790   __ profile_not_taken_branch(rax);
  1794 void TemplateTable::if_nullcmp(Condition cc) {
  1795   transition(atos, vtos);
  1796   // assume branch is more often taken than not (loops use backward branches)
  1797   Label not_taken;
  1798   __ testptr(rax, rax);
  1799   __ jcc(j_not(cc), not_taken);
  1800   branch(false, false);
  1801   __ bind(not_taken);
  1802   __ profile_not_taken_branch(rax);
  1806 void TemplateTable::if_acmp(Condition cc) {
  1807   transition(atos, vtos);
  1808   // assume branch is more often taken than not (loops use backward branches)
  1809   Label not_taken;
  1810   __ pop_ptr(rdx);
  1811   __ cmpptr(rdx, rax);
  1812   __ jcc(j_not(cc), not_taken);
  1813   branch(false, false);
  1814   __ bind(not_taken);
  1815   __ profile_not_taken_branch(rax);
  1819 void TemplateTable::ret() {
  1820   transition(vtos, vtos);
  1821   locals_index(rbx);
  1822   __ movptr(rbx, iaddress(rbx));                   // get return bci, compute return bcp
  1823   __ profile_ret(rbx, rcx);
  1824   __ get_method(rax);
  1825   __ movptr(rsi, Address(rax, methodOopDesc::const_offset()));
  1826   __ lea(rsi, Address(rsi, rbx, Address::times_1,
  1827                       constMethodOopDesc::codes_offset()));
  1828   __ dispatch_next(vtos);
  1832 void TemplateTable::wide_ret() {
  1833   transition(vtos, vtos);
  1834   locals_index_wide(rbx);
  1835   __ movptr(rbx, iaddress(rbx));                   // get return bci, compute return bcp
  1836   __ profile_ret(rbx, rcx);
  1837   __ get_method(rax);
  1838   __ movptr(rsi, Address(rax, methodOopDesc::const_offset()));
  1839   __ lea(rsi, Address(rsi, rbx, Address::times_1, constMethodOopDesc::codes_offset()));
  1840   __ dispatch_next(vtos);
  1844 void TemplateTable::tableswitch() {
  1845   Label default_case, continue_execution;
  1846   transition(itos, vtos);
  1847   // align rsi
  1848   __ lea(rbx, at_bcp(wordSize));
  1849   __ andptr(rbx, -wordSize);
  1850   // load lo & hi
  1851   __ movl(rcx, Address(rbx, 1 * wordSize));
  1852   __ movl(rdx, Address(rbx, 2 * wordSize));
  1853   __ bswapl(rcx);
  1854   __ bswapl(rdx);
  1855   // check against lo & hi
  1856   __ cmpl(rax, rcx);
  1857   __ jccb(Assembler::less, default_case);
  1858   __ cmpl(rax, rdx);
  1859   __ jccb(Assembler::greater, default_case);
  1860   // lookup dispatch offset
  1861   __ subl(rax, rcx);
  1862   __ movl(rdx, Address(rbx, rax, Address::times_4, 3 * BytesPerInt));
  1863   __ profile_switch_case(rax, rbx, rcx);
  1864   // continue execution
  1865   __ bind(continue_execution);
  1866   __ bswapl(rdx);
  1867   __ load_unsigned_byte(rbx, Address(rsi, rdx, Address::times_1));
  1868   __ addptr(rsi, rdx);
  1869   __ dispatch_only(vtos);
  1870   // handle default
  1871   __ bind(default_case);
  1872   __ profile_switch_default(rax);
  1873   __ movl(rdx, Address(rbx, 0));
  1874   __ jmp(continue_execution);
  1878 void TemplateTable::lookupswitch() {
  1879   transition(itos, itos);
  1880   __ stop("lookupswitch bytecode should have been rewritten");
  1884 void TemplateTable::fast_linearswitch() {
  1885   transition(itos, vtos);
  1886   Label loop_entry, loop, found, continue_execution;
  1887   // bswapl rax, so we can avoid bswapping the table entries
  1888   __ bswapl(rax);
  1889   // align rsi
  1890   __ lea(rbx, at_bcp(wordSize));                // btw: should be able to get rid of this instruction (change offsets below)
  1891   __ andptr(rbx, -wordSize);
  1892   // set counter
  1893   __ movl(rcx, Address(rbx, wordSize));
  1894   __ bswapl(rcx);
  1895   __ jmpb(loop_entry);
  1896   // table search
  1897   __ bind(loop);
  1898   __ cmpl(rax, Address(rbx, rcx, Address::times_8, 2 * wordSize));
  1899   __ jccb(Assembler::equal, found);
  1900   __ bind(loop_entry);
  1901   __ decrementl(rcx);
  1902   __ jcc(Assembler::greaterEqual, loop);
  1903   // default case
  1904   __ profile_switch_default(rax);
  1905   __ movl(rdx, Address(rbx, 0));
  1906   __ jmpb(continue_execution);
  1907   // entry found -> get offset
  1908   __ bind(found);
  1909   __ movl(rdx, Address(rbx, rcx, Address::times_8, 3 * wordSize));
  1910   __ profile_switch_case(rcx, rax, rbx);
  1911   // continue execution
  1912   __ bind(continue_execution);
  1913   __ bswapl(rdx);
  1914   __ load_unsigned_byte(rbx, Address(rsi, rdx, Address::times_1));
  1915   __ addptr(rsi, rdx);
  1916   __ dispatch_only(vtos);
  1920 void TemplateTable::fast_binaryswitch() {
  1921   transition(itos, vtos);
  1922   // Implementation using the following core algorithm:
  1923   //
  1924   // int binary_search(int key, LookupswitchPair* array, int n) {
  1925   //   // Binary search according to "Methodik des Programmierens" by
  1926   //   // Edsger W. Dijkstra and W.H.J. Feijen, Addison Wesley Germany 1985.
  1927   //   int i = 0;
  1928   //   int j = n;
  1929   //   while (i+1 < j) {
  1930   //     // invariant P: 0 <= i < j <= n and (a[i] <= key < a[j] or Q)
  1931   //     // with      Q: for all i: 0 <= i < n: key < a[i]
  1932   //     // where a stands for the array and assuming that the (inexisting)
  1933   //     // element a[n] is infinitely big.
  1934   //     int h = (i + j) >> 1;
  1935   //     // i < h < j
  1936   //     if (key < array[h].fast_match()) {
  1937   //       j = h;
  1938   //     } else {
  1939   //       i = h;
  1940   //     }
  1941   //   }
  1942   //   // R: a[i] <= key < a[i+1] or Q
  1943   //   // (i.e., if key is within array, i is the correct index)
  1944   //   return i;
  1945   // }
  1947   // register allocation
  1948   const Register key   = rax;                    // already set (tosca)
  1949   const Register array = rbx;
  1950   const Register i     = rcx;
  1951   const Register j     = rdx;
  1952   const Register h     = rdi;                    // needs to be restored
  1953   const Register temp  = rsi;
  1954   // setup array
  1955   __ save_bcp();
  1957   __ lea(array, at_bcp(3*wordSize));             // btw: should be able to get rid of this instruction (change offsets below)
  1958   __ andptr(array, -wordSize);
  1959   // initialize i & j
  1960   __ xorl(i, i);                                 // i = 0;
  1961   __ movl(j, Address(array, -wordSize));         // j = length(array);
  1962   // Convert j into native byteordering
  1963   __ bswapl(j);
  1964   // and start
  1965   Label entry;
  1966   __ jmp(entry);
  1968   // binary search loop
  1969   { Label loop;
  1970     __ bind(loop);
  1971     // int h = (i + j) >> 1;
  1972     __ leal(h, Address(i, j, Address::times_1)); // h = i + j;
  1973     __ sarl(h, 1);                               // h = (i + j) >> 1;
  1974     // if (key < array[h].fast_match()) {
  1975     //   j = h;
  1976     // } else {
  1977     //   i = h;
  1978     // }
  1979     // Convert array[h].match to native byte-ordering before compare
  1980     __ movl(temp, Address(array, h, Address::times_8, 0*wordSize));
  1981     __ bswapl(temp);
  1982     __ cmpl(key, temp);
  1983     // j = h if (key <  array[h].fast_match())
  1984     __ cmov32(Assembler::less        , j, h);
  1985     // i = h if (key >= array[h].fast_match())
  1986     __ cmov32(Assembler::greaterEqual, i, h);
  1987     // while (i+1 < j)
  1988     __ bind(entry);
  1989     __ leal(h, Address(i, 1));                   // i+1
  1990     __ cmpl(h, j);                               // i+1 < j
  1991     __ jcc(Assembler::less, loop);
  1994   // end of binary search, result index is i (must check again!)
  1995   Label default_case;
  1996   // Convert array[i].match to native byte-ordering before compare
  1997   __ movl(temp, Address(array, i, Address::times_8, 0*wordSize));
  1998   __ bswapl(temp);
  1999   __ cmpl(key, temp);
  2000   __ jcc(Assembler::notEqual, default_case);
  2002   // entry found -> j = offset
  2003   __ movl(j , Address(array, i, Address::times_8, 1*wordSize));
  2004   __ profile_switch_case(i, key, array);
  2005   __ bswapl(j);
  2006   LP64_ONLY(__ movslq(j, j));
  2007   __ restore_bcp();
  2008   __ restore_locals();                           // restore rdi
  2009   __ load_unsigned_byte(rbx, Address(rsi, j, Address::times_1));
  2011   __ addptr(rsi, j);
  2012   __ dispatch_only(vtos);
  2014   // default case -> j = default offset
  2015   __ bind(default_case);
  2016   __ profile_switch_default(i);
  2017   __ movl(j, Address(array, -2*wordSize));
  2018   __ bswapl(j);
  2019   LP64_ONLY(__ movslq(j, j));
  2020   __ restore_bcp();
  2021   __ restore_locals();                           // restore rdi
  2022   __ load_unsigned_byte(rbx, Address(rsi, j, Address::times_1));
  2023   __ addptr(rsi, j);
  2024   __ dispatch_only(vtos);
  2028 void TemplateTable::_return(TosState state) {
  2029   transition(state, state);
  2030   assert(_desc->calls_vm(), "inconsistent calls_vm information"); // call in remove_activation
  2032   if (_desc->bytecode() == Bytecodes::_return_register_finalizer) {
  2033     assert(state == vtos, "only valid state");
  2034     __ movptr(rax, aaddress(0));
  2035     __ load_klass(rdi, rax);
  2036     __ movl(rdi, Address(rdi, Klass::access_flags_offset()));
  2037     __ testl(rdi, JVM_ACC_HAS_FINALIZER);
  2038     Label skip_register_finalizer;
  2039     __ jcc(Assembler::zero, skip_register_finalizer);
  2041     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::register_finalizer), rax);
  2043     __ bind(skip_register_finalizer);
  2046   __ remove_activation(state, rsi);
  2047   __ jmp(rsi);
  2051 // ----------------------------------------------------------------------------
  2052 // Volatile variables demand their effects be made known to all CPU's in
  2053 // order.  Store buffers on most chips allow reads & writes to reorder; the
  2054 // JMM's ReadAfterWrite.java test fails in -Xint mode without some kind of
  2055 // memory barrier (i.e., it's not sufficient that the interpreter does not
  2056 // reorder volatile references, the hardware also must not reorder them).
  2057 //
  2058 // According to the new Java Memory Model (JMM):
  2059 // (1) All volatiles are serialized wrt to each other.
  2060 // ALSO reads & writes act as aquire & release, so:
  2061 // (2) A read cannot let unrelated NON-volatile memory refs that happen after
  2062 // the read float up to before the read.  It's OK for non-volatile memory refs
  2063 // that happen before the volatile read to float down below it.
  2064 // (3) Similar a volatile write cannot let unrelated NON-volatile memory refs
  2065 // that happen BEFORE the write float down to after the write.  It's OK for
  2066 // non-volatile memory refs that happen after the volatile write to float up
  2067 // before it.
  2068 //
  2069 // We only put in barriers around volatile refs (they are expensive), not
  2070 // _between_ memory refs (that would require us to track the flavor of the
  2071 // previous memory refs).  Requirements (2) and (3) require some barriers
  2072 // before volatile stores and after volatile loads.  These nearly cover
  2073 // requirement (1) but miss the volatile-store-volatile-load case.  This final
  2074 // case is placed after volatile-stores although it could just as well go
  2075 // before volatile-loads.
  2076 void TemplateTable::volatile_barrier(Assembler::Membar_mask_bits order_constraint ) {
  2077   // Helper function to insert a is-volatile test and memory barrier
  2078   if( !os::is_MP() ) return;    // Not needed on single CPU
  2079   __ membar(order_constraint);
  2082 void TemplateTable::resolve_cache_and_index(int byte_no,
  2083                                             Register result,
  2084                                             Register Rcache,
  2085                                             Register index,
  2086                                             size_t index_size) {
  2087   const Register temp = rbx;
  2088   assert_different_registers(result, Rcache, index, temp);
  2090   Label resolved;
  2091   if (byte_no == f12_oop) {
  2092     // We are resolved if the f1 field contains a non-null object (CallSite, MethodType, etc.)
  2093     // This kind of CP cache entry does not need to match bytecode_1 or bytecode_2, because
  2094     // there is a 1-1 relation between bytecode type and CP entry type.
  2095     // The caller will also load a methodOop from f2.
  2096     assert(result != noreg, ""); //else do cmpptr(Address(...), (int32_t) NULL_WORD)
  2097     __ get_cache_and_index_at_bcp(Rcache, index, 1, index_size);
  2098     __ movptr(result, Address(Rcache, index, Address::times_ptr, constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::f1_offset()));
  2099     __ testptr(result, result);
  2100     __ jcc(Assembler::notEqual, resolved);
  2101   } else {
  2102     assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
  2103     assert(result == noreg, "");  //else change code for setting result
  2104     __ get_cache_and_index_and_bytecode_at_bcp(Rcache, index, temp, byte_no, 1, index_size);
  2105     __ cmpl(temp, (int) bytecode());  // have we resolved this bytecode?
  2106     __ jcc(Assembler::equal, resolved);
  2109   // resolve first time through
  2110   address entry;
  2111   switch (bytecode()) {
  2112     case Bytecodes::_getstatic      : // fall through
  2113     case Bytecodes::_putstatic      : // fall through
  2114     case Bytecodes::_getfield       : // fall through
  2115     case Bytecodes::_putfield       : entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_get_put);        break;
  2116     case Bytecodes::_invokevirtual  : // fall through
  2117     case Bytecodes::_invokespecial  : // fall through
  2118     case Bytecodes::_invokestatic   : // fall through
  2119     case Bytecodes::_invokeinterface: entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_invoke);         break;
  2120     case Bytecodes::_invokehandle   : entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_invokehandle);   break;
  2121     case Bytecodes::_invokedynamic  : entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_invokedynamic);  break;
  2122     case Bytecodes::_fast_aldc      : entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_ldc);            break;
  2123     case Bytecodes::_fast_aldc_w    : entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_ldc);            break;
  2124     default:
  2125       fatal(err_msg("unexpected bytecode: %s", Bytecodes::name(bytecode())));
  2126       break;
  2128   __ movl(temp, (int)bytecode());
  2129   __ call_VM(noreg, entry, temp);
  2130   // Update registers with resolved info
  2131   __ get_cache_and_index_at_bcp(Rcache, index, 1, index_size);
  2132   if (result != noreg)
  2133     __ movptr(result, Address(Rcache, index, Address::times_ptr, constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::f1_offset()));
  2134   __ bind(resolved);
  2138 // The cache and index registers must be set before call
  2139 void TemplateTable::load_field_cp_cache_entry(Register obj,
  2140                                               Register cache,
  2141                                               Register index,
  2142                                               Register off,
  2143                                               Register flags,
  2144                                               bool is_static = false) {
  2145   assert_different_registers(cache, index, flags, off);
  2147   ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
  2148   // Field offset
  2149   __ movptr(off, Address(cache, index, Address::times_ptr,
  2150                          in_bytes(cp_base_offset + ConstantPoolCacheEntry::f2_offset())));
  2151   // Flags
  2152   __ movl(flags, Address(cache, index, Address::times_ptr,
  2153            in_bytes(cp_base_offset + ConstantPoolCacheEntry::flags_offset())));
  2155   // klass overwrite register
  2156   if (is_static) {
  2157     __ movptr(obj, Address(cache, index, Address::times_ptr,
  2158                            in_bytes(cp_base_offset + ConstantPoolCacheEntry::f1_offset())));
  2162 void TemplateTable::load_invoke_cp_cache_entry(int byte_no,
  2163                                                Register method,
  2164                                                Register itable_index,
  2165                                                Register flags,
  2166                                                bool is_invokevirtual,
  2167                                                bool is_invokevfinal, /*unused*/
  2168                                                bool is_invokedynamic) {
  2169   // setup registers
  2170   const Register cache = rcx;
  2171   const Register index = rdx;
  2172   assert_different_registers(method, flags);
  2173   assert_different_registers(method, cache, index);
  2174   assert_different_registers(itable_index, flags);
  2175   assert_different_registers(itable_index, cache, index);
  2176   // determine constant pool cache field offsets
  2177   assert(is_invokevirtual == (byte_no == f2_byte), "is_invokevirtual flag redundant");
  2178   const int method_offset = in_bytes(
  2179     constantPoolCacheOopDesc::base_offset() +
  2180       ((byte_no == f2_byte)
  2181        ? ConstantPoolCacheEntry::f2_offset()
  2182        : ConstantPoolCacheEntry::f1_offset()));
  2183   const int flags_offset = in_bytes(constantPoolCacheOopDesc::base_offset() +
  2184                                     ConstantPoolCacheEntry::flags_offset());
  2185   // access constant pool cache fields
  2186   const int index_offset = in_bytes(constantPoolCacheOopDesc::base_offset() +
  2187                                     ConstantPoolCacheEntry::f2_offset());
  2189   if (byte_no == f12_oop) {
  2190     // Resolved f1_oop (CallSite, MethodType, etc.) goes into 'itable_index'.
  2191     // Resolved f2_oop (methodOop invoker) will go into 'method' (at index_offset).
  2192     // See ConstantPoolCacheEntry::set_dynamic_call and set_method_handle.
  2193     size_t index_size = (is_invokedynamic ? sizeof(u4) : sizeof(u2));
  2194     resolve_cache_and_index(byte_no, itable_index, cache, index, index_size);
  2195     __ movptr(method, Address(cache, index, Address::times_ptr, index_offset));
  2196     itable_index = noreg;  // hack to disable load below
  2197   } else {
  2198     resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  2199     __ movptr(method, Address(cache, index, Address::times_ptr, method_offset));
  2201   if (itable_index != noreg) {
  2202     // pick up itable index from f2 also:
  2203     assert(byte_no == f1_byte, "already picked up f1");
  2204     __ movptr(itable_index, Address(cache, index, Address::times_ptr, index_offset));
  2206   __ movl(flags, Address(cache, index, Address::times_ptr, flags_offset));
  2210 // The registers cache and index expected to be set before call.
  2211 // Correct values of the cache and index registers are preserved.
  2212 void TemplateTable::jvmti_post_field_access(Register cache,
  2213                                             Register index,
  2214                                             bool is_static,
  2215                                             bool has_tos) {
  2216   if (JvmtiExport::can_post_field_access()) {
  2217     // Check to see if a field access watch has been set before we take
  2218     // the time to call into the VM.
  2219     Label L1;
  2220     assert_different_registers(cache, index, rax);
  2221     __ mov32(rax, ExternalAddress((address) JvmtiExport::get_field_access_count_addr()));
  2222     __ testl(rax,rax);
  2223     __ jcc(Assembler::zero, L1);
  2225     // cache entry pointer
  2226     __ addptr(cache, in_bytes(constantPoolCacheOopDesc::base_offset()));
  2227     __ shll(index, LogBytesPerWord);
  2228     __ addptr(cache, index);
  2229     if (is_static) {
  2230       __ xorptr(rax, rax);      // NULL object reference
  2231     } else {
  2232       __ pop(atos);         // Get the object
  2233       __ verify_oop(rax);
  2234       __ push(atos);        // Restore stack state
  2236     // rax,:   object pointer or NULL
  2237     // cache: cache entry pointer
  2238     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access),
  2239                rax, cache);
  2240     __ get_cache_and_index_at_bcp(cache, index, 1);
  2241     __ bind(L1);
  2245 void TemplateTable::pop_and_check_object(Register r) {
  2246   __ pop_ptr(r);
  2247   __ null_check(r);  // for field access must check obj.
  2248   __ verify_oop(r);
  2251 void TemplateTable::getfield_or_static(int byte_no, bool is_static) {
  2252   transition(vtos, vtos);
  2254   const Register cache = rcx;
  2255   const Register index = rdx;
  2256   const Register obj   = rcx;
  2257   const Register off   = rbx;
  2258   const Register flags = rax;
  2260   resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  2261   jvmti_post_field_access(cache, index, is_static, false);
  2262   load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  2264   if (!is_static) pop_and_check_object(obj);
  2266   const Address lo(obj, off, Address::times_1, 0*wordSize);
  2267   const Address hi(obj, off, Address::times_1, 1*wordSize);
  2269   Label Done, notByte, notInt, notShort, notChar, notLong, notFloat, notObj, notDouble;
  2271   __ shrl(flags, ConstantPoolCacheEntry::tos_state_shift);
  2272   assert(btos == 0, "change code, btos != 0");
  2273   // btos
  2274   __ andptr(flags, ConstantPoolCacheEntry::tos_state_mask);
  2275   __ jcc(Assembler::notZero, notByte);
  2277   __ load_signed_byte(rax, lo );
  2278   __ push(btos);
  2279   // Rewrite bytecode to be faster
  2280   if (!is_static) {
  2281     patch_bytecode(Bytecodes::_fast_bgetfield, rcx, rbx);
  2283   __ jmp(Done);
  2285   __ bind(notByte);
  2286   // itos
  2287   __ cmpl(flags, itos );
  2288   __ jcc(Assembler::notEqual, notInt);
  2290   __ movl(rax, lo );
  2291   __ push(itos);
  2292   // Rewrite bytecode to be faster
  2293   if (!is_static) {
  2294     patch_bytecode(Bytecodes::_fast_igetfield, rcx, rbx);
  2296   __ jmp(Done);
  2298   __ bind(notInt);
  2299   // atos
  2300   __ cmpl(flags, atos );
  2301   __ jcc(Assembler::notEqual, notObj);
  2303   __ movl(rax, lo );
  2304   __ push(atos);
  2305   if (!is_static) {
  2306     patch_bytecode(Bytecodes::_fast_agetfield, rcx, rbx);
  2308   __ jmp(Done);
  2310   __ bind(notObj);
  2311   // ctos
  2312   __ cmpl(flags, ctos );
  2313   __ jcc(Assembler::notEqual, notChar);
  2315   __ load_unsigned_short(rax, lo );
  2316   __ push(ctos);
  2317   if (!is_static) {
  2318     patch_bytecode(Bytecodes::_fast_cgetfield, rcx, rbx);
  2320   __ jmp(Done);
  2322   __ bind(notChar);
  2323   // stos
  2324   __ cmpl(flags, stos );
  2325   __ jcc(Assembler::notEqual, notShort);
  2327   __ load_signed_short(rax, lo );
  2328   __ push(stos);
  2329   if (!is_static) {
  2330     patch_bytecode(Bytecodes::_fast_sgetfield, rcx, rbx);
  2332   __ jmp(Done);
  2334   __ bind(notShort);
  2335   // ltos
  2336   __ cmpl(flags, ltos );
  2337   __ jcc(Assembler::notEqual, notLong);
  2339   // Generate code as if volatile.  There just aren't enough registers to
  2340   // save that information and this code is faster than the test.
  2341   __ fild_d(lo);                // Must load atomically
  2342   __ subptr(rsp,2*wordSize);    // Make space for store
  2343   __ fistp_d(Address(rsp,0));
  2344   __ pop(rax);
  2345   __ pop(rdx);
  2347   __ push(ltos);
  2348   // Don't rewrite to _fast_lgetfield for potential volatile case.
  2349   __ jmp(Done);
  2351   __ bind(notLong);
  2352   // ftos
  2353   __ cmpl(flags, ftos );
  2354   __ jcc(Assembler::notEqual, notFloat);
  2356   __ fld_s(lo);
  2357   __ push(ftos);
  2358   if (!is_static) {
  2359     patch_bytecode(Bytecodes::_fast_fgetfield, rcx, rbx);
  2361   __ jmp(Done);
  2363   __ bind(notFloat);
  2364   // dtos
  2365   __ cmpl(flags, dtos );
  2366   __ jcc(Assembler::notEqual, notDouble);
  2368   __ fld_d(lo);
  2369   __ push(dtos);
  2370   if (!is_static) {
  2371     patch_bytecode(Bytecodes::_fast_dgetfield, rcx, rbx);
  2373   __ jmpb(Done);
  2375   __ bind(notDouble);
  2377   __ stop("Bad state");
  2379   __ bind(Done);
  2380   // Doug Lea believes this is not needed with current Sparcs (TSO) and Intel (PSO).
  2381   // volatile_barrier( );
  2385 void TemplateTable::getfield(int byte_no) {
  2386   getfield_or_static(byte_no, false);
  2390 void TemplateTable::getstatic(int byte_no) {
  2391   getfield_or_static(byte_no, true);
  2394 // The registers cache and index expected to be set before call.
  2395 // The function may destroy various registers, just not the cache and index registers.
  2396 void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
  2398   ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
  2400   if (JvmtiExport::can_post_field_modification()) {
  2401     // Check to see if a field modification watch has been set before we take
  2402     // the time to call into the VM.
  2403     Label L1;
  2404     assert_different_registers(cache, index, rax);
  2405     __ mov32(rax, ExternalAddress((address)JvmtiExport::get_field_modification_count_addr()));
  2406     __ testl(rax, rax);
  2407     __ jcc(Assembler::zero, L1);
  2409     // The cache and index registers have been already set.
  2410     // This allows to eliminate this call but the cache and index
  2411     // registers have to be correspondingly used after this line.
  2412     __ get_cache_and_index_at_bcp(rax, rdx, 1);
  2414     if (is_static) {
  2415       // Life is simple.  Null out the object pointer.
  2416       __ xorptr(rbx, rbx);
  2417     } else {
  2418       // Life is harder. The stack holds the value on top, followed by the object.
  2419       // We don't know the size of the value, though; it could be one or two words
  2420       // depending on its type. As a result, we must find the type to determine where
  2421       // the object is.
  2422       Label two_word, valsize_known;
  2423       __ movl(rcx, Address(rax, rdx, Address::times_ptr, in_bytes(cp_base_offset +
  2424                                    ConstantPoolCacheEntry::flags_offset())));
  2425       __ mov(rbx, rsp);
  2426       __ shrl(rcx, ConstantPoolCacheEntry::tos_state_shift);
  2427       // Make sure we don't need to mask rcx after the above shift
  2428       ConstantPoolCacheEntry::verify_tos_state_shift();
  2429       __ cmpl(rcx, ltos);
  2430       __ jccb(Assembler::equal, two_word);
  2431       __ cmpl(rcx, dtos);
  2432       __ jccb(Assembler::equal, two_word);
  2433       __ addptr(rbx, Interpreter::expr_offset_in_bytes(1)); // one word jvalue (not ltos, dtos)
  2434       __ jmpb(valsize_known);
  2436       __ bind(two_word);
  2437       __ addptr(rbx, Interpreter::expr_offset_in_bytes(2)); // two words jvalue
  2439       __ bind(valsize_known);
  2440       // setup object pointer
  2441       __ movptr(rbx, Address(rbx, 0));
  2443     // cache entry pointer
  2444     __ addptr(rax, in_bytes(cp_base_offset));
  2445     __ shll(rdx, LogBytesPerWord);
  2446     __ addptr(rax, rdx);
  2447     // object (tos)
  2448     __ mov(rcx, rsp);
  2449     // rbx,: object pointer set up above (NULL if static)
  2450     // rax,: cache entry pointer
  2451     // rcx: jvalue object on the stack
  2452     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification),
  2453                rbx, rax, rcx);
  2454     __ get_cache_and_index_at_bcp(cache, index, 1);
  2455     __ bind(L1);
  2460 void TemplateTable::putfield_or_static(int byte_no, bool is_static) {
  2461   transition(vtos, vtos);
  2463   const Register cache = rcx;
  2464   const Register index = rdx;
  2465   const Register obj   = rcx;
  2466   const Register off   = rbx;
  2467   const Register flags = rax;
  2469   resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  2470   jvmti_post_field_mod(cache, index, is_static);
  2471   load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  2473   // Doug Lea believes this is not needed with current Sparcs (TSO) and Intel (PSO).
  2474   // volatile_barrier( );
  2476   Label notVolatile, Done;
  2477   __ movl(rdx, flags);
  2478   __ shrl(rdx, ConstantPoolCacheEntry::is_volatile_shift);
  2479   __ andl(rdx, 0x1);
  2481   // field addresses
  2482   const Address lo(obj, off, Address::times_1, 0*wordSize);
  2483   const Address hi(obj, off, Address::times_1, 1*wordSize);
  2485   Label notByte, notInt, notShort, notChar, notLong, notFloat, notObj, notDouble;
  2487   __ shrl(flags, ConstantPoolCacheEntry::tos_state_shift);
  2488   assert(btos == 0, "change code, btos != 0");
  2489   __ andl(flags, ConstantPoolCacheEntry::tos_state_mask);
  2490   __ jcc(Assembler::notZero, notByte);
  2492   // btos
  2494     __ pop(btos);
  2495     if (!is_static) pop_and_check_object(obj);
  2496     __ movb(lo, rax);
  2497     if (!is_static) {
  2498       patch_bytecode(Bytecodes::_fast_bputfield, rcx, rbx, true, byte_no);
  2500     __ jmp(Done);
  2503   __ bind(notByte);
  2504   __ cmpl(flags, itos);
  2505   __ jcc(Assembler::notEqual, notInt);
  2507   // itos
  2509     __ pop(itos);
  2510     if (!is_static) pop_and_check_object(obj);
  2511     __ movl(lo, rax);
  2512     if (!is_static) {
  2513       patch_bytecode(Bytecodes::_fast_iputfield, rcx, rbx, true, byte_no);
  2515     __ jmp(Done);
  2518   __ bind(notInt);
  2519   __ cmpl(flags, atos);
  2520   __ jcc(Assembler::notEqual, notObj);
  2522   // atos
  2524     __ pop(atos);
  2525     if (!is_static) pop_and_check_object(obj);
  2526     do_oop_store(_masm, lo, rax, _bs->kind(), false);
  2527     if (!is_static) {
  2528       patch_bytecode(Bytecodes::_fast_aputfield, rcx, rbx, true, byte_no);
  2530     __ jmp(Done);
  2533   __ bind(notObj);
  2534   __ cmpl(flags, ctos);
  2535   __ jcc(Assembler::notEqual, notChar);
  2537   // ctos
  2539     __ pop(ctos);
  2540     if (!is_static) pop_and_check_object(obj);
  2541     __ movw(lo, rax);
  2542     if (!is_static) {
  2543       patch_bytecode(Bytecodes::_fast_cputfield, rcx, rbx, true, byte_no);
  2545     __ jmp(Done);
  2548   __ bind(notChar);
  2549   __ cmpl(flags, stos);
  2550   __ jcc(Assembler::notEqual, notShort);
  2552   // stos
  2554     __ pop(stos);
  2555     if (!is_static) pop_and_check_object(obj);
  2556     __ movw(lo, rax);
  2557     if (!is_static) {
  2558       patch_bytecode(Bytecodes::_fast_sputfield, rcx, rbx, true, byte_no);
  2560     __ jmp(Done);
  2563   __ bind(notShort);
  2564   __ cmpl(flags, ltos);
  2565   __ jcc(Assembler::notEqual, notLong);
  2567   // ltos
  2569     Label notVolatileLong;
  2570     __ testl(rdx, rdx);
  2571     __ jcc(Assembler::zero, notVolatileLong);
  2573     __ pop(ltos);  // overwrites rdx, do this after testing volatile.
  2574     if (!is_static) pop_and_check_object(obj);
  2576     // Replace with real volatile test
  2577     __ push(rdx);
  2578     __ push(rax);                 // Must update atomically with FIST
  2579     __ fild_d(Address(rsp,0));    // So load into FPU register
  2580     __ fistp_d(lo);               // and put into memory atomically
  2581     __ addptr(rsp, 2*wordSize);
  2582     // volatile_barrier();
  2583     volatile_barrier(Assembler::Membar_mask_bits(Assembler::StoreLoad |
  2584                                                  Assembler::StoreStore));
  2585     // Don't rewrite volatile version
  2586     __ jmp(notVolatile);
  2588     __ bind(notVolatileLong);
  2590     __ pop(ltos);  // overwrites rdx
  2591     if (!is_static) pop_and_check_object(obj);
  2592     NOT_LP64(__ movptr(hi, rdx));
  2593     __ movptr(lo, rax);
  2594     if (!is_static) {
  2595       patch_bytecode(Bytecodes::_fast_lputfield, rcx, rbx, true, byte_no);
  2597     __ jmp(notVolatile);
  2600   __ bind(notLong);
  2601   __ cmpl(flags, ftos);
  2602   __ jcc(Assembler::notEqual, notFloat);
  2604   // ftos
  2606     __ pop(ftos);
  2607     if (!is_static) pop_and_check_object(obj);
  2608     __ fstp_s(lo);
  2609     if (!is_static) {
  2610       patch_bytecode(Bytecodes::_fast_fputfield, rcx, rbx, true, byte_no);
  2612     __ jmp(Done);
  2615   __ bind(notFloat);
  2616 #ifdef ASSERT
  2617   __ cmpl(flags, dtos);
  2618   __ jcc(Assembler::notEqual, notDouble);
  2619 #endif
  2621   // dtos
  2623     __ pop(dtos);
  2624     if (!is_static) pop_and_check_object(obj);
  2625     __ fstp_d(lo);
  2626     if (!is_static) {
  2627       patch_bytecode(Bytecodes::_fast_dputfield, rcx, rbx, true, byte_no);
  2629     __ jmp(Done);
  2632 #ifdef ASSERT
  2633   __ bind(notDouble);
  2634   __ stop("Bad state");
  2635 #endif
  2637   __ bind(Done);
  2639   // Check for volatile store
  2640   __ testl(rdx, rdx);
  2641   __ jcc(Assembler::zero, notVolatile);
  2642   volatile_barrier(Assembler::Membar_mask_bits(Assembler::StoreLoad |
  2643                                                Assembler::StoreStore));
  2644   __ bind(notVolatile);
  2648 void TemplateTable::putfield(int byte_no) {
  2649   putfield_or_static(byte_no, false);
  2653 void TemplateTable::putstatic(int byte_no) {
  2654   putfield_or_static(byte_no, true);
  2657 void TemplateTable::jvmti_post_fast_field_mod() {
  2658   if (JvmtiExport::can_post_field_modification()) {
  2659     // Check to see if a field modification watch has been set before we take
  2660     // the time to call into the VM.
  2661     Label L2;
  2662      __ mov32(rcx, ExternalAddress((address)JvmtiExport::get_field_modification_count_addr()));
  2663      __ testl(rcx,rcx);
  2664      __ jcc(Assembler::zero, L2);
  2665      __ pop_ptr(rbx);               // copy the object pointer from tos
  2666      __ verify_oop(rbx);
  2667      __ push_ptr(rbx);              // put the object pointer back on tos
  2669      // Save tos values before call_VM() clobbers them. Since we have
  2670      // to do it for every data type, we use the saved values as the
  2671      // jvalue object.
  2672      switch (bytecode()) {          // load values into the jvalue object
  2673      case Bytecodes::_fast_aputfield: __ push_ptr(rax); break;
  2674      case Bytecodes::_fast_bputfield: // fall through
  2675      case Bytecodes::_fast_sputfield: // fall through
  2676      case Bytecodes::_fast_cputfield: // fall through
  2677      case Bytecodes::_fast_iputfield: __ push_i(rax); break;
  2678      case Bytecodes::_fast_dputfield: __ push_d(); break;
  2679      case Bytecodes::_fast_fputfield: __ push_f(); break;
  2680      case Bytecodes::_fast_lputfield: __ push_l(rax); break;
  2682      default:
  2683        ShouldNotReachHere();
  2685      __ mov(rcx, rsp);              // points to jvalue on the stack
  2686      // access constant pool cache entry
  2687      __ get_cache_entry_pointer_at_bcp(rax, rdx, 1);
  2688      __ verify_oop(rbx);
  2689      // rbx,: object pointer copied above
  2690      // rax,: cache entry pointer
  2691      // rcx: jvalue object on the stack
  2692      __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification), rbx, rax, rcx);
  2694      switch (bytecode()) {             // restore tos values
  2695      case Bytecodes::_fast_aputfield: __ pop_ptr(rax); break;
  2696      case Bytecodes::_fast_bputfield: // fall through
  2697      case Bytecodes::_fast_sputfield: // fall through
  2698      case Bytecodes::_fast_cputfield: // fall through
  2699      case Bytecodes::_fast_iputfield: __ pop_i(rax); break;
  2700      case Bytecodes::_fast_dputfield: __ pop_d(); break;
  2701      case Bytecodes::_fast_fputfield: __ pop_f(); break;
  2702      case Bytecodes::_fast_lputfield: __ pop_l(rax); break;
  2704      __ bind(L2);
  2708 void TemplateTable::fast_storefield(TosState state) {
  2709   transition(state, vtos);
  2711   ByteSize base = constantPoolCacheOopDesc::base_offset();
  2713   jvmti_post_fast_field_mod();
  2715   // access constant pool cache
  2716   __ get_cache_and_index_at_bcp(rcx, rbx, 1);
  2718   // test for volatile with rdx but rdx is tos register for lputfield.
  2719   if (bytecode() == Bytecodes::_fast_lputfield) __ push(rdx);
  2720   __ movl(rdx, Address(rcx, rbx, Address::times_ptr, in_bytes(base +
  2721                        ConstantPoolCacheEntry::flags_offset())));
  2723   // replace index with field offset from cache entry
  2724   __ movptr(rbx, Address(rcx, rbx, Address::times_ptr, in_bytes(base + ConstantPoolCacheEntry::f2_offset())));
  2726   // Doug Lea believes this is not needed with current Sparcs (TSO) and Intel (PSO).
  2727   // volatile_barrier( );
  2729   Label notVolatile, Done;
  2730   __ shrl(rdx, ConstantPoolCacheEntry::is_volatile_shift);
  2731   __ andl(rdx, 0x1);
  2732   // Check for volatile store
  2733   __ testl(rdx, rdx);
  2734   __ jcc(Assembler::zero, notVolatile);
  2736   if (bytecode() == Bytecodes::_fast_lputfield) __ pop(rdx);
  2738   // Get object from stack
  2739   pop_and_check_object(rcx);
  2741   // field addresses
  2742   const Address lo(rcx, rbx, Address::times_1, 0*wordSize);
  2743   const Address hi(rcx, rbx, Address::times_1, 1*wordSize);
  2745   // access field
  2746   switch (bytecode()) {
  2747     case Bytecodes::_fast_bputfield: __ movb(lo, rax); break;
  2748     case Bytecodes::_fast_sputfield: // fall through
  2749     case Bytecodes::_fast_cputfield: __ movw(lo, rax); break;
  2750     case Bytecodes::_fast_iputfield: __ movl(lo, rax); break;
  2751     case Bytecodes::_fast_lputfield:
  2752       NOT_LP64(__ movptr(hi, rdx));
  2753       __ movptr(lo, rax);
  2754       break;
  2755     case Bytecodes::_fast_fputfield: __ fstp_s(lo); break;
  2756     case Bytecodes::_fast_dputfield: __ fstp_d(lo); break;
  2757     case Bytecodes::_fast_aputfield: {
  2758       do_oop_store(_masm, lo, rax, _bs->kind(), false);
  2759       break;
  2761     default:
  2762       ShouldNotReachHere();
  2765   Label done;
  2766   volatile_barrier(Assembler::Membar_mask_bits(Assembler::StoreLoad |
  2767                                                Assembler::StoreStore));
  2768   // Barriers are so large that short branch doesn't reach!
  2769   __ jmp(done);
  2771   // Same code as above, but don't need rdx to test for volatile.
  2772   __ bind(notVolatile);
  2774   if (bytecode() == Bytecodes::_fast_lputfield) __ pop(rdx);
  2776   // Get object from stack
  2777   pop_and_check_object(rcx);
  2779   // access field
  2780   switch (bytecode()) {
  2781     case Bytecodes::_fast_bputfield: __ movb(lo, rax); break;
  2782     case Bytecodes::_fast_sputfield: // fall through
  2783     case Bytecodes::_fast_cputfield: __ movw(lo, rax); break;
  2784     case Bytecodes::_fast_iputfield: __ movl(lo, rax); break;
  2785     case Bytecodes::_fast_lputfield:
  2786       NOT_LP64(__ movptr(hi, rdx));
  2787       __ movptr(lo, rax);
  2788       break;
  2789     case Bytecodes::_fast_fputfield: __ fstp_s(lo); break;
  2790     case Bytecodes::_fast_dputfield: __ fstp_d(lo); break;
  2791     case Bytecodes::_fast_aputfield: {
  2792       do_oop_store(_masm, lo, rax, _bs->kind(), false);
  2793       break;
  2795     default:
  2796       ShouldNotReachHere();
  2798   __ bind(done);
  2802 void TemplateTable::fast_accessfield(TosState state) {
  2803   transition(atos, state);
  2805   // do the JVMTI work here to avoid disturbing the register state below
  2806   if (JvmtiExport::can_post_field_access()) {
  2807     // Check to see if a field access watch has been set before we take
  2808     // the time to call into the VM.
  2809     Label L1;
  2810     __ mov32(rcx, ExternalAddress((address) JvmtiExport::get_field_access_count_addr()));
  2811     __ testl(rcx,rcx);
  2812     __ jcc(Assembler::zero, L1);
  2813     // access constant pool cache entry
  2814     __ get_cache_entry_pointer_at_bcp(rcx, rdx, 1);
  2815     __ push_ptr(rax);  // save object pointer before call_VM() clobbers it
  2816     __ verify_oop(rax);
  2817     // rax,: object pointer copied above
  2818     // rcx: cache entry pointer
  2819     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access), rax, rcx);
  2820     __ pop_ptr(rax);   // restore object pointer
  2821     __ bind(L1);
  2824   // access constant pool cache
  2825   __ get_cache_and_index_at_bcp(rcx, rbx, 1);
  2826   // replace index with field offset from cache entry
  2827   __ movptr(rbx, Address(rcx,
  2828                          rbx,
  2829                          Address::times_ptr,
  2830                          in_bytes(constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::f2_offset())));
  2833   // rax,: object
  2834   __ verify_oop(rax);
  2835   __ null_check(rax);
  2836   // field addresses
  2837   const Address lo = Address(rax, rbx, Address::times_1, 0*wordSize);
  2838   const Address hi = Address(rax, rbx, Address::times_1, 1*wordSize);
  2840   // access field
  2841   switch (bytecode()) {
  2842     case Bytecodes::_fast_bgetfield: __ movsbl(rax, lo );                 break;
  2843     case Bytecodes::_fast_sgetfield: __ load_signed_short(rax, lo );      break;
  2844     case Bytecodes::_fast_cgetfield: __ load_unsigned_short(rax, lo );    break;
  2845     case Bytecodes::_fast_igetfield: __ movl(rax, lo);                    break;
  2846     case Bytecodes::_fast_lgetfield: __ stop("should not be rewritten");  break;
  2847     case Bytecodes::_fast_fgetfield: __ fld_s(lo);                        break;
  2848     case Bytecodes::_fast_dgetfield: __ fld_d(lo);                        break;
  2849     case Bytecodes::_fast_agetfield: __ movptr(rax, lo); __ verify_oop(rax); break;
  2850     default:
  2851       ShouldNotReachHere();
  2854   // Doug Lea believes this is not needed with current Sparcs(TSO) and Intel(PSO)
  2855   // volatile_barrier( );
  2858 void TemplateTable::fast_xaccess(TosState state) {
  2859   transition(vtos, state);
  2860   // get receiver
  2861   __ movptr(rax, aaddress(0));
  2862   // access constant pool cache
  2863   __ get_cache_and_index_at_bcp(rcx, rdx, 2);
  2864   __ movptr(rbx, Address(rcx,
  2865                          rdx,
  2866                          Address::times_ptr,
  2867                          in_bytes(constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::f2_offset())));
  2868   // make sure exception is reported in correct bcp range (getfield is next instruction)
  2869   __ increment(rsi);
  2870   __ null_check(rax);
  2871   const Address lo = Address(rax, rbx, Address::times_1, 0*wordSize);
  2872   if (state == itos) {
  2873     __ movl(rax, lo);
  2874   } else if (state == atos) {
  2875     __ movptr(rax, lo);
  2876     __ verify_oop(rax);
  2877   } else if (state == ftos) {
  2878     __ fld_s(lo);
  2879   } else {
  2880     ShouldNotReachHere();
  2882   __ decrement(rsi);
  2887 //----------------------------------------------------------------------------------------------------
  2888 // Calls
  2890 void TemplateTable::count_calls(Register method, Register temp) {
  2891   // implemented elsewhere
  2892   ShouldNotReachHere();
  2896 void TemplateTable::prepare_invoke(int byte_no,
  2897                                    Register method,  // linked method (or i-klass)
  2898                                    Register index,   // itable index, MethodType, etc.
  2899                                    Register recv,    // if caller wants to see it
  2900                                    Register flags    // if caller wants to test it
  2901                                    ) {
  2902   // determine flags
  2903   const Bytecodes::Code code = bytecode();
  2904   const bool is_invokeinterface  = code == Bytecodes::_invokeinterface;
  2905   const bool is_invokedynamic    = code == Bytecodes::_invokedynamic;
  2906   const bool is_invokehandle     = code == Bytecodes::_invokehandle;
  2907   const bool is_invokevirtual    = code == Bytecodes::_invokevirtual;
  2908   const bool is_invokespecial    = code == Bytecodes::_invokespecial;
  2909   const bool load_receiver       = (recv  != noreg);
  2910   const bool save_flags          = (flags != noreg);
  2911   assert(load_receiver == (code != Bytecodes::_invokestatic && code != Bytecodes::_invokedynamic), "");
  2912   assert(save_flags    == (is_invokeinterface || is_invokevirtual), "need flags for vfinal");
  2913   assert(flags == noreg || flags == rdx, "");
  2914   assert(recv  == noreg || recv  == rcx, "");
  2916   // setup registers & access constant pool cache
  2917   if (recv  == noreg)  recv  = rcx;
  2918   if (flags == noreg)  flags = rdx;
  2919   assert_different_registers(method, index, recv, flags);
  2921   // save 'interpreter return address'
  2922   __ save_bcp();
  2924   load_invoke_cp_cache_entry(byte_no, method, index, flags, is_invokevirtual, false, is_invokedynamic);
  2926   // maybe push appendix to arguments (just before return address)
  2927   if (is_invokedynamic || is_invokehandle) {
  2928     Label L_no_push;
  2929     __ verify_oop(index);
  2930     __ testl(flags, (1 << ConstantPoolCacheEntry::has_appendix_shift));
  2931     __ jccb(Assembler::zero, L_no_push);
  2932     // Push the appendix as a trailing parameter.
  2933     // This must be done before we get the receiver,
  2934     // since the parameter_size includes it.
  2935     __ push(index);  // push appendix (MethodType, CallSite, etc.)
  2936     __ bind(L_no_push);
  2939   // load receiver if needed (note: no return address pushed yet)
  2940   if (load_receiver) {
  2941     __ movl(recv, flags);
  2942     __ andl(recv, ConstantPoolCacheEntry::parameter_size_mask);
  2943     const int no_return_pc_pushed_yet = -1;  // argument slot correction before we push return address
  2944     const int receiver_is_at_end      = -1;  // back off one slot to get receiver
  2945     Address recv_addr = __ argument_address(recv, no_return_pc_pushed_yet + receiver_is_at_end);
  2946     __ movptr(recv, recv_addr);
  2947     __ verify_oop(recv);
  2950   if (save_flags) {
  2951     __ mov(rsi, flags);
  2954   // compute return type
  2955   __ shrl(flags, ConstantPoolCacheEntry::tos_state_shift);
  2956   // Make sure we don't need to mask flags after the above shift
  2957   ConstantPoolCacheEntry::verify_tos_state_shift();
  2958   // load return address
  2960     const address table_addr = (is_invokeinterface || is_invokedynamic) ?
  2961         (address)Interpreter::return_5_addrs_by_index_table() :
  2962         (address)Interpreter::return_3_addrs_by_index_table();
  2963     ExternalAddress table(table_addr);
  2964     __ movptr(flags, ArrayAddress(table, Address(noreg, flags, Address::times_ptr)));
  2967   // push return address
  2968   __ push(flags);
  2970   // Restore flags value from the constant pool cache, and restore rsi
  2971   // for later null checks.  rsi is the bytecode pointer
  2972   if (save_flags) {
  2973     __ mov(flags, rsi);
  2974     __ restore_bcp();
  2979 void TemplateTable::invokevirtual_helper(Register index,
  2980                                          Register recv,
  2981                                          Register flags) {
  2982   // Uses temporary registers rax, rdx
  2983   assert_different_registers(index, recv, rax, rdx);
  2984   assert(index == rbx, "");
  2985   assert(recv  == rcx, "");
  2987   // Test for an invoke of a final method
  2988   Label notFinal;
  2989   __ movl(rax, flags);
  2990   __ andl(rax, (1 << ConstantPoolCacheEntry::is_vfinal_shift));
  2991   __ jcc(Assembler::zero, notFinal);
  2993   const Register method = index;  // method must be rbx
  2994   assert(method == rbx,
  2995          "methodOop must be rbx for interpreter calling convention");
  2997   // do the call - the index is actually the method to call
  2998   // that is, f2 is a vtable index if !is_vfinal, else f2 is a methodOop
  2999   __ verify_oop(method);
  3001   // It's final, need a null check here!
  3002   __ null_check(recv);
  3004   // profile this call
  3005   __ profile_final_call(rax);
  3007   __ jump_from_interpreted(method, rax);
  3009   __ bind(notFinal);
  3011   // get receiver klass
  3012   __ null_check(recv, oopDesc::klass_offset_in_bytes());
  3013   __ load_klass(rax, recv);
  3014   __ verify_oop(rax);
  3016   // profile this call
  3017   __ profile_virtual_call(rax, rdi, rdx);
  3019   // get target methodOop & entry point
  3020   __ lookup_virtual_method(rax, index, method);
  3021   __ jump_from_interpreted(method, rdx);
  3025 void TemplateTable::invokevirtual(int byte_no) {
  3026   transition(vtos, vtos);
  3027   assert(byte_no == f2_byte, "use this argument");
  3028   prepare_invoke(byte_no,
  3029                  rbx,    // method or vtable index
  3030                  noreg,  // unused itable index
  3031                  rcx, rdx); // recv, flags
  3033   // rbx: index
  3034   // rcx: receiver
  3035   // rdx: flags
  3037   invokevirtual_helper(rbx, rcx, rdx);
  3041 void TemplateTable::invokespecial(int byte_no) {
  3042   transition(vtos, vtos);
  3043   assert(byte_no == f1_byte, "use this argument");
  3044   prepare_invoke(byte_no, rbx, noreg,  // get f1 methodOop
  3045                  rcx);  // get receiver also for null check
  3046   __ verify_oop(rcx);
  3047   __ null_check(rcx);
  3048   // do the call
  3049   __ verify_oop(rbx);
  3050   __ profile_call(rax);
  3051   __ jump_from_interpreted(rbx, rax);
  3055 void TemplateTable::invokestatic(int byte_no) {
  3056   transition(vtos, vtos);
  3057   assert(byte_no == f1_byte, "use this argument");
  3058   prepare_invoke(byte_no, rbx);  // get f1 methodOop
  3059   // do the call
  3060   __ verify_oop(rbx);
  3061   __ profile_call(rax);
  3062   __ jump_from_interpreted(rbx, rax);
  3066 void TemplateTable::fast_invokevfinal(int byte_no) {
  3067   transition(vtos, vtos);
  3068   assert(byte_no == f2_byte, "use this argument");
  3069   __ stop("fast_invokevfinal not used on x86");
  3073 void TemplateTable::invokeinterface(int byte_no) {
  3074   transition(vtos, vtos);
  3075   assert(byte_no == f1_byte, "use this argument");
  3076   prepare_invoke(byte_no, rax, rbx,  // get f1 klassOop, f2 itable index
  3077                  rcx, rdx); // recv, flags
  3079   // rax: interface klass (from f1)
  3080   // rbx: itable index (from f2)
  3081   // rcx: receiver
  3082   // rdx: flags
  3084   // Special case of invokeinterface called for virtual method of
  3085   // java.lang.Object.  See cpCacheOop.cpp for details.
  3086   // This code isn't produced by javac, but could be produced by
  3087   // another compliant java compiler.
  3088   Label notMethod;
  3089   __ movl(rdi, rdx);
  3090   __ andl(rdi, (1 << ConstantPoolCacheEntry::is_forced_virtual_shift));
  3091   __ jcc(Assembler::zero, notMethod);
  3093   invokevirtual_helper(rbx, rcx, rdx);
  3094   __ bind(notMethod);
  3096   // Get receiver klass into rdx - also a null check
  3097   __ restore_locals();  // restore rdi
  3098   __ null_check(rcx, oopDesc::klass_offset_in_bytes());
  3099   __ load_klass(rdx, rcx);
  3100   __ verify_oop(rdx);
  3102   // profile this call
  3103   __ profile_virtual_call(rdx, rsi, rdi);
  3105   Label no_such_interface, no_such_method;
  3107   __ lookup_interface_method(// inputs: rec. class, interface, itable index
  3108                              rdx, rax, rbx,
  3109                              // outputs: method, scan temp. reg
  3110                              rbx, rsi,
  3111                              no_such_interface);
  3113   // rbx: methodOop to call
  3114   // rcx: receiver
  3115   // Check for abstract method error
  3116   // Note: This should be done more efficiently via a throw_abstract_method_error
  3117   //       interpreter entry point and a conditional jump to it in case of a null
  3118   //       method.
  3119   __ testptr(rbx, rbx);
  3120   __ jcc(Assembler::zero, no_such_method);
  3122   // do the call
  3123   // rcx: receiver
  3124   // rbx,: methodOop
  3125   __ jump_from_interpreted(rbx, rdx);
  3126   __ should_not_reach_here();
  3128   // exception handling code follows...
  3129   // note: must restore interpreter registers to canonical
  3130   //       state for exception handling to work correctly!
  3132   __ bind(no_such_method);
  3133   // throw exception
  3134   __ pop(rbx);           // pop return address (pushed by prepare_invoke)
  3135   __ restore_bcp();      // rsi must be correct for exception handler   (was destroyed)
  3136   __ restore_locals();   // make sure locals pointer is correct as well (was destroyed)
  3137   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError));
  3138   // the call_VM checks for exception, so we should never return here.
  3139   __ should_not_reach_here();
  3141   __ bind(no_such_interface);
  3142   // throw exception
  3143   __ pop(rbx);           // pop return address (pushed by prepare_invoke)
  3144   __ restore_bcp();      // rsi must be correct for exception handler   (was destroyed)
  3145   __ restore_locals();   // make sure locals pointer is correct as well (was destroyed)
  3146   __ call_VM(noreg, CAST_FROM_FN_PTR(address,
  3147                    InterpreterRuntime::throw_IncompatibleClassChangeError));
  3148   // the call_VM checks for exception, so we should never return here.
  3149   __ should_not_reach_here();
  3152 void TemplateTable::invokehandle(int byte_no) {
  3153   transition(vtos, vtos);
  3154   assert(byte_no == f12_oop, "use this argument");
  3155   const Register rbx_method = rbx;  // (from f2)
  3156   const Register rax_mtype  = rax;  // (from f1)
  3157   const Register rcx_recv   = rcx;
  3158   const Register rdx_flags  = rdx;
  3160   if (!EnableInvokeDynamic) {
  3161     // rewriter does not generate this bytecode
  3162     __ should_not_reach_here();
  3163     return;
  3166   prepare_invoke(byte_no,
  3167                  rbx_method, rax_mtype,  // get f2 methodOop, f1 MethodType
  3168                  rcx_recv);
  3169   __ verify_oop(rbx_method);
  3170   __ verify_oop(rcx_recv);
  3171   __ null_check(rcx_recv);
  3173   // Note:  rax_mtype is already pushed (if necessary) by prepare_invoke
  3175   // FIXME: profile the LambdaForm also
  3176   __ profile_final_call(rax);
  3178   __ jump_from_interpreted(rbx_method, rdx);
  3182 void TemplateTable::invokedynamic(int byte_no) {
  3183   transition(vtos, vtos);
  3184   assert(byte_no == f12_oop, "use this argument");
  3186   if (!EnableInvokeDynamic) {
  3187     // We should not encounter this bytecode if !EnableInvokeDynamic.
  3188     // The verifier will stop it.  However, if we get past the verifier,
  3189     // this will stop the thread in a reasonable way, without crashing the JVM.
  3190     __ call_VM(noreg, CAST_FROM_FN_PTR(address,
  3191                      InterpreterRuntime::throw_IncompatibleClassChangeError));
  3192     // the call_VM checks for exception, so we should never return here.
  3193     __ should_not_reach_here();
  3194     return;
  3197   const Register rbx_method   = rbx;
  3198   const Register rax_callsite = rax;
  3200   prepare_invoke(byte_no, rbx_method, rax_callsite);
  3202   // rax: CallSite object (from f1)
  3203   // rbx: MH.linkToCallSite method (from f2)
  3205   // Note:  rax_callsite is already pushed by prepare_invoke
  3207   // %%% should make a type profile for any invokedynamic that takes a ref argument
  3208   // profile this call
  3209   __ profile_call(rsi);
  3211   __ verify_oop(rax_callsite);
  3213   __ jump_from_interpreted(rbx_method, rdx);
  3216 //----------------------------------------------------------------------------------------------------
  3217 // Allocation
  3219 void TemplateTable::_new() {
  3220   transition(vtos, atos);
  3221   __ get_unsigned_2_byte_index_at_bcp(rdx, 1);
  3222   Label slow_case;
  3223   Label slow_case_no_pop;
  3224   Label done;
  3225   Label initialize_header;
  3226   Label initialize_object;  // including clearing the fields
  3227   Label allocate_shared;
  3229   __ get_cpool_and_tags(rcx, rax);
  3231   // Make sure the class we're about to instantiate has been resolved.
  3232   // This is done before loading instanceKlass to be consistent with the order
  3233   // how Constant Pool is updated (see constantPoolOopDesc::klass_at_put)
  3234   const int tags_offset = typeArrayOopDesc::header_size(T_BYTE) * wordSize;
  3235   __ cmpb(Address(rax, rdx, Address::times_1, tags_offset), JVM_CONSTANT_Class);
  3236   __ jcc(Assembler::notEqual, slow_case_no_pop);
  3238   // get instanceKlass
  3239   __ movptr(rcx, Address(rcx, rdx, Address::times_ptr, sizeof(constantPoolOopDesc)));
  3240   __ push(rcx);  // save the contexts of klass for initializing the header
  3242   // make sure klass is initialized & doesn't have finalizer
  3243   // make sure klass is fully initialized
  3244   __ cmpb(Address(rcx, instanceKlass::init_state_offset()), instanceKlass::fully_initialized);
  3245   __ jcc(Assembler::notEqual, slow_case);
  3247   // get instance_size in instanceKlass (scaled to a count of bytes)
  3248   __ movl(rdx, Address(rcx, Klass::layout_helper_offset()));
  3249   // test to see if it has a finalizer or is malformed in some way
  3250   __ testl(rdx, Klass::_lh_instance_slow_path_bit);
  3251   __ jcc(Assembler::notZero, slow_case);
  3253   //
  3254   // Allocate the instance
  3255   // 1) Try to allocate in the TLAB
  3256   // 2) if fail and the object is large allocate in the shared Eden
  3257   // 3) if the above fails (or is not applicable), go to a slow case
  3258   // (creates a new TLAB, etc.)
  3260   const bool allow_shared_alloc =
  3261     Universe::heap()->supports_inline_contig_alloc() && !CMSIncrementalMode;
  3263   const Register thread = rcx;
  3264   if (UseTLAB || allow_shared_alloc) {
  3265     __ get_thread(thread);
  3268   if (UseTLAB) {
  3269     __ movptr(rax, Address(thread, in_bytes(JavaThread::tlab_top_offset())));
  3270     __ lea(rbx, Address(rax, rdx, Address::times_1));
  3271     __ cmpptr(rbx, Address(thread, in_bytes(JavaThread::tlab_end_offset())));
  3272     __ jcc(Assembler::above, allow_shared_alloc ? allocate_shared : slow_case);
  3273     __ movptr(Address(thread, in_bytes(JavaThread::tlab_top_offset())), rbx);
  3274     if (ZeroTLAB) {
  3275       // the fields have been already cleared
  3276       __ jmp(initialize_header);
  3277     } else {
  3278       // initialize both the header and fields
  3279       __ jmp(initialize_object);
  3283   // Allocation in the shared Eden, if allowed.
  3284   //
  3285   // rdx: instance size in bytes
  3286   if (allow_shared_alloc) {
  3287     __ bind(allocate_shared);
  3289     ExternalAddress heap_top((address)Universe::heap()->top_addr());
  3291     Label retry;
  3292     __ bind(retry);
  3293     __ movptr(rax, heap_top);
  3294     __ lea(rbx, Address(rax, rdx, Address::times_1));
  3295     __ cmpptr(rbx, ExternalAddress((address)Universe::heap()->end_addr()));
  3296     __ jcc(Assembler::above, slow_case);
  3298     // Compare rax, with the top addr, and if still equal, store the new
  3299     // top addr in rbx, at the address of the top addr pointer. Sets ZF if was
  3300     // equal, and clears it otherwise. Use lock prefix for atomicity on MPs.
  3301     //
  3302     // rax,: object begin
  3303     // rbx,: object end
  3304     // rdx: instance size in bytes
  3305     __ locked_cmpxchgptr(rbx, heap_top);
  3307     // if someone beat us on the allocation, try again, otherwise continue
  3308     __ jcc(Assembler::notEqual, retry);
  3310     __ incr_allocated_bytes(thread, rdx, 0);
  3313   if (UseTLAB || Universe::heap()->supports_inline_contig_alloc()) {
  3314     // The object is initialized before the header.  If the object size is
  3315     // zero, go directly to the header initialization.
  3316     __ bind(initialize_object);
  3317     __ decrement(rdx, sizeof(oopDesc));
  3318     __ jcc(Assembler::zero, initialize_header);
  3320     // Initialize topmost object field, divide rdx by 8, check if odd and
  3321     // test if zero.
  3322     __ xorl(rcx, rcx);    // use zero reg to clear memory (shorter code)
  3323     __ shrl(rdx, LogBytesPerLong); // divide by 2*oopSize and set carry flag if odd
  3325     // rdx must have been multiple of 8
  3326 #ifdef ASSERT
  3327     // make sure rdx was multiple of 8
  3328     Label L;
  3329     // Ignore partial flag stall after shrl() since it is debug VM
  3330     __ jccb(Assembler::carryClear, L);
  3331     __ stop("object size is not multiple of 2 - adjust this code");
  3332     __ bind(L);
  3333     // rdx must be > 0, no extra check needed here
  3334 #endif
  3336     // initialize remaining object fields: rdx was a multiple of 8
  3337     { Label loop;
  3338     __ bind(loop);
  3339     __ movptr(Address(rax, rdx, Address::times_8, sizeof(oopDesc) - 1*oopSize), rcx);
  3340     NOT_LP64(__ movptr(Address(rax, rdx, Address::times_8, sizeof(oopDesc) - 2*oopSize), rcx));
  3341     __ decrement(rdx);
  3342     __ jcc(Assembler::notZero, loop);
  3345     // initialize object header only.
  3346     __ bind(initialize_header);
  3347     if (UseBiasedLocking) {
  3348       __ pop(rcx);   // get saved klass back in the register.
  3349       __ movptr(rbx, Address(rcx, Klass::prototype_header_offset()));
  3350       __ movptr(Address(rax, oopDesc::mark_offset_in_bytes ()), rbx);
  3351     } else {
  3352       __ movptr(Address(rax, oopDesc::mark_offset_in_bytes ()),
  3353                 (int32_t)markOopDesc::prototype()); // header
  3354       __ pop(rcx);   // get saved klass back in the register.
  3356     __ store_klass(rax, rcx);  // klass
  3359       SkipIfEqual skip_if(_masm, &DTraceAllocProbes, 0);
  3360       // Trigger dtrace event for fastpath
  3361       __ push(atos);
  3362       __ call_VM_leaf(
  3363            CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_object_alloc), rax);
  3364       __ pop(atos);
  3367     __ jmp(done);
  3370   // slow case
  3371   __ bind(slow_case);
  3372   __ pop(rcx);   // restore stack pointer to what it was when we came in.
  3373   __ bind(slow_case_no_pop);
  3374   __ get_constant_pool(rax);
  3375   __ get_unsigned_2_byte_index_at_bcp(rdx, 1);
  3376   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), rax, rdx);
  3378   // continue
  3379   __ bind(done);
  3383 void TemplateTable::newarray() {
  3384   transition(itos, atos);
  3385   __ push_i(rax);                                 // make sure everything is on the stack
  3386   __ load_unsigned_byte(rdx, at_bcp(1));
  3387   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::newarray), rdx, rax);
  3388   __ pop_i(rdx);                                  // discard size
  3392 void TemplateTable::anewarray() {
  3393   transition(itos, atos);
  3394   __ get_unsigned_2_byte_index_at_bcp(rdx, 1);
  3395   __ get_constant_pool(rcx);
  3396   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::anewarray), rcx, rdx, rax);
  3400 void TemplateTable::arraylength() {
  3401   transition(atos, itos);
  3402   __ null_check(rax, arrayOopDesc::length_offset_in_bytes());
  3403   __ movl(rax, Address(rax, arrayOopDesc::length_offset_in_bytes()));
  3407 void TemplateTable::checkcast() {
  3408   transition(atos, atos);
  3409   Label done, is_null, ok_is_subtype, quicked, resolved;
  3410   __ testptr(rax, rax);   // Object is in EAX
  3411   __ jcc(Assembler::zero, is_null);
  3413   // Get cpool & tags index
  3414   __ get_cpool_and_tags(rcx, rdx); // ECX=cpool, EDX=tags array
  3415   __ get_unsigned_2_byte_index_at_bcp(rbx, 1); // EBX=index
  3416   // See if bytecode has already been quicked
  3417   __ cmpb(Address(rdx, rbx, Address::times_1, typeArrayOopDesc::header_size(T_BYTE) * wordSize), JVM_CONSTANT_Class);
  3418   __ jcc(Assembler::equal, quicked);
  3420   __ push(atos);
  3421   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc) );
  3422   __ pop_ptr(rdx);
  3423   __ jmpb(resolved);
  3425   // Get superklass in EAX and subklass in EBX
  3426   __ bind(quicked);
  3427   __ mov(rdx, rax);          // Save object in EDX; EAX needed for subtype check
  3428   __ movptr(rax, Address(rcx, rbx, Address::times_ptr, sizeof(constantPoolOopDesc)));
  3430   __ bind(resolved);
  3431   __ load_klass(rbx, rdx);
  3433   // Generate subtype check.  Blows ECX.  Resets EDI.  Object in EDX.
  3434   // Superklass in EAX.  Subklass in EBX.
  3435   __ gen_subtype_check( rbx, ok_is_subtype );
  3437   // Come here on failure
  3438   __ push(rdx);
  3439   // object is at TOS
  3440   __ jump(ExternalAddress(Interpreter::_throw_ClassCastException_entry));
  3442   // Come here on success
  3443   __ bind(ok_is_subtype);
  3444   __ mov(rax,rdx);           // Restore object in EDX
  3446   // Collect counts on whether this check-cast sees NULLs a lot or not.
  3447   if (ProfileInterpreter) {
  3448     __ jmp(done);
  3449     __ bind(is_null);
  3450     __ profile_null_seen(rcx);
  3451   } else {
  3452     __ bind(is_null);   // same as 'done'
  3454   __ bind(done);
  3458 void TemplateTable::instanceof() {
  3459   transition(atos, itos);
  3460   Label done, is_null, ok_is_subtype, quicked, resolved;
  3461   __ testptr(rax, rax);
  3462   __ jcc(Assembler::zero, is_null);
  3464   // Get cpool & tags index
  3465   __ get_cpool_and_tags(rcx, rdx); // ECX=cpool, EDX=tags array
  3466   __ get_unsigned_2_byte_index_at_bcp(rbx, 1); // EBX=index
  3467   // See if bytecode has already been quicked
  3468   __ cmpb(Address(rdx, rbx, Address::times_1, typeArrayOopDesc::header_size(T_BYTE) * wordSize), JVM_CONSTANT_Class);
  3469   __ jcc(Assembler::equal, quicked);
  3471   __ push(atos);
  3472   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc) );
  3473   __ pop_ptr(rdx);
  3474   __ load_klass(rdx, rdx);
  3475   __ jmp(resolved);
  3477   // Get superklass in EAX and subklass in EDX
  3478   __ bind(quicked);
  3479   __ load_klass(rdx, rax);
  3480   __ movptr(rax, Address(rcx, rbx, Address::times_ptr, sizeof(constantPoolOopDesc)));
  3482   __ bind(resolved);
  3484   // Generate subtype check.  Blows ECX.  Resets EDI.
  3485   // Superklass in EAX.  Subklass in EDX.
  3486   __ gen_subtype_check( rdx, ok_is_subtype );
  3488   // Come here on failure
  3489   __ xorl(rax,rax);
  3490   __ jmpb(done);
  3491   // Come here on success
  3492   __ bind(ok_is_subtype);
  3493   __ movl(rax, 1);
  3495   // Collect counts on whether this test sees NULLs a lot or not.
  3496   if (ProfileInterpreter) {
  3497     __ jmp(done);
  3498     __ bind(is_null);
  3499     __ profile_null_seen(rcx);
  3500   } else {
  3501     __ bind(is_null);   // same as 'done'
  3503   __ bind(done);
  3504   // rax, = 0: obj == NULL or  obj is not an instanceof the specified klass
  3505   // rax, = 1: obj != NULL and obj is     an instanceof the specified klass
  3509 //----------------------------------------------------------------------------------------------------
  3510 // Breakpoints
  3511 void TemplateTable::_breakpoint() {
  3513   // Note: We get here even if we are single stepping..
  3514   // jbug inists on setting breakpoints at every bytecode
  3515   // even if we are in single step mode.
  3517   transition(vtos, vtos);
  3519   // get the unpatched byte code
  3520   __ get_method(rcx);
  3521   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::get_original_bytecode_at), rcx, rsi);
  3522   __ mov(rbx, rax);
  3524   // post the breakpoint event
  3525   __ get_method(rcx);
  3526   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::_breakpoint), rcx, rsi);
  3528   // complete the execution of original bytecode
  3529   __ dispatch_only_normal(vtos);
  3533 //----------------------------------------------------------------------------------------------------
  3534 // Exceptions
  3536 void TemplateTable::athrow() {
  3537   transition(atos, vtos);
  3538   __ null_check(rax);
  3539   __ jump(ExternalAddress(Interpreter::throw_exception_entry()));
  3543 //----------------------------------------------------------------------------------------------------
  3544 // Synchronization
  3545 //
  3546 // Note: monitorenter & exit are symmetric routines; which is reflected
  3547 //       in the assembly code structure as well
  3548 //
  3549 // Stack layout:
  3550 //
  3551 // [expressions  ] <--- rsp               = expression stack top
  3552 // ..
  3553 // [expressions  ]
  3554 // [monitor entry] <--- monitor block top = expression stack bot
  3555 // ..
  3556 // [monitor entry]
  3557 // [frame data   ] <--- monitor block bot
  3558 // ...
  3559 // [saved rbp,    ] <--- rbp,
  3562 void TemplateTable::monitorenter() {
  3563   transition(atos, vtos);
  3565   // check for NULL object
  3566   __ null_check(rax);
  3568   const Address monitor_block_top(rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
  3569   const Address monitor_block_bot(rbp, frame::interpreter_frame_initial_sp_offset        * wordSize);
  3570   const int entry_size =         (     frame::interpreter_frame_monitor_size()           * wordSize);
  3571   Label allocated;
  3573   // initialize entry pointer
  3574   __ xorl(rdx, rdx);                             // points to free slot or NULL
  3576   // find a free slot in the monitor block (result in rdx)
  3577   { Label entry, loop, exit;
  3578     __ movptr(rcx, monitor_block_top);           // points to current entry, starting with top-most entry
  3580     __ lea(rbx, monitor_block_bot);              // points to word before bottom of monitor block
  3581     __ jmpb(entry);
  3583     __ bind(loop);
  3584     __ cmpptr(Address(rcx, BasicObjectLock::obj_offset_in_bytes()), (int32_t)NULL_WORD);  // check if current entry is used
  3585     __ cmovptr(Assembler::equal, rdx, rcx);      // if not used then remember entry in rdx
  3586     __ cmpptr(rax, Address(rcx, BasicObjectLock::obj_offset_in_bytes()));   // check if current entry is for same object
  3587     __ jccb(Assembler::equal, exit);             // if same object then stop searching
  3588     __ addptr(rcx, entry_size);                  // otherwise advance to next entry
  3589     __ bind(entry);
  3590     __ cmpptr(rcx, rbx);                         // check if bottom reached
  3591     __ jcc(Assembler::notEqual, loop);           // if not at bottom then check this entry
  3592     __ bind(exit);
  3595   __ testptr(rdx, rdx);                          // check if a slot has been found
  3596   __ jccb(Assembler::notZero, allocated);        // if found, continue with that one
  3598   // allocate one if there's no free slot
  3599   { Label entry, loop;
  3600     // 1. compute new pointers                   // rsp: old expression stack top
  3601     __ movptr(rdx, monitor_block_bot);           // rdx: old expression stack bottom
  3602     __ subptr(rsp, entry_size);                  // move expression stack top
  3603     __ subptr(rdx, entry_size);                  // move expression stack bottom
  3604     __ mov(rcx, rsp);                            // set start value for copy loop
  3605     __ movptr(monitor_block_bot, rdx);           // set new monitor block top
  3606     __ jmp(entry);
  3607     // 2. move expression stack contents
  3608     __ bind(loop);
  3609     __ movptr(rbx, Address(rcx, entry_size));    // load expression stack word from old location
  3610     __ movptr(Address(rcx, 0), rbx);             // and store it at new location
  3611     __ addptr(rcx, wordSize);                    // advance to next word
  3612     __ bind(entry);
  3613     __ cmpptr(rcx, rdx);                         // check if bottom reached
  3614     __ jcc(Assembler::notEqual, loop);           // if not at bottom then copy next word
  3617   // call run-time routine
  3618   // rdx: points to monitor entry
  3619   __ bind(allocated);
  3621   // Increment bcp to point to the next bytecode, so exception handling for async. exceptions work correctly.
  3622   // The object has already been poped from the stack, so the expression stack looks correct.
  3623   __ increment(rsi);
  3625   __ movptr(Address(rdx, BasicObjectLock::obj_offset_in_bytes()), rax);     // store object
  3626   __ lock_object(rdx);
  3628   // check to make sure this monitor doesn't cause stack overflow after locking
  3629   __ save_bcp();  // in case of exception
  3630   __ generate_stack_overflow_check(0);
  3632   // The bcp has already been incremented. Just need to dispatch to next instruction.
  3633   __ dispatch_next(vtos);
  3637 void TemplateTable::monitorexit() {
  3638   transition(atos, vtos);
  3640   // check for NULL object
  3641   __ null_check(rax);
  3643   const Address monitor_block_top(rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
  3644   const Address monitor_block_bot(rbp, frame::interpreter_frame_initial_sp_offset        * wordSize);
  3645   const int entry_size =         (     frame::interpreter_frame_monitor_size()           * wordSize);
  3646   Label found;
  3648   // find matching slot
  3649   { Label entry, loop;
  3650     __ movptr(rdx, monitor_block_top);           // points to current entry, starting with top-most entry
  3651     __ lea(rbx, monitor_block_bot);             // points to word before bottom of monitor block
  3652     __ jmpb(entry);
  3654     __ bind(loop);
  3655     __ cmpptr(rax, Address(rdx, BasicObjectLock::obj_offset_in_bytes()));   // check if current entry is for same object
  3656     __ jcc(Assembler::equal, found);             // if same object then stop searching
  3657     __ addptr(rdx, entry_size);                  // otherwise advance to next entry
  3658     __ bind(entry);
  3659     __ cmpptr(rdx, rbx);                         // check if bottom reached
  3660     __ jcc(Assembler::notEqual, loop);           // if not at bottom then check this entry
  3663   // error handling. Unlocking was not block-structured
  3664   Label end;
  3665   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));
  3666   __ should_not_reach_here();
  3668   // call run-time routine
  3669   // rcx: points to monitor entry
  3670   __ bind(found);
  3671   __ push_ptr(rax);                                 // make sure object is on stack (contract with oopMaps)
  3672   __ unlock_object(rdx);
  3673   __ pop_ptr(rax);                                  // discard object
  3674   __ bind(end);
  3678 //----------------------------------------------------------------------------------------------------
  3679 // Wide instructions
  3681 void TemplateTable::wide() {
  3682   transition(vtos, vtos);
  3683   __ load_unsigned_byte(rbx, at_bcp(1));
  3684   ExternalAddress wtable((address)Interpreter::_wentry_point);
  3685   __ jump(ArrayAddress(wtable, Address(noreg, rbx, Address::times_ptr)));
  3686   // Note: the rsi increment step is part of the individual wide bytecode implementations
  3690 //----------------------------------------------------------------------------------------------------
  3691 // Multi arrays
  3693 void TemplateTable::multianewarray() {
  3694   transition(vtos, atos);
  3695   __ load_unsigned_byte(rax, at_bcp(3)); // get number of dimensions
  3696   // last dim is on top of stack; we want address of first one:
  3697   // first_addr = last_addr + (ndims - 1) * stackElementSize - 1*wordsize
  3698   // the latter wordSize to point to the beginning of the array.
  3699   __ lea(  rax, Address(rsp, rax, Interpreter::stackElementScale(), -wordSize));
  3700   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::multianewarray), rax);     // pass in rax,
  3701   __ load_unsigned_byte(rbx, at_bcp(3));
  3702   __ lea(rsp, Address(rsp, rbx, Interpreter::stackElementScale()));  // get rid of counts
  3705 #endif /* !CC_INTERP */

mercurial