< prev index next >

src/hotspot/cpu/x86/templateTable_x86.cpp

Print this page

  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "asm/macroAssembler.hpp"
  26 #include "compiler/disassembler.hpp"
  27 #include "gc/shared/collectedHeap.hpp"
  28 #include "gc/shared/gc_globals.hpp"
  29 #include "gc/shared/tlab_globals.hpp"
  30 #include "interpreter/interpreter.hpp"
  31 #include "interpreter/interpreterRuntime.hpp"
  32 #include "interpreter/interp_masm.hpp"
  33 #include "interpreter/templateTable.hpp"
  34 #include "memory/universe.hpp"
  35 #include "oops/methodCounters.hpp"
  36 #include "oops/methodData.hpp"
  37 #include "oops/objArrayKlass.hpp"
  38 #include "oops/oop.inline.hpp"

  39 #include "oops/resolvedFieldEntry.hpp"
  40 #include "oops/resolvedIndyEntry.hpp"
  41 #include "oops/resolvedMethodEntry.hpp"
  42 #include "prims/jvmtiExport.hpp"
  43 #include "prims/methodHandles.hpp"
  44 #include "runtime/frame.inline.hpp"
  45 #include "runtime/safepointMechanism.hpp"
  46 #include "runtime/sharedRuntime.hpp"
  47 #include "runtime/stubRoutines.hpp"
  48 #include "runtime/synchronizer.hpp"
  49 #include "utilities/macros.hpp"
  50 
  51 #define __ Disassembler::hook<InterpreterMacroAssembler>(__FILE__, __LINE__, _masm)->
  52 
  53 // Global Register Names
  54 static const Register rbcp     = r13;
  55 static const Register rlocals  = r14;
  56 
  57 // Address Computation: local variables
  58 static inline Address iaddress(int n) {

 150 static void do_oop_load(InterpreterMacroAssembler* _masm,
 151                         Address src,
 152                         Register dst,
 153                         DecoratorSet decorators = 0) {
 154   __ load_heap_oop(dst, src, rdx, decorators);
 155 }
 156 
 157 Address TemplateTable::at_bcp(int offset) {
 158   assert(_desc->uses_bcp(), "inconsistent uses_bcp information");
 159   return Address(rbcp, offset);
 160 }
 161 
 162 
 163 void TemplateTable::patch_bytecode(Bytecodes::Code bc, Register bc_reg,
 164                                    Register temp_reg, bool load_bc_into_bc_reg/*=true*/,
 165                                    int byte_no) {
 166   if (!RewriteBytecodes)  return;
 167   Label L_patch_done;
 168 
 169   switch (bc) {

 170   case Bytecodes::_fast_aputfield:
 171   case Bytecodes::_fast_bputfield:
 172   case Bytecodes::_fast_zputfield:
 173   case Bytecodes::_fast_cputfield:
 174   case Bytecodes::_fast_dputfield:
 175   case Bytecodes::_fast_fputfield:
 176   case Bytecodes::_fast_iputfield:
 177   case Bytecodes::_fast_lputfield:
 178   case Bytecodes::_fast_sputfield:
 179     {
 180       // We skip bytecode quickening for putfield instructions when
 181       // the put_code written to the constant pool cache is zero.
 182       // This is required so that every execution of this instruction
 183       // calls out to InterpreterRuntime::resolve_get_put to do
 184       // additional, required work.
 185       assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
 186       assert(load_bc_into_bc_reg, "we use bc_reg as temp");
 187       __ load_field_entry(temp_reg, bc_reg);
 188       if (byte_no == f1_byte) {
 189         __ load_unsigned_byte(temp_reg, Address(temp_reg, in_bytes(ResolvedFieldEntry::get_code_offset())));

 758                     Address(rdx, rax,
 759                             Address::times_4,
 760                             arrayOopDesc::base_offset_in_bytes(T_FLOAT)),
 761                     noreg);
 762 }
 763 
 764 void TemplateTable::daload() {
 765   transition(itos, dtos);
 766   // rax: index
 767   // rdx: array
 768   index_check(rdx, rax); // kills rbx
 769   __ access_load_at(T_DOUBLE, IN_HEAP | IS_ARRAY, noreg /* dtos */,
 770                     Address(rdx, rax,
 771                             Address::times_8,
 772                             arrayOopDesc::base_offset_in_bytes(T_DOUBLE)),
 773                     noreg);
 774 }
 775 
 776 void TemplateTable::aaload() {
 777   transition(itos, atos);
 778   // rax: index
 779   // rdx: array
 780   index_check(rdx, rax); // kills rbx
 781   do_oop_load(_masm,
 782               Address(rdx, rax,
 783                       UseCompressedOops ? Address::times_4 : Address::times_ptr,
 784                       arrayOopDesc::base_offset_in_bytes(T_OBJECT)),
 785               rax,
 786               IS_ARRAY);



















 787 }
 788 
 789 void TemplateTable::baload() {
 790   transition(itos, itos);
 791   // rax: index
 792   // rdx: array
 793   index_check(rdx, rax); // kills rbx
 794   __ access_load_at(T_BYTE, IN_HEAP | IS_ARRAY, rax,
 795                     Address(rdx, rax, Address::times_1, arrayOopDesc::base_offset_in_bytes(T_BYTE)),
 796                     noreg);
 797 }
 798 
 799 void TemplateTable::caload() {
 800   transition(itos, itos);
 801   // rax: index
 802   // rdx: array
 803   index_check(rdx, rax); // kills rbx
 804   __ access_load_at(T_CHAR, IN_HEAP | IS_ARRAY, rax,
 805                     Address(rdx, rax, Address::times_2, arrayOopDesc::base_offset_in_bytes(T_CHAR)),
 806                     noreg);

1040   __ access_store_at(T_FLOAT, IN_HEAP | IS_ARRAY,
1041                      Address(rdx, rbx, Address::times_4,
1042                              arrayOopDesc::base_offset_in_bytes(T_FLOAT)),
1043                      noreg /* ftos */, noreg, noreg, noreg);
1044 }
1045 
1046 void TemplateTable::dastore() {
1047   transition(dtos, vtos);
1048   __ pop_i(rbx);
1049   // value is in xmm0
1050   // rbx:  index
1051   // rdx:  array
1052   index_check(rdx, rbx); // prefer index in rbx
1053   __ access_store_at(T_DOUBLE, IN_HEAP | IS_ARRAY,
1054                      Address(rdx, rbx, Address::times_8,
1055                              arrayOopDesc::base_offset_in_bytes(T_DOUBLE)),
1056                      noreg /* dtos */, noreg, noreg, noreg);
1057 }
1058 
1059 void TemplateTable::aastore() {
1060   Label is_null, ok_is_subtype, done;
1061   transition(vtos, vtos);
1062   // stack: ..., array, index, value
1063   __ movptr(rax, at_tos());    // value
1064   __ movl(rcx, at_tos_p1()); // index
1065   __ movptr(rdx, at_tos_p2()); // array
1066 
1067   Address element_address(rdx, rcx,
1068                           UseCompressedOops? Address::times_4 : Address::times_ptr,
1069                           arrayOopDesc::base_offset_in_bytes(T_OBJECT));
1070 
1071   index_check_without_pop(rdx, rcx);     // kills rbx




1072   __ testptr(rax, rax);
1073   __ jcc(Assembler::zero, is_null);
1074 







1075   // Move subklass into rbx
1076   __ load_klass(rbx, rax, rscratch1);
1077   // Move superklass into rax
1078   __ load_klass(rax, rdx, rscratch1);
1079   __ movptr(rax, Address(rax,
1080                          ObjArrayKlass::element_klass_offset()));
1081 
1082   // Generate subtype check.  Blows rcx, rdi
1083   // Superklass in rax.  Subklass in rbx.
1084   __ gen_subtype_check(rbx, ok_is_subtype);

1085 
1086   // Come here on failure
1087   // object is at TOS
1088   __ jump(RuntimeAddress(Interpreter::_throw_ArrayStoreException_entry));
1089 
1090   // Come here on success
1091   __ bind(ok_is_subtype);
1092 
1093   // Get the value we will store
1094   __ movptr(rax, at_tos());
1095   __ movl(rcx, at_tos_p1()); // index
1096   // Now store using the appropriate barrier
1097   do_oop_store(_masm, element_address, rax, IS_ARRAY);
1098   __ jmp(done);
1099 
1100   // Have a null in rax, rdx=array, ecx=index.  Store null at ary[idx]
1101   __ bind(is_null);
1102   __ profile_null_seen(rbx);












1103 





1104   // Store a null
1105   do_oop_store(_masm, element_address, noreg, IS_ARRAY);





1106 






1107   // Pop stack arguments
1108   __ bind(done);
1109   __ addptr(rsp, 3 * Interpreter::stackElementSize);
1110 }
1111 
1112 void TemplateTable::bastore() {
1113   transition(itos, vtos);
1114   __ pop_i(rbx);
1115   // rax: value
1116   // rbx: index
1117   // rdx: array
1118   index_check(rdx, rbx); // prefer index in rbx
1119   // Need to check whether array is boolean or byte
1120   // since both types share the bastore bytecode.
1121   __ load_klass(rcx, rdx, rscratch1);
1122   __ movl(rcx, Address(rcx, Klass::layout_helper_offset()));
1123   int diffbit = Klass::layout_helper_boolean_diffbit();
1124   __ testl(rcx, diffbit);
1125   Label L_skip;
1126   __ jccb(Assembler::zero, L_skip);

1874   __ jcc(j_not(cc), not_taken);
1875   branch(false, false);
1876   __ bind(not_taken);
1877   __ profile_not_taken_branch(rax);
1878 }
1879 
1880 void TemplateTable::if_nullcmp(Condition cc) {
1881   transition(atos, vtos);
1882   // assume branch is more often taken than not (loops use backward branches)
1883   Label not_taken;
1884   __ testptr(rax, rax);
1885   __ jcc(j_not(cc), not_taken);
1886   branch(false, false);
1887   __ bind(not_taken);
1888   __ profile_not_taken_branch(rax);
1889 }
1890 
1891 void TemplateTable::if_acmp(Condition cc) {
1892   transition(atos, vtos);
1893   // assume branch is more often taken than not (loops use backward branches)
1894   Label not_taken;
1895   __ pop_ptr(rdx);




































1896   __ cmpoop(rdx, rax);
1897   __ jcc(j_not(cc), not_taken);

1898   branch(false, false);
1899   __ bind(not_taken);
1900   __ profile_not_taken_branch(rax);









1901 }
1902 
1903 void TemplateTable::ret() {
1904   transition(vtos, vtos);
1905   locals_index(rbx);
1906   __ movslq(rbx, iaddress(rbx)); // get return bci, compute return bcp
1907   __ profile_ret(rbx, rcx);
1908   __ get_method(rax);
1909   __ movptr(rbcp, Address(rax, Method::const_offset()));
1910   __ lea(rbcp, Address(rbcp, rbx, Address::times_1,
1911                       ConstMethod::codes_offset()));
1912   __ dispatch_next(vtos, 0, true);
1913 }
1914 
1915 void TemplateTable::wide_ret() {
1916   transition(vtos, vtos);
1917   locals_index_wide(rbx);
1918   __ movptr(rbx, aaddress(rbx)); // get return bci, compute return bcp
1919   __ profile_ret(rbx, rcx);
1920   __ get_method(rax);

2134   if (_desc->bytecode() != Bytecodes::_return_register_finalizer) {
2135     Label no_safepoint;
2136     NOT_PRODUCT(__ block_comment("Thread-local Safepoint poll"));
2137     __ testb(Address(r15_thread, JavaThread::polling_word_offset()), SafepointMechanism::poll_bit());
2138     __ jcc(Assembler::zero, no_safepoint);
2139     __ push(state);
2140     __ push_cont_fastpath();
2141     __ call_VM(noreg, CAST_FROM_FN_PTR(address,
2142                                        InterpreterRuntime::at_safepoint));
2143     __ pop_cont_fastpath();
2144     __ pop(state);
2145     __ bind(no_safepoint);
2146   }
2147 
2148   // Narrow result if state is itos but result type is smaller.
2149   // Need to narrow in the return bytecode rather than in generate_return_entry
2150   // since compiled code callers expect the result to already be narrowed.
2151   if (state == itos) {
2152     __ narrow(rax);
2153   }
2154   __ remove_activation(state, rbcp);

2155 
2156   __ jmp(rbcp);
2157 }
2158 
2159 // ----------------------------------------------------------------------------
2160 // Volatile variables demand their effects be made known to all CPU's
2161 // in order.  Store buffers on most chips allow reads & writes to
2162 // reorder; the JMM's ReadAfterWrite.java test fails in -Xint mode
2163 // without some kind of memory barrier (i.e., it's not sufficient that
2164 // the interpreter does not reorder volatile references, the hardware
2165 // also must not reorder them).
2166 //
2167 // According to the new Java Memory Model (JMM):
2168 // (1) All volatiles are serialized wrt to each other.  ALSO reads &
2169 //     writes act as acquire & release, so:
2170 // (2) A read cannot let unrelated NON-volatile memory refs that
2171 //     happen after the read float up to before the read.  It's OK for
2172 //     non-volatile memory refs that happen before the volatile read to
2173 //     float down below it.
2174 // (3) Similar a volatile write cannot let unrelated NON-volatile

2494     }
2495     // rax,:   object pointer or null
2496     // cache: cache entry pointer
2497     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access),
2498               rax, cache);
2499 
2500     __ load_field_entry(cache, index);
2501     __ bind(L1);
2502   }
2503 }
2504 
2505 void TemplateTable::pop_and_check_object(Register r) {
2506   __ pop_ptr(r);
2507   __ null_check(r);  // for field access must check obj.
2508   __ verify_oop(r);
2509 }
2510 
2511 void TemplateTable::getfield_or_static(int byte_no, bool is_static, RewriteControl rc) {
2512   transition(vtos, vtos);
2513 
2514   const Register obj   = c_rarg3;
2515   const Register cache = rcx;
2516   const Register index = rdx;
2517   const Register off   = rbx;
2518   const Register tos_state   = rax;
2519   const Register flags = rdx;
2520   const Register bc    = c_rarg3; // uses same reg as obj, so don't mix them
2521 
2522   resolve_cache_and_index_for_field(byte_no, cache, index);
2523   jvmti_post_field_access(cache, index, is_static, false);
2524   load_resolved_field_entry(obj, cache, tos_state, off, flags, is_static);
2525 
2526   if (!is_static) pop_and_check_object(obj);
2527 
2528   const Address field(obj, off, Address::times_1, 0*wordSize);
2529 
2530   Label Done, notByte, notBool, notInt, notShort, notChar, notLong, notFloat, notObj;
2531 
2532   // Make sure we don't need to mask edx after the above shift
2533   assert(btos == 0, "change code, btos != 0");
2534   __ testl(tos_state, tos_state);
2535   __ jcc(Assembler::notZero, notByte);
2536 
2537   // btos

2538   __ access_load_at(T_BYTE, IN_HEAP, rax, field, noreg);
2539   __ push(btos);
2540   // Rewrite bytecode to be faster
2541   if (!is_static && rc == may_rewrite) {
2542     patch_bytecode(Bytecodes::_fast_bgetfield, bc, rbx);
2543   }
2544   __ jmp(Done);
2545 
2546   __ bind(notByte);
2547   __ cmpl(tos_state, ztos);
2548   __ jcc(Assembler::notEqual, notBool);
2549 
2550   // ztos (same code as btos)
2551   __ access_load_at(T_BOOLEAN, IN_HEAP, rax, field, noreg);
2552   __ push(ztos);
2553   // Rewrite bytecode to be faster
2554   if (!is_static && rc == may_rewrite) {
2555     // use btos rewriting, no truncating to t/f bit is needed for getfield.
2556     patch_bytecode(Bytecodes::_fast_bgetfield, bc, rbx);
2557   }
2558   __ jmp(Done);
2559 
2560   __ bind(notBool);
2561   __ cmpl(tos_state, atos);
2562   __ jcc(Assembler::notEqual, notObj);
2563   // atos
2564   do_oop_load(_masm, field, rax);
2565   __ push(atos);
2566   if (!is_static && rc == may_rewrite) {
2567     patch_bytecode(Bytecodes::_fast_agetfield, bc, rbx);































2568   }
2569   __ jmp(Done);
2570 
2571   __ bind(notObj);



2572   __ cmpl(tos_state, itos);
2573   __ jcc(Assembler::notEqual, notInt);
2574   // itos
2575   __ access_load_at(T_INT, IN_HEAP, rax, field, noreg);
2576   __ push(itos);
2577   // Rewrite bytecode to be faster
2578   if (!is_static && rc == may_rewrite) {
2579     patch_bytecode(Bytecodes::_fast_igetfield, bc, rbx);
2580   }
2581   __ jmp(Done);
2582 
2583   __ bind(notInt);
2584   __ cmpl(tos_state, ctos);
2585   __ jcc(Assembler::notEqual, notChar);
2586   // ctos
2587   __ access_load_at(T_CHAR, IN_HEAP, rax, field, noreg);
2588   __ push(ctos);
2589   // Rewrite bytecode to be faster
2590   if (!is_static && rc == may_rewrite) {
2591     patch_bytecode(Bytecodes::_fast_cgetfield, bc, rbx);

2651 #endif
2652 
2653   __ bind(Done);
2654   // [jk] not needed currently
2655   // volatile_barrier(Assembler::Membar_mask_bits(Assembler::LoadLoad |
2656   //                                              Assembler::LoadStore));
2657 }
2658 
2659 void TemplateTable::getfield(int byte_no) {
2660   getfield_or_static(byte_no, false);
2661 }
2662 
2663 void TemplateTable::nofast_getfield(int byte_no) {
2664   getfield_or_static(byte_no, false, may_not_rewrite);
2665 }
2666 
2667 void TemplateTable::getstatic(int byte_no) {
2668   getfield_or_static(byte_no, true);
2669 }
2670 
2671 
2672 // The registers cache and index expected to be set before call.
2673 // The function may destroy various registers, just not the cache and index registers.
2674 void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
2675   // Cache is rcx and index is rdx
2676   const Register entry = c_rarg2; // ResolvedFieldEntry
2677   const Register obj = c_rarg1;   // Object pointer
2678   const Register value = c_rarg3; // JValue object
2679 
2680   if (JvmtiExport::can_post_field_modification()) {
2681     // Check to see if a field modification watch has been set before
2682     // we take the time to call into the VM.
2683     Label L1;
2684     assert_different_registers(cache, obj, rax);
2685     __ mov32(rax, ExternalAddress((address)JvmtiExport::get_field_modification_count_addr()));
2686     __ testl(rax, rax);
2687     __ jcc(Assembler::zero, L1);
2688 
2689     __ mov(entry, cache);
2690 
2691     if (is_static) {

2713     // cache: field entry pointer
2714     // value: jvalue object on the stack
2715     __ call_VM(noreg,
2716               CAST_FROM_FN_PTR(address,
2717                               InterpreterRuntime::post_field_modification),
2718               obj, entry, value);
2719     // Reload field entry
2720     __ load_field_entry(cache, index);
2721     __ bind(L1);
2722   }
2723 }
2724 
2725 void TemplateTable::putfield_or_static(int byte_no, bool is_static, RewriteControl rc) {
2726   transition(vtos, vtos);
2727 
2728   const Register obj = rcx;
2729   const Register cache = rcx;
2730   const Register index = rdx;
2731   const Register tos_state   = rdx;
2732   const Register off   = rbx;
2733   const Register flags = rax;
2734 
2735   resolve_cache_and_index_for_field(byte_no, cache, index);
2736   jvmti_post_field_mod(cache, index, is_static);
2737   load_resolved_field_entry(obj, cache, tos_state, off, flags, is_static);
2738 
2739   // [jk] not needed currently
2740   // volatile_barrier(Assembler::Membar_mask_bits(Assembler::LoadStore |
2741   //                                              Assembler::StoreStore));
2742 
2743   Label notVolatile, Done;
2744 
2745   // Check for volatile store
2746   __ andl(flags, (1 << ResolvedFieldEntry::is_volatile_shift));
2747   __ testl(flags, flags);

2748   __ jcc(Assembler::zero, notVolatile);
2749 
2750   putfield_or_static_helper(byte_no, is_static, rc, obj, off, tos_state);
2751   volatile_barrier(Assembler::Membar_mask_bits(Assembler::StoreLoad |
2752                                                Assembler::StoreStore));
2753   __ jmp(Done);
2754   __ bind(notVolatile);
2755 
2756   putfield_or_static_helper(byte_no, is_static, rc, obj, off, tos_state);
2757 
2758   __ bind(Done);
2759 }
2760 
2761 void TemplateTable::putfield_or_static_helper(int byte_no, bool is_static, RewriteControl rc,
2762                                               Register obj, Register off, Register tos_state) {
2763 
2764   // field addresses
2765   const Address field(obj, off, Address::times_1, 0*wordSize);
2766 
2767   Label notByte, notBool, notInt, notShort, notChar,
2768         notLong, notFloat, notObj;
2769   Label Done;
2770 
2771   const Register bc    = c_rarg3;
2772 
2773   // Test TOS state
2774   __ testl(tos_state, tos_state);
2775   __ jcc(Assembler::notZero, notByte);
2776 
2777   // btos
2778   {
2779     __ pop(btos);
2780     if (!is_static) pop_and_check_object(obj);
2781     __ access_store_at(T_BYTE, IN_HEAP, field, rax, noreg, noreg, noreg);
2782     if (!is_static && rc == may_rewrite) {
2783       patch_bytecode(Bytecodes::_fast_bputfield, bc, rbx, true, byte_no);
2784     }
2785     __ jmp(Done);
2786   }
2787 
2788   __ bind(notByte);
2789   __ cmpl(tos_state, ztos);
2790   __ jcc(Assembler::notEqual, notBool);
2791 
2792   // ztos
2793   {
2794     __ pop(ztos);
2795     if (!is_static) pop_and_check_object(obj);
2796     __ access_store_at(T_BOOLEAN, IN_HEAP, field, rax, noreg, noreg, noreg);
2797     if (!is_static && rc == may_rewrite) {
2798       patch_bytecode(Bytecodes::_fast_zputfield, bc, rbx, true, byte_no);
2799     }
2800     __ jmp(Done);
2801   }
2802 
2803   __ bind(notBool);
2804   __ cmpl(tos_state, atos);
2805   __ jcc(Assembler::notEqual, notObj);
2806 
2807   // atos
2808   {
2809     __ pop(atos);
2810     if (!is_static) pop_and_check_object(obj);
2811     // Store into the field
2812     do_oop_store(_masm, field, rax);
2813     if (!is_static && rc == may_rewrite) {
2814       patch_bytecode(Bytecodes::_fast_aputfield, bc, rbx, true, byte_no);






































2815     }
2816     __ jmp(Done);
2817   }
2818 
2819   __ bind(notObj);
2820   __ cmpl(tos_state, itos);
2821   __ jcc(Assembler::notEqual, notInt);
2822 
2823   // itos
2824   {
2825     __ pop(itos);
2826     if (!is_static) pop_and_check_object(obj);
2827     __ access_store_at(T_INT, IN_HEAP, field, rax, noreg, noreg, noreg);
2828     if (!is_static && rc == may_rewrite) {
2829       patch_bytecode(Bytecodes::_fast_iputfield, bc, rbx, true, byte_no);
2830     }
2831     __ jmp(Done);
2832   }
2833 
2834   __ bind(notInt);
2835   __ cmpl(tos_state, ctos);
2836   __ jcc(Assembler::notEqual, notChar);

2933 }
2934 
2935 void TemplateTable::jvmti_post_fast_field_mod() {
2936 
2937   const Register scratch = c_rarg3;
2938 
2939   if (JvmtiExport::can_post_field_modification()) {
2940     // Check to see if a field modification watch has been set before
2941     // we take the time to call into the VM.
2942     Label L2;
2943     __ mov32(scratch, ExternalAddress((address)JvmtiExport::get_field_modification_count_addr()));
2944     __ testl(scratch, scratch);
2945     __ jcc(Assembler::zero, L2);
2946     __ pop_ptr(rbx);                  // copy the object pointer from tos
2947     __ verify_oop(rbx);
2948     __ push_ptr(rbx);                 // put the object pointer back on tos
2949     // Save tos values before call_VM() clobbers them. Since we have
2950     // to do it for every data type, we use the saved values as the
2951     // jvalue object.
2952     switch (bytecode()) {          // load values into the jvalue object

2953     case Bytecodes::_fast_aputfield: __ push_ptr(rax); break;
2954     case Bytecodes::_fast_bputfield: // fall through
2955     case Bytecodes::_fast_zputfield: // fall through
2956     case Bytecodes::_fast_sputfield: // fall through
2957     case Bytecodes::_fast_cputfield: // fall through
2958     case Bytecodes::_fast_iputfield: __ push_i(rax); break;
2959     case Bytecodes::_fast_dputfield: __ push(dtos); break;
2960     case Bytecodes::_fast_fputfield: __ push(ftos); break;
2961     case Bytecodes::_fast_lputfield: __ push_l(rax); break;
2962 
2963     default:
2964       ShouldNotReachHere();
2965     }
2966     __ mov(scratch, rsp);             // points to jvalue on the stack
2967     // access constant pool cache entry
2968     __ load_field_entry(c_rarg2, rax);
2969     __ verify_oop(rbx);
2970     // rbx: object pointer copied above
2971     // c_rarg2: cache entry pointer
2972     // c_rarg3: jvalue object on the stack
2973     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification), rbx, c_rarg2, c_rarg3);
2974 
2975     switch (bytecode()) {             // restore tos values

2976     case Bytecodes::_fast_aputfield: __ pop_ptr(rax); break;
2977     case Bytecodes::_fast_bputfield: // fall through
2978     case Bytecodes::_fast_zputfield: // fall through
2979     case Bytecodes::_fast_sputfield: // fall through
2980     case Bytecodes::_fast_cputfield: // fall through
2981     case Bytecodes::_fast_iputfield: __ pop_i(rax); break;
2982     case Bytecodes::_fast_dputfield: __ pop(dtos); break;
2983     case Bytecodes::_fast_fputfield: __ pop(ftos); break;
2984     case Bytecodes::_fast_lputfield: __ pop_l(rax); break;
2985     default: break;
2986     }
2987     __ bind(L2);
2988   }
2989 }
2990 
2991 void TemplateTable::fast_storefield(TosState state) {
2992   transition(state, vtos);
2993 
2994   Register cache = rcx;
2995 
2996   Label notVolatile, Done;
2997 
2998   jvmti_post_fast_field_mod();
2999 
3000   __ push(rax);
3001   __ load_field_entry(rcx, rax);
3002   load_resolved_field_entry(noreg, cache, rax, rbx, rdx);
3003   // RBX: field offset, RAX: TOS, RDX: flags
3004   __ andl(rdx, (1 << ResolvedFieldEntry::is_volatile_shift));
3005   __ pop(rax);

3006 
3007   // Get object from stack
3008   pop_and_check_object(rcx);
3009 
3010   // field address
3011   const Address field(rcx, rbx, Address::times_1);
3012 
3013   // Check for volatile store
3014   __ testl(rdx, rdx);


3015   __ jcc(Assembler::zero, notVolatile);
3016 
3017   fast_storefield_helper(field, rax);
3018   volatile_barrier(Assembler::Membar_mask_bits(Assembler::StoreLoad |
3019                                                Assembler::StoreStore));
3020   __ jmp(Done);
3021   __ bind(notVolatile);
3022 
3023   fast_storefield_helper(field, rax);
3024 
3025   __ bind(Done);
3026 }
3027 
3028 void TemplateTable::fast_storefield_helper(Address field, Register rax) {


3029 
3030   // access field
3031   switch (bytecode()) {















3032   case Bytecodes::_fast_aputfield:
3033     do_oop_store(_masm, field, rax);


3034     break;
3035   case Bytecodes::_fast_lputfield:
3036     __ access_store_at(T_LONG, IN_HEAP, field, noreg /* ltos */, noreg, noreg, noreg);
3037     break;
3038   case Bytecodes::_fast_iputfield:
3039     __ access_store_at(T_INT, IN_HEAP, field, rax, noreg, noreg, noreg);
3040     break;
3041   case Bytecodes::_fast_zputfield:
3042     __ access_store_at(T_BOOLEAN, IN_HEAP, field, rax, noreg, noreg, noreg);
3043     break;
3044   case Bytecodes::_fast_bputfield:
3045     __ access_store_at(T_BYTE, IN_HEAP, field, rax, noreg, noreg, noreg);
3046     break;
3047   case Bytecodes::_fast_sputfield:
3048     __ access_store_at(T_SHORT, IN_HEAP, field, rax, noreg, noreg, noreg);
3049     break;
3050   case Bytecodes::_fast_cputfield:
3051     __ access_store_at(T_CHAR, IN_HEAP, field, rax, noreg, noreg, noreg);
3052     break;
3053   case Bytecodes::_fast_fputfield:

3069     // Check to see if a field access watch has been set before we
3070     // take the time to call into the VM.
3071     Label L1;
3072     __ mov32(rcx, ExternalAddress((address) JvmtiExport::get_field_access_count_addr()));
3073     __ testl(rcx, rcx);
3074     __ jcc(Assembler::zero, L1);
3075     // access constant pool cache entry
3076     __ load_field_entry(c_rarg2, rcx);
3077     __ verify_oop(rax);
3078     __ push_ptr(rax);  // save object pointer before call_VM() clobbers it
3079     __ mov(c_rarg1, rax);
3080     // c_rarg1: object pointer copied above
3081     // c_rarg2: cache entry pointer
3082     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access), c_rarg1, c_rarg2);
3083     __ pop_ptr(rax); // restore object pointer
3084     __ bind(L1);
3085   }
3086 
3087   // access constant pool cache
3088   __ load_field_entry(rcx, rbx);
3089   __ load_sized_value(rbx, Address(rcx, in_bytes(ResolvedFieldEntry::field_offset_offset())), sizeof(int), true /*is_signed*/);
3090 
3091   // rax: object
3092   __ verify_oop(rax);
3093   __ null_check(rax);
3094   Address field(rax, rbx, Address::times_1);
3095 
3096   // access field
3097   switch (bytecode()) {




3098   case Bytecodes::_fast_agetfield:
3099     do_oop_load(_masm, field, rax);
3100     __ verify_oop(rax);
3101     break;
3102   case Bytecodes::_fast_lgetfield:
3103     __ access_load_at(T_LONG, IN_HEAP, noreg /* ltos */, field, noreg);
3104     break;
3105   case Bytecodes::_fast_igetfield:
3106     __ access_load_at(T_INT, IN_HEAP, rax, field, noreg);
3107     break;
3108   case Bytecodes::_fast_bgetfield:
3109     __ access_load_at(T_BYTE, IN_HEAP, rax, field, noreg);
3110     break;
3111   case Bytecodes::_fast_sgetfield:
3112     __ access_load_at(T_SHORT, IN_HEAP, rax, field, noreg);
3113     break;
3114   case Bytecodes::_fast_cgetfield:
3115     __ access_load_at(T_CHAR, IN_HEAP, rax, field, noreg);
3116     break;
3117   case Bytecodes::_fast_fgetfield:

3502 
3503   // Note:  rax_callsite is already pushed
3504 
3505   // %%% should make a type profile for any invokedynamic that takes a ref argument
3506   // profile this call
3507   __ profile_call(rbcp);
3508   __ profile_arguments_type(rdx, rbx_method, rbcp, false);
3509 
3510   __ verify_oop(rax_callsite);
3511 
3512   __ jump_from_interpreted(rbx_method, rdx);
3513 }
3514 
3515 //-----------------------------------------------------------------------------
3516 // Allocation
3517 
3518 void TemplateTable::_new() {
3519   transition(vtos, atos);
3520   __ get_unsigned_2_byte_index_at_bcp(rdx, 1);
3521   Label slow_case;
3522   Label slow_case_no_pop;
3523   Label done;
3524   Label initialize_header;
3525 
3526   __ get_cpool_and_tags(rcx, rax);
3527 
3528   // Make sure the class we're about to instantiate has been resolved.
3529   // This is done before loading InstanceKlass to be consistent with the order
3530   // how Constant Pool is updated (see ConstantPool::klass_at_put)
3531   const int tags_offset = Array<u1>::base_offset_in_bytes();
3532   __ cmpb(Address(rax, rdx, Address::times_1, tags_offset), JVM_CONSTANT_Class);
3533   __ jcc(Assembler::notEqual, slow_case_no_pop);
3534 
3535   // get InstanceKlass
3536   __ load_resolved_klass_at_index(rcx, rcx, rdx);
3537   __ push(rcx);  // save the contexts of klass for initializing the header
3538 
3539   // make sure klass is initialized
3540   // init_state needs acquire, but x86 is TSO, and so we are already good.
3541   assert(VM_Version::supports_fast_class_init_checks(), "must support fast class initialization checks");
3542   __ clinit_barrier(rcx, nullptr /*L_fast_path*/, &slow_case);
3543 
3544   // get instance_size in InstanceKlass (scaled to a count of bytes)
3545   __ movl(rdx, Address(rcx, Klass::layout_helper_offset()));
3546   // test to see if it is malformed in some way
3547   __ testl(rdx, Klass::_lh_instance_slow_path_bit);
3548   __ jcc(Assembler::notZero, slow_case);
3549 
3550   // Allocate the instance:
3551   //  If TLAB is enabled:
3552   //    Try to allocate in the TLAB.
3553   //    If fails, go to the slow path.
3554   //    Initialize the allocation.
3555   //    Exit.
3556   //
3557   //  Go to slow path.
3558 
3559   if (UseTLAB) {
3560     __ tlab_allocate(rax, rdx, 0, rcx, rbx, slow_case);
3561     if (ZeroTLAB) {
3562       // the fields have been already cleared
3563       __ jmp(initialize_header);
3564     }
3565 
3566     // The object is initialized before the header.  If the object size is
3567     // zero, go directly to the header initialization.
3568     if (UseCompactObjectHeaders) {
3569       assert(is_aligned(oopDesc::base_offset_in_bytes(), BytesPerLong), "oop base offset must be 8-byte-aligned");
3570       __ decrement(rdx, oopDesc::base_offset_in_bytes());
3571     } else {
3572       __ decrement(rdx, sizeof(oopDesc));
3573     }
3574     __ jcc(Assembler::zero, initialize_header);
3575 
3576     // Initialize topmost object field, divide rdx by 8, check if odd and
3577     // test if zero.
3578     __ xorl(rcx, rcx);    // use zero reg to clear memory (shorter code)
3579     __ shrl(rdx, LogBytesPerLong); // divide by 2*oopSize and set carry flag if odd
3580 
3581     // rdx must have been multiple of 8
3582 #ifdef ASSERT
3583     // make sure rdx was multiple of 8
3584     Label L;
3585     // Ignore partial flag stall after shrl() since it is debug VM
3586     __ jcc(Assembler::carryClear, L);
3587     __ stop("object size is not multiple of 2 - adjust this code");
3588     __ bind(L);
3589     // rdx must be > 0, no extra check needed here
3590 #endif
3591 
3592     // initialize remaining object fields: rdx was a multiple of 8
3593     { Label loop;
3594     __ bind(loop);
3595     int header_size_bytes = oopDesc::header_size() * HeapWordSize;
3596     assert(is_aligned(header_size_bytes, BytesPerLong), "oop header size must be 8-byte-aligned");
3597     __ movptr(Address(rax, rdx, Address::times_8, header_size_bytes - 1*oopSize), rcx);
3598     __ decrement(rdx);
3599     __ jcc(Assembler::notZero, loop);
3600     }
3601 
3602     // initialize object header only.
3603     __ bind(initialize_header);
3604     if (UseCompactObjectHeaders) {
3605       __ pop(rcx);   // get saved klass back in the register.
3606       __ movptr(rbx, Address(rcx, Klass::prototype_header_offset()));
3607       __ movptr(Address(rax, oopDesc::mark_offset_in_bytes()), rbx);
3608     } else {
3609       __ movptr(Address(rax, oopDesc::mark_offset_in_bytes()),
3610                 (intptr_t)markWord::prototype().value()); // header
3611       __ pop(rcx);   // get saved klass back in the register.
3612       __ xorl(rsi, rsi); // use zero reg to clear memory (shorter code)
3613       __ store_klass_gap(rax, rsi);  // zero klass gap for compressed oops
3614       __ store_klass(rax, rcx, rscratch1);  // klass
3615     }
3616 
3617     if (DTraceAllocProbes) {
3618       // Trigger dtrace event for fastpath
3619       __ push(atos);
3620       __ call_VM_leaf(
3621            CAST_FROM_FN_PTR(address, static_cast<int (*)(oopDesc*)>(SharedRuntime::dtrace_object_alloc)), rax);
3622       __ pop(atos);
3623     }
3624 
3625     __ jmp(done);
3626   }
3627 
3628   // slow case
3629   __ bind(slow_case);
3630   __ pop(rcx);   // restore stack pointer to what it was when we came in.
3631   __ bind(slow_case_no_pop);
3632 
3633   __ get_constant_pool(c_rarg1);
3634   __ get_unsigned_2_byte_index_at_bcp(c_rarg2, 1);
3635   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), c_rarg1, c_rarg2);
3636    __ verify_oop(rax);
3637 
3638   // continue
3639   __ bind(done);
3640 }
3641 
3642 void TemplateTable::newarray() {
3643   transition(itos, atos);
3644   __ load_unsigned_byte(c_rarg1, at_bcp(1));
3645   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::newarray),
3646           c_rarg1, rax);
3647 }
3648 
3649 void TemplateTable::anewarray() {
3650   transition(itos, atos);
3651 

3653   __ get_constant_pool(c_rarg1);
3654   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::anewarray),
3655           c_rarg1, c_rarg2, rax);
3656 }
3657 
3658 void TemplateTable::arraylength() {
3659   transition(atos, itos);
3660   __ movl(rax, Address(rax, arrayOopDesc::length_offset_in_bytes()));
3661 }
3662 
3663 void TemplateTable::checkcast() {
3664   transition(atos, atos);
3665   Label done, is_null, ok_is_subtype, quicked, resolved;
3666   __ testptr(rax, rax); // object is in rax
3667   __ jcc(Assembler::zero, is_null);
3668 
3669   // Get cpool & tags index
3670   __ get_cpool_and_tags(rcx, rdx); // rcx=cpool, rdx=tags array
3671   __ get_unsigned_2_byte_index_at_bcp(rbx, 1); // rbx=index
3672   // See if bytecode has already been quicked
3673   __ cmpb(Address(rdx, rbx,
3674                   Address::times_1,
3675                   Array<u1>::base_offset_in_bytes()),
3676           JVM_CONSTANT_Class);
3677   __ jcc(Assembler::equal, quicked);
3678   __ push(atos); // save receiver for result, and for GC
3679   call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc));
3680 
3681   __ get_vm_result_metadata(rax);
3682 
3683   __ pop_ptr(rdx); // restore receiver
3684   __ jmpb(resolved);
3685 
3686   // Get superklass in rax and subklass in rbx
3687   __ bind(quicked);
3688   __ mov(rdx, rax); // Save object in rdx; rax needed for subtype check
3689   __ load_resolved_klass_at_index(rax, rcx, rbx);
3690 
3691   __ bind(resolved);
3692   __ load_klass(rbx, rdx, rscratch1);
3693 
3694   // Generate subtype check.  Blows rcx, rdi.  Object in rdx.
3695   // Superklass in rax.  Subklass in rbx.
3696   __ gen_subtype_check(rbx, ok_is_subtype);
3697 
3698   // Come here on failure
3699   __ push_ptr(rdx);
3700   // object is at TOS
3701   __ jump(RuntimeAddress(Interpreter::_throw_ClassCastException_entry));
3702 
3703   // Come here on success
3704   __ bind(ok_is_subtype);
3705   __ mov(rax, rdx); // Restore object in rdx



