< prev index next >

src/hotspot/cpu/aarch64/templateTable_aarch64.cpp

Print this page

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

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

 737   locals_index_wide(r1);
 738   __ ldr(r0, aaddress(r1));
 739 }
 740 
 741 void TemplateTable::index_check(Register array, Register index)
 742 {
 743   // destroys r1, rscratch1
 744   // sign extend index for use by indexed load
 745   // __ movl2ptr(index, index);
 746   // check index
 747   Register length = rscratch1;
 748   __ ldrw(length, Address(array, arrayOopDesc::length_offset_in_bytes()));
 749   __ cmpw(index, length);
 750   if (index != r1) {
 751     // ??? convention: move aberrant index into r1 for exception message
 752     assert(r1 != array, "different registers");
 753     __ mov(r1, index);
 754   }
 755   Label ok;
 756   __ br(Assembler::LO, ok);
 757     // ??? convention: move array into r3 for exception message
 758   __ mov(r3, array);
 759   __ mov(rscratch1, Interpreter::_throw_ArrayIndexOutOfBoundsException_entry);
 760   __ br(rscratch1);
 761   __ bind(ok);
 762 }
 763 
 764 void TemplateTable::iaload()
 765 {
 766   transition(itos, itos);
 767   __ mov(r1, r0);
 768   __ pop_ptr(r0);
 769   // r0: array
 770   // r1: index
 771   index_check(r0, r1); // leaves index in r1, kills rscratch1
 772   __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_INT) >> 2);
 773   __ access_load_at(T_INT, IN_HEAP | IS_ARRAY, r0, Address(r0, r1, Address::uxtw(2)), noreg, noreg);
 774 }
 775 
 776 void TemplateTable::laload()
 777 {
 778   transition(itos, ltos);
 779   __ mov(r1, r0);
 780   __ pop_ptr(r0);

 800 void TemplateTable::daload()
 801 {
 802   transition(itos, dtos);
 803   __ mov(r1, r0);
 804   __ pop_ptr(r0);
 805   // r0: array
 806   // r1: index
 807   index_check(r0, r1); // leaves index in r1, kills rscratch1
 808   __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_DOUBLE) >> 3);
 809   __ access_load_at(T_DOUBLE, IN_HEAP | IS_ARRAY, r0, Address(r0, r1, Address::uxtw(3)), noreg, noreg);
 810 }
 811 
 812 void TemplateTable::aaload()
 813 {
 814   transition(itos, atos);
 815   __ mov(r1, r0);
 816   __ pop_ptr(r0);
 817   // r0: array
 818   // r1: index
 819   index_check(r0, r1); // leaves index in r1, kills rscratch1
 820   __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_OBJECT) >> LogBytesPerHeapOop);
 821   do_oop_load(_masm,
 822               Address(r0, r1, Address::uxtw(LogBytesPerHeapOop)),
 823               r0,
 824               IS_ARRAY);















 825 }
 826 
 827 void TemplateTable::baload()
 828 {
 829   transition(itos, itos);
 830   __ mov(r1, r0);
 831   __ pop_ptr(r0);
 832   // r0: array
 833   // r1: index
 834   index_check(r0, r1); // leaves index in r1, kills rscratch1
 835   __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_BYTE) >> 0);
 836   __ access_load_at(T_BYTE, IN_HEAP | IS_ARRAY, r0, Address(r0, r1, Address::uxtw(0)), noreg, noreg);
 837 }
 838 
 839 void TemplateTable::caload()
 840 {
 841   transition(itos, itos);
 842   __ mov(r1, r0);
 843   __ pop_ptr(r0);
 844   // r0: array

1091   // r1:  index
1092   // r3:  array
1093   index_check(r3, r1); // prefer index in r1
1094   __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_FLOAT) >> 2);
1095   __ access_store_at(T_FLOAT, IN_HEAP | IS_ARRAY, Address(r3, r1, Address::uxtw(2)), noreg /* ftos */, noreg, noreg, noreg);
1096 }
1097 
1098 void TemplateTable::dastore() {
1099   transition(dtos, vtos);
1100   __ pop_i(r1);
1101   __ pop_ptr(r3);
1102   // v0: value
1103   // r1:  index
1104   // r3:  array
1105   index_check(r3, r1); // prefer index in r1
1106   __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_DOUBLE) >> 3);
1107   __ access_store_at(T_DOUBLE, IN_HEAP | IS_ARRAY, Address(r3, r1, Address::uxtw(3)), noreg /* dtos */, noreg, noreg, noreg);
1108 }
1109 
1110 void TemplateTable::aastore() {
1111   Label is_null, ok_is_subtype, done;
1112   transition(vtos, vtos);
1113   // stack: ..., array, index, value
1114   __ ldr(r0, at_tos());    // value
1115   __ ldr(r2, at_tos_p1()); // index
1116   __ ldr(r3, at_tos_p2()); // array
1117 
1118   Address element_address(r3, r4, Address::uxtw(LogBytesPerHeapOop));
1119 
1120   index_check(r3, r2);     // kills r1




1121   __ add(r4, r2, arrayOopDesc::base_offset_in_bytes(T_OBJECT) >> LogBytesPerHeapOop);


1122 
1123   // do array store check - check for null value first
1124   __ cbz(r0, is_null);
1125 








1126   // Move subklass into r1
1127   __ load_klass(r1, r0);
1128   // Move superklass into r0
1129   __ load_klass(r0, r3);
1130   __ ldr(r0, Address(r0,
1131                      ObjArrayKlass::element_klass_offset()));
1132   // Compress array + index*oopSize + 12 into a single register.  Frees r2.
1133 
1134   // Generate subtype check.  Blows r2, r5
1135   // Superklass in r0.  Subklass in r1.
1136   __ gen_subtype_check(r1, ok_is_subtype);


1137 
1138   // Come here on failure
1139   // object is at TOS
1140   __ b(Interpreter::_throw_ArrayStoreException_entry);
1141 
1142   // Come here on success
1143   __ bind(ok_is_subtype);
1144 
1145   // Get the value we will store
1146   __ ldr(r0, at_tos());
1147   // Now store using the appropriate barrier
1148   do_oop_store(_masm, element_address, r0, IS_ARRAY);
1149   __ b(done);
1150 
1151   // Have a null in r0, r3=array, r2=index.  Store null at ary[idx]
1152   __ bind(is_null);
1153   __ profile_null_seen(r2);











1154 
1155   // Store a null
1156   do_oop_store(_masm, element_address, noreg, IS_ARRAY);









































1157 
1158   // Pop stack arguments
1159   __ bind(done);
1160   __ add(esp, esp, 3 * Interpreter::stackElementSize);
1161 }
1162 
1163 void TemplateTable::bastore()
1164 {
1165   transition(itos, vtos);
1166   __ pop_i(r1);
1167   __ pop_ptr(r3);
1168   // r0: value
1169   // r1: index
1170   // r3: array
1171   index_check(r3, r1); // prefer index in r1
1172 
1173   // Need to check whether array is boolean or byte
1174   // since both types share the bastore bytecode.
1175   __ load_klass(r2, r3);
1176   __ ldrw(r2, Address(r2, Klass::layout_helper_offset()));

1941   __ br(j_not(cc), not_taken);
1942   branch(false, false);
1943   __ bind(not_taken);
1944   __ profile_not_taken_branch(r0);
1945 }
1946 
1947 void TemplateTable::if_nullcmp(Condition cc)
1948 {
1949   transition(atos, vtos);
1950   // assume branch is more often taken than not (loops use backward branches)
1951   Label not_taken;
1952   if (cc == equal)
1953     __ cbnz(r0, not_taken);
1954   else
1955     __ cbz(r0, not_taken);
1956   branch(false, false);
1957   __ bind(not_taken);
1958   __ profile_not_taken_branch(r0);
1959 }
1960 
1961 void TemplateTable::if_acmp(Condition cc)
1962 {
1963   transition(atos, vtos);
1964   // assume branch is more often taken than not (loops use backward branches)
1965   Label not_taken;
1966   __ pop_ptr(r1);






































1967   __ cmpoop(r1, r0);
1968   __ br(j_not(cc), not_taken);

1969   branch(false, false);
1970   __ bind(not_taken);
1971   __ profile_not_taken_branch(r0);
1972 }
1973 










