< 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(LdcType type) {
 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 (is_ldc_wide(type)) {
 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, is_ldc_wide(type) ? 1 : 0);
 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(LdcType type) {
 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 (is_ldc_wide(type)) {
 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, is_ldc_wide(type) ? 1 : 0);
 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 (EnablePrimitiveClasses) {
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 (UseFlatArray) {
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 (!EnablePrimitiveClasses) {
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       Label is_null_free_inline_type, uninitialized;
2993       // Issue below if the static field has not been initialized yet
2994       __ test_field_is_null_free_inline_type(flags2, rscratch1, is_null_free_inline_type);
2995         // field is not a null free inline type
2996         __ push(atos);
2997         __ jmp(Done);
2998       // field is a null free inline type, must not return null even if uninitialized
2999       __ bind(is_null_free_inline_type);
3000           __ testptr(rax, rax);
3001         __ jcc(Assembler::zero, uninitialized);
3002           __ push(atos);
3003           __ jmp(Done);
3004         __ bind(uninitialized);
3005           __ andl(flags2, ConstantPoolCacheEntry::field_index_mask);
3006 #ifdef _LP64
3007           Label slow_case, finish;
3008           __ movptr(rbx, Address(obj, java_lang_Class::klass_offset()));
3009           __ cmpb(Address(rbx, InstanceKlass::init_state_offset()), InstanceKlass::fully_initialized);
3010           __ jcc(Assembler::notEqual, slow_case);
3011         __ get_default_value_oop(rbx, rscratch1, rax);
3012         __ jmp(finish);
3013         __ bind(slow_case);
3014 #endif // LP64
3015           __ call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::uninitialized_static_inline_type_field),
3016                 obj, flags2);
3017 #ifdef _LP64
3018           __ bind(finish);
3019   #endif // _LP64
3020         __ verify_oop(rax);
3021         __ push(atos);
3022         __ jmp(Done);
3023     } else {
3024       Label is_inlined, nonnull, is_inline_type, rewrite_inline;
3025       __ test_field_is_null_free_inline_type(flags2, rscratch1, is_inline_type);
3026       // field is not a null free inline type
3027       pop_and_check_object(obj);
3028       __ load_heap_oop(rax, field);
3029       __ push(atos);
3030       if (rc == may_rewrite) {
3031         patch_bytecode(Bytecodes::_fast_agetfield, bc, rbx);
3032       }
3033       __ jmp(Done);
3034       __ bind(is_inline_type);
3035         __ test_field_is_inlined(flags2, rscratch1, is_inlined);
3036           // field is not inlined
3037           __ movptr(rax, rcx);  // small dance required to preserve the klass_holder somewhere
3038           pop_and_check_object(obj);
3039           __ push(rax);
3040           __ load_heap_oop(rax, field);
3041           __ pop(rcx);
3042           __ testptr(rax, rax);
3043           __ jcc(Assembler::notZero, nonnull);
3044             __ andl(flags2, ConstantPoolCacheEntry::field_index_mask);
3045             __ get_inline_type_field_klass(rcx, flags2, rbx);
3046             __ get_default_value_oop(rbx, rcx, rax);
3047           __ bind(nonnull);
3048           __ verify_oop(rax);
3049           __ push(atos);
3050           __ jmp(rewrite_inline);
3051         __ bind(is_inlined);
3052         // field is inlined
3053           __ andl(flags2, ConstantPoolCacheEntry::field_index_mask);
3054           pop_and_check_object(rax);
3055           __ read_inlined_field(rcx, flags2, rbx, rax);
3056           __ verify_oop(rax);
3057           __ push(atos);
3058       __ bind(rewrite_inline);
3059       if (rc == may_rewrite) {
3060         patch_bytecode(Bytecodes::_fast_qgetfield, bc, rbx);
3061       }
3062         __ jmp(Done);
3063     }
3064   }

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

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

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

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

3422   }
3423 
3424   __ bind(notObj);
3425   __ cmpl(flags, itos);
3426   __ jcc(Assembler::notEqual, notInt);
3427 
3428   // itos
3429   {
3430     __ pop(itos);
3431     if (!is_static) pop_and_check_object(obj);
3432     __ access_store_at(T_INT, IN_HEAP, field, rax, noreg, noreg, noreg);
3433     if (!is_static && rc == may_rewrite) {
3434       patch_bytecode(Bytecodes::_fast_iputfield, bc, rbx, true, byte_no);
3435     }
3436     __ jmp(Done);
3437   }
3438 
3439   __ bind(notInt);
3440   __ cmpl(flags, ctos);
3441   __ jcc(Assembler::notEqual, notChar);

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

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