3706 
3707   // Collect counts on whether this check-cast sees nulls a lot or not.
3708   if (ProfileInterpreter) {
3709     __ jmp(done);
3710     __ bind(is_null);
3711     __ profile_null_seen(rcx);
3712   } else {
3713     __ bind(is_null);   // same as 'done'
3714   }

3715   __ bind(done);
3716 }
3717 
3718 void TemplateTable::instanceof() {
3719   transition(atos, itos);
3720   Label done, is_null, ok_is_subtype, quicked, resolved;
3721   __ testptr(rax, rax);
3722   __ jcc(Assembler::zero, is_null);
3723 
3724   // Get cpool & tags index
3725   __ get_cpool_and_tags(rcx, rdx); // rcx=cpool, rdx=tags array
3726   __ get_unsigned_2_byte_index_at_bcp(rbx, 1); // rbx=index
3727   // See if bytecode has already been quicked
3728   __ cmpb(Address(rdx, rbx,
3729                   Address::times_1,
3730                   Array<u1>::base_offset_in_bytes()),
3731           JVM_CONSTANT_Class);
3732   __ jcc(Assembler::equal, quicked);
3733 
3734   __ push(atos); // save receiver for result, and for GC
3735   call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc));
3736 
3737   __ get_vm_result_metadata(rax);
3738 
3739   __ pop_ptr(rdx); // restore receiver
3740   __ verify_oop(rdx);
3741   __ load_klass(rdx, rdx, rscratch1);
3742   __ jmpb(resolved);
3743 
3744   // Get superklass in rax and subklass in rdx
3745   __ bind(quicked);
3746   __ load_klass(rdx, rax, rscratch1);
3747   __ load_resolved_klass_at_index(rax, rcx, rbx);
3748 
3749   __ bind(resolved);
3750 
3751   // Generate subtype check.  Blows rcx, rdi