1974 void TemplateTable::ret() {
1975   transition(vtos, vtos);
1976   locals_index(r1);
1977   __ ldr(r1, aaddress(r1)); // get return bci, compute return bcp
1978   __ profile_ret(r1, r2);
1979   __ ldr(rbcp, Address(rmethod, Method::const_offset()));
1980   __ lea(rbcp, Address(rbcp, r1));
1981   __ add(rbcp, rbcp, in_bytes(ConstMethod::codes_offset()));
1982   __ dispatch_next(vtos, 0, /*generate_poll*/true);
1983 }
1984 
1985 void TemplateTable::wide_ret() {
1986   transition(vtos, vtos);
1987   locals_index_wide(r1);
1988   __ ldr(r1, aaddress(r1)); // get return bci, compute return bcp
1989   __ profile_ret(r1, r2);
1990   __ ldr(rbcp, Address(rmethod, Method::const_offset()));
1991   __ lea(rbcp, Address(rbcp, r1));
1992   __ add(rbcp, rbcp, in_bytes(ConstMethod::codes_offset()));
1993   __ dispatch_next(vtos, 0, /*generate_poll*/true);

2563     }
2564     // c_rarg1: object pointer or null
2565     // c_rarg2: cache entry pointer
2566     __ call_VM(noreg, CAST_FROM_FN_PTR(address,
2567                                        InterpreterRuntime::post_field_access),
2568                c_rarg1, c_rarg2);
2569     __ load_field_entry(cache, index);
2570     __ bind(L1);
2571   }
2572 }
2573 
2574 void TemplateTable::pop_and_check_object(Register r)
2575 {
2576   __ pop_ptr(r);
2577   __ null_check(r);  // for field access must check obj.
2578   __ verify_oop(r);
2579 }
2580 
2581 void TemplateTable::getfield_or_static(int byte_no, bool is_static, RewriteControl rc)
2582 {
2583   const Register cache     = r4;
2584   const Register obj       = r4;



2585   const Register index     = r3;
2586   const Register tos_state = r3;
2587   const Register off       = r19;
2588   const Register flags     = r6;
2589   const Register bc        = r4; // uses same reg as obj, so don't mix them
2590 
2591   resolve_cache_and_index_for_field(byte_no, cache, index);
2592   jvmti_post_field_access(cache, index, is_static, false);





2593   load_resolved_field_entry(obj, cache, tos_state, off, flags, is_static);
2594 
2595   if (!is_static) {
2596     // obj is on the stack
2597     pop_and_check_object(obj);
2598   }
2599 
2600   // 8179954: We need to make sure that the code generated for
2601   // volatile accesses forms a sequentially-consistent set of
2602   // operations when combined with STLR and LDAR.  Without a leading
2603   // membar it's possible for a simple Dekker test to fail if loads
2604   // use LDR;DMB but stores use STLR.  This can happen if C2 compiles
2605   // the stores in one method and we interpret the loads in another.
2606   if (!CompilerConfig::is_c1_or_interpreter_only_no_jvmci()){
2607     Label notVolatile;
2608     __ tbz(flags, ResolvedFieldEntry::is_volatile_shift, notVolatile);
2609     __ membar(MacroAssembler::AnyAny);
2610     __ bind(notVolatile);
2611   }
2612 

2631   __ b(Done);
2632 
2633   __ bind(notByte);
2634   __ cmp(tos_state, (u1)ztos);
2635   __ br(Assembler::NE, notBool);
2636 
2637   // ztos (same code as btos)
2638   __ access_load_at(T_BOOLEAN, IN_HEAP, r0, field, noreg, noreg);
2639   __ push(ztos);
2640   // Rewrite bytecode to be faster
2641   if (rc == may_rewrite) {
2642     // use btos rewriting, no truncating to t/f bit is needed for getfield.
2643     patch_bytecode(Bytecodes::_fast_bgetfield, bc, r1);
2644   }
2645   __ b(Done);
2646 
2647   __ bind(notBool);
2648   __ cmp(tos_state, (u1)atos);
2649   __ br(Assembler::NE, notObj);
2650   // atos
2651   do_oop_load(_masm, field, r0, IN_HEAP);
2652   __ push(atos);
2653   if (rc == may_rewrite) {
2654     patch_bytecode(Bytecodes::_fast_agetfield, bc, r1);





































































2655   }
2656   __ b(Done);
2657 
2658   __ bind(notObj);
2659   __ cmp(tos_state, (u1)itos);
2660   __ br(Assembler::NE, notInt);
2661   // itos
2662   __ access_load_at(T_INT, IN_HEAP, r0, field, noreg, noreg);
2663   __ push(itos);
2664   // Rewrite bytecode to be faster
2665   if (rc == may_rewrite) {
2666     patch_bytecode(Bytecodes::_fast_igetfield, bc, r1);
2667   }
2668   __ b(Done);
2669 
2670   __ bind(notInt);
2671   __ cmp(tos_state, (u1)ctos);
2672   __ br(Assembler::NE, notChar);
2673   // ctos
2674   __ access_load_at(T_CHAR, IN_HEAP, r0, field, noreg, noreg);
2675   __ push(ctos);
2676   // Rewrite bytecode to be faster

2797     // c_rarg1: object pointer set up above (null if static)
2798     // c_rarg2: cache entry pointer
2799     // c_rarg3: jvalue object on the stack
2800     __ call_VM(noreg,
2801                CAST_FROM_FN_PTR(address,
2802                                 InterpreterRuntime::post_field_modification),
2803                c_rarg1, c_rarg2, c_rarg3);
2804     __ load_field_entry(cache, index);
2805     __ bind(L1);
2806   }
2807 }
2808 
2809 void TemplateTable::putfield_or_static(int byte_no, bool is_static, RewriteControl rc) {
2810   transition(vtos, vtos);
2811 
2812   const Register cache     = r2;
2813   const Register index     = r3;
2814   const Register tos_state = r3;
2815   const Register obj       = r2;
2816   const Register off       = r19;
2817   const Register flags     = r0;
2818   const Register bc        = r4;

2819 
2820   resolve_cache_and_index_for_field(byte_no, cache, index);
2821   jvmti_post_field_mod(cache, index, is_static);
2822   load_resolved_field_entry(obj, cache, tos_state, off, flags, is_static);
2823 
2824   Label Done;
2825   __ mov(r5, flags);
2826 
2827   {
2828     Label notVolatile;
2829     __ tbz(r5, ResolvedFieldEntry::is_volatile_shift, notVolatile);
2830     __ membar(MacroAssembler::StoreStore | MacroAssembler::LoadStore);
2831     __ bind(notVolatile);
2832   }
2833 
2834   // field address
2835   const Address field(obj, off);
2836 
2837   Label notByte, notBool, notInt, notShort, notChar,
2838         notLong, notFloat, notObj, notDouble;
2839 
2840   assert(btos == 0, "change code, btos != 0");
2841   __ cbnz(tos_state, notByte);
2842 
2843   // Don't rewrite putstatic, only putfield
2844   if (is_static) rc = may_not_rewrite;
2845 
2846   // btos
2847   {
2848     __ pop(btos);
2849     if (!is_static) pop_and_check_object(obj);

2858   __ cmp(tos_state, (u1)ztos);
2859   __ br(Assembler::NE, notBool);
2860 
2861   // ztos
2862   {
2863     __ pop(ztos);
2864     if (!is_static) pop_and_check_object(obj);
2865     __ access_store_at(T_BOOLEAN, IN_HEAP, field, r0, noreg, noreg, noreg);
2866     if (rc == may_rewrite) {
2867       patch_bytecode(Bytecodes::_fast_zputfield, bc, r1, true, byte_no);
2868     }
2869     __ b(Done);
2870   }
2871 
2872   __ bind(notBool);
2873   __ cmp(tos_state, (u1)atos);
2874   __ br(Assembler::NE, notObj);
2875 
2876   // atos
2877   {
2878     __ pop(atos);
2879     if (!is_static) pop_and_check_object(obj);
2880     // Store into the field
2881     do_oop_store(_masm, field, r0, IN_HEAP);
2882     if (rc == may_rewrite) {
2883       patch_bytecode(Bytecodes::_fast_aputfield, bc, r1, true, byte_no);
2884     }
2885     __ b(Done);























































2886   }
2887 
2888   __ bind(notObj);
2889   __ cmp(tos_state, (u1)itos);
2890   __ br(Assembler::NE, notInt);
2891 
2892   // itos
2893   {
2894     __ pop(itos);
2895     if (!is_static) pop_and_check_object(obj);
2896     __ access_store_at(T_INT, IN_HEAP, field, r0, noreg, noreg, noreg);
2897     if (rc == may_rewrite) {
2898       patch_bytecode(Bytecodes::_fast_iputfield, bc, r1, true, byte_no);
2899     }
2900     __ b(Done);
2901   }
2902 
2903   __ bind(notInt);
2904   __ cmp(tos_state, (u1)ctos);
2905   __ br(Assembler::NE, notChar);

2970   {
2971     __ pop(dtos);
2972     if (!is_static) pop_and_check_object(obj);
2973     __ access_store_at(T_DOUBLE, IN_HEAP, field, noreg /* dtos */, noreg, noreg, noreg);
2974     if (rc == may_rewrite) {
2975       patch_bytecode(Bytecodes::_fast_dputfield, bc, r1, true, byte_no);
2976     }
2977   }
2978 
2979 #ifdef ASSERT
2980   __ b(Done);
2981 
2982   __ bind(notDouble);
2983   __ stop("Bad state");
2984 #endif
2985 
2986   __ bind(Done);
2987 
2988   {
2989     Label notVolatile;
2990     __ tbz(r5, ResolvedFieldEntry::is_volatile_shift, notVolatile);
2991     __ membar(MacroAssembler::StoreLoad | MacroAssembler::StoreStore);
2992     __ bind(notVolatile);
2993   }
2994 }
2995 
2996 void TemplateTable::putfield(int byte_no)
2997 {
2998   putfield_or_static(byte_no, false);
2999 }
3000 
3001 void TemplateTable::nofast_putfield(int byte_no) {
3002   putfield_or_static(byte_no, false, may_not_rewrite);
3003 }
3004 
3005 void TemplateTable::putstatic(int byte_no) {
3006   putfield_or_static(byte_no, true);
3007 }
3008 
3009 void TemplateTable::jvmti_post_fast_field_mod() {
3010   if (JvmtiExport::can_post_field_modification()) {
3011     // Check to see if a field modification watch has been set before
3012     // we take the time to call into the VM.
3013     Label L2;
3014     __ lea(rscratch1, ExternalAddress((address)JvmtiExport::get_field_modification_count_addr()));
3015     __ ldrw(c_rarg3, Address(rscratch1));
3016     __ cbzw(c_rarg3, L2);
3017     __ pop_ptr(r19);                  // copy the object pointer from tos
3018     __ verify_oop(r19);
3019     __ push_ptr(r19);                 // put the object pointer back on tos
3020     // Save tos values before call_VM() clobbers them. Since we have
3021     // to do it for every data type, we use the saved values as the
3022     // jvalue object.
3023     switch (bytecode()) {          // load values into the jvalue object

3024     case Bytecodes::_fast_aputfield: __ push_ptr(r0); break;
3025     case Bytecodes::_fast_bputfield: // fall through
3026     case Bytecodes::_fast_zputfield: // fall through
3027     case Bytecodes::_fast_sputfield: // fall through
3028     case Bytecodes::_fast_cputfield: // fall through
3029     case Bytecodes::_fast_iputfield: __ push_i(r0); break;
3030     case Bytecodes::_fast_dputfield: __ push_d(); break;
3031     case Bytecodes::_fast_fputfield: __ push_f(); break;
3032     case Bytecodes::_fast_lputfield: __ push_l(r0); break;
3033 
3034     default:
3035       ShouldNotReachHere();
3036     }
3037     __ mov(c_rarg3, esp);             // points to jvalue on the stack
3038     // access constant pool cache entry
3039     __ load_field_entry(c_rarg2, r0);
3040     __ verify_oop(r19);
3041     // r19: object pointer copied above
3042     // c_rarg2: cache entry pointer
3043     // c_rarg3: jvalue object on the stack
3044     __ call_VM(noreg,
3045                CAST_FROM_FN_PTR(address,
3046                                 InterpreterRuntime::post_field_modification),
3047                r19, c_rarg2, c_rarg3);
3048 
3049     switch (bytecode()) {             // restore tos values

3050     case Bytecodes::_fast_aputfield: __ pop_ptr(r0); break;
3051     case Bytecodes::_fast_bputfield: // fall through
3052     case Bytecodes::_fast_zputfield: // fall through
3053     case Bytecodes::_fast_sputfield: // fall through
3054     case Bytecodes::_fast_cputfield: // fall through
3055     case Bytecodes::_fast_iputfield: __ pop_i(r0); break;
3056     case Bytecodes::_fast_dputfield: __ pop_d(); break;
3057     case Bytecodes::_fast_fputfield: __ pop_f(); break;
3058     case Bytecodes::_fast_lputfield: __ pop_l(r0); break;
3059     default: break;
3060     }
3061     __ bind(L2);
3062   }
3063 }
3064 
3065 void TemplateTable::fast_storefield(TosState state)
3066 {
3067   transition(state, vtos);
3068 
3069   ByteSize base = ConstantPoolCache::base_offset();

3076   // R1: field offset, R2: field holder, R3: flags
3077   load_resolved_field_entry(r2, r2, noreg, r1, r3);
3078 
3079   {
3080     Label notVolatile;
3081     __ tbz(r3, ResolvedFieldEntry::is_volatile_shift, notVolatile);
3082     __ membar(MacroAssembler::StoreStore | MacroAssembler::LoadStore);
3083     __ bind(notVolatile);
3084   }
3085 
3086   Label notVolatile;
3087 
3088   // Get object from stack
3089   pop_and_check_object(r2);
3090 
3091   // field address
3092   const Address field(r2, r1);
3093 
3094   // access field
3095   switch (bytecode()) {



























3096   case Bytecodes::_fast_aputfield:
3097     do_oop_store(_masm, field, r0, IN_HEAP);
3098     break;
3099   case Bytecodes::_fast_lputfield:
3100     __ access_store_at(T_LONG, IN_HEAP, field, r0, noreg, noreg, noreg);
3101     break;
3102   case Bytecodes::_fast_iputfield:
3103     __ access_store_at(T_INT, IN_HEAP, field, r0, noreg, noreg, noreg);
3104     break;
3105   case Bytecodes::_fast_zputfield:
3106     __ access_store_at(T_BOOLEAN, IN_HEAP, field, r0, noreg, noreg, noreg);
3107     break;
3108   case Bytecodes::_fast_bputfield:
3109     __ access_store_at(T_BYTE, IN_HEAP, field, r0, noreg, noreg, noreg);
3110     break;
3111   case Bytecodes::_fast_sputfield:
3112     __ access_store_at(T_SHORT, IN_HEAP, field, r0, noreg, noreg, noreg);
3113     break;
3114   case Bytecodes::_fast_cputfield:
3115     __ access_store_at(T_CHAR, IN_HEAP, field, r0, noreg, noreg, noreg);

3168   // r0: object
3169   __ verify_oop(r0);
3170   __ null_check(r0);
3171   const Address field(r0, r1);
3172 
3173   // 8179954: We need to make sure that the code generated for
3174   // volatile accesses forms a sequentially-consistent set of
3175   // operations when combined with STLR and LDAR.  Without a leading
3176   // membar it's possible for a simple Dekker test to fail if loads
3177   // use LDR;DMB but stores use STLR.  This can happen if C2 compiles
3178   // the stores in one method and we interpret the loads in another.
3179   if (!CompilerConfig::is_c1_or_interpreter_only_no_jvmci()) {
3180     Label notVolatile;
3181     __ tbz(r3, ResolvedFieldEntry::is_volatile_shift, notVolatile);
3182     __ membar(MacroAssembler::AnyAny);
3183     __ bind(notVolatile);
3184   }
3185 
3186   // access field
3187   switch (bytecode()) {




























3188   case Bytecodes::_fast_agetfield:
3189     do_oop_load(_masm, field, r0, IN_HEAP);
3190     __ verify_oop(r0);
3191     break;
3192   case Bytecodes::_fast_lgetfield:
3193     __ access_load_at(T_LONG, IN_HEAP, r0, field, noreg, noreg);
3194     break;
3195   case Bytecodes::_fast_igetfield:
3196     __ access_load_at(T_INT, IN_HEAP, r0, field, noreg, noreg);
3197     break;
3198   case Bytecodes::_fast_bgetfield:
3199     __ access_load_at(T_BYTE, IN_HEAP, r0, field, noreg, noreg);
3200     break;
3201   case Bytecodes::_fast_sgetfield:
3202     __ access_load_at(T_SHORT, IN_HEAP, r0, field, noreg, noreg);
3203     break;
3204   case Bytecodes::_fast_cgetfield:
3205     __ access_load_at(T_CHAR, IN_HEAP, r0, field, noreg, noreg);
3206     break;
3207   case Bytecodes::_fast_fgetfield:

3586   Label initialize_header;
3587 
3588   __ get_cpool_and_tags(r4, r0);
3589   // Make sure the class we're about to instantiate has been resolved.
3590   // This is done before loading InstanceKlass to be consistent with the order
3591   // how Constant Pool is updated (see ConstantPool::klass_at_put)
3592   const int tags_offset = Array<u1>::base_offset_in_bytes();
3593   __ lea(rscratch1, Address(r0, r3, Address::lsl(0)));
3594   __ lea(rscratch1, Address(rscratch1, tags_offset));
3595   __ ldarb(rscratch1, rscratch1);
3596   __ cmp(rscratch1, (u1)JVM_CONSTANT_Class);
3597   __ br(Assembler::NE, slow_case);
3598 
3599   // get InstanceKlass
3600   __ load_resolved_klass_at_offset(r4, r3, r4, rscratch1);
3601 
3602   // make sure klass is initialized
3603   assert(VM_Version::supports_fast_class_init_checks(), "Optimization requires support for fast class initialization checks");
3604   __ clinit_barrier(r4, rscratch1, nullptr /*L_fast_path*/, &slow_case);
3605 
3606   // get instance_size in InstanceKlass (scaled to a count of bytes)
3607   __ ldrw(r3,
3608           Address(r4,
3609                   Klass::layout_helper_offset()));
3610   // test to see if it is malformed in some way
3611   __ tbnz(r3, exact_log2(Klass::_lh_instance_slow_path_bit), slow_case);
3612 
3613   // Allocate the instance:
3614   //  If TLAB is enabled:
3615   //    Try to allocate in the TLAB.
3616   //    If fails, go to the slow path.
3617   //    Initialize the allocation.
3618   //    Exit.
3619   //
3620   //  Go to slow path.
3621 
3622   if (UseTLAB) {
3623     __ tlab_allocate(r0, r3, 0, noreg, r1, slow_case);
3624 
3625     if (ZeroTLAB) {
3626       // the fields have been already cleared
3627       __ b(initialize_header);
3628     }
3629 
3630     // The object is initialized before the header.  If the object size is
3631     // zero, go directly to the header initialization.
3632     __ sub(r3, r3, sizeof(oopDesc));
3633     __ cbz(r3, initialize_header);
3634 
3635     // Initialize object fields
3636     {
3637       __ add(r2, r0, sizeof(oopDesc));
3638       Label loop;
3639       __ bind(loop);
3640       __ str(zr, Address(__ post(r2, BytesPerLong)));
3641       __ sub(r3, r3, BytesPerLong);
3642       __ cbnz(r3, loop);
3643     }
3644 
3645     // initialize object header only.
3646     __ bind(initialize_header);
3647     __ mov(rscratch1, (intptr_t)markWord::prototype().value());
3648     __ str(rscratch1, Address(r0, oopDesc::mark_offset_in_bytes()));
3649     __ store_klass_gap(r0, zr);  // zero klass gap for compressed oops
3650     __ store_klass(r0, r4);      // store klass last
3651 
3652     if (DTraceAllocProbes) {
3653       // Trigger dtrace event for fastpath
3654       __ push(atos); // save the return value
3655       __ call_VM_leaf(
3656            CAST_FROM_FN_PTR(address, static_cast<int (*)(oopDesc*)>(SharedRuntime::dtrace_object_alloc)), r0);
3657       __ pop(atos); // restore the return value
3658 
3659     }
3660     __ b(done);
3661   }
3662 
3663   // slow case
3664   __ bind(slow_case);
3665   __ get_constant_pool(c_rarg1);
3666   __ get_unsigned_2_byte_index_at_bcp(c_rarg2, 1);
3667   call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), c_rarg1, c_rarg2);
3668   __ verify_oop(r0);
3669 
3670   // continue
3671   __ bind(done);
3672   // Must prevent reordering of stores for object initialization with stores that publish the new object.
3673   __ membar(Assembler::StoreStore);
3674 }
3675 
3676 void TemplateTable::newarray() {
3677   transition(itos, atos);
3678   __ load_unsigned_byte(c_rarg1, at_bcp(1));
3679   __ mov(c_rarg2, r0);
3680   call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::newarray),
3681           c_rarg1, c_rarg2);

