< prev index next >

src/hotspot/cpu/aarch64/templateTable_aarch64.cpp

Print this page

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

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

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

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















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

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




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


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








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


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











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









































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

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






































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

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










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

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



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





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

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































































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

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

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

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














































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

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

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

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

3077   // Must prevent reordering of the following cp cache loads with bytecode load
3078   __ membar(MacroAssembler::LoadLoad);
3079 
3080   {
3081     Label notVolatile;
3082     __ tbz(r3, ResolvedFieldEntry::is_volatile_shift, notVolatile);
3083     __ membar(MacroAssembler::StoreStore | MacroAssembler::LoadStore);
3084     __ bind(notVolatile);
3085   }
3086 
3087   Label notVolatile;
3088 
3089   // Get object from stack
3090   pop_and_check_object(r2);
3091 
3092   // field address
3093   const Address field(r2, r1);
3094 
3095   // access field
3096   switch (bytecode()) {

















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

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
























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

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

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



3753   // Collect counts on whether this test sees nulls a lot or not.
3754   if (ProfileInterpreter) {
3755     __ b(done);
3756     __ bind(is_null);
3757     __ profile_null_seen(r2);
3758   } else {
3759     __ bind(is_null);   // same as 'done'
3760   }

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

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




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

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





3980 }
3981 
3982 
3983 void TemplateTable::monitorexit()
3984 {
3985   transition(atos, vtos);
3986 
3987   // check for null object
3988   __ null_check(r0);
3989 












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

 155 static void do_oop_load(InterpreterMacroAssembler* _masm,
 156                         Address src,
 157                         Register dst,
 158                         DecoratorSet decorators) {
 159   __ load_heap_oop(dst, src, r10, r11, decorators);
 160 }
 161 
 162 Address TemplateTable::at_bcp(int offset) {
 163   assert(_desc->uses_bcp(), "inconsistent uses_bcp information");
 164   return Address(rbcp, offset);
 165 }
 166 
 167 void TemplateTable::patch_bytecode(Bytecodes::Code bc, Register bc_reg,
 168                                    Register temp_reg, bool load_bc_into_bc_reg/*=true*/,
 169                                    int byte_no)
 170 {
 171   if (!RewriteBytecodes)  return;
 172   Label L_patch_done;
 173 
 174   switch (bc) {
 175   case Bytecodes::_fast_qputfield:
 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   __ profile_array_type<ArrayLoadData>(r2, r0, r4);
 821   if (UseFlatArray) {
 822     Label is_flat_array, done;
 823 
 824     __ test_flat_array_oop(r0, r8 /*temp*/, is_flat_array);
 825     __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_OBJECT) >> LogBytesPerHeapOop);
 826     do_oop_load(_masm, Address(r0, r1, Address::uxtw(LogBytesPerHeapOop)), r0, IS_ARRAY);
 827 
 828     __ b(done);
 829     __ bind(is_flat_array);
 830     __ call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::value_array_load), r0, r1);
 831     // Ensure the stores to copy the inline field contents are visible
 832     // before any subsequent store that publishes this reference.
 833     __ membar(Assembler::StoreStore);
 834     __ bind(done);
 835   } else {
 836     __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_OBJECT) >> LogBytesPerHeapOop);
 837     do_oop_load(_masm, Address(r0, r1, Address::uxtw(LogBytesPerHeapOop)), r0, IS_ARRAY);
 838   }
 839   __ profile_element_type(r2, r0, r4);
 840 }
 841 
 842 void TemplateTable::baload()
 843 {
 844   transition(itos, itos);
 845   __ mov(r1, r0);
 846   __ pop_ptr(r0);
 847   // r0: array
 848   // r1: index
 849   index_check(r0, r1); // leaves index in r1, kills rscratch1
 850   __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_BYTE) >> 0);
 851   __ access_load_at(T_BYTE, IN_HEAP | IS_ARRAY, r0, Address(r0, r1, Address::uxtw(0)), noreg, noreg);
 852 }
 853 
 854 void TemplateTable::caload()
 855 {
 856   transition(itos, itos);
 857   __ mov(r1, r0);
 858   __ pop_ptr(r0);
 859   // r0: array

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


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

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

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

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

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

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

2853 
2854   __ bind(notObj);
2855   __ cmp(tos_state, (u1)itos);
2856   __ br(Assembler::NE, notInt);
2857   // itos
2858   __ access_load_at(T_INT, IN_HEAP, r0, field, noreg, noreg);
2859   __ push(itos);
2860   // Rewrite bytecode to be faster
2861   if (rc == may_rewrite) {
2862     patch_bytecode(Bytecodes::_fast_igetfield, bc, r1);
2863   }
2864   __ b(Done);
2865 
2866   __ bind(notInt);
2867   __ cmp(tos_state, (u1)ctos);
2868   __ br(Assembler::NE, notChar);
2869   // ctos
2870   __ access_load_at(T_CHAR, IN_HEAP, r0, field, noreg, noreg);
2871   __ push(ctos);
2872   // Rewrite bytecode to be faster

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


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

3053   __ cmp(tos_state, (u1)ztos);
3054   __ br(Assembler::NE, notBool);
3055 
3056   // ztos
3057   {
3058     __ pop(ztos);
3059     if (!is_static) pop_and_check_object(obj);
3060     __ access_store_at(T_BOOLEAN, IN_HEAP, field, r0, noreg, noreg, noreg);
3061     if (rc == may_rewrite) {
3062       patch_bytecode(Bytecodes::_fast_zputfield, bc, r1, true, byte_no);
3063     }
3064     __ b(Done);
3065   }
3066 
3067   __ bind(notBool);
3068   __ cmp(tos_state, (u1)atos);
3069   __ br(Assembler::NE, notObj);
3070 
3071   // atos
3072   {
3073      if (!EnableValhalla) {
3074       __ pop(atos);
3075       if (!is_static) pop_and_check_object(obj);
3076       // Store into the field
3077       do_oop_store(_masm, field, r0, IN_HEAP);
3078       if (rc == may_rewrite) {
3079         patch_bytecode(Bytecodes::_fast_aputfield, bc, r1, true, byte_no);
3080       }
3081       __ b(Done);
3082      } else { // Valhalla
3083       __ pop(atos);
3084       if (is_static) {
3085         Label is_inline_type;
3086          __ test_field_is_not_null_free_inline_type(flags, noreg /* temp */, is_inline_type);
3087          __ null_check(r0);
3088          __ bind(is_inline_type);
3089          do_oop_store(_masm, field, r0, IN_HEAP);
3090          __ b(Done);
3091       } else {
3092         Label is_inline_type, is_flat, rewrite_not_inline, rewrite_inline;
3093         __ test_field_is_null_free_inline_type(flags, noreg /*temp*/, is_inline_type);
3094         // Not an inline type
3095         pop_and_check_object(obj);
3096         // Store into the field
3097         do_oop_store(_masm, field, r0, IN_HEAP);
3098         __ bind(rewrite_not_inline);
3099         if (rc == may_rewrite) {
3100           patch_bytecode(Bytecodes::_fast_aputfield, bc, r19, true, byte_no);
3101         }
3102         __ b(Done);
3103         // Implementation of the inline type semantic
3104         __ bind(is_inline_type);
3105         __ null_check(r0);
3106         __ test_field_is_flat(flags, noreg /*temp*/, is_flat);
3107         // field is not flat
3108         pop_and_check_object(obj);
3109         // Store into the field
3110         do_oop_store(_masm, field, r0, IN_HEAP);
3111         __ b(rewrite_inline);
3112         __ bind(is_flat);
3113         // field is flat
3114         pop_and_check_object(obj);
3115         assert_different_registers(r0, inline_klass, obj, off);
3116         __ load_klass(inline_klass, r0);
3117         __ data_for_oop(r0, r0, inline_klass);
3118         __ add(obj, obj, off);
3119         __ access_value_copy(IN_HEAP, r0, obj, inline_klass);
3120         __ bind(rewrite_inline);
3121         if (rc == may_rewrite) {
3122           patch_bytecode(Bytecodes::_fast_qputfield, bc, r19, true, byte_no);
3123         }
3124         __ b(Done);
3125       }
3126      }  // Valhalla
3127   }
3128 
3129   __ bind(notObj);
3130   __ cmp(tos_state, (u1)itos);
3131   __ br(Assembler::NE, notInt);
3132 
3133   // itos
3134   {
3135     __ pop(itos);
3136     if (!is_static) pop_and_check_object(obj);
3137     __ access_store_at(T_INT, IN_HEAP, field, r0, noreg, noreg, noreg);
3138     if (rc == may_rewrite) {
3139       patch_bytecode(Bytecodes::_fast_iputfield, bc, r1, true, byte_no);
3140     }
3141     __ b(Done);
3142   }
3143 
3144   __ bind(notInt);
3145   __ cmp(tos_state, (u1)ctos);
3146   __ br(Assembler::NE, notChar);

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

3323   // Must prevent reordering of the following cp cache loads with bytecode load
3324   __ membar(MacroAssembler::LoadLoad);
3325 
3326   {
3327     Label notVolatile;
3328     __ tbz(r3, ResolvedFieldEntry::is_volatile_shift, notVolatile);
3329     __ membar(MacroAssembler::StoreStore | MacroAssembler::LoadStore);
3330     __ bind(notVolatile);
3331   }
3332 
3333   Label notVolatile;
3334 
3335   // Get object from stack
3336   pop_and_check_object(r2);
3337 
3338   // field address
3339   const Address field(r2, r1);
3340 
3341   // access field
3342   switch (bytecode()) {
3343   case Bytecodes::_fast_qputfield: //fall through
3344    {
3345       Label is_flat, done;
3346       __ null_check(r0);
3347       __ test_field_is_flat(r3, noreg /* temp */, is_flat);
3348       // field is not flat
3349       do_oop_store(_masm, field, r0, IN_HEAP);
3350       __ b(done);
3351       __ bind(is_flat);
3352       // field is flat
3353       __ load_klass(r4, r0);
3354       __ data_for_oop(r0, r0, r4);
3355       __ lea(rscratch1, field);
3356       __ access_value_copy(IN_HEAP, r0, rscratch1, r4);
3357       __ bind(done);
3358     }
3359     break;
3360   case Bytecodes::_fast_aputfield:
3361     do_oop_store(_masm, field, r0, IN_HEAP);
3362     break;
3363   case Bytecodes::_fast_lputfield:
3364     __ access_store_at(T_LONG, IN_HEAP, field, r0, noreg, noreg, noreg);
3365     break;
3366   case Bytecodes::_fast_iputfield:
3367     __ access_store_at(T_INT, IN_HEAP, field, r0, noreg, noreg, noreg);
3368     break;
3369   case Bytecodes::_fast_zputfield:
3370     __ access_store_at(T_BOOLEAN, IN_HEAP, field, r0, noreg, noreg, noreg);
3371     break;
3372   case Bytecodes::_fast_bputfield:
3373     __ access_store_at(T_BYTE, IN_HEAP, field, r0, noreg, noreg, noreg);
3374     break;
3375   case Bytecodes::_fast_sputfield:
3376     __ access_store_at(T_SHORT, IN_HEAP, field, r0, noreg, noreg, noreg);
3377     break;
3378   case Bytecodes::_fast_cputfield:
3379     __ access_store_at(T_CHAR, IN_HEAP, field, r0, noreg, noreg, noreg);

3435   // r0: object
3436   __ verify_oop(r0);
3437   __ null_check(r0);
3438   const Address field(r0, r1);
3439 
3440   // 8179954: We need to make sure that the code generated for
3441   // volatile accesses forms a sequentially-consistent set of
3442   // operations when combined with STLR and LDAR.  Without a leading
3443   // membar it's possible for a simple Dekker test to fail if loads
3444   // use LDR;DMB but stores use STLR.  This can happen if C2 compiles
3445   // the stores in one method and we interpret the loads in another.
3446   if (!CompilerConfig::is_c1_or_interpreter_only_no_jvmci()) {
3447     Label notVolatile;
3448     __ tbz(r3, ResolvedFieldEntry::is_volatile_shift, notVolatile);
3449     __ membar(MacroAssembler::AnyAny);
3450     __ bind(notVolatile);
3451   }
3452 
3453   // access field
3454   switch (bytecode()) {
3455   case Bytecodes::_fast_qgetfield:
3456     {
3457       Register index = r4, klass = r5, inline_klass = r6, tmp = r7;
3458       Label is_flat, nonnull, Done;
3459       __ test_field_is_flat(r3, noreg /* temp */, is_flat);
3460         // field is not flat
3461         __ load_heap_oop(r0, field, rscratch1, rscratch2);
3462         __ cbnz(r0, nonnull);
3463           __ load_unsigned_short(index, Address(r2, in_bytes(ResolvedFieldEntry::field_index_offset())));
3464           __ ldr(klass, Address(r2, in_bytes(ResolvedFieldEntry::field_holder_offset())));
3465           __ get_inline_type_field_klass(klass, index, inline_klass);
3466           __ get_default_value_oop(inline_klass, tmp /* temp */, r0);
3467         __ bind(nonnull);
3468         __ verify_oop(r0);
3469         __ b(Done);
3470       __ bind(is_flat);
3471       // field is flat
3472         __ load_unsigned_short(index, Address(r2, in_bytes(ResolvedFieldEntry::field_index_offset())));
3473         __ ldr(klass, Address(r2, in_bytes(ResolvedFieldEntry::field_holder_offset())));
3474         __ read_flat_field(klass, index, r1, tmp /* temp */, r0);
3475         __ verify_oop(r0);
3476       __ bind(Done);
3477     }
3478     break;
3479   case Bytecodes::_fast_agetfield:
3480     do_oop_load(_masm, field, r0, IN_HEAP);
3481     __ verify_oop(r0);
3482     break;
3483   case Bytecodes::_fast_lgetfield:
3484     __ access_load_at(T_LONG, IN_HEAP, r0, field, noreg, noreg);
3485     break;
3486   case Bytecodes::_fast_igetfield:
3487     __ access_load_at(T_INT, IN_HEAP, r0, field, noreg, noreg);
3488     break;
3489   case Bytecodes::_fast_bgetfield:
3490     __ access_load_at(T_BYTE, IN_HEAP, r0, field, noreg, noreg);
3491     break;
3492   case Bytecodes::_fast_sgetfield:
3493     __ access_load_at(T_SHORT, IN_HEAP, r0, field, noreg, noreg);
3494     break;
3495   case Bytecodes::_fast_cgetfield:
3496     __ access_load_at(T_CHAR, IN_HEAP, r0, field, noreg, noreg);
3497     break;
3498   case Bytecodes::_fast_fgetfield:

3879   __ get_cpool_and_tags(r4, r0);
3880   // Make sure the class we're about to instantiate has been resolved.
3881   // This is done before loading InstanceKlass to be consistent with the order
3882   // how Constant Pool is updated (see ConstantPool::klass_at_put)
3883   const int tags_offset = Array<u1>::base_offset_in_bytes();
3884   __ lea(rscratch1, Address(r0, r3, Address::lsl(0)));
3885   __ lea(rscratch1, Address(rscratch1, tags_offset));
3886   __ ldarb(rscratch1, rscratch1);
3887   __ cmp(rscratch1, (u1)JVM_CONSTANT_Class);
3888   __ br(Assembler::NE, slow_case);
3889 
3890   // get InstanceKlass
3891   __ load_resolved_klass_at_offset(r4, r3, r4, rscratch1);
3892 
3893   // make sure klass is initialized & doesn't have finalizer
3894   // make sure klass is fully initialized
3895   __ ldrb(rscratch1, Address(r4, InstanceKlass::init_state_offset()));
3896   __ cmp(rscratch1, (u1)InstanceKlass::fully_initialized);
3897   __ br(Assembler::NE, slow_case);
3898 
3899   __ allocate_instance(r4, r0, r3, r1, true, slow_case);
3900   __ b(done);























































3901 
3902   // slow case
3903   __ bind(slow_case);
3904   __ get_constant_pool(c_rarg1);
3905   __ get_unsigned_2_byte_index_at_bcp(c_rarg2, 1);
3906   call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), c_rarg1, c_rarg2);
3907   __ verify_oop(r0);
3908 
3909   // continue
3910   __ bind(done);
3911   // Must prevent reordering of stores for object initialization with stores that publish the new object.
3912   __ membar(Assembler::StoreStore);
3913 }
3914 
3915 void TemplateTable::newarray() {
3916   transition(itos, atos);
3917   __ load_unsigned_byte(c_rarg1, at_bcp(1));
3918   __ mov(c_rarg2, r0);
3919   call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::newarray),
3920           c_rarg1, c_rarg2);

