< prev index next >

src/hotspot/cpu/x86/templateTable_x86.cpp

Print this page

  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "asm/macroAssembler.hpp"
  27 #include "compiler/disassembler.hpp"
  28 #include "gc/shared/collectedHeap.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/methodData.hpp"
  36 #include "oops/objArrayKlass.hpp"
  37 #include "oops/oop.inline.hpp"

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

 135   case TemplateTable::less_equal   : return Assembler::greater;
 136   case TemplateTable::greater      : return Assembler::lessEqual;
 137   case TemplateTable::greater_equal: return Assembler::less;
 138   }
 139   ShouldNotReachHere();
 140   return Assembler::zero;
 141 }
 142 
 143 
 144 
 145 // Miscelaneous helper routines
 146 // Store an oop (or NULL) at the address described by obj.
 147 // If val == noreg this means store a NULL
 148 
 149 
 150 static void do_oop_store(InterpreterMacroAssembler* _masm,
 151                          Address dst,
 152                          Register val,
 153                          DecoratorSet decorators = 0) {
 154   assert(val == noreg || val == rax, "parameter is just for looks");
 155   __ store_heap_oop(dst, val, rdx, rbx, decorators);
 156 }
 157 
 158 static void do_oop_load(InterpreterMacroAssembler* _masm,
 159                         Address src,
 160                         Register dst,
 161                         DecoratorSet decorators = 0) {
 162   __ load_heap_oop(dst, src, rdx, rbx, decorators);
 163 }
 164 
 165 Address TemplateTable::at_bcp(int offset) {
 166   assert(_desc->uses_bcp(), "inconsistent uses_bcp information");
 167   return Address(rbcp, offset);
 168 }
 169 
 170 
 171 void TemplateTable::patch_bytecode(Bytecodes::Code bc, Register bc_reg,
 172                                    Register temp_reg, bool load_bc_into_bc_reg/*=true*/,
 173                                    int byte_no) {
 174   if (!RewriteBytecodes)  return;
 175   Label L_patch_done;
 176 
 177   switch (bc) {

 178   case Bytecodes::_fast_aputfield:
 179   case Bytecodes::_fast_bputfield:
 180   case Bytecodes::_fast_zputfield:
 181   case Bytecodes::_fast_cputfield:
 182   case Bytecodes::_fast_dputfield:
 183   case Bytecodes::_fast_fputfield:
 184   case Bytecodes::_fast_iputfield:
 185   case Bytecodes::_fast_lputfield:
 186   case Bytecodes::_fast_sputfield:
 187     {
 188       // We skip bytecode quickening for putfield instructions when
 189       // the put_code written to the constant pool cache is zero.
 190       // This is required so that every execution of this instruction
 191       // calls out to InterpreterRuntime::resolve_get_put to do
 192       // additional, required work.
 193       assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
 194       assert(load_bc_into_bc_reg, "we use bc_reg as temp");
 195       __ get_cache_and_index_and_bytecode_at_bcp(temp_reg, bc_reg, temp_reg, byte_no, 1);
 196       __ movl(bc_reg, bc);
 197       __ cmpl(temp_reg, (int) 0);

 350   __ sarl(rax, 16);
 351 }
 352 
 353 void TemplateTable::ldc(bool wide) {
 354   transition(vtos, vtos);
 355   Register rarg = NOT_LP64(rcx) LP64_ONLY(c_rarg1);
 356   Label call_ldc, notFloat, notClass, notInt, Done;
 357 
 358   if (wide) {
 359     __ get_unsigned_2_byte_index_at_bcp(rbx, 1);
 360   } else {
 361     __ load_unsigned_byte(rbx, at_bcp(1));
 362   }
 363 
 364   __ get_cpool_and_tags(rcx, rax);
 365   const int base_offset = ConstantPool::header_size() * wordSize;
 366   const int tags_offset = Array<u1>::base_offset_in_bytes();
 367 
 368   // get type
 369   __ movzbl(rdx, Address(rax, rbx, Address::times_1, tags_offset));

 370 
 371   // unresolved class - get the resolved class
 372   __ cmpl(rdx, JVM_CONSTANT_UnresolvedClass);
 373   __ jccb(Assembler::equal, call_ldc);
 374 
 375   // unresolved class in error state - call into runtime to throw the error
 376   // from the first resolution attempt
 377   __ cmpl(rdx, JVM_CONSTANT_UnresolvedClassInError);
 378   __ jccb(Assembler::equal, call_ldc);
 379 
 380   // resolved class - need to call vm to get java mirror of the class
 381   __ cmpl(rdx, JVM_CONSTANT_Class);
 382   __ jcc(Assembler::notEqual, notClass);
 383 
 384   __ bind(call_ldc);
 385 
 386   __ movl(rarg, wide);
 387   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::ldc), rarg);
 388 
 389   __ push(atos);

 801                     Address(rdx, rax,
 802                             Address::times_4,
 803                             arrayOopDesc::base_offset_in_bytes(T_FLOAT)),
 804                     noreg, noreg);
 805 }
 806 
 807 void TemplateTable::daload() {
 808   transition(itos, dtos);
 809   // rax: index
 810   // rdx: array
 811   index_check(rdx, rax); // kills rbx
 812   __ access_load_at(T_DOUBLE, IN_HEAP | IS_ARRAY, noreg /* dtos */,
 813                     Address(rdx, rax,
 814                             Address::times_8,
 815                             arrayOopDesc::base_offset_in_bytes(T_DOUBLE)),
 816                     noreg, noreg);
 817 }
 818 
 819 void TemplateTable::aaload() {
 820   transition(itos, atos);
 821   // rax: index
 822   // rdx: array
 823   index_check(rdx, rax); // kills rbx
 824   do_oop_load(_masm,
 825               Address(rdx, rax,
 826                       UseCompressedOops ? Address::times_4 : Address::times_ptr,
 827                       arrayOopDesc::base_offset_in_bytes(T_OBJECT)),
 828               rax,
 829               IS_ARRAY);


















 830 }
 831 
 832 void TemplateTable::baload() {
 833   transition(itos, itos);
 834   // rax: index
 835   // rdx: array
 836   index_check(rdx, rax); // kills rbx
 837   __ access_load_at(T_BYTE, IN_HEAP | IS_ARRAY, rax,
 838                     Address(rdx, rax, Address::times_1, arrayOopDesc::base_offset_in_bytes(T_BYTE)),
 839                     noreg, noreg);
 840 }
 841 
 842 void TemplateTable::caload() {
 843   transition(itos, itos);
 844   // rax: index
 845   // rdx: array
 846   index_check(rdx, rax); // kills rbx
 847   __ access_load_at(T_CHAR, IN_HEAP | IS_ARRAY, rax,
 848                     Address(rdx, rax, Address::times_2, arrayOopDesc::base_offset_in_bytes(T_CHAR)),
 849                     noreg, noreg);

1095   __ access_store_at(T_FLOAT, IN_HEAP | IS_ARRAY,
1096                      Address(rdx, rbx, Address::times_4,
1097                              arrayOopDesc::base_offset_in_bytes(T_FLOAT)),
1098                      noreg /* ftos */, noreg, noreg);
1099 }
1100 
1101 void TemplateTable::dastore() {
1102   transition(dtos, vtos);
1103   __ pop_i(rbx);
1104   // value is in UseSSE >= 2 ? xmm0 : ST(0)
1105   // rbx:  index
1106   // rdx:  array
1107   index_check(rdx, rbx); // prefer index in rbx
1108   __ access_store_at(T_DOUBLE, IN_HEAP | IS_ARRAY,
1109                      Address(rdx, rbx, Address::times_8,
1110                              arrayOopDesc::base_offset_in_bytes(T_DOUBLE)),
1111                      noreg /* dtos */, noreg, noreg);
1112 }
1113 
1114 void TemplateTable::aastore() {
1115   Label is_null, ok_is_subtype, done;
1116   transition(vtos, vtos);
1117   // stack: ..., array, index, value
1118   __ movptr(rax, at_tos());    // value
1119   __ movl(rcx, at_tos_p1()); // index
1120   __ movptr(rdx, at_tos_p2()); // array
1121 
1122   Address element_address(rdx, rcx,
1123                           UseCompressedOops? Address::times_4 : Address::times_ptr,
1124                           arrayOopDesc::base_offset_in_bytes(T_OBJECT));
1125 
1126   index_check_without_pop(rdx, rcx);     // kills rbx




1127   __ testptr(rax, rax);
1128   __ jcc(Assembler::zero, is_null);
1129 

1130   Register tmp_load_klass = LP64_ONLY(rscratch1) NOT_LP64(noreg);






1131   // Move subklass into rbx
1132   __ load_klass(rbx, rax, tmp_load_klass);
1133   // Move superklass into rax
1134   __ load_klass(rax, rdx, tmp_load_klass);
1135   __ movptr(rax, Address(rax,
1136                          ObjArrayKlass::element_klass_offset()));
1137 
1138   // Generate subtype check.  Blows rcx, rdi
1139   // Superklass in rax.  Subklass in rbx.
1140   __ gen_subtype_check(rbx, ok_is_subtype);

1141 
1142   // Come here on failure
1143   // object is at TOS
1144   __ jump(ExternalAddress(Interpreter::_throw_ArrayStoreException_entry));
1145 
1146   // Come here on success
1147   __ bind(ok_is_subtype);
1148 
1149   // Get the value we will store
1150   __ movptr(rax, at_tos());
1151   __ movl(rcx, at_tos_p1()); // index
1152   // Now store using the appropriate barrier
1153   do_oop_store(_masm, element_address, rax, IS_ARRAY);
1154   __ jmp(done);
1155 
1156   // Have a NULL in rax, rdx=array, ecx=index.  Store NULL at ary[idx]
1157   __ bind(is_null);
1158   __ profile_null_seen(rbx);





1159 





1160   // Store a NULL
1161   do_oop_store(_masm, element_address, noreg, IS_ARRAY);
















1162 


















1163   // Pop stack arguments
1164   __ bind(done);
1165   __ addptr(rsp, 3 * Interpreter::stackElementSize);
1166 }
1167 
1168 void TemplateTable::bastore() {
1169   transition(itos, vtos);
1170   __ pop_i(rbx);
1171   // rax: value
1172   // rbx: index
1173   // rdx: array
1174   index_check(rdx, rbx); // prefer index in rbx
1175   // Need to check whether array is boolean or byte
1176   // since both types share the bastore bytecode.
1177   Register tmp_load_klass = LP64_ONLY(rscratch1) NOT_LP64(noreg);
1178   __ load_klass(rcx, rdx, tmp_load_klass);
1179   __ movl(rcx, Address(rcx, Klass::layout_helper_offset()));
1180   int diffbit = Klass::layout_helper_boolean_diffbit();
1181   __ testl(rcx, diffbit);
1182   Label L_skip;

2313   __ jcc(j_not(cc), not_taken);
2314   branch(false, false);
2315   __ bind(not_taken);
2316   __ profile_not_taken_branch(rax);
2317 }
2318 
2319 void TemplateTable::if_nullcmp(Condition cc) {
2320   transition(atos, vtos);
2321   // assume branch is more often taken than not (loops use backward branches)
2322   Label not_taken;
2323   __ testptr(rax, rax);
2324   __ jcc(j_not(cc), not_taken);
2325   branch(false, false);
2326   __ bind(not_taken);
2327   __ profile_not_taken_branch(rax);
2328 }
2329 
2330 void TemplateTable::if_acmp(Condition cc) {
2331   transition(atos, vtos);
2332   // assume branch is more often taken than not (loops use backward branches)
2333   Label not_taken;
2334   __ pop_ptr(rdx);




































2335   __ cmpoop(rdx, rax);
2336   __ jcc(j_not(cc), not_taken);

2337   branch(false, false);
2338   __ bind(not_taken);
2339   __ profile_not_taken_branch(rax);









2340 }
2341 
2342 void TemplateTable::ret() {
2343   transition(vtos, vtos);
2344   locals_index(rbx);
2345   LP64_ONLY(__ movslq(rbx, iaddress(rbx))); // get return bci, compute return bcp
2346   NOT_LP64(__ movptr(rbx, iaddress(rbx)));
2347   __ profile_ret(rbx, rcx);
2348   __ get_method(rax);
2349   __ movptr(rbcp, Address(rax, Method::const_offset()));
2350   __ lea(rbcp, Address(rbcp, rbx, Address::times_1,
2351                       ConstMethod::codes_offset()));
2352   __ dispatch_next(vtos, 0, true);
2353 }
2354 
2355 void TemplateTable::wide_ret() {
2356   transition(vtos, vtos);
2357   locals_index_wide(rbx);
2358   __ movptr(rbx, aaddress(rbx)); // get return bci, compute return bcp
2359   __ profile_ret(rbx, rcx);

2588     __ testb(Address(r15_thread, JavaThread::polling_word_offset()), SafepointMechanism::poll_bit());
2589 #else
2590     const Register thread = rdi;
2591     __ get_thread(thread);
2592     __ testb(Address(thread, JavaThread::polling_word_offset()), SafepointMechanism::poll_bit());
2593 #endif
2594     __ jcc(Assembler::zero, no_safepoint);
2595     __ push(state);
2596     __ call_VM(noreg, CAST_FROM_FN_PTR(address,
2597                                        InterpreterRuntime::at_safepoint));
2598     __ pop(state);
2599     __ bind(no_safepoint);
2600   }
2601 
2602   // Narrow result if state is itos but result type is smaller.
2603   // Need to narrow in the return bytecode rather than in generate_return_entry
2604   // since compiled code callers expect the result to already be narrowed.
2605   if (state == itos) {
2606     __ narrow(rax);
2607   }
2608   __ remove_activation(state, rbcp);

2609 
2610   __ jmp(rbcp);
2611 }
2612 
2613 // ----------------------------------------------------------------------------
2614 // Volatile variables demand their effects be made known to all CPU's
2615 // in order.  Store buffers on most chips allow reads & writes to
2616 // reorder; the JMM's ReadAfterWrite.java test fails in -Xint mode
2617 // without some kind of memory barrier (i.e., it's not sufficient that
2618 // the interpreter does not reorder volatile references, the hardware
2619 // also must not reorder them).
2620 //
2621 // According to the new Java Memory Model (JMM):
2622 // (1) All volatiles are serialized wrt to each other.  ALSO reads &
2623 //     writes act as aquire & release, so:
2624 // (2) A read cannot let unrelated NON-volatile memory refs that
2625 //     happen after the read float up to before the read.  It's OK for
2626 //     non-volatile memory refs that happen before the volatile read to
2627 //     float down below it.
2628 // (3) Similar a volatile write cannot let unrelated NON-volatile