3726   __ bind(quicked);
3727   __ mov(r3, r0); // Save object in r3; r0 needed for subtype check
3728   __ load_resolved_klass_at_offset(r2, r19, r0, rscratch1); // r0 = klass
3729 
3730   __ bind(resolved);
3731   __ load_klass(r19, r3);
3732 
3733   // Generate subtype check.  Blows r2, r5.  Object in r3.
3734   // Superklass in r0.  Subklass in r19.
3735   __ gen_subtype_check(r19, ok_is_subtype);
3736 
3737   // Come here on failure
3738   __ push(r3);
3739   // object is at TOS
3740   __ b(Interpreter::_throw_ClassCastException_entry);
3741 
3742   // Come here on success
3743   __ bind(ok_is_subtype);
3744   __ mov(r0, r3); // Restore object in r3
3745 



3746   // Collect counts on whether this test sees nulls a lot or not.
3747   if (ProfileInterpreter) {
3748     __ b(done);
3749     __ bind(is_null);
3750     __ profile_null_seen(r2);
3751   } else {
3752     __ bind(is_null);   // same as 'done'
3753   }

3754   __ bind(done);
3755 }
3756 
3757 void TemplateTable::instanceof() {
3758   transition(atos, itos);
3759   Label done, is_null, ok_is_subtype, quicked, resolved;
3760   __ cbz(r0, is_null);
3761 
3762   // Get cpool & tags index
3763   __ get_cpool_and_tags(r2, r3); // r2=cpool, r3=tags array
3764   __ get_unsigned_2_byte_index_at_bcp(r19, 1); // r19=index
3765   // See if bytecode has already been quicked
3766   __ add(rscratch1, r3, Array<u1>::base_offset_in_bytes());
3767   __ lea(r1, Address(rscratch1, r19));
3768   __ ldarb(r1, r1);
3769   __ cmp(r1, (u1)JVM_CONSTANT_Class);
3770   __ br(Assembler::EQ, quicked);
3771 
3772   __ push(atos); // save receiver for result, and for GC
3773   call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc));