3965   __ bind(quicked);
3966   __ mov(r3, r0); // Save object in r3; r0 needed for subtype check
3967   __ load_resolved_klass_at_offset(r2, r19, r0, rscratch1); // r0 = klass
3968 
3969   __ bind(resolved);
3970   __ load_klass(r19, r3);
3971 
3972   // Generate subtype check.  Blows r2, r5.  Object in r3.
3973   // Superklass in r0.  Subklass in r19.
3974   __ gen_subtype_check(r19, ok_is_subtype);
3975 
3976   // Come here on failure
3977   __ push(r3);
3978   // object is at TOS
3979   __ b(Interpreter::_throw_ClassCastException_entry);
3980 
3981   // Come here on success
3982   __ bind(ok_is_subtype);
3983   __ mov(r0, r3); // Restore object in r3
3984 
3985   __ b(done);
3986   __ bind(is_null);
3987 
3988   // Collect counts on whether this test sees nulls a lot or not.
3989   if (ProfileInterpreter) {


3990     __ profile_null_seen(r2);


3991   }
3992 
3993   __ bind(done);
3994 }
3995 
3996 void TemplateTable::instanceof() {
3997   transition(atos, itos);
3998   Label done, is_null, ok_is_subtype, quicked, resolved;
3999   __ cbz(r0, is_null);
4000 
4001   // Get cpool & tags index
4002   __ get_cpool_and_tags(r2, r3); // r2=cpool, r3=tags array
4003   __ get_unsigned_2_byte_index_at_bcp(r19, 1); // r19=index
4004   // See if bytecode has already been quicked
4005   __ add(rscratch1, r3, Array<u1>::base_offset_in_bytes());
4006   __ lea(r1, Address(rscratch1, r19));
4007   __ ldarb(r1, r1);
4008   __ cmp(r1, (u1)JVM_CONSTANT_Class);
4009   __ br(Assembler::EQ, quicked);
4010 
4011   __ push(atos); // save receiver for result, and for GC
4012   call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc));