2786     __ get_cache_and_index_at_bcp(cache, index, 1);
2787     __ bind(L1);
2788   }
2789 }
2790 
2791 void TemplateTable::pop_and_check_object(Register r) {
2792   __ pop_ptr(r);
2793   __ null_check(r);  // for field access must check obj.
2794   __ verify_oop(r);
2795 }
2796 
2797 void TemplateTable::getfield_or_static(int byte_no, bool is_static, RewriteControl rc) {
2798   transition(vtos, vtos);
2799 
2800   const Register cache = rcx;
2801   const Register index = rdx;
2802   const Register obj   = LP64_ONLY(c_rarg3) NOT_LP64(rcx);
2803   const Register off   = rbx;
2804   const Register flags = rax;
2805   const Register bc    = LP64_ONLY(c_rarg3) NOT_LP64(rcx); // uses same reg as obj, so don't mix them

2806 
2807   resolve_cache_and_index(byte_no, cache, index, sizeof(u2));
2808   jvmti_post_field_access(cache, index, is_static, false);
2809   load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
2810 
2811   if (!is_static) pop_and_check_object(obj);
2812 
2813   const Address field(obj, off, Address::times_1, 0*wordSize);
2814 
2815   Label Done, notByte, notBool, notInt, notShort, notChar, notLong, notFloat, notObj;








2816 
2817   __ shrl(flags, ConstantPoolCacheEntry::tos_state_shift);
2818   // Make sure we don't need to mask edx after the above shift
2819   assert(btos == 0, "change code, btos != 0");
2820 
2821   __ andl(flags, ConstantPoolCacheEntry::tos_state_mask);
2822 
2823   __ jcc(Assembler::notZero, notByte);
2824   // btos

2825   __ access_load_at(T_BYTE, IN_HEAP, rax, field, noreg, noreg);
2826   __ push(btos);
2827   // Rewrite bytecode to be faster
2828   if (!is_static && rc == may_rewrite) {
2829     patch_bytecode(Bytecodes::_fast_bgetfield, bc, rbx);
2830   }
2831   __ jmp(Done);
2832 
2833   __ bind(notByte);

2834   __ cmpl(flags, ztos);
2835   __ jcc(Assembler::notEqual, notBool);
2836 
2837   // ztos (same code as btos)
2838   __ access_load_at(T_BOOLEAN, IN_HEAP, rax, field, noreg, noreg);
2839   __ push(ztos);
2840   // Rewrite bytecode to be faster
2841   if (!is_static && rc == may_rewrite) {
2842     // use btos rewriting, no truncating to t/f bit is needed for getfield.
2843     patch_bytecode(Bytecodes::_fast_bgetfield, bc, rbx);
2844   }
2845   __ jmp(Done);
2846 
2847   __ bind(notBool);
2848   __ cmpl(flags, atos);
2849   __ jcc(Assembler::notEqual, notObj);
2850   // atos
2851   do_oop_load(_masm, field, rax);
2852   __ push(atos);
2853   if (!is_static && rc == may_rewrite) {
2854     patch_bytecode(Bytecodes::_fast_agetfield, bc, rbx);




















































































2855   }
2856   __ jmp(Done);
2857 
2858   __ bind(notObj);



2859   __ cmpl(flags, itos);
2860   __ jcc(Assembler::notEqual, notInt);
2861   // itos
2862   __ access_load_at(T_INT, IN_HEAP, rax, field, noreg, noreg);
2863   __ push(itos);
2864   // Rewrite bytecode to be faster
2865   if (!is_static && rc == may_rewrite) {
2866     patch_bytecode(Bytecodes::_fast_igetfield, bc, rbx);
2867   }
2868   __ jmp(Done);
2869 
2870   __ bind(notInt);
2871   __ cmpl(flags, ctos);
2872   __ jcc(Assembler::notEqual, notChar);
2873   // ctos
2874   __ access_load_at(T_CHAR, IN_HEAP, rax, field, noreg, noreg);
2875   __ push(ctos);
2876   // Rewrite bytecode to be faster
2877   if (!is_static && rc == may_rewrite) {
2878     patch_bytecode(Bytecodes::_fast_cgetfield, bc, rbx);

2938 #endif
2939 
2940   __ bind(Done);
2941   // [jk] not needed currently
2942   // volatile_barrier(Assembler::Membar_mask_bits(Assembler::LoadLoad |
2943   //                                              Assembler::LoadStore));
2944 }
2945 
2946 void TemplateTable::getfield(int byte_no) {
2947   getfield_or_static(byte_no, false);
2948 }
2949 
2950 void TemplateTable::nofast_getfield(int byte_no) {
2951   getfield_or_static(byte_no, false, may_not_rewrite);
2952 }
2953 
2954 void TemplateTable::getstatic(int byte_no) {
2955   getfield_or_static(byte_no, true);
2956 }
2957 






















2958 
2959 // The registers cache and index expected to be set before call.
2960 // The function may destroy various registers, just not the cache and index registers.
2961 void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
2962 
2963   const Register robj = LP64_ONLY(c_rarg2)   NOT_LP64(rax);
2964   const Register RBX  = LP64_ONLY(c_rarg1)   NOT_LP64(rbx);
2965   const Register RCX  = LP64_ONLY(c_rarg3)   NOT_LP64(rcx);
2966   const Register RDX  = LP64_ONLY(rscratch1) NOT_LP64(rdx);
2967 
2968   ByteSize cp_base_offset = ConstantPoolCache::base_offset();
2969 
2970   if (JvmtiExport::can_post_field_modification()) {
2971     // Check to see if a field modification watch has been set before
2972     // we take the time to call into the VM.
2973     Label L1;
2974     assert_different_registers(cache, index, rax);
2975     __ mov32(rax, ExternalAddress((address)JvmtiExport::get_field_modification_count_addr()));
2976     __ testl(rax, rax);
2977     __ jcc(Assembler::zero, L1);

3033     // c_rarg1: object pointer set up above (NULL if static)
3034     // c_rarg2: cache entry pointer
3035     // c_rarg3: jvalue object on the stack
3036     __ call_VM(noreg,
3037                CAST_FROM_FN_PTR(address,
3038                                 InterpreterRuntime::post_field_modification),
3039                RBX, robj, RCX);
3040     __ get_cache_and_index_at_bcp(cache, index, 1);
3041     __ bind(L1);
3042   }
3043 }
3044 
3045 void TemplateTable::putfield_or_static(int byte_no, bool is_static, RewriteControl rc) {
3046   transition(vtos, vtos);
3047 
3048   const Register cache = rcx;
3049   const Register index = rdx;
3050   const Register obj   = rcx;
3051   const Register off   = rbx;
3052   const Register flags = rax;

3053 
3054   resolve_cache_and_index(byte_no, cache, index, sizeof(u2));
3055   jvmti_post_field_mod(cache, index, is_static);
3056   load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
3057 
3058   // [jk] not needed currently
3059   // volatile_barrier(Assembler::Membar_mask_bits(Assembler::LoadStore |
3060   //                                              Assembler::StoreStore));
3061 
3062   Label notVolatile, Done;
3063   __ movl(rdx, flags);
3064   __ shrl(rdx, ConstantPoolCacheEntry::is_volatile_shift);
3065   __ andl(rdx, 0x1);
3066 
3067   // Check for volatile store
3068   __ testl(rdx, rdx);

3069   __ jcc(Assembler::zero, notVolatile);
3070 
3071   putfield_or_static_helper(byte_no, is_static, rc, obj, off, flags);
3072   volatile_barrier(Assembler::Membar_mask_bits(Assembler::StoreLoad |
3073                                                Assembler::StoreStore));
3074   __ jmp(Done);
3075   __ bind(notVolatile);
3076 
3077   putfield_or_static_helper(byte_no, is_static, rc, obj, off, flags);
3078 
3079   __ bind(Done);
3080 }
3081 
3082 void TemplateTable::putfield_or_static_helper(int byte_no, bool is_static, RewriteControl rc,
3083                                               Register obj, Register off, Register flags) {
3084 
3085   // field addresses
3086   const Address field(obj, off, Address::times_1, 0*wordSize);
3087   NOT_LP64( const Address hi(obj, off, Address::times_1, 1*wordSize);)
3088 
3089   Label notByte, notBool, notInt, notShort, notChar,
3090         notLong, notFloat, notObj;
3091   Label Done;
3092 
3093   const Register bc    = LP64_ONLY(c_rarg3) NOT_LP64(rcx);
3094 
3095   __ shrl(flags, ConstantPoolCacheEntry::tos_state_shift);
3096 
3097   assert(btos == 0, "change code, btos != 0");
3098   __ andl(flags, ConstantPoolCacheEntry::tos_state_mask);
3099   __ jcc(Assembler::notZero, notByte);
3100 
3101   // btos
3102   {
3103     __ pop(btos);
3104     if (!is_static) pop_and_check_object(obj);
3105     __ access_store_at(T_BYTE, IN_HEAP, field, rax, noreg, noreg);
3106     if (!is_static && rc == may_rewrite) {
3107       patch_bytecode(Bytecodes::_fast_bputfield, bc, rbx, true, byte_no);
3108     }
3109     __ jmp(Done);
3110   }

3113   __ cmpl(flags, ztos);
3114   __ jcc(Assembler::notEqual, notBool);
3115 
3116   // ztos
3117   {
3118     __ pop(ztos);
3119     if (!is_static) pop_and_check_object(obj);
3120     __ access_store_at(T_BOOLEAN, IN_HEAP, field, rax, noreg, noreg);
3121     if (!is_static && rc == may_rewrite) {
3122       patch_bytecode(Bytecodes::_fast_zputfield, bc, rbx, true, byte_no);
3123     }
3124     __ jmp(Done);
3125   }
3126 
3127   __ bind(notBool);
3128   __ cmpl(flags, atos);
3129   __ jcc(Assembler::notEqual, notObj);
3130 
3131   // atos
3132   {
3133     __ pop(atos);
3134     if (!is_static) pop_and_check_object(obj);
3135     // Store into the field
3136     do_oop_store(_masm, field, rax);
3137     if (!is_static && rc == may_rewrite) {
3138       patch_bytecode(Bytecodes::_fast_aputfield, bc, rbx, true, byte_no);





















































3139     }
3140     __ jmp(Done);
3141   }
3142 
3143   __ bind(notObj);
3144   __ cmpl(flags, itos);
3145   __ jcc(Assembler::notEqual, notInt);
3146 
3147   // itos
3148   {
3149     __ pop(itos);
3150     if (!is_static) pop_and_check_object(obj);
3151     __ access_store_at(T_INT, IN_HEAP, field, rax, noreg, noreg);
3152     if (!is_static && rc == may_rewrite) {
3153       patch_bytecode(Bytecodes::_fast_iputfield, bc, rbx, true, byte_no);
3154     }
3155     __ jmp(Done);
3156   }
3157 
3158   __ bind(notInt);
3159   __ cmpl(flags, ctos);
3160   __ jcc(Assembler::notEqual, notChar);

3259 }
3260 
3261 void TemplateTable::jvmti_post_fast_field_mod() {
3262 
3263   const Register scratch = LP64_ONLY(c_rarg3) NOT_LP64(rcx);
3264 
3265   if (JvmtiExport::can_post_field_modification()) {
3266     // Check to see if a field modification watch has been set before
3267     // we take the time to call into the VM.
3268     Label L2;
3269     __ mov32(scratch, ExternalAddress((address)JvmtiExport::get_field_modification_count_addr()));
3270     __ testl(scratch, scratch);
3271     __ jcc(Assembler::zero, L2);
3272     __ pop_ptr(rbx);                  // copy the object pointer from tos
3273     __ verify_oop(rbx);
3274     __ push_ptr(rbx);                 // put the object pointer back on tos
3275     // Save tos values before call_VM() clobbers them. Since we have
3276     // to do it for every data type, we use the saved values as the
3277     // jvalue object.
3278     switch (bytecode()) {          // load values into the jvalue object

3279     case Bytecodes::_fast_aputfield: __ push_ptr(rax); break;
3280     case Bytecodes::_fast_bputfield: // fall through
3281     case Bytecodes::_fast_zputfield: // fall through
3282     case Bytecodes::_fast_sputfield: // fall through
3283     case Bytecodes::_fast_cputfield: // fall through
3284     case Bytecodes::_fast_iputfield: __ push_i(rax); break;
3285     case Bytecodes::_fast_dputfield: __ push(dtos); break;
3286     case Bytecodes::_fast_fputfield: __ push(ftos); break;
3287     case Bytecodes::_fast_lputfield: __ push_l(rax); break;
3288 
3289     default:
3290       ShouldNotReachHere();
3291     }
3292     __ mov(scratch, rsp);             // points to jvalue on the stack
3293     // access constant pool cache entry
3294     LP64_ONLY(__ get_cache_entry_pointer_at_bcp(c_rarg2, rax, 1));
3295     NOT_LP64(__ get_cache_entry_pointer_at_bcp(rax, rdx, 1));
3296     __ verify_oop(rbx);
3297     // rbx: object pointer copied above
3298     // c_rarg2: cache entry pointer
3299     // c_rarg3: jvalue object on the stack
3300     LP64_ONLY(__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification), rbx, c_rarg2, c_rarg3));
3301     NOT_LP64(__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification), rbx, rax, rcx));
3302 
3303     switch (bytecode()) {             // restore tos values

3304     case Bytecodes::_fast_aputfield: __ pop_ptr(rax); break;
3305     case Bytecodes::_fast_bputfield: // fall through
3306     case Bytecodes::_fast_zputfield: // fall through
3307     case Bytecodes::_fast_sputfield: // fall through
3308     case Bytecodes::_fast_cputfield: // fall through
3309     case Bytecodes::_fast_iputfield: __ pop_i(rax); break;
3310     case Bytecodes::_fast_dputfield: __ pop(dtos); break;
3311     case Bytecodes::_fast_fputfield: __ pop(ftos); break;
3312     case Bytecodes::_fast_lputfield: __ pop_l(rax); break;
3313     default: break;
3314     }
3315     __ bind(L2);
3316   }
3317 }
3318 
3319 void TemplateTable::fast_storefield(TosState state) {
3320   transition(state, vtos);
3321 
3322   ByteSize base = ConstantPoolCache::base_offset();
3323 
3324   jvmti_post_fast_field_mod();
3325 
3326   // access constant pool cache
3327   __ get_cache_and_index_at_bcp(rcx, rbx, 1);
3328 
3329   // test for volatile with rdx but rdx is tos register for lputfield.
3330   __ movl(rdx, Address(rcx, rbx, Address::times_ptr,
3331                        in_bytes(base +
3332                                 ConstantPoolCacheEntry::flags_offset())));
3333 
3334   // replace index with field offset from cache entry
3335   __ movptr(rbx, Address(rcx, rbx, Address::times_ptr,
3336                          in_bytes(base + ConstantPoolCacheEntry::f2_offset())));
3337 
3338   // [jk] not needed currently
3339   // volatile_barrier(Assembler::Membar_mask_bits(Assembler::LoadStore |
3340   //                                              Assembler::StoreStore));
3341 
3342   Label notVolatile, Done;




3343   __ shrl(rdx, ConstantPoolCacheEntry::is_volatile_shift);
3344   __ andl(rdx, 0x1);
3345 
3346   // Get object from stack
3347   pop_and_check_object(rcx);
3348 
3349   // field address
3350   const Address field(rcx, rbx, Address::times_1);
3351 
3352   // Check for volatile store
3353   __ testl(rdx, rdx);
3354   __ jcc(Assembler::zero, notVolatile);
3355 
3356   fast_storefield_helper(field, rax);



3357   volatile_barrier(Assembler::Membar_mask_bits(Assembler::StoreLoad |
3358                                                Assembler::StoreStore));
3359   __ jmp(Done);
3360   __ bind(notVolatile);
3361 
3362   fast_storefield_helper(field, rax);



3363 
3364   __ bind(Done);
3365 }
3366 
3367 void TemplateTable::fast_storefield_helper(Address field, Register rax) {
3368 
3369   // access field
3370   switch (bytecode()) {

















3371   case Bytecodes::_fast_aputfield:
3372     do_oop_store(_masm, field, rax);


3373     break;
3374   case Bytecodes::_fast_lputfield:
3375 #ifdef _LP64
3376     __ access_store_at(T_LONG, IN_HEAP, field, noreg /* ltos */, noreg, noreg);
3377 #else
3378   __ stop("should not be rewritten");
3379 #endif
3380     break;
3381   case Bytecodes::_fast_iputfield:
3382     __ access_store_at(T_INT, IN_HEAP, field, rax, noreg, noreg);
3383     break;
3384   case Bytecodes::_fast_zputfield:
3385     __ access_store_at(T_BOOLEAN, IN_HEAP, field, rax, noreg, noreg);
3386     break;
3387   case Bytecodes::_fast_bputfield:
3388     __ access_store_at(T_BYTE, IN_HEAP, field, rax, noreg, noreg);
3389     break;
3390   case Bytecodes::_fast_sputfield:
3391     __ access_store_at(T_SHORT, IN_HEAP, field, rax, noreg, noreg);
3392     break;

3422     __ push_ptr(rax);  // save object pointer before call_VM() clobbers it
3423     LP64_ONLY(__ mov(c_rarg1, rax));
3424     // c_rarg1: object pointer copied above
3425     // c_rarg2: cache entry pointer
3426     LP64_ONLY(__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access), c_rarg1, c_rarg2));
3427     NOT_LP64(__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access), rax, rcx));
3428     __ pop_ptr(rax); // restore object pointer
3429     __ bind(L1);
3430   }
3431 
3432   // access constant pool cache
3433   __ get_cache_and_index_at_bcp(rcx, rbx, 1);
3434   // replace index with field offset from cache entry
3435   // [jk] not needed currently
3436   // __ movl(rdx, Address(rcx, rbx, Address::times_8,
3437   //                      in_bytes(ConstantPoolCache::base_offset() +
3438   //                               ConstantPoolCacheEntry::flags_offset())));
3439   // __ shrl(rdx, ConstantPoolCacheEntry::is_volatile_shift);
3440   // __ andl(rdx, 0x1);
3441   //
3442   __ movptr(rbx, Address(rcx, rbx, Address::times_ptr,
3443                          in_bytes(ConstantPoolCache::base_offset() +
3444                                   ConstantPoolCacheEntry::f2_offset())));
3445 
3446   // rax: object
3447   __ verify_oop(rax);
3448   __ null_check(rax);
3449   Address field(rax, rbx, Address::times_1);
3450 
3451   // access field
3452   switch (bytecode()) {







































3453   case Bytecodes::_fast_agetfield:
3454     do_oop_load(_masm, field, rax);
3455     __ verify_oop(rax);
3456     break;
3457   case Bytecodes::_fast_lgetfield:
3458 #ifdef _LP64
3459     __ access_load_at(T_LONG, IN_HEAP, noreg /* ltos */, field, noreg, noreg);
3460 #else
3461   __ stop("should not be rewritten");
3462 #endif
3463     break;
3464   case Bytecodes::_fast_igetfield:
3465     __ access_load_at(T_INT, IN_HEAP, rax, field, noreg, noreg);
3466     break;
3467   case Bytecodes::_fast_bgetfield:
3468     __ access_load_at(T_BYTE, IN_HEAP, rax, field, noreg, noreg);
3469     break;
3470   case Bytecodes::_fast_sgetfield:
3471     __ access_load_at(T_SHORT, IN_HEAP, rax, field, noreg, noreg);
3472     break;

3901 
3902   // Note:  rax_callsite is already pushed by prepare_invoke
3903 
3904   // %%% should make a type profile for any invokedynamic that takes a ref argument
3905   // profile this call
3906   __ profile_call(rbcp);
3907   __ profile_arguments_type(rdx, rbx_method, rbcp, false);
3908 
3909   __ verify_oop(rax_callsite);
3910 
3911   __ jump_from_interpreted(rbx_method, rdx);
3912 }
3913 
3914 //-----------------------------------------------------------------------------
3915 // Allocation
3916 
3917 void TemplateTable::_new() {
3918   transition(vtos, atos);
3919   __ get_unsigned_2_byte_index_at_bcp(rdx, 1);
3920   Label slow_case;
3921   Label slow_case_no_pop;
3922   Label done;
3923   Label initialize_header;
3924   Label initialize_object;  // including clearing the fields
3925 
3926   __ get_cpool_and_tags(rcx, rax);
3927 
3928   // Make sure the class we're about to instantiate has been resolved.
3929   // This is done before loading InstanceKlass to be consistent with the order
3930   // how Constant Pool is updated (see ConstantPool::klass_at_put)
3931   const int tags_offset = Array<u1>::base_offset_in_bytes();
3932   __ cmpb(Address(rax, rdx, Address::times_1, tags_offset), JVM_CONSTANT_Class);
3933   __ jcc(Assembler::notEqual, slow_case_no_pop);
3934 
3935   // get InstanceKlass
3936   __ load_resolved_klass_at_index(rcx, rcx, rdx);
3937   __ push(rcx);  // save the contexts of klass for initializing the header






3938 
3939   // make sure klass is initialized & doesn't have finalizer
3940   // make sure klass is fully initialized
3941   __ cmpb(Address(rcx, InstanceKlass::init_state_offset()), InstanceKlass::fully_initialized);
3942   __ jcc(Assembler::notEqual, slow_case);
3943 
3944   // get instance_size in InstanceKlass (scaled to a count of bytes)
3945   __ movl(rdx, Address(rcx, Klass::layout_helper_offset()));
3946   // test to see if it has a finalizer or is malformed in some way
3947   __ testl(rdx, Klass::_lh_instance_slow_path_bit);
3948   __ jcc(Assembler::notZero, slow_case);
3949 
3950   // Allocate the instance:
3951   //  If TLAB is enabled:
3952   //    Try to allocate in the TLAB.
3953   //    If fails, go to the slow path.
3954   //  Else If inline contiguous allocations are enabled:
3955   //    Try to allocate in eden.
3956   //    If fails due to heap end, go to slow path.
3957   //
3958   //  If TLAB is enabled OR inline contiguous is enabled:
3959   //    Initialize the allocation.
3960   //    Exit.
3961   //
3962   //  Go to slow path.
3963 
3964   const bool allow_shared_alloc =
3965     Universe::heap()->supports_inline_contig_alloc();
3966 
3967   const Register thread = LP64_ONLY(r15_thread) NOT_LP64(rcx);
3968 #ifndef _LP64
3969   if (UseTLAB || allow_shared_alloc) {
3970     __ get_thread(thread);
3971   }
3972 #endif // _LP64
3973 
3974   if (UseTLAB) {
3975     __ tlab_allocate(thread, rax, rdx, 0, rcx, rbx, slow_case);
3976     if (ZeroTLAB) {
3977       // the fields have been already cleared
3978       __ jmp(initialize_header);
3979     } else {
3980       // initialize both the header and fields
3981       __ jmp(initialize_object);
3982     }
3983   } else {
3984     // Allocation in the shared Eden, if allowed.
3985     //
3986     // rdx: instance size in bytes
3987     __ eden_allocate(thread, rax, rdx, 0, rbx, slow_case);
3988   }
3989 
3990   // If UseTLAB or allow_shared_alloc are true, the object is created above and
3991   // there is an initialize need. Otherwise, skip and go to the slow path.
3992   if (UseTLAB || allow_shared_alloc) {
3993     // The object is initialized before the header.  If the object size is
3994     // zero, go directly to the header initialization.
3995     __ bind(initialize_object);
3996     __ decrement(rdx, sizeof(oopDesc));
3997     __ jcc(Assembler::zero, initialize_header);
3998 
3999     // Initialize topmost object field, divide rdx by 8, check if odd and
4000     // test if zero.
4001     __ xorl(rcx, rcx);    // use zero reg to clear memory (shorter code)
4002     __ shrl(rdx, LogBytesPerLong); // divide by 2*oopSize and set carry flag if odd
4003 
4004     // rdx must have been multiple of 8
4005 #ifdef ASSERT
4006     // make sure rdx was multiple of 8
4007     Label L;
4008     // Ignore partial flag stall after shrl() since it is debug VM
4009     __ jcc(Assembler::carryClear, L);
4010     __ stop("object size is not multiple of 2 - adjust this code");
4011     __ bind(L);
4012     // rdx must be > 0, no extra check needed here
4013 #endif
4014 
4015     // initialize remaining object fields: rdx was a multiple of 8
4016     { Label loop;
4017     __ bind(loop);
4018     __ movptr(Address(rax, rdx, Address::times_8, sizeof(oopDesc) - 1*oopSize), rcx);
4019     NOT_LP64(__ movptr(Address(rax, rdx, Address::times_8, sizeof(oopDesc) - 2*oopSize), rcx));
4020     __ decrement(rdx);
4021     __ jcc(Assembler::notZero, loop);
4022     }
4023 
4024     // initialize object header only.
4025     __ bind(initialize_header);
4026     __ movptr(Address(rax, oopDesc::mark_offset_in_bytes()),
4027               (intptr_t)markWord::prototype().value()); // header
4028     __ pop(rcx);   // get saved klass back in the register.
4029 #ifdef _LP64
4030     __ xorl(rsi, rsi); // use zero reg to clear memory (shorter code)
4031     __ store_klass_gap(rax, rsi);  // zero klass gap for compressed oops
4032 #endif
4033     Register tmp_store_klass = LP64_ONLY(rscratch1) NOT_LP64(noreg);
4034     __ store_klass(rax, rcx, tmp_store_klass);  // klass
4035 
4036     {
4037       SkipIfEqual skip_if(_masm, &DTraceAllocProbes, 0);
4038       // Trigger dtrace event for fastpath
4039       __ push(atos);
4040       __ call_VM_leaf(
4041            CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_object_alloc), rax);
4042       __ pop(atos);
4043     }
4044 
4045     __ jmp(done);
4046   }