3852 //       in the assembly code structure as well
3853 //
3854 // Stack layout:
3855 //
3856 // [expressions  ] <--- esp               = expression stack top
3857 // ..
3858 // [expressions  ]
3859 // [monitor entry] <--- monitor block top = expression stack bot
3860 // ..
3861 // [monitor entry]
3862 // [frame data   ] <--- monitor block bot
3863 // ...
3864 // [saved rfp    ] <--- rfp
3865 void TemplateTable::monitorenter()
3866 {
3867   transition(atos, vtos);
3868 
3869   // check for null object
3870   __ null_check(r0);
3871 




3872   const Address monitor_block_top(
3873         rfp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
3874   const Address monitor_block_bot(
3875         rfp, frame::interpreter_frame_initial_sp_offset * wordSize);
3876   const int entry_size = frame::interpreter_frame_monitor_size_in_bytes();
3877 
3878   Label allocated;
3879 
3880   // initialize entry pointer
3881   __ mov(c_rarg1, zr); // points to free slot or null
3882 
3883   // find a free slot in the monitor block (result in c_rarg1)
3884   {
3885     Label entry, loop, exit;
3886     __ ldr(c_rarg3, monitor_block_top); // derelativize pointer
3887     __ lea(c_rarg3, Address(rfp, c_rarg3, Address::lsl(Interpreter::logStackElementSize)));
3888     // c_rarg3 points to current entry, starting with top-most entry
3889 
3890     __ lea(c_rarg2, monitor_block_bot); // points to word before bottom
3891 

3953   // c_rarg1: points to monitor entry
3954   __ bind(allocated);
3955 
3956   // Increment bcp to point to the next bytecode, so exception
3957   // handling for async. exceptions work correctly.
3958   // The object has already been popped from the stack, so the
3959   // expression stack looks correct.
3960   __ increment(rbcp);
3961 
3962   // store object
3963   __ str(r0, Address(c_rarg1, BasicObjectLock::obj_offset()));
3964   __ lock_object(c_rarg1);
3965 
3966   // check to make sure this monitor doesn't cause stack overflow after locking
3967   __ save_bcp();  // in case of exception
3968   __ generate_stack_overflow_check(0);
3969 
3970   // The bcp has already been incremented. Just need to dispatch to
3971   // next instruction.
3972   __ dispatch_next(vtos);





3973 }
3974 
3975 
3976 void TemplateTable::monitorexit()
3977 {
3978   transition(atos, vtos);
3979 
3980   // check for null object
3981   __ null_check(r0);
3982 












3983   const Address monitor_block_top(
3984         rfp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
3985   const Address monitor_block_bot(
3986         rfp, frame::interpreter_frame_initial_sp_offset * wordSize);
3987   const int entry_size = frame::interpreter_frame_monitor_size_in_bytes();
3988 
3989   Label found;
3990 
3991   // find matching slot
3992   {
3993     Label entry, loop;
3994     __ ldr(c_rarg1, monitor_block_top); // derelativize pointer
3995     __ lea(c_rarg1, Address(rfp, c_rarg1, Address::lsl(Interpreter::logStackElementSize)));
3996     // c_rarg1 points to current entry, starting with top-most entry
3997 
3998     __ lea(c_rarg2, monitor_block_bot); // points to word before bottom
3999                                         // of monitor block
4000     __ b(entry);
4001 
4002     __ bind(loop);

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

 738   locals_index_wide(r1);
 739   __ ldr(r0, aaddress(r1));
 740 }
 741 
 742 void TemplateTable::index_check(Register array, Register index)
 743 {
 744   // destroys r1, rscratch1
 745   // sign extend index for use by indexed load
 746   // __ movl2ptr(index, index);
 747   // check index
 748   Register length = rscratch1;
 749   __ ldrw(length, Address(array, arrayOopDesc::length_offset_in_bytes()));
 750   __ cmpw(index, length);
 751   if (index != r1) {
 752     // ??? convention: move aberrant index into r1 for exception message
 753     assert(r1 != array, "different registers");
 754     __ mov(r1, index);
 755   }
 756   Label ok;
 757   __ br(Assembler::LO, ok);
 758   // ??? convention: move array into r3 for exception message
 759    __ mov(r3, array);
 760    __ mov(rscratch1, Interpreter::_throw_ArrayIndexOutOfBoundsException_entry);
 761    __ br(rscratch1);
 762   __ bind(ok);
 763 }
 764 
 765 void TemplateTable::iaload()
 766 {
 767   transition(itos, itos);
 768   __ mov(r1, r0);
 769   __ pop_ptr(r0);
 770   // r0: array
 771   // r1: index
 772   index_check(r0, r1); // leaves index in r1, kills rscratch1
 773   __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_INT) >> 2);
 774   __ access_load_at(T_INT, IN_HEAP | IS_ARRAY, r0, Address(r0, r1, Address::uxtw(2)), noreg, noreg);
 775 }
 776 
 777 void TemplateTable::laload()
 778 {
 779   transition(itos, ltos);
 780   __ mov(r1, r0);
 781   __ pop_ptr(r0);

 801 void TemplateTable::daload()
 802 {
 803   transition(itos, dtos);
 804   __ mov(r1, r0);
 805   __ pop_ptr(r0);
 806   // r0: array
 807   // r1: index
 808   index_check(r0, r1); // leaves index in r1, kills rscratch1
 809   __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_DOUBLE) >> 3);
 810   __ access_load_at(T_DOUBLE, IN_HEAP | IS_ARRAY, r0, Address(r0, r1, Address::uxtw(3)), noreg, noreg);
 811 }
 812 
 813 void TemplateTable::aaload()
 814 {
 815   transition(itos, atos);
 816   __ mov(r1, r0);
 817   __ pop_ptr(r0);
 818   // r0: array
 819   // r1: index
 820   index_check(r0, r1); // leaves index in r1, kills rscratch1
 821   __ profile_array_type<ArrayLoadData>(r2, r0, r4);
 822   if (UseFlatArray) {
 823     Label is_flat_array, done;
 824 
 825     __ test_flat_array_oop(r0, r8 /*temp*/, is_flat_array);
 826     __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_OBJECT) >> LogBytesPerHeapOop);
 827     do_oop_load(_masm, Address(r0, r1, Address::uxtw(LogBytesPerHeapOop)), r0, IS_ARRAY);
 828 
 829     __ b(done);
 830     __ bind(is_flat_array);
 831     __ call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::value_array_load), r0, r1);
 832     // Ensure the stores to copy the inline field contents are visible
 833     // before any subsequent store that publishes this reference.
 834     __ membar(Assembler::StoreStore);
 835     __ bind(done);
 836   } else {
 837     __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_OBJECT) >> LogBytesPerHeapOop);
 838     do_oop_load(_masm, Address(r0, r1, Address::uxtw(LogBytesPerHeapOop)), r0, IS_ARRAY);
 839   }
 840   __ profile_element_type(r2, r0, r4);
 841 }
 842 
 843 void TemplateTable::baload()
 844 {
 845   transition(itos, itos);
 846   __ mov(r1, r0);
 847   __ pop_ptr(r0);
 848   // r0: array
 849   // r1: index
 850   index_check(r0, r1); // leaves index in r1, kills rscratch1
 851   __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_BYTE) >> 0);
 852   __ access_load_at(T_BYTE, IN_HEAP | IS_ARRAY, r0, Address(r0, r1, Address::uxtw(0)), noreg, noreg);
 853 }
 854 
 855 void TemplateTable::caload()
 856 {
 857   transition(itos, itos);
 858   __ mov(r1, r0);
 859   __ pop_ptr(r0);
 860   // r0: array

1107   // r1:  index
1108   // r3:  array
1109   index_check(r3, r1); // prefer index in r1
1110   __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_FLOAT) >> 2);
1111   __ access_store_at(T_FLOAT, IN_HEAP | IS_ARRAY, Address(r3, r1, Address::uxtw(2)), noreg /* ftos */, noreg, noreg, noreg);
1112 }
1113 
1114 void TemplateTable::dastore() {
1115   transition(dtos, vtos);
1116   __ pop_i(r1);
1117   __ pop_ptr(r3);
1118   // v0: value
1119   // r1:  index
1120   // r3:  array
1121   index_check(r3, r1); // prefer index in r1
1122   __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_DOUBLE) >> 3);
1123   __ access_store_at(T_DOUBLE, IN_HEAP | IS_ARRAY, Address(r3, r1, Address::uxtw(3)), noreg /* dtos */, noreg, noreg, noreg);
1124 }
1125 
1126 void TemplateTable::aastore() {
1127   Label is_null, is_flat_array, ok_is_subtype, done;
1128   transition(vtos, vtos);
1129   // stack: ..., array, index, value
1130   __ ldr(r0, at_tos());    // value
1131   __ ldr(r2, at_tos_p1()); // index
1132   __ ldr(r3, at_tos_p2()); // array
1133 


1134   index_check(r3, r2);     // kills r1
1135 
1136   __ profile_array_type<ArrayStoreData>(r4, r3, r5);
1137   __ profile_multiple_element_types(r4, r0, r5, r6);
1138 
1139   __ add(r4, r2, arrayOopDesc::base_offset_in_bytes(T_OBJECT) >> LogBytesPerHeapOop);
1140   Address element_address(r3, r4, Address::uxtw(LogBytesPerHeapOop));
1141   // Be careful not to clobber r4 below
1142 
1143   // do array store check - check for null value first
1144   __ cbz(r0, is_null);
1145 
1146   // Move array class to r5
1147   __ load_klass(r5, r3);
1148 
1149   if (UseFlatArray) {
1150     __ ldrw(r6, Address(r5, Klass::layout_helper_offset()));
1151     __ test_flat_array_layout(r6, is_flat_array);
1152   }
1153 
1154   // Move subklass into r1
1155   __ load_klass(r1, r0);
1156 
1157   // Move array element superklass into r0
1158   __ ldr(r0, Address(r5, ObjArrayKlass::element_klass_offset()));

1159   // Compress array + index*oopSize + 12 into a single register.  Frees r2.
1160 
1161   // Generate subtype check.  Blows r2, r5
1162   // Superklass in r0.  Subklass in r1.
1163 
1164   // is "r1 <: r0" ? (value subclass <: array element superclass)
1165   __ gen_subtype_check(r1, ok_is_subtype, false);
1166 
1167   // Come here on failure
1168   // object is at TOS
1169   __ b(Interpreter::_throw_ArrayStoreException_entry);
1170 
1171   // Come here on success
1172   __ bind(ok_is_subtype);
1173 
1174   // Get the value we will store
1175   __ ldr(r0, at_tos());
1176   // Now store using the appropriate barrier
1177   do_oop_store(_masm, element_address, r0, IS_ARRAY);
1178   __ b(done);
1179 
1180   // Have a null in r0, r3=array, r2=index.  Store null at ary[idx]
1181   __ bind(is_null);
1182   if (EnableValhalla) {
1183     Label is_null_into_value_array_npe, store_null;
1184 
1185     // No way to store null in flat null-free array
1186     __ test_null_free_array_oop(r3, r8, is_null_into_value_array_npe);
1187     __ b(store_null);
1188 
1189     __ bind(is_null_into_value_array_npe);
1190     __ b(ExternalAddress(Interpreter::_throw_NullPointerException_entry));
1191 
1192     __ bind(store_null);
1193   }
1194 
1195   // Store a null
1196   do_oop_store(_masm, element_address, noreg, IS_ARRAY);
1197   __ b(done);
1198 
1199   if (UseFlatArray) {
1200      Label is_type_ok;
1201     __ bind(is_flat_array); // Store non-null value to flat
1202 
1203     // Simplistic type check...
1204     // r0 - value, r2 - index, r3 - array.
1205 
1206     // Profile the not-null value's klass.
1207     // Load value class
1208      __ load_klass(r1, r0);
1209 
1210     // Move element klass into r7
1211      __ ldr(r7, Address(r5, ArrayKlass::element_klass_offset()));
1212 
1213     // flat value array needs exact type match
1214     // is "r1 == r7" (value subclass == array element superclass)
1215 
1216      __ cmp(r7, r1);
1217      __ br(Assembler::EQ, is_type_ok);
1218 
1219      __ b(ExternalAddress(Interpreter::_throw_ArrayStoreException_entry));
1220 
1221      __ bind(is_type_ok);
1222     // r1: value's klass
1223     // r3: array
1224     // r5: array klass
1225     __ test_klass_is_empty_inline_type(r1, r7, done);
1226 
1227     // calc dst for copy
1228     __ ldrw(r7, at_tos_p1()); // index
1229     __ data_for_value_array_index(r3, r5, r7, r7);
1230 
1231     // ...and src for copy
1232     __ ldr(r6, at_tos());  // value
1233     __ data_for_oop(r6, r6, r1);
1234 
1235     __ mov(r4, r1);  // Shuffle arguments to avoid conflict with c_rarg1
1236     __ access_value_copy(IN_HEAP, r6, r7, r4);
1237   }
1238 
1239   // Pop stack arguments
1240   __ bind(done);
1241   __ add(esp, esp, 3 * Interpreter::stackElementSize);
1242 }
1243 
1244 void TemplateTable::bastore()
1245 {
1246   transition(itos, vtos);
1247   __ pop_i(r1);
1248   __ pop_ptr(r3);
1249   // r0: value
1250   // r1: index
1251   // r3: array
1252   index_check(r3, r1); // prefer index in r1
1253 
1254   // Need to check whether array is boolean or byte
1255   // since both types share the bastore bytecode.
1256   __ load_klass(r2, r3);
1257   __ ldrw(r2, Address(r2, Klass::layout_helper_offset()));

2022   __ br(j_not(cc), not_taken);
2023   branch(false, false);
2024   __ bind(not_taken);
2025   __ profile_not_taken_branch(r0);
2026 }
2027 
2028 void TemplateTable::if_nullcmp(Condition cc)
2029 {
2030   transition(atos, vtos);
2031   // assume branch is more often taken than not (loops use backward branches)
2032   Label not_taken;
2033   if (cc == equal)
2034     __ cbnz(r0, not_taken);
2035   else
2036     __ cbz(r0, not_taken);
2037   branch(false, false);
2038   __ bind(not_taken);
2039   __ profile_not_taken_branch(r0);
2040 }
2041 
2042 void TemplateTable::if_acmp(Condition cc) {

2043   transition(atos, vtos);
2044   // assume branch is more often taken than not (loops use backward branches)
2045   Label taken, not_taken;
2046   __ pop_ptr(r1);
2047 
2048   __ profile_acmp(r2, r1, r0, r4);
2049 
2050   Register is_inline_type_mask = rscratch1;
2051   __ mov(is_inline_type_mask, markWord::inline_type_pattern);
2052 
2053   if (EnableValhalla) {
2054     __ cmp(r1, r0);
2055     __ br(Assembler::EQ, (cc == equal) ? taken : not_taken);
2056 
2057     // might be substitutable, test if either r0 or r1 is null
2058     __ andr(r2, r0, r1);
2059     __ cbz(r2, (cc == equal) ? not_taken : taken);
2060 
2061     // and both are values ?
2062     __ ldr(r2, Address(r1, oopDesc::mark_offset_in_bytes()));
2063     __ andr(r2, r2, is_inline_type_mask);
2064     __ ldr(r4, Address(r0, oopDesc::mark_offset_in_bytes()));
2065     __ andr(r4, r4, is_inline_type_mask);
2066     __ andr(r2, r2, r4);
2067     __ cmp(r2,  is_inline_type_mask);
2068     __ br(Assembler::NE, (cc == equal) ? not_taken : taken);
2069 
2070     // same value klass ?
2071     __ load_metadata(r2, r1);
2072     __ load_metadata(r4, r0);
2073     __ cmp(r2, r4);
2074     __ br(Assembler::NE, (cc == equal) ? not_taken : taken);
2075 
2076     // Know both are the same type, let's test for substitutability...
2077     if (cc == equal) {
2078       invoke_is_substitutable(r0, r1, taken, not_taken);
2079     } else {
2080       invoke_is_substitutable(r0, r1, not_taken, taken);
2081     }
2082     __ stop("Not reachable");
2083   }
2084 
2085   __ cmpoop(r1, r0);
2086   __ br(j_not(cc), not_taken);
2087   __ bind(taken);
2088   branch(false, false);
2089   __ bind(not_taken);
2090   __ profile_not_taken_branch(r0, true);
2091 }
2092 
2093 void TemplateTable::invoke_is_substitutable(Register aobj, Register bobj,
2094                                             Label& is_subst, Label& not_subst) {
2095 
2096   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::is_substitutable), aobj, bobj);
2097   // Restored... r0 answer, jmp to outcome...
2098   __ cbz(r0, not_subst);
2099   __ b(is_subst);
2100 }
2101 
2102 
2103 void TemplateTable::ret() {
2104   transition(vtos, vtos);
2105   locals_index(r1);
2106   __ ldr(r1, aaddress(r1)); // get return bci, compute return bcp
2107   __ profile_ret(r1, r2);
2108   __ ldr(rbcp, Address(rmethod, Method::const_offset()));
2109   __ lea(rbcp, Address(rbcp, r1));
2110   __ add(rbcp, rbcp, in_bytes(ConstMethod::codes_offset()));
2111   __ dispatch_next(vtos, 0, /*generate_poll*/true);
2112 }
2113 
2114 void TemplateTable::wide_ret() {
2115   transition(vtos, vtos);
2116   locals_index_wide(r1);
2117   __ ldr(r1, aaddress(r1)); // get return bci, compute return bcp
2118   __ profile_ret(r1, r2);
2119   __ ldr(rbcp, Address(rmethod, Method::const_offset()));
2120   __ lea(rbcp, Address(rbcp, r1));
2121   __ add(rbcp, rbcp, in_bytes(ConstMethod::codes_offset()));
2122   __ dispatch_next(vtos, 0, /*generate_poll*/true);

2692     }
2693     // c_rarg1: object pointer or null
2694     // c_rarg2: cache entry pointer
2695     __ call_VM(noreg, CAST_FROM_FN_PTR(address,
2696                                        InterpreterRuntime::post_field_access),
2697                c_rarg1, c_rarg2);
2698     __ load_field_entry(cache, index);
2699     __ bind(L1);
2700   }
2701 }
2702 
2703 void TemplateTable::pop_and_check_object(Register r)
2704 {
2705   __ pop_ptr(r);
2706   __ null_check(r);  // for field access must check obj.
2707   __ verify_oop(r);
2708 }
2709 
2710 void TemplateTable::getfield_or_static(int byte_no, bool is_static, RewriteControl rc)
2711 {
2712   const Register cache     = r2;
2713   const Register obj       = r4;
2714   const Register klass     = r5;
2715   const Register inline_klass = r7;
2716   const Register field_index = r23;
2717   const Register index     = r3;
2718   const Register tos_state = r3;
2719   const Register off       = r19;
2720   const Register flags     = r6;
2721   const Register bc        = r4; // uses same reg as obj, so don't mix them
2722 
2723   resolve_cache_and_index_for_field(byte_no, cache, index);
2724   jvmti_post_field_access(cache, index, is_static, false);
2725 
2726   // Valhalla extras
2727   __ load_unsigned_short(field_index, Address(cache, in_bytes(ResolvedFieldEntry::field_index_offset())));
2728   __ ldr(klass, Address(cache, ResolvedFieldEntry::field_holder_offset()));
2729 
2730   load_resolved_field_entry(obj, cache, tos_state, off, flags, is_static);
2731 
2732   if (!is_static) {
2733     // obj is on the stack
2734     pop_and_check_object(obj);
2735   }
2736 
2737   // 8179954: We need to make sure that the code generated for
2738   // volatile accesses forms a sequentially-consistent set of
2739   // operations when combined with STLR and LDAR.  Without a leading
2740   // membar it's possible for a simple Dekker test to fail if loads
2741   // use LDR;DMB but stores use STLR.  This can happen if C2 compiles
2742   // the stores in one method and we interpret the loads in another.
2743   if (!CompilerConfig::is_c1_or_interpreter_only_no_jvmci()){
2744     Label notVolatile;
2745     __ tbz(flags, ResolvedFieldEntry::is_volatile_shift, notVolatile);
2746     __ membar(MacroAssembler::AnyAny);
2747     __ bind(notVolatile);
2748   }
2749 

2768   __ b(Done);
2769 
2770   __ bind(notByte);
2771   __ cmp(tos_state, (u1)ztos);
2772   __ br(Assembler::NE, notBool);
2773 
2774   // ztos (same code as btos)
2775   __ access_load_at(T_BOOLEAN, IN_HEAP, r0, field, noreg, noreg);
2776   __ push(ztos);
2777   // Rewrite bytecode to be faster
2778   if (rc == may_rewrite) {
2779     // use btos rewriting, no truncating to t/f bit is needed for getfield.
2780     patch_bytecode(Bytecodes::_fast_bgetfield, bc, r1);
2781   }
2782   __ b(Done);
2783 
2784   __ bind(notBool);
2785   __ cmp(tos_state, (u1)atos);
2786   __ br(Assembler::NE, notObj);
2787   // atos
2788   if (!EnableValhalla) {
2789     do_oop_load(_masm, field, r0, IN_HEAP);
2790     __ push(atos);
2791     if (rc == may_rewrite) {
2792       patch_bytecode(Bytecodes::_fast_agetfield, bc, r1);
2793     }
2794     __ b(Done);
2795   } else { // Valhalla
2796     if (is_static) {
2797       __ load_heap_oop(r0, field, rscratch1, rscratch2);
2798       Label is_null_free_inline_type, uninitialized;
2799       // Issue below if the static field has not been initialized yet
2800       __ test_field_is_null_free_inline_type(flags, noreg /*temp*/, is_null_free_inline_type);
2801         // field is not a null free inline type
2802         __ push(atos);
2803         __ b(Done);
2804       // field is a null free inline type, must not return null even if uninitialized
2805       __ bind(is_null_free_inline_type);
2806         __ cbz(r0, uninitialized);
2807           __ push(atos);
2808           __ b(Done);
2809         __ bind(uninitialized);
2810           Label slow_case, finish;
2811           __ ldrb(rscratch1, Address(klass, InstanceKlass::init_state_offset()));
2812           __ cmp(rscratch1, (u1)InstanceKlass::fully_initialized);
2813           __ br(Assembler::NE, slow_case);
2814           __ get_default_value_oop(klass, off /* temp */, r0);
2815         __ b(finish);
2816         __ bind(slow_case);
2817           __ call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::uninitialized_static_inline_type_field), obj, cache);
2818           __ bind(finish);
2819           __ verify_oop(r0);
2820           __ push(atos);
2821           __ b(Done);
2822     } else {
2823       Label is_flat, nonnull, is_inline_type, has_null_marker, rewrite_inline;
2824       __ test_field_is_null_free_inline_type(flags, noreg /*temp*/, is_inline_type);
2825       __ test_field_has_null_marker(flags, noreg /*temp*/, has_null_marker);
2826         // Non-inline field case
2827         __ load_heap_oop(r0, field, rscratch1, rscratch2);
2828         __ push(atos);
2829         if (rc == may_rewrite) {
2830           patch_bytecode(Bytecodes::_fast_agetfield, bc, r1);
2831         }
2832         __ b(Done);
2833       __ bind(is_inline_type);
2834         __ test_field_is_flat(flags, noreg /* temp */, is_flat);
2835          // field is not flat
2836           __ load_heap_oop(r0, field, rscratch1, rscratch2);
2837           __ cbnz(r0, nonnull);
2838             __ get_inline_type_field_klass(klass, field_index, inline_klass);
2839             __ get_default_value_oop(inline_klass, klass /* temp */, r0);
2840           __ bind(nonnull);
2841           __ verify_oop(r0);
2842           __ push(atos);
2843           __ b(rewrite_inline);
2844         __ bind(is_flat);
2845         // field is flat
2846           __ mov(r0, obj);
2847           __ read_flat_field(cache, field_index, off, inline_klass /* temp */, r0);
2848           __ verify_oop(r0);
2849           __ push(atos);
2850           __ b(rewrite_inline);
2851         __ bind(has_null_marker);
2852           call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::read_nullable_flat_field), obj, cache);
2853           __ verify_oop(r0);
2854           __ push(atos);
2855       __ bind(rewrite_inline);
2856       if (rc == may_rewrite) {
2857         patch_bytecode(Bytecodes::_fast_vgetfield, bc, r1);
2858       }
2859       __ b(Done);
2860     }
2861   }