3755   // Come here on failure
3756   __ xorl(rax, rax);
3757   __ jmpb(done);
3758   // Come here on success
3759   __ bind(ok_is_subtype);
3760   __ movl(rax, 1);
3761 
3762   // Collect counts on whether this test sees nulls a lot or not.
3763   if (ProfileInterpreter) {
3764     __ jmp(done);
3765     __ bind(is_null);
3766     __ profile_null_seen(rcx);
3767   } else {
3768     __ bind(is_null);   // same as 'done'
3769   }
3770   __ bind(done);
3771   // rax = 0: obj == nullptr or  obj is not an instanceof the specified klass
3772   // rax = 1: obj != nullptr and obj is     an instanceof the specified klass
3773 }
3774 
3775 
3776 //----------------------------------------------------------------------------------------------------
3777 // Breakpoints
3778 void TemplateTable::_breakpoint() {
3779   // Note: We get here even if we are single stepping..
3780   // jbug insists on setting breakpoints at every bytecode
3781   // even if we are in single step mode.
3782 
3783   transition(vtos, vtos);
3784 
3785   // get the unpatched byte code
3786   __ get_method(c_rarg1);
3787   __ call_VM(noreg,
3788              CAST_FROM_FN_PTR(address,
3789                               InterpreterRuntime::get_original_bytecode_at),
3790              c_rarg1, rbcp);
3791   __ mov(rbx, rax);  // why?
3792 
3793   // post the breakpoint event
3794   __ get_method(c_rarg1);
3795   __ call_VM(noreg,

3815 // Note: monitorenter & exit are symmetric routines; which is reflected
3816 //       in the assembly code structure as well
3817 //
3818 // Stack layout:
3819 //
3820 // [expressions  ] <--- rsp               = expression stack top
3821 // ..
3822 // [expressions  ]
3823 // [monitor entry] <--- monitor block top = expression stack bot
3824 // ..
3825 // [monitor entry]
3826 // [frame data   ] <--- monitor block bot
3827 // ...
3828 // [saved rbp    ] <--- rbp
3829 void TemplateTable::monitorenter() {
3830   transition(atos, vtos);
3831 
3832   // check for null object
3833   __ null_check(rax);
3834 




3835   const Address monitor_block_top(
3836         rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
3837   const Address monitor_block_bot(
3838         rbp, frame::interpreter_frame_initial_sp_offset * wordSize);
3839   const int entry_size = frame::interpreter_frame_monitor_size_in_bytes();
3840 
3841   Label allocated;
3842 
3843   Register rtop = c_rarg3;
3844   Register rbot = c_rarg2;
3845   Register rmon = c_rarg1;
3846 
3847   // initialize entry pointer
3848   __ xorl(rmon, rmon); // points to free slot or null
3849 
3850   // find a free slot in the monitor block (result in rmon)
3851   {
3852     Label entry, loop, exit;
3853     __ movptr(rtop, monitor_block_top); // derelativize pointer
3854     __ lea(rtop, Address(rbp, rtop, Address::times_ptr));

3907   // rmon: points to monitor entry
3908   __ bind(allocated);
3909 
3910   // Increment bcp to point to the next bytecode, so exception
3911   // handling for async. exceptions work correctly.
3912   // The object has already been popped from the stack, so the
3913   // expression stack looks correct.
3914   __ increment(rbcp);
3915 
3916   // store object
3917   __ movptr(Address(rmon, BasicObjectLock::obj_offset()), rax);
3918   __ lock_object(rmon);
3919 
3920   // check to make sure this monitor doesn't cause stack overflow after locking
3921   __ save_bcp();  // in case of exception
3922   __ generate_stack_overflow_check(0);
3923 
3924   // The bcp has already been incremented. Just need to dispatch to
3925   // next instruction.
3926   __ dispatch_next(vtos);





3927 }
3928 
3929 void TemplateTable::monitorexit() {
3930   transition(atos, vtos);
3931 
3932   // check for null object
3933   __ null_check(rax);
3934 











3935   const Address monitor_block_top(
3936         rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
3937   const Address monitor_block_bot(
3938         rbp, frame::interpreter_frame_initial_sp_offset * wordSize);
3939   const int entry_size = frame::interpreter_frame_monitor_size_in_bytes();
3940 
3941   Register rtop = c_rarg1;
3942   Register rbot = c_rarg2;
3943 
3944   Label found;
3945 
3946   // find matching slot
3947   {
3948     Label entry, loop;
3949     __ movptr(rtop, monitor_block_top); // derelativize pointer
3950     __ lea(rtop, Address(rbp, rtop, Address::times_ptr));
3951     // rtop points to current entry, starting with top-most entry
3952 
3953     __ lea(rbot, monitor_block_bot);    // points to word before bottom
3954                                         // of monitor block

  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "asm/macroAssembler.hpp"
  26 #include "compiler/disassembler.hpp"
  27 #include "gc/shared/collectedHeap.hpp"
  28 #include "gc/shared/gc_globals.hpp"
  29 #include "gc/shared/tlab_globals.hpp"
  30 #include "interpreter/interpreter.hpp"
  31 #include "interpreter/interpreterRuntime.hpp"
  32 #include "interpreter/interp_masm.hpp"
  33 #include "interpreter/templateTable.hpp"
  34 #include "memory/universe.hpp"
  35 #include "oops/methodCounters.hpp"
  36 #include "oops/methodData.hpp"
  37 #include "oops/objArrayKlass.hpp"
  38 #include "oops/oop.inline.hpp"
  39 #include "oops/inlineKlass.hpp"
  40 #include "oops/resolvedFieldEntry.hpp"
  41 #include "oops/resolvedIndyEntry.hpp"
  42 #include "oops/resolvedMethodEntry.hpp"
  43 #include "prims/jvmtiExport.hpp"
  44 #include "prims/methodHandles.hpp"
  45 #include "runtime/frame.inline.hpp"
  46 #include "runtime/safepointMechanism.hpp"
  47 #include "runtime/sharedRuntime.hpp"
  48 #include "runtime/stubRoutines.hpp"
  49 #include "runtime/synchronizer.hpp"
  50 #include "utilities/macros.hpp"
  51 
  52 #define __ Disassembler::hook<InterpreterMacroAssembler>(__FILE__, __LINE__, _masm)->
  53 
  54 // Global Register Names
  55 static const Register rbcp     = r13;
  56 static const Register rlocals  = r14;
  57 
  58 // Address Computation: local variables
  59 static inline Address iaddress(int n) {

 151 static void do_oop_load(InterpreterMacroAssembler* _masm,
 152                         Address src,
 153                         Register dst,
 154                         DecoratorSet decorators = 0) {
 155   __ load_heap_oop(dst, src, rdx, decorators);
 156 }
 157 
 158 Address TemplateTable::at_bcp(int offset) {
 159   assert(_desc->uses_bcp(), "inconsistent uses_bcp information");
 160   return Address(rbcp, offset);
 161 }
 162 
 163 
 164 void TemplateTable::patch_bytecode(Bytecodes::Code bc, Register bc_reg,
 165                                    Register temp_reg, bool load_bc_into_bc_reg/*=true*/,
 166                                    int byte_no) {
 167   if (!RewriteBytecodes)  return;
 168   Label L_patch_done;
 169 
 170   switch (bc) {
 171   case Bytecodes::_fast_vputfield:
 172   case Bytecodes::_fast_aputfield:
 173   case Bytecodes::_fast_bputfield:
 174   case Bytecodes::_fast_zputfield:
 175   case Bytecodes::_fast_cputfield:
 176   case Bytecodes::_fast_dputfield:
 177   case Bytecodes::_fast_fputfield:
 178   case Bytecodes::_fast_iputfield:
 179   case Bytecodes::_fast_lputfield:
 180   case Bytecodes::_fast_sputfield:
 181     {
 182       // We skip bytecode quickening for putfield instructions when
 183       // the put_code written to the constant pool cache is zero.
 184       // This is required so that every execution of this instruction
 185       // calls out to InterpreterRuntime::resolve_get_put to do
 186       // additional, required work.
 187       assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
 188       assert(load_bc_into_bc_reg, "we use bc_reg as temp");
 189       __ load_field_entry(temp_reg, bc_reg);
 190       if (byte_no == f1_byte) {
 191         __ load_unsigned_byte(temp_reg, Address(temp_reg, in_bytes(ResolvedFieldEntry::get_code_offset())));

 760                     Address(rdx, rax,
 761                             Address::times_4,
 762                             arrayOopDesc::base_offset_in_bytes(T_FLOAT)),
 763                     noreg);
 764 }
 765 
 766 void TemplateTable::daload() {
 767   transition(itos, dtos);
 768   // rax: index
 769   // rdx: array
 770   index_check(rdx, rax); // kills rbx
 771   __ access_load_at(T_DOUBLE, IN_HEAP | IS_ARRAY, noreg /* dtos */,
 772                     Address(rdx, rax,
 773                             Address::times_8,
 774                             arrayOopDesc::base_offset_in_bytes(T_DOUBLE)),
 775                     noreg);
 776 }
 777 
 778 void TemplateTable::aaload() {
 779   transition(itos, atos);
 780   Register array = rdx;
 781   Register index = rax;
 782 
 783   index_check(array, index); // kills rbx
 784   __ profile_array_type<ArrayLoadData>(rbx, array, rcx);
 785   if (UseArrayFlattening) {
 786     Label is_flat_array, done;
 787     __ test_flat_array_oop(array, rbx, is_flat_array);
 788     do_oop_load(_masm,
 789                 Address(array, index,
 790                         UseCompressedOops ? Address::times_4 : Address::times_ptr,
 791                         arrayOopDesc::base_offset_in_bytes(T_OBJECT)),
 792                 rax,
 793                 IS_ARRAY);
 794     __ jmp(done);
 795     __ bind(is_flat_array);
 796     __ movptr(rcx, array);
 797     call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::flat_array_load), rcx, index);
 798     __ bind(done);
 799   } else {
 800     do_oop_load(_masm,
 801                 Address(array, index,
 802                         UseCompressedOops ? Address::times_4 : Address::times_ptr,
 803                         arrayOopDesc::base_offset_in_bytes(T_OBJECT)),
 804                 rax,
 805                 IS_ARRAY);
 806   }
 807   __ profile_element_type(rbx, rax, rcx);
 808 }
 809 
 810 void TemplateTable::baload() {
 811   transition(itos, itos);
 812   // rax: index
 813   // rdx: array
 814   index_check(rdx, rax); // kills rbx
 815   __ access_load_at(T_BYTE, IN_HEAP | IS_ARRAY, rax,
 816                     Address(rdx, rax, Address::times_1, arrayOopDesc::base_offset_in_bytes(T_BYTE)),
 817                     noreg);
 818 }
 819 
 820 void TemplateTable::caload() {
 821   transition(itos, itos);
 822   // rax: index
 823   // rdx: array
 824   index_check(rdx, rax); // kills rbx
 825   __ access_load_at(T_CHAR, IN_HEAP | IS_ARRAY, rax,
 826                     Address(rdx, rax, Address::times_2, arrayOopDesc::base_offset_in_bytes(T_CHAR)),
 827                     noreg);

1061   __ access_store_at(T_FLOAT, IN_HEAP | IS_ARRAY,
1062                      Address(rdx, rbx, Address::times_4,
1063                              arrayOopDesc::base_offset_in_bytes(T_FLOAT)),
1064                      noreg /* ftos */, noreg, noreg, noreg);
1065 }
1066 
1067 void TemplateTable::dastore() {
1068   transition(dtos, vtos);
1069   __ pop_i(rbx);
1070   // value is in xmm0
1071   // rbx:  index
1072   // rdx:  array
1073   index_check(rdx, rbx); // prefer index in rbx
1074   __ access_store_at(T_DOUBLE, IN_HEAP | IS_ARRAY,
1075                      Address(rdx, rbx, Address::times_8,
1076                              arrayOopDesc::base_offset_in_bytes(T_DOUBLE)),
1077                      noreg /* dtos */, noreg, noreg, noreg);
1078 }
1079 
1080 void TemplateTable::aastore() {
1081   Label is_null, is_flat_array, ok_is_subtype, done;
1082   transition(vtos, vtos);
1083   // stack: ..., array, index, value
1084   __ movptr(rax, at_tos());    // value
1085   __ movl(rcx, at_tos_p1()); // index
1086   __ movptr(rdx, at_tos_p2()); // array
1087 
1088   Address element_address(rdx, rcx,
1089                           UseCompressedOops? Address::times_4 : Address::times_ptr,
1090                           arrayOopDesc::base_offset_in_bytes(T_OBJECT));
1091 
1092   index_check_without_pop(rdx, rcx);     // kills rbx
1093 
1094   __ profile_array_type<ArrayStoreData>(rdi, rdx, rbx);
1095   __ profile_multiple_element_types(rdi, rax, rbx, rcx);
1096 
1097   __ testptr(rax, rax);
1098   __ jcc(Assembler::zero, is_null);
1099 
1100   // Move array class to rdi
1101   __ load_klass(rdi, rdx, rscratch1);
1102   if (UseArrayFlattening) {
1103     __ movl(rbx, Address(rdi, Klass::layout_helper_offset()));
1104     __ test_flat_array_layout(rbx, is_flat_array);
1105   }
1106 
1107   // Move subklass into rbx
1108   __ load_klass(rbx, rax, rscratch1);
1109   // Move array element superklass into rax
1110   __ movptr(rax, Address(rdi,

1111                          ObjArrayKlass::element_klass_offset()));
1112 
1113   // Generate subtype check.  Blows rcx, rdi
1114   // Superklass in rax.  Subklass in rbx.
1115   // is "rbx <: rax" ? (value subclass <: array element superclass)
1116   __ gen_subtype_check(rbx, ok_is_subtype, false);
1117 
1118   // Come here on failure
1119   // object is at TOS
1120   __ jump(RuntimeAddress(Interpreter::_throw_ArrayStoreException_entry));
1121 
1122   // Come here on success
1123   __ bind(ok_is_subtype);
1124 
1125   // Get the value we will store
1126   __ movptr(rax, at_tos());
1127   __ movl(rcx, at_tos_p1()); // index
1128   // Now store using the appropriate barrier
1129   do_oop_store(_masm, element_address, rax, IS_ARRAY);
1130   __ jmp(done);
1131 
1132   // Have a null in rax, rdx=array, ecx=index.  Store null at ary[idx]
1133   __ bind(is_null);
1134   if (EnableValhalla) {
1135     Label write_null_to_null_free_array, store_null;
1136 
1137       // Move array class to rdi
1138     __ load_klass(rdi, rdx, rscratch1);
1139     if (UseArrayFlattening) {
1140       __ movl(rbx, Address(rdi, Klass::layout_helper_offset()));
1141       __ test_flat_array_layout(rbx, is_flat_array);
1142     }
1143 
1144     // No way to store null in null-free array
1145     __ test_null_free_array_oop(rdx, rbx, write_null_to_null_free_array);
1146     __ jmp(store_null);
1147 
1148     __ bind(write_null_to_null_free_array);
1149     __ jump(RuntimeAddress(Interpreter::_throw_NullPointerException_entry));
1150 
1151     __ bind(store_null);
1152   }
1153   // Store a null
1154   do_oop_store(_masm, element_address, noreg, IS_ARRAY);
1155   __ jmp(done);
1156 
1157   if (UseArrayFlattening) {
1158     Label is_type_ok;
1159     __ bind(is_flat_array); // Store non-null value to flat
1160 
1161     __ movptr(rax, at_tos());
1162     __ movl(rcx, at_tos_p1()); // index
1163     __ movptr(rdx, at_tos_p2()); // array
1164 
1165     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::flat_array_store), rax, rdx, rcx);
1166   }
1167   // Pop stack arguments
1168   __ bind(done);
1169   __ addptr(rsp, 3 * Interpreter::stackElementSize);
1170 }
1171 
1172 void TemplateTable::bastore() {
1173   transition(itos, vtos);
1174   __ pop_i(rbx);
1175   // rax: value
1176   // rbx: index
1177   // rdx: array
1178   index_check(rdx, rbx); // prefer index in rbx
1179   // Need to check whether array is boolean or byte
1180   // since both types share the bastore bytecode.
1181   __ load_klass(rcx, rdx, rscratch1);
1182   __ movl(rcx, Address(rcx, Klass::layout_helper_offset()));
1183   int diffbit = Klass::layout_helper_boolean_diffbit();
1184   __ testl(rcx, diffbit);
1185   Label L_skip;
1186   __ jccb(Assembler::zero, L_skip);

1934   __ jcc(j_not(cc), not_taken);
1935   branch(false, false);
1936   __ bind(not_taken);
1937   __ profile_not_taken_branch(rax);
1938 }
1939 
1940 void TemplateTable::if_nullcmp(Condition cc) {
1941   transition(atos, vtos);
1942   // assume branch is more often taken than not (loops use backward branches)
1943   Label not_taken;
1944   __ testptr(rax, rax);
1945   __ jcc(j_not(cc), not_taken);
1946   branch(false, false);
1947   __ bind(not_taken);
1948   __ profile_not_taken_branch(rax);
1949 }
1950 
1951 void TemplateTable::if_acmp(Condition cc) {
1952   transition(atos, vtos);
1953   // assume branch is more often taken than not (loops use backward branches)
1954   Label taken, not_taken;
1955   __ pop_ptr(rdx);
1956 
1957   __ profile_acmp(rbx, rdx, rax, rcx);
1958 
1959   const int is_inline_type_mask = markWord::inline_type_pattern;
1960   if (EnableValhalla) {
1961     __ cmpoop(rdx, rax);
1962     __ jcc(Assembler::equal, (cc == equal) ? taken : not_taken);
1963 
1964     // might be substitutable, test if either rax or rdx is null
1965     __ testptr(rax, rax);
1966     __ jcc(Assembler::zero, (cc == equal) ? not_taken : taken);
1967     __ testptr(rdx, rdx);
1968     __ jcc(Assembler::zero, (cc == equal) ? not_taken : taken);
1969 
1970     // and both are values ?
1971     __ movptr(rbx, Address(rdx, oopDesc::mark_offset_in_bytes()));
1972     __ andptr(rbx, Address(rax, oopDesc::mark_offset_in_bytes()));
1973     __ andptr(rbx, is_inline_type_mask);
1974     __ cmpptr(rbx, is_inline_type_mask);
1975     __ jcc(Assembler::notEqual, (cc == equal) ? not_taken : taken);
1976 
1977     // same value klass ?
1978     __ load_metadata(rbx, rdx);
1979     __ load_metadata(rcx, rax);
1980     __ cmpptr(rbx, rcx);
1981     __ jcc(Assembler::notEqual, (cc == equal) ? not_taken : taken);
1982 
1983     // Know both are the same type, let's test for substitutability...
1984     if (cc == equal) {
1985       invoke_is_substitutable(rax, rdx, taken, not_taken);
1986     } else {
1987       invoke_is_substitutable(rax, rdx, not_taken, taken);
1988     }
1989     __ stop("Not reachable");
1990   }
1991 
1992   __ cmpoop(rdx, rax);
1993   __ jcc(j_not(cc), not_taken);
1994   __ bind(taken);
1995   branch(false, false);
1996   __ bind(not_taken);
1997   __ profile_not_taken_branch(rax, true);
1998 }
1999 
2000 void TemplateTable::invoke_is_substitutable(Register aobj, Register bobj,
2001                                             Label& is_subst, Label& not_subst) {
2002   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::is_substitutable), aobj, bobj);
2003   // Restored...rax answer, jmp to outcome...
2004   __ testl(rax, rax);
2005   __ jcc(Assembler::zero, not_subst);
2006   __ jmp(is_subst);
2007 }
2008 
2009 void TemplateTable::ret() {
2010   transition(vtos, vtos);
2011   locals_index(rbx);
2012   __ movslq(rbx, iaddress(rbx)); // get return bci, compute return bcp
2013   __ profile_ret(rbx, rcx);
2014   __ get_method(rax);
2015   __ movptr(rbcp, Address(rax, Method::const_offset()));
2016   __ lea(rbcp, Address(rbcp, rbx, Address::times_1,
2017                       ConstMethod::codes_offset()));
2018   __ dispatch_next(vtos, 0, true);
2019 }
2020 
2021 void TemplateTable::wide_ret() {
2022   transition(vtos, vtos);
2023   locals_index_wide(rbx);
2024   __ movptr(rbx, aaddress(rbx)); // get return bci, compute return bcp
2025   __ profile_ret(rbx, rcx);
2026   __ get_method(rax);

2240   if (_desc->bytecode() != Bytecodes::_return_register_finalizer) {
2241     Label no_safepoint;
2242     NOT_PRODUCT(__ block_comment("Thread-local Safepoint poll"));
2243     __ testb(Address(r15_thread, JavaThread::polling_word_offset()), SafepointMechanism::poll_bit());
2244     __ jcc(Assembler::zero, no_safepoint);
2245     __ push(state);
2246     __ push_cont_fastpath();
2247     __ call_VM(noreg, CAST_FROM_FN_PTR(address,
2248                                        InterpreterRuntime::at_safepoint));
2249     __ pop_cont_fastpath();
2250     __ pop(state);
2251     __ bind(no_safepoint);
2252   }
2253 
2254   // Narrow result if state is itos but result type is smaller.
2255   // Need to narrow in the return bytecode rather than in generate_return_entry
2256   // since compiled code callers expect the result to already be narrowed.
2257   if (state == itos) {
2258     __ narrow(rax);
2259   }
2260 
2261   __ remove_activation(state, rbcp, true, true, true);
2262 
2263   __ jmp(rbcp);
2264 }
2265 
2266 // ----------------------------------------------------------------------------
2267 // Volatile variables demand their effects be made known to all CPU's
2268 // in order.  Store buffers on most chips allow reads & writes to
2269 // reorder; the JMM's ReadAfterWrite.java test fails in -Xint mode
2270 // without some kind of memory barrier (i.e., it's not sufficient that
2271 // the interpreter does not reorder volatile references, the hardware
2272 // also must not reorder them).
2273 //
2274 // According to the new Java Memory Model (JMM):
2275 // (1) All volatiles are serialized wrt to each other.  ALSO reads &
2276 //     writes act as acquire & release, so:
2277 // (2) A read cannot let unrelated NON-volatile memory refs that
2278 //     happen after the read float up to before the read.  It's OK for
2279 //     non-volatile memory refs that happen before the volatile read to
2280 //     float down below it.
2281 // (3) Similar a volatile write cannot let unrelated NON-volatile

2601     }
2602     // rax,:   object pointer or null
2603     // cache: cache entry pointer
2604     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access),
2605               rax, cache);
2606 
2607     __ load_field_entry(cache, index);
2608     __ bind(L1);
2609   }
2610 }
2611 
2612 void TemplateTable::pop_and_check_object(Register r) {
2613   __ pop_ptr(r);
2614   __ null_check(r);  // for field access must check obj.
2615   __ verify_oop(r);
2616 }
2617 
2618 void TemplateTable::getfield_or_static(int byte_no, bool is_static, RewriteControl rc) {
2619   transition(vtos, vtos);
2620 
2621   const Register obj   = r9;
2622   const Register cache = rcx;
2623   const Register index = rdx;
2624   const Register off   = rbx;
2625   const Register tos_state   = rax;
2626   const Register flags = rdx;
2627   const Register bc    = c_rarg3; // uses same reg as obj, so don't mix them
2628 
2629   resolve_cache_and_index_for_field(byte_no, cache, index);
2630   jvmti_post_field_access(cache, index, is_static, false);
2631   load_resolved_field_entry(obj, cache, tos_state, off, flags, is_static);
2632 


2633   const Address field(obj, off, Address::times_1, 0*wordSize);
2634 
2635   Label Done, notByte, notBool, notInt, notShort, notChar, notLong, notFloat, notObj, notInlineType;
2636 
2637   // Make sure we don't need to mask edx after the above shift
2638   assert(btos == 0, "change code, btos != 0");
2639   __ testl(tos_state, tos_state);
2640   __ jcc(Assembler::notZero, notByte);
2641 
2642   // btos
2643   if (!is_static) pop_and_check_object(obj);
2644   __ access_load_at(T_BYTE, IN_HEAP, rax, field, noreg);
2645   __ push(btos);
2646   // Rewrite bytecode to be faster
2647   if (!is_static && rc == may_rewrite) {
2648     patch_bytecode(Bytecodes::_fast_bgetfield, bc, rbx);
2649   }
2650   __ jmp(Done);
2651 
2652   __ bind(notByte);
2653   __ cmpl(tos_state, ztos);
2654   __ jcc(Assembler::notEqual, notBool);
2655    if (!is_static) pop_and_check_object(obj);
2656   // ztos (same code as btos)
2657   __ access_load_at(T_BOOLEAN, IN_HEAP, rax, field, noreg);
2658   __ push(ztos);
2659   // Rewrite bytecode to be faster
2660   if (!is_static && rc == may_rewrite) {
2661     // use btos rewriting, no truncating to t/f bit is needed for getfield.
2662     patch_bytecode(Bytecodes::_fast_bgetfield, bc, rbx);
2663   }
2664   __ jmp(Done);
2665 
2666   __ bind(notBool);
2667   __ cmpl(tos_state, atos);
2668   __ jcc(Assembler::notEqual, notObj);
2669   // atos
2670   if (!EnableValhalla) {
2671     if (!is_static) pop_and_check_object(obj);
2672     do_oop_load(_masm, field, rax);
2673     __ push(atos);
2674     if (!is_static && rc == may_rewrite) {
2675       patch_bytecode(Bytecodes::_fast_agetfield, bc, rbx);
2676     }
2677     __ jmp(Done);
2678   } else {
2679     if (is_static) {
2680       __ load_heap_oop(rax, field);
2681       __ push(atos);
2682       __ jmp(Done);
2683     } else {
2684       Label is_flat, rewrite_inline;
2685       __ test_field_is_flat(flags, rscratch1, is_flat);
2686       pop_and_check_object(obj);
2687       __ load_heap_oop(rax, field);
2688       __ push(atos);
2689       if (rc == may_rewrite) {
2690         patch_bytecode(Bytecodes::_fast_agetfield, bc, rbx);
2691       }
2692       __ jmp(Done);
2693       __ bind(is_flat);
2694       // field is flat (null-free or nullable with a null-marker)
2695       pop_and_check_object(rax);
2696       __ read_flat_field(rcx, rdx, rbx, rax);
2697       __ verify_oop(rax);
2698       __ push(atos);
2699       __ bind(rewrite_inline);
2700       if (rc == may_rewrite) {
2701         patch_bytecode(Bytecodes::_fast_vgetfield, bc, rbx);
2702       }
2703       __ jmp(Done);
2704     }
2705   }

2706 
2707   __ bind(notObj);
2708 
2709   if (!is_static) pop_and_check_object(obj);
2710 
2711   __ cmpl(tos_state, itos);
2712   __ jcc(Assembler::notEqual, notInt);
2713   // itos
2714   __ access_load_at(T_INT, IN_HEAP, rax, field, noreg);
2715   __ push(itos);
2716   // Rewrite bytecode to be faster
2717   if (!is_static && rc == may_rewrite) {
2718     patch_bytecode(Bytecodes::_fast_igetfield, bc, rbx);
2719   }
2720   __ jmp(Done);
2721 
2722   __ bind(notInt);
2723   __ cmpl(tos_state, ctos);
2724   __ jcc(Assembler::notEqual, notChar);
2725   // ctos
2726   __ access_load_at(T_CHAR, IN_HEAP, rax, field, noreg);
2727   __ push(ctos);
2728   // Rewrite bytecode to be faster
2729   if (!is_static && rc == may_rewrite) {
2730     patch_bytecode(Bytecodes::_fast_cgetfield, bc, rbx);

2790 #endif
2791 
2792   __ bind(Done);
2793   // [jk] not needed currently
2794   // volatile_barrier(Assembler::Membar_mask_bits(Assembler::LoadLoad |
2795   //                                              Assembler::LoadStore));
2796 }
2797 
2798 void TemplateTable::getfield(int byte_no) {
2799   getfield_or_static(byte_no, false);
2800 }
2801 
2802 void TemplateTable::nofast_getfield(int byte_no) {
2803   getfield_or_static(byte_no, false, may_not_rewrite);
2804 }
2805 
2806 void TemplateTable::getstatic(int byte_no) {
2807   getfield_or_static(byte_no, true);
2808 }
2809 

2810 // The registers cache and index expected to be set before call.
2811 // The function may destroy various registers, just not the cache and index registers.
2812 void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
2813   // Cache is rcx and index is rdx
2814   const Register entry = c_rarg2; // ResolvedFieldEntry
2815   const Register obj = c_rarg1;   // Object pointer
2816   const Register value = c_rarg3; // JValue object
2817 
2818   if (JvmtiExport::can_post_field_modification()) {
2819     // Check to see if a field modification watch has been set before
2820     // we take the time to call into the VM.
2821     Label L1;
2822     assert_different_registers(cache, obj, rax);
2823     __ mov32(rax, ExternalAddress((address)JvmtiExport::get_field_modification_count_addr()));
2824     __ testl(rax, rax);
2825     __ jcc(Assembler::zero, L1);
2826 
2827     __ mov(entry, cache);
2828 
2829     if (is_static) {

2851     // cache: field entry pointer
2852     // value: jvalue object on the stack
2853     __ call_VM(noreg,
2854               CAST_FROM_FN_PTR(address,
2855                               InterpreterRuntime::post_field_modification),
2856               obj, entry, value);
2857     // Reload field entry
2858     __ load_field_entry(cache, index);
2859     __ bind(L1);
2860   }
2861 }
2862 
2863 void TemplateTable::putfield_or_static(int byte_no, bool is_static, RewriteControl rc) {
2864   transition(vtos, vtos);
2865 
2866   const Register obj = rcx;
2867   const Register cache = rcx;
2868   const Register index = rdx;
2869   const Register tos_state   = rdx;
2870   const Register off   = rbx;
2871   const Register flags = r9;
2872 
2873   resolve_cache_and_index_for_field(byte_no, cache, index);
2874   jvmti_post_field_mod(cache, index, is_static);
2875   load_resolved_field_entry(obj, cache, tos_state, off, flags, is_static);
2876 
2877   // [jk] not needed currently
2878   // volatile_barrier(Assembler::Membar_mask_bits(Assembler::LoadStore |
2879   //                                              Assembler::StoreStore));
2880 
2881   Label notVolatile, Done;
2882 
2883   // Check for volatile store
2884   __ movl(rscratch1, flags);
2885   __ andl(rscratch1, (1 << ResolvedFieldEntry::is_volatile_shift));
2886   __ testl(rscratch1, rscratch1);
2887   __ jcc(Assembler::zero, notVolatile);
2888 
2889   putfield_or_static_helper(byte_no, is_static, rc, obj, off, tos_state, flags);
2890   volatile_barrier(Assembler::Membar_mask_bits(Assembler::StoreLoad |
2891                                                Assembler::StoreStore));
2892   __ jmp(Done);
2893   __ bind(notVolatile);
2894 
2895   putfield_or_static_helper(byte_no, is_static, rc, obj, off, tos_state, flags);
2896 
2897   __ bind(Done);
2898 }
2899 
2900 void TemplateTable::putfield_or_static_helper(int byte_no, bool is_static, RewriteControl rc,
2901                                               Register obj, Register off, Register tos_state, Register flags) {
2902 
2903   // field addresses
2904   const Address field(obj, off, Address::times_1, 0*wordSize);
2905 
2906   Label notByte, notBool, notInt, notShort, notChar,
2907         notLong, notFloat, notObj, notInlineType;
2908   Label Done;
2909 
2910   const Register bc    = c_rarg3;
2911 
2912   // Test TOS state
2913   __ testl(tos_state, tos_state);
2914   __ jcc(Assembler::notZero, notByte);
2915 
2916   // btos
2917   {
2918     __ pop(btos);
2919     if (!is_static) pop_and_check_object(obj);
2920     __ access_store_at(T_BYTE, IN_HEAP, field, rax, noreg, noreg, noreg);
2921     if (!is_static && rc == may_rewrite) {
2922       patch_bytecode(Bytecodes::_fast_bputfield, bc, rbx, true, byte_no);
2923     }
2924     __ jmp(Done);
2925   }
2926 
2927   __ bind(notByte);
2928   __ cmpl(tos_state, ztos);
2929   __ jcc(Assembler::notEqual, notBool);
2930 
2931   // ztos
2932   {
2933     __ pop(ztos);
2934     if (!is_static) pop_and_check_object(obj);
2935     __ access_store_at(T_BOOLEAN, IN_HEAP, field, rax, noreg, noreg, noreg);
2936     if (!is_static && rc == may_rewrite) {
2937       patch_bytecode(Bytecodes::_fast_zputfield, bc, rbx, true, byte_no);
2938     }
2939     __ jmp(Done);
2940   }
2941 
2942   __ bind(notBool);
2943   __ cmpl(tos_state, atos);
2944   __ jcc(Assembler::notEqual, notObj);
2945 
2946   // atos
2947   {
2948     if (!EnableValhalla) {
2949       __ pop(atos);
2950       if (!is_static) pop_and_check_object(obj);
2951       // Store into the field
2952       do_oop_store(_masm, field, rax);
2953       if (!is_static && rc == may_rewrite) {
2954         patch_bytecode(Bytecodes::_fast_aputfield, bc, rbx, true, byte_no);
2955       }
2956       __ jmp(Done);
2957     } else {
2958       __ pop(atos);
2959       if (is_static) {
2960         Label is_nullable;
2961         __ test_field_is_not_null_free_inline_type(flags, rscratch1, is_nullable);
2962         __ null_check(rax);  // FIXME JDK-8341120
2963         __ bind(is_nullable);
2964         do_oop_store(_masm, field, rax);
2965         __ jmp(Done);
2966       } else {
2967         Label is_flat, null_free_reference, rewrite_inline;
2968         __ test_field_is_flat(flags, rscratch1, is_flat);
2969         __ test_field_is_null_free_inline_type(flags, rscratch1, null_free_reference);
2970         pop_and_check_object(obj);
2971         // Store into the field
2972         do_oop_store(_masm, field, rax);
2973         if (rc == may_rewrite) {
2974           patch_bytecode(Bytecodes::_fast_aputfield, bc, rbx, true, byte_no);
2975         }
2976         __ jmp(Done);
2977         __ bind(null_free_reference);
2978         __ null_check(rax);  // FIXME JDK-8341120
2979         pop_and_check_object(obj);
2980         // Store into the field
2981         do_oop_store(_masm, field, rax);
2982         __ jmp(rewrite_inline);
2983         __ bind(is_flat);
2984         pop_and_check_object(r8);
2985         __ write_flat_field(rcx, r9, rscratch2, r8, rbx, rax);
2986         __ bind(rewrite_inline);
2987         if (rc == may_rewrite) {
2988           patch_bytecode(Bytecodes::_fast_vputfield, bc, rbx, true, byte_no);
2989         }
2990         __ jmp(Done);
2991       }
2992     }

2993   }
2994 
2995   __ bind(notObj);
2996   __ cmpl(tos_state, itos);
2997   __ jcc(Assembler::notEqual, notInt);
2998 
2999   // itos
3000   {
3001     __ pop(itos);
3002     if (!is_static) pop_and_check_object(obj);
3003     __ access_store_at(T_INT, IN_HEAP, field, rax, noreg, noreg, noreg);
3004     if (!is_static && rc == may_rewrite) {
3005       patch_bytecode(Bytecodes::_fast_iputfield, bc, rbx, true, byte_no);
3006     }
3007     __ jmp(Done);
3008   }
3009 
3010   __ bind(notInt);
3011   __ cmpl(tos_state, ctos);
3012   __ jcc(Assembler::notEqual, notChar);

3109 }
3110 
3111 void TemplateTable::jvmti_post_fast_field_mod() {
3112 
3113   const Register scratch = c_rarg3;
3114 
3115   if (JvmtiExport::can_post_field_modification()) {
3116     // Check to see if a field modification watch has been set before
3117     // we take the time to call into the VM.
3118     Label L2;
3119     __ mov32(scratch, ExternalAddress((address)JvmtiExport::get_field_modification_count_addr()));
3120     __ testl(scratch, scratch);
3121     __ jcc(Assembler::zero, L2);
3122     __ pop_ptr(rbx);                  // copy the object pointer from tos
3123     __ verify_oop(rbx);
3124     __ push_ptr(rbx);                 // put the object pointer back on tos
3125     // Save tos values before call_VM() clobbers them. Since we have
3126     // to do it for every data type, we use the saved values as the
3127     // jvalue object.
3128     switch (bytecode()) {          // load values into the jvalue object
3129     case Bytecodes::_fast_vputfield: //fall through
3130     case Bytecodes::_fast_aputfield: __ push_ptr(rax); break;
3131     case Bytecodes::_fast_bputfield: // fall through
3132     case Bytecodes::_fast_zputfield: // fall through
3133     case Bytecodes::_fast_sputfield: // fall through
3134     case Bytecodes::_fast_cputfield: // fall through
3135     case Bytecodes::_fast_iputfield: __ push_i(rax); break;
3136     case Bytecodes::_fast_dputfield: __ push(dtos); break;
3137     case Bytecodes::_fast_fputfield: __ push(ftos); break;
3138     case Bytecodes::_fast_lputfield: __ push_l(rax); break;
3139 
3140     default:
3141       ShouldNotReachHere();
3142     }
3143     __ mov(scratch, rsp);             // points to jvalue on the stack
3144     // access constant pool cache entry
3145     __ load_field_entry(c_rarg2, rax);
3146     __ verify_oop(rbx);
3147     // rbx: object pointer copied above
3148     // c_rarg2: cache entry pointer
3149     // c_rarg3: jvalue object on the stack
3150     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification), rbx, c_rarg2, c_rarg3);
3151 
3152     switch (bytecode()) {             // restore tos values
3153     case Bytecodes::_fast_vputfield: // fall through
3154     case Bytecodes::_fast_aputfield: __ pop_ptr(rax); break;
3155     case Bytecodes::_fast_bputfield: // fall through
3156     case Bytecodes::_fast_zputfield: // fall through
3157     case Bytecodes::_fast_sputfield: // fall through
3158     case Bytecodes::_fast_cputfield: // fall through
3159     case Bytecodes::_fast_iputfield: __ pop_i(rax); break;
3160     case Bytecodes::_fast_dputfield: __ pop(dtos); break;
3161     case Bytecodes::_fast_fputfield: __ pop(ftos); break;
3162     case Bytecodes::_fast_lputfield: __ pop_l(rax); break;
3163     default: break;
3164     }
3165     __ bind(L2);
3166   }
3167 }
3168 
3169 void TemplateTable::fast_storefield(TosState state) {
3170   transition(state, vtos);
3171 


3172   Label notVolatile, Done;
3173 
3174   jvmti_post_fast_field_mod();
3175 
3176   __ push(rax);
3177   __ load_field_entry(rcx, rax);
3178   load_resolved_field_entry(noreg, rcx, rax, rbx, rdx);


3179   __ pop(rax);
3180   // RBX: field offset, RCX: RAX: TOS, RDX: flags
3181 
3182   // Get object from stack
3183   pop_and_check_object(rcx);
3184 
3185   // field address
3186   const Address field(rcx, rbx, Address::times_1);
3187 
3188   // Check for volatile store
3189   __ movl(rscratch2, rdx);  // saving flags for is_flat test
3190   __ andl(rscratch2, (1 << ResolvedFieldEntry::is_volatile_shift));
3191   __ testl(rscratch2, rscratch2);
3192   __ jcc(Assembler::zero, notVolatile);
3193 
3194   fast_storefield_helper(field, rax, rdx);
3195   volatile_barrier(Assembler::Membar_mask_bits(Assembler::StoreLoad |
3196                                                Assembler::StoreStore));
3197   __ jmp(Done);
3198   __ bind(notVolatile);
3199 
3200   fast_storefield_helper(field, rax, rdx);
3201 
3202   __ bind(Done);
3203 }
3204 
3205 void TemplateTable::fast_storefield_helper(Address field, Register rax, Register flags) {
3206 
3207   // DANGER: 'field' argument depends on rcx and rbx
3208 
3209   // access field
3210   switch (bytecode()) {
3211   case Bytecodes::_fast_vputfield:
3212     {
3213       // Field is either flat (nullable or not) or non-flat and null-free
3214       Label is_flat, done;
3215       __ test_field_is_flat(flags, rscratch1, is_flat);
3216       __ null_check(rax);  // FIXME JDK-8341120
3217       do_oop_store(_masm, field, rax);
3218       __ jmp(done);
3219       __ bind(is_flat);
3220       __ load_field_entry(r8, r9);
3221       __ movptr(r9, rcx);  // re-shuffle registers because of VM call calling convention
3222       __ write_flat_field(r8, rscratch1, rscratch2, r9, rbx, rax);
3223       __ bind(done);
3224     }
3225     break;
3226   case Bytecodes::_fast_aputfield:
3227     {
3228       do_oop_store(_masm, field, rax);
3229     }
3230     break;
3231   case Bytecodes::_fast_lputfield:
3232     __ access_store_at(T_LONG, IN_HEAP, field, noreg /* ltos */, noreg, noreg, noreg);
3233     break;
3234   case Bytecodes::_fast_iputfield:
3235     __ access_store_at(T_INT, IN_HEAP, field, rax, noreg, noreg, noreg);
3236     break;
3237   case Bytecodes::_fast_zputfield:
3238     __ access_store_at(T_BOOLEAN, IN_HEAP, field, rax, noreg, noreg, noreg);
3239     break;
3240   case Bytecodes::_fast_bputfield:
3241     __ access_store_at(T_BYTE, IN_HEAP, field, rax, noreg, noreg, noreg);
3242     break;
3243   case Bytecodes::_fast_sputfield:
3244     __ access_store_at(T_SHORT, IN_HEAP, field, rax, noreg, noreg, noreg);
3245     break;
3246   case Bytecodes::_fast_cputfield:
3247     __ access_store_at(T_CHAR, IN_HEAP, field, rax, noreg, noreg, noreg);
3248     break;
3249   case Bytecodes::_fast_fputfield:

3265     // Check to see if a field access watch has been set before we
3266     // take the time to call into the VM.
3267     Label L1;
3268     __ mov32(rcx, ExternalAddress((address) JvmtiExport::get_field_access_count_addr()));
3269     __ testl(rcx, rcx);
3270     __ jcc(Assembler::zero, L1);
3271     // access constant pool cache entry
3272     __ load_field_entry(c_rarg2, rcx);
3273     __ verify_oop(rax);
3274     __ push_ptr(rax);  // save object pointer before call_VM() clobbers it
3275     __ mov(c_rarg1, rax);
3276     // c_rarg1: object pointer copied above
3277     // c_rarg2: cache entry pointer
3278     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access), c_rarg1, c_rarg2);
3279     __ pop_ptr(rax); // restore object pointer
3280     __ bind(L1);
3281   }
3282 
3283   // access constant pool cache
3284   __ load_field_entry(rcx, rbx);
3285   __ load_sized_value(rdx, Address(rcx, in_bytes(ResolvedFieldEntry::field_offset_offset())), sizeof(int), true /*is_signed*/);
3286 
3287   // rax: object
3288   __ verify_oop(rax);
3289   __ null_check(rax);
3290   Address field(rax, rdx, Address::times_1);
3291 
3292   // access field
3293   switch (bytecode()) {
3294   case Bytecodes::_fast_vgetfield:
3295     __ read_flat_field(rcx, rdx, rbx, rax);
3296     __ verify_oop(rax);
3297     break;
3298   case Bytecodes::_fast_agetfield:
3299     do_oop_load(_masm, field, rax);
3300     __ verify_oop(rax);
3301     break;
3302   case Bytecodes::_fast_lgetfield:
3303     __ access_load_at(T_LONG, IN_HEAP, noreg /* ltos */, field, noreg);
3304     break;
3305   case Bytecodes::_fast_igetfield:
3306     __ access_load_at(T_INT, IN_HEAP, rax, field, noreg);
3307     break;
3308   case Bytecodes::_fast_bgetfield:
3309     __ access_load_at(T_BYTE, IN_HEAP, rax, field, noreg);
3310     break;
3311   case Bytecodes::_fast_sgetfield:
3312     __ access_load_at(T_SHORT, IN_HEAP, rax, field, noreg);
3313     break;
3314   case Bytecodes::_fast_cgetfield:
3315     __ access_load_at(T_CHAR, IN_HEAP, rax, field, noreg);
3316     break;
3317   case Bytecodes::_fast_fgetfield:

3702 
3703   // Note:  rax_callsite is already pushed
3704 
3705   // %%% should make a type profile for any invokedynamic that takes a ref argument
3706   // profile this call
3707   __ profile_call(rbcp);
3708   __ profile_arguments_type(rdx, rbx_method, rbcp, false);
3709 
3710   __ verify_oop(rax_callsite);
3711 
3712   __ jump_from_interpreted(rbx_method, rdx);
3713 }
3714 
3715 //-----------------------------------------------------------------------------
3716 // Allocation
3717 
3718 void TemplateTable::_new() {
3719   transition(vtos, atos);
3720   __ get_unsigned_2_byte_index_at_bcp(rdx, 1);
3721   Label slow_case;

3722   Label done;

3723 
3724   __ get_cpool_and_tags(rcx, rax);
3725 
3726   // Make sure the class we're about to instantiate has been resolved.
3727   // This is done before loading InstanceKlass to be consistent with the order
3728   // how Constant Pool is updated (see ConstantPool::klass_at_put)
3729   const int tags_offset = Array<u1>::base_offset_in_bytes();
3730   __ cmpb(Address(rax, rdx, Address::times_1, tags_offset), JVM_CONSTANT_Class);
3731   __ jcc(Assembler::notEqual, slow_case);
3732 
3733   // get InstanceKlass
3734   __ load_resolved_klass_at_index(rcx, rcx, rdx);

3735 
3736   // make sure klass is initialized
3737   // init_state needs acquire, but x86 is TSO, and so we are already good.
3738   assert(VM_Version::supports_fast_class_init_checks(), "must support fast class initialization checks");
3739   __ clinit_barrier(rcx, nullptr /*L_fast_path*/, &slow_case);
3740 
3741   __ allocate_instance(rcx, rax, rdx, rbx, true, slow_case);
3742   __ jmp(done);

















































































3743 
3744   // slow case
3745   __ bind(slow_case);


3746 
3747   __ get_constant_pool(c_rarg1);
3748   __ get_unsigned_2_byte_index_at_bcp(c_rarg2, 1);
3749   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), c_rarg1, c_rarg2);
3750    __ verify_oop(rax);
3751 
3752   // continue
3753   __ bind(done);
3754 }
3755 
3756 void TemplateTable::newarray() {
3757   transition(itos, atos);
3758   __ load_unsigned_byte(c_rarg1, at_bcp(1));
3759   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::newarray),
3760           c_rarg1, rax);
3761 }
3762 
3763 void TemplateTable::anewarray() {
3764   transition(itos, atos);
3765 

3767   __ get_constant_pool(c_rarg1);
3768   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::anewarray),
3769           c_rarg1, c_rarg2, rax);
3770 }
3771 
3772 void TemplateTable::arraylength() {
3773   transition(atos, itos);
3774   __ movl(rax, Address(rax, arrayOopDesc::length_offset_in_bytes()));
3775 }
3776 
3777 void TemplateTable::checkcast() {
3778   transition(atos, atos);
3779   Label done, is_null, ok_is_subtype, quicked, resolved;
3780   __ testptr(rax, rax); // object is in rax
3781   __ jcc(Assembler::zero, is_null);
3782 
3783   // Get cpool & tags index
3784   __ get_cpool_and_tags(rcx, rdx); // rcx=cpool, rdx=tags array
3785   __ get_unsigned_2_byte_index_at_bcp(rbx, 1); // rbx=index
3786   // See if bytecode has already been quicked
3787   __ movzbl(rdx, Address(rdx, rbx,
3788       Address::times_1,
3789       Array<u1>::base_offset_in_bytes()));
3790   __ cmpl(rdx, JVM_CONSTANT_Class);
3791   __ jcc(Assembler::equal, quicked);
3792   __ push(atos); // save receiver for result, and for GC
3793   call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc));
3794 
3795   __ get_vm_result_metadata(rax);
3796 
3797   __ pop_ptr(rdx); // restore receiver
3798   __ jmpb(resolved);
3799 
3800   // Get superklass in rax and subklass in rbx
3801   __ bind(quicked);
3802   __ mov(rdx, rax); // Save object in rdx; rax needed for subtype check
3803   __ load_resolved_klass_at_index(rax, rcx, rbx);
3804 
3805   __ bind(resolved);
3806   __ load_klass(rbx, rdx, rscratch1);
3807 
3808   // Generate subtype check.  Blows rcx, rdi.  Object in rdx.
3809   // Superklass in rax.  Subklass in rbx.
3810   __ gen_subtype_check(rbx, ok_is_subtype);
3811 
3812   // Come here on failure
3813   __ push_ptr(rdx);
3814   // object is at TOS
3815   __ jump(RuntimeAddress(Interpreter::_throw_ClassCastException_entry));
3816 
3817   // Come here on success
3818   __ bind(ok_is_subtype);
3819   __ mov(rax, rdx); // Restore object in rdx
3820   __ jmp(done);
3821 
3822   __ bind(is_null);
3823 
3824   // Collect counts on whether this check-cast sees nulls a lot or not.
3825   if (ProfileInterpreter) {


3826     __ profile_null_seen(rcx);


3827   }
3828 
3829   __ bind(done);
3830 }
3831 
3832 void TemplateTable::instanceof() {
3833   transition(atos, itos);
3834   Label done, is_null, ok_is_subtype, quicked, resolved;
3835   __ testptr(rax, rax);
3836   __ jcc(Assembler::zero, is_null);
3837 
3838   // Get cpool & tags index
3839   __ get_cpool_and_tags(rcx, rdx); // rcx=cpool, rdx=tags array
3840   __ get_unsigned_2_byte_index_at_bcp(rbx, 1); // rbx=index
3841   // See if bytecode has already been quicked
3842   __ movzbl(rdx, Address(rdx, rbx,
3843         Address::times_1,
3844         Array<u1>::base_offset_in_bytes()));
3845   __ cmpl(rdx, JVM_CONSTANT_Class);
3846   __ jcc(Assembler::equal, quicked);
3847 
3848   __ push(atos); // save receiver for result, and for GC
3849   call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc));
3850 
3851   __ get_vm_result_metadata(rax);
3852 
3853   __ pop_ptr(rdx); // restore receiver
3854   __ verify_oop(rdx);
3855   __ load_klass(rdx, rdx, rscratch1);
3856   __ jmpb(resolved);
3857 
3858   // Get superklass in rax and subklass in rdx
3859   __ bind(quicked);
3860   __ load_klass(rdx, rax, rscratch1);
3861   __ load_resolved_klass_at_index(rax, rcx, rbx);
3862 
3863   __ bind(resolved);
3864 
3865   // Generate subtype check.  Blows rcx, rdi