4047 
4048   // slow case
4049   __ bind(slow_case);
4050   __ pop(rcx);   // restore stack pointer to what it was when we came in.
4051   __ bind(slow_case_no_pop);
4052 
4053   Register rarg1 = LP64_ONLY(c_rarg1) NOT_LP64(rax);
4054   Register rarg2 = LP64_ONLY(c_rarg2) NOT_LP64(rdx);
4055 
4056   __ get_constant_pool(rarg1);
4057   __ get_unsigned_2_byte_index_at_bcp(rarg2, 1);
4058   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), rarg1, rarg2);
4059    __ verify_oop(rax);


4060 
4061   // continue
4062   __ bind(done);

4063 }
4064 
4065 void TemplateTable::newarray() {
4066   transition(itos, atos);
4067   Register rarg1 = LP64_ONLY(c_rarg1) NOT_LP64(rdx);
4068   __ load_unsigned_byte(rarg1, at_bcp(1));
4069   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::newarray),
4070           rarg1, rax);
4071 }
4072 
4073 void TemplateTable::anewarray() {
4074   transition(itos, atos);
4075 
4076   Register rarg1 = LP64_ONLY(c_rarg1) NOT_LP64(rcx);
4077   Register rarg2 = LP64_ONLY(c_rarg2) NOT_LP64(rdx);
4078 
4079   __ get_unsigned_2_byte_index_at_bcp(rarg2, 1);
4080   __ get_constant_pool(rarg1);
4081   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::anewarray),
4082           rarg1, rarg2, rax);
4083 }
4084 
4085 void TemplateTable::arraylength() {
4086   transition(atos, itos);
4087   __ null_check(rax, arrayOopDesc::length_offset_in_bytes());
4088   __ movl(rax, Address(rax, arrayOopDesc::length_offset_in_bytes()));
4089 }
4090 
4091 void TemplateTable::checkcast() {
4092   transition(atos, atos);
4093   Label done, is_null, ok_is_subtype, quicked, resolved;
4094   __ testptr(rax, rax); // object is in rax
4095   __ jcc(Assembler::zero, is_null);
4096 
4097   // Get cpool & tags index
4098   __ get_cpool_and_tags(rcx, rdx); // rcx=cpool, rdx=tags array
4099   __ get_unsigned_2_byte_index_at_bcp(rbx, 1); // rbx=index
4100   // See if bytecode has already been quicked
4101   __ cmpb(Address(rdx, rbx,
4102                   Address::times_1,
4103                   Array<u1>::base_offset_in_bytes()),
4104           JVM_CONSTANT_Class);

4105   __ jcc(Assembler::equal, quicked);
4106   __ push(atos); // save receiver for result, and for GC
4107   call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc));
4108 
4109   // vm_result_2 has metadata result
4110 #ifndef _LP64
4111   // borrow rdi from locals
4112   __ get_thread(rdi);
4113   __ get_vm_result_2(rax, rdi);
4114   __ restore_locals();
4115 #else
4116   __ get_vm_result_2(rax, r15_thread);
4117 #endif
4118 
4119   __ pop_ptr(rdx); // restore receiver
4120   __ jmpb(resolved);
4121 
4122   // Get superklass in rax and subklass in rbx
4123   __ bind(quicked);
4124   __ mov(rdx, rax); // Save object in rdx; rax needed for subtype check
4125   __ load_resolved_klass_at_index(rax, rcx, rbx);
4126 
4127   __ bind(resolved);
4128   Register tmp_load_klass = LP64_ONLY(rscratch1) NOT_LP64(noreg);
4129   __ load_klass(rbx, rdx, tmp_load_klass);
4130 
4131   // Generate subtype check.  Blows rcx, rdi.  Object in rdx.
4132   // Superklass in rax.  Subklass in rbx.
4133   __ gen_subtype_check(rbx, ok_is_subtype);
4134 
4135   // Come here on failure
4136   __ push_ptr(rdx);
4137   // object is at TOS
4138   __ jump(ExternalAddress(Interpreter::_throw_ClassCastException_entry));
4139 
4140   // Come here on success
4141   __ bind(ok_is_subtype);
4142   __ mov(rax, rdx); // Restore object in rdx



