< 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 

 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, 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, 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   // Move subklass into rbx
1131   __ load_klass(rbx, rax, rscratch1);
1132   // Move superklass into rax
1133   __ load_klass(rax, rdx, rscratch1);
1134   __ movptr(rax, Address(rax,
1135                          ObjArrayKlass::element_klass_offset()));
1136 
1137   // Generate subtype check.  Blows rcx, rdi
1138   // Superklass in rax.  Subklass in rbx.
1139   __ gen_subtype_check(rbx, ok_is_subtype);

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

1158 









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







1161 



























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

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




































2332   __ cmpoop(rdx, rax);
2333   __ jcc(j_not(cc), not_taken);

2334   branch(false, false);
2335   __ bind(not_taken);
2336   __ profile_not_taken_branch(rax);









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

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

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

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

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








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

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

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





















































































2853   }
2854   __ jmp(Done);
2855 
2856   __ bind(notObj);



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

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






















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

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

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

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

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





















































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

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

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

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




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



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



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

















3369   case Bytecodes::_fast_aputfield:
3370     do_oop_store(_masm, field, rax);


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

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







































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

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






3936 
3937   // make sure klass is initialized & doesn't have finalizer
3938   // make sure klass is fully initialized
3939   __ cmpb(Address(rcx, InstanceKlass::init_state_offset()), InstanceKlass::fully_initialized);
3940   __ jcc(Assembler::notEqual, slow_case);
3941 
3942   // get instance_size in InstanceKlass (scaled to a count of bytes)
3943   __ movl(rdx, Address(rcx, Klass::layout_helper_offset()));
3944   // test to see if it has a finalizer or is malformed in some way
3945   __ testl(rdx, Klass::_lh_instance_slow_path_bit);
3946   __ jcc(Assembler::notZero, slow_case);
3947 
3948   // Allocate the instance:
3949   //  If TLAB is enabled:
3950   //    Try to allocate in the TLAB.
3951   //    If fails, go to the slow path.
3952   //    Initialize the allocation.
3953   //    Exit.
3954   //
3955   //  Go to slow path.
3956 
3957   const Register thread = LP64_ONLY(r15_thread) NOT_LP64(rcx);

3958 
3959   if (UseTLAB) {
3960     NOT_LP64(__ get_thread(thread);)
3961     __ tlab_allocate(thread, rax, rdx, 0, rcx, rbx, slow_case);
3962     if (ZeroTLAB) {
3963       // the fields have been already cleared
3964       __ jmp(initialize_header);
3965     }
3966 
3967     // The object is initialized before the header.  If the object size is
3968     // zero, go directly to the header initialization.
3969     __ decrement(rdx, sizeof(oopDesc));
3970     __ jcc(Assembler::zero, initialize_header);
3971 
3972     // Initialize topmost object field, divide rdx by 8, check if odd and
3973     // test if zero.
3974     __ xorl(rcx, rcx);    // use zero reg to clear memory (shorter code)
3975     __ shrl(rdx, LogBytesPerLong); // divide by 2*oopSize and set carry flag if odd
3976 
3977     // rdx must have been multiple of 8
3978 #ifdef ASSERT
3979     // make sure rdx was multiple of 8
3980     Label L;
3981     // Ignore partial flag stall after shrl() since it is debug VM
3982     __ jcc(Assembler::carryClear, L);
3983     __ stop("object size is not multiple of 2 - adjust this code");
3984     __ bind(L);
3985     // rdx must be > 0, no extra check needed here
3986 #endif
3987 
3988     // initialize remaining object fields: rdx was a multiple of 8
3989     { Label loop;
3990     __ bind(loop);
3991     __ movptr(Address(rax, rdx, Address::times_8, sizeof(oopDesc) - 1*oopSize), rcx);
3992     NOT_LP64(__ movptr(Address(rax, rdx, Address::times_8, sizeof(oopDesc) - 2*oopSize), rcx));
3993     __ decrement(rdx);
3994     __ jcc(Assembler::notZero, loop);
3995     }
3996 
3997     // initialize object header only.
3998     __ bind(initialize_header);
3999     __ movptr(Address(rax, oopDesc::mark_offset_in_bytes()),
4000               (intptr_t)markWord::prototype().value()); // header
4001     __ pop(rcx);   // get saved klass back in the register.
4002 #ifdef _LP64
4003     __ xorl(rsi, rsi); // use zero reg to clear memory (shorter code)
4004     __ store_klass_gap(rax, rsi);  // zero klass gap for compressed oops
4005 #endif
4006     __ store_klass(rax, rcx, rscratch1);  // klass
4007 
4008     {
4009       SkipIfEqual skip_if(_masm, &DTraceAllocProbes, 0, rscratch1);
4010       // Trigger dtrace event for fastpath
4011       __ push(atos);
4012       __ call_VM_leaf(
4013            CAST_FROM_FN_PTR(address, static_cast<int (*)(oopDesc*)>(SharedRuntime::dtrace_object_alloc)), rax);
4014       __ pop(atos);
4015     }
4016 
4017     __ jmp(done);
4018   }
