3869   // Come here on failure
3870   __ xorl(rax, rax);
3871   __ jmpb(done);
3872   // Come here on success
3873   __ bind(ok_is_subtype);
3874   __ movl(rax, 1);
3875 
3876   // Collect counts on whether this test sees nulls a lot or not.
3877   if (ProfileInterpreter) {
3878     __ jmp(done);
3879     __ bind(is_null);
3880     __ profile_null_seen(rcx);
3881   } else {
3882     __ bind(is_null);   // same as 'done'
3883   }
3884   __ bind(done);
3885   // rax = 0: obj == nullptr or  obj is not an instanceof the specified klass
3886   // rax = 1: obj != nullptr and obj is     an instanceof the specified klass
3887 }
3888 

3889 //----------------------------------------------------------------------------------------------------
3890 // Breakpoints
3891 void TemplateTable::_breakpoint() {
3892   // Note: We get here even if we are single stepping..
3893   // jbug insists on setting breakpoints at every bytecode
3894   // even if we are in single step mode.
3895 
3896   transition(vtos, vtos);
3897 
3898   // get the unpatched byte code
3899   __ get_method(c_rarg1);
3900   __ call_VM(noreg,
3901              CAST_FROM_FN_PTR(address,
3902                               InterpreterRuntime::get_original_bytecode_at),
3903              c_rarg1, rbcp);
3904   __ mov(rbx, rax);  // why?
3905 
3906   // post the breakpoint event
3907   __ get_method(c_rarg1);
3908   __ call_VM(noreg,

3928 // Note: monitorenter & exit are symmetric routines; which is reflected
3929 //       in the assembly code structure as well
3930 //
3931 // Stack layout:
3932 //
3933 // [expressions  ] <--- rsp               = expression stack top
3934 // ..
3935 // [expressions  ]
3936 // [monitor entry] <--- monitor block top = expression stack bot
3937 // ..
3938 // [monitor entry]
3939 // [frame data   ] <--- monitor block bot
3940 // ...
3941 // [saved rbp    ] <--- rbp
3942 void TemplateTable::monitorenter() {
3943   transition(atos, vtos);
3944 
3945   // check for null object
3946   __ null_check(rax);
3947 
3948   Label is_inline_type;
3949   __ movptr(rbx, Address(rax, oopDesc::mark_offset_in_bytes()));
3950   __ test_markword_is_inline_type(rbx, is_inline_type);
3951 
3952   const Address monitor_block_top(
3953         rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
3954   const Address monitor_block_bot(
3955         rbp, frame::interpreter_frame_initial_sp_offset * wordSize);
3956   const int entry_size = frame::interpreter_frame_monitor_size_in_bytes();
3957 
3958   Label allocated;
3959 
3960   Register rtop = c_rarg3;
3961   Register rbot = c_rarg2;
3962   Register rmon = c_rarg1;
3963 
3964   // initialize entry pointer
3965   __ xorl(rmon, rmon); // points to free slot or null
3966 
3967   // find a free slot in the monitor block (result in rmon)
3968   {
3969     Label entry, loop, exit;
3970     __ movptr(rtop, monitor_block_top); // derelativize pointer
3971     __ lea(rtop, Address(rbp, rtop, Address::times_ptr));

4024   // rmon: points to monitor entry
4025   __ bind(allocated);
4026 
4027   // Increment bcp to point to the next bytecode, so exception
4028   // handling for async. exceptions work correctly.
4029   // The object has already been popped from the stack, so the
4030   // expression stack looks correct.
4031   __ increment(rbcp);
4032 
4033   // store object
4034   __ movptr(Address(rmon, BasicObjectLock::obj_offset()), rax);
4035   __ lock_object(rmon);
4036 
4037   // check to make sure this monitor doesn't cause stack overflow after locking
4038   __ save_bcp();  // in case of exception
4039   __ generate_stack_overflow_check(0);
4040 
4041   // The bcp has already been incremented. Just need to dispatch to
4042   // next instruction.
4043   __ dispatch_next(vtos);
4044 
4045   __ bind(is_inline_type);
4046   __ call_VM(noreg, CAST_FROM_FN_PTR(address,
4047                     InterpreterRuntime::throw_identity_exception), rax);
4048   __ should_not_reach_here();
4049 }
4050 
4051 void TemplateTable::monitorexit() {
4052   transition(atos, vtos);
4053 
4054   // check for null object
4055   __ null_check(rax);
4056 
4057   const int is_inline_type_mask = markWord::inline_type_pattern;
4058   Label has_identity;
4059   __ movptr(rbx, Address(rax, oopDesc::mark_offset_in_bytes()));
4060   __ andptr(rbx, is_inline_type_mask);
4061   __ cmpl(rbx, is_inline_type_mask);
4062   __ jcc(Assembler::notEqual, has_identity);
4063   __ call_VM(noreg, CAST_FROM_FN_PTR(address,
4064                      InterpreterRuntime::throw_illegal_monitor_state_exception));
4065   __ should_not_reach_here();
4066   __ bind(has_identity);
4067 
4068   const Address monitor_block_top(
4069         rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
4070   const Address monitor_block_bot(
4071         rbp, frame::interpreter_frame_initial_sp_offset * wordSize);
4072   const int entry_size = frame::interpreter_frame_monitor_size_in_bytes();
4073 
4074   Register rtop = c_rarg1;
4075   Register rbot = c_rarg2;
4076 
4077   Label found;
4078 
4079   // find matching slot
4080   {
4081     Label entry, loop;
4082     __ movptr(rtop, monitor_block_top); // derelativize pointer
4083     __ lea(rtop, Address(rbp, rtop, Address::times_ptr));
4084     // rtop points to current entry, starting with top-most entry
4085 
4086     __ lea(rbot, monitor_block_bot);    // points to word before bottom
4087                                         // of monitor block
< prev index next >