4143 
4144   // Collect counts on whether this check-cast sees NULLs a lot or not.
4145   if (ProfileInterpreter) {
4146     __ jmp(done);
4147     __ bind(is_null);
4148     __ profile_null_seen(rcx);
4149   } else {
4150     __ bind(is_null);   // same as 'done'
4151   }















4152   __ bind(done);
4153 }
4154 
4155 void TemplateTable::instanceof() {
4156   transition(atos, itos);
4157   Label done, is_null, ok_is_subtype, quicked, resolved;
4158   __ testptr(rax, rax);
4159   __ jcc(Assembler::zero, is_null);
4160 
4161   // Get cpool & tags index
4162   __ get_cpool_and_tags(rcx, rdx); // rcx=cpool, rdx=tags array
4163   __ get_unsigned_2_byte_index_at_bcp(rbx, 1); // rbx=index
4164   // See if bytecode has already been quicked
4165   __ cmpb(Address(rdx, rbx,
4166                   Address::times_1,
4167                   Array<u1>::base_offset_in_bytes()),
4168           JVM_CONSTANT_Class);

4169   __ jcc(Assembler::equal, quicked);
4170 
4171   __ push(atos); // save receiver for result, and for GC
4172   call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc));
4173   // vm_result_2 has metadata result
4174 
4175 #ifndef _LP64
4176   // borrow rdi from locals
4177   __ get_thread(rdi);
4178   __ get_vm_result_2(rax, rdi);
4179   __ restore_locals();
4180 #else
4181   __ get_vm_result_2(rax, r15_thread);
4182 #endif
4183 
4184   __ pop_ptr(rdx); // restore receiver
4185   __ verify_oop(rdx);
4186   Register tmp_load_klass = LP64_ONLY(rscratch1) NOT_LP64(noreg);
4187   __ load_klass(rdx, rdx, tmp_load_klass);
4188   __ jmpb(resolved);

4201   // Come here on failure
4202   __ xorl(rax, rax);
4203   __ jmpb(done);
4204   // Come here on success
4205   __ bind(ok_is_subtype);
4206   __ movl(rax, 1);
4207 
4208   // Collect counts on whether this test sees NULLs a lot or not.
4209   if (ProfileInterpreter) {
4210     __ jmp(done);
4211     __ bind(is_null);
4212     __ profile_null_seen(rcx);
4213   } else {
4214     __ bind(is_null);   // same as 'done'
4215   }
4216   __ bind(done);
4217   // rax = 0: obj == NULL or  obj is not an instanceof the specified klass
4218   // rax = 1: obj != NULL and obj is     an instanceof the specified klass
4219 }
4220 
4221 
4222 //----------------------------------------------------------------------------------------------------
4223 // Breakpoints
4224 void TemplateTable::_breakpoint() {
4225   // Note: We get here even if we are single stepping..
4226   // jbug insists on setting breakpoints at every bytecode
4227   // even if we are in single step mode.
4228 
4229   transition(vtos, vtos);
4230 
4231   Register rarg = LP64_ONLY(c_rarg1) NOT_LP64(rcx);
4232 
4233   // get the unpatched byte code
4234   __ get_method(rarg);
4235   __ call_VM(noreg,
4236              CAST_FROM_FN_PTR(address,
4237                               InterpreterRuntime::get_original_bytecode_at),
4238              rarg, rbcp);
4239   __ mov(rbx, rax);  // why?
4240 
4241   // post the breakpoint event

4263 // Note: monitorenter & exit are symmetric routines; which is reflected
4264 //       in the assembly code structure as well
4265 //
4266 // Stack layout:
4267 //
4268 // [expressions  ] <--- rsp               = expression stack top
4269 // ..
4270 // [expressions  ]
4271 // [monitor entry] <--- monitor block top = expression stack bot
4272 // ..
4273 // [monitor entry]
4274 // [frame data   ] <--- monitor block bot
4275 // ...
4276 // [saved rbp    ] <--- rbp
4277 void TemplateTable::monitorenter() {
4278   transition(atos, vtos);
4279 
4280   // check for NULL object
4281   __ null_check(rax);
4282 




4283   const Address monitor_block_top(
4284         rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
4285   const Address monitor_block_bot(
4286         rbp, frame::interpreter_frame_initial_sp_offset * wordSize);
4287   const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
4288 
4289   Label allocated;
4290 
4291   Register rtop = LP64_ONLY(c_rarg3) NOT_LP64(rcx);
4292   Register rbot = LP64_ONLY(c_rarg2) NOT_LP64(rbx);
4293   Register rmon = LP64_ONLY(c_rarg1) NOT_LP64(rdx);
4294 
4295   // initialize entry pointer
4296   __ xorl(rmon, rmon); // points to free slot or NULL
4297 
4298   // find a free slot in the monitor block (result in rmon)
4299   {
4300     Label entry, loop, exit;
4301     __ movptr(rtop, monitor_block_top); // points to current entry,
4302                                         // starting with top-most entry

4352   // rmon: points to monitor entry
4353   __ bind(allocated);
4354 
4355   // Increment bcp to point to the next bytecode, so exception
4356   // handling for async. exceptions work correctly.
4357   // The object has already been poped from the stack, so the
4358   // expression stack looks correct.
4359   __ increment(rbcp);
4360 
4361   // store object
4362   __ movptr(Address(rmon, BasicObjectLock::obj_offset_in_bytes()), rax);
4363   __ lock_object(rmon);
4364 
4365   // check to make sure this monitor doesn't cause stack overflow after locking
4366   __ save_bcp();  // in case of exception
4367   __ generate_stack_overflow_check(0);
4368 
4369   // The bcp has already been incremented. Just need to dispatch to
4370   // next instruction.
4371   __ dispatch_next(vtos);





4372 }
4373 
4374 void TemplateTable::monitorexit() {
4375   transition(atos, vtos);
4376 
4377   // check for NULL object
4378   __ null_check(rax);
4379 











4380   const Address monitor_block_top(
4381         rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
4382   const Address monitor_block_bot(
4383         rbp, frame::interpreter_frame_initial_sp_offset * wordSize);
4384   const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
4385 
4386   Register rtop = LP64_ONLY(c_rarg1) NOT_LP64(rdx);
4387   Register rbot = LP64_ONLY(c_rarg2) NOT_LP64(rbx);
4388 
4389   Label found;
4390 
4391   // find matching slot
4392   {
4393     Label entry, loop;
4394     __ movptr(rtop, monitor_block_top); // points to current entry,
4395                                         // starting with top-most entry
4396     __ lea(rbot, monitor_block_bot);    // points to word before bottom
4397                                         // of monitor block
4398     __ jmpb(entry);
4399 

  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "asm/macroAssembler.hpp"
  27 #include "compiler/disassembler.hpp"
  28 #include "gc/shared/collectedHeap.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/methodData.hpp"
  36 #include "oops/objArrayKlass.hpp"
  37 #include "oops/oop.inline.hpp"
  38 #include "oops/inlineKlass.hpp"
  39 #include "prims/jvmtiExport.hpp"
  40 #include "prims/methodHandles.hpp"
  41 #include "runtime/frame.inline.hpp"
  42 #include "runtime/safepointMechanism.hpp"
  43 #include "runtime/sharedRuntime.hpp"
  44 #include "runtime/stubRoutines.hpp"
  45 #include "runtime/synchronizer.hpp"
  46 #include "utilities/macros.hpp"
  47 
  48 #define __ Disassembler::hook<InterpreterMacroAssembler>(__FILE__, __LINE__, _masm)->
  49 
  50 // Global Register Names
  51 static const Register rbcp     = LP64_ONLY(r13) NOT_LP64(rsi);
  52 static const Register rlocals  = LP64_ONLY(r14) NOT_LP64(rdi);
  53 
  54 // Address Computation: local variables
  55 static inline Address iaddress(int n) {
  56   return Address(rlocals, Interpreter::local_offset_in_bytes(n));
  57 }
  58 

 136   case TemplateTable::less_equal   : return Assembler::greater;
 137   case TemplateTable::greater      : return Assembler::lessEqual;
 138   case TemplateTable::greater_equal: return Assembler::less;
 139   }
 140   ShouldNotReachHere();
 141   return Assembler::zero;
 142 }
 143 
 144 
 145 
 146 // Miscelaneous helper routines
 147 // Store an oop (or NULL) at the address described by obj.
 148 // If val == noreg this means store a NULL
 149 
 150 
 151 static void do_oop_store(InterpreterMacroAssembler* _masm,
 152                          Address dst,
 153                          Register val,
 154                          DecoratorSet decorators = 0) {
 155   assert(val == noreg || val == rax, "parameter is just for looks");
 156   __ store_heap_oop(dst, val, rdx, rbx, noreg, decorators);
 157 }
 158 
 159 static void do_oop_load(InterpreterMacroAssembler* _masm,
 160                         Address src,
 161                         Register dst,
 162                         DecoratorSet decorators = 0) {
 163   __ load_heap_oop(dst, src, rdx, rbx, decorators);
 164 }
 165 
 166 Address TemplateTable::at_bcp(int offset) {
 167   assert(_desc->uses_bcp(), "inconsistent uses_bcp information");
 168   return Address(rbcp, offset);
 169 }
 170 
 171 
 172 void TemplateTable::patch_bytecode(Bytecodes::Code bc, Register bc_reg,
 173                                    Register temp_reg, bool load_bc_into_bc_reg/*=true*/,
 174                                    int byte_no) {
 175   if (!RewriteBytecodes)  return;
 176   Label L_patch_done;
 177 
 178   switch (bc) {
 179   case Bytecodes::_fast_qputfield:
 180   case Bytecodes::_fast_aputfield:
 181   case Bytecodes::_fast_bputfield:
 182   case Bytecodes::_fast_zputfield:
 183   case Bytecodes::_fast_cputfield:
 184   case Bytecodes::_fast_dputfield:
 185   case Bytecodes::_fast_fputfield:
 186   case Bytecodes::_fast_iputfield:
 187   case Bytecodes::_fast_lputfield:
 188   case Bytecodes::_fast_sputfield:
 189     {
 190       // We skip bytecode quickening for putfield instructions when
 191       // the put_code written to the constant pool cache is zero.
 192       // This is required so that every execution of this instruction
 193       // calls out to InterpreterRuntime::resolve_get_put to do
 194       // additional, required work.
 195       assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
 196       assert(load_bc_into_bc_reg, "we use bc_reg as temp");
 197       __ get_cache_and_index_and_bytecode_at_bcp(temp_reg, bc_reg, temp_reg, byte_no, 1);
 198       __ movl(bc_reg, bc);
 199       __ cmpl(temp_reg, (int) 0);

 352   __ sarl(rax, 16);
 353 }
 354 
 355 void TemplateTable::ldc(bool wide) {
 356   transition(vtos, vtos);
 357   Register rarg = NOT_LP64(rcx) LP64_ONLY(c_rarg1);
 358   Label call_ldc, notFloat, notClass, notInt, Done;
 359 
 360   if (wide) {
 361     __ get_unsigned_2_byte_index_at_bcp(rbx, 1);
 362   } else {
 363     __ load_unsigned_byte(rbx, at_bcp(1));
 364   }
 365 
 366   __ get_cpool_and_tags(rcx, rax);
 367   const int base_offset = ConstantPool::header_size() * wordSize;
 368   const int tags_offset = Array<u1>::base_offset_in_bytes();
 369 
 370   // get type
 371   __ movzbl(rdx, Address(rax, rbx, Address::times_1, tags_offset));
 372   __ andl(rdx, ~JVM_CONSTANT_QDescBit);
 373 
 374   // unresolved class - get the resolved class
 375   __ cmpl(rdx, JVM_CONSTANT_UnresolvedClass);
 376   __ jccb(Assembler::equal, call_ldc);
 377 
 378   // unresolved class in error state - call into runtime to throw the error
 379   // from the first resolution attempt
 380   __ cmpl(rdx, JVM_CONSTANT_UnresolvedClassInError);
 381   __ jccb(Assembler::equal, call_ldc);
 382 
 383   // resolved class - need to call vm to get java mirror of the class
 384   __ cmpl(rdx, JVM_CONSTANT_Class);
 385   __ jcc(Assembler::notEqual, notClass);
 386 
 387   __ bind(call_ldc);
 388 
 389   __ movl(rarg, wide);
 390   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::ldc), rarg);
 391 
 392   __ push(atos);

 804                     Address(rdx, rax,
 805                             Address::times_4,
 806                             arrayOopDesc::base_offset_in_bytes(T_FLOAT)),
 807                     noreg, noreg);
 808 }
 809 
 810 void TemplateTable::daload() {
 811   transition(itos, dtos);
 812   // rax: index
 813   // rdx: array
 814   index_check(rdx, rax); // kills rbx
 815   __ access_load_at(T_DOUBLE, IN_HEAP | IS_ARRAY, noreg /* dtos */,
 816                     Address(rdx, rax,
 817                             Address::times_8,
 818                             arrayOopDesc::base_offset_in_bytes(T_DOUBLE)),
 819                     noreg, noreg);
 820 }
 821 
 822 void TemplateTable::aaload() {
 823   transition(itos, atos);
 824   Register array = rdx;
 825   Register index = rax;
 826 
 827   index_check(array, index); // kills rbx
 828   __ profile_array(rbx, array, rcx);
 829   if (UseFlatArray) {
 830     Label is_flat_array, done;
 831     __ test_flattened_array_oop(array, rbx, is_flat_array);
 832     do_oop_load(_masm,
 833                 Address(array, index,
 834                         UseCompressedOops ? Address::times_4 : Address::times_ptr,
 835                         arrayOopDesc::base_offset_in_bytes(T_OBJECT)),
 836                 rax,
 837                 IS_ARRAY);
 838     __ jmp(done);
 839     __ bind(is_flat_array);
 840     __ read_flattened_element(array, index, rbx, rcx, rax);
 841     __ bind(done);
 842   } else {
 843     do_oop_load(_masm,
 844                 Address(array, index,
 845                         UseCompressedOops ? Address::times_4 : Address::times_ptr,
 846                         arrayOopDesc::base_offset_in_bytes(T_OBJECT)),
 847                 rax,
 848                 IS_ARRAY);
 849   }
 850   __ profile_element(rbx, rax, rcx);
 851 }
 852 
 853 void TemplateTable::baload() {
 854   transition(itos, itos);
 855   // rax: index
 856   // rdx: array
 857   index_check(rdx, rax); // kills rbx
 858   __ access_load_at(T_BYTE, IN_HEAP | IS_ARRAY, rax,
 859                     Address(rdx, rax, Address::times_1, arrayOopDesc::base_offset_in_bytes(T_BYTE)),
 860                     noreg, noreg);
 861 }
 862 
 863 void TemplateTable::caload() {
 864   transition(itos, itos);
 865   // rax: index
 866   // rdx: array
 867   index_check(rdx, rax); // kills rbx
 868   __ access_load_at(T_CHAR, IN_HEAP | IS_ARRAY, rax,
 869                     Address(rdx, rax, Address::times_2, arrayOopDesc::base_offset_in_bytes(T_CHAR)),
 870                     noreg, noreg);

1116   __ access_store_at(T_FLOAT, IN_HEAP | IS_ARRAY,
1117                      Address(rdx, rbx, Address::times_4,
1118                              arrayOopDesc::base_offset_in_bytes(T_FLOAT)),
1119                      noreg /* ftos */, noreg, noreg);
1120 }
1121 
1122 void TemplateTable::dastore() {
1123   transition(dtos, vtos);
1124   __ pop_i(rbx);
1125   // value is in UseSSE >= 2 ? xmm0 : ST(0)
1126   // rbx:  index
1127   // rdx:  array
1128   index_check(rdx, rbx); // prefer index in rbx
1129   __ access_store_at(T_DOUBLE, IN_HEAP | IS_ARRAY,
1130                      Address(rdx, rbx, Address::times_8,
1131                              arrayOopDesc::base_offset_in_bytes(T_DOUBLE)),
1132                      noreg /* dtos */, noreg, noreg);
1133 }
1134 
1135 void TemplateTable::aastore() {
1136   Label is_null, is_flat_array, ok_is_subtype, done;
1137   transition(vtos, vtos);
1138   // stack: ..., array, index, value
1139   __ movptr(rax, at_tos());    // value
1140   __ movl(rcx, at_tos_p1()); // index
1141   __ movptr(rdx, at_tos_p2()); // array
1142 
1143   Address element_address(rdx, rcx,
1144                           UseCompressedOops? Address::times_4 : Address::times_ptr,
1145                           arrayOopDesc::base_offset_in_bytes(T_OBJECT));
1146 
1147   index_check_without_pop(rdx, rcx);     // kills rbx
1148 
1149   __ profile_array(rdi, rdx, rbx);
1150   __ profile_element(rdi, rax, rbx);
1151 
1152   __ testptr(rax, rax);
1153   __ jcc(Assembler::zero, is_null);
1154 
1155   // Move array class to rdi
1156   Register tmp_load_klass = LP64_ONLY(rscratch1) NOT_LP64(noreg);
1157   __ load_klass(rdi, rdx, tmp_load_klass);
1158   if (UseFlatArray) {
1159     __ movl(rbx, Address(rdi, Klass::layout_helper_offset()));
1160     __ test_flattened_array_layout(rbx, is_flat_array);
1161   }
1162 
1163   // Move subklass into rbx
1164   __ load_klass(rbx, rax, tmp_load_klass);
1165   // Move array element superklass into rax
1166   __ movptr(rax, Address(rdi,

1167                          ObjArrayKlass::element_klass_offset()));
1168 
1169   // Generate subtype check.  Blows rcx, rdi
1170   // Superklass in rax.  Subklass in rbx.
1171   // is "rbx <: rax" ? (value subclass <: array element superclass)
1172   __ gen_subtype_check(rbx, ok_is_subtype, false);
1173 
1174   // Come here on failure
1175   // object is at TOS
1176   __ jump(ExternalAddress(Interpreter::_throw_ArrayStoreException_entry));
1177 
1178   // Come here on success
1179   __ bind(ok_is_subtype);
1180 
1181   // Get the value we will store
1182   __ movptr(rax, at_tos());
1183   __ movl(rcx, at_tos_p1()); // index
1184   // Now store using the appropriate barrier
1185   do_oop_store(_masm, element_address, rax, IS_ARRAY);
1186   __ jmp(done);
1187 
1188   // Have a NULL in rax, rdx=array, ecx=index.  Store NULL at ary[idx]
1189   __ bind(is_null);
1190   if (EnableValhalla) {
1191     Label is_null_into_value_array_npe, store_null;
1192 
1193     // No way to store null in null-free array
1194     __ test_null_free_array_oop(rdx, rbx, is_null_into_value_array_npe);
1195     __ jmp(store_null);
1196 
1197     __ bind(is_null_into_value_array_npe);
1198     __ jump(ExternalAddress(Interpreter::_throw_NullPointerException_entry));
1199 
1200     __ bind(store_null);
1201   }
1202   // Store a NULL
1203   do_oop_store(_masm, element_address, noreg, IS_ARRAY);
1204   __ jmp(done);
1205 
1206   if (EnableValhalla) {
1207     Label is_type_ok;
1208     __ bind(is_flat_array); // Store non-null value to flat
1209 
1210     // Simplistic type check...
1211 
1212     // Profile the not-null value's klass.
1213     __ load_klass(rbx, rax, tmp_load_klass);
1214     // Move element klass into rax
1215     __ movptr(rax, Address(rdi, ArrayKlass::element_klass_offset()));
1216     // flat value array needs exact type match
1217     // is "rax == rbx" (value subclass == array element superclass)
1218     __ cmpptr(rax, rbx);
1219     __ jccb(Assembler::equal, is_type_ok);
1220 
1221     __ jump(ExternalAddress(Interpreter::_throw_ArrayStoreException_entry));
1222 
1223     __ bind(is_type_ok);
1224     // rbx: value's klass
1225     // rdx: array
1226     // rdi: array klass
1227     __ test_klass_is_empty_inline_type(rbx, rax, done);
1228 
1229     // calc dst for copy
1230     __ movl(rax, at_tos_p1()); // index
1231     __ data_for_value_array_index(rdx, rdi, rax, rax);
1232 
1233     // ...and src for copy
1234     __ movptr(rcx, at_tos());  // value
1235     __ data_for_oop(rcx, rcx, rbx);
1236 
1237     __ access_value_copy(IN_HEAP, rcx, rax, rbx);
1238   }
1239   // Pop stack arguments
1240   __ bind(done);
1241   __ addptr(rsp, 3 * Interpreter::stackElementSize);
1242 }
1243 
1244 void TemplateTable::bastore() {
1245   transition(itos, vtos);
1246   __ pop_i(rbx);
1247   // rax: value
1248   // rbx: index
1249   // rdx: array
1250   index_check(rdx, rbx); // prefer index in rbx
1251   // Need to check whether array is boolean or byte
1252   // since both types share the bastore bytecode.
1253   Register tmp_load_klass = LP64_ONLY(rscratch1) NOT_LP64(noreg);
1254   __ load_klass(rcx, rdx, tmp_load_klass);
1255   __ movl(rcx, Address(rcx, Klass::layout_helper_offset()));
1256   int diffbit = Klass::layout_helper_boolean_diffbit();
1257   __ testl(rcx, diffbit);
1258   Label L_skip;

2389   __ jcc(j_not(cc), not_taken);
2390   branch(false, false);
2391   __ bind(not_taken);
2392   __ profile_not_taken_branch(rax);
2393 }
2394 
2395 void TemplateTable::if_nullcmp(Condition cc) {
2396   transition(atos, vtos);
2397   // assume branch is more often taken than not (loops use backward branches)
2398   Label not_taken;
2399   __ testptr(rax, rax);
2400   __ jcc(j_not(cc), not_taken);
2401   branch(false, false);
2402   __ bind(not_taken);
2403   __ profile_not_taken_branch(rax);
2404 }
2405 
2406 void TemplateTable::if_acmp(Condition cc) {
2407   transition(atos, vtos);
2408   // assume branch is more often taken than not (loops use backward branches)
2409   Label taken, not_taken;
2410   __ pop_ptr(rdx);
2411 
2412   __ profile_acmp(rbx, rdx, rax, rcx);
2413 
2414   const int is_inline_type_mask = markWord::inline_type_pattern;
2415   if (EnableValhalla) {
2416     __ cmpoop(rdx, rax);
2417     __ jcc(Assembler::equal, (cc == equal) ? taken : not_taken);
2418 
2419     // might be substitutable, test if either rax or rdx is null
2420     __ testptr(rax, rax);
2421     __ jcc(Assembler::zero, (cc == equal) ? not_taken : taken);
2422     __ testptr(rdx, rdx);
2423     __ jcc(Assembler::zero, (cc == equal) ? not_taken : taken);
2424 
2425     // and both are values ?
2426     __ movptr(rbx, Address(rdx, oopDesc::mark_offset_in_bytes()));
2427     __ andptr(rbx, Address(rax, oopDesc::mark_offset_in_bytes()));
2428     __ andptr(rbx, is_inline_type_mask);
2429     __ cmpptr(rbx, is_inline_type_mask);
2430     __ jcc(Assembler::notEqual, (cc == equal) ? not_taken : taken);
2431 
2432     // same value klass ?
2433     __ load_metadata(rbx, rdx);
2434     __ load_metadata(rcx, rax);
2435     __ cmpptr(rbx, rcx);
2436     __ jcc(Assembler::notEqual, (cc == equal) ? not_taken : taken);
2437 
2438     // Know both are the same type, let's test for substitutability...
2439     if (cc == equal) {
2440       invoke_is_substitutable(rax, rdx, taken, not_taken);
2441     } else {
2442       invoke_is_substitutable(rax, rdx, not_taken, taken);
2443     }
2444     __ stop("Not reachable");
2445   }
2446 
2447   __ cmpoop(rdx, rax);
2448   __ jcc(j_not(cc), not_taken);
2449   __ bind(taken);
2450   branch(false, false);
2451   __ bind(not_taken);
2452   __ profile_not_taken_branch(rax, true);
2453 }
2454 
2455 void TemplateTable::invoke_is_substitutable(Register aobj, Register bobj,
2456                                             Label& is_subst, Label& not_subst) {
2457   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::is_substitutable), aobj, bobj);
2458   // Restored...rax answer, jmp to outcome...
2459   __ testl(rax, rax);
2460   __ jcc(Assembler::zero, not_subst);
2461   __ jmp(is_subst);
2462 }
2463 
2464 void TemplateTable::ret() {
2465   transition(vtos, vtos);
2466   locals_index(rbx);
2467   LP64_ONLY(__ movslq(rbx, iaddress(rbx))); // get return bci, compute return bcp
2468   NOT_LP64(__ movptr(rbx, iaddress(rbx)));
2469   __ profile_ret(rbx, rcx);
2470   __ get_method(rax);
2471   __ movptr(rbcp, Address(rax, Method::const_offset()));
2472   __ lea(rbcp, Address(rbcp, rbx, Address::times_1,
2473                       ConstMethod::codes_offset()));
2474   __ dispatch_next(vtos, 0, true);
2475 }
2476 
2477 void TemplateTable::wide_ret() {
2478   transition(vtos, vtos);
2479   locals_index_wide(rbx);
2480   __ movptr(rbx, aaddress(rbx)); // get return bci, compute return bcp
2481   __ profile_ret(rbx, rcx);

2710     __ testb(Address(r15_thread, JavaThread::polling_word_offset()), SafepointMechanism::poll_bit());
2711 #else
2712     const Register thread = rdi;
2713     __ get_thread(thread);
2714     __ testb(Address(thread, JavaThread::polling_word_offset()), SafepointMechanism::poll_bit());
2715 #endif
2716     __ jcc(Assembler::zero, no_safepoint);
2717     __ push(state);
2718     __ call_VM(noreg, CAST_FROM_FN_PTR(address,
2719                                        InterpreterRuntime::at_safepoint));
2720     __ pop(state);
2721     __ bind(no_safepoint);
2722   }
2723 
2724   // Narrow result if state is itos but result type is smaller.
2725   // Need to narrow in the return bytecode rather than in generate_return_entry
2726   // since compiled code callers expect the result to already be narrowed.
2727   if (state == itos) {
2728     __ narrow(rax);
2729   }
2730 
2731   __ remove_activation(state, rbcp, true, true, true);
2732 
2733   __ jmp(rbcp);
2734 }
2735 
2736 // ----------------------------------------------------------------------------
2737 // Volatile variables demand their effects be made known to all CPU's
2738 // in order.  Store buffers on most chips allow reads & writes to
2739 // reorder; the JMM's ReadAfterWrite.java test fails in -Xint mode
2740 // without some kind of memory barrier (i.e., it's not sufficient that
2741 // the interpreter does not reorder volatile references, the hardware
2742 // also must not reorder them).
2743 //
2744 // According to the new Java Memory Model (JMM):
2745 // (1) All volatiles are serialized wrt to each other.  ALSO reads &
2746 //     writes act as aquire & release, so:
2747 // (2) A read cannot let unrelated NON-volatile memory refs that
2748 //     happen after the read float up to before the read.  It's OK for
2749 //     non-volatile memory refs that happen before the volatile read to
2750 //     float down below it.
2751 // (3) Similar a volatile write cannot let unrelated NON-volatile