4091 //       in the assembly code structure as well
4092 //
4093 // Stack layout:
4094 //
4095 // [expressions  ] <--- esp               = expression stack top
4096 // ..
4097 // [expressions  ]
4098 // [monitor entry] <--- monitor block top = expression stack bot
4099 // ..
4100 // [monitor entry]
4101 // [frame data   ] <--- monitor block bot
4102 // ...
4103 // [saved rfp    ] <--- rfp
4104 void TemplateTable::monitorenter()
4105 {
4106   transition(atos, vtos);
4107 
4108   // check for null object
4109   __ null_check(r0);
4110 
4111   Label is_inline_type;
4112   __ ldr(rscratch1, Address(r0, oopDesc::mark_offset_in_bytes()));
4113   __ test_markword_is_inline_type(rscratch1, is_inline_type);
4114 
4115   const Address monitor_block_top(
4116         rfp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
4117   const Address monitor_block_bot(
4118         rfp, frame::interpreter_frame_initial_sp_offset * wordSize);
4119   const int entry_size = frame::interpreter_frame_monitor_size_in_bytes();
4120 
4121   Label allocated;
4122 
4123   // initialize entry pointer
4124   __ mov(c_rarg1, zr); // points to free slot or null
4125 
4126   // find a free slot in the monitor block (result in c_rarg1)
4127   {
4128     Label entry, loop, exit;
4129     __ ldr(c_rarg3, monitor_block_top); // derelativize pointer
4130     __ lea(c_rarg3, Address(rfp, c_rarg3, Address::lsl(Interpreter::logStackElementSize)));
4131     // c_rarg3 points to current entry, starting with top-most entry
4132 
4133     __ lea(c_rarg2, monitor_block_bot); // points to word before bottom
4134 

4196   // c_rarg1: points to monitor entry
4197   __ bind(allocated);
4198 
4199   // Increment bcp to point to the next bytecode, so exception
4200   // handling for async. exceptions work correctly.
4201   // The object has already been popped from the stack, so the
4202   // expression stack looks correct.
4203   __ increment(rbcp);
4204 
4205   // store object
4206   __ str(r0, Address(c_rarg1, BasicObjectLock::obj_offset()));
4207   __ lock_object(c_rarg1);
4208 
4209   // check to make sure this monitor doesn't cause stack overflow after locking
4210   __ save_bcp();  // in case of exception
4211   __ generate_stack_overflow_check(0);
4212 
4213   // The bcp has already been incremented. Just need to dispatch to
4214   // next instruction.
4215   __ dispatch_next(vtos);
4216 
4217   __ bind(is_inline_type);
4218   __ call_VM(noreg, CAST_FROM_FN_PTR(address,
4219                     InterpreterRuntime::throw_illegal_monitor_state_exception));
4220   __ should_not_reach_here();
4221 }
4222 
4223 
4224 void TemplateTable::monitorexit()
4225 {
4226   transition(atos, vtos);
4227 
4228   // check for null object
4229   __ null_check(r0);
4230 
4231   const int is_inline_type_mask = markWord::inline_type_pattern;
4232   Label has_identity;
4233   __ ldr(rscratch1, Address(r0, oopDesc::mark_offset_in_bytes()));
4234   __ mov(rscratch2, is_inline_type_mask);
4235   __ andr(rscratch1, rscratch1, rscratch2);
4236   __ cmp(rscratch1, rscratch2);
4237   __ br(Assembler::NE, has_identity);
4238   __ call_VM(noreg, CAST_FROM_FN_PTR(address,
4239                      InterpreterRuntime::throw_illegal_monitor_state_exception));
4240   __ should_not_reach_here();
4241   __ bind(has_identity);
4242 
4243   const Address monitor_block_top(
4244         rfp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
4245   const Address monitor_block_bot(
4246         rfp, frame::interpreter_frame_initial_sp_offset * wordSize);
4247   const int entry_size = frame::interpreter_frame_monitor_size_in_bytes();
4248 
4249   Label found;
4250 
4251   // find matching slot
4252   {
4253     Label entry, loop;
4254     __ ldr(c_rarg1, monitor_block_top); // derelativize pointer
4255     __ lea(c_rarg1, Address(rfp, c_rarg1, Address::lsl(Interpreter::logStackElementSize)));
4256     // c_rarg1 points to current entry, starting with top-most entry
4257 
4258     __ lea(c_rarg2, monitor_block_bot); // points to word before bottom
4259                                         // of monitor block
4260     __ b(entry);
4261 
4262     __ bind(loop);
< prev index next >