4253 
4254   // Note:  rax_callsite is already pushed by prepare_invoke
4255 
4256   // %%% should make a type profile for any invokedynamic that takes a ref argument
4257   // profile this call
4258   __ profile_call(rbcp);
4259   __ profile_arguments_type(rdx, rbx_method, rbcp, false);
4260 
4261   __ verify_oop(rax_callsite);
4262 
4263   __ jump_from_interpreted(rbx_method, rdx);
4264 }
4265 
4266 //-----------------------------------------------------------------------------
4267 // Allocation
4268 
4269 void TemplateTable::_new() {
4270   transition(vtos, atos);
4271   __ get_unsigned_2_byte_index_at_bcp(rdx, 1);
4272   Label slow_case;

4273   Label done;
4274   Label is_not_value;
4275 
4276   __ get_cpool_and_tags(rcx, rax);
4277 
4278   // Make sure the class we're about to instantiate has been resolved.
4279   // This is done before loading InstanceKlass to be consistent with the order
4280   // how Constant Pool is updated (see ConstantPool::klass_at_put)
4281   const int tags_offset = Array<u1>::base_offset_in_bytes();
4282   __ cmpb(Address(rax, rdx, Address::times_1, tags_offset), JVM_CONSTANT_Class);
4283   __ jcc(Assembler::notEqual, slow_case);
4284 
4285   // get InstanceKlass
4286   __ load_resolved_klass_at_index(rcx, rcx, rdx);
4287 
4288   __ cmpb(Address(rcx, InstanceKlass::kind_offset()), InlineKlassKind);
4289   __ jcc(Assembler::notEqual, is_not_value);
4290 
4291   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_InstantiationError));
4292 
4293   __ bind(is_not_value);
4294 
4295   // make sure klass is initialized & doesn't have finalizer

4296   __ cmpb(Address(rcx, InstanceKlass::init_state_offset()), InstanceKlass::fully_initialized);
4297   __ jcc(Assembler::notEqual, slow_case);
4298 
4299   __ allocate_instance(rcx, rax, rdx, rbx, true, slow_case);
4300   __ jmp(done);












4301 
4302   // slow case
4303   __ bind(slow_case);
4304 
4305   Register rarg1 = LP64_ONLY(c_rarg1) NOT_LP64(rax);
4306   Register rarg2 = LP64_ONLY(c_rarg2) NOT_LP64(rdx);





4307 
4308   __ get_constant_pool(rarg1);
4309   __ get_unsigned_2_byte_index_at_bcp(rarg2, 1);
4310   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), rarg1, rarg2);
4311    __ verify_oop(rax);
4312 
4313   // continue
4314   __ bind(done);
4315 }

4316 
4317 void TemplateTable::aconst_init() {
4318   transition(vtos, atos);








4319 
4320   Label slow_case;
4321   Label done;
4322   Label is_value;





4323 
4324   __ get_unsigned_2_byte_index_at_bcp(rdx, 1);
4325   __ get_cpool_and_tags(rcx, rax);








4326 
4327   // Make sure the class we're about to instantiate has been resolved.
4328   // This is done before loading InstanceKlass to be consistent with the order
4329   // how Constant Pool is updated (see ConstantPool::klass_at_put)
4330   const int tags_offset = Array<u1>::base_offset_in_bytes();
4331   __ cmpb(Address(rax, rdx, Address::times_1, tags_offset), JVM_CONSTANT_Class);
4332   __ jcc(Assembler::notEqual, slow_case);


4333 
4334   // get InstanceKlass
4335   __ load_resolved_klass_at_index(rcx, rcx, rdx);
4336 
4337   __ cmpb(Address(rcx, InstanceKlass::kind_offset()), InlineKlassKind);
4338   __ jcc(Assembler::equal, is_value);
4339 
4340   // in the future, aconst_init will just return null instead of throwing an exception
4341   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_IncompatibleClassChangeError));
4342 
4343   __ bind(is_value);
4344 
4345   // make sure klass is fully initialized
4346   __ cmpb(Address(rcx, InstanceKlass::init_state_offset()), InstanceKlass::fully_initialized);
4347   __ jcc(Assembler::notEqual, slow_case);
4348 
4349   // have a resolved InlineKlass in rcx, return the default value oop from it
4350   __ get_default_value_oop(rcx, rdx, rax);
4351   __ jmp(done);
4352 

4353   __ bind(slow_case);


4354 
4355   Register rarg1 = LP64_ONLY(c_rarg1) NOT_LP64(rcx);
4356   Register rarg2 = LP64_ONLY(c_rarg2) NOT_LP64(rdx);
4357 

4358   __ get_unsigned_2_byte_index_at_bcp(rarg2, 1);
4359   __ get_constant_pool(rarg1);
4360 
4361   call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::aconst_init),
4362       rarg1, rarg2);
4363 

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


4452     __ profile_null_seen(rcx);


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

4518   // Come here on failure
4519   __ xorl(rax, rax);
4520   __ jmpb(done);
4521   // Come here on success
4522   __ bind(ok_is_subtype);
4523   __ movl(rax, 1);
4524 
4525   // Collect counts on whether this test sees NULLs a lot or not.
4526   if (ProfileInterpreter) {
4527     __ jmp(done);
4528     __ bind(is_null);
4529     __ profile_null_seen(rcx);
4530   } else {
4531     __ bind(is_null);   // same as 'done'
4532   }
4533   __ bind(done);
4534   // rax = 0: obj == NULL or  obj is not an instanceof the specified klass
4535   // rax = 1: obj != NULL and obj is     an instanceof the specified klass
4536 }
4537 

4538 //----------------------------------------------------------------------------------------------------
4539 // Breakpoints
4540 void TemplateTable::_breakpoint() {
4541   // Note: We get here even if we are single stepping..
4542   // jbug insists on setting breakpoints at every bytecode
4543   // even if we are in single step mode.
4544 
4545   transition(vtos, vtos);
4546 
4547   Register rarg = LP64_ONLY(c_rarg1) NOT_LP64(rcx);
4548 
4549   // get the unpatched byte code
4550   __ get_method(rarg);
4551   __ call_VM(noreg,
4552              CAST_FROM_FN_PTR(address,
4553                               InterpreterRuntime::get_original_bytecode_at),
4554              rarg, rbcp);
4555   __ mov(rbx, rax);  // why?
4556 
4557   // post the breakpoint event

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

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