2862 
2863   __ bind(notObj);
2864   __ cmp(tos_state, (u1)itos);
2865   __ br(Assembler::NE, notInt);
2866   // itos
2867   __ access_load_at(T_INT, IN_HEAP, r0, field, noreg, noreg);
2868   __ push(itos);
2869   // Rewrite bytecode to be faster
2870   if (rc == may_rewrite) {
2871     patch_bytecode(Bytecodes::_fast_igetfield, bc, r1);
2872   }
2873   __ b(Done);
2874 
2875   __ bind(notInt);
2876   __ cmp(tos_state, (u1)ctos);
2877   __ br(Assembler::NE, notChar);
2878   // ctos
2879   __ access_load_at(T_CHAR, IN_HEAP, r0, field, noreg, noreg);
2880   __ push(ctos);
2881   // Rewrite bytecode to be faster

3002     // c_rarg1: object pointer set up above (null if static)
3003     // c_rarg2: cache entry pointer
3004     // c_rarg3: jvalue object on the stack
3005     __ call_VM(noreg,
3006                CAST_FROM_FN_PTR(address,
3007                                 InterpreterRuntime::post_field_modification),
3008                c_rarg1, c_rarg2, c_rarg3);
3009     __ load_field_entry(cache, index);
3010     __ bind(L1);
3011   }
3012 }
3013 
3014 void TemplateTable::putfield_or_static(int byte_no, bool is_static, RewriteControl rc) {
3015   transition(vtos, vtos);
3016 
3017   const Register cache     = r2;
3018   const Register index     = r3;
3019   const Register tos_state = r3;
3020   const Register obj       = r2;
3021   const Register off       = r19;
3022   const Register flags     = r6;
3023   const Register bc        = r4;
3024   const Register inline_klass = r5;
3025 
3026   resolve_cache_and_index_for_field(byte_no, cache, index);
3027   jvmti_post_field_mod(cache, index, is_static);
3028   load_resolved_field_entry(obj, cache, tos_state, off, flags, is_static);
3029 
3030   Label Done;


3031   {
3032     Label notVolatile;
3033     __ tbz(flags, ResolvedFieldEntry::is_volatile_shift, notVolatile);
3034     __ membar(MacroAssembler::StoreStore | MacroAssembler::LoadStore);
3035     __ bind(notVolatile);
3036   }
3037 
3038   // field address
3039   const Address field(obj, off);
3040 
3041   Label notByte, notBool, notInt, notShort, notChar,
3042         notLong, notFloat, notObj, notDouble;
3043 
3044   assert(btos == 0, "change code, btos != 0");
3045   __ cbnz(tos_state, notByte);
3046 
3047   // Don't rewrite putstatic, only putfield
3048   if (is_static) rc = may_not_rewrite;
3049 
3050   // btos
3051   {
3052     __ pop(btos);
3053     if (!is_static) pop_and_check_object(obj);

3062   __ cmp(tos_state, (u1)ztos);
3063   __ br(Assembler::NE, notBool);
3064 
3065   // ztos
3066   {
3067     __ pop(ztos);
3068     if (!is_static) pop_and_check_object(obj);
3069     __ access_store_at(T_BOOLEAN, IN_HEAP, field, r0, noreg, noreg, noreg);
3070     if (rc == may_rewrite) {
3071       patch_bytecode(Bytecodes::_fast_zputfield, bc, r1, true, byte_no);
3072     }
3073     __ b(Done);
3074   }
3075 
3076   __ bind(notBool);
3077   __ cmp(tos_state, (u1)atos);
3078   __ br(Assembler::NE, notObj);
3079 
3080   // atos
3081   {
3082      if (!EnableValhalla) {
3083       __ pop(atos);
3084       if (!is_static) pop_and_check_object(obj);
3085       // Store into the field
3086       do_oop_store(_masm, field, r0, IN_HEAP);
3087       if (rc == may_rewrite) {
3088         patch_bytecode(Bytecodes::_fast_aputfield, bc, r1, true, byte_no);
3089       }
3090       __ b(Done);
3091      } else { // Valhalla
3092       __ pop(atos);
3093       if (is_static) {
3094         Label is_inline_type;
3095          __ test_field_is_not_null_free_inline_type(flags, noreg /* temp */, is_inline_type);
3096          __ null_check(r0);
3097          __ bind(is_inline_type);
3098          do_oop_store(_masm, field, r0, IN_HEAP);
3099          __ b(Done);
3100       } else {
3101         Label is_inline_type, is_flat, has_null_marker, rewrite_not_inline, rewrite_inline;
3102         __ test_field_is_null_free_inline_type(flags, noreg /*temp*/, is_inline_type);
3103         __ test_field_has_null_marker(flags, noreg /*temp*/, has_null_marker);
3104         // Not an inline type
3105         pop_and_check_object(obj);
3106         // Store into the field
3107         do_oop_store(_masm, field, r0, IN_HEAP);
3108         __ bind(rewrite_not_inline);
3109         if (rc == may_rewrite) {
3110           patch_bytecode(Bytecodes::_fast_aputfield, bc, r19, true, byte_no);
3111         }
3112         __ b(Done);
3113         // Implementation of the inline type semantic
3114         __ bind(is_inline_type);
3115         __ null_check(r0);
3116         __ test_field_is_flat(flags, noreg /*temp*/, is_flat);
3117         // field is not flat
3118         pop_and_check_object(obj);
3119         // Store into the field
3120         do_oop_store(_masm, field, r0, IN_HEAP);
3121         __ b(rewrite_inline);
3122         __ bind(is_flat);
3123         __ load_field_entry(cache, index); // reload field entry (cache) because it was erased by tos_state
3124         __ load_unsigned_short(index, Address(cache, in_bytes(ResolvedFieldEntry::field_index_offset())));
3125         __ ldr(r2, Address(cache, in_bytes(ResolvedFieldEntry::field_holder_offset())));
3126         __ inline_layout_info(r2, index, r6);
3127         pop_and_check_object(obj);
3128         __ load_klass(inline_klass, r0);
3129         __ data_for_oop(r0, r0, inline_klass);
3130         __ add(obj, obj, off);
3131         // because we use InlineLayoutInfo, we need special value access code specialized for fields (arrays will need a different API)
3132         __ flat_field_copy(IN_HEAP, r0, obj, r6);
3133         __ b(rewrite_inline);
3134         __ bind(has_null_marker);
3135         assert_different_registers(r0, cache, r19);
3136         pop_and_check_object(r19);
3137         __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::write_nullable_flat_field), r19, r0, cache);
3138         __ bind(rewrite_inline);
3139         if (rc == may_rewrite) {
3140           patch_bytecode(Bytecodes::_fast_vputfield, bc, r19, true, byte_no);
3141         }
3142         __ b(Done);
3143       }
3144      }  // Valhalla
3145   }
3146 
3147   __ bind(notObj);
3148   __ cmp(tos_state, (u1)itos);
3149   __ br(Assembler::NE, notInt);
3150 
3151   // itos
3152   {
3153     __ pop(itos);
3154     if (!is_static) pop_and_check_object(obj);
3155     __ access_store_at(T_INT, IN_HEAP, field, r0, noreg, noreg, noreg);
3156     if (rc == may_rewrite) {
3157       patch_bytecode(Bytecodes::_fast_iputfield, bc, r1, true, byte_no);
3158     }
3159     __ b(Done);
3160   }
3161 
3162   __ bind(notInt);
3163   __ cmp(tos_state, (u1)ctos);
3164   __ br(Assembler::NE, notChar);