2909     __ get_cache_and_index_at_bcp(cache, index, 1);
2910     __ bind(L1);
2911   }
2912 }
2913 
2914 void TemplateTable::pop_and_check_object(Register r) {
2915   __ pop_ptr(r);
2916   __ null_check(r);  // for field access must check obj.
2917   __ verify_oop(r);
2918 }
2919 
2920 void TemplateTable::getfield_or_static(int byte_no, bool is_static, RewriteControl rc) {
2921   transition(vtos, vtos);
2922 
2923   const Register cache = rcx;
2924   const Register index = rdx;
2925   const Register obj   = LP64_ONLY(c_rarg3) NOT_LP64(rcx);
2926   const Register off   = rbx;
2927   const Register flags = rax;
2928   const Register bc    = LP64_ONLY(c_rarg3) NOT_LP64(rcx); // uses same reg as obj, so don't mix them
2929   const Register flags2 = rdx;
2930 
2931   resolve_cache_and_index(byte_no, cache, index, sizeof(u2));
2932   jvmti_post_field_access(cache, index, is_static, false);
2933   load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
2934 


2935   const Address field(obj, off, Address::times_1, 0*wordSize);
2936 
2937   Label Done, notByte, notBool, notInt, notShort, notChar, notLong, notFloat, notObj, notInlineType;
2938 
2939   if (!is_static) {
2940     __ movptr(rcx, Address(cache, index, Address::times_ptr,
2941                            in_bytes(ConstantPoolCache::base_offset() +
2942                                     ConstantPoolCacheEntry::f1_offset())));
2943   }
2944 
2945   __ movl(flags2, flags);
2946 
2947   __ shrl(flags, ConstantPoolCacheEntry::tos_state_shift);
2948   // Make sure we don't need to mask edx after the above shift
2949   assert(btos == 0, "change code, btos != 0");
2950 
2951   __ andl(flags, ConstantPoolCacheEntry::tos_state_mask);
2952 
2953   __ jcc(Assembler::notZero, notByte);
2954   // btos
2955   if (!is_static) pop_and_check_object(obj);
2956   __ access_load_at(T_BYTE, IN_HEAP, rax, field, noreg, noreg);
2957   __ push(btos);
2958   // Rewrite bytecode to be faster
2959   if (!is_static && rc == may_rewrite) {
2960     patch_bytecode(Bytecodes::_fast_bgetfield, bc, rbx);
2961   }
2962   __ jmp(Done);
2963 
2964   __ bind(notByte);
2965 
2966   __ cmpl(flags, ztos);
2967   __ jcc(Assembler::notEqual, notBool);
2968    if (!is_static) pop_and_check_object(obj);
2969   // ztos (same code as btos)
2970   __ access_load_at(T_BOOLEAN, IN_HEAP, rax, field, noreg, noreg);
2971   __ push(ztos);
2972   // Rewrite bytecode to be faster
2973   if (!is_static && rc == may_rewrite) {
2974     // use btos rewriting, no truncating to t/f bit is needed for getfield.
2975     patch_bytecode(Bytecodes::_fast_bgetfield, bc, rbx);
2976   }
2977   __ jmp(Done);
2978 
2979   __ bind(notBool);
2980   __ cmpl(flags, atos);
2981   __ jcc(Assembler::notEqual, notObj);
2982   // atos
2983   if (!EnableValhalla) {
2984     if (!is_static) pop_and_check_object(obj);
2985     do_oop_load(_masm, field, rax);
2986     __ push(atos);
2987     if (!is_static && rc == may_rewrite) {
2988       patch_bytecode(Bytecodes::_fast_agetfield, bc, rbx);
2989     }
2990     __ jmp(Done);
2991   } else {
2992     if (is_static) {
2993       __ load_heap_oop(rax, field);
2994       if (EnableValhalla) {
2995         Label is_null_free_inline_type, uninitialized;
2996         // Issue below if the static field has not been initialized yet
2997         __ test_field_is_null_free_inline_type(flags2, rscratch1, is_null_free_inline_type);
2998           // field is not a null free inline type
2999           __ push(atos);
3000           __ jmp(Done);
3001         // field is a null free inline type, must not return null even if uninitialized
3002         __ bind(is_null_free_inline_type);
3003            __ testptr(rax, rax);
3004           __ jcc(Assembler::zero, uninitialized);
3005             __ push(atos);
3006             __ jmp(Done);
3007           __ bind(uninitialized);
3008             __ andl(flags2, ConstantPoolCacheEntry::field_index_mask);
3009   #ifdef _LP64
3010             Label slow_case, finish;
3011             __ cmpb(Address(rcx, InstanceKlass::init_state_offset()), InstanceKlass::fully_initialized);
3012             __ jcc(Assembler::notEqual, slow_case);
3013           __ get_default_value_oop(rcx, off, rax);
3014           __ jmp(finish);
3015           __ bind(slow_case);
3016   #endif // LP64
3017             __ call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::uninitialized_static_inline_type_field),
3018                   obj, flags2);
3019   #ifdef _LP64
3020             __ bind(finish);
3021   #endif // _LP64
3022       }
3023         __ verify_oop(rax);
3024         __ push(atos);
3025         __ jmp(Done);
3026     } else {
3027       Label is_inlined, nonnull, is_inline_type, rewrite_inline;
3028       if (EnableValhalla) {
3029         __ test_field_is_null_free_inline_type(flags2, rscratch1, is_inline_type);
3030       }
3031       // field is not a null free inline type
3032       pop_and_check_object(obj);
3033       __ load_heap_oop(rax, field);
3034       __ push(atos);
3035       if (rc == may_rewrite) {
3036         patch_bytecode(Bytecodes::_fast_agetfield, bc, rbx);
3037       }
3038       __ jmp(Done);
3039       if (EnableValhalla) {
3040         __ bind(is_inline_type);
3041           __ test_field_is_inlined(flags2, rscratch1, is_inlined);
3042             // field is not inlined
3043             __ movptr(rax, rcx);  // small dance required to preserve the klass_holder somewhere
3044             pop_and_check_object(obj);
3045             __ push(rax);
3046             __ load_heap_oop(rax, field);
3047             __ pop(rcx);
3048             __ testptr(rax, rax);
3049             __ jcc(Assembler::notZero, nonnull);
3050               __ andl(flags2, ConstantPoolCacheEntry::field_index_mask);
3051               __ get_inline_type_field_klass(rcx, flags2, rbx);
3052               __ get_default_value_oop(rbx, rcx, rax);
3053             __ bind(nonnull);
3054             __ verify_oop(rax);
3055             __ push(atos);
3056             __ jmp(rewrite_inline);
3057           __ bind(is_inlined);
3058           // field is inlined
3059             __ andl(flags2, ConstantPoolCacheEntry::field_index_mask);
3060             pop_and_check_object(rax);
3061             __ read_inlined_field(rcx, flags2, rbx, rax);
3062             __ verify_oop(rax);
3063             __ push(atos);
3064         __ bind(rewrite_inline);
3065         if (rc == may_rewrite) {
3066           patch_bytecode(Bytecodes::_fast_qgetfield, bc, rbx);
3067         }
3068         __ jmp(Done);
3069       }
3070     }
3071   }