4019 
4020   // slow case
4021   __ bind(slow_case);
4022   __ pop(rcx);   // restore stack pointer to what it was when we came in.
4023   __ bind(slow_case_no_pop);
4024 
4025   Register rarg1 = LP64_ONLY(c_rarg1) NOT_LP64(rax);
4026   Register rarg2 = LP64_ONLY(c_rarg2) NOT_LP64(rdx);
4027 
4028   __ get_constant_pool(rarg1);
4029   __ get_unsigned_2_byte_index_at_bcp(rarg2, 1);
4030   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), rarg1, rarg2);
4031    __ verify_oop(rax);


4032 
4033   // continue
4034   __ bind(done);

4035 }
4036 
4037 void TemplateTable::newarray() {
4038   transition(itos, atos);
4039   Register rarg1 = LP64_ONLY(c_rarg1) NOT_LP64(rdx);
4040   __ load_unsigned_byte(rarg1, at_bcp(1));
4041   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::newarray),
4042           rarg1, rax);
4043 }
4044 
4045 void TemplateTable::anewarray() {
4046   transition(itos, atos);
4047 
4048   Register rarg1 = LP64_ONLY(c_rarg1) NOT_LP64(rcx);
4049   Register rarg2 = LP64_ONLY(c_rarg2) NOT_LP64(rdx);
4050 
4051   __ get_unsigned_2_byte_index_at_bcp(rarg2, 1);
4052   __ get_constant_pool(rarg1);
4053   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::anewarray),
4054           rarg1, rarg2, rax);
4055 }
4056 
4057 void TemplateTable::arraylength() {
4058   transition(atos, itos);
4059   __ null_check(rax, arrayOopDesc::length_offset_in_bytes());
4060   __ movl(rax, Address(rax, arrayOopDesc::length_offset_in_bytes()));
4061 }
4062 
4063 void TemplateTable::checkcast() {
4064   transition(atos, atos);
4065   Label done, is_null, ok_is_subtype, quicked, resolved;
4066   __ testptr(rax, rax); // object is in rax
4067   __ jcc(Assembler::zero, is_null);
4068 
4069   // Get cpool & tags index
4070   __ get_cpool_and_tags(rcx, rdx); // rcx=cpool, rdx=tags array
4071   __ get_unsigned_2_byte_index_at_bcp(rbx, 1); // rbx=index
4072   // See if bytecode has already been quicked
4073   __ cmpb(Address(rdx, rbx,
4074                   Address::times_1,
4075                   Array<u1>::base_offset_in_bytes()),
4076           JVM_CONSTANT_Class);

4077   __ jcc(Assembler::equal, quicked);
4078   __ push(atos); // save receiver for result, and for GC
4079   call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc));
4080 
4081   // vm_result_2 has metadata result
4082 #ifndef _LP64
4083   // borrow rdi from locals
4084   __ get_thread(rdi);
4085   __ get_vm_result_2(rax, rdi);
4086   __ restore_locals();
4087 #else
4088   __ get_vm_result_2(rax, r15_thread);
4089 #endif
4090 
4091   __ pop_ptr(rdx); // restore receiver
4092   __ jmpb(resolved);
4093 
4094   // Get superklass in rax and subklass in rbx
4095   __ bind(quicked);
4096   __ mov(rdx, rax); // Save object in rdx; rax needed for subtype check
4097   __ load_resolved_klass_at_index(rax, rcx, rbx);
4098 
4099   __ bind(resolved);
4100   __ load_klass(rbx, rdx, rscratch1);
4101 
4102   // Generate subtype check.  Blows rcx, rdi.  Object in rdx.
4103   // Superklass in rax.  Subklass in rbx.
4104   __ gen_subtype_check(rbx, ok_is_subtype);
4105 
4106   // Come here on failure
4107   __ push_ptr(rdx);
4108   // object is at TOS
4109   __ jump(ExternalAddress(Interpreter::_throw_ClassCastException_entry));
4110 
4111   // Come here on success
4112   __ bind(ok_is_subtype);
4113   __ mov(rax, rdx); // Restore object in rdx



