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 // Clobbers: r10, r11, r3
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 // Clobbers: r10, r11, r3
1157 do_oop_store(_masm, element_address, noreg, IS_ARRAY);
1158
1159 // Pop stack arguments
1160 __ bind(done);
1161 __ add(esp, esp, 3 * Interpreter::stackElementSize);
1162 }
1163
1164 void TemplateTable::bastore()
1165 {
1166 transition(itos, vtos);
1167 __ pop_i(r1);
1168 __ pop_ptr(r3);
1169 // r0: value
1170 // r1: index
1171 // r3: array
1172 index_check(r3, r1); // prefer index in r1
1173
1174 // Need to check whether array is boolean or byte
1175 // since both types share the bastore bytecode.
1176 __ load_klass(r2, r3);
1177 __ ldrw(r2, Address(r2, Klass::layout_helper_offset()));
1944 __ br(j_not(cc), not_taken);
1945 branch(false, false);
1946 __ bind(not_taken);
1947 __ profile_not_taken_branch(r0);
1948 }
1949
1950 void TemplateTable::if_nullcmp(Condition cc)
1951 {
1952 transition(atos, vtos);
1953 // assume branch is more often taken than not (loops use backward branches)
1954 Label not_taken;
1955 if (cc == equal)
1956 __ cbnz(r0, not_taken);
1957 else
1958 __ cbz(r0, not_taken);
1959 branch(false, false);
1960 __ bind(not_taken);
1961 __ profile_not_taken_branch(r0);
1962 }
1963
1964 void TemplateTable::if_acmp(Condition cc)
1965 {
1966 transition(atos, vtos);
1967 // assume branch is more often taken than not (loops use backward branches)
1968 Label not_taken;
1969 __ pop_ptr(r1);
1970 __ cmpoop(r1, r0);
1971 __ br(j_not(cc), not_taken);
1972 branch(false, false);
1973 __ bind(not_taken);
1974 __ profile_not_taken_branch(r0);
1975 }
1976
1977 void TemplateTable::ret() {
1978 transition(vtos, vtos);
1979 locals_index(r1);
1980 __ ldr(r1, aaddress(r1)); // get return bci, compute return bcp
1981 __ profile_ret(r1, r2);
1982 __ ldr(rbcp, Address(rmethod, Method::const_offset()));
1983 __ lea(rbcp, Address(rbcp, r1));
1984 __ add(rbcp, rbcp, in_bytes(ConstMethod::codes_offset()));
1985 __ dispatch_next(vtos, 0, /*generate_poll*/true);
1986 }
1987
1988 void TemplateTable::wide_ret() {
1989 transition(vtos, vtos);
1990 locals_index_wide(r1);
1991 __ ldr(r1, aaddress(r1)); // get return bci, compute return bcp
1992 __ profile_ret(r1, r2);
1993 __ ldr(rbcp, Address(rmethod, Method::const_offset()));
1994 __ lea(rbcp, Address(rbcp, r1));
1995 __ add(rbcp, rbcp, in_bytes(ConstMethod::codes_offset()));
1996 __ dispatch_next(vtos, 0, /*generate_poll*/true);
2566 }
2567 // c_rarg1: object pointer or null
2568 // c_rarg2: cache entry pointer
2569 __ call_VM(noreg, CAST_FROM_FN_PTR(address,
2570 InterpreterRuntime::post_field_access),
2571 c_rarg1, c_rarg2);
2572 __ load_field_entry(cache, index);
2573 __ bind(L1);
2574 }
2575 }
2576
2577 void TemplateTable::pop_and_check_object(Register r)
2578 {
2579 __ pop_ptr(r);
2580 __ null_check(r); // for field access must check obj.
2581 __ verify_oop(r);
2582 }
2583
2584 void TemplateTable::getfield_or_static(int byte_no, bool is_static, RewriteControl rc)
2585 {
2586 const Register cache = r4;
2587 const Register obj = r4;
2588 const Register index = r3;
2589 const Register tos_state = r3;
2590 const Register off = r19;
2591 const Register flags = r6;
2592 const Register bc = r4; // uses same reg as obj, so don't mix them
2593
2594 resolve_cache_and_index_for_field(byte_no, cache, index);
2595 jvmti_post_field_access(cache, index, is_static, false);
2596 load_resolved_field_entry(obj, cache, tos_state, off, flags, is_static);
2597
2598 if (!is_static) {
2599 // obj is on the stack
2600 pop_and_check_object(obj);
2601 }
2602
2603 // 8179954: We need to make sure that the code generated for
2604 // volatile accesses forms a sequentially-consistent set of
2605 // operations when combined with STLR and LDAR. Without a leading
2606 // membar it's possible for a simple Dekker test to fail if loads
2607 // use LDR;DMB but stores use STLR. This can happen if C2 compiles
2608 // the stores in one method and we interpret the loads in another.
2609 if (!CompilerConfig::is_c1_or_interpreter_only_no_jvmci()){
2610 Label notVolatile;
2611 __ tbz(flags, ResolvedFieldEntry::is_volatile_shift, notVolatile);
2612 __ membar(MacroAssembler::AnyAny);
2613 __ bind(notVolatile);
2614 }
2615
2634 __ b(Done);
2635
2636 __ bind(notByte);
2637 __ cmp(tos_state, (u1)ztos);
2638 __ br(Assembler::NE, notBool);
2639
2640 // ztos (same code as btos)
2641 __ access_load_at(T_BOOLEAN, IN_HEAP, r0, field, noreg, noreg);
2642 __ push(ztos);
2643 // Rewrite bytecode to be faster
2644 if (rc == may_rewrite) {
2645 // use btos rewriting, no truncating to t/f bit is needed for getfield.
2646 patch_bytecode(Bytecodes::_fast_bgetfield, bc, r1);
2647 }
2648 __ b(Done);
2649
2650 __ bind(notBool);
2651 __ cmp(tos_state, (u1)atos);
2652 __ br(Assembler::NE, notObj);
2653 // atos
2654 do_oop_load(_masm, field, r0, IN_HEAP);
2655 __ push(atos);
2656 if (rc == may_rewrite) {
2657 patch_bytecode(Bytecodes::_fast_agetfield, bc, r1);
2658 }
2659 __ b(Done);
2660
2661 __ bind(notObj);
2662 __ cmp(tos_state, (u1)itos);
2663 __ br(Assembler::NE, notInt);
2664 // itos
2665 __ access_load_at(T_INT, IN_HEAP, r0, field, noreg, noreg);
2666 __ push(itos);
2667 // Rewrite bytecode to be faster
2668 if (rc == may_rewrite) {
2669 patch_bytecode(Bytecodes::_fast_igetfield, bc, r1);
2670 }
2671 __ b(Done);
2672
2673 __ bind(notInt);
2674 __ cmp(tos_state, (u1)ctos);
2675 __ br(Assembler::NE, notChar);
2676 // ctos
2677 __ access_load_at(T_CHAR, IN_HEAP, r0, field, noreg, noreg);
2678 __ push(ctos);
2679 // Rewrite bytecode to be faster
2800 // c_rarg1: object pointer set up above (null if static)
2801 // c_rarg2: cache entry pointer
2802 // c_rarg3: jvalue object on the stack
2803 __ call_VM(noreg,
2804 CAST_FROM_FN_PTR(address,
2805 InterpreterRuntime::post_field_modification),
2806 c_rarg1, c_rarg2, c_rarg3);
2807 __ load_field_entry(cache, index);
2808 __ bind(L1);
2809 }
2810 }
2811
2812 void TemplateTable::putfield_or_static(int byte_no, bool is_static, RewriteControl rc) {
2813 transition(vtos, vtos);
2814
2815 const Register cache = r2;
2816 const Register index = r3;
2817 const Register tos_state = r3;
2818 const Register obj = r2;
2819 const Register off = r19;
2820 const Register flags = r0;
2821 const Register bc = r4;
2822
2823 resolve_cache_and_index_for_field(byte_no, cache, index);
2824 jvmti_post_field_mod(cache, index, is_static);
2825 load_resolved_field_entry(obj, cache, tos_state, off, flags, is_static);
2826
2827 Label Done;
2828 __ mov(r5, flags);
2829
2830 {
2831 Label notVolatile;
2832 __ tbz(r5, ResolvedFieldEntry::is_volatile_shift, notVolatile);
2833 __ membar(MacroAssembler::StoreStore | MacroAssembler::LoadStore);
2834 __ bind(notVolatile);
2835 }
2836
2837 // field address
2838 const Address field(obj, off);
2839
2840 Label notByte, notBool, notInt, notShort, notChar,
2841 notLong, notFloat, notObj, notDouble;
2842
2843 assert(btos == 0, "change code, btos != 0");
2844 __ cbnz(tos_state, notByte);
2845
2846 // Don't rewrite putstatic, only putfield
2847 if (is_static) rc = may_not_rewrite;
2848
2849 // btos
2850 {
2851 __ pop(btos);
2852 if (!is_static) pop_and_check_object(obj);
2861 __ cmp(tos_state, (u1)ztos);
2862 __ br(Assembler::NE, notBool);
2863
2864 // ztos
2865 {
2866 __ pop(ztos);
2867 if (!is_static) pop_and_check_object(obj);
2868 __ access_store_at(T_BOOLEAN, IN_HEAP, field, r0, noreg, noreg, noreg);
2869 if (rc == may_rewrite) {
2870 patch_bytecode(Bytecodes::_fast_zputfield, bc, r1, true, byte_no);
2871 }
2872 __ b(Done);
2873 }
2874
2875 __ bind(notBool);
2876 __ cmp(tos_state, (u1)atos);
2877 __ br(Assembler::NE, notObj);
2878
2879 // atos
2880 {
2881 __ pop(atos);
2882 if (!is_static) pop_and_check_object(obj);
2883 // Store into the field
2884 // Clobbers: r10, r11, r3
2885 do_oop_store(_masm, field, r0, IN_HEAP);
2886 if (rc == may_rewrite) {
2887 patch_bytecode(Bytecodes::_fast_aputfield, bc, r1, true, byte_no);
2888 }
2889 __ b(Done);
2890 }
2891
2892 __ bind(notObj);
2893 __ cmp(tos_state, (u1)itos);
2894 __ br(Assembler::NE, notInt);
2895
2896 // itos
2897 {
2898 __ pop(itos);
2899 if (!is_static) pop_and_check_object(obj);
2900 __ access_store_at(T_INT, IN_HEAP, field, r0, noreg, noreg, noreg);
2901 if (rc == may_rewrite) {
2902 patch_bytecode(Bytecodes::_fast_iputfield, bc, r1, true, byte_no);
2903 }
2904 __ b(Done);
2905 }
2906
2907 __ bind(notInt);
2908 __ cmp(tos_state, (u1)ctos);
2909 __ br(Assembler::NE, notChar);
2974 {
2975 __ pop(dtos);
2976 if (!is_static) pop_and_check_object(obj);
2977 __ access_store_at(T_DOUBLE, IN_HEAP, field, noreg /* dtos */, noreg, noreg, noreg);
2978 if (rc == may_rewrite) {
2979 patch_bytecode(Bytecodes::_fast_dputfield, bc, r1, true, byte_no);
2980 }
2981 }
2982
2983 #ifdef ASSERT
2984 __ b(Done);
2985
2986 __ bind(notDouble);
2987 __ stop("Bad state");
2988 #endif
2989
2990 __ bind(Done);
2991
2992 {
2993 Label notVolatile;
2994 __ tbz(r5, ResolvedFieldEntry::is_volatile_shift, notVolatile);
2995 __ membar(MacroAssembler::StoreLoad | MacroAssembler::StoreStore);
2996 __ bind(notVolatile);
2997 }
2998 }
2999
3000 void TemplateTable::putfield(int byte_no)
3001 {
3002 putfield_or_static(byte_no, false);
3003 }
3004
3005 void TemplateTable::nofast_putfield(int byte_no) {
3006 putfield_or_static(byte_no, false, may_not_rewrite);
3007 }
3008
3009 void TemplateTable::putstatic(int byte_no) {
3010 putfield_or_static(byte_no, true);
3011 }
3012
3013 void TemplateTable::jvmti_post_fast_field_mod() {
3014 if (JvmtiExport::can_post_field_modification()) {
3015 // Check to see if a field modification watch has been set before
3016 // we take the time to call into the VM.
3017 Label L2;
3018 __ lea(rscratch1, ExternalAddress((address)JvmtiExport::get_field_modification_count_addr()));
3019 __ ldrw(c_rarg3, Address(rscratch1));
3020 __ cbzw(c_rarg3, L2);
3021 __ pop_ptr(r19); // copy the object pointer from tos
3022 __ verify_oop(r19);
3023 __ push_ptr(r19); // put the object pointer back on tos
3024 // Save tos values before call_VM() clobbers them. Since we have
3025 // to do it for every data type, we use the saved values as the
3026 // jvalue object.
3027 switch (bytecode()) { // load values into the jvalue object
3028 case Bytecodes::_fast_aputfield: __ push_ptr(r0); break;
3029 case Bytecodes::_fast_bputfield: // fall through
3030 case Bytecodes::_fast_zputfield: // fall through
3031 case Bytecodes::_fast_sputfield: // fall through
3032 case Bytecodes::_fast_cputfield: // fall through
3033 case Bytecodes::_fast_iputfield: __ push_i(r0); break;
3034 case Bytecodes::_fast_dputfield: __ push_d(); break;
3035 case Bytecodes::_fast_fputfield: __ push_f(); break;
3036 case Bytecodes::_fast_lputfield: __ push_l(r0); break;
3037
3038 default:
3039 ShouldNotReachHere();
3040 }
3041 __ mov(c_rarg3, esp); // points to jvalue on the stack
3042 // access constant pool cache entry
3043 __ load_field_entry(c_rarg2, r0);
3044 __ verify_oop(r19);
3045 // r19: object pointer copied above
3046 // c_rarg2: cache entry pointer
3047 // c_rarg3: jvalue object on the stack
3048 __ call_VM(noreg,
3049 CAST_FROM_FN_PTR(address,
3050 InterpreterRuntime::post_field_modification),
3051 r19, c_rarg2, c_rarg3);
3052
3053 switch (bytecode()) { // restore tos values
3054 case Bytecodes::_fast_aputfield: __ pop_ptr(r0); break;
3055 case Bytecodes::_fast_bputfield: // fall through
3056 case Bytecodes::_fast_zputfield: // fall through
3057 case Bytecodes::_fast_sputfield: // fall through
3058 case Bytecodes::_fast_cputfield: // fall through
3059 case Bytecodes::_fast_iputfield: __ pop_i(r0); break;
3060 case Bytecodes::_fast_dputfield: __ pop_d(); break;
3061 case Bytecodes::_fast_fputfield: __ pop_f(); break;
3062 case Bytecodes::_fast_lputfield: __ pop_l(r0); break;
3063 default: break;
3064 }
3065 __ bind(L2);
3066 }
3067 }
3068
3069 void TemplateTable::fast_storefield(TosState state)
3070 {
3071 transition(state, vtos);
3072
3073 ByteSize base = ConstantPoolCache::base_offset();
3080 // R1: field offset, R2: field holder, R5: flags
3081 load_resolved_field_entry(r2, r2, noreg, r1, r5);
3082
3083 {
3084 Label notVolatile;
3085 __ tbz(r5, ResolvedFieldEntry::is_volatile_shift, notVolatile);
3086 __ membar(MacroAssembler::StoreStore | MacroAssembler::LoadStore);
3087 __ bind(notVolatile);
3088 }
3089
3090 Label notVolatile;
3091
3092 // Get object from stack
3093 pop_and_check_object(r2);
3094
3095 // field address
3096 const Address field(r2, r1);
3097
3098 // access field
3099 switch (bytecode()) {
3100 case Bytecodes::_fast_aputfield:
3101 // Clobbers: r10, r11, r3
3102 do_oop_store(_masm, field, r0, IN_HEAP);
3103 break;
3104 case Bytecodes::_fast_lputfield:
3105 __ access_store_at(T_LONG, IN_HEAP, field, r0, noreg, noreg, noreg);
3106 break;
3107 case Bytecodes::_fast_iputfield:
3108 __ access_store_at(T_INT, IN_HEAP, field, r0, noreg, noreg, noreg);
3109 break;
3110 case Bytecodes::_fast_zputfield:
3111 __ access_store_at(T_BOOLEAN, IN_HEAP, field, r0, noreg, noreg, noreg);
3112 break;
3113 case Bytecodes::_fast_bputfield:
3114 __ access_store_at(T_BYTE, IN_HEAP, field, r0, noreg, noreg, noreg);
3115 break;
3116 case Bytecodes::_fast_sputfield:
3117 __ access_store_at(T_SHORT, IN_HEAP, field, r0, noreg, noreg, noreg);
3118 break;
3119 case Bytecodes::_fast_cputfield:
3173 // r0: object
3174 __ verify_oop(r0);
3175 __ null_check(r0);
3176 const Address field(r0, r1);
3177
3178 // 8179954: We need to make sure that the code generated for
3179 // volatile accesses forms a sequentially-consistent set of
3180 // operations when combined with STLR and LDAR. Without a leading
3181 // membar it's possible for a simple Dekker test to fail if loads
3182 // use LDR;DMB but stores use STLR. This can happen if C2 compiles
3183 // the stores in one method and we interpret the loads in another.
3184 if (!CompilerConfig::is_c1_or_interpreter_only_no_jvmci()) {
3185 Label notVolatile;
3186 __ tbz(r3, ResolvedFieldEntry::is_volatile_shift, notVolatile);
3187 __ membar(MacroAssembler::AnyAny);
3188 __ bind(notVolatile);
3189 }
3190
3191 // access field
3192 switch (bytecode()) {
3193 case Bytecodes::_fast_agetfield:
3194 do_oop_load(_masm, field, r0, IN_HEAP);
3195 __ verify_oop(r0);
3196 break;
3197 case Bytecodes::_fast_lgetfield:
3198 __ access_load_at(T_LONG, IN_HEAP, r0, field, noreg, noreg);
3199 break;
3200 case Bytecodes::_fast_igetfield:
3201 __ access_load_at(T_INT, IN_HEAP, r0, field, noreg, noreg);
3202 break;
3203 case Bytecodes::_fast_bgetfield:
3204 __ access_load_at(T_BYTE, IN_HEAP, r0, field, noreg, noreg);
3205 break;
3206 case Bytecodes::_fast_sgetfield:
3207 __ access_load_at(T_SHORT, IN_HEAP, r0, field, noreg, noreg);
3208 break;
3209 case Bytecodes::_fast_cgetfield:
3210 __ access_load_at(T_CHAR, IN_HEAP, r0, field, noreg, noreg);
3211 break;
3212 case Bytecodes::_fast_fgetfield:
3591 Label initialize_header;
3592
3593 __ get_cpool_and_tags(r4, r0);
3594 // Make sure the class we're about to instantiate has been resolved.
3595 // This is done before loading InstanceKlass to be consistent with the order
3596 // how Constant Pool is updated (see ConstantPool::klass_at_put)
3597 const int tags_offset = Array<u1>::base_offset_in_bytes();
3598 __ lea(rscratch1, Address(r0, r3, Address::lsl(0)));
3599 __ lea(rscratch1, Address(rscratch1, tags_offset));
3600 __ ldarb(rscratch1, rscratch1);
3601 __ cmp(rscratch1, (u1)JVM_CONSTANT_Class);
3602 __ br(Assembler::NE, slow_case);
3603
3604 // get InstanceKlass
3605 __ load_resolved_klass_at_offset(r4, r3, r4, rscratch1);
3606
3607 // make sure klass is initialized
3608 assert(VM_Version::supports_fast_class_init_checks(), "Optimization requires support for fast class initialization checks");
3609 __ clinit_barrier(r4, rscratch1, nullptr /*L_fast_path*/, &slow_case);
3610
3611 // get instance_size in InstanceKlass (scaled to a count of bytes)
3612 __ ldrw(r3,
3613 Address(r4,
3614 Klass::layout_helper_offset()));
3615 // test to see if it is malformed in some way
3616 __ tbnz(r3, exact_log2(Klass::_lh_instance_slow_path_bit), slow_case);
3617
3618 // Allocate the instance:
3619 // If TLAB is enabled:
3620 // Try to allocate in the TLAB.
3621 // If fails, go to the slow path.
3622 // Initialize the allocation.
3623 // Exit.
3624 //
3625 // Go to slow path.
3626
3627 if (UseTLAB) {
3628 __ tlab_allocate(r0, r3, 0, noreg, r1, slow_case);
3629
3630 if (ZeroTLAB) {
3631 // the fields have been already cleared
3632 __ b(initialize_header);
3633 }
3634
3635 // The object is initialized before the header. If the object size is
3636 // zero, go directly to the header initialization.
3637 int header_size = oopDesc::header_size() * HeapWordSize;
3638 assert(is_aligned(header_size, BytesPerLong), "oop header size must be 8-byte-aligned");
3639 __ sub(r3, r3, header_size);
3640 __ cbz(r3, initialize_header);
3641
3642 // Initialize object fields
3643 {
3644 __ add(r2, r0, header_size);
3645 Label loop;
3646 __ bind(loop);
3647 __ str(zr, Address(__ post(r2, BytesPerLong)));
3648 __ sub(r3, r3, BytesPerLong);
3649 __ cbnz(r3, loop);
3650 }
3651
3652 // initialize object header only.
3653 __ bind(initialize_header);
3654 if (UseCompactObjectHeaders) {
3655 __ ldr(rscratch1, Address(r4, Klass::prototype_header_offset()));
3656 __ str(rscratch1, Address(r0, oopDesc::mark_offset_in_bytes()));
3657 } else {
3658 __ mov(rscratch1, (intptr_t)markWord::prototype().value());
3659 __ str(rscratch1, Address(r0, oopDesc::mark_offset_in_bytes()));
3660 __ store_klass_gap(r0, zr); // zero klass gap for compressed oops
3661 __ store_klass(r0, r4); // store klass last
3662 }
3663
3664 if (DTraceAllocProbes) {
3665 // Trigger dtrace event for fastpath
3666 __ push(atos); // save the return value
3667 __ call_VM_leaf(
3668 CAST_FROM_FN_PTR(address, static_cast<int (*)(oopDesc*)>(SharedRuntime::dtrace_object_alloc)), r0);
3669 __ pop(atos); // restore the return value
3670
3671 }
3672 __ b(done);
3673 }
3674
3675 // slow case
3676 __ bind(slow_case);
3677 __ get_constant_pool(c_rarg1);
3678 __ get_unsigned_2_byte_index_at_bcp(c_rarg2, 1);
3679 call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), c_rarg1, c_rarg2);
3680 __ verify_oop(r0);
3681
3682 // continue
3683 __ bind(done);
3684 // Must prevent reordering of stores for object initialization with stores that publish the new object.
3685 __ membar(Assembler::StoreStore);
3686 }
3687
3688 void TemplateTable::newarray() {
3689 transition(itos, atos);
3690 __ load_unsigned_byte(c_rarg1, at_bcp(1));
3691 __ mov(c_rarg2, r0);
3692 call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::newarray),
3693 c_rarg1, c_rarg2);
3737 __ bind(quicked);
3738 __ mov(r3, r0); // Save object in r3; r0 needed for subtype check
3739 __ load_resolved_klass_at_offset(r2, r19, r0, rscratch1); // r0 = klass
3740
3741 __ bind(resolved);
3742 __ load_klass(r19, r3);
3743
3744 // Generate subtype check. Blows r2, r5. Object in r3.
3745 // Superklass in r0. Subklass in r19.
3746 __ gen_subtype_check(r19, ok_is_subtype);
3747
3748 // Come here on failure
3749 __ push(r3);
3750 // object is at TOS
3751 __ b(Interpreter::_throw_ClassCastException_entry);
3752
3753 // Come here on success
3754 __ bind(ok_is_subtype);
3755 __ mov(r0, r3); // Restore object in r3
3756
3757 // Collect counts on whether this test sees nulls a lot or not.
3758 if (ProfileInterpreter) {
3759 __ b(done);
3760 __ bind(is_null);
3761 __ profile_null_seen(r2);
3762 } else {
3763 __ bind(is_null); // same as 'done'
3764 }
3765 __ bind(done);
3766 }
3767
3768 void TemplateTable::instanceof() {
3769 transition(atos, itos);
3770 Label done, is_null, ok_is_subtype, quicked, resolved;
3771 __ cbz(r0, is_null);
3772
3773 // Get cpool & tags index
3774 __ get_cpool_and_tags(r2, r3); // r2=cpool, r3=tags array
3775 __ get_unsigned_2_byte_index_at_bcp(r19, 1); // r19=index
3776 // See if bytecode has already been quicked
3777 __ add(rscratch1, r3, Array<u1>::base_offset_in_bytes());
3778 __ lea(r1, Address(rscratch1, r19));
3779 __ ldarb(r1, r1);
3780 __ cmp(r1, (u1)JVM_CONSTANT_Class);
3781 __ br(Assembler::EQ, quicked);
3782
3783 __ push(atos); // save receiver for result, and for GC
3784 call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc));
3862 // in the assembly code structure as well
3863 //
3864 // Stack layout:
3865 //
3866 // [expressions ] <--- esp = expression stack top
3867 // ..
3868 // [expressions ]
3869 // [monitor entry] <--- monitor block top = expression stack bot
3870 // ..
3871 // [monitor entry]
3872 // [frame data ] <--- monitor block bot
3873 // ...
3874 // [saved rfp ] <--- rfp
3875 void TemplateTable::monitorenter()
3876 {
3877 transition(atos, vtos);
3878
3879 // check for null object
3880 __ null_check(r0);
3881
3882 const Address monitor_block_top(
3883 rfp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
3884 const Address monitor_block_bot(
3885 rfp, frame::interpreter_frame_initial_sp_offset * wordSize);
3886 const int entry_size = frame::interpreter_frame_monitor_size_in_bytes();
3887
3888 Label allocated;
3889
3890 // initialize entry pointer
3891 __ mov(c_rarg1, zr); // points to free slot or null
3892
3893 // find a free slot in the monitor block (result in c_rarg1)
3894 {
3895 Label entry, loop, exit;
3896 __ ldr(c_rarg3, monitor_block_top); // derelativize pointer
3897 __ lea(c_rarg3, Address(rfp, c_rarg3, Address::lsl(Interpreter::logStackElementSize)));
3898 // c_rarg3 points to current entry, starting with top-most entry
3899
3900 __ lea(c_rarg2, monitor_block_bot); // points to word before bottom
3901
3963 // c_rarg1: points to monitor entry
3964 __ bind(allocated);
3965
3966 // Increment bcp to point to the next bytecode, so exception
3967 // handling for async. exceptions work correctly.
3968 // The object has already been popped from the stack, so the
3969 // expression stack looks correct.
3970 __ increment(rbcp);
3971
3972 // store object
3973 __ str(r0, Address(c_rarg1, BasicObjectLock::obj_offset()));
3974 __ lock_object(c_rarg1);
3975
3976 // check to make sure this monitor doesn't cause stack overflow after locking
3977 __ save_bcp(); // in case of exception
3978 __ generate_stack_overflow_check(0);
3979
3980 // The bcp has already been incremented. Just need to dispatch to
3981 // next instruction.
3982 __ dispatch_next(vtos);
3983 }
3984
3985
3986 void TemplateTable::monitorexit()
3987 {
3988 transition(atos, vtos);
3989
3990 // check for null object
3991 __ null_check(r0);
3992
3993 const Address monitor_block_top(
3994 rfp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
3995 const Address monitor_block_bot(
3996 rfp, frame::interpreter_frame_initial_sp_offset * wordSize);
3997 const int entry_size = frame::interpreter_frame_monitor_size_in_bytes();
3998
3999 Label found;
4000
4001 // find matching slot
4002 {
4003 Label entry, loop;
4004 __ ldr(c_rarg1, monitor_block_top); // derelativize pointer
4005 __ lea(c_rarg1, Address(rfp, c_rarg1, Address::lsl(Interpreter::logStackElementSize)));
4006 // c_rarg1 points to current entry, starting with top-most entry
4007
4008 __ lea(c_rarg2, monitor_block_bot); // points to word before bottom
4009 // of monitor block
4010 __ b(entry);
4011
4012 __ 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_vputfield:
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 (UseArrayFlattening) {
822 Label is_flat_array, done;
823
824 __ test_flat_array_oop(r0, rscratch1 /*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::flat_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 (UseArrayFlattening) {
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 // Clobbers: r10, r11, r3
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 if (UseArrayFlattening) {
1186 __ test_flat_array_oop(r3, rscratch1, is_flat_array);
1187 }
1188
1189 // No way to store null in a null-free array
1190 __ test_null_free_array_oop(r3, rscratch1, is_null_into_value_array_npe);
1191 __ b(store_null);
1192
1193 __ bind(is_null_into_value_array_npe);
1194 __ b(ExternalAddress(Interpreter::_throw_NullPointerException_entry));
1195
1196 __ bind(store_null);
1197 }
1198
1199 // Store a null
1200 // Clobbers: r10, r11, r3
1201 do_oop_store(_masm, element_address, noreg, IS_ARRAY);
1202 __ b(done);
1203
1204 if (UseArrayFlattening) {
1205 Label is_type_ok;
1206 __ bind(is_flat_array); // Store non-null value to flat
1207
1208 __ ldr(r0, at_tos()); // value
1209 __ ldr(r3, at_tos_p1()); // index
1210 __ ldr(r2, at_tos_p2()); // array
1211 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::flat_array_store), r0, r2, r3);
1212 }
1213
1214 // Pop stack arguments
1215 __ bind(done);
1216 __ add(esp, esp, 3 * Interpreter::stackElementSize);
1217 }
1218
1219 void TemplateTable::bastore()
1220 {
1221 transition(itos, vtos);
1222 __ pop_i(r1);
1223 __ pop_ptr(r3);
1224 // r0: value
1225 // r1: index
1226 // r3: array
1227 index_check(r3, r1); // prefer index in r1
1228
1229 // Need to check whether array is boolean or byte
1230 // since both types share the bastore bytecode.
1231 __ load_klass(r2, r3);
1232 __ ldrw(r2, Address(r2, Klass::layout_helper_offset()));
1999 __ br(j_not(cc), not_taken);
2000 branch(false, false);
2001 __ bind(not_taken);
2002 __ profile_not_taken_branch(r0);
2003 }
2004
2005 void TemplateTable::if_nullcmp(Condition cc)
2006 {
2007 transition(atos, vtos);
2008 // assume branch is more often taken than not (loops use backward branches)
2009 Label not_taken;
2010 if (cc == equal)
2011 __ cbnz(r0, not_taken);
2012 else
2013 __ cbz(r0, not_taken);
2014 branch(false, false);
2015 __ bind(not_taken);
2016 __ profile_not_taken_branch(r0);
2017 }
2018
2019 void TemplateTable::if_acmp(Condition cc) {
2020 transition(atos, vtos);
2021 // assume branch is more often taken than not (loops use backward branches)
2022 Label taken, not_taken;
2023 __ pop_ptr(r1);
2024
2025 __ profile_acmp(r2, r1, r0, r4);
2026
2027 Register is_inline_type_mask = rscratch1;
2028 __ mov(is_inline_type_mask, markWord::inline_type_pattern);
2029
2030 if (EnableValhalla) {
2031 __ cmp(r1, r0);
2032 __ br(Assembler::EQ, (cc == equal) ? taken : not_taken);
2033
2034 // might be substitutable, test if either r0 or r1 is null
2035 __ andr(r2, r0, r1);
2036 __ cbz(r2, (cc == equal) ? not_taken : taken);
2037
2038 // and both are values ?
2039 __ ldr(r2, Address(r1, oopDesc::mark_offset_in_bytes()));
2040 __ andr(r2, r2, is_inline_type_mask);
2041 __ ldr(r4, Address(r0, oopDesc::mark_offset_in_bytes()));
2042 __ andr(r4, r4, is_inline_type_mask);
2043 __ andr(r2, r2, r4);
2044 __ cmp(r2, is_inline_type_mask);
2045 __ br(Assembler::NE, (cc == equal) ? not_taken : taken);
2046
2047 // same value klass ?
2048 __ load_metadata(r2, r1);
2049 __ load_metadata(r4, r0);
2050 __ cmp(r2, r4);
2051 __ br(Assembler::NE, (cc == equal) ? not_taken : taken);
2052
2053 // Know both are the same type, let's test for substitutability...
2054 if (cc == equal) {
2055 invoke_is_substitutable(r0, r1, taken, not_taken);
2056 } else {
2057 invoke_is_substitutable(r0, r1, not_taken, taken);
2058 }
2059 __ stop("Not reachable");
2060 }
2061
2062 __ cmpoop(r1, r0);
2063 __ br(j_not(cc), not_taken);
2064 __ bind(taken);
2065 branch(false, false);
2066 __ bind(not_taken);
2067 __ profile_not_taken_branch(r0, true);
2068 }
2069
2070 void TemplateTable::invoke_is_substitutable(Register aobj, Register bobj,
2071 Label& is_subst, Label& not_subst) {
2072
2073 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::is_substitutable), aobj, bobj);
2074 // Restored... r0 answer, jmp to outcome...
2075 __ cbz(r0, not_subst);
2076 __ b(is_subst);
2077 }
2078
2079
2080 void TemplateTable::ret() {
2081 transition(vtos, vtos);
2082 locals_index(r1);
2083 __ ldr(r1, aaddress(r1)); // get return bci, compute return bcp
2084 __ profile_ret(r1, r2);
2085 __ ldr(rbcp, Address(rmethod, Method::const_offset()));
2086 __ lea(rbcp, Address(rbcp, r1));
2087 __ add(rbcp, rbcp, in_bytes(ConstMethod::codes_offset()));
2088 __ dispatch_next(vtos, 0, /*generate_poll*/true);
2089 }
2090
2091 void TemplateTable::wide_ret() {
2092 transition(vtos, vtos);
2093 locals_index_wide(r1);
2094 __ ldr(r1, aaddress(r1)); // get return bci, compute return bcp
2095 __ profile_ret(r1, r2);
2096 __ ldr(rbcp, Address(rmethod, Method::const_offset()));
2097 __ lea(rbcp, Address(rbcp, r1));
2098 __ add(rbcp, rbcp, in_bytes(ConstMethod::codes_offset()));
2099 __ dispatch_next(vtos, 0, /*generate_poll*/true);
2669 }
2670 // c_rarg1: object pointer or null
2671 // c_rarg2: cache entry pointer
2672 __ call_VM(noreg, CAST_FROM_FN_PTR(address,
2673 InterpreterRuntime::post_field_access),
2674 c_rarg1, c_rarg2);
2675 __ load_field_entry(cache, index);
2676 __ bind(L1);
2677 }
2678 }
2679
2680 void TemplateTable::pop_and_check_object(Register r)
2681 {
2682 __ pop_ptr(r);
2683 __ null_check(r); // for field access must check obj.
2684 __ verify_oop(r);
2685 }
2686
2687 void TemplateTable::getfield_or_static(int byte_no, bool is_static, RewriteControl rc)
2688 {
2689 const Register cache = r2;
2690 const Register obj = r4;
2691 const Register klass = r5;
2692 const Register inline_klass = r7;
2693 const Register field_index = r23;
2694 const Register index = r3;
2695 const Register tos_state = r3;
2696 const Register off = r19;
2697 const Register flags = r6;
2698 const Register bc = r4; // uses same reg as obj, so don't mix them
2699
2700 resolve_cache_and_index_for_field(byte_no, cache, index);
2701 jvmti_post_field_access(cache, index, is_static, false);
2702
2703 // Valhalla extras
2704 __ load_unsigned_short(field_index, Address(cache, in_bytes(ResolvedFieldEntry::field_index_offset())));
2705 __ ldr(klass, Address(cache, ResolvedFieldEntry::field_holder_offset()));
2706
2707 load_resolved_field_entry(obj, cache, tos_state, off, flags, is_static);
2708
2709 if (!is_static) {
2710 // obj is on the stack
2711 pop_and_check_object(obj);
2712 }
2713
2714 // 8179954: We need to make sure that the code generated for
2715 // volatile accesses forms a sequentially-consistent set of
2716 // operations when combined with STLR and LDAR. Without a leading
2717 // membar it's possible for a simple Dekker test to fail if loads
2718 // use LDR;DMB but stores use STLR. This can happen if C2 compiles
2719 // the stores in one method and we interpret the loads in another.
2720 if (!CompilerConfig::is_c1_or_interpreter_only_no_jvmci()){
2721 Label notVolatile;
2722 __ tbz(flags, ResolvedFieldEntry::is_volatile_shift, notVolatile);
2723 __ membar(MacroAssembler::AnyAny);
2724 __ bind(notVolatile);
2725 }
2726
2745 __ b(Done);
2746
2747 __ bind(notByte);
2748 __ cmp(tos_state, (u1)ztos);
2749 __ br(Assembler::NE, notBool);
2750
2751 // ztos (same code as btos)
2752 __ access_load_at(T_BOOLEAN, IN_HEAP, r0, field, noreg, noreg);
2753 __ push(ztos);
2754 // Rewrite bytecode to be faster
2755 if (rc == may_rewrite) {
2756 // use btos rewriting, no truncating to t/f bit is needed for getfield.
2757 patch_bytecode(Bytecodes::_fast_bgetfield, bc, r1);
2758 }
2759 __ b(Done);
2760
2761 __ bind(notBool);
2762 __ cmp(tos_state, (u1)atos);
2763 __ br(Assembler::NE, notObj);
2764 // atos
2765 if (!EnableValhalla) {
2766 do_oop_load(_masm, field, r0, IN_HEAP);
2767 __ push(atos);
2768 if (rc == may_rewrite) {
2769 patch_bytecode(Bytecodes::_fast_agetfield, bc, r1);
2770 }
2771 __ b(Done);
2772 } else { // Valhalla
2773 if (is_static) {
2774 __ load_heap_oop(r0, field, rscratch1, rscratch2);
2775 __ push(atos);
2776 __ b(Done);
2777 } else {
2778 Label is_flat, rewrite_inline;
2779 __ test_field_is_flat(flags, noreg /*temp*/, is_flat);
2780 __ load_heap_oop(r0, field, rscratch1, rscratch2);
2781 __ push(atos);
2782 if (rc == may_rewrite) {
2783 patch_bytecode(Bytecodes::_fast_agetfield, bc, r1);
2784 }
2785 __ b(Done);
2786 __ bind(is_flat);
2787 // field is flat (null-free or nullable with a null-marker)
2788 __ mov(r0, obj);
2789 __ read_flat_field(cache, field_index, off, inline_klass /* temp */, r0);
2790 __ verify_oop(r0);
2791 __ push(atos);
2792 __ bind(rewrite_inline);
2793 if (rc == may_rewrite) {
2794 patch_bytecode(Bytecodes::_fast_vgetfield, bc, r1);
2795 }
2796 __ b(Done);
2797 }
2798 }
2799
2800 __ bind(notObj);
2801 __ cmp(tos_state, (u1)itos);
2802 __ br(Assembler::NE, notInt);
2803 // itos
2804 __ access_load_at(T_INT, IN_HEAP, r0, field, noreg, noreg);
2805 __ push(itos);
2806 // Rewrite bytecode to be faster
2807 if (rc == may_rewrite) {
2808 patch_bytecode(Bytecodes::_fast_igetfield, bc, r1);
2809 }
2810 __ b(Done);
2811
2812 __ bind(notInt);
2813 __ cmp(tos_state, (u1)ctos);
2814 __ br(Assembler::NE, notChar);
2815 // ctos
2816 __ access_load_at(T_CHAR, IN_HEAP, r0, field, noreg, noreg);
2817 __ push(ctos);
2818 // Rewrite bytecode to be faster
2939 // c_rarg1: object pointer set up above (null if static)
2940 // c_rarg2: cache entry pointer
2941 // c_rarg3: jvalue object on the stack
2942 __ call_VM(noreg,
2943 CAST_FROM_FN_PTR(address,
2944 InterpreterRuntime::post_field_modification),
2945 c_rarg1, c_rarg2, c_rarg3);
2946 __ load_field_entry(cache, index);
2947 __ bind(L1);
2948 }
2949 }
2950
2951 void TemplateTable::putfield_or_static(int byte_no, bool is_static, RewriteControl rc) {
2952 transition(vtos, vtos);
2953
2954 const Register cache = r2;
2955 const Register index = r3;
2956 const Register tos_state = r3;
2957 const Register obj = r2;
2958 const Register off = r19;
2959 const Register flags = r6;
2960 const Register bc = r4;
2961 const Register inline_klass = r5;
2962
2963 resolve_cache_and_index_for_field(byte_no, cache, index);
2964 jvmti_post_field_mod(cache, index, is_static);
2965 load_resolved_field_entry(obj, cache, tos_state, off, flags, is_static);
2966
2967 Label Done;
2968 {
2969 Label notVolatile;
2970 __ tbz(flags, ResolvedFieldEntry::is_volatile_shift, notVolatile);
2971 __ membar(MacroAssembler::StoreStore | MacroAssembler::LoadStore);
2972 __ bind(notVolatile);
2973 }
2974
2975 // field address
2976 const Address field(obj, off);
2977
2978 Label notByte, notBool, notInt, notShort, notChar,
2979 notLong, notFloat, notObj, notDouble;
2980
2981 assert(btos == 0, "change code, btos != 0");
2982 __ cbnz(tos_state, notByte);
2983
2984 // Don't rewrite putstatic, only putfield
2985 if (is_static) rc = may_not_rewrite;
2986
2987 // btos
2988 {
2989 __ pop(btos);
2990 if (!is_static) pop_and_check_object(obj);
2999 __ cmp(tos_state, (u1)ztos);
3000 __ br(Assembler::NE, notBool);
3001
3002 // ztos
3003 {
3004 __ pop(ztos);
3005 if (!is_static) pop_and_check_object(obj);
3006 __ access_store_at(T_BOOLEAN, IN_HEAP, field, r0, noreg, noreg, noreg);
3007 if (rc == may_rewrite) {
3008 patch_bytecode(Bytecodes::_fast_zputfield, bc, r1, true, byte_no);
3009 }
3010 __ b(Done);
3011 }
3012
3013 __ bind(notBool);
3014 __ cmp(tos_state, (u1)atos);
3015 __ br(Assembler::NE, notObj);
3016
3017 // atos
3018 {
3019 if (!EnableValhalla) {
3020 __ pop(atos);
3021 if (!is_static) pop_and_check_object(obj);
3022 // Store into the field
3023 // Clobbers: r10, r11, r3
3024 do_oop_store(_masm, field, r0, IN_HEAP);
3025 if (rc == may_rewrite) {
3026 patch_bytecode(Bytecodes::_fast_aputfield, bc, r1, true, byte_no);
3027 }
3028 __ b(Done);
3029 } else { // Valhalla
3030 __ pop(atos);
3031 if (is_static) {
3032 Label is_nullable;
3033 __ test_field_is_not_null_free_inline_type(flags, noreg /* temp */, is_nullable);
3034 __ null_check(r0); // FIXME JDK-8341120
3035 __ bind(is_nullable);
3036 do_oop_store(_masm, field, r0, IN_HEAP);
3037 __ b(Done);
3038 } else {
3039 Label null_free_reference, is_flat, rewrite_inline;
3040 __ test_field_is_flat(flags, noreg /*temp*/, is_flat);
3041 __ test_field_is_null_free_inline_type(flags, noreg /*temp*/, null_free_reference);
3042 pop_and_check_object(obj);
3043 // Store into the field
3044 // Clobbers: r10, r11, r3
3045 do_oop_store(_masm, field, r0, IN_HEAP);
3046 if (rc == may_rewrite) {
3047 patch_bytecode(Bytecodes::_fast_aputfield, bc, r19, true, byte_no);
3048 }
3049 __ b(Done);
3050 // Implementation of the inline type semantic
3051 __ bind(null_free_reference);
3052 __ null_check(r0); // FIXME JDK-8341120
3053 pop_and_check_object(obj);
3054 // Store into the field
3055 // Clobbers: r10, r11, r3
3056 do_oop_store(_masm, field, r0, IN_HEAP);
3057 __ b(rewrite_inline);
3058 __ bind(is_flat);
3059 pop_and_check_object(r7);
3060 __ write_flat_field(cache, off, r3, r6, r7);
3061 __ bind(rewrite_inline);
3062 if (rc == may_rewrite) {
3063 patch_bytecode(Bytecodes::_fast_vputfield, bc, r19, true, byte_no);
3064 }
3065 __ b(Done);
3066 }
3067 } // Valhalla
3068 }
3069
3070 __ bind(notObj);
3071 __ cmp(tos_state, (u1)itos);
3072 __ br(Assembler::NE, notInt);
3073
3074 // itos
3075 {
3076 __ pop(itos);
3077 if (!is_static) pop_and_check_object(obj);
3078 __ access_store_at(T_INT, IN_HEAP, field, r0, noreg, noreg, noreg);
3079 if (rc == may_rewrite) {
3080 patch_bytecode(Bytecodes::_fast_iputfield, bc, r1, true, byte_no);
3081 }
3082 __ b(Done);
3083 }
3084
3085 __ bind(notInt);
3086 __ cmp(tos_state, (u1)ctos);
3087 __ br(Assembler::NE, notChar);
3152 {
3153 __ pop(dtos);
3154 if (!is_static) pop_and_check_object(obj);
3155 __ access_store_at(T_DOUBLE, IN_HEAP, field, noreg /* dtos */, noreg, noreg, noreg);
3156 if (rc == may_rewrite) {
3157 patch_bytecode(Bytecodes::_fast_dputfield, bc, r1, true, byte_no);
3158 }
3159 }
3160
3161 #ifdef ASSERT
3162 __ b(Done);
3163
3164 __ bind(notDouble);
3165 __ stop("Bad state");
3166 #endif
3167
3168 __ bind(Done);
3169
3170 {
3171 Label notVolatile;
3172 __ tbz(flags, ResolvedFieldEntry::is_volatile_shift, notVolatile);
3173 __ membar(MacroAssembler::StoreLoad | MacroAssembler::StoreStore);
3174 __ bind(notVolatile);
3175 }
3176 }
3177
3178 void TemplateTable::putfield(int byte_no)
3179 {
3180 putfield_or_static(byte_no, false);
3181 }
3182
3183 void TemplateTable::nofast_putfield(int byte_no) {
3184 putfield_or_static(byte_no, false, may_not_rewrite);
3185 }
3186
3187 void TemplateTable::putstatic(int byte_no) {
3188 putfield_or_static(byte_no, true);
3189 }
3190
3191 void TemplateTable::jvmti_post_fast_field_mod() {
3192 if (JvmtiExport::can_post_field_modification()) {
3193 // Check to see if a field modification watch has been set before
3194 // we take the time to call into the VM.
3195 Label L2;
3196 __ lea(rscratch1, ExternalAddress((address)JvmtiExport::get_field_modification_count_addr()));
3197 __ ldrw(c_rarg3, Address(rscratch1));
3198 __ cbzw(c_rarg3, L2);
3199 __ pop_ptr(r19); // copy the object pointer from tos
3200 __ verify_oop(r19);
3201 __ push_ptr(r19); // put the object pointer back on tos
3202 // Save tos values before call_VM() clobbers them. Since we have
3203 // to do it for every data type, we use the saved values as the
3204 // jvalue object.
3205 switch (bytecode()) { // load values into the jvalue object
3206 case Bytecodes::_fast_vputfield: //fall through
3207 case Bytecodes::_fast_aputfield: __ push_ptr(r0); break;
3208 case Bytecodes::_fast_bputfield: // fall through
3209 case Bytecodes::_fast_zputfield: // fall through
3210 case Bytecodes::_fast_sputfield: // fall through
3211 case Bytecodes::_fast_cputfield: // fall through
3212 case Bytecodes::_fast_iputfield: __ push_i(r0); break;
3213 case Bytecodes::_fast_dputfield: __ push_d(); break;
3214 case Bytecodes::_fast_fputfield: __ push_f(); break;
3215 case Bytecodes::_fast_lputfield: __ push_l(r0); break;
3216
3217 default:
3218 ShouldNotReachHere();
3219 }
3220 __ mov(c_rarg3, esp); // points to jvalue on the stack
3221 // access constant pool cache entry
3222 __ load_field_entry(c_rarg2, r0);
3223 __ verify_oop(r19);
3224 // r19: object pointer copied above
3225 // c_rarg2: cache entry pointer
3226 // c_rarg3: jvalue object on the stack
3227 __ call_VM(noreg,
3228 CAST_FROM_FN_PTR(address,
3229 InterpreterRuntime::post_field_modification),
3230 r19, c_rarg2, c_rarg3);
3231
3232 switch (bytecode()) { // restore tos values
3233 case Bytecodes::_fast_vputfield: //fall through
3234 case Bytecodes::_fast_aputfield: __ pop_ptr(r0); break;
3235 case Bytecodes::_fast_bputfield: // fall through
3236 case Bytecodes::_fast_zputfield: // fall through
3237 case Bytecodes::_fast_sputfield: // fall through
3238 case Bytecodes::_fast_cputfield: // fall through
3239 case Bytecodes::_fast_iputfield: __ pop_i(r0); break;
3240 case Bytecodes::_fast_dputfield: __ pop_d(); break;
3241 case Bytecodes::_fast_fputfield: __ pop_f(); break;
3242 case Bytecodes::_fast_lputfield: __ pop_l(r0); break;
3243 default: break;
3244 }
3245 __ bind(L2);
3246 }
3247 }
3248
3249 void TemplateTable::fast_storefield(TosState state)
3250 {
3251 transition(state, vtos);
3252
3253 ByteSize base = ConstantPoolCache::base_offset();
3260 // R1: field offset, R2: field holder, R5: flags
3261 load_resolved_field_entry(r2, r2, noreg, r1, r5);
3262
3263 {
3264 Label notVolatile;
3265 __ tbz(r5, ResolvedFieldEntry::is_volatile_shift, notVolatile);
3266 __ membar(MacroAssembler::StoreStore | MacroAssembler::LoadStore);
3267 __ bind(notVolatile);
3268 }
3269
3270 Label notVolatile;
3271
3272 // Get object from stack
3273 pop_and_check_object(r2);
3274
3275 // field address
3276 const Address field(r2, r1);
3277
3278 // access field
3279 switch (bytecode()) {
3280 case Bytecodes::_fast_vputfield:
3281 {
3282 Label is_flat, has_null_marker, done;
3283 __ test_field_is_flat(r5, noreg /* temp */, is_flat);
3284 __ null_check(r0);
3285 do_oop_store(_masm, field, r0, IN_HEAP);
3286 __ b(done);
3287 __ bind(is_flat);
3288 __ load_field_entry(r4, r5);
3289 // Re-shuffle registers because of VM calls calling convention
3290 __ mov(r19, r1);
3291 __ mov(r7, r2);
3292 __ write_flat_field(r4, r19, r6, r8, r7);
3293 __ bind(done);
3294 }
3295 break;
3296 case Bytecodes::_fast_aputfield:
3297 // Clobbers: r10, r11, r3
3298 do_oop_store(_masm, field, r0, IN_HEAP);
3299 break;
3300 case Bytecodes::_fast_lputfield:
3301 __ access_store_at(T_LONG, IN_HEAP, field, r0, noreg, noreg, noreg);
3302 break;
3303 case Bytecodes::_fast_iputfield:
3304 __ access_store_at(T_INT, IN_HEAP, field, r0, noreg, noreg, noreg);
3305 break;
3306 case Bytecodes::_fast_zputfield:
3307 __ access_store_at(T_BOOLEAN, IN_HEAP, field, r0, noreg, noreg, noreg);
3308 break;
3309 case Bytecodes::_fast_bputfield:
3310 __ access_store_at(T_BYTE, IN_HEAP, field, r0, noreg, noreg, noreg);
3311 break;
3312 case Bytecodes::_fast_sputfield:
3313 __ access_store_at(T_SHORT, IN_HEAP, field, r0, noreg, noreg, noreg);
3314 break;
3315 case Bytecodes::_fast_cputfield:
3369 // r0: object
3370 __ verify_oop(r0);
3371 __ null_check(r0);
3372 const Address field(r0, r1);
3373
3374 // 8179954: We need to make sure that the code generated for
3375 // volatile accesses forms a sequentially-consistent set of
3376 // operations when combined with STLR and LDAR. Without a leading
3377 // membar it's possible for a simple Dekker test to fail if loads
3378 // use LDR;DMB but stores use STLR. This can happen if C2 compiles
3379 // the stores in one method and we interpret the loads in another.
3380 if (!CompilerConfig::is_c1_or_interpreter_only_no_jvmci()) {
3381 Label notVolatile;
3382 __ tbz(r3, ResolvedFieldEntry::is_volatile_shift, notVolatile);
3383 __ membar(MacroAssembler::AnyAny);
3384 __ bind(notVolatile);
3385 }
3386
3387 // access field
3388 switch (bytecode()) {
3389 case Bytecodes::_fast_vgetfield:
3390 {
3391 Register index = r4, tmp = r7;
3392 // field is flat
3393 __ load_unsigned_short(index, Address(r2, in_bytes(ResolvedFieldEntry::field_index_offset())));
3394 __ read_flat_field(r2, index, r1, tmp /* temp */, r0);
3395 __ verify_oop(r0);
3396 }
3397 break;
3398 case Bytecodes::_fast_agetfield:
3399 do_oop_load(_masm, field, r0, IN_HEAP);
3400 __ verify_oop(r0);
3401 break;
3402 case Bytecodes::_fast_lgetfield:
3403 __ access_load_at(T_LONG, IN_HEAP, r0, field, noreg, noreg);
3404 break;
3405 case Bytecodes::_fast_igetfield:
3406 __ access_load_at(T_INT, IN_HEAP, r0, field, noreg, noreg);
3407 break;
3408 case Bytecodes::_fast_bgetfield:
3409 __ access_load_at(T_BYTE, IN_HEAP, r0, field, noreg, noreg);
3410 break;
3411 case Bytecodes::_fast_sgetfield:
3412 __ access_load_at(T_SHORT, IN_HEAP, r0, field, noreg, noreg);
3413 break;
3414 case Bytecodes::_fast_cgetfield:
3415 __ access_load_at(T_CHAR, IN_HEAP, r0, field, noreg, noreg);
3416 break;
3417 case Bytecodes::_fast_fgetfield:
3796 Label initialize_header;
3797
3798 __ get_cpool_and_tags(r4, r0);
3799 // Make sure the class we're about to instantiate has been resolved.
3800 // This is done before loading InstanceKlass to be consistent with the order
3801 // how Constant Pool is updated (see ConstantPool::klass_at_put)
3802 const int tags_offset = Array<u1>::base_offset_in_bytes();
3803 __ lea(rscratch1, Address(r0, r3, Address::lsl(0)));
3804 __ lea(rscratch1, Address(rscratch1, tags_offset));
3805 __ ldarb(rscratch1, rscratch1);
3806 __ cmp(rscratch1, (u1)JVM_CONSTANT_Class);
3807 __ br(Assembler::NE, slow_case);
3808
3809 // get InstanceKlass
3810 __ load_resolved_klass_at_offset(r4, r3, r4, rscratch1);
3811
3812 // make sure klass is initialized
3813 assert(VM_Version::supports_fast_class_init_checks(), "Optimization requires support for fast class initialization checks");
3814 __ clinit_barrier(r4, rscratch1, nullptr /*L_fast_path*/, &slow_case);
3815
3816 __ allocate_instance(r4, r0, r3, r1, true, slow_case);
3817 __ b(done);
3818
3819 // slow case
3820 __ bind(slow_case);
3821 __ get_constant_pool(c_rarg1);
3822 __ get_unsigned_2_byte_index_at_bcp(c_rarg2, 1);
3823 call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), c_rarg1, c_rarg2);
3824 __ verify_oop(r0);
3825
3826 // continue
3827 __ bind(done);
3828 // Must prevent reordering of stores for object initialization with stores that publish the new object.
3829 __ membar(Assembler::StoreStore);
3830 }
3831
3832 void TemplateTable::newarray() {
3833 transition(itos, atos);
3834 __ load_unsigned_byte(c_rarg1, at_bcp(1));
3835 __ mov(c_rarg2, r0);
3836 call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::newarray),
3837 c_rarg1, c_rarg2);
3881 __ bind(quicked);
3882 __ mov(r3, r0); // Save object in r3; r0 needed for subtype check
3883 __ load_resolved_klass_at_offset(r2, r19, r0, rscratch1); // r0 = klass
3884
3885 __ bind(resolved);
3886 __ load_klass(r19, r3);
3887
3888 // Generate subtype check. Blows r2, r5. Object in r3.
3889 // Superklass in r0. Subklass in r19.
3890 __ gen_subtype_check(r19, ok_is_subtype);
3891
3892 // Come here on failure
3893 __ push(r3);
3894 // object is at TOS
3895 __ b(Interpreter::_throw_ClassCastException_entry);
3896
3897 // Come here on success
3898 __ bind(ok_is_subtype);
3899 __ mov(r0, r3); // Restore object in r3
3900
3901 __ b(done);
3902 __ bind(is_null);
3903
3904 // Collect counts on whether this test sees nulls a lot or not.
3905 if (ProfileInterpreter) {
3906 __ profile_null_seen(r2);
3907 }
3908
3909 __ bind(done);
3910 }
3911
3912 void TemplateTable::instanceof() {
3913 transition(atos, itos);
3914 Label done, is_null, ok_is_subtype, quicked, resolved;
3915 __ cbz(r0, is_null);
3916
3917 // Get cpool & tags index
3918 __ get_cpool_and_tags(r2, r3); // r2=cpool, r3=tags array
3919 __ get_unsigned_2_byte_index_at_bcp(r19, 1); // r19=index
3920 // See if bytecode has already been quicked
3921 __ add(rscratch1, r3, Array<u1>::base_offset_in_bytes());
3922 __ lea(r1, Address(rscratch1, r19));
3923 __ ldarb(r1, r1);
3924 __ cmp(r1, (u1)JVM_CONSTANT_Class);
3925 __ br(Assembler::EQ, quicked);
3926
3927 __ push(atos); // save receiver for result, and for GC
3928 call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc));
4006 // in the assembly code structure as well
4007 //
4008 // Stack layout:
4009 //
4010 // [expressions ] <--- esp = expression stack top
4011 // ..
4012 // [expressions ]
4013 // [monitor entry] <--- monitor block top = expression stack bot
4014 // ..
4015 // [monitor entry]
4016 // [frame data ] <--- monitor block bot
4017 // ...
4018 // [saved rfp ] <--- rfp
4019 void TemplateTable::monitorenter()
4020 {
4021 transition(atos, vtos);
4022
4023 // check for null object
4024 __ null_check(r0);
4025
4026 Label is_inline_type;
4027 __ ldr(rscratch1, Address(r0, oopDesc::mark_offset_in_bytes()));
4028 __ test_markword_is_inline_type(rscratch1, is_inline_type);
4029
4030 const Address monitor_block_top(
4031 rfp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
4032 const Address monitor_block_bot(
4033 rfp, frame::interpreter_frame_initial_sp_offset * wordSize);
4034 const int entry_size = frame::interpreter_frame_monitor_size_in_bytes();
4035
4036 Label allocated;
4037
4038 // initialize entry pointer
4039 __ mov(c_rarg1, zr); // points to free slot or null
4040
4041 // find a free slot in the monitor block (result in c_rarg1)
4042 {
4043 Label entry, loop, exit;
4044 __ ldr(c_rarg3, monitor_block_top); // derelativize pointer
4045 __ lea(c_rarg3, Address(rfp, c_rarg3, Address::lsl(Interpreter::logStackElementSize)));
4046 // c_rarg3 points to current entry, starting with top-most entry
4047
4048 __ lea(c_rarg2, monitor_block_bot); // points to word before bottom
4049
4111 // c_rarg1: points to monitor entry
4112 __ bind(allocated);
4113
4114 // Increment bcp to point to the next bytecode, so exception
4115 // handling for async. exceptions work correctly.
4116 // The object has already been popped from the stack, so the
4117 // expression stack looks correct.
4118 __ increment(rbcp);
4119
4120 // store object
4121 __ str(r0, Address(c_rarg1, BasicObjectLock::obj_offset()));
4122 __ lock_object(c_rarg1);
4123
4124 // check to make sure this monitor doesn't cause stack overflow after locking
4125 __ save_bcp(); // in case of exception
4126 __ generate_stack_overflow_check(0);
4127
4128 // The bcp has already been incremented. Just need to dispatch to
4129 // next instruction.
4130 __ dispatch_next(vtos);
4131
4132 __ bind(is_inline_type);
4133 __ call_VM(noreg, CAST_FROM_FN_PTR(address,
4134 InterpreterRuntime::throw_identity_exception), r0);
4135 __ should_not_reach_here();
4136 }
4137
4138
4139 void TemplateTable::monitorexit()
4140 {
4141 transition(atos, vtos);
4142
4143 // check for null object
4144 __ null_check(r0);
4145
4146 const int is_inline_type_mask = markWord::inline_type_pattern;
4147 Label has_identity;
4148 __ ldr(rscratch1, Address(r0, oopDesc::mark_offset_in_bytes()));
4149 __ mov(rscratch2, is_inline_type_mask);
4150 __ andr(rscratch1, rscratch1, rscratch2);
4151 __ cmp(rscratch1, rscratch2);
4152 __ br(Assembler::NE, has_identity);
4153 __ call_VM(noreg, CAST_FROM_FN_PTR(address,
4154 InterpreterRuntime::throw_illegal_monitor_state_exception));
4155 __ should_not_reach_here();
4156 __ bind(has_identity);
4157
4158 const Address monitor_block_top(
4159 rfp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
4160 const Address monitor_block_bot(
4161 rfp, frame::interpreter_frame_initial_sp_offset * wordSize);
4162 const int entry_size = frame::interpreter_frame_monitor_size_in_bytes();
4163
4164 Label found;
4165
4166 // find matching slot
4167 {
4168 Label entry, loop;
4169 __ ldr(c_rarg1, monitor_block_top); // derelativize pointer
4170 __ lea(c_rarg1, Address(rfp, c_rarg1, Address::lsl(Interpreter::logStackElementSize)));
4171 // c_rarg1 points to current entry, starting with top-most entry
4172
4173 __ lea(c_rarg2, monitor_block_bot); // points to word before bottom
4174 // of monitor block
4175 __ b(entry);
4176
4177 __ bind(loop);
|