3072 
3073   __ bind(notObj);
3074 
3075   if (!is_static) pop_and_check_object(obj);
3076 
3077   __ cmpl(flags, itos);
3078   __ jcc(Assembler::notEqual, notInt);
3079   // itos
3080   __ access_load_at(T_INT, IN_HEAP, rax, field, noreg, noreg);
3081   __ push(itos);
3082   // Rewrite bytecode to be faster
3083   if (!is_static && rc == may_rewrite) {
3084     patch_bytecode(Bytecodes::_fast_igetfield, bc, rbx);
3085   }
3086   __ jmp(Done);
3087 
3088   __ bind(notInt);
3089   __ cmpl(flags, ctos);
3090   __ jcc(Assembler::notEqual, notChar);
3091   // ctos
3092   __ access_load_at(T_CHAR, IN_HEAP, rax, field, noreg, noreg);
3093   __ push(ctos);
3094   // Rewrite bytecode to be faster
3095   if (!is_static && rc == may_rewrite) {
3096     patch_bytecode(Bytecodes::_fast_cgetfield, bc, rbx);

3156 #endif
3157 
3158   __ bind(Done);
3159   // [jk] not needed currently
3160   // volatile_barrier(Assembler::Membar_mask_bits(Assembler::LoadLoad |
3161   //                                              Assembler::LoadStore));
3162 }
3163 
3164 void TemplateTable::getfield(int byte_no) {
3165   getfield_or_static(byte_no, false);
3166 }
3167 
3168 void TemplateTable::nofast_getfield(int byte_no) {
3169   getfield_or_static(byte_no, false, may_not_rewrite);
3170 }
3171 
3172 void TemplateTable::getstatic(int byte_no) {
3173   getfield_or_static(byte_no, true);
3174 }
3175 
3176 void TemplateTable::withfield() {
3177   transition(vtos, atos);
3178 
3179   Register cache = LP64_ONLY(c_rarg1) NOT_LP64(rcx);
3180   Register index = LP64_ONLY(c_rarg2) NOT_LP64(rdx);
3181 
3182   resolve_cache_and_index(f2_byte, cache, index, sizeof(u2));
3183 
3184   Register cpentry = rbx;
3185 
3186   ByteSize cp_base_offset = ConstantPoolCache::base_offset();
3187 
3188   __ lea(cpentry, Address(cache, index, Address::times_ptr,
3189                          in_bytes(cp_base_offset)));
3190   __ lea(rax, at_tos());
3191   __ call_VM(rbx, CAST_FROM_FN_PTR(address, InterpreterRuntime::withfield), cpentry, rax);
3192   // new value type is returned in rbx
3193   // stack adjustment is returned in rax
3194   __ verify_oop(rbx);
3195   __ addptr(rsp, rax);
3196   __ movptr(rax, rbx);
3197 }
3198 
3199 // The registers cache and index expected to be set before call.
3200 // The function may destroy various registers, just not the cache and index registers.
3201 void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
3202 
3203   const Register robj = LP64_ONLY(c_rarg2)   NOT_LP64(rax);
3204   const Register RBX  = LP64_ONLY(c_rarg1)   NOT_LP64(rbx);
3205   const Register RCX  = LP64_ONLY(c_rarg3)   NOT_LP64(rcx);
3206   const Register RDX  = LP64_ONLY(rscratch1) NOT_LP64(rdx);
3207 
3208   ByteSize cp_base_offset = ConstantPoolCache::base_offset();
3209 
3210   if (JvmtiExport::can_post_field_modification()) {
3211     // Check to see if a field modification watch has been set before
3212     // we take the time to call into the VM.
3213     Label L1;
3214     assert_different_registers(cache, index, rax);
3215     __ mov32(rax, ExternalAddress((address)JvmtiExport::get_field_modification_count_addr()));
3216     __ testl(rax, rax);
3217     __ jcc(Assembler::zero, L1);

3273     // c_rarg1: object pointer set up above (NULL if static)
3274     // c_rarg2: cache entry pointer
3275     // c_rarg3: jvalue object on the stack
3276     __ call_VM(noreg,
3277                CAST_FROM_FN_PTR(address,
3278                                 InterpreterRuntime::post_field_modification),
3279                RBX, robj, RCX);
3280     __ get_cache_and_index_at_bcp(cache, index, 1);
3281     __ bind(L1);
3282   }
3283 }
3284 
3285 void TemplateTable::putfield_or_static(int byte_no, bool is_static, RewriteControl rc) {
3286   transition(vtos, vtos);
3287 
3288   const Register cache = rcx;
3289   const Register index = rdx;
3290   const Register obj   = rcx;
3291   const Register off   = rbx;
3292   const Register flags = rax;
3293   const Register flags2 = rdx;
3294 
3295   resolve_cache_and_index(byte_no, cache, index, sizeof(u2));
3296   jvmti_post_field_mod(cache, index, is_static);
3297   load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
3298 
3299   // [jk] not needed currently
3300   // volatile_barrier(Assembler::Membar_mask_bits(Assembler::LoadStore |
3301   //                                              Assembler::StoreStore));
3302 
3303   Label notVolatile, Done;
3304   __ movl(rdx, flags);
3305   __ shrl(rdx, ConstantPoolCacheEntry::is_volatile_shift);
3306   __ andl(rdx, 0x1);
3307 
3308   // Check for volatile store
3309   __ testl(rdx, rdx);
3310   __ movl(flags2, flags);
3311   __ jcc(Assembler::zero, notVolatile);
3312 
3313   putfield_or_static_helper(byte_no, is_static, rc, obj, off, flags, flags2);
3314   volatile_barrier(Assembler::Membar_mask_bits(Assembler::StoreLoad |
3315                                                Assembler::StoreStore));
3316   __ jmp(Done);
3317   __ bind(notVolatile);
3318 
3319   putfield_or_static_helper(byte_no, is_static, rc, obj, off, flags, flags2);
3320 
3321   __ bind(Done);
3322 }
3323 
3324 void TemplateTable::putfield_or_static_helper(int byte_no, bool is_static, RewriteControl rc,
3325                                               Register obj, Register off, Register flags, Register flags2) {
3326 
3327   // field addresses
3328   const Address field(obj, off, Address::times_1, 0*wordSize);
3329   NOT_LP64( const Address hi(obj, off, Address::times_1, 1*wordSize);)
3330 
3331   Label notByte, notBool, notInt, notShort, notChar,
3332         notLong, notFloat, notObj, notInlineType;
3333   Label Done;
3334 
3335   const Register bc    = LP64_ONLY(c_rarg3) NOT_LP64(rcx);
3336 
3337   __ shrl(flags, ConstantPoolCacheEntry::tos_state_shift);
3338 
3339   assert(btos == 0, "change code, btos != 0");
3340   __ andl(flags, ConstantPoolCacheEntry::tos_state_mask);
3341   __ jcc(Assembler::notZero, notByte);
3342 
3343   // btos
3344   {
3345     __ pop(btos);
3346     if (!is_static) pop_and_check_object(obj);
3347     __ access_store_at(T_BYTE, IN_HEAP, field, rax, noreg, noreg);
3348     if (!is_static && rc == may_rewrite) {
3349       patch_bytecode(Bytecodes::_fast_bputfield, bc, rbx, true, byte_no);
3350     }
3351     __ jmp(Done);
3352   }

3355   __ cmpl(flags, ztos);
3356   __ jcc(Assembler::notEqual, notBool);
3357 
3358   // ztos
3359   {
3360     __ pop(ztos);
3361     if (!is_static) pop_and_check_object(obj);
3362     __ access_store_at(T_BOOLEAN, IN_HEAP, field, rax, noreg, noreg);
3363     if (!is_static && rc == may_rewrite) {
3364       patch_bytecode(Bytecodes::_fast_zputfield, bc, rbx, true, byte_no);
3365     }
3366     __ jmp(Done);
3367   }
3368 
3369   __ bind(notBool);
3370   __ cmpl(flags, atos);
3371   __ jcc(Assembler::notEqual, notObj);
3372 
3373   // atos
3374   {
3375     if (!EnableValhalla) {
3376       __ pop(atos);
3377       if (!is_static) pop_and_check_object(obj);
3378       // Store into the field
3379       do_oop_store(_masm, field, rax);
3380       if (!is_static && rc == may_rewrite) {
3381         patch_bytecode(Bytecodes::_fast_aputfield, bc, rbx, true, byte_no);
3382       }
3383       __ jmp(Done);
3384     } else {
3385       __ pop(atos);
3386       if (is_static) {
3387         Label is_inline_type;
3388         if (EnableValhalla) {
3389           __ test_field_is_not_null_free_inline_type(flags2, rscratch1, is_inline_type);
3390           __ null_check(rax);
3391           __ bind(is_inline_type);
3392         }
3393         do_oop_store(_masm, field, rax);
3394         __ jmp(Done);
3395       } else {
3396         Label is_inline_type, is_inlined, rewrite_not_inline, rewrite_inline;
3397         if (EnableValhalla) {
3398           __ test_field_is_null_free_inline_type(flags2, rscratch1, is_inline_type);
3399         }
3400         // Not an inline type
3401         pop_and_check_object(obj);
3402         // Store into the field
3403         do_oop_store(_masm, field, rax);
3404         __ bind(rewrite_not_inline);
3405         if (rc == may_rewrite) {
3406           patch_bytecode(Bytecodes::_fast_aputfield, bc, rbx, true, byte_no);
3407         }
3408         __ jmp(Done);
3409         if (EnableValhalla) {
3410           // Implementation of the inline type semantic
3411           __ bind(is_inline_type);
3412           __ null_check(rax);
3413           __ test_field_is_inlined(flags2, rscratch1, is_inlined);
3414           // field is not inlined
3415           pop_and_check_object(obj);
3416           // Store into the field
3417           do_oop_store(_masm, field, rax);
3418           __ jmp(rewrite_inline);
3419           __ bind(is_inlined);
3420           // field is inlined
3421           pop_and_check_object(obj);
3422           assert_different_registers(rax, rdx, obj, off);
3423           __ load_klass(rdx, rax, rscratch1);
3424           __ data_for_oop(rax, rax, rdx);
3425           __ addptr(obj, off);
3426           __ access_value_copy(IN_HEAP, rax, obj, rdx);
3427           __ bind(rewrite_inline);
3428           if (rc == may_rewrite) {
3429             patch_bytecode(Bytecodes::_fast_qputfield, bc, rbx, true, byte_no);
3430           }
3431           __ jmp(Done);
3432         }
3433       }
3434     }

3435   }
3436 
3437   __ bind(notObj);
3438   __ cmpl(flags, itos);
3439   __ jcc(Assembler::notEqual, notInt);
3440 
3441   // itos
3442   {
3443     __ pop(itos);
3444     if (!is_static) pop_and_check_object(obj);
3445     __ access_store_at(T_INT, IN_HEAP, field, rax, noreg, noreg);
3446     if (!is_static && rc == may_rewrite) {
3447       patch_bytecode(Bytecodes::_fast_iputfield, bc, rbx, true, byte_no);
3448     }
3449     __ jmp(Done);
3450   }
3451 
3452   __ bind(notInt);
3453   __ cmpl(flags, ctos);
3454   __ jcc(Assembler::notEqual, notChar);

3553 }
3554 
3555 void TemplateTable::jvmti_post_fast_field_mod() {
3556 
3557   const Register scratch = LP64_ONLY(c_rarg3) NOT_LP64(rcx);
3558 
3559   if (JvmtiExport::can_post_field_modification()) {
3560     // Check to see if a field modification watch has been set before
3561     // we take the time to call into the VM.
3562     Label L2;
3563     __ mov32(scratch, ExternalAddress((address)JvmtiExport::get_field_modification_count_addr()));
3564     __ testl(scratch, scratch);
3565     __ jcc(Assembler::zero, L2);
3566     __ pop_ptr(rbx);                  // copy the object pointer from tos
3567     __ verify_oop(rbx);
3568     __ push_ptr(rbx);                 // put the object pointer back on tos
3569     // Save tos values before call_VM() clobbers them. Since we have
3570     // to do it for every data type, we use the saved values as the
3571     // jvalue object.
3572     switch (bytecode()) {          // load values into the jvalue object
3573     case Bytecodes::_fast_qputfield: //fall through
3574     case Bytecodes::_fast_aputfield: __ push_ptr(rax); break;
3575     case Bytecodes::_fast_bputfield: // fall through
3576     case Bytecodes::_fast_zputfield: // fall through
3577     case Bytecodes::_fast_sputfield: // fall through
3578     case Bytecodes::_fast_cputfield: // fall through
3579     case Bytecodes::_fast_iputfield: __ push_i(rax); break;
3580     case Bytecodes::_fast_dputfield: __ push(dtos); break;
3581     case Bytecodes::_fast_fputfield: __ push(ftos); break;
3582     case Bytecodes::_fast_lputfield: __ push_l(rax); break;
3583 
3584     default:
3585       ShouldNotReachHere();
3586     }
3587     __ mov(scratch, rsp);             // points to jvalue on the stack
3588     // access constant pool cache entry
3589     LP64_ONLY(__ get_cache_entry_pointer_at_bcp(c_rarg2, rax, 1));
3590     NOT_LP64(__ get_cache_entry_pointer_at_bcp(rax, rdx, 1));
3591     __ verify_oop(rbx);
3592     // rbx: object pointer copied above
3593     // c_rarg2: cache entry pointer
3594     // c_rarg3: jvalue object on the stack
3595     LP64_ONLY(__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification), rbx, c_rarg2, c_rarg3));
3596     NOT_LP64(__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification), rbx, rax, rcx));
3597 
3598     switch (bytecode()) {             // restore tos values
3599     case Bytecodes::_fast_qputfield: // fall through
3600     case Bytecodes::_fast_aputfield: __ pop_ptr(rax); break;
3601     case Bytecodes::_fast_bputfield: // fall through
3602     case Bytecodes::_fast_zputfield: // fall through
3603     case Bytecodes::_fast_sputfield: // fall through
3604     case Bytecodes::_fast_cputfield: // fall through
3605     case Bytecodes::_fast_iputfield: __ pop_i(rax); break;
3606     case Bytecodes::_fast_dputfield: __ pop(dtos); break;
3607     case Bytecodes::_fast_fputfield: __ pop(ftos); break;
3608     case Bytecodes::_fast_lputfield: __ pop_l(rax); break;
3609     default: break;
3610     }
3611     __ bind(L2);
3612   }
3613 }
3614 
3615 void TemplateTable::fast_storefield(TosState state) {
3616   transition(state, vtos);
3617 
3618   ByteSize base = ConstantPoolCache::base_offset();
3619 
3620   jvmti_post_fast_field_mod();
3621 
3622   // access constant pool cache
3623   __ get_cache_and_index_at_bcp(rcx, rbx, 1);
3624 
3625   // test for volatile with rdx but rdx is tos register for lputfield.
3626   __ movl(rdx, Address(rcx, rbx, Address::times_ptr,
3627                        in_bytes(base +
3628                                 ConstantPoolCacheEntry::flags_offset())));
3629 
3630   // replace index with field offset from cache entry
3631   __ movptr(rbx, Address(rcx, rbx, Address::times_ptr,
3632                          in_bytes(base + ConstantPoolCacheEntry::f2_offset())));
3633 
3634   // [jk] not needed currently
3635   // volatile_barrier(Assembler::Membar_mask_bits(Assembler::LoadStore |
3636   //                                              Assembler::StoreStore));
3637 
3638   Label notVolatile, Done;
3639   if (bytecode() == Bytecodes::_fast_qputfield) {
3640     __ movl(rscratch2, rdx);  // saving flags for is_inlined test
3641   }
3642 
3643   __ shrl(rdx, ConstantPoolCacheEntry::is_volatile_shift);
3644   __ andl(rdx, 0x1);
3645 
3646   // Get object from stack
3647   pop_and_check_object(rcx);
3648 
3649   // field address
3650   const Address field(rcx, rbx, Address::times_1);
3651 
3652   // Check for volatile store
3653   __ testl(rdx, rdx);
3654   __ jcc(Assembler::zero, notVolatile);
3655 
3656   if (bytecode() == Bytecodes::_fast_qputfield) {
3657     __ movl(rdx, rscratch2);  // restoring flags for is_inlined test
3658   }
3659   fast_storefield_helper(field, rax, rdx);
3660   volatile_barrier(Assembler::Membar_mask_bits(Assembler::StoreLoad |
3661                                                Assembler::StoreStore));
3662   __ jmp(Done);
3663   __ bind(notVolatile);
3664 
3665   if (bytecode() == Bytecodes::_fast_qputfield) {
3666     __ movl(rdx, rscratch2);  // restoring flags for is_inlined test
3667   }
3668   fast_storefield_helper(field, rax, rdx);
3669 
3670   __ bind(Done);
3671 }
3672 
3673 void TemplateTable::fast_storefield_helper(Address field, Register rax, Register flags) {
3674 
3675   // access field
3676   switch (bytecode()) {
3677   case Bytecodes::_fast_qputfield:
3678     {
3679       Label is_inlined, done;
3680       __ null_check(rax);
3681       __ test_field_is_inlined(flags, rscratch1, is_inlined);
3682       // field is not inlined
3683       do_oop_store(_masm, field, rax);
3684       __ jmp(done);
3685       __ bind(is_inlined);
3686       // field is inlined
3687       __ load_klass(rdx, rax, rscratch1);
3688       __ data_for_oop(rax, rax, rdx);
3689       __ lea(rcx, field);
3690       __ access_value_copy(IN_HEAP, rax, rcx, rdx);
3691       __ bind(done);
3692     }
3693     break;
3694   case Bytecodes::_fast_aputfield:
3695     {
3696       do_oop_store(_masm, field, rax);
3697     }
3698     break;
3699   case Bytecodes::_fast_lputfield:
3700 #ifdef _LP64
3701     __ access_store_at(T_LONG, IN_HEAP, field, noreg /* ltos */, noreg, noreg);
3702 #else
3703   __ stop("should not be rewritten");
3704 #endif
3705     break;
3706   case Bytecodes::_fast_iputfield:
3707     __ access_store_at(T_INT, IN_HEAP, field, rax, noreg, noreg);
3708     break;
3709   case Bytecodes::_fast_zputfield:
3710     __ access_store_at(T_BOOLEAN, IN_HEAP, field, rax, noreg, noreg);
3711     break;
3712   case Bytecodes::_fast_bputfield:
3713     __ access_store_at(T_BYTE, IN_HEAP, field, rax, noreg, noreg);
3714     break;
3715   case Bytecodes::_fast_sputfield:
3716     __ access_store_at(T_SHORT, IN_HEAP, field, rax, noreg, noreg);
3717     break;

3747     __ push_ptr(rax);  // save object pointer before call_VM() clobbers it
3748     LP64_ONLY(__ mov(c_rarg1, rax));
3749     // c_rarg1: object pointer copied above
3750     // c_rarg2: cache entry pointer
3751     LP64_ONLY(__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access), c_rarg1, c_rarg2));
3752     NOT_LP64(__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access), rax, rcx));
3753     __ pop_ptr(rax); // restore object pointer
3754     __ bind(L1);
3755   }
3756 
3757   // access constant pool cache
3758   __ get_cache_and_index_at_bcp(rcx, rbx, 1);
3759   // replace index with field offset from cache entry
3760   // [jk] not needed currently
3761   // __ movl(rdx, Address(rcx, rbx, Address::times_8,
3762   //                      in_bytes(ConstantPoolCache::base_offset() +
3763   //                               ConstantPoolCacheEntry::flags_offset())));
3764   // __ shrl(rdx, ConstantPoolCacheEntry::is_volatile_shift);
3765   // __ andl(rdx, 0x1);
3766   //
3767   __ movptr(rdx, Address(rcx, rbx, Address::times_ptr,
3768                          in_bytes(ConstantPoolCache::base_offset() +
3769                                   ConstantPoolCacheEntry::f2_offset())));
3770 
3771   // rax: object
3772   __ verify_oop(rax);
3773   __ null_check(rax);
3774   Address field(rax, rdx, Address::times_1);
3775 
3776   // access field
3777   switch (bytecode()) {
3778   case Bytecodes::_fast_qgetfield:
3779     {
3780       Label is_inlined, nonnull, Done;
3781       __ movptr(rscratch1, Address(rcx, rbx, Address::times_ptr,
3782                                    in_bytes(ConstantPoolCache::base_offset() +
3783                                             ConstantPoolCacheEntry::flags_offset())));
3784       __ test_field_is_inlined(rscratch1, rscratch2, is_inlined);
3785         // field is not inlined
3786         __ load_heap_oop(rax, field);
3787         __ testptr(rax, rax);
3788         __ jcc(Assembler::notZero, nonnull);
3789           __ movl(rdx, Address(rcx, rbx, Address::times_ptr,
3790                              in_bytes(ConstantPoolCache::base_offset() +
3791                                       ConstantPoolCacheEntry::flags_offset())));
3792           __ andl(rdx, ConstantPoolCacheEntry::field_index_mask);
3793           __ movptr(rcx, Address(rcx, rbx, Address::times_ptr,
3794                                        in_bytes(ConstantPoolCache::base_offset() +
3795                                                 ConstantPoolCacheEntry::f1_offset())));
3796           __ get_inline_type_field_klass(rcx, rdx, rbx);
3797           __ get_default_value_oop(rbx, rcx, rax);
3798         __ bind(nonnull);
3799         __ verify_oop(rax);
3800         __ jmp(Done);
3801       __ bind(is_inlined);
3802       // field is inlined
3803         __ push(rdx); // save offset
3804         __ movl(rdx, Address(rcx, rbx, Address::times_ptr,
3805                            in_bytes(ConstantPoolCache::base_offset() +
3806                                     ConstantPoolCacheEntry::flags_offset())));
3807         __ andl(rdx, ConstantPoolCacheEntry::field_index_mask);
3808         __ movptr(rcx, Address(rcx, rbx, Address::times_ptr,
3809                                      in_bytes(ConstantPoolCache::base_offset() +
3810                                               ConstantPoolCacheEntry::f1_offset())));
3811         __ pop(rbx); // restore offset
3812         __ read_inlined_field(rcx, rdx, rbx, rax);
3813       __ bind(Done);
3814       __ verify_oop(rax);
3815     }
3816     break;
3817   case Bytecodes::_fast_agetfield:
3818     do_oop_load(_masm, field, rax);
3819     __ verify_oop(rax);
3820     break;
3821   case Bytecodes::_fast_lgetfield:
3822 #ifdef _LP64
3823     __ access_load_at(T_LONG, IN_HEAP, noreg /* ltos */, field, noreg, noreg);
3824 #else
3825   __ stop("should not be rewritten");
3826 #endif
3827     break;
3828   case Bytecodes::_fast_igetfield:
3829     __ access_load_at(T_INT, IN_HEAP, rax, field, noreg, noreg);
3830     break;
3831   case Bytecodes::_fast_bgetfield:
3832     __ access_load_at(T_BYTE, IN_HEAP, rax, field, noreg, noreg);
3833     break;
3834   case Bytecodes::_fast_sgetfield:
3835     __ access_load_at(T_SHORT, IN_HEAP, rax, field, noreg, noreg);
3836     break;

4265 
4266   // Note:  rax_callsite is already pushed by prepare_invoke
4267 
4268   // %%% should make a type profile for any invokedynamic that takes a ref argument
4269   // profile this call
4270   __ profile_call(rbcp);
4271   __ profile_arguments_type(rdx, rbx_method, rbcp, false);
4272 
4273   __ verify_oop(rax_callsite);
4274 
4275   __ jump_from_interpreted(rbx_method, rdx);
4276 }
4277 
4278 //-----------------------------------------------------------------------------
4279 // Allocation
4280 
4281 void TemplateTable::_new() {
4282   transition(vtos, atos);
4283   __ get_unsigned_2_byte_index_at_bcp(rdx, 1);
4284   Label slow_case;

4285   Label done;
4286   Label is_not_value;

4287 
4288   __ get_cpool_and_tags(rcx, rax);
4289 
4290   // Make sure the class we're about to instantiate has been resolved.
4291   // This is done before loading InstanceKlass to be consistent with the order
4292   // how Constant Pool is updated (see ConstantPool::klass_at_put)
4293   const int tags_offset = Array<u1>::base_offset_in_bytes();
4294   __ cmpb(Address(rax, rdx, Address::times_1, tags_offset), JVM_CONSTANT_Class);
4295   __ jcc(Assembler::notEqual, slow_case);
4296 
4297   // get InstanceKlass
4298   __ load_resolved_klass_at_index(rcx, rcx, rdx);
4299 
4300   __ cmpb(Address(rcx, InstanceKlass::kind_offset()), InstanceKlass::_kind_inline_type);
4301   __ jcc(Assembler::notEqual, is_not_value);
4302 
4303   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_InstantiationError));
4304 
4305   __ bind(is_not_value);
4306 
4307   // make sure klass is initialized & doesn't have finalizer