4114 
4115   // Collect counts on whether this check-cast sees NULLs a lot or not.
4116   if (ProfileInterpreter) {
4117     __ jmp(done);
4118     __ bind(is_null);
4119     __ profile_null_seen(rcx);
4120   } else {
4121     __ bind(is_null);   // same as 'done'
4122   }















4123   __ bind(done);
4124 }
4125 
4126 void TemplateTable::instanceof() {
4127   transition(atos, itos);
4128   Label done, is_null, ok_is_subtype, quicked, resolved;
4129   __ testptr(rax, rax);
4130   __ jcc(Assembler::zero, is_null);
4131 
4132   // Get cpool & tags index
4133   __ get_cpool_and_tags(rcx, rdx); // rcx=cpool, rdx=tags array
4134   __ get_unsigned_2_byte_index_at_bcp(rbx, 1); // rbx=index
4135   // See if bytecode has already been quicked
4136   __ cmpb(Address(rdx, rbx,
4137                   Address::times_1,
4138                   Array<u1>::base_offset_in_bytes()),
4139           JVM_CONSTANT_Class);

4140   __ jcc(Assembler::equal, quicked);
4141 
4142   __ push(atos); // save receiver for result, and for GC
4143   call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc));
4144   // vm_result_2 has metadata result
4145 
4146 #ifndef _LP64
4147   // borrow rdi from locals
4148   __ get_thread(rdi);
4149   __ get_vm_result_2(rax, rdi);
4150   __ restore_locals();
4151 #else
4152   __ get_vm_result_2(rax, r15_thread);
4153 #endif
4154 
4155   __ pop_ptr(rdx); // restore receiver
4156   __ verify_oop(rdx);
4157   __ load_klass(rdx, rdx, rscratch1);
4158   __ jmpb(resolved);
4159 