3229   {
3230     __ pop(dtos);
3231     if (!is_static) pop_and_check_object(obj);
3232     __ access_store_at(T_DOUBLE, IN_HEAP, field, noreg /* dtos */, noreg, noreg, noreg);
3233     if (rc == may_rewrite) {
3234       patch_bytecode(Bytecodes::_fast_dputfield, bc, r1, true, byte_no);
3235     }
3236   }
3237 
3238 #ifdef ASSERT
3239   __ b(Done);
3240 
3241   __ bind(notDouble);
3242   __ stop("Bad state");
3243 #endif
3244 
3245   __ bind(Done);
3246 
3247   {
3248     Label notVolatile;
3249     __ tbz(flags, ResolvedFieldEntry::is_volatile_shift, notVolatile);
3250     __ membar(MacroAssembler::StoreLoad | MacroAssembler::StoreStore);
3251     __ bind(notVolatile);
3252   }
3253 }
3254 
3255 void TemplateTable::putfield(int byte_no)
3256 {
3257   putfield_or_static(byte_no, false);
3258 }
3259 
3260 void TemplateTable::nofast_putfield(int byte_no) {
3261   putfield_or_static(byte_no, false, may_not_rewrite);
3262 }
3263 
3264 void TemplateTable::putstatic(int byte_no) {
3265   putfield_or_static(byte_no, true);
3266 }
3267 
3268 void TemplateTable::jvmti_post_fast_field_mod() {
3269   if (JvmtiExport::can_post_field_modification()) {
3270     // Check to see if a field modification watch has been set before
3271     // we take the time to call into the VM.
3272     Label L2;
3273     __ lea(rscratch1, ExternalAddress((address)JvmtiExport::get_field_modification_count_addr()));
3274     __ ldrw(c_rarg3, Address(rscratch1));
3275     __ cbzw(c_rarg3, L2);
3276     __ pop_ptr(r19);                  // copy the object pointer from tos
3277     __ verify_oop(r19);
3278     __ push_ptr(r19);                 // put the object pointer back on tos
3279     // Save tos values before call_VM() clobbers them. Since we have
3280     // to do it for every data type, we use the saved values as the
3281     // jvalue object.
3282     switch (bytecode()) {          // load values into the jvalue object
3283     case Bytecodes::_fast_vputfield: //fall through
3284     case Bytecodes::_fast_aputfield: __ push_ptr(r0); break;
3285     case Bytecodes::_fast_bputfield: // fall through
3286     case Bytecodes::_fast_zputfield: // fall through
3287     case Bytecodes::_fast_sputfield: // fall through
3288     case Bytecodes::_fast_cputfield: // fall through
3289     case Bytecodes::_fast_iputfield: __ push_i(r0); break;
3290     case Bytecodes::_fast_dputfield: __ push_d(); break;
3291     case Bytecodes::_fast_fputfield: __ push_f(); break;
3292     case Bytecodes::_fast_lputfield: __ push_l(r0); break;
3293 
3294     default:
3295       ShouldNotReachHere();
3296     }
3297     __ mov(c_rarg3, esp);             // points to jvalue on the stack
3298     // access constant pool cache entry
3299     __ load_field_entry(c_rarg2, r0);
3300     __ verify_oop(r19);
3301     // r19: object pointer copied above
3302     // c_rarg2: cache entry pointer
3303     // c_rarg3: jvalue object on the stack
3304     __ call_VM(noreg,
3305                CAST_FROM_FN_PTR(address,
3306                                 InterpreterRuntime::post_field_modification),
3307                r19, c_rarg2, c_rarg3);
3308 
3309     switch (bytecode()) {             // restore tos values
3310     case Bytecodes::_fast_vputfield: //fall through
3311     case Bytecodes::_fast_aputfield: __ pop_ptr(r0); break;
3312     case Bytecodes::_fast_bputfield: // fall through
3313     case Bytecodes::_fast_zputfield: // fall through
3314     case Bytecodes::_fast_sputfield: // fall through
3315     case Bytecodes::_fast_cputfield: // fall through
3316     case Bytecodes::_fast_iputfield: __ pop_i(r0); break;
3317     case Bytecodes::_fast_dputfield: __ pop_d(); break;
3318     case Bytecodes::_fast_fputfield: __ pop_f(); break;
3319     case Bytecodes::_fast_lputfield: __ pop_l(r0); break;
3320     default: break;
3321     }
3322     __ bind(L2);
3323   }
3324 }
3325 
3326 void TemplateTable::fast_storefield(TosState state)
3327 {
3328   transition(state, vtos);
3329 
3330   ByteSize base = ConstantPoolCache::base_offset();

3337   // R1: field offset, R2: field holder, R3: flags
3338   load_resolved_field_entry(r2, r2, noreg, r1, r3);
3339 
3340   {
3341     Label notVolatile;
3342     __ tbz(r3, ResolvedFieldEntry::is_volatile_shift, notVolatile);
3343     __ membar(MacroAssembler::StoreStore | MacroAssembler::LoadStore);
3344     __ bind(notVolatile);
3345   }
3346 
3347   Label notVolatile;
3348 
3349   // Get object from stack
3350   pop_and_check_object(r2);
3351 
3352   // field address
3353   const Address field(r2, r1);
3354 
3355   // access field
3356   switch (bytecode()) {
3357   case Bytecodes::_fast_vputfield:
3358    {
3359       Label is_flat, has_null_marker, done;
3360       __ test_field_has_null_marker(r3, noreg /* temp */, has_null_marker);
3361       __ null_check(r0);
3362       __ test_field_is_flat(r3, noreg /* temp */, is_flat);
3363       // field is not flat
3364       do_oop_store(_masm, field, r0, IN_HEAP);
3365       __ b(done);
3366       __ bind(is_flat);
3367       // field is flat
3368       __ load_field_entry(r4, r3);
3369       __ load_unsigned_short(r3, Address(r4, in_bytes(ResolvedFieldEntry::field_index_offset())));
3370       __ ldr(r4, Address(r4, in_bytes(ResolvedFieldEntry::field_holder_offset())));
3371       __ inline_layout_info(r4, r3, r5);
3372       __ load_klass(r4, r0);
3373       __ data_for_oop(r0, r0, r4);
3374       __ lea(rscratch1, field);
3375       __ flat_field_copy(IN_HEAP, r0, rscratch1, r5);
3376       __ b(done);
3377       __ bind(has_null_marker);
3378       __ load_field_entry(r4, r1);
3379       __ mov(r1, r2);
3380       __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::write_nullable_flat_field), r1, r0, r4);
3381       __ bind(done);
3382     }
3383     break;
3384   case Bytecodes::_fast_aputfield:
3385     do_oop_store(_masm, field, r0, IN_HEAP);
3386     break;
3387   case Bytecodes::_fast_lputfield:
3388     __ access_store_at(T_LONG, IN_HEAP, field, r0, noreg, noreg, noreg);
3389     break;
3390   case Bytecodes::_fast_iputfield:
3391     __ access_store_at(T_INT, IN_HEAP, field, r0, noreg, noreg, noreg);
3392     break;
3393   case Bytecodes::_fast_zputfield:
3394     __ access_store_at(T_BOOLEAN, IN_HEAP, field, r0, noreg, noreg, noreg);
3395     break;
3396   case Bytecodes::_fast_bputfield:
3397     __ access_store_at(T_BYTE, IN_HEAP, field, r0, noreg, noreg, noreg);
3398     break;
3399   case Bytecodes::_fast_sputfield:
3400     __ access_store_at(T_SHORT, IN_HEAP, field, r0, noreg, noreg, noreg);
3401     break;
3402   case Bytecodes::_fast_cputfield:
3403     __ access_store_at(T_CHAR, IN_HEAP, field, r0, noreg, noreg, noreg);