4308   __ cmpb(Address(rcx, InstanceKlass::init_state_offset()), InstanceKlass::fully_initialized);
4309   __ jcc(Assembler::notEqual, slow_case);
4310 
4311   __ allocate_instance(rcx, rax, rdx, rbx, true, slow_case);
4312   __ jmp(done);

















4313 
4314   // slow case
4315   __ bind(slow_case);
4316 
4317   Register rarg1 = LP64_ONLY(c_rarg1) NOT_LP64(rax);
4318   Register rarg2 = LP64_ONLY(c_rarg2) NOT_LP64(rdx);




4319 
4320   __ get_constant_pool(rarg1);
4321   __ get_unsigned_2_byte_index_at_bcp(rarg2, 1);
4322   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), rarg1, rarg2);
4323    __ verify_oop(rax);











4324 
4325   // continue
4326   __ bind(done);
4327 }





















4328 
4329 void TemplateTable::defaultvalue() {
4330   transition(vtos, atos);






4331 
4332   Label slow_case;
4333   Label done;
4334   Label is_value;








4335 
4336   __ get_unsigned_2_byte_index_at_bcp(rdx, 1);
4337   __ get_cpool_and_tags(rcx, rax);






4338 
4339   // Make sure the class we're about to instantiate has been resolved.
4340   // This is done before loading InstanceKlass to be consistent with the order
4341   // how Constant Pool is updated (see ConstantPool::klass_at_put)
4342   const int tags_offset = Array<u1>::base_offset_in_bytes();
4343   __ cmpb(Address(rax, rdx, Address::times_1, tags_offset), JVM_CONSTANT_Class);
4344   __ jcc(Assembler::notEqual, slow_case);
4345 
4346   // get InstanceKlass
4347   __ load_resolved_klass_at_index(rcx, rcx, rdx);
4348 
4349   __ cmpb(Address(rcx, InstanceKlass::kind_offset()), InstanceKlass::_kind_inline_type);
4350   __ jcc(Assembler::equal, is_value);
4351 
4352   // in the future, defaultvalue will just return null instead of throwing an exception
4353   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_IncompatibleClassChangeError));
4354 
4355   __ bind(is_value);
4356 
4357   // make sure klass is fully initialized
4358   __ cmpb(Address(rcx, InstanceKlass::init_state_offset()), InstanceKlass::fully_initialized);
4359   __ jcc(Assembler::notEqual, slow_case);
4360 
4361   // have a resolved InlineKlass in rcx, return the default value oop from it
4362   __ get_default_value_oop(rcx, rdx, rax);
4363   __ jmp(done);
4364 

