1 /*
2 * Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2014, Red Hat Inc. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
156 static void do_oop_load(InterpreterMacroAssembler* _masm,
157 Address src,
158 Register dst,
159 DecoratorSet decorators) {
160 __ load_heap_oop(dst, src, r10, r11, decorators);
161 }
162
163 Address TemplateTable::at_bcp(int offset) {
164 assert(_desc->uses_bcp(), "inconsistent uses_bcp information");
165 return Address(rbcp, offset);
166 }
167
168 void TemplateTable::patch_bytecode(Bytecodes::Code bc, Register bc_reg,
169 Register temp_reg, bool load_bc_into_bc_reg/*=true*/,
170 int byte_no)
171 {
172 if (!RewriteBytecodes) return;
173 Label L_patch_done;
174
175 switch (bc) {
176 case Bytecodes::_fast_aputfield:
177 case Bytecodes::_fast_bputfield:
178 case Bytecodes::_fast_zputfield:
179 case Bytecodes::_fast_cputfield:
180 case Bytecodes::_fast_dputfield:
181 case Bytecodes::_fast_fputfield:
182 case Bytecodes::_fast_iputfield:
183 case Bytecodes::_fast_lputfield:
184 case Bytecodes::_fast_sputfield:
185 {
186 // We skip bytecode quickening for putfield instructions when
187 // the put_code written to the constant pool cache is zero.
188 // This is required so that every execution of this instruction
189 // calls out to InterpreterRuntime::resolve_get_put to do
190 // additional, required work.
191 assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
192 assert(load_bc_into_bc_reg, "we use bc_reg as temp");
193 __ load_field_entry(temp_reg, bc_reg);
194 if (byte_no == f1_byte) {
195 __ lea(temp_reg, Address(temp_reg, in_bytes(ResolvedFieldEntry::get_code_offset())));
737 locals_index_wide(r1);
738 __ ldr(r0, aaddress(r1));
739 }
740
741 void TemplateTable::index_check(Register array, Register index)
742 {
743 // destroys r1, rscratch1
744 // sign extend index for use by indexed load
745 // __ movl2ptr(index, index);
746 // check index
747 Register length = rscratch1;
748 __ ldrw(length, Address(array, arrayOopDesc::length_offset_in_bytes()));
749 __ cmpw(index, length);
750 if (index != r1) {
751 // ??? convention: move aberrant index into r1 for exception message
752 assert(r1 != array, "different registers");
753 __ mov(r1, index);
754 }
755 Label ok;
756 __ br(Assembler::LO, ok);
757 // ??? convention: move array into r3 for exception message
758 __ mov(r3, array);
759 __ mov(rscratch1, Interpreter::_throw_ArrayIndexOutOfBoundsException_entry);
760 __ br(rscratch1);
761 __ bind(ok);
762 }
763
764 void TemplateTable::iaload()
765 {
766 transition(itos, itos);
767 __ mov(r1, r0);
768 __ pop_ptr(r0);
769 // r0: array
770 // r1: index
771 index_check(r0, r1); // leaves index in r1, kills rscratch1
772 __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_INT) >> 2);
773 __ access_load_at(T_INT, IN_HEAP | IS_ARRAY, r0, Address(r0, r1, Address::uxtw(2)), noreg, noreg);
774 }
775
776 void TemplateTable::laload()
777 {
778 transition(itos, ltos);
779 __ mov(r1, r0);
780 __ pop_ptr(r0);
800 void TemplateTable::daload()
801 {
802 transition(itos, dtos);
803 __ mov(r1, r0);
804 __ pop_ptr(r0);
805 // r0: array
806 // r1: index
807 index_check(r0, r1); // leaves index in r1, kills rscratch1
808 __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_DOUBLE) >> 3);
809 __ access_load_at(T_DOUBLE, IN_HEAP | IS_ARRAY, r0, Address(r0, r1, Address::uxtw(3)), noreg, noreg);
810 }
811
812 void TemplateTable::aaload()
813 {
814 transition(itos, atos);
815 __ mov(r1, r0);
816 __ pop_ptr(r0);
817 // r0: array
818 // r1: index
819 index_check(r0, r1); // leaves index in r1, kills rscratch1
820 __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_OBJECT) >> LogBytesPerHeapOop);
821 do_oop_load(_masm,
822 Address(r0, r1, Address::uxtw(LogBytesPerHeapOop)),
823 r0,
824 IS_ARRAY);
825 }
826
827 void TemplateTable::baload()
828 {
829 transition(itos, itos);
830 __ mov(r1, r0);
831 __ pop_ptr(r0);
832 // r0: array
833 // r1: index
834 index_check(r0, r1); // leaves index in r1, kills rscratch1
835 __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_BYTE) >> 0);
836 __ access_load_at(T_BYTE, IN_HEAP | IS_ARRAY, r0, Address(r0, r1, Address::uxtw(0)), noreg, noreg);
837 }
838
839 void TemplateTable::caload()
840 {
841 transition(itos, itos);
842 __ mov(r1, r0);
843 __ pop_ptr(r0);
844 // r0: array
1091 // r1: index
1092 // r3: array
1093 index_check(r3, r1); // prefer index in r1
1094 __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_FLOAT) >> 2);
1095 __ access_store_at(T_FLOAT, IN_HEAP | IS_ARRAY, Address(r3, r1, Address::uxtw(2)), noreg /* ftos */, noreg, noreg, noreg);
1096 }
1097
1098 void TemplateTable::dastore() {
1099 transition(dtos, vtos);
1100 __ pop_i(r1);
1101 __ pop_ptr(r3);
1102 // v0: value
1103 // r1: index
1104 // r3: array
1105 index_check(r3, r1); // prefer index in r1
1106 __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_DOUBLE) >> 3);
1107 __ access_store_at(T_DOUBLE, IN_HEAP | IS_ARRAY, Address(r3, r1, Address::uxtw(3)), noreg /* dtos */, noreg, noreg, noreg);
1108 }
1109
1110 void TemplateTable::aastore() {
1111 Label is_null, ok_is_subtype, done;
1112 transition(vtos, vtos);
1113 // stack: ..., array, index, value
1114 __ ldr(r0, at_tos()); // value
1115 __ ldr(r2, at_tos_p1()); // index
1116 __ ldr(r3, at_tos_p2()); // array
1117
1118 Address element_address(r3, r4, Address::uxtw(LogBytesPerHeapOop));
1119
1120 index_check(r3, r2); // kills r1
1121 __ add(r4, r2, arrayOopDesc::base_offset_in_bytes(T_OBJECT) >> LogBytesPerHeapOop);
1122
1123 // do array store check - check for null value first
1124 __ cbz(r0, is_null);
1125
1126 // Move subklass into r1
1127 __ load_klass(r1, r0);
1128 // Move superklass into r0
1129 __ load_klass(r0, r3);
1130 __ ldr(r0, Address(r0,
1131 ObjArrayKlass::element_klass_offset()));
1132 // Compress array + index*oopSize + 12 into a single register. Frees r2.
1133
1134 // Generate subtype check. Blows r2, r5
1135 // Superklass in r0. Subklass in r1.
1136 __ gen_subtype_check(r1, ok_is_subtype);
1137
1138 // Come here on failure
1139 // object is at TOS
1140 __ b(Interpreter::_throw_ArrayStoreException_entry);
1141
1142 // Come here on success
1143 __ bind(ok_is_subtype);
1144
1145 // Get the value we will store
1146 __ ldr(r0, at_tos());
1147 // Now store using the appropriate barrier
1148 do_oop_store(_masm, element_address, r0, IS_ARRAY);
1149 __ b(done);
1150
1151 // Have a null in r0, r3=array, r2=index. Store null at ary[idx]
1152 __ bind(is_null);
1153 __ profile_null_seen(r2);
1154
1155 // Store a null
1156 do_oop_store(_masm, element_address, noreg, IS_ARRAY);
1157
1158 // Pop stack arguments
1159 __ bind(done);
1160 __ add(esp, esp, 3 * Interpreter::stackElementSize);
1161 }
1162
1163 void TemplateTable::bastore()
1164 {
1165 transition(itos, vtos);
1166 __ pop_i(r1);
1167 __ pop_ptr(r3);
1168 // r0: value
1169 // r1: index
1170 // r3: array
1171 index_check(r3, r1); // prefer index in r1
1172
1173 // Need to check whether array is boolean or byte
1174 // since both types share the bastore bytecode.
1175 __ load_klass(r2, r3);
1176 __ ldrw(r2, Address(r2, Klass::layout_helper_offset()));
1941 __ br(j_not(cc), not_taken);
1942 branch(false, false);
1943 __ bind(not_taken);
1944 __ profile_not_taken_branch(r0);
1945 }
1946
1947 void TemplateTable::if_nullcmp(Condition cc)
1948 {
1949 transition(atos, vtos);
1950 // assume branch is more often taken than not (loops use backward branches)
1951 Label not_taken;
1952 if (cc == equal)
1953 __ cbnz(r0, not_taken);
1954 else
1955 __ cbz(r0, not_taken);
1956 branch(false, false);
1957 __ bind(not_taken);
1958 __ profile_not_taken_branch(r0);
1959 }
1960
1961 void TemplateTable::if_acmp(Condition cc)
1962 {
1963 transition(atos, vtos);
1964 // assume branch is more often taken than not (loops use backward branches)
1965 Label not_taken;
1966 __ pop_ptr(r1);
1967 __ cmpoop(r1, r0);
1968 __ br(j_not(cc), not_taken);
1969 branch(false, false);
1970 __ bind(not_taken);
1971 __ profile_not_taken_branch(r0);
1972 }
1973
1974 void TemplateTable::ret() {
1975 transition(vtos, vtos);
1976 locals_index(r1);
1977 __ ldr(r1, aaddress(r1)); // get return bci, compute return bcp
1978 __ profile_ret(r1, r2);
1979 __ ldr(rbcp, Address(rmethod, Method::const_offset()));
1980 __ lea(rbcp, Address(rbcp, r1));
1981 __ add(rbcp, rbcp, in_bytes(ConstMethod::codes_offset()));
1982 __ dispatch_next(vtos, 0, /*generate_poll*/true);
1983 }
1984
1985 void TemplateTable::wide_ret() {
1986 transition(vtos, vtos);
1987 locals_index_wide(r1);
1988 __ ldr(r1, aaddress(r1)); // get return bci, compute return bcp
1989 __ profile_ret(r1, r2);
1990 __ ldr(rbcp, Address(rmethod, Method::const_offset()));
1991 __ lea(rbcp, Address(rbcp, r1));
1992 __ add(rbcp, rbcp, in_bytes(ConstMethod::codes_offset()));
1993 __ dispatch_next(vtos, 0, /*generate_poll*/true);
2563 }
2564 // c_rarg1: object pointer or null
2565 // c_rarg2: cache entry pointer
2566 __ call_VM(noreg, CAST_FROM_FN_PTR(address,
2567 InterpreterRuntime::post_field_access),
2568 c_rarg1, c_rarg2);
2569 __ load_field_entry(cache, index);
2570 __ bind(L1);
2571 }
2572 }
2573
2574 void TemplateTable::pop_and_check_object(Register r)
2575 {
2576 __ pop_ptr(r);
2577 __ null_check(r); // for field access must check obj.
2578 __ verify_oop(r);
2579 }
2580
2581 void TemplateTable::getfield_or_static(int byte_no, bool is_static, RewriteControl rc)
2582 {
2583 const Register cache = r4;
2584 const Register obj = r4;
2585 const Register index = r3;
2586 const Register tos_state = r3;
2587 const Register off = r19;
2588 const Register flags = r6;
2589 const Register bc = r4; // uses same reg as obj, so don't mix them
2590
2591 resolve_cache_and_index_for_field(byte_no, cache, index);
2592 jvmti_post_field_access(cache, index, is_static, false);
2593 load_resolved_field_entry(obj, cache, tos_state, off, flags, is_static);
2594
2595 if (!is_static) {
2596 // obj is on the stack
2597 pop_and_check_object(obj);
2598 }
2599
2600 // 8179954: We need to make sure that the code generated for
2601 // volatile accesses forms a sequentially-consistent set of
2602 // operations when combined with STLR and LDAR. Without a leading
2603 // membar it's possible for a simple Dekker test to fail if loads
2604 // use LDR;DMB but stores use STLR. This can happen if C2 compiles
2605 // the stores in one method and we interpret the loads in another.
2606 if (!CompilerConfig::is_c1_or_interpreter_only_no_jvmci()){
2607 Label notVolatile;
2608 __ tbz(flags, ResolvedFieldEntry::is_volatile_shift, notVolatile);
2609 __ membar(MacroAssembler::AnyAny);
2610 __ bind(notVolatile);
2611 }
2612
2631 __ b(Done);
2632
2633 __ bind(notByte);
2634 __ cmp(tos_state, (u1)ztos);
2635 __ br(Assembler::NE, notBool);
2636
2637 // ztos (same code as btos)
2638 __ access_load_at(T_BOOLEAN, IN_HEAP, r0, field, noreg, noreg);
2639 __ push(ztos);
2640 // Rewrite bytecode to be faster
2641 if (rc == may_rewrite) {
2642 // use btos rewriting, no truncating to t/f bit is needed for getfield.
2643 patch_bytecode(Bytecodes::_fast_bgetfield, bc, r1);
2644 }
2645 __ b(Done);
2646
2647 __ bind(notBool);
2648 __ cmp(tos_state, (u1)atos);
2649 __ br(Assembler::NE, notObj);
2650 // atos
2651 do_oop_load(_masm, field, r0, IN_HEAP);
2652 __ push(atos);
2653 if (rc == may_rewrite) {
2654 patch_bytecode(Bytecodes::_fast_agetfield, bc, r1);
2655 }
2656 __ b(Done);
2657
2658 __ bind(notObj);
2659 __ cmp(tos_state, (u1)itos);
2660 __ br(Assembler::NE, notInt);
2661 // itos
2662 __ access_load_at(T_INT, IN_HEAP, r0, field, noreg, noreg);
2663 __ push(itos);
2664 // Rewrite bytecode to be faster
2665 if (rc == may_rewrite) {
2666 patch_bytecode(Bytecodes::_fast_igetfield, bc, r1);
2667 }
2668 __ b(Done);
2669
2670 __ bind(notInt);
2671 __ cmp(tos_state, (u1)ctos);
2672 __ br(Assembler::NE, notChar);
2673 // ctos
2674 __ access_load_at(T_CHAR, IN_HEAP, r0, field, noreg, noreg);
2675 __ push(ctos);
2676 // Rewrite bytecode to be faster
2797 // c_rarg1: object pointer set up above (null if static)
2798 // c_rarg2: cache entry pointer
2799 // c_rarg3: jvalue object on the stack
2800 __ call_VM(noreg,
2801 CAST_FROM_FN_PTR(address,
2802 InterpreterRuntime::post_field_modification),
2803 c_rarg1, c_rarg2, c_rarg3);
2804 __ load_field_entry(cache, index);
2805 __ bind(L1);
2806 }
2807 }
2808
2809 void TemplateTable::putfield_or_static(int byte_no, bool is_static, RewriteControl rc) {
2810 transition(vtos, vtos);
2811
2812 const Register cache = r2;
2813 const Register index = r3;
2814 const Register tos_state = r3;
2815 const Register obj = r2;
2816 const Register off = r19;
2817 const Register flags = r0;
2818 const Register bc = r4;
2819
2820 resolve_cache_and_index_for_field(byte_no, cache, index);
2821 jvmti_post_field_mod(cache, index, is_static);
2822 load_resolved_field_entry(obj, cache, tos_state, off, flags, is_static);
2823
2824 Label Done;
2825 __ mov(r5, flags);
2826
2827 {
2828 Label notVolatile;
2829 __ tbz(r5, ResolvedFieldEntry::is_volatile_shift, notVolatile);
2830 __ membar(MacroAssembler::StoreStore | MacroAssembler::LoadStore);
2831 __ bind(notVolatile);
2832 }
2833
2834 // field address
2835 const Address field(obj, off);
2836
2837 Label notByte, notBool, notInt, notShort, notChar,
2838 notLong, notFloat, notObj, notDouble;
2839
2840 assert(btos == 0, "change code, btos != 0");
2841 __ cbnz(tos_state, notByte);
2842
2843 // Don't rewrite putstatic, only putfield
2844 if (is_static) rc = may_not_rewrite;
2845
2846 // btos
2847 {
2848 __ pop(btos);
2849 if (!is_static) pop_and_check_object(obj);
2858 __ cmp(tos_state, (u1)ztos);
2859 __ br(Assembler::NE, notBool);
2860
2861 // ztos
2862 {
2863 __ pop(ztos);
2864 if (!is_static) pop_and_check_object(obj);
2865 __ access_store_at(T_BOOLEAN, IN_HEAP, field, r0, noreg, noreg, noreg);
2866 if (rc == may_rewrite) {
2867 patch_bytecode(Bytecodes::_fast_zputfield, bc, r1, true, byte_no);
2868 }
2869 __ b(Done);
2870 }
2871
2872 __ bind(notBool);
2873 __ cmp(tos_state, (u1)atos);
2874 __ br(Assembler::NE, notObj);
2875
2876 // atos
2877 {
2878 __ pop(atos);
2879 if (!is_static) pop_and_check_object(obj);
2880 // Store into the field
2881 do_oop_store(_masm, field, r0, IN_HEAP);
2882 if (rc == may_rewrite) {
2883 patch_bytecode(Bytecodes::_fast_aputfield, bc, r1, true, byte_no);
2884 }
2885 __ b(Done);
2886 }
2887
2888 __ bind(notObj);
2889 __ cmp(tos_state, (u1)itos);
2890 __ br(Assembler::NE, notInt);
2891
2892 // itos
2893 {
2894 __ pop(itos);
2895 if (!is_static) pop_and_check_object(obj);
2896 __ access_store_at(T_INT, IN_HEAP, field, r0, noreg, noreg, noreg);
2897 if (rc == may_rewrite) {
2898 patch_bytecode(Bytecodes::_fast_iputfield, bc, r1, true, byte_no);
2899 }
2900 __ b(Done);
2901 }
2902
2903 __ bind(notInt);
2904 __ cmp(tos_state, (u1)ctos);
2905 __ br(Assembler::NE, notChar);
2970 {
2971 __ pop(dtos);
2972 if (!is_static) pop_and_check_object(obj);
2973 __ access_store_at(T_DOUBLE, IN_HEAP, field, noreg /* dtos */, noreg, noreg, noreg);
2974 if (rc == may_rewrite) {
2975 patch_bytecode(Bytecodes::_fast_dputfield, bc, r1, true, byte_no);
2976 }
2977 }
2978
2979 #ifdef ASSERT
2980 __ b(Done);
2981
2982 __ bind(notDouble);
2983 __ stop("Bad state");
2984 #endif
2985
2986 __ bind(Done);
2987
2988 {
2989 Label notVolatile;
2990 __ tbz(r5, ResolvedFieldEntry::is_volatile_shift, notVolatile);
2991 __ membar(MacroAssembler::StoreLoad | MacroAssembler::StoreStore);
2992 __ bind(notVolatile);
2993 }
2994 }
2995
2996 void TemplateTable::putfield(int byte_no)
2997 {
2998 putfield_or_static(byte_no, false);
2999 }
3000
3001 void TemplateTable::nofast_putfield(int byte_no) {
3002 putfield_or_static(byte_no, false, may_not_rewrite);
3003 }
3004
3005 void TemplateTable::putstatic(int byte_no) {
3006 putfield_or_static(byte_no, true);
3007 }
3008
3009 void TemplateTable::jvmti_post_fast_field_mod() {
3010 if (JvmtiExport::can_post_field_modification()) {
3011 // Check to see if a field modification watch has been set before
3012 // we take the time to call into the VM.
3013 Label L2;
3014 __ lea(rscratch1, ExternalAddress((address)JvmtiExport::get_field_modification_count_addr()));
3015 __ ldrw(c_rarg3, Address(rscratch1));
3016 __ cbzw(c_rarg3, L2);
3017 __ pop_ptr(r19); // copy the object pointer from tos
3018 __ verify_oop(r19);
3019 __ push_ptr(r19); // put the object pointer back on tos
3020 // Save tos values before call_VM() clobbers them. Since we have
3021 // to do it for every data type, we use the saved values as the
3022 // jvalue object.
3023 switch (bytecode()) { // load values into the jvalue object
3024 case Bytecodes::_fast_aputfield: __ push_ptr(r0); break;
3025 case Bytecodes::_fast_bputfield: // fall through
3026 case Bytecodes::_fast_zputfield: // fall through
3027 case Bytecodes::_fast_sputfield: // fall through
3028 case Bytecodes::_fast_cputfield: // fall through
3029 case Bytecodes::_fast_iputfield: __ push_i(r0); break;
3030 case Bytecodes::_fast_dputfield: __ push_d(); break;
3031 case Bytecodes::_fast_fputfield: __ push_f(); break;
3032 case Bytecodes::_fast_lputfield: __ push_l(r0); break;
3033
3034 default:
3035 ShouldNotReachHere();
3036 }
3037 __ mov(c_rarg3, esp); // points to jvalue on the stack
3038 // access constant pool cache entry
3039 __ load_field_entry(c_rarg2, r0);
3040 __ verify_oop(r19);
3041 // r19: object pointer copied above
3042 // c_rarg2: cache entry pointer
3043 // c_rarg3: jvalue object on the stack
3044 __ call_VM(noreg,
3045 CAST_FROM_FN_PTR(address,
3046 InterpreterRuntime::post_field_modification),
3047 r19, c_rarg2, c_rarg3);
3048
3049 switch (bytecode()) { // restore tos values
3050 case Bytecodes::_fast_aputfield: __ pop_ptr(r0); break;
3051 case Bytecodes::_fast_bputfield: // fall through
3052 case Bytecodes::_fast_zputfield: // fall through
3053 case Bytecodes::_fast_sputfield: // fall through
3054 case Bytecodes::_fast_cputfield: // fall through
3055 case Bytecodes::_fast_iputfield: __ pop_i(r0); break;
3056 case Bytecodes::_fast_dputfield: __ pop_d(); break;
3057 case Bytecodes::_fast_fputfield: __ pop_f(); break;
3058 case Bytecodes::_fast_lputfield: __ pop_l(r0); break;
3059 default: break;
3060 }
3061 __ bind(L2);
3062 }
3063 }
3064
3065 void TemplateTable::fast_storefield(TosState state)
3066 {
3067 transition(state, vtos);
3068
3069 ByteSize base = ConstantPoolCache::base_offset();
3076 // R1: field offset, R2: field holder, R3: flags
3077 load_resolved_field_entry(r2, r2, noreg, r1, r3);
3078
3079 {
3080 Label notVolatile;
3081 __ tbz(r3, ResolvedFieldEntry::is_volatile_shift, notVolatile);
3082 __ membar(MacroAssembler::StoreStore | MacroAssembler::LoadStore);
3083 __ bind(notVolatile);
3084 }
3085
3086 Label notVolatile;
3087
3088 // Get object from stack
3089 pop_and_check_object(r2);
3090
3091 // field address
3092 const Address field(r2, r1);
3093
3094 // access field
3095 switch (bytecode()) {
3096 case Bytecodes::_fast_aputfield:
3097 do_oop_store(_masm, field, r0, IN_HEAP);
3098 break;
3099 case Bytecodes::_fast_lputfield:
3100 __ access_store_at(T_LONG, IN_HEAP, field, r0, noreg, noreg, noreg);
3101 break;
3102 case Bytecodes::_fast_iputfield:
3103 __ access_store_at(T_INT, IN_HEAP, field, r0, noreg, noreg, noreg);
3104 break;
3105 case Bytecodes::_fast_zputfield:
3106 __ access_store_at(T_BOOLEAN, IN_HEAP, field, r0, noreg, noreg, noreg);
3107 break;
3108 case Bytecodes::_fast_bputfield:
3109 __ access_store_at(T_BYTE, IN_HEAP, field, r0, noreg, noreg, noreg);
3110 break;
3111 case Bytecodes::_fast_sputfield:
3112 __ access_store_at(T_SHORT, IN_HEAP, field, r0, noreg, noreg, noreg);
3113 break;
3114 case Bytecodes::_fast_cputfield:
3115 __ access_store_at(T_CHAR, IN_HEAP, field, r0, noreg, noreg, noreg);
3168 // r0: object
3169 __ verify_oop(r0);
3170 __ null_check(r0);
3171 const Address field(r0, r1);
3172
3173 // 8179954: We need to make sure that the code generated for
3174 // volatile accesses forms a sequentially-consistent set of
3175 // operations when combined with STLR and LDAR. Without a leading
3176 // membar it's possible for a simple Dekker test to fail if loads
3177 // use LDR;DMB but stores use STLR. This can happen if C2 compiles
3178 // the stores in one method and we interpret the loads in another.
3179 if (!CompilerConfig::is_c1_or_interpreter_only_no_jvmci()) {
3180 Label notVolatile;
3181 __ tbz(r3, ResolvedFieldEntry::is_volatile_shift, notVolatile);
3182 __ membar(MacroAssembler::AnyAny);
3183 __ bind(notVolatile);
3184 }
3185
3186 // access field
3187 switch (bytecode()) {
3188 case Bytecodes::_fast_agetfield:
3189 do_oop_load(_masm, field, r0, IN_HEAP);
3190 __ verify_oop(r0);
3191 break;
3192 case Bytecodes::_fast_lgetfield:
3193 __ access_load_at(T_LONG, IN_HEAP, r0, field, noreg, noreg);
3194 break;
3195 case Bytecodes::_fast_igetfield:
3196 __ access_load_at(T_INT, IN_HEAP, r0, field, noreg, noreg);
3197 break;
3198 case Bytecodes::_fast_bgetfield:
3199 __ access_load_at(T_BYTE, IN_HEAP, r0, field, noreg, noreg);
3200 break;
3201 case Bytecodes::_fast_sgetfield:
3202 __ access_load_at(T_SHORT, IN_HEAP, r0, field, noreg, noreg);
3203 break;
3204 case Bytecodes::_fast_cgetfield:
3205 __ access_load_at(T_CHAR, IN_HEAP, r0, field, noreg, noreg);
3206 break;
3207 case Bytecodes::_fast_fgetfield:
3586 Label initialize_header;
3587
3588 __ get_cpool_and_tags(r4, r0);
3589 // Make sure the class we're about to instantiate has been resolved.
3590 // This is done before loading InstanceKlass to be consistent with the order
3591 // how Constant Pool is updated (see ConstantPool::klass_at_put)
3592 const int tags_offset = Array<u1>::base_offset_in_bytes();
3593 __ lea(rscratch1, Address(r0, r3, Address::lsl(0)));
3594 __ lea(rscratch1, Address(rscratch1, tags_offset));
3595 __ ldarb(rscratch1, rscratch1);
3596 __ cmp(rscratch1, (u1)JVM_CONSTANT_Class);
3597 __ br(Assembler::NE, slow_case);
3598
3599 // get InstanceKlass
3600 __ load_resolved_klass_at_offset(r4, r3, r4, rscratch1);
3601
3602 // make sure klass is initialized
3603 assert(VM_Version::supports_fast_class_init_checks(), "Optimization requires support for fast class initialization checks");
3604 __ clinit_barrier(r4, rscratch1, nullptr /*L_fast_path*/, &slow_case);
3605
3606 // get instance_size in InstanceKlass (scaled to a count of bytes)
3607 __ ldrw(r3,
3608 Address(r4,
3609 Klass::layout_helper_offset()));
3610 // test to see if it is malformed in some way
3611 __ tbnz(r3, exact_log2(Klass::_lh_instance_slow_path_bit), slow_case);
3612
3613 // Allocate the instance:
3614 // If TLAB is enabled:
3615 // Try to allocate in the TLAB.
3616 // If fails, go to the slow path.
3617 // Initialize the allocation.
3618 // Exit.
3619 //
3620 // Go to slow path.
3621
3622 if (UseTLAB) {
3623 __ tlab_allocate(r0, r3, 0, noreg, r1, slow_case);
3624
3625 if (ZeroTLAB) {
3626 // the fields have been already cleared
3627 __ b(initialize_header);
3628 }
3629
3630 // The object is initialized before the header. If the object size is
3631 // zero, go directly to the header initialization.
3632 __ sub(r3, r3, sizeof(oopDesc));
3633 __ cbz(r3, initialize_header);
3634
3635 // Initialize object fields
3636 {
3637 __ add(r2, r0, sizeof(oopDesc));
3638 Label loop;
3639 __ bind(loop);
3640 __ str(zr, Address(__ post(r2, BytesPerLong)));
3641 __ sub(r3, r3, BytesPerLong);
3642 __ cbnz(r3, loop);
3643 }
3644
3645 // initialize object header only.
3646 __ bind(initialize_header);
3647 __ mov(rscratch1, (intptr_t)markWord::prototype().value());
3648 __ str(rscratch1, Address(r0, oopDesc::mark_offset_in_bytes()));
3649 __ store_klass_gap(r0, zr); // zero klass gap for compressed oops
3650 __ store_klass(r0, r4); // store klass last
3651
3652 if (DTraceAllocProbes) {
3653 // Trigger dtrace event for fastpath
3654 __ push(atos); // save the return value
3655 __ call_VM_leaf(
3656 CAST_FROM_FN_PTR(address, static_cast<int (*)(oopDesc*)>(SharedRuntime::dtrace_object_alloc)), r0);
3657 __ pop(atos); // restore the return value
3658
3659 }
3660 __ b(done);
3661 }
3662
3663 // slow case
3664 __ bind(slow_case);
3665 __ get_constant_pool(c_rarg1);
3666 __ get_unsigned_2_byte_index_at_bcp(c_rarg2, 1);
3667 call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), c_rarg1, c_rarg2);
3668 __ verify_oop(r0);
3669
3670 // continue
3671 __ bind(done);
3672 // Must prevent reordering of stores for object initialization with stores that publish the new object.
3673 __ membar(Assembler::StoreStore);
3674 }
3675
3676 void TemplateTable::newarray() {
3677 transition(itos, atos);
3678 __ load_unsigned_byte(c_rarg1, at_bcp(1));
3679 __ mov(c_rarg2, r0);
3680 call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::newarray),
3681 c_rarg1, c_rarg2);
3726 __ bind(quicked);
3727 __ mov(r3, r0); // Save object in r3; r0 needed for subtype check
3728 __ load_resolved_klass_at_offset(r2, r19, r0, rscratch1); // r0 = klass
3729
3730 __ bind(resolved);
3731 __ load_klass(r19, r3);
3732
3733 // Generate subtype check. Blows r2, r5. Object in r3.
3734 // Superklass in r0. Subklass in r19.
3735 __ gen_subtype_check(r19, ok_is_subtype);
3736
3737 // Come here on failure
3738 __ push(r3);
3739 // object is at TOS
3740 __ b(Interpreter::_throw_ClassCastException_entry);
3741
3742 // Come here on success
3743 __ bind(ok_is_subtype);
3744 __ mov(r0, r3); // Restore object in r3
3745
3746 // Collect counts on whether this test sees nulls a lot or not.
3747 if (ProfileInterpreter) {
3748 __ b(done);
3749 __ bind(is_null);
3750 __ profile_null_seen(r2);
3751 } else {
3752 __ bind(is_null); // same as 'done'
3753 }
3754 __ bind(done);
3755 }
3756
3757 void TemplateTable::instanceof() {
3758 transition(atos, itos);
3759 Label done, is_null, ok_is_subtype, quicked, resolved;
3760 __ cbz(r0, is_null);
3761
3762 // Get cpool & tags index
3763 __ get_cpool_and_tags(r2, r3); // r2=cpool, r3=tags array
3764 __ get_unsigned_2_byte_index_at_bcp(r19, 1); // r19=index
3765 // See if bytecode has already been quicked
3766 __ add(rscratch1, r3, Array<u1>::base_offset_in_bytes());
3767 __ lea(r1, Address(rscratch1, r19));
3768 __ ldarb(r1, r1);
3769 __ cmp(r1, (u1)JVM_CONSTANT_Class);
3770 __ br(Assembler::EQ, quicked);
3771
3772 __ push(atos); // save receiver for result, and for GC
3773 call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc));
3852 // in the assembly code structure as well
3853 //
3854 // Stack layout:
3855 //
3856 // [expressions ] <--- esp = expression stack top
3857 // ..
3858 // [expressions ]
3859 // [monitor entry] <--- monitor block top = expression stack bot
3860 // ..
3861 // [monitor entry]
3862 // [frame data ] <--- monitor block bot
3863 // ...
3864 // [saved rfp ] <--- rfp
3865 void TemplateTable::monitorenter()
3866 {
3867 transition(atos, vtos);
3868
3869 // check for null object
3870 __ null_check(r0);
3871
3872 const Address monitor_block_top(
3873 rfp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
3874 const Address monitor_block_bot(
3875 rfp, frame::interpreter_frame_initial_sp_offset * wordSize);
3876 const int entry_size = frame::interpreter_frame_monitor_size_in_bytes();
3877
3878 Label allocated;
3879
3880 // initialize entry pointer
3881 __ mov(c_rarg1, zr); // points to free slot or null
3882
3883 // find a free slot in the monitor block (result in c_rarg1)
3884 {
3885 Label entry, loop, exit;
3886 __ ldr(c_rarg3, monitor_block_top); // derelativize pointer
3887 __ lea(c_rarg3, Address(rfp, c_rarg3, Address::lsl(Interpreter::logStackElementSize)));
3888 // c_rarg3 points to current entry, starting with top-most entry
3889
3890 __ lea(c_rarg2, monitor_block_bot); // points to word before bottom
3891
3953 // c_rarg1: points to monitor entry
3954 __ bind(allocated);
3955
3956 // Increment bcp to point to the next bytecode, so exception
3957 // handling for async. exceptions work correctly.
3958 // The object has already been popped from the stack, so the
3959 // expression stack looks correct.
3960 __ increment(rbcp);
3961
3962 // store object
3963 __ str(r0, Address(c_rarg1, BasicObjectLock::obj_offset()));
3964 __ lock_object(c_rarg1);
3965
3966 // check to make sure this monitor doesn't cause stack overflow after locking
3967 __ save_bcp(); // in case of exception
3968 __ generate_stack_overflow_check(0);
3969
3970 // The bcp has already been incremented. Just need to dispatch to
3971 // next instruction.
3972 __ dispatch_next(vtos);
3973 }
3974
3975
3976 void TemplateTable::monitorexit()
3977 {
3978 transition(atos, vtos);
3979
3980 // check for null object
3981 __ null_check(r0);
3982
3983 const Address monitor_block_top(
3984 rfp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
3985 const Address monitor_block_bot(
3986 rfp, frame::interpreter_frame_initial_sp_offset * wordSize);
3987 const int entry_size = frame::interpreter_frame_monitor_size_in_bytes();
3988
3989 Label found;
3990
3991 // find matching slot
3992 {
3993 Label entry, loop;
3994 __ ldr(c_rarg1, monitor_block_top); // derelativize pointer
3995 __ lea(c_rarg1, Address(rfp, c_rarg1, Address::lsl(Interpreter::logStackElementSize)));
3996 // c_rarg1 points to current entry, starting with top-most entry
3997
3998 __ lea(c_rarg2, monitor_block_bot); // points to word before bottom
3999 // of monitor block
4000 __ b(entry);
4001
4002 __ bind(loop);
|
1 /*
2 * Copyright (c) 2003, 2025, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2014, Red Hat Inc. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
156 static void do_oop_load(InterpreterMacroAssembler* _masm,
157 Address src,
158 Register dst,
159 DecoratorSet decorators) {
160 __ load_heap_oop(dst, src, r10, r11, decorators);
161 }
162
163 Address TemplateTable::at_bcp(int offset) {
164 assert(_desc->uses_bcp(), "inconsistent uses_bcp information");
165 return Address(rbcp, offset);
166 }
167
168 void TemplateTable::patch_bytecode(Bytecodes::Code bc, Register bc_reg,
169 Register temp_reg, bool load_bc_into_bc_reg/*=true*/,
170 int byte_no)
171 {
172 if (!RewriteBytecodes) return;
173 Label L_patch_done;
174
175 switch (bc) {
176 case Bytecodes::_fast_vputfield:
177 case Bytecodes::_fast_aputfield:
178 case Bytecodes::_fast_bputfield:
179 case Bytecodes::_fast_zputfield:
180 case Bytecodes::_fast_cputfield:
181 case Bytecodes::_fast_dputfield:
182 case Bytecodes::_fast_fputfield:
183 case Bytecodes::_fast_iputfield:
184 case Bytecodes::_fast_lputfield:
185 case Bytecodes::_fast_sputfield:
186 {
187 // We skip bytecode quickening for putfield instructions when
188 // the put_code written to the constant pool cache is zero.
189 // This is required so that every execution of this instruction
190 // calls out to InterpreterRuntime::resolve_get_put to do
191 // additional, required work.
192 assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
193 assert(load_bc_into_bc_reg, "we use bc_reg as temp");
194 __ load_field_entry(temp_reg, bc_reg);
195 if (byte_no == f1_byte) {
196 __ lea(temp_reg, Address(temp_reg, in_bytes(ResolvedFieldEntry::get_code_offset())));
738 locals_index_wide(r1);
739 __ ldr(r0, aaddress(r1));
740 }
741
742 void TemplateTable::index_check(Register array, Register index)
743 {
744 // destroys r1, rscratch1
745 // sign extend index for use by indexed load
746 // __ movl2ptr(index, index);
747 // check index
748 Register length = rscratch1;
749 __ ldrw(length, Address(array, arrayOopDesc::length_offset_in_bytes()));
750 __ cmpw(index, length);
751 if (index != r1) {
752 // ??? convention: move aberrant index into r1 for exception message
753 assert(r1 != array, "different registers");
754 __ mov(r1, index);
755 }
756 Label ok;
757 __ br(Assembler::LO, ok);
758 // ??? convention: move array into r3 for exception message
759 __ mov(r3, array);
760 __ mov(rscratch1, Interpreter::_throw_ArrayIndexOutOfBoundsException_entry);
761 __ br(rscratch1);
762 __ bind(ok);
763 }
764
765 void TemplateTable::iaload()
766 {
767 transition(itos, itos);
768 __ mov(r1, r0);
769 __ pop_ptr(r0);
770 // r0: array
771 // r1: index
772 index_check(r0, r1); // leaves index in r1, kills rscratch1
773 __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_INT) >> 2);
774 __ access_load_at(T_INT, IN_HEAP | IS_ARRAY, r0, Address(r0, r1, Address::uxtw(2)), noreg, noreg);
775 }
776
777 void TemplateTable::laload()
778 {
779 transition(itos, ltos);
780 __ mov(r1, r0);
781 __ pop_ptr(r0);
801 void TemplateTable::daload()
802 {
803 transition(itos, dtos);
804 __ mov(r1, r0);
805 __ pop_ptr(r0);
806 // r0: array
807 // r1: index
808 index_check(r0, r1); // leaves index in r1, kills rscratch1
809 __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_DOUBLE) >> 3);
810 __ access_load_at(T_DOUBLE, IN_HEAP | IS_ARRAY, r0, Address(r0, r1, Address::uxtw(3)), noreg, noreg);
811 }
812
813 void TemplateTable::aaload()
814 {
815 transition(itos, atos);
816 __ mov(r1, r0);
817 __ pop_ptr(r0);
818 // r0: array
819 // r1: index
820 index_check(r0, r1); // leaves index in r1, kills rscratch1
821 __ profile_array_type<ArrayLoadData>(r2, r0, r4);
822 if (UseFlatArray) {
823 Label is_flat_array, done;
824
825 __ test_flat_array_oop(r0, r8 /*temp*/, is_flat_array);
826 __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_OBJECT) >> LogBytesPerHeapOop);
827 do_oop_load(_masm, Address(r0, r1, Address::uxtw(LogBytesPerHeapOop)), r0, IS_ARRAY);
828
829 __ b(done);
830 __ bind(is_flat_array);
831 __ call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::flat_array_load), r0, r1);
832 // Ensure the stores to copy the inline field contents are visible
833 // before any subsequent store that publishes this reference.
834 __ membar(Assembler::StoreStore);
835 __ bind(done);
836 } else {
837 __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_OBJECT) >> LogBytesPerHeapOop);
838 do_oop_load(_masm, Address(r0, r1, Address::uxtw(LogBytesPerHeapOop)), r0, IS_ARRAY);
839 }
840 __ profile_element_type(r2, r0, r4);
841 }
842
843 void TemplateTable::baload()
844 {
845 transition(itos, itos);
846 __ mov(r1, r0);
847 __ pop_ptr(r0);
848 // r0: array
849 // r1: index
850 index_check(r0, r1); // leaves index in r1, kills rscratch1
851 __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_BYTE) >> 0);
852 __ access_load_at(T_BYTE, IN_HEAP | IS_ARRAY, r0, Address(r0, r1, Address::uxtw(0)), noreg, noreg);
853 }
854
855 void TemplateTable::caload()
856 {
857 transition(itos, itos);
858 __ mov(r1, r0);
859 __ pop_ptr(r0);
860 // r0: array
1107 // r1: index
1108 // r3: array
1109 index_check(r3, r1); // prefer index in r1
1110 __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_FLOAT) >> 2);
1111 __ access_store_at(T_FLOAT, IN_HEAP | IS_ARRAY, Address(r3, r1, Address::uxtw(2)), noreg /* ftos */, noreg, noreg, noreg);
1112 }
1113
1114 void TemplateTable::dastore() {
1115 transition(dtos, vtos);
1116 __ pop_i(r1);
1117 __ pop_ptr(r3);
1118 // v0: value
1119 // r1: index
1120 // r3: array
1121 index_check(r3, r1); // prefer index in r1
1122 __ add(r1, r1, arrayOopDesc::base_offset_in_bytes(T_DOUBLE) >> 3);
1123 __ access_store_at(T_DOUBLE, IN_HEAP | IS_ARRAY, Address(r3, r1, Address::uxtw(3)), noreg /* dtos */, noreg, noreg, noreg);
1124 }
1125
1126 void TemplateTable::aastore() {
1127 Label is_null, is_flat_array, ok_is_subtype, done;
1128 transition(vtos, vtos);
1129 // stack: ..., array, index, value
1130 __ ldr(r0, at_tos()); // value
1131 __ ldr(r2, at_tos_p1()); // index
1132 __ ldr(r3, at_tos_p2()); // array
1133
1134 index_check(r3, r2); // kills r1
1135
1136 __ profile_array_type<ArrayStoreData>(r4, r3, r5);
1137 __ profile_multiple_element_types(r4, r0, r5, r6);
1138
1139 __ add(r4, r2, arrayOopDesc::base_offset_in_bytes(T_OBJECT) >> LogBytesPerHeapOop);
1140 Address element_address(r3, r4, Address::uxtw(LogBytesPerHeapOop));
1141 // Be careful not to clobber r4 below
1142
1143 // do array store check - check for null value first
1144 __ cbz(r0, is_null);
1145
1146 // Move array class to r5
1147 __ load_klass(r5, r3);
1148
1149 if (UseFlatArray) {
1150 __ ldrw(r6, Address(r5, Klass::layout_helper_offset()));
1151 __ test_flat_array_layout(r6, is_flat_array);
1152 }
1153
1154 // Move subklass into r1
1155 __ load_klass(r1, r0);
1156
1157 // Move array element superklass into r0
1158 __ ldr(r0, Address(r5, ObjArrayKlass::element_klass_offset()));
1159 // Compress array + index*oopSize + 12 into a single register. Frees r2.
1160
1161 // Generate subtype check. Blows r2, r5
1162 // Superklass in r0. Subklass in r1.
1163
1164 // is "r1 <: r0" ? (value subclass <: array element superclass)
1165 __ gen_subtype_check(r1, ok_is_subtype, false);
1166
1167 // Come here on failure
1168 // object is at TOS
1169 __ b(Interpreter::_throw_ArrayStoreException_entry);
1170
1171 // Come here on success
1172 __ bind(ok_is_subtype);
1173
1174 // Get the value we will store
1175 __ ldr(r0, at_tos());
1176 // Now store using the appropriate barrier
1177 do_oop_store(_masm, element_address, r0, IS_ARRAY);
1178 __ b(done);
1179
1180 // Have a null in r0, r3=array, r2=index. Store null at ary[idx]
1181 __ bind(is_null);
1182 if (EnableValhalla) {
1183 Label is_null_into_value_array_npe, store_null;
1184
1185 if (UseFlatArray) {
1186 __ test_flat_array_oop(r3, r8, is_flat_array);
1187 }
1188
1189 // No way to store null in a null-free array
1190 __ test_null_free_array_oop(r3, r8, 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 do_oop_store(_masm, element_address, noreg, IS_ARRAY);
1201 __ b(done);
1202
1203 if (UseFlatArray) {
1204 Label is_type_ok;
1205 __ bind(is_flat_array); // Store non-null value to flat
1206
1207 __ ldr(r0, at_tos()); // value
1208 __ ldr(r3, at_tos_p1()); // index
1209 __ ldr(r2, at_tos_p2()); // array
1210 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::flat_array_store), r0, r2, r3);
1211 }
1212
1213 // Pop stack arguments
1214 __ bind(done);
1215 __ add(esp, esp, 3 * Interpreter::stackElementSize);
1216 }
1217
1218 void TemplateTable::bastore()
1219 {
1220 transition(itos, vtos);
1221 __ pop_i(r1);
1222 __ pop_ptr(r3);
1223 // r0: value
1224 // r1: index
1225 // r3: array
1226 index_check(r3, r1); // prefer index in r1
1227
1228 // Need to check whether array is boolean or byte
1229 // since both types share the bastore bytecode.
1230 __ load_klass(r2, r3);
1231 __ ldrw(r2, Address(r2, Klass::layout_helper_offset()));
1996 __ br(j_not(cc), not_taken);
1997 branch(false, false);
1998 __ bind(not_taken);
1999 __ profile_not_taken_branch(r0);
2000 }
2001
2002 void TemplateTable::if_nullcmp(Condition cc)
2003 {
2004 transition(atos, vtos);
2005 // assume branch is more often taken than not (loops use backward branches)
2006 Label not_taken;
2007 if (cc == equal)
2008 __ cbnz(r0, not_taken);
2009 else
2010 __ cbz(r0, not_taken);
2011 branch(false, false);
2012 __ bind(not_taken);
2013 __ profile_not_taken_branch(r0);
2014 }
2015
2016 void TemplateTable::if_acmp(Condition cc) {
2017 transition(atos, vtos);
2018 // assume branch is more often taken than not (loops use backward branches)
2019 Label taken, not_taken;
2020 __ pop_ptr(r1);
2021
2022 __ profile_acmp(r2, r1, r0, r4);
2023
2024 Register is_inline_type_mask = rscratch1;
2025 __ mov(is_inline_type_mask, markWord::inline_type_pattern);
2026
2027 if (EnableValhalla) {
2028 __ cmp(r1, r0);
2029 __ br(Assembler::EQ, (cc == equal) ? taken : not_taken);
2030
2031 // might be substitutable, test if either r0 or r1 is null
2032 __ andr(r2, r0, r1);
2033 __ cbz(r2, (cc == equal) ? not_taken : taken);
2034
2035 // and both are values ?
2036 __ ldr(r2, Address(r1, oopDesc::mark_offset_in_bytes()));
2037 __ andr(r2, r2, is_inline_type_mask);
2038 __ ldr(r4, Address(r0, oopDesc::mark_offset_in_bytes()));
2039 __ andr(r4, r4, is_inline_type_mask);
2040 __ andr(r2, r2, r4);
2041 __ cmp(r2, is_inline_type_mask);
2042 __ br(Assembler::NE, (cc == equal) ? not_taken : taken);
2043
2044 // same value klass ?
2045 __ load_metadata(r2, r1);
2046 __ load_metadata(r4, r0);
2047 __ cmp(r2, r4);
2048 __ br(Assembler::NE, (cc == equal) ? not_taken : taken);
2049
2050 // Know both are the same type, let's test for substitutability...
2051 if (cc == equal) {
2052 invoke_is_substitutable(r0, r1, taken, not_taken);
2053 } else {
2054 invoke_is_substitutable(r0, r1, not_taken, taken);
2055 }
2056 __ stop("Not reachable");
2057 }
2058
2059 __ cmpoop(r1, r0);
2060 __ br(j_not(cc), not_taken);
2061 __ bind(taken);
2062 branch(false, false);
2063 __ bind(not_taken);
2064 __ profile_not_taken_branch(r0, true);
2065 }
2066
2067 void TemplateTable::invoke_is_substitutable(Register aobj, Register bobj,
2068 Label& is_subst, Label& not_subst) {
2069
2070 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::is_substitutable), aobj, bobj);
2071 // Restored... r0 answer, jmp to outcome...
2072 __ cbz(r0, not_subst);
2073 __ b(is_subst);
2074 }
2075
2076
2077 void TemplateTable::ret() {
2078 transition(vtos, vtos);
2079 locals_index(r1);
2080 __ ldr(r1, aaddress(r1)); // get return bci, compute return bcp
2081 __ profile_ret(r1, r2);
2082 __ ldr(rbcp, Address(rmethod, Method::const_offset()));
2083 __ lea(rbcp, Address(rbcp, r1));
2084 __ add(rbcp, rbcp, in_bytes(ConstMethod::codes_offset()));
2085 __ dispatch_next(vtos, 0, /*generate_poll*/true);
2086 }
2087
2088 void TemplateTable::wide_ret() {
2089 transition(vtos, vtos);
2090 locals_index_wide(r1);
2091 __ ldr(r1, aaddress(r1)); // get return bci, compute return bcp
2092 __ profile_ret(r1, r2);
2093 __ ldr(rbcp, Address(rmethod, Method::const_offset()));
2094 __ lea(rbcp, Address(rbcp, r1));
2095 __ add(rbcp, rbcp, in_bytes(ConstMethod::codes_offset()));
2096 __ dispatch_next(vtos, 0, /*generate_poll*/true);
2666 }
2667 // c_rarg1: object pointer or null
2668 // c_rarg2: cache entry pointer
2669 __ call_VM(noreg, CAST_FROM_FN_PTR(address,
2670 InterpreterRuntime::post_field_access),
2671 c_rarg1, c_rarg2);
2672 __ load_field_entry(cache, index);
2673 __ bind(L1);
2674 }
2675 }
2676
2677 void TemplateTable::pop_and_check_object(Register r)
2678 {
2679 __ pop_ptr(r);
2680 __ null_check(r); // for field access must check obj.
2681 __ verify_oop(r);
2682 }
2683
2684 void TemplateTable::getfield_or_static(int byte_no, bool is_static, RewriteControl rc)
2685 {
2686 const Register cache = r2;
2687 const Register obj = r4;
2688 const Register klass = r5;
2689 const Register inline_klass = r7;
2690 const Register field_index = r23;
2691 const Register index = r3;
2692 const Register tos_state = r3;
2693 const Register off = r19;
2694 const Register flags = r6;
2695 const Register bc = r4; // uses same reg as obj, so don't mix them
2696
2697 resolve_cache_and_index_for_field(byte_no, cache, index);
2698 jvmti_post_field_access(cache, index, is_static, false);
2699
2700 // Valhalla extras
2701 __ load_unsigned_short(field_index, Address(cache, in_bytes(ResolvedFieldEntry::field_index_offset())));
2702 __ ldr(klass, Address(cache, ResolvedFieldEntry::field_holder_offset()));
2703
2704 load_resolved_field_entry(obj, cache, tos_state, off, flags, is_static);
2705
2706 if (!is_static) {
2707 // obj is on the stack
2708 pop_and_check_object(obj);
2709 }
2710
2711 // 8179954: We need to make sure that the code generated for
2712 // volatile accesses forms a sequentially-consistent set of
2713 // operations when combined with STLR and LDAR. Without a leading
2714 // membar it's possible for a simple Dekker test to fail if loads
2715 // use LDR;DMB but stores use STLR. This can happen if C2 compiles
2716 // the stores in one method and we interpret the loads in another.
2717 if (!CompilerConfig::is_c1_or_interpreter_only_no_jvmci()){
2718 Label notVolatile;
2719 __ tbz(flags, ResolvedFieldEntry::is_volatile_shift, notVolatile);
2720 __ membar(MacroAssembler::AnyAny);
2721 __ bind(notVolatile);
2722 }
2723
2742 __ b(Done);
2743
2744 __ bind(notByte);
2745 __ cmp(tos_state, (u1)ztos);
2746 __ br(Assembler::NE, notBool);
2747
2748 // ztos (same code as btos)
2749 __ access_load_at(T_BOOLEAN, IN_HEAP, r0, field, noreg, noreg);
2750 __ push(ztos);
2751 // Rewrite bytecode to be faster
2752 if (rc == may_rewrite) {
2753 // use btos rewriting, no truncating to t/f bit is needed for getfield.
2754 patch_bytecode(Bytecodes::_fast_bgetfield, bc, r1);
2755 }
2756 __ b(Done);
2757
2758 __ bind(notBool);
2759 __ cmp(tos_state, (u1)atos);
2760 __ br(Assembler::NE, notObj);
2761 // atos
2762 if (!EnableValhalla) {
2763 do_oop_load(_masm, field, r0, IN_HEAP);
2764 __ push(atos);
2765 if (rc == may_rewrite) {
2766 patch_bytecode(Bytecodes::_fast_agetfield, bc, r1);
2767 }
2768 __ b(Done);
2769 } else { // Valhalla
2770 if (is_static) {
2771 __ load_heap_oop(r0, field, rscratch1, rscratch2);
2772 Label is_null_free_inline_type, uninitialized;
2773 // Issue below if the static field has not been initialized yet
2774 __ test_field_is_null_free_inline_type(flags, noreg /*temp*/, is_null_free_inline_type);
2775 // field is not a null free inline type
2776 __ push(atos);
2777 __ b(Done);
2778 // field is a null free inline type, must not return null even if uninitialized
2779 __ bind(is_null_free_inline_type);
2780 __ cbz(r0, uninitialized);
2781 __ push(atos);
2782 __ b(Done);
2783 __ bind(uninitialized);
2784 Label slow_case, finish;
2785 __ ldrb(rscratch1, Address(klass, InstanceKlass::init_state_offset()));
2786 __ cmp(rscratch1, (u1)InstanceKlass::fully_initialized);
2787 __ br(Assembler::NE, slow_case);
2788 __ get_default_value_oop(klass, off /* temp */, r0);
2789 __ b(finish);
2790 __ bind(slow_case);
2791 __ call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::uninitialized_static_inline_type_field), obj, cache);
2792 __ bind(finish);
2793 __ verify_oop(r0);
2794 __ push(atos);
2795 __ b(Done);
2796 } else {
2797 Label is_flat, nonnull, is_inline_type, has_null_marker, rewrite_inline;
2798 __ test_field_is_null_free_inline_type(flags, noreg /*temp*/, is_inline_type);
2799 __ test_field_has_null_marker(flags, noreg /*temp*/, has_null_marker);
2800 // Non-inline field case
2801 __ load_heap_oop(r0, field, rscratch1, rscratch2);
2802 __ push(atos);
2803 if (rc == may_rewrite) {
2804 patch_bytecode(Bytecodes::_fast_agetfield, bc, r1);
2805 }
2806 __ b(Done);
2807 __ bind(is_inline_type);
2808 __ test_field_is_flat(flags, noreg /* temp */, is_flat);
2809 // field is not flat
2810 __ load_heap_oop(r0, field, rscratch1, rscratch2);
2811 __ cbnz(r0, nonnull);
2812 __ get_inline_type_field_klass(klass, field_index, inline_klass);
2813 __ get_default_value_oop(inline_klass, klass /* temp */, r0);
2814 __ bind(nonnull);
2815 __ verify_oop(r0);
2816 __ push(atos);
2817 __ b(rewrite_inline);
2818 __ bind(is_flat);
2819 // field is flat
2820 __ mov(r0, obj);
2821 __ read_flat_field(cache, field_index, off, inline_klass /* temp */, r0);
2822 __ verify_oop(r0);
2823 __ push(atos);
2824 __ b(rewrite_inline);
2825 __ bind(has_null_marker);
2826 call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::read_nullable_flat_field), obj, cache);
2827 __ verify_oop(r0);
2828 __ push(atos);
2829 __ bind(rewrite_inline);
2830 if (rc == may_rewrite) {
2831 patch_bytecode(Bytecodes::_fast_vgetfield, bc, r1);
2832 }
2833 __ b(Done);
2834 }
2835 }
2836
2837 __ bind(notObj);
2838 __ cmp(tos_state, (u1)itos);
2839 __ br(Assembler::NE, notInt);
2840 // itos
2841 __ access_load_at(T_INT, IN_HEAP, r0, field, noreg, noreg);
2842 __ push(itos);
2843 // Rewrite bytecode to be faster
2844 if (rc == may_rewrite) {
2845 patch_bytecode(Bytecodes::_fast_igetfield, bc, r1);
2846 }
2847 __ b(Done);
2848
2849 __ bind(notInt);
2850 __ cmp(tos_state, (u1)ctos);
2851 __ br(Assembler::NE, notChar);
2852 // ctos
2853 __ access_load_at(T_CHAR, IN_HEAP, r0, field, noreg, noreg);
2854 __ push(ctos);
2855 // Rewrite bytecode to be faster
2976 // c_rarg1: object pointer set up above (null if static)
2977 // c_rarg2: cache entry pointer
2978 // c_rarg3: jvalue object on the stack
2979 __ call_VM(noreg,
2980 CAST_FROM_FN_PTR(address,
2981 InterpreterRuntime::post_field_modification),
2982 c_rarg1, c_rarg2, c_rarg3);
2983 __ load_field_entry(cache, index);
2984 __ bind(L1);
2985 }
2986 }
2987
2988 void TemplateTable::putfield_or_static(int byte_no, bool is_static, RewriteControl rc) {
2989 transition(vtos, vtos);
2990
2991 const Register cache = r2;
2992 const Register index = r3;
2993 const Register tos_state = r3;
2994 const Register obj = r2;
2995 const Register off = r19;
2996 const Register flags = r6;
2997 const Register bc = r4;
2998 const Register inline_klass = r5;
2999
3000 resolve_cache_and_index_for_field(byte_no, cache, index);
3001 jvmti_post_field_mod(cache, index, is_static);
3002 load_resolved_field_entry(obj, cache, tos_state, off, flags, is_static);
3003
3004 Label Done;
3005 {
3006 Label notVolatile;
3007 __ tbz(flags, ResolvedFieldEntry::is_volatile_shift, notVolatile);
3008 __ membar(MacroAssembler::StoreStore | MacroAssembler::LoadStore);
3009 __ bind(notVolatile);
3010 }
3011
3012 // field address
3013 const Address field(obj, off);
3014
3015 Label notByte, notBool, notInt, notShort, notChar,
3016 notLong, notFloat, notObj, notDouble;
3017
3018 assert(btos == 0, "change code, btos != 0");
3019 __ cbnz(tos_state, notByte);
3020
3021 // Don't rewrite putstatic, only putfield
3022 if (is_static) rc = may_not_rewrite;
3023
3024 // btos
3025 {
3026 __ pop(btos);
3027 if (!is_static) pop_and_check_object(obj);
3036 __ cmp(tos_state, (u1)ztos);
3037 __ br(Assembler::NE, notBool);
3038
3039 // ztos
3040 {
3041 __ pop(ztos);
3042 if (!is_static) pop_and_check_object(obj);
3043 __ access_store_at(T_BOOLEAN, IN_HEAP, field, r0, noreg, noreg, noreg);
3044 if (rc == may_rewrite) {
3045 patch_bytecode(Bytecodes::_fast_zputfield, bc, r1, true, byte_no);
3046 }
3047 __ b(Done);
3048 }
3049
3050 __ bind(notBool);
3051 __ cmp(tos_state, (u1)atos);
3052 __ br(Assembler::NE, notObj);
3053
3054 // atos
3055 {
3056 if (!EnableValhalla) {
3057 __ pop(atos);
3058 if (!is_static) pop_and_check_object(obj);
3059 // Store into the field
3060 do_oop_store(_masm, field, r0, IN_HEAP);
3061 if (rc == may_rewrite) {
3062 patch_bytecode(Bytecodes::_fast_aputfield, bc, r1, true, byte_no);
3063 }
3064 __ b(Done);
3065 } else { // Valhalla
3066 __ pop(atos);
3067 if (is_static) {
3068 Label is_inline_type;
3069 __ test_field_is_not_null_free_inline_type(flags, noreg /* temp */, is_inline_type);
3070 __ null_check(r0);
3071 __ bind(is_inline_type);
3072 do_oop_store(_masm, field, r0, IN_HEAP);
3073 __ b(Done);
3074 } else {
3075 Label is_inline_type, is_flat, has_null_marker, rewrite_not_inline, rewrite_inline;
3076 __ test_field_is_null_free_inline_type(flags, noreg /*temp*/, is_inline_type);
3077 __ test_field_has_null_marker(flags, noreg /*temp*/, has_null_marker);
3078 // Not an inline type
3079 pop_and_check_object(obj);
3080 // Store into the field
3081 do_oop_store(_masm, field, r0, IN_HEAP);
3082 __ bind(rewrite_not_inline);
3083 if (rc == may_rewrite) {
3084 patch_bytecode(Bytecodes::_fast_aputfield, bc, r19, true, byte_no);
3085 }
3086 __ b(Done);
3087 // Implementation of the inline type semantic
3088 __ bind(is_inline_type);
3089 __ null_check(r0);
3090 __ test_field_is_flat(flags, noreg /*temp*/, is_flat);
3091 // field is not flat
3092 pop_and_check_object(obj);
3093 // Store into the field
3094 do_oop_store(_masm, field, r0, IN_HEAP);
3095 __ b(rewrite_inline);
3096 __ bind(is_flat);
3097 __ load_field_entry(cache, index); // reload field entry (cache) because it was erased by tos_state
3098 __ load_unsigned_short(index, Address(cache, in_bytes(ResolvedFieldEntry::field_index_offset())));
3099 __ ldr(r2, Address(cache, in_bytes(ResolvedFieldEntry::field_holder_offset())));
3100 __ inline_layout_info(r2, index, r6);
3101 pop_and_check_object(obj);
3102 __ load_klass(inline_klass, r0);
3103 __ data_for_oop(r0, r0, inline_klass);
3104 __ add(obj, obj, off);
3105 // because we use InlineLayoutInfo, we need special value access code specialized for fields (arrays will need a different API)
3106 __ flat_field_copy(IN_HEAP, r0, obj, r6);
3107 __ b(rewrite_inline);
3108 __ bind(has_null_marker);
3109 assert_different_registers(r0, cache, r19);
3110 pop_and_check_object(r19);
3111 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::write_nullable_flat_field), r19, r0, cache);
3112 __ bind(rewrite_inline);
3113 if (rc == may_rewrite) {
3114 patch_bytecode(Bytecodes::_fast_vputfield, bc, r19, true, byte_no);
3115 }
3116 __ b(Done);
3117 }
3118 } // Valhalla
3119 }
3120
3121 __ bind(notObj);
3122 __ cmp(tos_state, (u1)itos);
3123 __ br(Assembler::NE, notInt);
3124
3125 // itos
3126 {
3127 __ pop(itos);
3128 if (!is_static) pop_and_check_object(obj);
3129 __ access_store_at(T_INT, IN_HEAP, field, r0, noreg, noreg, noreg);
3130 if (rc == may_rewrite) {
3131 patch_bytecode(Bytecodes::_fast_iputfield, bc, r1, true, byte_no);
3132 }
3133 __ b(Done);
3134 }
3135
3136 __ bind(notInt);
3137 __ cmp(tos_state, (u1)ctos);
3138 __ br(Assembler::NE, notChar);
3203 {
3204 __ pop(dtos);
3205 if (!is_static) pop_and_check_object(obj);
3206 __ access_store_at(T_DOUBLE, IN_HEAP, field, noreg /* dtos */, noreg, noreg, noreg);
3207 if (rc == may_rewrite) {
3208 patch_bytecode(Bytecodes::_fast_dputfield, bc, r1, true, byte_no);
3209 }
3210 }
3211
3212 #ifdef ASSERT
3213 __ b(Done);
3214
3215 __ bind(notDouble);
3216 __ stop("Bad state");
3217 #endif
3218
3219 __ bind(Done);
3220
3221 {
3222 Label notVolatile;
3223 __ tbz(flags, ResolvedFieldEntry::is_volatile_shift, notVolatile);
3224 __ membar(MacroAssembler::StoreLoad | MacroAssembler::StoreStore);
3225 __ bind(notVolatile);
3226 }
3227 }
3228
3229 void TemplateTable::putfield(int byte_no)
3230 {
3231 putfield_or_static(byte_no, false);
3232 }
3233
3234 void TemplateTable::nofast_putfield(int byte_no) {
3235 putfield_or_static(byte_no, false, may_not_rewrite);
3236 }
3237
3238 void TemplateTable::putstatic(int byte_no) {
3239 putfield_or_static(byte_no, true);
3240 }
3241
3242 void TemplateTable::jvmti_post_fast_field_mod() {
3243 if (JvmtiExport::can_post_field_modification()) {
3244 // Check to see if a field modification watch has been set before
3245 // we take the time to call into the VM.
3246 Label L2;
3247 __ lea(rscratch1, ExternalAddress((address)JvmtiExport::get_field_modification_count_addr()));
3248 __ ldrw(c_rarg3, Address(rscratch1));
3249 __ cbzw(c_rarg3, L2);
3250 __ pop_ptr(r19); // copy the object pointer from tos
3251 __ verify_oop(r19);
3252 __ push_ptr(r19); // put the object pointer back on tos
3253 // Save tos values before call_VM() clobbers them. Since we have
3254 // to do it for every data type, we use the saved values as the
3255 // jvalue object.
3256 switch (bytecode()) { // load values into the jvalue object
3257 case Bytecodes::_fast_vputfield: //fall through
3258 case Bytecodes::_fast_aputfield: __ push_ptr(r0); break;
3259 case Bytecodes::_fast_bputfield: // fall through
3260 case Bytecodes::_fast_zputfield: // fall through
3261 case Bytecodes::_fast_sputfield: // fall through
3262 case Bytecodes::_fast_cputfield: // fall through
3263 case Bytecodes::_fast_iputfield: __ push_i(r0); break;
3264 case Bytecodes::_fast_dputfield: __ push_d(); break;
3265 case Bytecodes::_fast_fputfield: __ push_f(); break;
3266 case Bytecodes::_fast_lputfield: __ push_l(r0); break;
3267
3268 default:
3269 ShouldNotReachHere();
3270 }
3271 __ mov(c_rarg3, esp); // points to jvalue on the stack
3272 // access constant pool cache entry
3273 __ load_field_entry(c_rarg2, r0);
3274 __ verify_oop(r19);
3275 // r19: object pointer copied above
3276 // c_rarg2: cache entry pointer
3277 // c_rarg3: jvalue object on the stack
3278 __ call_VM(noreg,
3279 CAST_FROM_FN_PTR(address,
3280 InterpreterRuntime::post_field_modification),
3281 r19, c_rarg2, c_rarg3);
3282
3283 switch (bytecode()) { // restore tos values
3284 case Bytecodes::_fast_vputfield: //fall through
3285 case Bytecodes::_fast_aputfield: __ pop_ptr(r0); break;
3286 case Bytecodes::_fast_bputfield: // fall through
3287 case Bytecodes::_fast_zputfield: // fall through
3288 case Bytecodes::_fast_sputfield: // fall through
3289 case Bytecodes::_fast_cputfield: // fall through
3290 case Bytecodes::_fast_iputfield: __ pop_i(r0); break;
3291 case Bytecodes::_fast_dputfield: __ pop_d(); break;
3292 case Bytecodes::_fast_fputfield: __ pop_f(); break;
3293 case Bytecodes::_fast_lputfield: __ pop_l(r0); break;
3294 default: break;
3295 }
3296 __ bind(L2);
3297 }
3298 }
3299
3300 void TemplateTable::fast_storefield(TosState state)
3301 {
3302 transition(state, vtos);
3303
3304 ByteSize base = ConstantPoolCache::base_offset();
3311 // R1: field offset, R2: field holder, R3: flags
3312 load_resolved_field_entry(r2, r2, noreg, r1, r3);
3313
3314 {
3315 Label notVolatile;
3316 __ tbz(r3, ResolvedFieldEntry::is_volatile_shift, notVolatile);
3317 __ membar(MacroAssembler::StoreStore | MacroAssembler::LoadStore);
3318 __ bind(notVolatile);
3319 }
3320
3321 Label notVolatile;
3322
3323 // Get object from stack
3324 pop_and_check_object(r2);
3325
3326 // field address
3327 const Address field(r2, r1);
3328
3329 // access field
3330 switch (bytecode()) {
3331 case Bytecodes::_fast_vputfield:
3332 {
3333 Label is_flat, has_null_marker, done;
3334 __ test_field_has_null_marker(r3, noreg /* temp */, has_null_marker);
3335 __ null_check(r0);
3336 __ test_field_is_flat(r3, noreg /* temp */, is_flat);
3337 // field is not flat
3338 do_oop_store(_masm, field, r0, IN_HEAP);
3339 __ b(done);
3340 __ bind(is_flat);
3341 // field is flat
3342 __ load_field_entry(r4, r3);
3343 __ load_unsigned_short(r3, Address(r4, in_bytes(ResolvedFieldEntry::field_index_offset())));
3344 __ ldr(r4, Address(r4, in_bytes(ResolvedFieldEntry::field_holder_offset())));
3345 __ inline_layout_info(r4, r3, r5);
3346 __ load_klass(r4, r0);
3347 __ data_for_oop(r0, r0, r4);
3348 __ lea(rscratch1, field);
3349 __ flat_field_copy(IN_HEAP, r0, rscratch1, r5);
3350 __ b(done);
3351 __ bind(has_null_marker);
3352 __ load_field_entry(r4, r1);
3353 __ mov(r1, r2);
3354 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::write_nullable_flat_field), r1, r0, r4);
3355 __ bind(done);
3356 }
3357 break;
3358 case Bytecodes::_fast_aputfield:
3359 do_oop_store(_masm, field, r0, IN_HEAP);
3360 break;
3361 case Bytecodes::_fast_lputfield:
3362 __ access_store_at(T_LONG, IN_HEAP, field, r0, noreg, noreg, noreg);
3363 break;
3364 case Bytecodes::_fast_iputfield:
3365 __ access_store_at(T_INT, IN_HEAP, field, r0, noreg, noreg, noreg);
3366 break;
3367 case Bytecodes::_fast_zputfield:
3368 __ access_store_at(T_BOOLEAN, IN_HEAP, field, r0, noreg, noreg, noreg);
3369 break;
3370 case Bytecodes::_fast_bputfield:
3371 __ access_store_at(T_BYTE, IN_HEAP, field, r0, noreg, noreg, noreg);
3372 break;
3373 case Bytecodes::_fast_sputfield:
3374 __ access_store_at(T_SHORT, IN_HEAP, field, r0, noreg, noreg, noreg);
3375 break;
3376 case Bytecodes::_fast_cputfield:
3377 __ access_store_at(T_CHAR, IN_HEAP, field, r0, noreg, noreg, noreg);
3430 // r0: object
3431 __ verify_oop(r0);
3432 __ null_check(r0);
3433 const Address field(r0, r1);
3434
3435 // 8179954: We need to make sure that the code generated for
3436 // volatile accesses forms a sequentially-consistent set of
3437 // operations when combined with STLR and LDAR. Without a leading
3438 // membar it's possible for a simple Dekker test to fail if loads
3439 // use LDR;DMB but stores use STLR. This can happen if C2 compiles
3440 // the stores in one method and we interpret the loads in another.
3441 if (!CompilerConfig::is_c1_or_interpreter_only_no_jvmci()) {
3442 Label notVolatile;
3443 __ tbz(r3, ResolvedFieldEntry::is_volatile_shift, notVolatile);
3444 __ membar(MacroAssembler::AnyAny);
3445 __ bind(notVolatile);
3446 }
3447
3448 // access field
3449 switch (bytecode()) {
3450 case Bytecodes::_fast_vgetfield:
3451 {
3452 Register index = r4, klass = r5, inline_klass = r6, tmp = r7;
3453 Label is_flat, has_null_marker, nonnull, Done;
3454 __ test_field_has_null_marker(r3, noreg /*temp*/, has_null_marker);
3455 __ test_field_is_flat(r3, noreg /* temp */, is_flat);
3456 // field is not flat
3457 __ load_heap_oop(r0, field, rscratch1, rscratch2);
3458 __ cbnz(r0, nonnull);
3459 __ load_unsigned_short(index, Address(r2, in_bytes(ResolvedFieldEntry::field_index_offset())));
3460 __ ldr(klass, Address(r2, in_bytes(ResolvedFieldEntry::field_holder_offset())));
3461 __ get_inline_type_field_klass(klass, index, inline_klass);
3462 __ get_default_value_oop(inline_klass, tmp /* temp */, r0);
3463 __ bind(nonnull);
3464 __ verify_oop(r0);
3465 __ b(Done);
3466 __ bind(is_flat);
3467 // field is flat
3468 __ load_unsigned_short(index, Address(r2, in_bytes(ResolvedFieldEntry::field_index_offset())));
3469 __ read_flat_field(r2, index, r1, tmp /* temp */, r0);
3470 __ verify_oop(r0);
3471 __ b(Done);
3472 __ bind(has_null_marker);
3473 call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::read_nullable_flat_field), r0, r2);
3474 __ verify_oop(r0);
3475 __ bind(Done);
3476 }
3477 break;
3478 case Bytecodes::_fast_agetfield:
3479 do_oop_load(_masm, field, r0, IN_HEAP);
3480 __ verify_oop(r0);
3481 break;
3482 case Bytecodes::_fast_lgetfield:
3483 __ access_load_at(T_LONG, IN_HEAP, r0, field, noreg, noreg);
3484 break;
3485 case Bytecodes::_fast_igetfield:
3486 __ access_load_at(T_INT, IN_HEAP, r0, field, noreg, noreg);
3487 break;
3488 case Bytecodes::_fast_bgetfield:
3489 __ access_load_at(T_BYTE, IN_HEAP, r0, field, noreg, noreg);
3490 break;
3491 case Bytecodes::_fast_sgetfield:
3492 __ access_load_at(T_SHORT, IN_HEAP, r0, field, noreg, noreg);
3493 break;
3494 case Bytecodes::_fast_cgetfield:
3495 __ access_load_at(T_CHAR, IN_HEAP, r0, field, noreg, noreg);
3496 break;
3497 case Bytecodes::_fast_fgetfield:
3876 Label initialize_header;
3877
3878 __ get_cpool_and_tags(r4, r0);
3879 // Make sure the class we're about to instantiate has been resolved.
3880 // This is done before loading InstanceKlass to be consistent with the order
3881 // how Constant Pool is updated (see ConstantPool::klass_at_put)
3882 const int tags_offset = Array<u1>::base_offset_in_bytes();
3883 __ lea(rscratch1, Address(r0, r3, Address::lsl(0)));
3884 __ lea(rscratch1, Address(rscratch1, tags_offset));
3885 __ ldarb(rscratch1, rscratch1);
3886 __ cmp(rscratch1, (u1)JVM_CONSTANT_Class);
3887 __ br(Assembler::NE, slow_case);
3888
3889 // get InstanceKlass
3890 __ load_resolved_klass_at_offset(r4, r3, r4, rscratch1);
3891
3892 // make sure klass is initialized
3893 assert(VM_Version::supports_fast_class_init_checks(), "Optimization requires support for fast class initialization checks");
3894 __ clinit_barrier(r4, rscratch1, nullptr /*L_fast_path*/, &slow_case);
3895
3896 __ allocate_instance(r4, r0, r3, r1, true, slow_case);
3897 if (DTraceAllocProbes) {
3898 // Trigger dtrace event for fastpath
3899 __ push(atos); // save the return value
3900 __ call_VM_leaf(
3901 CAST_FROM_FN_PTR(address, static_cast<int (*)(oopDesc*)>(SharedRuntime::dtrace_object_alloc)), r0);
3902 __ pop(atos); // restore the return value
3903
3904 }
3905 __ b(done);
3906
3907 // slow case
3908 __ bind(slow_case);
3909 __ get_constant_pool(c_rarg1);
3910 __ get_unsigned_2_byte_index_at_bcp(c_rarg2, 1);
3911 call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), c_rarg1, c_rarg2);
3912 __ verify_oop(r0);
3913
3914 // continue
3915 __ bind(done);
3916 // Must prevent reordering of stores for object initialization with stores that publish the new object.
3917 __ membar(Assembler::StoreStore);
3918 }
3919
3920 void TemplateTable::newarray() {
3921 transition(itos, atos);
3922 __ load_unsigned_byte(c_rarg1, at_bcp(1));
3923 __ mov(c_rarg2, r0);
3924 call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::newarray),
3925 c_rarg1, c_rarg2);
3970 __ bind(quicked);
3971 __ mov(r3, r0); // Save object in r3; r0 needed for subtype check
3972 __ load_resolved_klass_at_offset(r2, r19, r0, rscratch1); // r0 = klass
3973
3974 __ bind(resolved);
3975 __ load_klass(r19, r3);
3976
3977 // Generate subtype check. Blows r2, r5. Object in r3.
3978 // Superklass in r0. Subklass in r19.
3979 __ gen_subtype_check(r19, ok_is_subtype);
3980
3981 // Come here on failure
3982 __ push(r3);
3983 // object is at TOS
3984 __ b(Interpreter::_throw_ClassCastException_entry);
3985
3986 // Come here on success
3987 __ bind(ok_is_subtype);
3988 __ mov(r0, r3); // Restore object in r3
3989
3990 __ b(done);
3991 __ bind(is_null);
3992
3993 // Collect counts on whether this test sees nulls a lot or not.
3994 if (ProfileInterpreter) {
3995 __ profile_null_seen(r2);
3996 }
3997
3998 __ bind(done);
3999 }
4000
4001 void TemplateTable::instanceof() {
4002 transition(atos, itos);
4003 Label done, is_null, ok_is_subtype, quicked, resolved;
4004 __ cbz(r0, is_null);
4005
4006 // Get cpool & tags index
4007 __ get_cpool_and_tags(r2, r3); // r2=cpool, r3=tags array
4008 __ get_unsigned_2_byte_index_at_bcp(r19, 1); // r19=index
4009 // See if bytecode has already been quicked
4010 __ add(rscratch1, r3, Array<u1>::base_offset_in_bytes());
4011 __ lea(r1, Address(rscratch1, r19));
4012 __ ldarb(r1, r1);
4013 __ cmp(r1, (u1)JVM_CONSTANT_Class);
4014 __ br(Assembler::EQ, quicked);
4015
4016 __ push(atos); // save receiver for result, and for GC
4017 call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc));
4096 // in the assembly code structure as well
4097 //
4098 // Stack layout:
4099 //
4100 // [expressions ] <--- esp = expression stack top
4101 // ..
4102 // [expressions ]
4103 // [monitor entry] <--- monitor block top = expression stack bot
4104 // ..
4105 // [monitor entry]
4106 // [frame data ] <--- monitor block bot
4107 // ...
4108 // [saved rfp ] <--- rfp
4109 void TemplateTable::monitorenter()
4110 {
4111 transition(atos, vtos);
4112
4113 // check for null object
4114 __ null_check(r0);
4115
4116 Label is_inline_type;
4117 __ ldr(rscratch1, Address(r0, oopDesc::mark_offset_in_bytes()));
4118 __ test_markword_is_inline_type(rscratch1, is_inline_type);
4119
4120 const Address monitor_block_top(
4121 rfp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
4122 const Address monitor_block_bot(
4123 rfp, frame::interpreter_frame_initial_sp_offset * wordSize);
4124 const int entry_size = frame::interpreter_frame_monitor_size_in_bytes();
4125
4126 Label allocated;
4127
4128 // initialize entry pointer
4129 __ mov(c_rarg1, zr); // points to free slot or null
4130
4131 // find a free slot in the monitor block (result in c_rarg1)
4132 {
4133 Label entry, loop, exit;
4134 __ ldr(c_rarg3, monitor_block_top); // derelativize pointer
4135 __ lea(c_rarg3, Address(rfp, c_rarg3, Address::lsl(Interpreter::logStackElementSize)));
4136 // c_rarg3 points to current entry, starting with top-most entry
4137
4138 __ lea(c_rarg2, monitor_block_bot); // points to word before bottom
4139
4201 // c_rarg1: points to monitor entry
4202 __ bind(allocated);
4203
4204 // Increment bcp to point to the next bytecode, so exception
4205 // handling for async. exceptions work correctly.
4206 // The object has already been popped from the stack, so the
4207 // expression stack looks correct.
4208 __ increment(rbcp);
4209
4210 // store object
4211 __ str(r0, Address(c_rarg1, BasicObjectLock::obj_offset()));
4212 __ lock_object(c_rarg1);
4213
4214 // check to make sure this monitor doesn't cause stack overflow after locking
4215 __ save_bcp(); // in case of exception
4216 __ generate_stack_overflow_check(0);
4217
4218 // The bcp has already been incremented. Just need to dispatch to
4219 // next instruction.
4220 __ dispatch_next(vtos);
4221
4222 __ bind(is_inline_type);
4223 __ call_VM(noreg, CAST_FROM_FN_PTR(address,
4224 InterpreterRuntime::throw_identity_exception), r0);
4225 __ should_not_reach_here();
4226 }
4227
4228
4229 void TemplateTable::monitorexit()
4230 {
4231 transition(atos, vtos);
4232
4233 // check for null object
4234 __ null_check(r0);
4235
4236 const int is_inline_type_mask = markWord::inline_type_pattern;
4237 Label has_identity;
4238 __ ldr(rscratch1, Address(r0, oopDesc::mark_offset_in_bytes()));
4239 __ mov(rscratch2, is_inline_type_mask);
4240 __ andr(rscratch1, rscratch1, rscratch2);
4241 __ cmp(rscratch1, rscratch2);
4242 __ br(Assembler::NE, has_identity);
4243 __ call_VM(noreg, CAST_FROM_FN_PTR(address,
4244 InterpreterRuntime::throw_illegal_monitor_state_exception));
4245 __ should_not_reach_here();
4246 __ bind(has_identity);
4247
4248 const Address monitor_block_top(
4249 rfp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
4250 const Address monitor_block_bot(
4251 rfp, frame::interpreter_frame_initial_sp_offset * wordSize);
4252 const int entry_size = frame::interpreter_frame_monitor_size_in_bytes();
4253
4254 Label found;
4255
4256 // find matching slot
4257 {
4258 Label entry, loop;
4259 __ ldr(c_rarg1, monitor_block_top); // derelativize pointer
4260 __ lea(c_rarg1, Address(rfp, c_rarg1, Address::lsl(Interpreter::logStackElementSize)));
4261 // c_rarg1 points to current entry, starting with top-most entry
4262
4263 __ lea(c_rarg2, monitor_block_bot); // points to word before bottom
4264 // of monitor block
4265 __ b(entry);
4266
4267 __ bind(loop);
|