4171   // Come here on failure
4172   __ xorl(rax, rax);
4173   __ jmpb(done);
4174   // Come here on success
4175   __ bind(ok_is_subtype);
4176   __ movl(rax, 1);
4177 
4178   // Collect counts on whether this test sees NULLs a lot or not.
4179   if (ProfileInterpreter) {
4180     __ jmp(done);
4181     __ bind(is_null);
4182     __ profile_null_seen(rcx);
4183   } else {
4184     __ bind(is_null);   // same as 'done'
4185   }
4186   __ bind(done);
4187   // rax = 0: obj == NULL or  obj is not an instanceof the specified klass
4188   // rax = 1: obj != NULL and obj is     an instanceof the specified klass
4189 }
4190 
4191 
4192 //----------------------------------------------------------------------------------------------------
4193 // Breakpoints
4194 void TemplateTable::_breakpoint() {
4195   // Note: We get here even if we are single stepping..
4196   // jbug insists on setting breakpoints at every bytecode
4197   // even if we are in single step mode.
4198 
4199   transition(vtos, vtos);
4200 
4201   Register rarg = LP64_ONLY(c_rarg1) NOT_LP64(rcx);
4202 
4203   // get the unpatched byte code
4204   __ get_method(rarg);
4205   __ call_VM(noreg,
4206              CAST_FROM_FN_PTR(address,
4207                               InterpreterRuntime::get_original_bytecode_at),
4208              rarg, rbcp);
4209   __ mov(rbx, rax);  // why?
4210 
4211   // post the breakpoint event

4233 // Note: monitorenter & exit are symmetric routines; which is reflected
4234 //       in the assembly code structure as well
4235 //
4236 // Stack layout:
4237 //
4238 // [expressions  ] <--- rsp               = expression stack top
4239 // ..
4240 // [expressions  ]
4241 // [monitor entry] <--- monitor block top = expression stack bot
4242 // ..
4243 // [monitor entry]
4244 // [frame data   ] <--- monitor block bot
4245 // ...
4246 // [saved rbp    ] <--- rbp
4247 void TemplateTable::monitorenter() {
4248   transition(atos, vtos);
4249 
4250   // check for NULL object
4251   __ null_check(rax);
4252 




4253   const Address monitor_block_top(
4254         rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
4255   const Address monitor_block_bot(
4256         rbp, frame::interpreter_frame_initial_sp_offset * wordSize);
4257   const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
4258 
4259   Label allocated;
4260 
4261   Register rtop = LP64_ONLY(c_rarg3) NOT_LP64(rcx);
4262   Register rbot = LP64_ONLY(c_rarg2) NOT_LP64(rbx);
4263   Register rmon = LP64_ONLY(c_rarg1) NOT_LP64(rdx);
4264 
4265   // initialize entry pointer
4266   __ xorl(rmon, rmon); // points to free slot or NULL
4267 
4268   // find a free slot in the monitor block (result in rmon)
4269   {
4270     Label entry, loop, exit;
4271     __ movptr(rtop, monitor_block_top); // points to current entry,
4272                                         // starting with top-most entry

4322   // rmon: points to monitor entry
4323   __ bind(allocated);
4324 
4325   // Increment bcp to point to the next bytecode, so exception
4326   // handling for async. exceptions work correctly.
4327   // The object has already been popped from the stack, so the
4328   // expression stack looks correct.
4329   __ increment(rbcp);
4330 
4331   // store object
4332   __ movptr(Address(rmon, BasicObjectLock::obj_offset_in_bytes()), rax);
4333   __ lock_object(rmon);
4334 
4335   // check to make sure this monitor doesn't cause stack overflow after locking
4336   __ save_bcp();  // in case of exception
4337   __ generate_stack_overflow_check(0);
4338 
4339   // The bcp has already been incremented. Just need to dispatch to
4340   // next instruction.
4341   __ dispatch_next(vtos);





4342 }
4343 
4344 void TemplateTable::monitorexit() {
4345   transition(atos, vtos);
4346 
4347   // check for NULL object
4348   __ null_check(rax);
4349 











4350   const Address monitor_block_top(
4351         rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
4352   const Address monitor_block_bot(
4353         rbp, frame::interpreter_frame_initial_sp_offset * wordSize);
4354   const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
4355 
4356   Register rtop = LP64_ONLY(c_rarg1) NOT_LP64(rdx);
4357   Register rbot = LP64_ONLY(c_rarg2) NOT_LP64(rbx);
4358 
4359   Label found;
4360 
4361   // find matching slot
4362   {
4363     Label entry, loop;
4364     __ movptr(rtop, monitor_block_top); // points to current entry,
4365                                         // starting with top-most entry
4366     __ lea(rbot, monitor_block_bot);    // points to word before bottom
4367                                         // of monitor block
4368     __ jmpb(entry);
4369 

  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 

 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, 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, 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   __ load_klass(rdi, rdx, rscratch1);
1157   if (UseFlatArray) {
1158     __ movl(rbx, Address(rdi, Klass::layout_helper_offset()));
1159     __ test_flattened_array_layout(rbx, is_flat_array);
1160   }
1161 
1162   // Move subklass into rbx
1163   __ load_klass(rbx, rax, rscratch1);
1164   // Move array element superklass into rax
1165   __ movptr(rax, Address(rdi,

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

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

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

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


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

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

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

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

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

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

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

3746     __ push_ptr(rax);  // save object pointer before call_VM() clobbers it
3747     LP64_ONLY(__ mov(c_rarg1, rax));
3748     // c_rarg1: object pointer copied above
3749     // c_rarg2: cache entry pointer
3750     LP64_ONLY(__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access), c_rarg1, c_rarg2));
3751     NOT_LP64(__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access), rax, rcx));
3752     __ pop_ptr(rax); // restore object pointer
3753     __ bind(L1);
3754   }
3755 
3756   // access constant pool cache
3757   __ get_cache_and_index_at_bcp(rcx, rbx, 1);
3758   // replace index with field offset from cache entry
3759   // [jk] not needed currently
3760   // __ movl(rdx, Address(rcx, rbx, Address::times_8,
3761   //                      in_bytes(ConstantPoolCache::base_offset() +
3762   //                               ConstantPoolCacheEntry::flags_offset())));
3763   // __ shrl(rdx, ConstantPoolCacheEntry::is_volatile_shift);
3764   // __ andl(rdx, 0x1);
3765   //
3766   __ movptr(rdx, Address(rcx, rbx, Address::times_ptr,
3767                          in_bytes(ConstantPoolCache::base_offset() +
3768                                   ConstantPoolCacheEntry::f2_offset())));
3769 
3770   // rax: object
3771   __ verify_oop(rax);
3772   __ null_check(rax);
3773   Address field(rax, rdx, Address::times_1);
3774 
3775   // access field
3776   switch (bytecode()) {
3777   case Bytecodes::_fast_qgetfield:
3778     {
3779       Label is_inlined, nonnull, Done;
3780       __ movptr(rscratch1, Address(rcx, rbx, Address::times_ptr,
3781                                    in_bytes(ConstantPoolCache::base_offset() +
3782                                             ConstantPoolCacheEntry::flags_offset())));
3783       __ test_field_is_inlined(rscratch1, rscratch2, is_inlined);
3784         // field is not inlined
3785         __ load_heap_oop(rax, field);
3786         __ testptr(rax, rax);
3787         __ jcc(Assembler::notZero, nonnull);
3788           __ movl(rdx, Address(rcx, rbx, Address::times_ptr,
3789                              in_bytes(ConstantPoolCache::base_offset() +
3790                                       ConstantPoolCacheEntry::flags_offset())));
3791           __ andl(rdx, ConstantPoolCacheEntry::field_index_mask);
3792           __ movptr(rcx, Address(rcx, rbx, Address::times_ptr,
3793                                        in_bytes(ConstantPoolCache::base_offset() +
3794                                                 ConstantPoolCacheEntry::f1_offset())));
3795           __ get_inline_type_field_klass(rcx, rdx, rbx);
3796           __ get_default_value_oop(rbx, rcx, rax);
3797         __ bind(nonnull);
3798         __ verify_oop(rax);
3799         __ jmp(Done);
3800       __ bind(is_inlined);
3801       // field is inlined
3802         __ push(rdx); // save offset
3803         __ movl(rdx, Address(rcx, rbx, Address::times_ptr,
3804                            in_bytes(ConstantPoolCache::base_offset() +
3805                                     ConstantPoolCacheEntry::flags_offset())));
3806         __ andl(rdx, ConstantPoolCacheEntry::field_index_mask);
3807         __ movptr(rcx, Address(rcx, rbx, Address::times_ptr,
3808                                      in_bytes(ConstantPoolCache::base_offset() +
3809                                               ConstantPoolCacheEntry::f1_offset())));
3810         __ pop(rbx); // restore offset
3811         __ read_inlined_field(rcx, rdx, rbx, rax);
3812       __ bind(Done);
3813       __ verify_oop(rax);
3814     }
3815     break;
3816   case Bytecodes::_fast_agetfield:
3817     do_oop_load(_masm, field, rax);
3818     __ verify_oop(rax);
3819     break;
3820   case Bytecodes::_fast_lgetfield:
3821 #ifdef _LP64
3822     __ access_load_at(T_LONG, IN_HEAP, noreg /* ltos */, field, noreg, noreg);
3823 #else
3824   __ stop("should not be rewritten");
3825 #endif
3826     break;
3827   case Bytecodes::_fast_igetfield:
3828     __ access_load_at(T_INT, IN_HEAP, rax, field, noreg, noreg);
3829     break;
3830   case Bytecodes::_fast_bgetfield:
3831     __ access_load_at(T_BYTE, IN_HEAP, rax, field, noreg, noreg);
3832     break;
3833   case Bytecodes::_fast_sgetfield:
3834     __ access_load_at(T_SHORT, IN_HEAP, rax, field, noreg, noreg);
3835     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()), InlineKlassKind);
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::aconst_init() {
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()), InlineKlassKind);
4350   __ jcc(Assembler::equal, is_value);
4351 
4352   // in the future, aconst_init 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::aconst_init),
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   __ load_klass(rbx, rdx, rscratch1);
4445 
4446   // Generate subtype check.  Blows rcx, rdi.  Object in rdx.
4447   // Superklass in rax.  Subklass in rbx.
4448   __ gen_subtype_check(rbx, ok_is_subtype);
4449 
4450   // Come here on failure
4451   __ push_ptr(rdx);
4452   // object is at TOS
4453   __ jump(ExternalAddress(Interpreter::_throw_ClassCastException_entry));
4454 
4455   // Come here on success
4456   __ bind(ok_is_subtype);
4457   __ mov(rax, rdx); // Restore object in rdx
4458   __ jmp(done);
4459 
4460   __ bind(is_null);
4461 
4462   // Collect counts on whether this check-cast sees NULLs a lot or not.
4463   if (ProfileInterpreter) {


4464     __ profile_null_seen(rcx);


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

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

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

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

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