src/cpu/x86/vm/templateTable_x86_32.cpp

Thu, 02 Oct 2008 19:58:19 -0700

author
xdono
date
Thu, 02 Oct 2008 19:58:19 -0700
changeset 772
9ee9cf798b59
parent 739
dc7f315e41f7
child 797
f8199438385b
permissions
-rw-r--r--

6754988: Update copyright year
Summary: Update for files that have been modified starting July 2008
Reviewed-by: ohair, tbell

     1 /*
     2  * Copyright 1997-2008 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  *
    23  */
    25 #include "incls/_precompiled.incl"
    26 #include "incls/_templateTable_x86_32.cpp.incl"
    28 #ifndef CC_INTERP
    29 #define __ _masm->
    31 //----------------------------------------------------------------------------------------------------
    32 // Platform-dependent initialization
    34 void TemplateTable::pd_initialize() {
    35   // No i486 specific initialization
    36 }
    38 //----------------------------------------------------------------------------------------------------
    39 // Address computation
    41 // local variables
    42 static inline Address iaddress(int n)            {
    43   return Address(rdi, Interpreter::local_offset_in_bytes(n));
    44 }
    46 static inline Address laddress(int n)            { return iaddress(n + 1); }
    47 static inline Address haddress(int n)            { return iaddress(n + 0); }
    48 static inline Address faddress(int n)            { return iaddress(n); }
    49 static inline Address daddress(int n)            { return laddress(n); }
    50 static inline Address aaddress(int n)            { return iaddress(n); }
    52 static inline Address iaddress(Register r)       {
    53   return Address(rdi, r, Interpreter::stackElementScale(), Interpreter::value_offset_in_bytes());
    54 }
    55 static inline Address laddress(Register r)       {
    56   return Address(rdi, r, Interpreter::stackElementScale(), Interpreter::local_offset_in_bytes(1));
    57 }
    58 static inline Address haddress(Register r)       {
    59   return Address(rdi, r, Interpreter::stackElementScale(), Interpreter::local_offset_in_bytes(0));
    60 }
    62 static inline Address faddress(Register r)       { return iaddress(r); };
    63 static inline Address daddress(Register r)       {
    64   assert(!TaggedStackInterpreter, "This doesn't work");
    65   return laddress(r);
    66 };
    67 static inline Address aaddress(Register r)       { return iaddress(r); };
    69 // expression stack
    70 // (Note: Must not use symmetric equivalents at_rsp_m1/2 since they store
    71 // data beyond the rsp which is potentially unsafe in an MT environment;
    72 // an interrupt may overwrite that data.)
    73 static inline Address at_rsp   () {
    74   return Address(rsp, 0);
    75 }
    77 // At top of Java expression stack which may be different than rsp().  It
    78 // isn't for category 1 objects.
    79 static inline Address at_tos   () {
    80   Address tos = Address(rsp,  Interpreter::expr_offset_in_bytes(0));
    81   return tos;
    82 }
    84 static inline Address at_tos_p1() {
    85   return Address(rsp,  Interpreter::expr_offset_in_bytes(1));
    86 }
    88 static inline Address at_tos_p2() {
    89   return Address(rsp,  Interpreter::expr_offset_in_bytes(2));
    90 }
    92 // Condition conversion
    93 static Assembler::Condition j_not(TemplateTable::Condition cc) {
    94   switch (cc) {
    95     case TemplateTable::equal        : return Assembler::notEqual;
    96     case TemplateTable::not_equal    : return Assembler::equal;
    97     case TemplateTable::less         : return Assembler::greaterEqual;
    98     case TemplateTable::less_equal   : return Assembler::greater;
    99     case TemplateTable::greater      : return Assembler::lessEqual;
   100     case TemplateTable::greater_equal: return Assembler::less;
   101   }
   102   ShouldNotReachHere();
   103   return Assembler::zero;
   104 }
   107 //----------------------------------------------------------------------------------------------------
   108 // Miscelaneous helper routines
   110 Address TemplateTable::at_bcp(int offset) {
   111   assert(_desc->uses_bcp(), "inconsistent uses_bcp information");
   112   return Address(rsi, offset);
   113 }
   116 void TemplateTable::patch_bytecode(Bytecodes::Code bytecode, Register bc,
   117                                    Register scratch,
   118                                    bool load_bc_into_scratch/*=true*/) {
   120   if (!RewriteBytecodes) return;
   121   // the pair bytecodes have already done the load.
   122   if (load_bc_into_scratch) {
   123     __ movl(bc, bytecode);
   124   }
   125   Label patch_done;
   126   if (JvmtiExport::can_post_breakpoint()) {
   127     Label fast_patch;
   128     // if a breakpoint is present we can't rewrite the stream directly
   129     __ movzbl(scratch, at_bcp(0));
   130     __ cmpl(scratch, Bytecodes::_breakpoint);
   131     __ jcc(Assembler::notEqual, fast_patch);
   132     __ get_method(scratch);
   133     // Let breakpoint table handling rewrite to quicker bytecode
   134     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::set_original_bytecode_at), scratch, rsi, bc);
   135 #ifndef ASSERT
   136     __ jmpb(patch_done);
   137     __ bind(fast_patch);
   138   }
   139 #else
   140     __ jmp(patch_done);
   141     __ bind(fast_patch);
   142   }
   143   Label okay;
   144   __ load_unsigned_byte(scratch, at_bcp(0));
   145   __ cmpl(scratch, (int)Bytecodes::java_code(bytecode));
   146   __ jccb(Assembler::equal, okay);
   147   __ cmpl(scratch, bc);
   148   __ jcc(Assembler::equal, okay);
   149   __ stop("patching the wrong bytecode");
   150   __ bind(okay);
   151 #endif
   152   // patch bytecode
   153   __ movb(at_bcp(0), bc);
   154   __ bind(patch_done);
   155 }
   157 //----------------------------------------------------------------------------------------------------
   158 // Individual instructions
   160 void TemplateTable::nop() {
   161   transition(vtos, vtos);
   162   // nothing to do
   163 }
   165 void TemplateTable::shouldnotreachhere() {
   166   transition(vtos, vtos);
   167   __ stop("shouldnotreachhere bytecode");
   168 }
   172 void TemplateTable::aconst_null() {
   173   transition(vtos, atos);
   174   __ xorptr(rax, rax);
   175 }
   178 void TemplateTable::iconst(int value) {
   179   transition(vtos, itos);
   180   if (value == 0) {
   181     __ xorptr(rax, rax);
   182   } else {
   183     __ movptr(rax, value);
   184   }
   185 }
   188 void TemplateTable::lconst(int value) {
   189   transition(vtos, ltos);
   190   if (value == 0) {
   191     __ xorptr(rax, rax);
   192   } else {
   193     __ movptr(rax, value);
   194   }
   195   assert(value >= 0, "check this code");
   196   __ xorptr(rdx, rdx);
   197 }
   200 void TemplateTable::fconst(int value) {
   201   transition(vtos, ftos);
   202          if (value == 0) { __ fldz();
   203   } else if (value == 1) { __ fld1();
   204   } else if (value == 2) { __ fld1(); __ fld1(); __ faddp(); // should do a better solution here
   205   } else                 { ShouldNotReachHere();
   206   }
   207 }
   210 void TemplateTable::dconst(int value) {
   211   transition(vtos, dtos);
   212          if (value == 0) { __ fldz();
   213   } else if (value == 1) { __ fld1();
   214   } else                 { ShouldNotReachHere();
   215   }
   216 }
   219 void TemplateTable::bipush() {
   220   transition(vtos, itos);
   221   __ load_signed_byte(rax, at_bcp(1));
   222 }
   225 void TemplateTable::sipush() {
   226   transition(vtos, itos);
   227   __ load_unsigned_word(rax, at_bcp(1));
   228   __ bswapl(rax);
   229   __ sarl(rax, 16);
   230 }
   232 void TemplateTable::ldc(bool wide) {
   233   transition(vtos, vtos);
   234   Label call_ldc, notFloat, notClass, Done;
   236   if (wide) {
   237     __ get_unsigned_2_byte_index_at_bcp(rbx, 1);
   238   } else {
   239     __ load_unsigned_byte(rbx, at_bcp(1));
   240   }
   241   __ get_cpool_and_tags(rcx, rax);
   242   const int base_offset = constantPoolOopDesc::header_size() * wordSize;
   243   const int tags_offset = typeArrayOopDesc::header_size(T_BYTE) * wordSize;
   245   // get type
   246   __ xorptr(rdx, rdx);
   247   __ movb(rdx, Address(rax, rbx, Address::times_1, tags_offset));
   249   // unresolved string - get the resolved string
   250   __ cmpl(rdx, JVM_CONSTANT_UnresolvedString);
   251   __ jccb(Assembler::equal, call_ldc);
   253   // unresolved class - get the resolved class
   254   __ cmpl(rdx, JVM_CONSTANT_UnresolvedClass);
   255   __ jccb(Assembler::equal, call_ldc);
   257   // unresolved class in error (resolution failed) - call into runtime
   258   // so that the same error from first resolution attempt is thrown.
   259   __ cmpl(rdx, JVM_CONSTANT_UnresolvedClassInError);
   260   __ jccb(Assembler::equal, call_ldc);
   262   // resolved class - need to call vm to get java mirror of the class
   263   __ cmpl(rdx, JVM_CONSTANT_Class);
   264   __ jcc(Assembler::notEqual, notClass);
   266   __ bind(call_ldc);
   267   __ movl(rcx, wide);
   268   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::ldc), rcx);
   269   __ push(atos);
   270   __ jmp(Done);
   272   __ bind(notClass);
   273   __ cmpl(rdx, JVM_CONSTANT_Float);
   274   __ jccb(Assembler::notEqual, notFloat);
   275   // ftos
   276   __ fld_s(    Address(rcx, rbx, Address::times_ptr, base_offset));
   277   __ push(ftos);
   278   __ jmp(Done);
   280   __ bind(notFloat);
   281 #ifdef ASSERT
   282   { Label L;
   283     __ cmpl(rdx, JVM_CONSTANT_Integer);
   284     __ jcc(Assembler::equal, L);
   285     __ cmpl(rdx, JVM_CONSTANT_String);
   286     __ jcc(Assembler::equal, L);
   287     __ stop("unexpected tag type in ldc");
   288     __ bind(L);
   289   }
   290 #endif
   291   Label isOop;
   292   // atos and itos
   293   // String is only oop type we will see here
   294   __ cmpl(rdx, JVM_CONSTANT_String);
   295   __ jccb(Assembler::equal, isOop);
   296   __ movl(rax, Address(rcx, rbx, Address::times_ptr, base_offset));
   297   __ push(itos);
   298   __ jmp(Done);
   299   __ bind(isOop);
   300   __ movptr(rax, Address(rcx, rbx, Address::times_ptr, base_offset));
   301   __ push(atos);
   303   if (VerifyOops) {
   304     __ verify_oop(rax);
   305   }
   306   __ bind(Done);
   307 }
   309 void TemplateTable::ldc2_w() {
   310   transition(vtos, vtos);
   311   Label Long, Done;
   312   __ get_unsigned_2_byte_index_at_bcp(rbx, 1);
   314   __ get_cpool_and_tags(rcx, rax);
   315   const int base_offset = constantPoolOopDesc::header_size() * wordSize;
   316   const int tags_offset = typeArrayOopDesc::header_size(T_BYTE) * wordSize;
   318   // get type
   319   __ cmpb(Address(rax, rbx, Address::times_1, tags_offset), JVM_CONSTANT_Double);
   320   __ jccb(Assembler::notEqual, Long);
   321   // dtos
   322   __ fld_d(    Address(rcx, rbx, Address::times_ptr, base_offset));
   323   __ push(dtos);
   324   __ jmpb(Done);
   326   __ bind(Long);
   327   // ltos
   328   __ movptr(rax, Address(rcx, rbx, Address::times_ptr, base_offset + 0 * wordSize));
   329   NOT_LP64(__ movptr(rdx, Address(rcx, rbx, Address::times_ptr, base_offset + 1 * wordSize)));
   331   __ push(ltos);
   333   __ bind(Done);
   334 }
   337 void TemplateTable::locals_index(Register reg, int offset) {
   338   __ load_unsigned_byte(reg, at_bcp(offset));
   339   __ negptr(reg);
   340 }
   343 void TemplateTable::iload() {
   344   transition(vtos, itos);
   345   if (RewriteFrequentPairs) {
   346     Label rewrite, done;
   348     // get next byte
   349     __ load_unsigned_byte(rbx, at_bcp(Bytecodes::length_for(Bytecodes::_iload)));
   350     // if _iload, wait to rewrite to iload2.  We only want to rewrite the
   351     // last two iloads in a pair.  Comparing against fast_iload means that
   352     // the next bytecode is neither an iload or a caload, and therefore
   353     // an iload pair.
   354     __ cmpl(rbx, Bytecodes::_iload);
   355     __ jcc(Assembler::equal, done);
   357     __ cmpl(rbx, Bytecodes::_fast_iload);
   358     __ movl(rcx, Bytecodes::_fast_iload2);
   359     __ jccb(Assembler::equal, rewrite);
   361     // if _caload, rewrite to fast_icaload
   362     __ cmpl(rbx, Bytecodes::_caload);
   363     __ movl(rcx, Bytecodes::_fast_icaload);
   364     __ jccb(Assembler::equal, rewrite);
   366     // rewrite so iload doesn't check again.
   367     __ movl(rcx, Bytecodes::_fast_iload);
   369     // rewrite
   370     // rcx: fast bytecode
   371     __ bind(rewrite);
   372     patch_bytecode(Bytecodes::_iload, rcx, rbx, false);
   373     __ bind(done);
   374   }
   376   // Get the local value into tos
   377   locals_index(rbx);
   378   __ movl(rax, iaddress(rbx));
   379   debug_only(__ verify_local_tag(frame::TagValue, rbx));
   380 }
   383 void TemplateTable::fast_iload2() {
   384   transition(vtos, itos);
   385   locals_index(rbx);
   386   __ movl(rax, iaddress(rbx));
   387   debug_only(__ verify_local_tag(frame::TagValue, rbx));
   388   __ push(itos);
   389   locals_index(rbx, 3);
   390   __ movl(rax, iaddress(rbx));
   391   debug_only(__ verify_local_tag(frame::TagValue, rbx));
   392 }
   394 void TemplateTable::fast_iload() {
   395   transition(vtos, itos);
   396   locals_index(rbx);
   397   __ movl(rax, iaddress(rbx));
   398   debug_only(__ verify_local_tag(frame::TagValue, rbx));
   399 }
   402 void TemplateTable::lload() {
   403   transition(vtos, ltos);
   404   locals_index(rbx);
   405   __ movptr(rax, laddress(rbx));
   406   NOT_LP64(__ movl(rdx, haddress(rbx)));
   407   debug_only(__ verify_local_tag(frame::TagCategory2, rbx));
   408 }
   411 void TemplateTable::fload() {
   412   transition(vtos, ftos);
   413   locals_index(rbx);
   414   __ fld_s(faddress(rbx));
   415   debug_only(__ verify_local_tag(frame::TagValue, rbx));
   416 }
   419 void TemplateTable::dload() {
   420   transition(vtos, dtos);
   421   locals_index(rbx);
   422   if (TaggedStackInterpreter) {
   423     // Get double out of locals array, onto temp stack and load with
   424     // float instruction into ST0
   425     __ movl(rax, laddress(rbx));
   426     __ movl(rdx, haddress(rbx));
   427     __ push(rdx);  // push hi first
   428     __ push(rax);
   429     __ fld_d(Address(rsp, 0));
   430     __ addptr(rsp, 2*wordSize);
   431     debug_only(__ verify_local_tag(frame::TagCategory2, rbx));
   432   } else {
   433     __ fld_d(daddress(rbx));
   434   }
   435 }
   438 void TemplateTable::aload() {
   439   transition(vtos, atos);
   440   locals_index(rbx);
   441   __ movptr(rax, aaddress(rbx));
   442   debug_only(__ verify_local_tag(frame::TagReference, rbx));
   443 }
   446 void TemplateTable::locals_index_wide(Register reg) {
   447   __ movl(reg, at_bcp(2));
   448   __ bswapl(reg);
   449   __ shrl(reg, 16);
   450   __ negptr(reg);
   451 }
   454 void TemplateTable::wide_iload() {
   455   transition(vtos, itos);
   456   locals_index_wide(rbx);
   457   __ movl(rax, iaddress(rbx));
   458   debug_only(__ verify_local_tag(frame::TagValue, rbx));
   459 }
   462 void TemplateTable::wide_lload() {
   463   transition(vtos, ltos);
   464   locals_index_wide(rbx);
   465   __ movptr(rax, laddress(rbx));
   466   NOT_LP64(__ movl(rdx, haddress(rbx)));
   467   debug_only(__ verify_local_tag(frame::TagCategory2, rbx));
   468 }
   471 void TemplateTable::wide_fload() {
   472   transition(vtos, ftos);
   473   locals_index_wide(rbx);
   474   __ fld_s(faddress(rbx));
   475   debug_only(__ verify_local_tag(frame::TagValue, rbx));
   476 }
   479 void TemplateTable::wide_dload() {
   480   transition(vtos, dtos);
   481   locals_index_wide(rbx);
   482   if (TaggedStackInterpreter) {
   483     // Get double out of locals array, onto temp stack and load with
   484     // float instruction into ST0
   485     __ movl(rax, laddress(rbx));
   486     __ movl(rdx, haddress(rbx));
   487     __ push(rdx);  // push hi first
   488     __ push(rax);
   489     __ fld_d(Address(rsp, 0));
   490     __ addl(rsp, 2*wordSize);
   491     debug_only(__ verify_local_tag(frame::TagCategory2, rbx));
   492   } else {
   493     __ fld_d(daddress(rbx));
   494   }
   495 }
   498 void TemplateTable::wide_aload() {
   499   transition(vtos, atos);
   500   locals_index_wide(rbx);
   501   __ movptr(rax, aaddress(rbx));
   502   debug_only(__ verify_local_tag(frame::TagReference, rbx));
   503 }
   505 void TemplateTable::index_check(Register array, Register index) {
   506   // Pop ptr into array
   507   __ pop_ptr(array);
   508   index_check_without_pop(array, index);
   509 }
   511 void TemplateTable::index_check_without_pop(Register array, Register index) {
   512   // destroys rbx,
   513   // check array
   514   __ null_check(array, arrayOopDesc::length_offset_in_bytes());
   515   LP64_ONLY(__ movslq(index, index));
   516   // check index
   517   __ cmpl(index, Address(array, arrayOopDesc::length_offset_in_bytes()));
   518   if (index != rbx) {
   519     // ??? convention: move aberrant index into rbx, for exception message
   520     assert(rbx != array, "different registers");
   521     __ mov(rbx, index);
   522   }
   523   __ jump_cc(Assembler::aboveEqual,
   524              ExternalAddress(Interpreter::_throw_ArrayIndexOutOfBoundsException_entry));
   525 }
   528 void TemplateTable::iaload() {
   529   transition(itos, itos);
   530   // rdx: array
   531   index_check(rdx, rax);  // kills rbx,
   532   // rax,: index
   533   __ movl(rax, Address(rdx, rax, Address::times_4, arrayOopDesc::base_offset_in_bytes(T_INT)));
   534 }
   537 void TemplateTable::laload() {
   538   transition(itos, ltos);
   539   // rax,: index
   540   // rdx: array
   541   index_check(rdx, rax);
   542   __ mov(rbx, rax);
   543   // rbx,: index
   544   __ movptr(rax, Address(rdx, rbx, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_LONG) + 0 * wordSize));
   545   NOT_LP64(__ movl(rdx, Address(rdx, rbx, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_LONG) + 1 * wordSize)));
   546 }
   549 void TemplateTable::faload() {
   550   transition(itos, ftos);
   551   // rdx: array
   552   index_check(rdx, rax);  // kills rbx,
   553   // rax,: index
   554   __ fld_s(Address(rdx, rax, Address::times_4, arrayOopDesc::base_offset_in_bytes(T_FLOAT)));
   555 }
   558 void TemplateTable::daload() {
   559   transition(itos, dtos);
   560   // rdx: array
   561   index_check(rdx, rax);  // kills rbx,
   562   // rax,: index
   563   __ fld_d(Address(rdx, rax, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_DOUBLE)));
   564 }
   567 void TemplateTable::aaload() {
   568   transition(itos, atos);
   569   // rdx: array
   570   index_check(rdx, rax);  // kills rbx,
   571   // rax,: index
   572   __ movptr(rax, Address(rdx, rax, Address::times_ptr, arrayOopDesc::base_offset_in_bytes(T_OBJECT)));
   573 }
   576 void TemplateTable::baload() {
   577   transition(itos, itos);
   578   // rdx: array
   579   index_check(rdx, rax);  // kills rbx,
   580   // rax,: index
   581   // can do better code for P5 - fix this at some point
   582   __ load_signed_byte(rbx, Address(rdx, rax, Address::times_1, arrayOopDesc::base_offset_in_bytes(T_BYTE)));
   583   __ mov(rax, rbx);
   584 }
   587 void TemplateTable::caload() {
   588   transition(itos, itos);
   589   // rdx: array
   590   index_check(rdx, rax);  // kills rbx,
   591   // rax,: index
   592   // can do better code for P5 - may want to improve this at some point
   593   __ load_unsigned_word(rbx, Address(rdx, rax, Address::times_2, arrayOopDesc::base_offset_in_bytes(T_CHAR)));
   594   __ mov(rax, rbx);
   595 }
   597 // iload followed by caload frequent pair
   598 void TemplateTable::fast_icaload() {
   599   transition(vtos, itos);
   600   // load index out of locals
   601   locals_index(rbx);
   602   __ movl(rax, iaddress(rbx));
   603   debug_only(__ verify_local_tag(frame::TagValue, rbx));
   605   // rdx: array
   606   index_check(rdx, rax);
   607   // rax,: index
   608   __ load_unsigned_word(rbx, Address(rdx, rax, Address::times_2, arrayOopDesc::base_offset_in_bytes(T_CHAR)));
   609   __ mov(rax, rbx);
   610 }
   612 void TemplateTable::saload() {
   613   transition(itos, itos);
   614   // rdx: array
   615   index_check(rdx, rax);  // kills rbx,
   616   // rax,: index
   617   // can do better code for P5 - may want to improve this at some point
   618   __ load_signed_word(rbx, Address(rdx, rax, Address::times_2, arrayOopDesc::base_offset_in_bytes(T_SHORT)));
   619   __ mov(rax, rbx);
   620 }
   623 void TemplateTable::iload(int n) {
   624   transition(vtos, itos);
   625   __ movl(rax, iaddress(n));
   626   debug_only(__ verify_local_tag(frame::TagValue, n));
   627 }
   630 void TemplateTable::lload(int n) {
   631   transition(vtos, ltos);
   632   __ movptr(rax, laddress(n));
   633   NOT_LP64(__ movptr(rdx, haddress(n)));
   634   debug_only(__ verify_local_tag(frame::TagCategory2, n));
   635 }
   638 void TemplateTable::fload(int n) {
   639   transition(vtos, ftos);
   640   __ fld_s(faddress(n));
   641   debug_only(__ verify_local_tag(frame::TagValue, n));
   642 }
   645 void TemplateTable::dload(int n) {
   646   transition(vtos, dtos);
   647   if (TaggedStackInterpreter) {
   648     // Get double out of locals array, onto temp stack and load with
   649     // float instruction into ST0
   650     __ movl(rax, laddress(n));
   651     __ movl(rdx, haddress(n));
   652     __ push(rdx);  // push hi first
   653     __ push(rax);
   654     __ fld_d(Address(rsp, 0));
   655     __ addptr(rsp, 2*wordSize);  // reset rsp
   656     debug_only(__ verify_local_tag(frame::TagCategory2, n));
   657   } else {
   658     __ fld_d(daddress(n));
   659   }
   660 }
   663 void TemplateTable::aload(int n) {
   664   transition(vtos, atos);
   665   __ movptr(rax, aaddress(n));
   666   debug_only(__ verify_local_tag(frame::TagReference, n));
   667 }
   670 void TemplateTable::aload_0() {
   671   transition(vtos, atos);
   672   // According to bytecode histograms, the pairs:
   673   //
   674   // _aload_0, _fast_igetfield
   675   // _aload_0, _fast_agetfield
   676   // _aload_0, _fast_fgetfield
   677   //
   678   // occur frequently. If RewriteFrequentPairs is set, the (slow) _aload_0
   679   // bytecode checks if the next bytecode is either _fast_igetfield,
   680   // _fast_agetfield or _fast_fgetfield and then rewrites the
   681   // current bytecode into a pair bytecode; otherwise it rewrites the current
   682   // bytecode into _fast_aload_0 that doesn't do the pair check anymore.
   683   //
   684   // Note: If the next bytecode is _getfield, the rewrite must be delayed,
   685   //       otherwise we may miss an opportunity for a pair.
   686   //
   687   // Also rewrite frequent pairs
   688   //   aload_0, aload_1
   689   //   aload_0, iload_1
   690   // These bytecodes with a small amount of code are most profitable to rewrite
   691   if (RewriteFrequentPairs) {
   692     Label rewrite, done;
   693     // get next byte
   694     __ load_unsigned_byte(rbx, at_bcp(Bytecodes::length_for(Bytecodes::_aload_0)));
   696     // do actual aload_0
   697     aload(0);
   699     // if _getfield then wait with rewrite
   700     __ cmpl(rbx, Bytecodes::_getfield);
   701     __ jcc(Assembler::equal, done);
   703     // if _igetfield then reqrite to _fast_iaccess_0
   704     assert(Bytecodes::java_code(Bytecodes::_fast_iaccess_0) == Bytecodes::_aload_0, "fix bytecode definition");
   705     __ cmpl(rbx, Bytecodes::_fast_igetfield);
   706     __ movl(rcx, Bytecodes::_fast_iaccess_0);
   707     __ jccb(Assembler::equal, rewrite);
   709     // if _agetfield then reqrite to _fast_aaccess_0
   710     assert(Bytecodes::java_code(Bytecodes::_fast_aaccess_0) == Bytecodes::_aload_0, "fix bytecode definition");
   711     __ cmpl(rbx, Bytecodes::_fast_agetfield);
   712     __ movl(rcx, Bytecodes::_fast_aaccess_0);
   713     __ jccb(Assembler::equal, rewrite);
   715     // if _fgetfield then reqrite to _fast_faccess_0
   716     assert(Bytecodes::java_code(Bytecodes::_fast_faccess_0) == Bytecodes::_aload_0, "fix bytecode definition");
   717     __ cmpl(rbx, Bytecodes::_fast_fgetfield);
   718     __ movl(rcx, Bytecodes::_fast_faccess_0);
   719     __ jccb(Assembler::equal, rewrite);
   721     // else rewrite to _fast_aload0
   722     assert(Bytecodes::java_code(Bytecodes::_fast_aload_0) == Bytecodes::_aload_0, "fix bytecode definition");
   723     __ movl(rcx, Bytecodes::_fast_aload_0);
   725     // rewrite
   726     // rcx: fast bytecode
   727     __ bind(rewrite);
   728     patch_bytecode(Bytecodes::_aload_0, rcx, rbx, false);
   730     __ bind(done);
   731   } else {
   732     aload(0);
   733   }
   734 }
   736 void TemplateTable::istore() {
   737   transition(itos, vtos);
   738   locals_index(rbx);
   739   __ movl(iaddress(rbx), rax);
   740   __ tag_local(frame::TagValue, rbx);
   741 }
   744 void TemplateTable::lstore() {
   745   transition(ltos, vtos);
   746   locals_index(rbx);
   747   __ movptr(laddress(rbx), rax);
   748   NOT_LP64(__ movptr(haddress(rbx), rdx));
   749   __ tag_local(frame::TagCategory2, rbx);
   750 }
   753 void TemplateTable::fstore() {
   754   transition(ftos, vtos);
   755   locals_index(rbx);
   756   __ fstp_s(faddress(rbx));
   757   __ tag_local(frame::TagValue, rbx);
   758 }
   761 void TemplateTable::dstore() {
   762   transition(dtos, vtos);
   763   locals_index(rbx);
   764   if (TaggedStackInterpreter) {
   765     // Store double on stack and reload into locals nonadjacently
   766     __ subptr(rsp, 2 * wordSize);
   767     __ fstp_d(Address(rsp, 0));
   768     __ pop(rax);
   769     __ pop(rdx);
   770     __ movptr(laddress(rbx), rax);
   771     __ movptr(haddress(rbx), rdx);
   772     __ tag_local(frame::TagCategory2, rbx);
   773   } else {
   774     __ fstp_d(daddress(rbx));
   775   }
   776 }
   779 void TemplateTable::astore() {
   780   transition(vtos, vtos);
   781   __ pop_ptr(rax, rdx);   // will need to pop tag too
   782   locals_index(rbx);
   783   __ movptr(aaddress(rbx), rax);
   784   __ tag_local(rdx, rbx);    // need to store same tag in local may be returnAddr
   785 }
   788 void TemplateTable::wide_istore() {
   789   transition(vtos, vtos);
   790   __ pop_i(rax);
   791   locals_index_wide(rbx);
   792   __ movl(iaddress(rbx), rax);
   793   __ tag_local(frame::TagValue, rbx);
   794 }
   797 void TemplateTable::wide_lstore() {
   798   transition(vtos, vtos);
   799   __ pop_l(rax, rdx);
   800   locals_index_wide(rbx);
   801   __ movptr(laddress(rbx), rax);
   802   NOT_LP64(__ movl(haddress(rbx), rdx));
   803   __ tag_local(frame::TagCategory2, rbx);
   804 }
   807 void TemplateTable::wide_fstore() {
   808   wide_istore();
   809 }
   812 void TemplateTable::wide_dstore() {
   813   wide_lstore();
   814 }
   817 void TemplateTable::wide_astore() {
   818   transition(vtos, vtos);
   819   __ pop_ptr(rax, rdx);
   820   locals_index_wide(rbx);
   821   __ movptr(aaddress(rbx), rax);
   822   __ tag_local(rdx, rbx);
   823 }
   826 void TemplateTable::iastore() {
   827   transition(itos, vtos);
   828   __ pop_i(rbx);
   829   // rax,: value
   830   // rdx: array
   831   index_check(rdx, rbx);  // prefer index in rbx,
   832   // rbx,: index
   833   __ movl(Address(rdx, rbx, Address::times_4, arrayOopDesc::base_offset_in_bytes(T_INT)), rax);
   834 }
   837 void TemplateTable::lastore() {
   838   transition(ltos, vtos);
   839   __ pop_i(rbx);
   840   // rax,: low(value)
   841   // rcx: array
   842   // rdx: high(value)
   843   index_check(rcx, rbx);  // prefer index in rbx,
   844   // rbx,: index
   845   __ movptr(Address(rcx, rbx, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_LONG) + 0 * wordSize), rax);
   846   NOT_LP64(__ movl(Address(rcx, rbx, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_LONG) + 1 * wordSize), rdx));
   847 }
   850 void TemplateTable::fastore() {
   851   transition(ftos, vtos);
   852   __ pop_i(rbx);
   853   // rdx: array
   854   // st0: value
   855   index_check(rdx, rbx);  // prefer index in rbx,
   856   // rbx,: index
   857   __ fstp_s(Address(rdx, rbx, Address::times_4, arrayOopDesc::base_offset_in_bytes(T_FLOAT)));
   858 }
   861 void TemplateTable::dastore() {
   862   transition(dtos, vtos);
   863   __ pop_i(rbx);
   864   // rdx: array
   865   // st0: value
   866   index_check(rdx, rbx);  // prefer index in rbx,
   867   // rbx,: index
   868   __ fstp_d(Address(rdx, rbx, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_DOUBLE)));
   869 }
   872 void TemplateTable::aastore() {
   873   Label is_null, ok_is_subtype, done;
   874   transition(vtos, vtos);
   875   // stack: ..., array, index, value
   876   __ movptr(rax, at_tos());     // Value
   877   __ movl(rcx, at_tos_p1());  // Index
   878   __ movptr(rdx, at_tos_p2());  // Array
   879   index_check_without_pop(rdx, rcx);      // kills rbx,
   880   // do array store check - check for NULL value first
   881   __ testptr(rax, rax);
   882   __ jcc(Assembler::zero, is_null);
   884   // Move subklass into EBX
   885   __ movptr(rbx, Address(rax, oopDesc::klass_offset_in_bytes()));
   886   // Move superklass into EAX
   887   __ movptr(rax, Address(rdx, oopDesc::klass_offset_in_bytes()));
   888   __ movptr(rax, Address(rax, sizeof(oopDesc) + objArrayKlass::element_klass_offset_in_bytes()));
   889   // Compress array+index*wordSize+12 into a single register.  Frees ECX.
   890   __ lea(rdx, Address(rdx, rcx, Address::times_ptr, arrayOopDesc::base_offset_in_bytes(T_OBJECT)));
   892   // Generate subtype check.  Blows ECX.  Resets EDI to locals.
   893   // Superklass in EAX.  Subklass in EBX.
   894   __ gen_subtype_check( rbx, ok_is_subtype );
   896   // Come here on failure
   897   // object is at TOS
   898   __ jump(ExternalAddress(Interpreter::_throw_ArrayStoreException_entry));
   900   // Come here on success
   901   __ bind(ok_is_subtype);
   902   __ movptr(rax, at_rsp());     // Value
   903   __ movptr(Address(rdx, 0), rax);
   904   __ store_check(rdx);
   905   __ jmpb(done);
   907   // Have a NULL in EAX, EDX=array, ECX=index.  Store NULL at ary[idx]
   908   __ bind(is_null);
   909   __ profile_null_seen(rbx);
   910   __ movptr(Address(rdx, rcx, Address::times_ptr, arrayOopDesc::base_offset_in_bytes(T_OBJECT)), rax);
   912   // Pop stack arguments
   913   __ bind(done);
   914   __ addptr(rsp, 3 * Interpreter::stackElementSize());
   915 }
   918 void TemplateTable::bastore() {
   919   transition(itos, vtos);
   920   __ pop_i(rbx);
   921   // rax,: value
   922   // rdx: array
   923   index_check(rdx, rbx);  // prefer index in rbx,
   924   // rbx,: index
   925   __ movb(Address(rdx, rbx, Address::times_1, arrayOopDesc::base_offset_in_bytes(T_BYTE)), rax);
   926 }
   929 void TemplateTable::castore() {
   930   transition(itos, vtos);
   931   __ pop_i(rbx);
   932   // rax,: value
   933   // rdx: array
   934   index_check(rdx, rbx);  // prefer index in rbx,
   935   // rbx,: index
   936   __ movw(Address(rdx, rbx, Address::times_2, arrayOopDesc::base_offset_in_bytes(T_CHAR)), rax);
   937 }
   940 void TemplateTable::sastore() {
   941   castore();
   942 }
   945 void TemplateTable::istore(int n) {
   946   transition(itos, vtos);
   947   __ movl(iaddress(n), rax);
   948   __ tag_local(frame::TagValue, n);
   949 }
   952 void TemplateTable::lstore(int n) {
   953   transition(ltos, vtos);
   954   __ movptr(laddress(n), rax);
   955   NOT_LP64(__ movptr(haddress(n), rdx));
   956   __ tag_local(frame::TagCategory2, n);
   957 }
   960 void TemplateTable::fstore(int n) {
   961   transition(ftos, vtos);
   962   __ fstp_s(faddress(n));
   963   __ tag_local(frame::TagValue, n);
   964 }
   967 void TemplateTable::dstore(int n) {
   968   transition(dtos, vtos);
   969   if (TaggedStackInterpreter) {
   970     __ subptr(rsp, 2 * wordSize);
   971     __ fstp_d(Address(rsp, 0));
   972     __ pop(rax);
   973     __ pop(rdx);
   974     __ movl(laddress(n), rax);
   975     __ movl(haddress(n), rdx);
   976     __ tag_local(frame::TagCategory2, n);
   977   } else {
   978     __ fstp_d(daddress(n));
   979   }
   980 }
   983 void TemplateTable::astore(int n) {
   984   transition(vtos, vtos);
   985   __ pop_ptr(rax, rdx);
   986   __ movptr(aaddress(n), rax);
   987   __ tag_local(rdx, n);
   988 }
   991 void TemplateTable::pop() {
   992   transition(vtos, vtos);
   993   __ addptr(rsp, Interpreter::stackElementSize());
   994 }
   997 void TemplateTable::pop2() {
   998   transition(vtos, vtos);
   999   __ addptr(rsp, 2*Interpreter::stackElementSize());
  1003 void TemplateTable::dup() {
  1004   transition(vtos, vtos);
  1005   // stack: ..., a
  1006   __ load_ptr_and_tag(0, rax, rdx);
  1007   __ push_ptr(rax, rdx);
  1008   // stack: ..., a, a
  1012 void TemplateTable::dup_x1() {
  1013   transition(vtos, vtos);
  1014   // stack: ..., a, b
  1015   __ load_ptr_and_tag(0, rax, rdx);  // load b
  1016   __ load_ptr_and_tag(1, rcx, rbx);  // load a
  1017   __ store_ptr_and_tag(1, rax, rdx); // store b
  1018   __ store_ptr_and_tag(0, rcx, rbx); // store a
  1019   __ push_ptr(rax, rdx);             // push b
  1020   // stack: ..., b, a, b
  1024 void TemplateTable::dup_x2() {
  1025   transition(vtos, vtos);
  1026   // stack: ..., a, b, c
  1027   __ load_ptr_and_tag(0, rax, rdx);  // load c
  1028   __ load_ptr_and_tag(2, rcx, rbx);  // load a
  1029   __ store_ptr_and_tag(2, rax, rdx); // store c in a
  1030   __ push_ptr(rax, rdx);             // push c
  1031   // stack: ..., c, b, c, c
  1032   __ load_ptr_and_tag(2, rax, rdx);  // load b
  1033   __ store_ptr_and_tag(2, rcx, rbx); // store a in b
  1034   // stack: ..., c, a, c, c
  1035   __ store_ptr_and_tag(1, rax, rdx); // store b in c
  1036   // stack: ..., c, a, b, c
  1040 void TemplateTable::dup2() {
  1041   transition(vtos, vtos);
  1042   // stack: ..., a, b
  1043   __ load_ptr_and_tag(1, rax, rdx);  // load a
  1044   __ push_ptr(rax, rdx);             // push a
  1045   __ load_ptr_and_tag(1, rax, rdx);  // load b
  1046   __ push_ptr(rax, rdx);             // push b
  1047   // stack: ..., a, b, a, b
  1051 void TemplateTable::dup2_x1() {
  1052   transition(vtos, vtos);
  1053   // stack: ..., a, b, c
  1054   __ load_ptr_and_tag(0, rcx, rbx);  // load c
  1055   __ load_ptr_and_tag(1, rax, rdx);  // load b
  1056   __ push_ptr(rax, rdx);             // push b
  1057   __ push_ptr(rcx, rbx);             // push c
  1058   // stack: ..., a, b, c, b, c
  1059   __ store_ptr_and_tag(3, rcx, rbx); // store c in b
  1060   // stack: ..., a, c, c, b, c
  1061   __ load_ptr_and_tag(4, rcx, rbx);  // load a
  1062   __ store_ptr_and_tag(2, rcx, rbx); // store a in 2nd c
  1063   // stack: ..., a, c, a, b, c
  1064   __ store_ptr_and_tag(4, rax, rdx); // store b in a
  1065   // stack: ..., b, c, a, b, c
  1066   // stack: ..., b, c, a, b, c
  1070 void TemplateTable::dup2_x2() {
  1071   transition(vtos, vtos);
  1072   // stack: ..., a, b, c, d
  1073   __ load_ptr_and_tag(0, rcx, rbx);  // load d
  1074   __ load_ptr_and_tag(1, rax, rdx);  // load c
  1075   __ push_ptr(rax, rdx);             // push c
  1076   __ push_ptr(rcx, rbx);             // push d
  1077   // stack: ..., a, b, c, d, c, d
  1078   __ load_ptr_and_tag(4, rax, rdx);  // load b
  1079   __ store_ptr_and_tag(2, rax, rdx); // store b in d
  1080   __ store_ptr_and_tag(4, rcx, rbx); // store d in b
  1081   // stack: ..., a, d, c, b, c, d
  1082   __ load_ptr_and_tag(5, rcx, rbx);  // load a
  1083   __ load_ptr_and_tag(3, rax, rdx);  // load c
  1084   __ store_ptr_and_tag(3, rcx, rbx); // store a in c
  1085   __ store_ptr_and_tag(5, rax, rdx); // store c in a
  1086   // stack: ..., c, d, a, b, c, d
  1087   // stack: ..., c, d, a, b, c, d
  1091 void TemplateTable::swap() {
  1092   transition(vtos, vtos);
  1093   // stack: ..., a, b
  1094   __ load_ptr_and_tag(1, rcx, rbx);  // load a
  1095   __ load_ptr_and_tag(0, rax, rdx);  // load b
  1096   __ store_ptr_and_tag(0, rcx, rbx); // store a in b
  1097   __ store_ptr_and_tag(1, rax, rdx); // store b in a
  1098   // stack: ..., b, a
  1102 void TemplateTable::iop2(Operation op) {
  1103   transition(itos, itos);
  1104   switch (op) {
  1105     case add  :                    __ pop_i(rdx); __ addl (rax, rdx); break;
  1106     case sub  : __ mov(rdx, rax); __ pop_i(rax); __ subl (rax, rdx); break;
  1107     case mul  :                    __ pop_i(rdx); __ imull(rax, rdx); break;
  1108     case _and :                    __ pop_i(rdx); __ andl (rax, rdx); break;
  1109     case _or  :                    __ pop_i(rdx); __ orl  (rax, rdx); break;
  1110     case _xor :                    __ pop_i(rdx); __ xorl (rax, rdx); break;
  1111     case shl  : __ mov(rcx, rax); __ pop_i(rax); __ shll (rax);      break; // implicit masking of lower 5 bits by Intel shift instr.
  1112     case shr  : __ mov(rcx, rax); __ pop_i(rax); __ sarl (rax);      break; // implicit masking of lower 5 bits by Intel shift instr.
  1113     case ushr : __ mov(rcx, rax); __ pop_i(rax); __ shrl (rax);      break; // implicit masking of lower 5 bits by Intel shift instr.
  1114     default   : ShouldNotReachHere();
  1119 void TemplateTable::lop2(Operation op) {
  1120   transition(ltos, ltos);
  1121   __ pop_l(rbx, rcx);
  1122   switch (op) {
  1123     case add : __ addl(rax, rbx); __ adcl(rdx, rcx); break;
  1124     case sub : __ subl(rbx, rax); __ sbbl(rcx, rdx);
  1125                __ mov(rax, rbx); __ mov(rdx, rcx); break;
  1126     case _and: __ andl(rax, rbx); __ andl(rdx, rcx); break;
  1127     case _or : __ orl (rax, rbx); __ orl (rdx, rcx); break;
  1128     case _xor: __ xorl(rax, rbx); __ xorl(rdx, rcx); break;
  1129     default : ShouldNotReachHere();
  1134 void TemplateTable::idiv() {
  1135   transition(itos, itos);
  1136   __ mov(rcx, rax);
  1137   __ pop_i(rax);
  1138   // Note: could xor rax, and rcx and compare with (-1 ^ min_int). If
  1139   //       they are not equal, one could do a normal division (no correction
  1140   //       needed), which may speed up this implementation for the common case.
  1141   //       (see also JVM spec., p.243 & p.271)
  1142   __ corrected_idivl(rcx);
  1146 void TemplateTable::irem() {
  1147   transition(itos, itos);
  1148   __ mov(rcx, rax);
  1149   __ pop_i(rax);
  1150   // Note: could xor rax, and rcx and compare with (-1 ^ min_int). If
  1151   //       they are not equal, one could do a normal division (no correction
  1152   //       needed), which may speed up this implementation for the common case.
  1153   //       (see also JVM spec., p.243 & p.271)
  1154   __ corrected_idivl(rcx);
  1155   __ mov(rax, rdx);
  1159 void TemplateTable::lmul() {
  1160   transition(ltos, ltos);
  1161   __ pop_l(rbx, rcx);
  1162   __ push(rcx); __ push(rbx);
  1163   __ push(rdx); __ push(rax);
  1164   __ lmul(2 * wordSize, 0);
  1165   __ addptr(rsp, 4 * wordSize);  // take off temporaries
  1169 void TemplateTable::ldiv() {
  1170   transition(ltos, ltos);
  1171   __ pop_l(rbx, rcx);
  1172   __ push(rcx); __ push(rbx);
  1173   __ push(rdx); __ push(rax);
  1174   // check if y = 0
  1175   __ orl(rax, rdx);
  1176   __ jump_cc(Assembler::zero,
  1177              ExternalAddress(Interpreter::_throw_ArithmeticException_entry));
  1178   __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::ldiv));
  1179   __ addptr(rsp, 4 * wordSize);  // take off temporaries
  1183 void TemplateTable::lrem() {
  1184   transition(ltos, ltos);
  1185   __ pop_l(rbx, rcx);
  1186   __ push(rcx); __ push(rbx);
  1187   __ push(rdx); __ push(rax);
  1188   // check if y = 0
  1189   __ orl(rax, rdx);
  1190   __ jump_cc(Assembler::zero,
  1191              ExternalAddress(Interpreter::_throw_ArithmeticException_entry));
  1192   __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::lrem));
  1193   __ addptr(rsp, 4 * wordSize);
  1197 void TemplateTable::lshl() {
  1198   transition(itos, ltos);
  1199   __ movl(rcx, rax);                             // get shift count
  1200   __ pop_l(rax, rdx);                            // get shift value
  1201   __ lshl(rdx, rax);
  1205 void TemplateTable::lshr() {
  1206   transition(itos, ltos);
  1207   __ mov(rcx, rax);                              // get shift count
  1208   __ pop_l(rax, rdx);                            // get shift value
  1209   __ lshr(rdx, rax, true);
  1213 void TemplateTable::lushr() {
  1214   transition(itos, ltos);
  1215   __ mov(rcx, rax);                              // get shift count
  1216   __ pop_l(rax, rdx);                            // get shift value
  1217   __ lshr(rdx, rax);
  1221 void TemplateTable::fop2(Operation op) {
  1222   transition(ftos, ftos);
  1223   __ pop_ftos_to_rsp();  // pop ftos into rsp
  1224   switch (op) {
  1225     case add: __ fadd_s (at_rsp());                break;
  1226     case sub: __ fsubr_s(at_rsp());                break;
  1227     case mul: __ fmul_s (at_rsp());                break;
  1228     case div: __ fdivr_s(at_rsp());                break;
  1229     case rem: __ fld_s  (at_rsp()); __ fremr(rax); break;
  1230     default : ShouldNotReachHere();
  1232   __ f2ieee();
  1233   __ pop(rax);  // pop float thing off
  1237 void TemplateTable::dop2(Operation op) {
  1238   transition(dtos, dtos);
  1239   __ pop_dtos_to_rsp();  // pop dtos into rsp
  1241   switch (op) {
  1242     case add: __ fadd_d (at_rsp());                break;
  1243     case sub: __ fsubr_d(at_rsp());                break;
  1244     case mul: {
  1245       Label L_strict;
  1246       Label L_join;
  1247       const Address access_flags      (rcx, methodOopDesc::access_flags_offset());
  1248       __ get_method(rcx);
  1249       __ movl(rcx, access_flags);
  1250       __ testl(rcx, JVM_ACC_STRICT);
  1251       __ jccb(Assembler::notZero, L_strict);
  1252       __ fmul_d (at_rsp());
  1253       __ jmpb(L_join);
  1254       __ bind(L_strict);
  1255       __ fld_x(ExternalAddress(StubRoutines::addr_fpu_subnormal_bias1()));
  1256       __ fmulp();
  1257       __ fmul_d (at_rsp());
  1258       __ fld_x(ExternalAddress(StubRoutines::addr_fpu_subnormal_bias2()));
  1259       __ fmulp();
  1260       __ bind(L_join);
  1261       break;
  1263     case div: {
  1264       Label L_strict;
  1265       Label L_join;
  1266       const Address access_flags      (rcx, methodOopDesc::access_flags_offset());
  1267       __ get_method(rcx);
  1268       __ movl(rcx, access_flags);
  1269       __ testl(rcx, JVM_ACC_STRICT);
  1270       __ jccb(Assembler::notZero, L_strict);
  1271       __ fdivr_d(at_rsp());
  1272       __ jmp(L_join);
  1273       __ bind(L_strict);
  1274       __ fld_x(ExternalAddress(StubRoutines::addr_fpu_subnormal_bias1()));
  1275       __ fmul_d (at_rsp());
  1276       __ fdivrp();
  1277       __ fld_x(ExternalAddress(StubRoutines::addr_fpu_subnormal_bias2()));
  1278       __ fmulp();
  1279       __ bind(L_join);
  1280       break;
  1282     case rem: __ fld_d  (at_rsp()); __ fremr(rax); break;
  1283     default : ShouldNotReachHere();
  1285   __ d2ieee();
  1286   // Pop double precision number from rsp.
  1287   __ pop(rax);
  1288   __ pop(rdx);
  1292 void TemplateTable::ineg() {
  1293   transition(itos, itos);
  1294   __ negl(rax);
  1298 void TemplateTable::lneg() {
  1299   transition(ltos, ltos);
  1300   __ lneg(rdx, rax);
  1304 void TemplateTable::fneg() {
  1305   transition(ftos, ftos);
  1306   __ fchs();
  1310 void TemplateTable::dneg() {
  1311   transition(dtos, dtos);
  1312   __ fchs();
  1316 void TemplateTable::iinc() {
  1317   transition(vtos, vtos);
  1318   __ load_signed_byte(rdx, at_bcp(2));           // get constant
  1319   locals_index(rbx);
  1320   __ addl(iaddress(rbx), rdx);
  1324 void TemplateTable::wide_iinc() {
  1325   transition(vtos, vtos);
  1326   __ movl(rdx, at_bcp(4));                       // get constant
  1327   locals_index_wide(rbx);
  1328   __ bswapl(rdx);                                 // swap bytes & sign-extend constant
  1329   __ sarl(rdx, 16);
  1330   __ addl(iaddress(rbx), rdx);
  1331   // Note: should probably use only one movl to get both
  1332   //       the index and the constant -> fix this
  1336 void TemplateTable::convert() {
  1337   // Checking
  1338 #ifdef ASSERT
  1339   { TosState tos_in  = ilgl;
  1340     TosState tos_out = ilgl;
  1341     switch (bytecode()) {
  1342       case Bytecodes::_i2l: // fall through
  1343       case Bytecodes::_i2f: // fall through
  1344       case Bytecodes::_i2d: // fall through
  1345       case Bytecodes::_i2b: // fall through
  1346       case Bytecodes::_i2c: // fall through
  1347       case Bytecodes::_i2s: tos_in = itos; break;
  1348       case Bytecodes::_l2i: // fall through
  1349       case Bytecodes::_l2f: // fall through
  1350       case Bytecodes::_l2d: tos_in = ltos; break;
  1351       case Bytecodes::_f2i: // fall through
  1352       case Bytecodes::_f2l: // fall through
  1353       case Bytecodes::_f2d: tos_in = ftos; break;
  1354       case Bytecodes::_d2i: // fall through
  1355       case Bytecodes::_d2l: // fall through
  1356       case Bytecodes::_d2f: tos_in = dtos; break;
  1357       default             : ShouldNotReachHere();
  1359     switch (bytecode()) {
  1360       case Bytecodes::_l2i: // fall through
  1361       case Bytecodes::_f2i: // fall through
  1362       case Bytecodes::_d2i: // fall through
  1363       case Bytecodes::_i2b: // fall through
  1364       case Bytecodes::_i2c: // fall through
  1365       case Bytecodes::_i2s: tos_out = itos; break;
  1366       case Bytecodes::_i2l: // fall through
  1367       case Bytecodes::_f2l: // fall through
  1368       case Bytecodes::_d2l: tos_out = ltos; break;
  1369       case Bytecodes::_i2f: // fall through
  1370       case Bytecodes::_l2f: // fall through
  1371       case Bytecodes::_d2f: tos_out = ftos; break;
  1372       case Bytecodes::_i2d: // fall through
  1373       case Bytecodes::_l2d: // fall through
  1374       case Bytecodes::_f2d: tos_out = dtos; break;
  1375       default             : ShouldNotReachHere();
  1377     transition(tos_in, tos_out);
  1379 #endif // ASSERT
  1381   // Conversion
  1382   // (Note: use push(rcx)/pop(rcx) for 1/2-word stack-ptr manipulation)
  1383   switch (bytecode()) {
  1384     case Bytecodes::_i2l:
  1385       __ extend_sign(rdx, rax);
  1386       break;
  1387     case Bytecodes::_i2f:
  1388       __ push(rax);          // store int on tos
  1389       __ fild_s(at_rsp());   // load int to ST0
  1390       __ f2ieee();           // truncate to float size
  1391       __ pop(rcx);           // adjust rsp
  1392       break;
  1393     case Bytecodes::_i2d:
  1394       __ push(rax);          // add one slot for d2ieee()
  1395       __ push(rax);          // store int on tos
  1396       __ fild_s(at_rsp());   // load int to ST0
  1397       __ d2ieee();           // truncate to double size
  1398       __ pop(rcx);           // adjust rsp
  1399       __ pop(rcx);
  1400       break;
  1401     case Bytecodes::_i2b:
  1402       __ shll(rax, 24);      // truncate upper 24 bits
  1403       __ sarl(rax, 24);      // and sign-extend byte
  1404       LP64_ONLY(__ movsbl(rax, rax));
  1405       break;
  1406     case Bytecodes::_i2c:
  1407       __ andl(rax, 0xFFFF);  // truncate upper 16 bits
  1408       LP64_ONLY(__ movzwl(rax, rax));
  1409       break;
  1410     case Bytecodes::_i2s:
  1411       __ shll(rax, 16);      // truncate upper 16 bits
  1412       __ sarl(rax, 16);      // and sign-extend short
  1413       LP64_ONLY(__ movswl(rax, rax));
  1414       break;
  1415     case Bytecodes::_l2i:
  1416       /* nothing to do */
  1417       break;
  1418     case Bytecodes::_l2f:
  1419       __ push(rdx);          // store long on tos
  1420       __ push(rax);
  1421       __ fild_d(at_rsp());   // load long to ST0
  1422       __ f2ieee();           // truncate to float size
  1423       __ pop(rcx);           // adjust rsp
  1424       __ pop(rcx);
  1425       break;
  1426     case Bytecodes::_l2d:
  1427       __ push(rdx);          // store long on tos
  1428       __ push(rax);
  1429       __ fild_d(at_rsp());   // load long to ST0
  1430       __ d2ieee();           // truncate to double size
  1431       __ pop(rcx);           // adjust rsp
  1432       __ pop(rcx);
  1433       break;
  1434     case Bytecodes::_f2i:
  1435       __ push(rcx);          // reserve space for argument
  1436       __ fstp_s(at_rsp());   // pass float argument on stack
  1437       __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::f2i), 1);
  1438       break;
  1439     case Bytecodes::_f2l:
  1440       __ push(rcx);          // reserve space for argument
  1441       __ fstp_s(at_rsp());   // pass float argument on stack
  1442       __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::f2l), 1);
  1443       break;
  1444     case Bytecodes::_f2d:
  1445       /* nothing to do */
  1446       break;
  1447     case Bytecodes::_d2i:
  1448       __ push(rcx);          // reserve space for argument
  1449       __ push(rcx);
  1450       __ fstp_d(at_rsp());   // pass double argument on stack
  1451       __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::d2i), 2);
  1452       break;
  1453     case Bytecodes::_d2l:
  1454       __ push(rcx);          // reserve space for argument
  1455       __ push(rcx);
  1456       __ fstp_d(at_rsp());   // pass double argument on stack
  1457       __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::d2l), 2);
  1458       break;
  1459     case Bytecodes::_d2f:
  1460       __ push(rcx);          // reserve space for f2ieee()
  1461       __ f2ieee();           // truncate to float size
  1462       __ pop(rcx);           // adjust rsp
  1463       break;
  1464     default             :
  1465       ShouldNotReachHere();
  1470 void TemplateTable::lcmp() {
  1471   transition(ltos, itos);
  1472   // y = rdx:rax
  1473   __ pop_l(rbx, rcx);             // get x = rcx:rbx
  1474   __ lcmp2int(rcx, rbx, rdx, rax);// rcx := cmp(x, y)
  1475   __ mov(rax, rcx);
  1479 void TemplateTable::float_cmp(bool is_float, int unordered_result) {
  1480   if (is_float) {
  1481     __ pop_ftos_to_rsp();
  1482     __ fld_s(at_rsp());
  1483   } else {
  1484     __ pop_dtos_to_rsp();
  1485     __ fld_d(at_rsp());
  1486     __ pop(rdx);
  1488   __ pop(rcx);
  1489   __ fcmp2int(rax, unordered_result < 0);
  1493 void TemplateTable::branch(bool is_jsr, bool is_wide) {
  1494   __ get_method(rcx);           // ECX holds method
  1495   __ profile_taken_branch(rax,rbx); // EAX holds updated MDP, EBX holds bumped taken count
  1497   const ByteSize be_offset = methodOopDesc::backedge_counter_offset() + InvocationCounter::counter_offset();
  1498   const ByteSize inv_offset = methodOopDesc::invocation_counter_offset() + InvocationCounter::counter_offset();
  1499   const int method_offset = frame::interpreter_frame_method_offset * wordSize;
  1501   // Load up EDX with the branch displacement
  1502   __ movl(rdx, at_bcp(1));
  1503   __ bswapl(rdx);
  1504   if (!is_wide) __ sarl(rdx, 16);
  1505   LP64_ONLY(__ movslq(rdx, rdx));
  1508   // Handle all the JSR stuff here, then exit.
  1509   // It's much shorter and cleaner than intermingling with the
  1510   // non-JSR normal-branch stuff occuring below.
  1511   if (is_jsr) {
  1512     // Pre-load the next target bytecode into EBX
  1513     __ load_unsigned_byte(rbx, Address(rsi, rdx, Address::times_1, 0));
  1515     // compute return address as bci in rax,
  1516     __ lea(rax, at_bcp((is_wide ? 5 : 3) - in_bytes(constMethodOopDesc::codes_offset())));
  1517     __ subptr(rax, Address(rcx, methodOopDesc::const_offset()));
  1518     // Adjust the bcp in ESI by the displacement in EDX
  1519     __ addptr(rsi, rdx);
  1520     // Push return address
  1521     __ push_i(rax);
  1522     // jsr returns vtos
  1523     __ dispatch_only_noverify(vtos);
  1524     return;
  1527   // Normal (non-jsr) branch handling
  1529   // Adjust the bcp in ESI by the displacement in EDX
  1530   __ addptr(rsi, rdx);
  1532   assert(UseLoopCounter || !UseOnStackReplacement, "on-stack-replacement requires loop counters");
  1533   Label backedge_counter_overflow;
  1534   Label profile_method;
  1535   Label dispatch;
  1536   if (UseLoopCounter) {
  1537     // increment backedge counter for backward branches
  1538     // rax,: MDO
  1539     // rbx,: MDO bumped taken-count
  1540     // rcx: method
  1541     // rdx: target offset
  1542     // rsi: target bcp
  1543     // rdi: locals pointer
  1544     __ testl(rdx, rdx);             // check if forward or backward branch
  1545     __ jcc(Assembler::positive, dispatch); // count only if backward branch
  1547     // increment counter
  1548     __ movl(rax, Address(rcx, be_offset));        // load backedge counter
  1549     __ incrementl(rax, InvocationCounter::count_increment); // increment counter
  1550     __ movl(Address(rcx, be_offset), rax);        // store counter
  1552     __ movl(rax, Address(rcx, inv_offset));    // load invocation counter
  1553     __ andl(rax, InvocationCounter::count_mask_value);     // and the status bits
  1554     __ addl(rax, Address(rcx, be_offset));        // add both counters
  1556     if (ProfileInterpreter) {
  1557       // Test to see if we should create a method data oop
  1558       __ cmp32(rax,
  1559                ExternalAddress((address) &InvocationCounter::InterpreterProfileLimit));
  1560       __ jcc(Assembler::less, dispatch);
  1562       // if no method data exists, go to profile method
  1563       __ test_method_data_pointer(rax, profile_method);
  1565       if (UseOnStackReplacement) {
  1566         // check for overflow against rbx, which is the MDO taken count
  1567         __ cmp32(rbx,
  1568                  ExternalAddress((address) &InvocationCounter::InterpreterBackwardBranchLimit));
  1569         __ jcc(Assembler::below, dispatch);
  1571         // When ProfileInterpreter is on, the backedge_count comes from the
  1572         // methodDataOop, which value does not get reset on the call to
  1573         // frequency_counter_overflow().  To avoid excessive calls to the overflow
  1574         // routine while the method is being compiled, add a second test to make
  1575         // sure the overflow function is called only once every overflow_frequency.
  1576         const int overflow_frequency = 1024;
  1577         __ andptr(rbx, overflow_frequency-1);
  1578         __ jcc(Assembler::zero, backedge_counter_overflow);
  1581     } else {
  1582       if (UseOnStackReplacement) {
  1583         // check for overflow against rax, which is the sum of the counters
  1584         __ cmp32(rax,
  1585                  ExternalAddress((address) &InvocationCounter::InterpreterBackwardBranchLimit));
  1586         __ jcc(Assembler::aboveEqual, backedge_counter_overflow);
  1590     __ bind(dispatch);
  1593   // Pre-load the next target bytecode into EBX
  1594   __ load_unsigned_byte(rbx, Address(rsi, 0));
  1596   // continue with the bytecode @ target
  1597   // rax,: return bci for jsr's, unused otherwise
  1598   // rbx,: target bytecode
  1599   // rsi: target bcp
  1600   __ dispatch_only(vtos);
  1602   if (UseLoopCounter) {
  1603     if (ProfileInterpreter) {
  1604       // Out-of-line code to allocate method data oop.
  1605       __ bind(profile_method);
  1606       __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::profile_method), rsi);
  1607       __ load_unsigned_byte(rbx, Address(rsi, 0));  // restore target bytecode
  1608       __ movptr(rcx, Address(rbp, method_offset));
  1609       __ movptr(rcx, Address(rcx, in_bytes(methodOopDesc::method_data_offset())));
  1610       __ movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), rcx);
  1611       __ test_method_data_pointer(rcx, dispatch);
  1612       // offset non-null mdp by MDO::data_offset() + IR::profile_method()
  1613       __ addptr(rcx, in_bytes(methodDataOopDesc::data_offset()));
  1614       __ addptr(rcx, rax);
  1615       __ movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), rcx);
  1616       __ jmp(dispatch);
  1619     if (UseOnStackReplacement) {
  1621       // invocation counter overflow
  1622       __ bind(backedge_counter_overflow);
  1623       __ negptr(rdx);
  1624       __ addptr(rdx, rsi);        // branch bcp
  1625       call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow), rdx);
  1626       __ load_unsigned_byte(rbx, Address(rsi, 0));  // restore target bytecode
  1628       // rax,: osr nmethod (osr ok) or NULL (osr not possible)
  1629       // rbx,: target bytecode
  1630       // rdx: scratch
  1631       // rdi: locals pointer
  1632       // rsi: bcp
  1633       __ testptr(rax, rax);                      // test result
  1634       __ jcc(Assembler::zero, dispatch);         // no osr if null
  1635       // nmethod may have been invalidated (VM may block upon call_VM return)
  1636       __ movl(rcx, Address(rax, nmethod::entry_bci_offset()));
  1637       __ cmpl(rcx, InvalidOSREntryBci);
  1638       __ jcc(Assembler::equal, dispatch);
  1640       // We have the address of an on stack replacement routine in rax,
  1641       // We need to prepare to execute the OSR method. First we must
  1642       // migrate the locals and monitors off of the stack.
  1644       __ mov(rbx, rax);                             // save the nmethod
  1646       const Register thread = rcx;
  1647       __ get_thread(thread);
  1648       call_VM(noreg, CAST_FROM_FN_PTR(address, SharedRuntime::OSR_migration_begin));
  1649       // rax, is OSR buffer, move it to expected parameter location
  1650       __ mov(rcx, rax);
  1652       // pop the interpreter frame
  1653       __ movptr(rdx, Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize)); // get sender sp
  1654       __ leave();                                // remove frame anchor
  1655       __ pop(rdi);                               // get return address
  1656       __ mov(rsp, rdx);                          // set sp to sender sp
  1659       Label skip;
  1660       Label chkint;
  1662       // The interpreter frame we have removed may be returning to
  1663       // either the callstub or the interpreter. Since we will
  1664       // now be returning from a compiled (OSR) nmethod we must
  1665       // adjust the return to the return were it can handler compiled
  1666       // results and clean the fpu stack. This is very similar to
  1667       // what a i2c adapter must do.
  1669       // Are we returning to the call stub?
  1671       __ cmp32(rdi, ExternalAddress(StubRoutines::_call_stub_return_address));
  1672       __ jcc(Assembler::notEqual, chkint);
  1674       // yes adjust to the specialized call stub  return.
  1675       assert(StubRoutines::x86::get_call_stub_compiled_return() != NULL, "must be set");
  1676       __ lea(rdi, ExternalAddress(StubRoutines::x86::get_call_stub_compiled_return()));
  1677       __ jmp(skip);
  1679       __ bind(chkint);
  1681       // Are we returning to the interpreter? Look for sentinel
  1683       __ cmpl(Address(rdi, -2*wordSize), Interpreter::return_sentinel);
  1684       __ jcc(Assembler::notEqual, skip);
  1686       // Adjust to compiled return back to interpreter
  1688       __ movptr(rdi, Address(rdi, -wordSize));
  1689       __ bind(skip);
  1691       // Align stack pointer for compiled code (note that caller is
  1692       // responsible for undoing this fixup by remembering the old SP
  1693       // in an rbp,-relative location)
  1694       __ andptr(rsp, -(StackAlignmentInBytes));
  1696       // push the (possibly adjusted) return address
  1697       __ push(rdi);
  1699       // and begin the OSR nmethod
  1700       __ jmp(Address(rbx, nmethod::osr_entry_point_offset()));
  1706 void TemplateTable::if_0cmp(Condition cc) {
  1707   transition(itos, vtos);
  1708   // assume branch is more often taken than not (loops use backward branches)
  1709   Label not_taken;
  1710   __ testl(rax, rax);
  1711   __ jcc(j_not(cc), not_taken);
  1712   branch(false, false);
  1713   __ bind(not_taken);
  1714   __ profile_not_taken_branch(rax);
  1718 void TemplateTable::if_icmp(Condition cc) {
  1719   transition(itos, vtos);
  1720   // assume branch is more often taken than not (loops use backward branches)
  1721   Label not_taken;
  1722   __ pop_i(rdx);
  1723   __ cmpl(rdx, rax);
  1724   __ jcc(j_not(cc), not_taken);
  1725   branch(false, false);
  1726   __ bind(not_taken);
  1727   __ profile_not_taken_branch(rax);
  1731 void TemplateTable::if_nullcmp(Condition cc) {
  1732   transition(atos, vtos);
  1733   // assume branch is more often taken than not (loops use backward branches)
  1734   Label not_taken;
  1735   __ testptr(rax, rax);
  1736   __ jcc(j_not(cc), not_taken);
  1737   branch(false, false);
  1738   __ bind(not_taken);
  1739   __ profile_not_taken_branch(rax);
  1743 void TemplateTable::if_acmp(Condition cc) {
  1744   transition(atos, vtos);
  1745   // assume branch is more often taken than not (loops use backward branches)
  1746   Label not_taken;
  1747   __ pop_ptr(rdx);
  1748   __ cmpptr(rdx, rax);
  1749   __ jcc(j_not(cc), not_taken);
  1750   branch(false, false);
  1751   __ bind(not_taken);
  1752   __ profile_not_taken_branch(rax);
  1756 void TemplateTable::ret() {
  1757   transition(vtos, vtos);
  1758   locals_index(rbx);
  1759   __ movptr(rbx, iaddress(rbx));                   // get return bci, compute return bcp
  1760   __ profile_ret(rbx, rcx);
  1761   __ get_method(rax);
  1762   __ movptr(rsi, Address(rax, methodOopDesc::const_offset()));
  1763   __ lea(rsi, Address(rsi, rbx, Address::times_1,
  1764                       constMethodOopDesc::codes_offset()));
  1765   __ dispatch_next(vtos);
  1769 void TemplateTable::wide_ret() {
  1770   transition(vtos, vtos);
  1771   locals_index_wide(rbx);
  1772   __ movptr(rbx, iaddress(rbx));                   // get return bci, compute return bcp
  1773   __ profile_ret(rbx, rcx);
  1774   __ get_method(rax);
  1775   __ movptr(rsi, Address(rax, methodOopDesc::const_offset()));
  1776   __ lea(rsi, Address(rsi, rbx, Address::times_1, constMethodOopDesc::codes_offset()));
  1777   __ dispatch_next(vtos);
  1781 void TemplateTable::tableswitch() {
  1782   Label default_case, continue_execution;
  1783   transition(itos, vtos);
  1784   // align rsi
  1785   __ lea(rbx, at_bcp(wordSize));
  1786   __ andptr(rbx, -wordSize);
  1787   // load lo & hi
  1788   __ movl(rcx, Address(rbx, 1 * wordSize));
  1789   __ movl(rdx, Address(rbx, 2 * wordSize));
  1790   __ bswapl(rcx);
  1791   __ bswapl(rdx);
  1792   // check against lo & hi
  1793   __ cmpl(rax, rcx);
  1794   __ jccb(Assembler::less, default_case);
  1795   __ cmpl(rax, rdx);
  1796   __ jccb(Assembler::greater, default_case);
  1797   // lookup dispatch offset
  1798   __ subl(rax, rcx);
  1799   __ movl(rdx, Address(rbx, rax, Address::times_4, 3 * BytesPerInt));
  1800   __ profile_switch_case(rax, rbx, rcx);
  1801   // continue execution
  1802   __ bind(continue_execution);
  1803   __ bswapl(rdx);
  1804   __ load_unsigned_byte(rbx, Address(rsi, rdx, Address::times_1));
  1805   __ addptr(rsi, rdx);
  1806   __ dispatch_only(vtos);
  1807   // handle default
  1808   __ bind(default_case);
  1809   __ profile_switch_default(rax);
  1810   __ movl(rdx, Address(rbx, 0));
  1811   __ jmp(continue_execution);
  1815 void TemplateTable::lookupswitch() {
  1816   transition(itos, itos);
  1817   __ stop("lookupswitch bytecode should have been rewritten");
  1821 void TemplateTable::fast_linearswitch() {
  1822   transition(itos, vtos);
  1823   Label loop_entry, loop, found, continue_execution;
  1824   // bswapl rax, so we can avoid bswapping the table entries
  1825   __ bswapl(rax);
  1826   // align rsi
  1827   __ lea(rbx, at_bcp(wordSize));                // btw: should be able to get rid of this instruction (change offsets below)
  1828   __ andptr(rbx, -wordSize);
  1829   // set counter
  1830   __ movl(rcx, Address(rbx, wordSize));
  1831   __ bswapl(rcx);
  1832   __ jmpb(loop_entry);
  1833   // table search
  1834   __ bind(loop);
  1835   __ cmpl(rax, Address(rbx, rcx, Address::times_8, 2 * wordSize));
  1836   __ jccb(Assembler::equal, found);
  1837   __ bind(loop_entry);
  1838   __ decrementl(rcx);
  1839   __ jcc(Assembler::greaterEqual, loop);
  1840   // default case
  1841   __ profile_switch_default(rax);
  1842   __ movl(rdx, Address(rbx, 0));
  1843   __ jmpb(continue_execution);
  1844   // entry found -> get offset
  1845   __ bind(found);
  1846   __ movl(rdx, Address(rbx, rcx, Address::times_8, 3 * wordSize));
  1847   __ profile_switch_case(rcx, rax, rbx);
  1848   // continue execution
  1849   __ bind(continue_execution);
  1850   __ bswapl(rdx);
  1851   __ load_unsigned_byte(rbx, Address(rsi, rdx, Address::times_1));
  1852   __ addptr(rsi, rdx);
  1853   __ dispatch_only(vtos);
  1857 void TemplateTable::fast_binaryswitch() {
  1858   transition(itos, vtos);
  1859   // Implementation using the following core algorithm:
  1860   //
  1861   // int binary_search(int key, LookupswitchPair* array, int n) {
  1862   //   // Binary search according to "Methodik des Programmierens" by
  1863   //   // Edsger W. Dijkstra and W.H.J. Feijen, Addison Wesley Germany 1985.
  1864   //   int i = 0;
  1865   //   int j = n;
  1866   //   while (i+1 < j) {
  1867   //     // invariant P: 0 <= i < j <= n and (a[i] <= key < a[j] or Q)
  1868   //     // with      Q: for all i: 0 <= i < n: key < a[i]
  1869   //     // where a stands for the array and assuming that the (inexisting)
  1870   //     // element a[n] is infinitely big.
  1871   //     int h = (i + j) >> 1;
  1872   //     // i < h < j
  1873   //     if (key < array[h].fast_match()) {
  1874   //       j = h;
  1875   //     } else {
  1876   //       i = h;
  1877   //     }
  1878   //   }
  1879   //   // R: a[i] <= key < a[i+1] or Q
  1880   //   // (i.e., if key is within array, i is the correct index)
  1881   //   return i;
  1882   // }
  1884   // register allocation
  1885   const Register key   = rax;                    // already set (tosca)
  1886   const Register array = rbx;
  1887   const Register i     = rcx;
  1888   const Register j     = rdx;
  1889   const Register h     = rdi;                    // needs to be restored
  1890   const Register temp  = rsi;
  1891   // setup array
  1892   __ save_bcp();
  1894   __ lea(array, at_bcp(3*wordSize));             // btw: should be able to get rid of this instruction (change offsets below)
  1895   __ andptr(array, -wordSize);
  1896   // initialize i & j
  1897   __ xorl(i, i);                                 // i = 0;
  1898   __ movl(j, Address(array, -wordSize));         // j = length(array);
  1899   // Convert j into native byteordering
  1900   __ bswapl(j);
  1901   // and start
  1902   Label entry;
  1903   __ jmp(entry);
  1905   // binary search loop
  1906   { Label loop;
  1907     __ bind(loop);
  1908     // int h = (i + j) >> 1;
  1909     __ leal(h, Address(i, j, Address::times_1)); // h = i + j;
  1910     __ sarl(h, 1);                               // h = (i + j) >> 1;
  1911     // if (key < array[h].fast_match()) {
  1912     //   j = h;
  1913     // } else {
  1914     //   i = h;
  1915     // }
  1916     // Convert array[h].match to native byte-ordering before compare
  1917     __ movl(temp, Address(array, h, Address::times_8, 0*wordSize));
  1918     __ bswapl(temp);
  1919     __ cmpl(key, temp);
  1920     if (VM_Version::supports_cmov()) {
  1921       __ cmovl(Assembler::less        , j, h);   // j = h if (key <  array[h].fast_match())
  1922       __ cmovl(Assembler::greaterEqual, i, h);   // i = h if (key >= array[h].fast_match())
  1923     } else {
  1924       Label set_i, end_of_if;
  1925       __ jccb(Assembler::greaterEqual, set_i);     // {
  1926       __ mov(j, h);                                //   j = h;
  1927       __ jmp(end_of_if);                           // }
  1928       __ bind(set_i);                              // else {
  1929       __ mov(i, h);                                //   i = h;
  1930       __ bind(end_of_if);                          // }
  1932     // while (i+1 < j)
  1933     __ bind(entry);
  1934     __ leal(h, Address(i, 1));                   // i+1
  1935     __ cmpl(h, j);                               // i+1 < j
  1936     __ jcc(Assembler::less, loop);
  1939   // end of binary search, result index is i (must check again!)
  1940   Label default_case;
  1941   // Convert array[i].match to native byte-ordering before compare
  1942   __ movl(temp, Address(array, i, Address::times_8, 0*wordSize));
  1943   __ bswapl(temp);
  1944   __ cmpl(key, temp);
  1945   __ jcc(Assembler::notEqual, default_case);
  1947   // entry found -> j = offset
  1948   __ movl(j , Address(array, i, Address::times_8, 1*wordSize));
  1949   __ profile_switch_case(i, key, array);
  1950   __ bswapl(j);
  1951   LP64_ONLY(__ movslq(j, j));
  1952   __ restore_bcp();
  1953   __ restore_locals();                           // restore rdi
  1954   __ load_unsigned_byte(rbx, Address(rsi, j, Address::times_1));
  1956   __ addptr(rsi, j);
  1957   __ dispatch_only(vtos);
  1959   // default case -> j = default offset
  1960   __ bind(default_case);
  1961   __ profile_switch_default(i);
  1962   __ movl(j, Address(array, -2*wordSize));
  1963   __ bswapl(j);
  1964   LP64_ONLY(__ movslq(j, j));
  1965   __ restore_bcp();
  1966   __ restore_locals();                           // restore rdi
  1967   __ load_unsigned_byte(rbx, Address(rsi, j, Address::times_1));
  1968   __ addptr(rsi, j);
  1969   __ dispatch_only(vtos);
  1973 void TemplateTable::_return(TosState state) {
  1974   transition(state, state);
  1975   assert(_desc->calls_vm(), "inconsistent calls_vm information"); // call in remove_activation
  1977   if (_desc->bytecode() == Bytecodes::_return_register_finalizer) {
  1978     assert(state == vtos, "only valid state");
  1979     __ movptr(rax, aaddress(0));
  1980     __ movptr(rdi, Address(rax, oopDesc::klass_offset_in_bytes()));
  1981     __ movl(rdi, Address(rdi, Klass::access_flags_offset_in_bytes() + sizeof(oopDesc)));
  1982     __ testl(rdi, JVM_ACC_HAS_FINALIZER);
  1983     Label skip_register_finalizer;
  1984     __ jcc(Assembler::zero, skip_register_finalizer);
  1986     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::register_finalizer), rax);
  1988     __ bind(skip_register_finalizer);
  1991   __ remove_activation(state, rsi);
  1992   __ jmp(rsi);
  1996 // ----------------------------------------------------------------------------
  1997 // Volatile variables demand their effects be made known to all CPU's in
  1998 // order.  Store buffers on most chips allow reads & writes to reorder; the
  1999 // JMM's ReadAfterWrite.java test fails in -Xint mode without some kind of
  2000 // memory barrier (i.e., it's not sufficient that the interpreter does not
  2001 // reorder volatile references, the hardware also must not reorder them).
  2002 //
  2003 // According to the new Java Memory Model (JMM):
  2004 // (1) All volatiles are serialized wrt to each other.
  2005 // ALSO reads & writes act as aquire & release, so:
  2006 // (2) A read cannot let unrelated NON-volatile memory refs that happen after
  2007 // the read float up to before the read.  It's OK for non-volatile memory refs
  2008 // that happen before the volatile read to float down below it.
  2009 // (3) Similar a volatile write cannot let unrelated NON-volatile memory refs
  2010 // that happen BEFORE the write float down to after the write.  It's OK for
  2011 // non-volatile memory refs that happen after the volatile write to float up
  2012 // before it.
  2013 //
  2014 // We only put in barriers around volatile refs (they are expensive), not
  2015 // _between_ memory refs (that would require us to track the flavor of the
  2016 // previous memory refs).  Requirements (2) and (3) require some barriers
  2017 // before volatile stores and after volatile loads.  These nearly cover
  2018 // requirement (1) but miss the volatile-store-volatile-load case.  This final
  2019 // case is placed after volatile-stores although it could just as well go
  2020 // before volatile-loads.
  2021 void TemplateTable::volatile_barrier(Assembler::Membar_mask_bits order_constraint ) {
  2022   // Helper function to insert a is-volatile test and memory barrier
  2023   if( !os::is_MP() ) return;    // Not needed on single CPU
  2024   __ membar(order_constraint);
  2027 void TemplateTable::resolve_cache_and_index(int byte_no, Register Rcache, Register index) {
  2028   assert(byte_no == 1 || byte_no == 2, "byte_no out of range");
  2030   Register temp = rbx;
  2032   assert_different_registers(Rcache, index, temp);
  2034   const int shift_count = (1 + byte_no)*BitsPerByte;
  2035   Label resolved;
  2036   __ get_cache_and_index_at_bcp(Rcache, index, 1);
  2037   __ movl(temp, Address(Rcache,
  2038                           index,
  2039                           Address::times_ptr,
  2040                           constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::indices_offset()));
  2041   __ shrl(temp, shift_count);
  2042   // have we resolved this bytecode?
  2043   __ andptr(temp, 0xFF);
  2044   __ cmpl(temp, (int)bytecode());
  2045   __ jcc(Assembler::equal, resolved);
  2047   // resolve first time through
  2048   address entry;
  2049   switch (bytecode()) {
  2050     case Bytecodes::_getstatic      : // fall through
  2051     case Bytecodes::_putstatic      : // fall through
  2052     case Bytecodes::_getfield       : // fall through
  2053     case Bytecodes::_putfield       : entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_get_put); break;
  2054     case Bytecodes::_invokevirtual  : // fall through
  2055     case Bytecodes::_invokespecial  : // fall through
  2056     case Bytecodes::_invokestatic   : // fall through
  2057     case Bytecodes::_invokeinterface: entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_invoke);  break;
  2058     default                         : ShouldNotReachHere();                                 break;
  2060   __ movl(temp, (int)bytecode());
  2061   __ call_VM(noreg, entry, temp);
  2062   // Update registers with resolved info
  2063   __ get_cache_and_index_at_bcp(Rcache, index, 1);
  2064   __ bind(resolved);
  2068 // The cache and index registers must be set before call
  2069 void TemplateTable::load_field_cp_cache_entry(Register obj,
  2070                                               Register cache,
  2071                                               Register index,
  2072                                               Register off,
  2073                                               Register flags,
  2074                                               bool is_static = false) {
  2075   assert_different_registers(cache, index, flags, off);
  2077   ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
  2078   // Field offset
  2079   __ movptr(off, Address(cache, index, Address::times_ptr,
  2080                          in_bytes(cp_base_offset + ConstantPoolCacheEntry::f2_offset())));
  2081   // Flags
  2082   __ movl(flags, Address(cache, index, Address::times_ptr,
  2083            in_bytes(cp_base_offset + ConstantPoolCacheEntry::flags_offset())));
  2085   // klass     overwrite register
  2086   if (is_static) {
  2087     __ movptr(obj, Address(cache, index, Address::times_ptr,
  2088                            in_bytes(cp_base_offset + ConstantPoolCacheEntry::f1_offset())));
  2092 void TemplateTable::load_invoke_cp_cache_entry(int byte_no,
  2093                                                Register method,
  2094                                                Register itable_index,
  2095                                                Register flags,
  2096                                                bool is_invokevirtual,
  2097                                                bool is_invokevfinal /*unused*/) {
  2098   // setup registers
  2099   const Register cache = rcx;
  2100   const Register index = rdx;
  2101   assert_different_registers(method, flags);
  2102   assert_different_registers(method, cache, index);
  2103   assert_different_registers(itable_index, flags);
  2104   assert_different_registers(itable_index, cache, index);
  2105   // determine constant pool cache field offsets
  2106   const int method_offset = in_bytes(
  2107     constantPoolCacheOopDesc::base_offset() +
  2108       (is_invokevirtual
  2109        ? ConstantPoolCacheEntry::f2_offset()
  2110        : ConstantPoolCacheEntry::f1_offset()
  2112     );
  2113   const int flags_offset = in_bytes(constantPoolCacheOopDesc::base_offset() +
  2114                                     ConstantPoolCacheEntry::flags_offset());
  2115   // access constant pool cache fields
  2116   const int index_offset = in_bytes(constantPoolCacheOopDesc::base_offset() +
  2117                                     ConstantPoolCacheEntry::f2_offset());
  2119   resolve_cache_and_index(byte_no, cache, index);
  2121   __ movptr(method, Address(cache, index, Address::times_ptr, method_offset));
  2122   if (itable_index != noreg) {
  2123     __ movptr(itable_index, Address(cache, index, Address::times_ptr, index_offset));
  2125   __ movl(flags , Address(cache, index, Address::times_ptr, flags_offset ));
  2129 // The registers cache and index expected to be set before call.
  2130 // Correct values of the cache and index registers are preserved.
  2131 void TemplateTable::jvmti_post_field_access(Register cache,
  2132                                             Register index,
  2133                                             bool is_static,
  2134                                             bool has_tos) {
  2135   if (JvmtiExport::can_post_field_access()) {
  2136     // Check to see if a field access watch has been set before we take
  2137     // the time to call into the VM.
  2138     Label L1;
  2139     assert_different_registers(cache, index, rax);
  2140     __ mov32(rax, ExternalAddress((address) JvmtiExport::get_field_access_count_addr()));
  2141     __ testl(rax,rax);
  2142     __ jcc(Assembler::zero, L1);
  2144     // cache entry pointer
  2145     __ addptr(cache, in_bytes(constantPoolCacheOopDesc::base_offset()));
  2146     __ shll(index, LogBytesPerWord);
  2147     __ addptr(cache, index);
  2148     if (is_static) {
  2149       __ xorptr(rax, rax);      // NULL object reference
  2150     } else {
  2151       __ pop(atos);         // Get the object
  2152       __ verify_oop(rax);
  2153       __ push(atos);        // Restore stack state
  2155     // rax,:   object pointer or NULL
  2156     // cache: cache entry pointer
  2157     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access),
  2158                rax, cache);
  2159     __ get_cache_and_index_at_bcp(cache, index, 1);
  2160     __ bind(L1);
  2164 void TemplateTable::pop_and_check_object(Register r) {
  2165   __ pop_ptr(r);
  2166   __ null_check(r);  // for field access must check obj.
  2167   __ verify_oop(r);
  2170 void TemplateTable::getfield_or_static(int byte_no, bool is_static) {
  2171   transition(vtos, vtos);
  2173   const Register cache = rcx;
  2174   const Register index = rdx;
  2175   const Register obj   = rcx;
  2176   const Register off   = rbx;
  2177   const Register flags = rax;
  2179   resolve_cache_and_index(byte_no, cache, index);
  2180   jvmti_post_field_access(cache, index, is_static, false);
  2181   load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  2183   if (!is_static) pop_and_check_object(obj);
  2185   const Address lo(obj, off, Address::times_1, 0*wordSize);
  2186   const Address hi(obj, off, Address::times_1, 1*wordSize);
  2188   Label Done, notByte, notInt, notShort, notChar, notLong, notFloat, notObj, notDouble;
  2190   __ shrl(flags, ConstantPoolCacheEntry::tosBits);
  2191   assert(btos == 0, "change code, btos != 0");
  2192   // btos
  2193   __ andptr(flags, 0x0f);
  2194   __ jcc(Assembler::notZero, notByte);
  2196   __ load_signed_byte(rax, lo );
  2197   __ push(btos);
  2198   // Rewrite bytecode to be faster
  2199   if (!is_static) {
  2200     patch_bytecode(Bytecodes::_fast_bgetfield, rcx, rbx);
  2202   __ jmp(Done);
  2204   __ bind(notByte);
  2205   // itos
  2206   __ cmpl(flags, itos );
  2207   __ jcc(Assembler::notEqual, notInt);
  2209   __ movl(rax, lo );
  2210   __ push(itos);
  2211   // Rewrite bytecode to be faster
  2212   if (!is_static) {
  2213     patch_bytecode(Bytecodes::_fast_igetfield, rcx, rbx);
  2215   __ jmp(Done);
  2217   __ bind(notInt);
  2218   // atos
  2219   __ cmpl(flags, atos );
  2220   __ jcc(Assembler::notEqual, notObj);
  2222   __ movl(rax, lo );
  2223   __ push(atos);
  2224   if (!is_static) {
  2225     patch_bytecode(Bytecodes::_fast_agetfield, rcx, rbx);
  2227   __ jmp(Done);
  2229   __ bind(notObj);
  2230   // ctos
  2231   __ cmpl(flags, ctos );
  2232   __ jcc(Assembler::notEqual, notChar);
  2234   __ load_unsigned_word(rax, lo );
  2235   __ push(ctos);
  2236   if (!is_static) {
  2237     patch_bytecode(Bytecodes::_fast_cgetfield, rcx, rbx);
  2239   __ jmp(Done);
  2241   __ bind(notChar);
  2242   // stos
  2243   __ cmpl(flags, stos );
  2244   __ jcc(Assembler::notEqual, notShort);
  2246   __ load_signed_word(rax, lo );
  2247   __ push(stos);
  2248   if (!is_static) {
  2249     patch_bytecode(Bytecodes::_fast_sgetfield, rcx, rbx);
  2251   __ jmp(Done);
  2253   __ bind(notShort);
  2254   // ltos
  2255   __ cmpl(flags, ltos );
  2256   __ jcc(Assembler::notEqual, notLong);
  2258   // Generate code as if volatile.  There just aren't enough registers to
  2259   // save that information and this code is faster than the test.
  2260   __ fild_d(lo);                // Must load atomically
  2261   __ subptr(rsp,2*wordSize);    // Make space for store
  2262   __ fistp_d(Address(rsp,0));
  2263   __ pop(rax);
  2264   __ pop(rdx);
  2266   __ push(ltos);
  2267   // Don't rewrite to _fast_lgetfield for potential volatile case.
  2268   __ jmp(Done);
  2270   __ bind(notLong);
  2271   // ftos
  2272   __ cmpl(flags, ftos );
  2273   __ jcc(Assembler::notEqual, notFloat);
  2275   __ fld_s(lo);
  2276   __ push(ftos);
  2277   if (!is_static) {
  2278     patch_bytecode(Bytecodes::_fast_fgetfield, rcx, rbx);
  2280   __ jmp(Done);
  2282   __ bind(notFloat);
  2283   // dtos
  2284   __ cmpl(flags, dtos );
  2285   __ jcc(Assembler::notEqual, notDouble);
  2287   __ fld_d(lo);
  2288   __ push(dtos);
  2289   if (!is_static) {
  2290     patch_bytecode(Bytecodes::_fast_dgetfield, rcx, rbx);
  2292   __ jmpb(Done);
  2294   __ bind(notDouble);
  2296   __ stop("Bad state");
  2298   __ bind(Done);
  2299   // Doug Lea believes this is not needed with current Sparcs (TSO) and Intel (PSO).
  2300   // volatile_barrier( );
  2304 void TemplateTable::getfield(int byte_no) {
  2305   getfield_or_static(byte_no, false);
  2309 void TemplateTable::getstatic(int byte_no) {
  2310   getfield_or_static(byte_no, true);
  2313 // The registers cache and index expected to be set before call.
  2314 // The function may destroy various registers, just not the cache and index registers.
  2315 void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
  2317   ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
  2319   if (JvmtiExport::can_post_field_modification()) {
  2320     // Check to see if a field modification watch has been set before we take
  2321     // the time to call into the VM.
  2322     Label L1;
  2323     assert_different_registers(cache, index, rax);
  2324     __ mov32(rax, ExternalAddress((address)JvmtiExport::get_field_modification_count_addr()));
  2325     __ testl(rax, rax);
  2326     __ jcc(Assembler::zero, L1);
  2328     // The cache and index registers have been already set.
  2329     // This allows to eliminate this call but the cache and index
  2330     // registers have to be correspondingly used after this line.
  2331     __ get_cache_and_index_at_bcp(rax, rdx, 1);
  2333     if (is_static) {
  2334       // Life is simple.  Null out the object pointer.
  2335       __ xorptr(rbx, rbx);
  2336     } else {
  2337       // Life is harder. The stack holds the value on top, followed by the object.
  2338       // We don't know the size of the value, though; it could be one or two words
  2339       // depending on its type. As a result, we must find the type to determine where
  2340       // the object is.
  2341       Label two_word, valsize_known;
  2342       __ movl(rcx, Address(rax, rdx, Address::times_ptr, in_bytes(cp_base_offset +
  2343                                    ConstantPoolCacheEntry::flags_offset())));
  2344       __ mov(rbx, rsp);
  2345       __ shrl(rcx, ConstantPoolCacheEntry::tosBits);
  2346       // Make sure we don't need to mask rcx for tosBits after the above shift
  2347       ConstantPoolCacheEntry::verify_tosBits();
  2348       __ cmpl(rcx, ltos);
  2349       __ jccb(Assembler::equal, two_word);
  2350       __ cmpl(rcx, dtos);
  2351       __ jccb(Assembler::equal, two_word);
  2352       __ addptr(rbx, Interpreter::expr_offset_in_bytes(1)); // one word jvalue (not ltos, dtos)
  2353       __ jmpb(valsize_known);
  2355       __ bind(two_word);
  2356       __ addptr(rbx, Interpreter::expr_offset_in_bytes(2)); // two words jvalue
  2358       __ bind(valsize_known);
  2359       // setup object pointer
  2360       __ movptr(rbx, Address(rbx, 0));
  2362     // cache entry pointer
  2363     __ addptr(rax, in_bytes(cp_base_offset));
  2364     __ shll(rdx, LogBytesPerWord);
  2365     __ addptr(rax, rdx);
  2366     // object (tos)
  2367     __ mov(rcx, rsp);
  2368     // rbx,: object pointer set up above (NULL if static)
  2369     // rax,: cache entry pointer
  2370     // rcx: jvalue object on the stack
  2371     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification),
  2372                rbx, rax, rcx);
  2373     __ get_cache_and_index_at_bcp(cache, index, 1);
  2374     __ bind(L1);
  2379 void TemplateTable::putfield_or_static(int byte_no, bool is_static) {
  2380   transition(vtos, vtos);
  2382   const Register cache = rcx;
  2383   const Register index = rdx;
  2384   const Register obj   = rcx;
  2385   const Register off   = rbx;
  2386   const Register flags = rax;
  2388   resolve_cache_and_index(byte_no, cache, index);
  2389   jvmti_post_field_mod(cache, index, is_static);
  2390   load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  2392   // Doug Lea believes this is not needed with current Sparcs (TSO) and Intel (PSO).
  2393   // volatile_barrier( );
  2395   Label notVolatile, Done;
  2396   __ movl(rdx, flags);
  2397   __ shrl(rdx, ConstantPoolCacheEntry::volatileField);
  2398   __ andl(rdx, 0x1);
  2400   // field addresses
  2401   const Address lo(obj, off, Address::times_1, 0*wordSize);
  2402   const Address hi(obj, off, Address::times_1, 1*wordSize);
  2404   Label notByte, notInt, notShort, notChar, notLong, notFloat, notObj, notDouble;
  2406   __ shrl(flags, ConstantPoolCacheEntry::tosBits);
  2407   assert(btos == 0, "change code, btos != 0");
  2408   // btos
  2409   __ andl(flags, 0x0f);
  2410   __ jcc(Assembler::notZero, notByte);
  2412   __ pop(btos);
  2413   if (!is_static) pop_and_check_object(obj);
  2414   __ movb(lo, rax );
  2415   if (!is_static) {
  2416     patch_bytecode(Bytecodes::_fast_bputfield, rcx, rbx);
  2418   __ jmp(Done);
  2420   __ bind(notByte);
  2421   // itos
  2422   __ cmpl(flags, itos );
  2423   __ jcc(Assembler::notEqual, notInt);
  2425   __ pop(itos);
  2426   if (!is_static) pop_and_check_object(obj);
  2428   __ movl(lo, rax );
  2429   if (!is_static) {
  2430     patch_bytecode(Bytecodes::_fast_iputfield, rcx, rbx);
  2432   __ jmp(Done);
  2434   __ bind(notInt);
  2435   // atos
  2436   __ cmpl(flags, atos );
  2437   __ jcc(Assembler::notEqual, notObj);
  2439   __ pop(atos);
  2440   if (!is_static) pop_and_check_object(obj);
  2442   __ movptr(lo, rax );
  2443   __ store_check(obj, lo);  // Need to mark card
  2444   if (!is_static) {
  2445     patch_bytecode(Bytecodes::_fast_aputfield, rcx, rbx);
  2447   __ jmp(Done);
  2449   __ bind(notObj);
  2450   // ctos
  2451   __ cmpl(flags, ctos );
  2452   __ jcc(Assembler::notEqual, notChar);
  2454   __ pop(ctos);
  2455   if (!is_static) pop_and_check_object(obj);
  2456   __ movw(lo, rax );
  2457   if (!is_static) {
  2458     patch_bytecode(Bytecodes::_fast_cputfield, rcx, rbx);
  2460   __ jmp(Done);
  2462   __ bind(notChar);
  2463   // stos
  2464   __ cmpl(flags, stos );
  2465   __ jcc(Assembler::notEqual, notShort);
  2467   __ pop(stos);
  2468   if (!is_static) pop_and_check_object(obj);
  2469   __ movw(lo, rax );
  2470   if (!is_static) {
  2471     patch_bytecode(Bytecodes::_fast_sputfield, rcx, rbx);
  2473   __ jmp(Done);
  2475   __ bind(notShort);
  2476   // ltos
  2477   __ cmpl(flags, ltos );
  2478   __ jcc(Assembler::notEqual, notLong);
  2480   Label notVolatileLong;
  2481   __ testl(rdx, rdx);
  2482   __ jcc(Assembler::zero, notVolatileLong);
  2484   __ pop(ltos);  // overwrites rdx, do this after testing volatile.
  2485   if (!is_static) pop_and_check_object(obj);
  2487   // Replace with real volatile test
  2488   __ push(rdx);
  2489   __ push(rax);                 // Must update atomically with FIST
  2490   __ fild_d(Address(rsp,0));    // So load into FPU register
  2491   __ fistp_d(lo);               // and put into memory atomically
  2492   __ addptr(rsp, 2*wordSize);
  2493   // volatile_barrier();
  2494   volatile_barrier(Assembler::Membar_mask_bits(Assembler::StoreLoad |
  2495                                                Assembler::StoreStore));
  2496   // Don't rewrite volatile version
  2497   __ jmp(notVolatile);
  2499   __ bind(notVolatileLong);
  2501   __ pop(ltos);  // overwrites rdx
  2502   if (!is_static) pop_and_check_object(obj);
  2503   NOT_LP64(__ movptr(hi, rdx));
  2504   __ movptr(lo, rax);
  2505   if (!is_static) {
  2506     patch_bytecode(Bytecodes::_fast_lputfield, rcx, rbx);
  2508   __ jmp(notVolatile);
  2510   __ bind(notLong);
  2511   // ftos
  2512   __ cmpl(flags, ftos );
  2513   __ jcc(Assembler::notEqual, notFloat);
  2515   __ pop(ftos);
  2516   if (!is_static) pop_and_check_object(obj);
  2517   __ fstp_s(lo);
  2518   if (!is_static) {
  2519     patch_bytecode(Bytecodes::_fast_fputfield, rcx, rbx);
  2521   __ jmp(Done);
  2523   __ bind(notFloat);
  2524   // dtos
  2525   __ cmpl(flags, dtos );
  2526   __ jcc(Assembler::notEqual, notDouble);
  2528   __ pop(dtos);
  2529   if (!is_static) pop_and_check_object(obj);
  2530   __ fstp_d(lo);
  2531   if (!is_static) {
  2532     patch_bytecode(Bytecodes::_fast_dputfield, rcx, rbx);
  2534   __ jmp(Done);
  2536   __ bind(notDouble);
  2538   __ stop("Bad state");
  2540   __ bind(Done);
  2542   // Check for volatile store
  2543   __ testl(rdx, rdx);
  2544   __ jcc(Assembler::zero, notVolatile);
  2545   volatile_barrier(Assembler::Membar_mask_bits(Assembler::StoreLoad |
  2546                                                Assembler::StoreStore));
  2547   __ bind(notVolatile);
  2551 void TemplateTable::putfield(int byte_no) {
  2552   putfield_or_static(byte_no, false);
  2556 void TemplateTable::putstatic(int byte_no) {
  2557   putfield_or_static(byte_no, true);
  2560 void TemplateTable::jvmti_post_fast_field_mod() {
  2561   if (JvmtiExport::can_post_field_modification()) {
  2562     // Check to see if a field modification watch has been set before we take
  2563     // the time to call into the VM.
  2564     Label L2;
  2565     __ mov32(rcx, ExternalAddress((address)JvmtiExport::get_field_modification_count_addr()));
  2566     __ testl(rcx,rcx);
  2567     __ jcc(Assembler::zero, L2);
  2568     __ pop_ptr(rbx);               // copy the object pointer from tos
  2569     __ verify_oop(rbx);
  2570     __ push_ptr(rbx);              // put the object pointer back on tos
  2571     __ subptr(rsp, sizeof(jvalue));  // add space for a jvalue object
  2572     __ mov(rcx, rsp);
  2573     __ push_ptr(rbx);                 // save object pointer so we can steal rbx,
  2574     __ xorptr(rbx, rbx);
  2575     const Address lo_value(rcx, rbx, Address::times_1, 0*wordSize);
  2576     const Address hi_value(rcx, rbx, Address::times_1, 1*wordSize);
  2577     switch (bytecode()) {          // load values into the jvalue object
  2578     case Bytecodes::_fast_bputfield: __ movb(lo_value, rax); break;
  2579     case Bytecodes::_fast_sputfield: __ movw(lo_value, rax); break;
  2580     case Bytecodes::_fast_cputfield: __ movw(lo_value, rax); break;
  2581     case Bytecodes::_fast_iputfield: __ movl(lo_value, rax);                         break;
  2582     case Bytecodes::_fast_lputfield:
  2583       NOT_LP64(__ movptr(hi_value, rdx));
  2584       __ movptr(lo_value, rax);
  2585       break;
  2587     // need to call fld_s() after fstp_s() to restore the value for below
  2588     case Bytecodes::_fast_fputfield: __ fstp_s(lo_value); __ fld_s(lo_value);        break;
  2590     // need to call fld_d() after fstp_d() to restore the value for below
  2591     case Bytecodes::_fast_dputfield: __ fstp_d(lo_value); __ fld_d(lo_value);        break;
  2593     // since rcx is not an object we don't call store_check() here
  2594     case Bytecodes::_fast_aputfield: __ movptr(lo_value, rax);                       break;
  2596     default:  ShouldNotReachHere();
  2598     __ pop_ptr(rbx);  // restore copy of object pointer
  2600     // Save rax, and sometimes rdx because call_VM() will clobber them,
  2601     // then use them for JVM/DI purposes
  2602     __ push(rax);
  2603     if (bytecode() == Bytecodes::_fast_lputfield) __ push(rdx);
  2604     // access constant pool cache entry
  2605     __ get_cache_entry_pointer_at_bcp(rax, rdx, 1);
  2606     __ verify_oop(rbx);
  2607     // rbx,: object pointer copied above
  2608     // rax,: cache entry pointer
  2609     // rcx: jvalue object on the stack
  2610     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification), rbx, rax, rcx);
  2611     if (bytecode() == Bytecodes::_fast_lputfield) __ pop(rdx);  // restore high value
  2612     __ pop(rax);     // restore lower value
  2613     __ addptr(rsp, sizeof(jvalue));  // release jvalue object space
  2614     __ bind(L2);
  2618 void TemplateTable::fast_storefield(TosState state) {
  2619   transition(state, vtos);
  2621   ByteSize base = constantPoolCacheOopDesc::base_offset();
  2623   jvmti_post_fast_field_mod();
  2625   // access constant pool cache
  2626   __ get_cache_and_index_at_bcp(rcx, rbx, 1);
  2628   // test for volatile with rdx but rdx is tos register for lputfield.
  2629   if (bytecode() == Bytecodes::_fast_lputfield) __ push(rdx);
  2630   __ movl(rdx, Address(rcx, rbx, Address::times_ptr, in_bytes(base +
  2631                        ConstantPoolCacheEntry::flags_offset())));
  2633   // replace index with field offset from cache entry
  2634   __ movptr(rbx, Address(rcx, rbx, Address::times_ptr, in_bytes(base + ConstantPoolCacheEntry::f2_offset())));
  2636   // Doug Lea believes this is not needed with current Sparcs (TSO) and Intel (PSO).
  2637   // volatile_barrier( );
  2639   Label notVolatile, Done;
  2640   __ shrl(rdx, ConstantPoolCacheEntry::volatileField);
  2641   __ andl(rdx, 0x1);
  2642   // Check for volatile store
  2643   __ testl(rdx, rdx);
  2644   __ jcc(Assembler::zero, notVolatile);
  2646   if (bytecode() == Bytecodes::_fast_lputfield) __ pop(rdx);
  2648   // Get object from stack
  2649   pop_and_check_object(rcx);
  2651   // field addresses
  2652   const Address lo(rcx, rbx, Address::times_1, 0*wordSize);
  2653   const Address hi(rcx, rbx, Address::times_1, 1*wordSize);
  2655   // access field
  2656   switch (bytecode()) {
  2657     case Bytecodes::_fast_bputfield: __ movb(lo, rax); break;
  2658     case Bytecodes::_fast_sputfield: // fall through
  2659     case Bytecodes::_fast_cputfield: __ movw(lo, rax); break;
  2660     case Bytecodes::_fast_iputfield: __ movl(lo, rax); break;
  2661     case Bytecodes::_fast_lputfield:
  2662       NOT_LP64(__ movptr(hi, rdx));
  2663       __ movptr(lo, rax);
  2664       break;
  2665     case Bytecodes::_fast_fputfield: __ fstp_s(lo); break;
  2666     case Bytecodes::_fast_dputfield: __ fstp_d(lo); break;
  2667     case Bytecodes::_fast_aputfield: __ movptr(lo, rax); __ store_check(rcx, lo); break;
  2668     default:
  2669       ShouldNotReachHere();
  2672   Label done;
  2673   volatile_barrier(Assembler::Membar_mask_bits(Assembler::StoreLoad |
  2674                                                Assembler::StoreStore));
  2675   __ jmpb(done);
  2677   // Same code as above, but don't need rdx to test for volatile.
  2678   __ bind(notVolatile);
  2680   if (bytecode() == Bytecodes::_fast_lputfield) __ pop(rdx);
  2682   // Get object from stack
  2683   pop_and_check_object(rcx);
  2685   // access field
  2686   switch (bytecode()) {
  2687     case Bytecodes::_fast_bputfield: __ movb(lo, rax); break;
  2688     case Bytecodes::_fast_sputfield: // fall through
  2689     case Bytecodes::_fast_cputfield: __ movw(lo, rax); break;
  2690     case Bytecodes::_fast_iputfield: __ movl(lo, rax); break;
  2691     case Bytecodes::_fast_lputfield:
  2692       NOT_LP64(__ movptr(hi, rdx));
  2693       __ movptr(lo, rax);
  2694       break;
  2695     case Bytecodes::_fast_fputfield: __ fstp_s(lo); break;
  2696     case Bytecodes::_fast_dputfield: __ fstp_d(lo); break;
  2697     case Bytecodes::_fast_aputfield: __ movptr(lo, rax); __ store_check(rcx, lo); break;
  2698     default:
  2699       ShouldNotReachHere();
  2701   __ bind(done);
  2705 void TemplateTable::fast_accessfield(TosState state) {
  2706   transition(atos, state);
  2708   // do the JVMTI work here to avoid disturbing the register state below
  2709   if (JvmtiExport::can_post_field_access()) {
  2710     // Check to see if a field access watch has been set before we take
  2711     // the time to call into the VM.
  2712     Label L1;
  2713     __ mov32(rcx, ExternalAddress((address) JvmtiExport::get_field_access_count_addr()));
  2714     __ testl(rcx,rcx);
  2715     __ jcc(Assembler::zero, L1);
  2716     // access constant pool cache entry
  2717     __ get_cache_entry_pointer_at_bcp(rcx, rdx, 1);
  2718     __ push_ptr(rax);  // save object pointer before call_VM() clobbers it
  2719     __ verify_oop(rax);
  2720     // rax,: object pointer copied above
  2721     // rcx: cache entry pointer
  2722     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access), rax, rcx);
  2723     __ pop_ptr(rax);   // restore object pointer
  2724     __ bind(L1);
  2727   // access constant pool cache
  2728   __ get_cache_and_index_at_bcp(rcx, rbx, 1);
  2729   // replace index with field offset from cache entry
  2730   __ movptr(rbx, Address(rcx,
  2731                          rbx,
  2732                          Address::times_ptr,
  2733                          in_bytes(constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::f2_offset())));
  2736   // rax,: object
  2737   __ verify_oop(rax);
  2738   __ null_check(rax);
  2739   // field addresses
  2740   const Address lo = Address(rax, rbx, Address::times_1, 0*wordSize);
  2741   const Address hi = Address(rax, rbx, Address::times_1, 1*wordSize);
  2743   // access field
  2744   switch (bytecode()) {
  2745     case Bytecodes::_fast_bgetfield: __ movsbl(rax, lo );                 break;
  2746     case Bytecodes::_fast_sgetfield: __ load_signed_word(rax, lo );       break;
  2747     case Bytecodes::_fast_cgetfield: __ load_unsigned_word(rax, lo );     break;
  2748     case Bytecodes::_fast_igetfield: __ movl(rax, lo);                    break;
  2749     case Bytecodes::_fast_lgetfield: __ stop("should not be rewritten");  break;
  2750     case Bytecodes::_fast_fgetfield: __ fld_s(lo);                        break;
  2751     case Bytecodes::_fast_dgetfield: __ fld_d(lo);                        break;
  2752     case Bytecodes::_fast_agetfield: __ movptr(rax, lo); __ verify_oop(rax); break;
  2753     default:
  2754       ShouldNotReachHere();
  2757   // Doug Lea believes this is not needed with current Sparcs(TSO) and Intel(PSO)
  2758   // volatile_barrier( );
  2761 void TemplateTable::fast_xaccess(TosState state) {
  2762   transition(vtos, state);
  2763   // get receiver
  2764   __ movptr(rax, aaddress(0));
  2765   debug_only(__ verify_local_tag(frame::TagReference, 0));
  2766   // access constant pool cache
  2767   __ get_cache_and_index_at_bcp(rcx, rdx, 2);
  2768   __ movptr(rbx, Address(rcx,
  2769                          rdx,
  2770                          Address::times_ptr,
  2771                          in_bytes(constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::f2_offset())));
  2772   // make sure exception is reported in correct bcp range (getfield is next instruction)
  2773   __ increment(rsi);
  2774   __ null_check(rax);
  2775   const Address lo = Address(rax, rbx, Address::times_1, 0*wordSize);
  2776   if (state == itos) {
  2777     __ movl(rax, lo);
  2778   } else if (state == atos) {
  2779     __ movptr(rax, lo);
  2780     __ verify_oop(rax);
  2781   } else if (state == ftos) {
  2782     __ fld_s(lo);
  2783   } else {
  2784     ShouldNotReachHere();
  2786   __ decrement(rsi);
  2791 //----------------------------------------------------------------------------------------------------
  2792 // Calls
  2794 void TemplateTable::count_calls(Register method, Register temp) {
  2795   // implemented elsewhere
  2796   ShouldNotReachHere();
  2800 void TemplateTable::prepare_invoke(Register method, Register index, int byte_no, Bytecodes::Code code) {
  2801   // determine flags
  2802   const bool is_invokeinterface  = code == Bytecodes::_invokeinterface;
  2803   const bool is_invokevirtual    = code == Bytecodes::_invokevirtual;
  2804   const bool is_invokespecial    = code == Bytecodes::_invokespecial;
  2805   const bool load_receiver       = code != Bytecodes::_invokestatic;
  2806   const bool receiver_null_check = is_invokespecial;
  2807   const bool save_flags = is_invokeinterface || is_invokevirtual;
  2808   // setup registers & access constant pool cache
  2809   const Register recv   = rcx;
  2810   const Register flags  = rdx;
  2811   assert_different_registers(method, index, recv, flags);
  2813   // save 'interpreter return address'
  2814   __ save_bcp();
  2816   load_invoke_cp_cache_entry(byte_no, method, index, flags, is_invokevirtual);
  2818   // load receiver if needed (note: no return address pushed yet)
  2819   if (load_receiver) {
  2820     __ movl(recv, flags);
  2821     __ andl(recv, 0xFF);
  2822     // recv count is 0 based?
  2823     __ movptr(recv, Address(rsp, recv, Interpreter::stackElementScale(), -Interpreter::expr_offset_in_bytes(1)));
  2824     __ verify_oop(recv);
  2827   // do null check if needed
  2828   if (receiver_null_check) {
  2829     __ null_check(recv);
  2832   if (save_flags) {
  2833     __ mov(rsi, flags);
  2836   // compute return type
  2837   __ shrl(flags, ConstantPoolCacheEntry::tosBits);
  2838   // Make sure we don't need to mask flags for tosBits after the above shift
  2839   ConstantPoolCacheEntry::verify_tosBits();
  2840   // load return address
  2842     ExternalAddress table(is_invokeinterface ? (address)Interpreter::return_5_addrs_by_index_table() :
  2843                                                (address)Interpreter::return_3_addrs_by_index_table());
  2844     __ movptr(flags, ArrayAddress(table, Address(noreg, flags, Address::times_ptr)));
  2847   // push return address
  2848   __ push(flags);
  2850   // Restore flag value from the constant pool cache, and restore rsi
  2851   // for later null checks.  rsi is the bytecode pointer
  2852   if (save_flags) {
  2853     __ mov(flags, rsi);
  2854     __ restore_bcp();
  2859 void TemplateTable::invokevirtual_helper(Register index, Register recv,
  2860                         Register flags) {
  2862   // Uses temporary registers rax, rdx
  2863   assert_different_registers(index, recv, rax, rdx);
  2865   // Test for an invoke of a final method
  2866   Label notFinal;
  2867   __ movl(rax, flags);
  2868   __ andl(rax, (1 << ConstantPoolCacheEntry::vfinalMethod));
  2869   __ jcc(Assembler::zero, notFinal);
  2871   Register method = index;  // method must be rbx,
  2872   assert(method == rbx, "methodOop must be rbx, for interpreter calling convention");
  2874   // do the call - the index is actually the method to call
  2875   __ verify_oop(method);
  2877   // It's final, need a null check here!
  2878   __ null_check(recv);
  2880   // profile this call
  2881   __ profile_final_call(rax);
  2883   __ jump_from_interpreted(method, rax);
  2885   __ bind(notFinal);
  2887   // get receiver klass
  2888   __ null_check(recv, oopDesc::klass_offset_in_bytes());
  2889   // Keep recv in rcx for callee expects it there
  2890   __ movptr(rax, Address(recv, oopDesc::klass_offset_in_bytes()));
  2891   __ verify_oop(rax);
  2893   // profile this call
  2894   __ profile_virtual_call(rax, rdi, rdx);
  2896   // get target methodOop & entry point
  2897   const int base = instanceKlass::vtable_start_offset() * wordSize;
  2898   assert(vtableEntry::size() * wordSize == 4, "adjust the scaling in the code below");
  2899   __ movptr(method, Address(rax, index, Address::times_ptr, base + vtableEntry::method_offset_in_bytes()));
  2900   __ jump_from_interpreted(method, rdx);
  2904 void TemplateTable::invokevirtual(int byte_no) {
  2905   transition(vtos, vtos);
  2906   prepare_invoke(rbx, noreg, byte_no, bytecode());
  2908   // rbx,: index
  2909   // rcx: receiver
  2910   // rdx: flags
  2912   invokevirtual_helper(rbx, rcx, rdx);
  2916 void TemplateTable::invokespecial(int byte_no) {
  2917   transition(vtos, vtos);
  2918   prepare_invoke(rbx, noreg, byte_no, bytecode());
  2919   // do the call
  2920   __ verify_oop(rbx);
  2921   __ profile_call(rax);
  2922   __ jump_from_interpreted(rbx, rax);
  2926 void TemplateTable::invokestatic(int byte_no) {
  2927   transition(vtos, vtos);
  2928   prepare_invoke(rbx, noreg, byte_no, bytecode());
  2929   // do the call
  2930   __ verify_oop(rbx);
  2931   __ profile_call(rax);
  2932   __ jump_from_interpreted(rbx, rax);
  2936 void TemplateTable::fast_invokevfinal(int byte_no) {
  2937   transition(vtos, vtos);
  2938   __ stop("fast_invokevfinal not used on x86");
  2942 void TemplateTable::invokeinterface(int byte_no) {
  2943   transition(vtos, vtos);
  2944   prepare_invoke(rax, rbx, byte_no, bytecode());
  2946   // rax,: Interface
  2947   // rbx,: index
  2948   // rcx: receiver
  2949   // rdx: flags
  2951   // Special case of invokeinterface called for virtual method of
  2952   // java.lang.Object.  See cpCacheOop.cpp for details.
  2953   // This code isn't produced by javac, but could be produced by
  2954   // another compliant java compiler.
  2955   Label notMethod;
  2956   __ movl(rdi, rdx);
  2957   __ andl(rdi, (1 << ConstantPoolCacheEntry::methodInterface));
  2958   __ jcc(Assembler::zero, notMethod);
  2960   invokevirtual_helper(rbx, rcx, rdx);
  2961   __ bind(notMethod);
  2963   // Get receiver klass into rdx - also a null check
  2964   __ restore_locals();  // restore rdi
  2965   __ movptr(rdx, Address(rcx, oopDesc::klass_offset_in_bytes()));
  2966   __ verify_oop(rdx);
  2968   // profile this call
  2969   __ profile_virtual_call(rdx, rsi, rdi);
  2971   __ mov(rdi, rdx); // Save klassOop in rdi
  2973   // Compute start of first itableOffsetEntry (which is at the end of the vtable)
  2974   const int base = instanceKlass::vtable_start_offset() * wordSize;
  2975   assert(vtableEntry::size() * wordSize == (1 << (int)Address::times_ptr), "adjust the scaling in the code below");
  2976   __ movl(rsi, Address(rdx, instanceKlass::vtable_length_offset() * wordSize)); // Get length of vtable
  2977   __ lea(rdx, Address(rdx, rsi, Address::times_4, base));
  2978   if (HeapWordsPerLong > 1) {
  2979     // Round up to align_object_offset boundary
  2980     __ round_to(rdx, BytesPerLong);
  2983   Label entry, search, interface_ok;
  2985   __ jmpb(entry);
  2986   __ bind(search);
  2987   __ addptr(rdx, itableOffsetEntry::size() * wordSize);
  2989   __ bind(entry);
  2991   // Check that the entry is non-null.  A null entry means that the receiver
  2992   // class doesn't implement the interface, and wasn't the same as the
  2993   // receiver class checked when the interface was resolved.
  2994   __ push(rdx);
  2995   __ movptr(rdx, Address(rdx, itableOffsetEntry::interface_offset_in_bytes()));
  2996   __ testptr(rdx, rdx);
  2997   __ jcc(Assembler::notZero, interface_ok);
  2998   // throw exception
  2999   __ pop(rdx);           // pop saved register first.
  3000   __ pop(rbx);           // pop return address (pushed by prepare_invoke)
  3001   __ restore_bcp();      // rsi must be correct for exception handler   (was destroyed)
  3002   __ restore_locals();   // make sure locals pointer is correct as well (was destroyed)
  3003   __ call_VM(noreg, CAST_FROM_FN_PTR(address,
  3004                    InterpreterRuntime::throw_IncompatibleClassChangeError));
  3005   // the call_VM checks for exception, so we should never return here.
  3006   __ should_not_reach_here();
  3007   __ bind(interface_ok);
  3009     __ pop(rdx);
  3011     __ cmpptr(rax, Address(rdx, itableOffsetEntry::interface_offset_in_bytes()));
  3012     __ jcc(Assembler::notEqual, search);
  3014     __ movl(rdx, Address(rdx, itableOffsetEntry::offset_offset_in_bytes()));
  3015     __ addptr(rdx, rdi); // Add offset to klassOop
  3016     assert(itableMethodEntry::size() * wordSize == (1 << (int)Address::times_ptr), "adjust the scaling in the code below");
  3017     __ movptr(rbx, Address(rdx, rbx, Address::times_ptr));
  3018     // rbx,: methodOop to call
  3019     // rcx: receiver
  3020     // Check for abstract method error
  3021     // Note: This should be done more efficiently via a throw_abstract_method_error
  3022     //       interpreter entry point and a conditional jump to it in case of a null
  3023     //       method.
  3024     { Label L;
  3025       __ testptr(rbx, rbx);
  3026       __ jcc(Assembler::notZero, L);
  3027       // throw exception
  3028           // note: must restore interpreter registers to canonical
  3029           //       state for exception handling to work correctly!
  3030           __ pop(rbx);           // pop return address (pushed by prepare_invoke)
  3031           __ restore_bcp();      // rsi must be correct for exception handler   (was destroyed)
  3032           __ restore_locals();   // make sure locals pointer is correct as well (was destroyed)
  3033       __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError));
  3034       // the call_VM checks for exception, so we should never return here.
  3035       __ should_not_reach_here();
  3036       __ bind(L);
  3039   // do the call
  3040   // rcx: receiver
  3041   // rbx,: methodOop
  3042   __ jump_from_interpreted(rbx, rdx);
  3045 //----------------------------------------------------------------------------------------------------
  3046 // Allocation
  3048 void TemplateTable::_new() {
  3049   transition(vtos, atos);
  3050   __ get_unsigned_2_byte_index_at_bcp(rdx, 1);
  3051   Label slow_case;
  3052   Label done;
  3053   Label initialize_header;
  3054   Label initialize_object;  // including clearing the fields
  3055   Label allocate_shared;
  3057   ExternalAddress heap_top((address)Universe::heap()->top_addr());
  3059   __ get_cpool_and_tags(rcx, rax);
  3060   // get instanceKlass
  3061   __ movptr(rcx, Address(rcx, rdx, Address::times_ptr, sizeof(constantPoolOopDesc)));
  3062   __ push(rcx);  // save the contexts of klass for initializing the header
  3064   // make sure the class we're about to instantiate has been resolved.
  3065   // Note: slow_case does a pop of stack, which is why we loaded class/pushed above
  3066   const int tags_offset = typeArrayOopDesc::header_size(T_BYTE) * wordSize;
  3067   __ cmpb(Address(rax, rdx, Address::times_1, tags_offset), JVM_CONSTANT_Class);
  3068   __ jcc(Assembler::notEqual, slow_case);
  3070   // make sure klass is initialized & doesn't have finalizer
  3071   // make sure klass is fully initialized
  3072   __ cmpl(Address(rcx, instanceKlass::init_state_offset_in_bytes() + sizeof(oopDesc)), instanceKlass::fully_initialized);
  3073   __ jcc(Assembler::notEqual, slow_case);
  3075   // get instance_size in instanceKlass (scaled to a count of bytes)
  3076   __ movl(rdx, Address(rcx, Klass::layout_helper_offset_in_bytes() + sizeof(oopDesc)));
  3077   // test to see if it has a finalizer or is malformed in some way
  3078   __ testl(rdx, Klass::_lh_instance_slow_path_bit);
  3079   __ jcc(Assembler::notZero, slow_case);
  3081   //
  3082   // Allocate the instance
  3083   // 1) Try to allocate in the TLAB
  3084   // 2) if fail and the object is large allocate in the shared Eden
  3085   // 3) if the above fails (or is not applicable), go to a slow case
  3086   // (creates a new TLAB, etc.)
  3088   const bool allow_shared_alloc =
  3089     Universe::heap()->supports_inline_contig_alloc() && !CMSIncrementalMode;
  3091   if (UseTLAB) {
  3092     const Register thread = rcx;
  3094     __ get_thread(thread);
  3095     __ movptr(rax, Address(thread, in_bytes(JavaThread::tlab_top_offset())));
  3096     __ lea(rbx, Address(rax, rdx, Address::times_1));
  3097     __ cmpptr(rbx, Address(thread, in_bytes(JavaThread::tlab_end_offset())));
  3098     __ jcc(Assembler::above, allow_shared_alloc ? allocate_shared : slow_case);
  3099     __ movptr(Address(thread, in_bytes(JavaThread::tlab_top_offset())), rbx);
  3100     if (ZeroTLAB) {
  3101       // the fields have been already cleared
  3102       __ jmp(initialize_header);
  3103     } else {
  3104       // initialize both the header and fields
  3105       __ jmp(initialize_object);
  3109   // Allocation in the shared Eden, if allowed.
  3110   //
  3111   // rdx: instance size in bytes
  3112   if (allow_shared_alloc) {
  3113     __ bind(allocate_shared);
  3115     Label retry;
  3116     __ bind(retry);
  3117     __ movptr(rax, heap_top);
  3118     __ lea(rbx, Address(rax, rdx, Address::times_1));
  3119     __ cmpptr(rbx, ExternalAddress((address)Universe::heap()->end_addr()));
  3120     __ jcc(Assembler::above, slow_case);
  3122     // Compare rax, with the top addr, and if still equal, store the new
  3123     // top addr in rbx, at the address of the top addr pointer. Sets ZF if was
  3124     // equal, and clears it otherwise. Use lock prefix for atomicity on MPs.
  3125     //
  3126     // rax,: object begin
  3127     // rbx,: object end
  3128     // rdx: instance size in bytes
  3129     __ locked_cmpxchgptr(rbx, heap_top);
  3131     // if someone beat us on the allocation, try again, otherwise continue
  3132     __ jcc(Assembler::notEqual, retry);
  3135   if (UseTLAB || Universe::heap()->supports_inline_contig_alloc()) {
  3136     // The object is initialized before the header.  If the object size is
  3137     // zero, go directly to the header initialization.
  3138     __ bind(initialize_object);
  3139     __ decrement(rdx, sizeof(oopDesc));
  3140     __ jcc(Assembler::zero, initialize_header);
  3142   // Initialize topmost object field, divide rdx by 8, check if odd and
  3143   // test if zero.
  3144     __ xorl(rcx, rcx);    // use zero reg to clear memory (shorter code)
  3145     __ shrl(rdx, LogBytesPerLong); // divide by 2*oopSize and set carry flag if odd
  3147   // rdx must have been multiple of 8
  3148 #ifdef ASSERT
  3149     // make sure rdx was multiple of 8
  3150     Label L;
  3151     // Ignore partial flag stall after shrl() since it is debug VM
  3152     __ jccb(Assembler::carryClear, L);
  3153     __ stop("object size is not multiple of 2 - adjust this code");
  3154     __ bind(L);
  3155     // rdx must be > 0, no extra check needed here
  3156 #endif
  3158     // initialize remaining object fields: rdx was a multiple of 8
  3159     { Label loop;
  3160     __ bind(loop);
  3161     __ movptr(Address(rax, rdx, Address::times_8, sizeof(oopDesc) - 1*oopSize), rcx);
  3162     NOT_LP64(__ movptr(Address(rax, rdx, Address::times_8, sizeof(oopDesc) - 2*oopSize), rcx));
  3163     __ decrement(rdx);
  3164     __ jcc(Assembler::notZero, loop);
  3167     // initialize object header only.
  3168     __ bind(initialize_header);
  3169     if (UseBiasedLocking) {
  3170       __ pop(rcx);   // get saved klass back in the register.
  3171       __ movptr(rbx, Address(rcx, Klass::prototype_header_offset_in_bytes() + klassOopDesc::klass_part_offset_in_bytes()));
  3172       __ movptr(Address(rax, oopDesc::mark_offset_in_bytes ()), rbx);
  3173     } else {
  3174       __ movptr(Address(rax, oopDesc::mark_offset_in_bytes ()),
  3175                 (int32_t)markOopDesc::prototype()); // header
  3176       __ pop(rcx);   // get saved klass back in the register.
  3178     __ movptr(Address(rax, oopDesc::klass_offset_in_bytes()), rcx);  // klass
  3181       SkipIfEqual skip_if(_masm, &DTraceAllocProbes, 0);
  3182       // Trigger dtrace event for fastpath
  3183       __ push(atos);
  3184       __ call_VM_leaf(
  3185            CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_object_alloc), rax);
  3186       __ pop(atos);
  3189     __ jmp(done);
  3192   // slow case
  3193   __ bind(slow_case);
  3194   __ pop(rcx);   // restore stack pointer to what it was when we came in.
  3195   __ get_constant_pool(rax);
  3196   __ get_unsigned_2_byte_index_at_bcp(rdx, 1);
  3197   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), rax, rdx);
  3199   // continue
  3200   __ bind(done);
  3204 void TemplateTable::newarray() {
  3205   transition(itos, atos);
  3206   __ push_i(rax);                                 // make sure everything is on the stack
  3207   __ load_unsigned_byte(rdx, at_bcp(1));
  3208   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::newarray), rdx, rax);
  3209   __ pop_i(rdx);                                  // discard size
  3213 void TemplateTable::anewarray() {
  3214   transition(itos, atos);
  3215   __ get_unsigned_2_byte_index_at_bcp(rdx, 1);
  3216   __ get_constant_pool(rcx);
  3217   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::anewarray), rcx, rdx, rax);
  3221 void TemplateTable::arraylength() {
  3222   transition(atos, itos);
  3223   __ null_check(rax, arrayOopDesc::length_offset_in_bytes());
  3224   __ movl(rax, Address(rax, arrayOopDesc::length_offset_in_bytes()));
  3228 void TemplateTable::checkcast() {
  3229   transition(atos, atos);
  3230   Label done, is_null, ok_is_subtype, quicked, resolved;
  3231   __ testptr(rax, rax);   // Object is in EAX
  3232   __ jcc(Assembler::zero, is_null);
  3234   // Get cpool & tags index
  3235   __ get_cpool_and_tags(rcx, rdx); // ECX=cpool, EDX=tags array
  3236   __ get_unsigned_2_byte_index_at_bcp(rbx, 1); // EBX=index
  3237   // See if bytecode has already been quicked
  3238   __ cmpb(Address(rdx, rbx, Address::times_1, typeArrayOopDesc::header_size(T_BYTE) * wordSize), JVM_CONSTANT_Class);
  3239   __ jcc(Assembler::equal, quicked);
  3241   __ push(atos);
  3242   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc) );
  3243   __ pop_ptr(rdx);
  3244   __ jmpb(resolved);
  3246   // Get superklass in EAX and subklass in EBX
  3247   __ bind(quicked);
  3248   __ mov(rdx, rax);          // Save object in EDX; EAX needed for subtype check
  3249   __ movptr(rax, Address(rcx, rbx, Address::times_ptr, sizeof(constantPoolOopDesc)));
  3251   __ bind(resolved);
  3252   __ movptr(rbx, Address(rdx, oopDesc::klass_offset_in_bytes()));
  3254   // Generate subtype check.  Blows ECX.  Resets EDI.  Object in EDX.
  3255   // Superklass in EAX.  Subklass in EBX.
  3256   __ gen_subtype_check( rbx, ok_is_subtype );
  3258   // Come here on failure
  3259   __ push(rdx);
  3260   // object is at TOS
  3261   __ jump(ExternalAddress(Interpreter::_throw_ClassCastException_entry));
  3263   // Come here on success
  3264   __ bind(ok_is_subtype);
  3265   __ mov(rax,rdx);           // Restore object in EDX
  3267   // Collect counts on whether this check-cast sees NULLs a lot or not.
  3268   if (ProfileInterpreter) {
  3269     __ jmp(done);
  3270     __ bind(is_null);
  3271     __ profile_null_seen(rcx);
  3272   } else {
  3273     __ bind(is_null);   // same as 'done'
  3275   __ bind(done);
  3279 void TemplateTable::instanceof() {
  3280   transition(atos, itos);
  3281   Label done, is_null, ok_is_subtype, quicked, resolved;
  3282   __ testptr(rax, rax);
  3283   __ jcc(Assembler::zero, is_null);
  3285   // Get cpool & tags index
  3286   __ get_cpool_and_tags(rcx, rdx); // ECX=cpool, EDX=tags array
  3287   __ get_unsigned_2_byte_index_at_bcp(rbx, 1); // EBX=index
  3288   // See if bytecode has already been quicked
  3289   __ cmpb(Address(rdx, rbx, Address::times_1, typeArrayOopDesc::header_size(T_BYTE) * wordSize), JVM_CONSTANT_Class);
  3290   __ jcc(Assembler::equal, quicked);
  3292   __ push(atos);
  3293   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc) );
  3294   __ pop_ptr(rdx);
  3295   __ movptr(rdx, Address(rdx, oopDesc::klass_offset_in_bytes()));
  3296   __ jmp(resolved);
  3298   // Get superklass in EAX and subklass in EDX
  3299   __ bind(quicked);
  3300   __ movptr(rdx, Address(rax, oopDesc::klass_offset_in_bytes()));
  3301   __ movptr(rax, Address(rcx, rbx, Address::times_ptr, sizeof(constantPoolOopDesc)));
  3303   __ bind(resolved);
  3305   // Generate subtype check.  Blows ECX.  Resets EDI.
  3306   // Superklass in EAX.  Subklass in EDX.
  3307   __ gen_subtype_check( rdx, ok_is_subtype );
  3309   // Come here on failure
  3310   __ xorl(rax,rax);
  3311   __ jmpb(done);
  3312   // Come here on success
  3313   __ bind(ok_is_subtype);
  3314   __ movl(rax, 1);
  3316   // Collect counts on whether this test sees NULLs a lot or not.
  3317   if (ProfileInterpreter) {
  3318     __ jmp(done);
  3319     __ bind(is_null);
  3320     __ profile_null_seen(rcx);
  3321   } else {
  3322     __ bind(is_null);   // same as 'done'
  3324   __ bind(done);
  3325   // rax, = 0: obj == NULL or  obj is not an instanceof the specified klass
  3326   // rax, = 1: obj != NULL and obj is     an instanceof the specified klass
  3330 //----------------------------------------------------------------------------------------------------
  3331 // Breakpoints
  3332 void TemplateTable::_breakpoint() {
  3334   // Note: We get here even if we are single stepping..
  3335   // jbug inists on setting breakpoints at every bytecode
  3336   // even if we are in single step mode.
  3338   transition(vtos, vtos);
  3340   // get the unpatched byte code
  3341   __ get_method(rcx);
  3342   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::get_original_bytecode_at), rcx, rsi);
  3343   __ mov(rbx, rax);
  3345   // post the breakpoint event
  3346   __ get_method(rcx);
  3347   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::_breakpoint), rcx, rsi);
  3349   // complete the execution of original bytecode
  3350   __ dispatch_only_normal(vtos);
  3354 //----------------------------------------------------------------------------------------------------
  3355 // Exceptions
  3357 void TemplateTable::athrow() {
  3358   transition(atos, vtos);
  3359   __ null_check(rax);
  3360   __ jump(ExternalAddress(Interpreter::throw_exception_entry()));
  3364 //----------------------------------------------------------------------------------------------------
  3365 // Synchronization
  3366 //
  3367 // Note: monitorenter & exit are symmetric routines; which is reflected
  3368 //       in the assembly code structure as well
  3369 //
  3370 // Stack layout:
  3371 //
  3372 // [expressions  ] <--- rsp               = expression stack top
  3373 // ..
  3374 // [expressions  ]
  3375 // [monitor entry] <--- monitor block top = expression stack bot
  3376 // ..
  3377 // [monitor entry]
  3378 // [frame data   ] <--- monitor block bot
  3379 // ...
  3380 // [saved rbp,    ] <--- rbp,
  3383 void TemplateTable::monitorenter() {
  3384   transition(atos, vtos);
  3386   // check for NULL object
  3387   __ null_check(rax);
  3389   const Address monitor_block_top(rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
  3390   const Address monitor_block_bot(rbp, frame::interpreter_frame_initial_sp_offset        * wordSize);
  3391   const int entry_size =         (     frame::interpreter_frame_monitor_size()           * wordSize);
  3392   Label allocated;
  3394   // initialize entry pointer
  3395   __ xorl(rdx, rdx);                             // points to free slot or NULL
  3397   // find a free slot in the monitor block (result in rdx)
  3398   { Label entry, loop, exit;
  3399     __ movptr(rcx, monitor_block_top);            // points to current entry, starting with top-most entry
  3400     __ lea(rbx, monitor_block_bot);               // points to word before bottom of monitor block
  3401     __ jmpb(entry);
  3403     __ bind(loop);
  3404     __ cmpptr(Address(rcx, BasicObjectLock::obj_offset_in_bytes()), (int32_t)NULL_WORD);  // check if current entry is used
  3406 // TODO - need new func here - kbt
  3407     if (VM_Version::supports_cmov()) {
  3408       __ cmov(Assembler::equal, rdx, rcx);       // if not used then remember entry in rdx
  3409     } else {
  3410       Label L;
  3411       __ jccb(Assembler::notEqual, L);
  3412       __ mov(rdx, rcx);                          // if not used then remember entry in rdx
  3413       __ bind(L);
  3415     __ cmpptr(rax, Address(rcx, BasicObjectLock::obj_offset_in_bytes()));   // check if current entry is for same object
  3416     __ jccb(Assembler::equal, exit);             // if same object then stop searching
  3417     __ addptr(rcx, entry_size);                  // otherwise advance to next entry
  3418     __ bind(entry);
  3419     __ cmpptr(rcx, rbx);                         // check if bottom reached
  3420     __ jcc(Assembler::notEqual, loop);           // if not at bottom then check this entry
  3421     __ bind(exit);
  3424   __ testptr(rdx, rdx);                          // check if a slot has been found
  3425   __ jccb(Assembler::notZero, allocated);        // if found, continue with that one
  3427   // allocate one if there's no free slot
  3428   { Label entry, loop;
  3429     // 1. compute new pointers                   // rsp: old expression stack top
  3430     __ movptr(rdx, monitor_block_bot);           // rdx: old expression stack bottom
  3431     __ subptr(rsp, entry_size);                  // move expression stack top
  3432     __ subptr(rdx, entry_size);                  // move expression stack bottom
  3433     __ mov(rcx, rsp);                            // set start value for copy loop
  3434     __ movptr(monitor_block_bot, rdx);           // set new monitor block top
  3435     __ jmp(entry);
  3436     // 2. move expression stack contents
  3437     __ bind(loop);
  3438     __ movptr(rbx, Address(rcx, entry_size));    // load expression stack word from old location
  3439     __ movptr(Address(rcx, 0), rbx);             // and store it at new location
  3440     __ addptr(rcx, wordSize);                    // advance to next word
  3441     __ bind(entry);
  3442     __ cmpptr(rcx, rdx);                         // check if bottom reached
  3443     __ jcc(Assembler::notEqual, loop);           // if not at bottom then copy next word
  3446   // call run-time routine
  3447   // rdx: points to monitor entry
  3448   __ bind(allocated);
  3450   // Increment bcp to point to the next bytecode, so exception handling for async. exceptions work correctly.
  3451   // The object has already been poped from the stack, so the expression stack looks correct.
  3452   __ increment(rsi);
  3454   __ movptr(Address(rdx, BasicObjectLock::obj_offset_in_bytes()), rax);     // store object
  3455   __ lock_object(rdx);
  3457   // check to make sure this monitor doesn't cause stack overflow after locking
  3458   __ save_bcp();  // in case of exception
  3459   __ generate_stack_overflow_check(0);
  3461   // The bcp has already been incremented. Just need to dispatch to next instruction.
  3462   __ dispatch_next(vtos);
  3466 void TemplateTable::monitorexit() {
  3467   transition(atos, vtos);
  3469   // check for NULL object
  3470   __ null_check(rax);
  3472   const Address monitor_block_top(rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
  3473   const Address monitor_block_bot(rbp, frame::interpreter_frame_initial_sp_offset        * wordSize);
  3474   const int entry_size =         (     frame::interpreter_frame_monitor_size()           * wordSize);
  3475   Label found;
  3477   // find matching slot
  3478   { Label entry, loop;
  3479     __ movptr(rdx, monitor_block_top);           // points to current entry, starting with top-most entry
  3480     __ lea(rbx, monitor_block_bot);             // points to word before bottom of monitor block
  3481     __ jmpb(entry);
  3483     __ bind(loop);
  3484     __ cmpptr(rax, Address(rdx, BasicObjectLock::obj_offset_in_bytes()));   // check if current entry is for same object
  3485     __ jcc(Assembler::equal, found);             // if same object then stop searching
  3486     __ addptr(rdx, entry_size);                  // otherwise advance to next entry
  3487     __ bind(entry);
  3488     __ cmpptr(rdx, rbx);                         // check if bottom reached
  3489     __ jcc(Assembler::notEqual, loop);           // if not at bottom then check this entry
  3492   // error handling. Unlocking was not block-structured
  3493   Label end;
  3494   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));
  3495   __ should_not_reach_here();
  3497   // call run-time routine
  3498   // rcx: points to monitor entry
  3499   __ bind(found);
  3500   __ push_ptr(rax);                                 // make sure object is on stack (contract with oopMaps)
  3501   __ unlock_object(rdx);
  3502   __ pop_ptr(rax);                                  // discard object
  3503   __ bind(end);
  3507 //----------------------------------------------------------------------------------------------------
  3508 // Wide instructions
  3510 void TemplateTable::wide() {
  3511   transition(vtos, vtos);
  3512   __ load_unsigned_byte(rbx, at_bcp(1));
  3513   ExternalAddress wtable((address)Interpreter::_wentry_point);
  3514   __ jump(ArrayAddress(wtable, Address(noreg, rbx, Address::times_ptr)));
  3515   // Note: the rsi increment step is part of the individual wide bytecode implementations
  3519 //----------------------------------------------------------------------------------------------------
  3520 // Multi arrays
  3522 void TemplateTable::multianewarray() {
  3523   transition(vtos, atos);
  3524   __ load_unsigned_byte(rax, at_bcp(3)); // get number of dimensions
  3525   // last dim is on top of stack; we want address of first one:
  3526   // first_addr = last_addr + (ndims - 1) * stackElementSize - 1*wordsize
  3527   // the latter wordSize to point to the beginning of the array.
  3528   __ lea(  rax, Address(rsp, rax, Interpreter::stackElementScale(), -wordSize));
  3529   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::multianewarray), rax);     // pass in rax,
  3530   __ load_unsigned_byte(rbx, at_bcp(3));
  3531   __ lea(rsp, Address(rsp, rbx, Interpreter::stackElementScale()));  // get rid of counts
  3534 #endif /* !CC_INTERP */

mercurial