4365   __ bind(slow_case);


4366 
4367   Register rarg1 = LP64_ONLY(c_rarg1) NOT_LP64(rcx);
4368   Register rarg2 = LP64_ONLY(c_rarg2) NOT_LP64(rdx);
4369 

4370   __ get_unsigned_2_byte_index_at_bcp(rarg2, 1);
4371   __ get_constant_pool(rarg1);
4372 
4373   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::defaultvalue),
4374       rarg1, rarg2);
4375 

4376   __ bind(done);
4377   __ verify_oop(rax);
4378 }
4379 
4380 void TemplateTable::newarray() {
4381   transition(itos, atos);
4382   Register rarg1 = LP64_ONLY(c_rarg1) NOT_LP64(rdx);
4383   __ load_unsigned_byte(rarg1, at_bcp(1));
4384   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::newarray),
4385           rarg1, rax);
4386 }
4387 
4388 void TemplateTable::anewarray() {
4389   transition(itos, atos);
4390 
4391   Register rarg1 = LP64_ONLY(c_rarg1) NOT_LP64(rcx);
4392   Register rarg2 = LP64_ONLY(c_rarg2) NOT_LP64(rdx);
4393 
4394   __ get_unsigned_2_byte_index_at_bcp(rarg2, 1);
4395   __ get_constant_pool(rarg1);
4396   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::anewarray),
4397           rarg1, rarg2, rax);
4398 }
4399 
4400 void TemplateTable::arraylength() {
4401   transition(atos, itos);
4402   __ null_check(rax, arrayOopDesc::length_offset_in_bytes());
4403   __ movl(rax, Address(rax, arrayOopDesc::length_offset_in_bytes()));
4404 }
4405 
4406 void TemplateTable::checkcast() {
4407   transition(atos, atos);
4408   Label done, is_null, ok_is_subtype, quicked, resolved;
4409   __ testptr(rax, rax); // object is in rax
4410   __ jcc(Assembler::zero, is_null);
4411 
4412   // Get cpool & tags index
4413   __ get_cpool_and_tags(rcx, rdx); // rcx=cpool, rdx=tags array
4414   __ get_unsigned_2_byte_index_at_bcp(rbx, 1); // rbx=index
4415   // See if bytecode has already been quicked
4416   __ movzbl(rdx, Address(rdx, rbx,
4417       Address::times_1,
4418       Array<u1>::base_offset_in_bytes()));
4419   __ andl (rdx, ~JVM_CONSTANT_QDescBit);
4420   __ cmpl(rdx, JVM_CONSTANT_Class);
4421   __ jcc(Assembler::equal, quicked);
4422   __ push(atos); // save receiver for result, and for GC
4423   call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc));
4424 
4425   // vm_result_2 has metadata result
4426 #ifndef _LP64
4427   // borrow rdi from locals
4428   __ get_thread(rdi);
4429   __ get_vm_result_2(rax, rdi);
4430   __ restore_locals();
4431 #else
4432   __ get_vm_result_2(rax, r15_thread);
4433 #endif
4434 
4435   __ pop_ptr(rdx); // restore receiver
4436   __ jmpb(resolved);
4437 
4438   // Get superklass in rax and subklass in rbx
4439   __ bind(quicked);
4440   __ mov(rdx, rax); // Save object in rdx; rax needed for subtype check
4441   __ load_resolved_klass_at_index(rax, rcx, rbx);
4442 
4443   __ bind(resolved);
4444   Register tmp_load_klass = LP64_ONLY(rscratch1) NOT_LP64(noreg);
4445   __ load_klass(rbx, rdx, tmp_load_klass);
4446 
4447   // Generate subtype check.  Blows rcx, rdi.  Object in rdx.
4448   // Superklass in rax.  Subklass in rbx.
4449   __ gen_subtype_check(rbx, ok_is_subtype);
4450 
4451   // Come here on failure
4452   __ push_ptr(rdx);
4453   // object is at TOS
4454   __ jump(ExternalAddress(Interpreter::_throw_ClassCastException_entry));
4455 
4456   // Come here on success
4457   __ bind(ok_is_subtype);
4458   __ mov(rax, rdx); // Restore object in rdx
4459   __ jmp(done);
4460 
4461   __ bind(is_null);
4462 
4463   // Collect counts on whether this check-cast sees NULLs a lot or not.
4464   if (ProfileInterpreter) {


4465     __ profile_null_seen(rcx);


4466   }
4467 
4468   if (EnableValhalla) {
4469     // Get cpool & tags index
4470     __ get_cpool_and_tags(rcx, rdx); // rcx=cpool, rdx=tags array
4471     __ get_unsigned_2_byte_index_at_bcp(rbx, 1); // rbx=index
4472     // See if CP entry is a Q-descriptor
4473     __ movzbl(rcx, Address(rdx, rbx,
4474         Address::times_1,
4475         Array<u1>::base_offset_in_bytes()));
4476     __ andl (rcx, JVM_CONSTANT_QDescBit);
4477     __ cmpl(rcx, JVM_CONSTANT_QDescBit);
4478     __ jcc(Assembler::notEqual, done);
4479     __ jump(ExternalAddress(Interpreter::_throw_NullPointerException_entry));
4480   }
4481 
4482   __ bind(done);
4483 }
4484 
4485 void TemplateTable::instanceof() {
4486   transition(atos, itos);
4487   Label done, is_null, ok_is_subtype, quicked, resolved;
4488   __ testptr(rax, rax);
4489   __ jcc(Assembler::zero, is_null);
4490 
4491   // Get cpool & tags index
4492   __ get_cpool_and_tags(rcx, rdx); // rcx=cpool, rdx=tags array
4493   __ get_unsigned_2_byte_index_at_bcp(rbx, 1); // rbx=index
4494   // See if bytecode has already been quicked
4495   __ movzbl(rdx, Address(rdx, rbx,
4496         Address::times_1,
4497         Array<u1>::base_offset_in_bytes()));
4498   __ andl (rdx, ~JVM_CONSTANT_QDescBit);
4499   __ cmpl(rdx, JVM_CONSTANT_Class);
4500   __ jcc(Assembler::equal, quicked);
4501 
4502   __ push(atos); // save receiver for result, and for GC
4503   call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc));
4504   // vm_result_2 has metadata result
4505 
4506 #ifndef _LP64
4507   // borrow rdi from locals
4508   __ get_thread(rdi);
4509   __ get_vm_result_2(rax, rdi);
4510   __ restore_locals();
4511 #else
4512   __ get_vm_result_2(rax, r15_thread);
4513 #endif
4514 
4515   __ pop_ptr(rdx); // restore receiver
4516   __ verify_oop(rdx);
4517   Register tmp_load_klass = LP64_ONLY(rscratch1) NOT_LP64(noreg);
4518   __ load_klass(rdx, rdx, tmp_load_klass);
4519   __ jmpb(resolved);

4532   // Come here on failure
4533   __ xorl(rax, rax);
4534   __ jmpb(done);
4535   // Come here on success
4536   __ bind(ok_is_subtype);
4537   __ movl(rax, 1);
4538 
4539   // Collect counts on whether this test sees NULLs a lot or not.
4540   if (ProfileInterpreter) {
4541     __ jmp(done);
4542     __ bind(is_null);
4543     __ profile_null_seen(rcx);
4544   } else {
4545     __ bind(is_null);   // same as 'done'
4546   }
4547   __ bind(done);
4548   // rax = 0: obj == NULL or  obj is not an instanceof the specified klass
4549   // rax = 1: obj != NULL and obj is     an instanceof the specified klass
4550 }
4551 

4552 //----------------------------------------------------------------------------------------------------
4553 // Breakpoints
4554 void TemplateTable::_breakpoint() {
4555   // Note: We get here even if we are single stepping..
4556   // jbug insists on setting breakpoints at every bytecode
4557   // even if we are in single step mode.
4558 
4559   transition(vtos, vtos);
4560 
4561   Register rarg = LP64_ONLY(c_rarg1) NOT_LP64(rcx);
4562 
4563   // get the unpatched byte code
4564   __ get_method(rarg);
4565   __ call_VM(noreg,
4566              CAST_FROM_FN_PTR(address,
4567                               InterpreterRuntime::get_original_bytecode_at),
4568              rarg, rbcp);
4569   __ mov(rbx, rax);  // why?
4570 
4571   // post the breakpoint event

4593 // Note: monitorenter & exit are symmetric routines; which is reflected
4594 //       in the assembly code structure as well
4595 //
4596 // Stack layout:
4597 //
4598 // [expressions  ] <--- rsp               = expression stack top
4599 // ..
4600 // [expressions  ]
4601 // [monitor entry] <--- monitor block top = expression stack bot
4602 // ..
4603 // [monitor entry]
4604 // [frame data   ] <--- monitor block bot
4605 // ...
4606 // [saved rbp    ] <--- rbp
4607 void TemplateTable::monitorenter() {
4608   transition(atos, vtos);
4609 
4610   // check for NULL object
4611   __ null_check(rax);
4612 
4613   Label is_inline_type;
4614   __ movptr(rbx, Address(rax, oopDesc::mark_offset_in_bytes()));
4615   __ test_markword_is_inline_type(rbx, is_inline_type);
4616 
4617   const Address monitor_block_top(
4618         rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
4619   const Address monitor_block_bot(
4620         rbp, frame::interpreter_frame_initial_sp_offset * wordSize);
4621   const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
4622 
4623   Label allocated;
4624 
4625   Register rtop = LP64_ONLY(c_rarg3) NOT_LP64(rcx);
4626   Register rbot = LP64_ONLY(c_rarg2) NOT_LP64(rbx);
4627   Register rmon = LP64_ONLY(c_rarg1) NOT_LP64(rdx);
4628 
4629   // initialize entry pointer
4630   __ xorl(rmon, rmon); // points to free slot or NULL
4631 
4632   // find a free slot in the monitor block (result in rmon)
4633   {
4634     Label entry, loop, exit;
4635     __ movptr(rtop, monitor_block_top); // points to current entry,
4636                                         // starting with top-most entry

4686   // rmon: points to monitor entry
4687   __ bind(allocated);
4688 
4689   // Increment bcp to point to the next bytecode, so exception
4690   // handling for async. exceptions work correctly.
4691   // The object has already been poped from the stack, so the
4692   // expression stack looks correct.
4693   __ increment(rbcp);
4694 
4695   // store object
4696   __ movptr(Address(rmon, BasicObjectLock::obj_offset_in_bytes()), rax);
4697   __ lock_object(rmon);
4698 
4699   // check to make sure this monitor doesn't cause stack overflow after locking
4700   __ save_bcp();  // in case of exception
4701   __ generate_stack_overflow_check(0);
4702 
4703   // The bcp has already been incremented. Just need to dispatch to
4704   // next instruction.
4705   __ dispatch_next(vtos);
4706 
4707   __ bind(is_inline_type);
4708   __ call_VM(noreg, CAST_FROM_FN_PTR(address,
4709                     InterpreterRuntime::throw_illegal_monitor_state_exception));
4710   __ should_not_reach_here();
4711 }
4712 
4713 void TemplateTable::monitorexit() {
4714   transition(atos, vtos);
4715 
4716   // check for NULL object
4717   __ null_check(rax);
4718 
4719   const int is_inline_type_mask = markWord::inline_type_pattern;
4720   Label has_identity;
4721   __ movptr(rbx, Address(rax, oopDesc::mark_offset_in_bytes()));
4722   __ andptr(rbx, is_inline_type_mask);
4723   __ cmpl(rbx, is_inline_type_mask);
4724   __ jcc(Assembler::notEqual, has_identity);
4725   __ call_VM(noreg, CAST_FROM_FN_PTR(address,
4726                      InterpreterRuntime::throw_illegal_monitor_state_exception));
4727   __ should_not_reach_here();
4728   __ bind(has_identity);
4729 
4730   const Address monitor_block_top(
4731         rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
4732   const Address monitor_block_bot(
4733         rbp, frame::interpreter_frame_initial_sp_offset * wordSize);
4734   const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
4735 
4736   Register rtop = LP64_ONLY(c_rarg1) NOT_LP64(rdx);
4737   Register rbot = LP64_ONLY(c_rarg2) NOT_LP64(rbx);
4738 
4739   Label found;
4740 
4741   // find matching slot
4742   {
4743     Label entry, loop;
4744     __ movptr(rtop, monitor_block_top); // points to current entry,
4745                                         // starting with top-most entry
4746     __ lea(rbot, monitor_block_bot);    // points to word before bottom
4747                                         // of monitor block
4748     __ jmpb(entry);
4749 
< prev index next >