3456   // r0: object
3457   __ verify_oop(r0);
3458   __ null_check(r0);
3459   const Address field(r0, r1);
3460 
3461   // 8179954: We need to make sure that the code generated for
3462   // volatile accesses forms a sequentially-consistent set of
3463   // operations when combined with STLR and LDAR.  Without a leading
3464   // membar it's possible for a simple Dekker test to fail if loads
3465   // use LDR;DMB but stores use STLR.  This can happen if C2 compiles
3466   // the stores in one method and we interpret the loads in another.
3467   if (!CompilerConfig::is_c1_or_interpreter_only_no_jvmci()) {
3468     Label notVolatile;
3469     __ tbz(r3, ResolvedFieldEntry::is_volatile_shift, notVolatile);
3470     __ membar(MacroAssembler::AnyAny);
3471     __ bind(notVolatile);
3472   }
3473 
3474   // access field
3475   switch (bytecode()) {
3476   case Bytecodes::_fast_vgetfield:
3477     {
3478       Register index = r4, klass = r5, inline_klass = r6, tmp = r7;
3479       Label is_flat, has_null_marker, nonnull, Done;
3480       __ test_field_has_null_marker(r3, noreg /*temp*/, has_null_marker);
3481       __ test_field_is_flat(r3, noreg /* temp */, is_flat);
3482         // field is not flat
3483         __ load_heap_oop(r0, field, rscratch1, rscratch2);
3484         __ cbnz(r0, nonnull);
3485           __ load_unsigned_short(index, Address(r2, in_bytes(ResolvedFieldEntry::field_index_offset())));
3486           __ ldr(klass, Address(r2, in_bytes(ResolvedFieldEntry::field_holder_offset())));
3487           __ get_inline_type_field_klass(klass, index, inline_klass);
3488           __ get_default_value_oop(inline_klass, tmp /* temp */, r0);
3489         __ bind(nonnull);
3490         __ verify_oop(r0);
3491         __ b(Done);
3492       __ bind(is_flat);
3493       // field is flat
3494         __ load_unsigned_short(index, Address(r2, in_bytes(ResolvedFieldEntry::field_index_offset())));
3495         __ read_flat_field(r2, index, r1, tmp /* temp */, r0);
3496         __ verify_oop(r0);
3497         __ b(Done);
3498       __ bind(has_null_marker);
3499         call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::read_nullable_flat_field), r0, r2);
3500         __ verify_oop(r0);
3501       __ bind(Done);
3502     }
3503     break;
3504   case Bytecodes::_fast_agetfield:
3505     do_oop_load(_masm, field, r0, IN_HEAP);
3506     __ verify_oop(r0);
3507     break;
3508   case Bytecodes::_fast_lgetfield:
3509     __ access_load_at(T_LONG, IN_HEAP, r0, field, noreg, noreg);
3510     break;
3511   case Bytecodes::_fast_igetfield:
3512     __ access_load_at(T_INT, IN_HEAP, r0, field, noreg, noreg);
3513     break;
3514   case Bytecodes::_fast_bgetfield:
3515     __ access_load_at(T_BYTE, IN_HEAP, r0, field, noreg, noreg);
3516     break;
3517   case Bytecodes::_fast_sgetfield:
3518     __ access_load_at(T_SHORT, IN_HEAP, r0, field, noreg, noreg);
3519     break;
3520   case Bytecodes::_fast_cgetfield:
3521     __ access_load_at(T_CHAR, IN_HEAP, r0, field, noreg, noreg);
3522     break;
3523   case Bytecodes::_fast_fgetfield:

3902   Label initialize_header;
3903 
3904   __ get_cpool_and_tags(r4, r0);
3905   // Make sure the class we're about to instantiate has been resolved.
3906   // This is done before loading InstanceKlass to be consistent with the order
3907   // how Constant Pool is updated (see ConstantPool::klass_at_put)
3908   const int tags_offset = Array<u1>::base_offset_in_bytes();
3909   __ lea(rscratch1, Address(r0, r3, Address::lsl(0)));
3910   __ lea(rscratch1, Address(rscratch1, tags_offset));
3911   __ ldarb(rscratch1, rscratch1);
3912   __ cmp(rscratch1, (u1)JVM_CONSTANT_Class);
3913   __ br(Assembler::NE, slow_case);
3914 
3915   // get InstanceKlass
3916   __ load_resolved_klass_at_offset(r4, r3, r4, rscratch1);
3917 
3918   // make sure klass is initialized
3919   assert(VM_Version::supports_fast_class_init_checks(), "Optimization requires support for fast class initialization checks");
3920   __ clinit_barrier(r4, rscratch1, nullptr /*L_fast_path*/, &slow_case);
3921 
3922   __ allocate_instance(r4, r0, r3, r1, true, slow_case);













































3923     if (DTraceAllocProbes) {
3924       // Trigger dtrace event for fastpath
3925       __ push(atos); // save the return value
3926       __ call_VM_leaf(
3927            CAST_FROM_FN_PTR(address, static_cast<int (*)(oopDesc*)>(SharedRuntime::dtrace_object_alloc)), r0);
3928       __ pop(atos); // restore the return value
3929 
3930     }
3931   __ b(done);

3932 
3933   // slow case
3934   __ bind(slow_case);
3935   __ get_constant_pool(c_rarg1);
3936   __ get_unsigned_2_byte_index_at_bcp(c_rarg2, 1);
3937   call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), c_rarg1, c_rarg2);
3938   __ verify_oop(r0);
3939 
3940   // continue
3941   __ bind(done);
3942   // Must prevent reordering of stores for object initialization with stores that publish the new object.
3943   __ membar(Assembler::StoreStore);
3944 }
3945 
3946 void TemplateTable::newarray() {
3947   transition(itos, atos);
3948   __ load_unsigned_byte(c_rarg1, at_bcp(1));
3949   __ mov(c_rarg2, r0);
3950   call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::newarray),
3951           c_rarg1, c_rarg2);

3996   __ bind(quicked);
3997   __ mov(r3, r0); // Save object in r3; r0 needed for subtype check
3998   __ load_resolved_klass_at_offset(r2, r19, r0, rscratch1); // r0 = klass
3999 
4000   __ bind(resolved);
4001   __ load_klass(r19, r3);
4002 
4003   // Generate subtype check.  Blows r2, r5.  Object in r3.
4004   // Superklass in r0.  Subklass in r19.
4005   __ gen_subtype_check(r19, ok_is_subtype);
4006 
4007   // Come here on failure
4008   __ push(r3);
4009   // object is at TOS
4010   __ b(Interpreter::_throw_ClassCastException_entry);
4011 
4012   // Come here on success
4013   __ bind(ok_is_subtype);
4014   __ mov(r0, r3); // Restore object in r3
4015 
4016   __ b(done);
4017   __ bind(is_null);
4018 
4019   // Collect counts on whether this test sees nulls a lot or not.
4020   if (ProfileInterpreter) {


4021     __ profile_null_seen(r2);


4022   }
4023 
4024   __ bind(done);
4025 }
4026 
4027 void TemplateTable::instanceof() {
4028   transition(atos, itos);
4029   Label done, is_null, ok_is_subtype, quicked, resolved;
4030   __ cbz(r0, is_null);
4031 
4032   // Get cpool & tags index
4033   __ get_cpool_and_tags(r2, r3); // r2=cpool, r3=tags array
4034   __ get_unsigned_2_byte_index_at_bcp(r19, 1); // r19=index
4035   // See if bytecode has already been quicked
4036   __ add(rscratch1, r3, Array<u1>::base_offset_in_bytes());
4037   __ lea(r1, Address(rscratch1, r19));
4038   __ ldarb(r1, r1);
4039   __ cmp(r1, (u1)JVM_CONSTANT_Class);
4040   __ br(Assembler::EQ, quicked);
4041 
4042   __ push(atos); // save receiver for result, and for GC
4043   call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc));

4122 //       in the assembly code structure as well
4123 //
4124 // Stack layout:
4125 //
4126 // [expressions  ] <--- esp               = expression stack top
4127 // ..
4128 // [expressions  ]
4129 // [monitor entry] <--- monitor block top = expression stack bot
4130 // ..
4131 // [monitor entry]
4132 // [frame data   ] <--- monitor block bot
4133 // ...
4134 // [saved rfp    ] <--- rfp
4135 void TemplateTable::monitorenter()
4136 {
4137   transition(atos, vtos);
4138 
4139   // check for null object
4140   __ null_check(r0);
4141 
4142   Label is_inline_type;
4143   __ ldr(rscratch1, Address(r0, oopDesc::mark_offset_in_bytes()));
4144   __ test_markword_is_inline_type(rscratch1, is_inline_type);
4145 
4146   const Address monitor_block_top(
4147         rfp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
4148   const Address monitor_block_bot(
4149         rfp, frame::interpreter_frame_initial_sp_offset * wordSize);
4150   const int entry_size = frame::interpreter_frame_monitor_size_in_bytes();
4151 
4152   Label allocated;
4153 
4154   // initialize entry pointer
4155   __ mov(c_rarg1, zr); // points to free slot or null
4156 
4157   // find a free slot in the monitor block (result in c_rarg1)
4158   {
4159     Label entry, loop, exit;
4160     __ ldr(c_rarg3, monitor_block_top); // derelativize pointer
4161     __ lea(c_rarg3, Address(rfp, c_rarg3, Address::lsl(Interpreter::logStackElementSize)));
4162     // c_rarg3 points to current entry, starting with top-most entry
4163 
4164     __ lea(c_rarg2, monitor_block_bot); // points to word before bottom
4165 

4227   // c_rarg1: points to monitor entry
4228   __ bind(allocated);
4229 
4230   // Increment bcp to point to the next bytecode, so exception
4231   // handling for async. exceptions work correctly.
4232   // The object has already been popped from the stack, so the
4233   // expression stack looks correct.
4234   __ increment(rbcp);
4235 
4236   // store object
4237   __ str(r0, Address(c_rarg1, BasicObjectLock::obj_offset()));
4238   __ lock_object(c_rarg1);
4239 
4240   // check to make sure this monitor doesn't cause stack overflow after locking
4241   __ save_bcp();  // in case of exception
4242   __ generate_stack_overflow_check(0);
4243 
4244   // The bcp has already been incremented. Just need to dispatch to
4245   // next instruction.
4246   __ dispatch_next(vtos);
4247 
4248   __ bind(is_inline_type);
4249   __ call_VM(noreg, CAST_FROM_FN_PTR(address,
4250                     InterpreterRuntime::throw_identity_exception), r0);
4251   __ should_not_reach_here();
4252 }
4253 
4254 
4255 void TemplateTable::monitorexit()
4256 {
4257   transition(atos, vtos);
4258 
4259   // check for null object
4260   __ null_check(r0);
4261 
4262   const int is_inline_type_mask = markWord::inline_type_pattern;
4263   Label has_identity;
4264   __ ldr(rscratch1, Address(r0, oopDesc::mark_offset_in_bytes()));
4265   __ mov(rscratch2, is_inline_type_mask);
4266   __ andr(rscratch1, rscratch1, rscratch2);
4267   __ cmp(rscratch1, rscratch2);
4268   __ br(Assembler::NE, has_identity);
4269   __ call_VM(noreg, CAST_FROM_FN_PTR(address,
4270                      InterpreterRuntime::throw_illegal_monitor_state_exception));
4271   __ should_not_reach_here();
4272   __ bind(has_identity);
4273 
4274   const Address monitor_block_top(
4275         rfp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
4276   const Address monitor_block_bot(
4277         rfp, frame::interpreter_frame_initial_sp_offset * wordSize);
4278   const int entry_size = frame::interpreter_frame_monitor_size_in_bytes();
4279 
4280   Label found;
4281 
4282   // find matching slot
4283   {
4284     Label entry, loop;
4285     __ ldr(c_rarg1, monitor_block_top); // derelativize pointer
4286     __ lea(c_rarg1, Address(rfp, c_rarg1, Address::lsl(Interpreter::logStackElementSize)));
4287     // c_rarg1 points to current entry, starting with top-most entry
4288 
4289     __ lea(c_rarg2, monitor_block_bot); // points to word before bottom
4290                                         // of monitor block
4291     __ b(entry);
4292 
4293     __ bind(loop);
< prev index next >