26
27 #include "asm/macroAssembler.inline.hpp"
28 #include "compiler/disassembler.hpp"
29 #include "gc/shared/barrierSetAssembler.hpp"
30 #include "gc/shared/collectedHeap.hpp"
31 #include "gc/shared/tlab_globals.hpp"
32 #include "interpreter/interp_masm.hpp"
33 #include "interpreter/interpreter.hpp"
34 #include "interpreter/interpreterRuntime.hpp"
35 #include "interpreter/templateTable.hpp"
36 #include "memory/universe.hpp"
37 #include "oops/method.inline.hpp"
38 #include "oops/methodData.hpp"
39 #include "oops/objArrayKlass.hpp"
40 #include "oops/oop.inline.hpp"
41 #include "oops/resolvedFieldEntry.hpp"
42 #include "oops/resolvedIndyEntry.hpp"
43 #include "oops/resolvedMethodEntry.hpp"
44 #include "prims/jvmtiExport.hpp"
45 #include "prims/methodHandles.hpp"
46 #include "runtime/frame.inline.hpp"
47 #include "runtime/sharedRuntime.hpp"
48 #include "runtime/stubRoutines.hpp"
49 #include "runtime/synchronizer.hpp"
50 #include "utilities/powerOfTwo.hpp"
51
52 #define __ Disassembler::hook<InterpreterMacroAssembler>(__FILE__, __LINE__, _masm)->
53
54 // Address computation: local variables
55
56 static inline Address iaddress(int n) {
57 return Address(xlocals, Interpreter::local_offset_in_bytes(n));
58 }
59
60 static inline Address laddress(int n) {
61 return iaddress(n + 1);
62 }
63
64 static inline Address faddress(int n) {
65 return iaddress(n);
121 return Address(esp, Interpreter::expr_offset_in_bytes(4));
122 }
123
124 static inline Address at_tos_p5() {
125 return Address(esp, Interpreter::expr_offset_in_bytes(5));
126 }
127
128 Address TemplateTable::at_bcp(int offset) {
129 assert(_desc->uses_bcp(), "inconsistent uses_bcp information");
130 return Address(xbcp, offset);
131 }
132
133 void TemplateTable::patch_bytecode(Bytecodes::Code bc, Register bc_reg,
134 Register temp_reg, bool load_bc_into_bc_reg /*=true*/,
135 int byte_no) {
136 assert_different_registers(bc_reg, temp_reg);
137 if (!RewriteBytecodes) { return; }
138 Label L_patch_done;
139
140 switch (bc) {
141 case Bytecodes::_fast_aputfield: // fall through
142 case Bytecodes::_fast_bputfield: // fall through
143 case Bytecodes::_fast_zputfield: // fall through
144 case Bytecodes::_fast_cputfield: // fall through
145 case Bytecodes::_fast_dputfield: // fall through
146 case Bytecodes::_fast_fputfield: // fall through
147 case Bytecodes::_fast_iputfield: // fall through
148 case Bytecodes::_fast_lputfield: // fall through
149 case Bytecodes::_fast_sputfield: {
150 // We skip bytecode quickening for putfield instructions when
151 // the put_code written to the constant pool cache is zero.
152 // This is required so that every execution of this instruction
153 // calls out to InterpreterRuntime::resolve_get_put to do
154 // additional, required work.
155 assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
156 assert(load_bc_into_bc_reg, "we use bc_reg as temp");
157 __ load_field_entry(temp_reg, bc_reg);
158 if (byte_no == f1_byte) {
159 __ la(temp_reg, Address(temp_reg, in_bytes(ResolvedFieldEntry::get_code_offset())));
160 } else {
754
755 void TemplateTable::daload() {
756 transition(itos, dtos);
757 __ mv(x11, x10);
758 __ pop_ptr(x10);
759 // x10: array
760 // x11: index
761 index_check(x10, x11); // leaves index in x11
762 __ addi(x11, x11, arrayOopDesc::base_offset_in_bytes(T_DOUBLE) >> 3);
763 __ shadd(x10, x11, x10, t0, 3);
764 __ access_load_at(T_DOUBLE, IN_HEAP | IS_ARRAY, x10, Address(x10), noreg, noreg);
765 }
766
767 void TemplateTable::aaload() {
768 transition(itos, atos);
769 __ mv(x11, x10);
770 __ pop_ptr(x10);
771 // x10: array
772 // x11: index
773 index_check(x10, x11); // leaves index in x11
774 __ addi(x11, x11, arrayOopDesc::base_offset_in_bytes(T_OBJECT) >> LogBytesPerHeapOop);
775 __ shadd(x10, x11, x10, t0, LogBytesPerHeapOop);
776 __ load_heap_oop(x10, Address(x10), x28, x29, IS_ARRAY);
777 }
778
779 void TemplateTable::baload() {
780 transition(itos, itos);
781 __ mv(x11, x10);
782 __ pop_ptr(x10);
783 // x10: array
784 // x11: index
785 index_check(x10, x11); // leaves index in x11
786 __ addi(x11, x11, arrayOopDesc::base_offset_in_bytes(T_BYTE) >> 0);
787 __ shadd(x10, x11, x10, t0, 0);
788 __ access_load_at(T_BYTE, IN_HEAP | IS_ARRAY, x10, Address(x10), noreg, noreg);
789 }
790
791 void TemplateTable::caload() {
792 transition(itos, itos);
793 __ mv(x11, x10);
794 __ pop_ptr(x10);
795 // x10: array
796 // x11: index
1030 index_check(x13, x11); // prefer index in x11
1031 __ addi(x11, x11, arrayOopDesc::base_offset_in_bytes(T_FLOAT) >> 2);
1032 __ shadd(t0, x11, x13, t0, 2);
1033 __ access_store_at(T_FLOAT, IN_HEAP | IS_ARRAY, Address(t0, 0), noreg /* ftos */, noreg, noreg, noreg);
1034 }
1035
1036 void TemplateTable::dastore() {
1037 transition(dtos, vtos);
1038 __ pop_i(x11);
1039 __ pop_ptr(x13);
1040 // f10: value
1041 // x11: index
1042 // x13: array
1043 index_check(x13, x11); // prefer index in x11
1044 __ addi(x11, x11, arrayOopDesc::base_offset_in_bytes(T_DOUBLE) >> 3);
1045 __ shadd(t0, x11, x13, t0, 3);
1046 __ access_store_at(T_DOUBLE, IN_HEAP | IS_ARRAY, Address(t0, 0), noreg /* dtos */, noreg, noreg, noreg);
1047 }
1048
1049 void TemplateTable::aastore() {
1050 Label is_null, ok_is_subtype, done;
1051 transition(vtos, vtos);
1052 // stack: ..., array, index, value
1053 __ ld(x10, at_tos()); // value
1054 __ lw(x12, at_tos_p1()); // index
1055 __ ld(x13, at_tos_p2()); // array
1056
1057 index_check(x13, x12); // kills x11
1058 __ addi(x14, x12, arrayOopDesc::base_offset_in_bytes(T_OBJECT) >> LogBytesPerHeapOop);
1059 __ shadd(x14, x14, x13, x14, LogBytesPerHeapOop);
1060
1061 Address element_address(x14, 0);
1062
1063 // do array store check - check for null value first
1064 __ beqz(x10, is_null);
1065
1066 // Move subklass into x11
1067 __ load_klass(x11, x10);
1068 // Move superklass into x10
1069 __ load_klass(x10, x13);
1070 __ ld(x10, Address(x10,
1071 ObjArrayKlass::element_klass_offset()));
1072 // Compress array + index * oopSize + 12 into a single register. Frees x12.
1073
1074 // Generate subtype check. Blows x12, x15
1075 // Superklass in x10. Subklass in x11.
1076 __ gen_subtype_check(x11, ok_is_subtype);
1077
1078 // Come here on failure
1079 // object is at TOS
1080 __ j(RuntimeAddress(Interpreter::_throw_ArrayStoreException_entry));
1081
1082 // Come here on success
1083 __ bind(ok_is_subtype);
1084
1085 // Get the value we will store
1086 __ ld(x10, at_tos());
1087 // Now store using the appropriate barrier
1088 __ store_heap_oop(element_address, x10, x28, x29, x13, IS_ARRAY);
1089 __ j(done);
1090
1091 // Have a null in x10, x13=array, x12=index. Store null at ary[idx]
1092 __ bind(is_null);
1093 __ profile_null_seen(x12);
1094
1095 // Store a null
1096 __ store_heap_oop(element_address, noreg, x28, x29, x13, IS_ARRAY);
1097
1098 // Pop stack arguments
1099 __ bind(done);
1100 __ addi(esp, esp, 3 * Interpreter::stackElementSize);
1101 }
1102
1103 void TemplateTable::bastore() {
1104 transition(itos, vtos);
1105 __ pop_i(x11);
1106 __ pop_ptr(x13);
1107 // x10: value
1108 // x11: index
1109 // x13: array
1110 index_check(x13, x11); // prefer index in x11
1111
1112 // Need to check whether array is boolean or byte
1113 // since both types share the bastore bytecode.
1114 __ load_klass(x12, x13);
1115 __ lwu(x12, Address(x12, Klass::layout_helper_offset()));
1116 Label L_skip;
1833 __ profile_not_taken_branch(x10);
1834 }
1835
1836 void TemplateTable::if_nullcmp(Condition cc) {
1837 transition(atos, vtos);
1838 // assume branch is more often taken than not (loops use backward branches)
1839 Label not_taken;
1840 if (cc == equal) {
1841 __ bnez(x10, not_taken);
1842 } else {
1843 __ beqz(x10, not_taken);
1844 }
1845 branch(false, false);
1846 __ bind(not_taken);
1847 __ profile_not_taken_branch(x10);
1848 }
1849
1850 void TemplateTable::if_acmp(Condition cc) {
1851 transition(atos, vtos);
1852 // assume branch is more often taken than not (loops use backward branches)
1853 Label not_taken;
1854 __ pop_ptr(x11);
1855
1856 if (cc == equal) {
1857 __ bne(x11, x10, not_taken);
1858 } else if (cc == not_equal) {
1859 __ beq(x11, x10, not_taken);
1860 }
1861 branch(false, false);
1862 __ bind(not_taken);
1863 __ profile_not_taken_branch(x10);
1864 }
1865
1866 void TemplateTable::ret() {
1867 transition(vtos, vtos);
1868 locals_index(x11);
1869 __ ld(x11, aaddress(x11, t1, _masm)); // get return bci, compute return bcp
1870 __ profile_ret(x11, x12);
1871 __ ld(xbcp, Address(xmethod, Method::const_offset()));
1872 __ add(xbcp, xbcp, x11);
1873 __ add(xbcp, xbcp, in_bytes(ConstMethod::codes_offset()));
1874 __ dispatch_next(vtos, 0, /*generate_poll*/true);
1875 }
1876
1877 void TemplateTable::wide_ret() {
1878 transition(vtos, vtos);
1879 locals_index_wide(x11);
1880 __ ld(x11, aaddress(x11, t0, _masm)); // get return bci, compute return bcp
1881 __ profile_ret(x11, x12);
1882 __ ld(xbcp, Address(xmethod, Method::const_offset()));
1883 __ add(xbcp, xbcp, x11);
2090 "inconsistent calls_vm information"); // call in remove_activation
2091
2092 if (_desc->bytecode() == Bytecodes::_return_register_finalizer) {
2093 assert(state == vtos, "only valid state");
2094
2095 __ ld(c_rarg1, aaddress(0));
2096 __ load_klass(x13, c_rarg1);
2097 __ lbu(x13, Address(x13, Klass::misc_flags_offset()));
2098 Label skip_register_finalizer;
2099 __ test_bit(t0, x13, exact_log2(KlassFlags::_misc_has_finalizer));
2100 __ beqz(t0, skip_register_finalizer);
2101
2102 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::register_finalizer), c_rarg1);
2103
2104 __ bind(skip_register_finalizer);
2105 }
2106
2107 // Issue a StoreStore barrier after all stores but before return
2108 // from any constructor for any class with a final field. We don't
2109 // know if this is a finalizer, so we always do so.
2110 if (_desc->bytecode() == Bytecodes::_return) {
2111 __ membar(MacroAssembler::StoreStore);
2112 }
2113
2114 if (_desc->bytecode() != Bytecodes::_return_register_finalizer) {
2115 Label no_safepoint;
2116 __ ld(t0, Address(xthread, JavaThread::polling_word_offset()));
2117 __ test_bit(t0, t0, exact_log2(SafepointMechanism::poll_bit()));
2118 __ beqz(t0, no_safepoint);
2119 __ push(state);
2120 __ push_cont_fastpath(xthread);
2121 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint));
2122 __ pop_cont_fastpath(xthread);
2123 __ pop(state);
2124 __ bind(no_safepoint);
2125 }
2126
2127 // Narrow result if state is itos but result type is smaller.
2128 // Need to narrow in the return bytecode rather than in generate_return_entry
2129 // since compiled code callers expect the result to already be narrowed.
2130 if (state == itos) {
2488 __ ld(c_rarg1, at_tos()); // get object pointer without popping it
2489 __ verify_oop(c_rarg1);
2490 }
2491 // c_rarg1: object pointer or null
2492 // c_rarg2: cache entry pointer
2493 __ call_VM(noreg, CAST_FROM_FN_PTR(address,
2494 InterpreterRuntime::post_field_access),
2495 c_rarg1, c_rarg2);
2496 __ load_field_entry(cache, index);
2497 __ bind(L1);
2498 }
2499 }
2500
2501 void TemplateTable::pop_and_check_object(Register r) {
2502 __ pop_ptr(r);
2503 __ null_check(r); // for field access must check obj.
2504 __ verify_oop(r);
2505 }
2506
2507 void TemplateTable::getfield_or_static(int byte_no, bool is_static, RewriteControl rc) {
2508 const Register cache = x14;
2509 const Register obj = x14;
2510 const Register index = x13;
2511 const Register tos_state = x13;
2512 const Register off = x9;
2513 const Register flags = x16;
2514 const Register bc = x14; // uses same reg as obj, so don't mix them
2515
2516 resolve_cache_and_index_for_field(byte_no, cache, index);
2517 jvmti_post_field_access(cache, index, is_static, false);
2518 load_resolved_field_entry(obj, cache, tos_state, off, flags, is_static);
2519
2520 if (!is_static) {
2521 // obj is on the stack
2522 pop_and_check_object(obj);
2523 }
2524
2525 __ add(off, obj, off);
2526 const Address field(off);
2527
2528 Label Done, notByte, notBool, notInt, notShort, notChar,
2529 notLong, notFloat, notObj, notDouble;
2530
2531 assert(btos == 0, "change code, btos != 0");
2532 __ bnez(tos_state, notByte);
2533
2534 // Don't rewrite getstatic, only getfield
2535 if (is_static) {
2536 rc = may_not_rewrite;
2537 }
2546 __ j(Done);
2547
2548 __ bind(notByte);
2549 __ subi(t0, tos_state, (u1)ztos);
2550 __ bnez(t0, notBool);
2551
2552 // ztos (same code as btos)
2553 __ access_load_at(T_BOOLEAN, IN_HEAP, x10, field, noreg, noreg);
2554 __ push(ztos);
2555 // Rewrite bytecode to be faster
2556 if (rc == may_rewrite) {
2557 // uses btos rewriting, no truncating to t/f bit is needed for getfield
2558 patch_bytecode(Bytecodes::_fast_bgetfield, bc, x11);
2559 }
2560 __ j(Done);
2561
2562 __ bind(notBool);
2563 __ subi(t0, tos_state, (u1)atos);
2564 __ bnez(t0, notObj);
2565 // atos
2566 __ load_heap_oop(x10, field, x28, x29, IN_HEAP);
2567 __ push(atos);
2568 if (rc == may_rewrite) {
2569 patch_bytecode(Bytecodes::_fast_agetfield, bc, x11);
2570 }
2571 __ j(Done);
2572
2573 __ bind(notObj);
2574 __ subi(t0, tos_state, (u1)itos);
2575 __ bnez(t0, notInt);
2576 // itos
2577 __ access_load_at(T_INT, IN_HEAP, x10, field, noreg, noreg);
2578 __ sext(x10, x10, 32);
2579 __ push(itos);
2580 // Rewrite bytecode to be faster
2581 if (rc == may_rewrite) {
2582 patch_bytecode(Bytecodes::_fast_igetfield, bc, x11);
2583 }
2584 __ j(Done);
2585
2586 __ bind(notInt);
2587 __ subi(t0, tos_state, (u1)ctos);
2588 __ bnez(t0, notChar);
2589 // ctos
2590 __ access_load_at(T_CHAR, IN_HEAP, x10, field, noreg, noreg);
2591 __ push(ctos);
2711 // c_rarg1: object pointer set up above (null if static)
2712 // c_rarg2: cache entry pointer
2713 // c_rarg3: jvalue object on the stack
2714 __ call_VM(noreg,
2715 CAST_FROM_FN_PTR(address,
2716 InterpreterRuntime::post_field_modification),
2717 c_rarg1, c_rarg2, c_rarg3);
2718 __ load_field_entry(cache, index);
2719 __ bind(L1);
2720 }
2721 }
2722
2723 void TemplateTable::putfield_or_static(int byte_no, bool is_static, RewriteControl rc) {
2724 transition(vtos, vtos);
2725
2726 const Register cache = x12;
2727 const Register index = x13;
2728 const Register tos_state = x13;
2729 const Register obj = x12;
2730 const Register off = x9;
2731 const Register flags = x10;
2732 const Register bc = x14;
2733
2734 resolve_cache_and_index_for_field(byte_no, cache, index);
2735 jvmti_post_field_mod(cache, index, is_static);
2736 load_resolved_field_entry(obj, cache, tos_state, off, flags, is_static);
2737
2738 Label Done;
2739 __ mv(x15, flags);
2740
2741 {
2742 Label notVolatile;
2743 __ test_bit(t0, x15, ResolvedFieldEntry::is_volatile_shift);
2744 __ beqz(t0, notVolatile);
2745 __ membar(MacroAssembler::StoreStore | MacroAssembler::LoadStore);
2746 __ bind(notVolatile);
2747 }
2748
2749 Label notByte, notBool, notInt, notShort, notChar,
2750 notLong, notFloat, notObj, notDouble;
2751
2752 assert(btos == 0, "change code, btos != 0");
2753 __ bnez(tos_state, notByte);
2754
2755 // Don't rewrite putstatic, only putfield
2756 if (is_static) {
2757 rc = may_not_rewrite;
2758 }
2759
2760 // btos
2761 {
2762 __ pop(btos);
2763 // field address
2782 __ pop(ztos);
2783 // field address
2784 if (!is_static) {
2785 pop_and_check_object(obj);
2786 }
2787 __ add(off, obj, off); // if static, obj from cache, else obj from stack.
2788 const Address field(off, 0);
2789 __ access_store_at(T_BOOLEAN, IN_HEAP, field, x10, noreg, noreg, noreg);
2790 if (rc == may_rewrite) {
2791 patch_bytecode(Bytecodes::_fast_zputfield, bc, x11, true, byte_no);
2792 }
2793 __ j(Done);
2794 }
2795
2796 __ bind(notBool);
2797 __ subi(t0, tos_state, (u1)atos);
2798 __ bnez(t0, notObj);
2799
2800 // atos
2801 {
2802 __ pop(atos);
2803 // field address
2804 if (!is_static) {
2805 pop_and_check_object(obj);
2806 }
2807 __ add(off, obj, off); // if static, obj from cache, else obj from stack.
2808 const Address field(off, 0);
2809 // Store into the field
2810 __ store_heap_oop(field, x10, x28, x29, x13, IN_HEAP);
2811 if (rc == may_rewrite) {
2812 patch_bytecode(Bytecodes::_fast_aputfield, bc, x11, true, byte_no);
2813 }
2814 __ j(Done);
2815 }
2816
2817 __ bind(notObj);
2818 __ subi(t0, tos_state, (u1)itos);
2819 __ bnez(t0, notInt);
2820
2821 // itos
2822 {
2823 __ pop(itos);
2824 // field address
2825 if (!is_static) {
2826 pop_and_check_object(obj);
2827 }
2828 __ add(off, obj, off); // if static, obj from cache, else obj from stack.
2829 const Address field(off, 0);
2830 __ access_store_at(T_INT, IN_HEAP, field, x10, noreg, noreg, noreg);
2831 if (rc == may_rewrite) {
2832 patch_bytecode(Bytecodes::_fast_iputfield, bc, x11, true, byte_no);
2833 }
2834 __ j(Done);
2929 }
2930 __ add(off, obj, off); // if static, obj from cache, else obj from stack.
2931 const Address field(off, 0);
2932 __ access_store_at(T_DOUBLE, IN_HEAP, field, noreg /* dtos */, noreg, noreg, noreg);
2933 if (rc == may_rewrite) {
2934 patch_bytecode(Bytecodes::_fast_dputfield, bc, x11, true, byte_no);
2935 }
2936 }
2937
2938 #ifdef ASSERT
2939 __ j(Done);
2940
2941 __ bind(notDouble);
2942 __ stop("Bad state");
2943 #endif
2944
2945 __ bind(Done);
2946
2947 {
2948 Label notVolatile;
2949 __ test_bit(t0, x15, ResolvedFieldEntry::is_volatile_shift);
2950 __ beqz(t0, notVolatile);
2951 __ membar(MacroAssembler::StoreLoad | MacroAssembler::StoreStore);
2952 __ bind(notVolatile);
2953 }
2954 }
2955
2956 void TemplateTable::putfield(int byte_no) {
2957 putfield_or_static(byte_no, false);
2958 }
2959
2960 void TemplateTable::nofast_putfield(int byte_no) {
2961 putfield_or_static(byte_no, false, may_not_rewrite);
2962 }
2963
2964 void TemplateTable::putstatic(int byte_no) {
2965 putfield_or_static(byte_no, true);
2966 }
2967
2968 void TemplateTable::jvmti_post_fast_field_mod() {
2969 if (JvmtiExport::can_post_field_modification()) {
2970 // Check to see if a field modification watch has been set before
2971 // we take the time to call into the VM.
2972 Label L2;
2973 __ lwu(c_rarg3, ExternalAddress(JvmtiExport::get_field_modification_count_addr()));
2974 __ beqz(c_rarg3, L2);
2975
2976 __ pop_ptr(x9); // copy the object pointer from tos
2977 __ verify_oop(x9);
2978 __ push_ptr(x9); // put the object pointer back on tos
2979 // Save tos values before call_VM() clobbers them. Since we have
2980 // to do it for every data type, we use the saved values as the
2981 // jvalue object.
2982 switch (bytecode()) { // load values into the jvalue object
2983 case Bytecodes::_fast_aputfield: __ push_ptr(x10); break;
2984 case Bytecodes::_fast_bputfield: // fall through
2985 case Bytecodes::_fast_zputfield: // fall through
2986 case Bytecodes::_fast_sputfield: // fall through
2987 case Bytecodes::_fast_cputfield: // fall through
2988 case Bytecodes::_fast_iputfield: __ push_i(x10); break;
2989 case Bytecodes::_fast_dputfield: __ push_d(); break;
2990 case Bytecodes::_fast_fputfield: __ push_f(); break;
2991 case Bytecodes::_fast_lputfield: __ push_l(x10); break;
2992
2993 default:
2994 ShouldNotReachHere();
2995 }
2996 __ mv(c_rarg3, esp); // points to jvalue on the stack
2997 // access constant pool cache entry
2998 __ load_field_entry(c_rarg2, x10);
2999 __ verify_oop(x9);
3000 // x9: object pointer copied above
3001 // c_rarg2: cache entry pointer
3002 // c_rarg3: jvalue object on the stack
3003 __ call_VM(noreg,
3004 CAST_FROM_FN_PTR(address,
3005 InterpreterRuntime::post_field_modification),
3006 x9, c_rarg2, c_rarg3);
3007
3008 switch (bytecode()) { // restore tos values
3009 case Bytecodes::_fast_aputfield: __ pop_ptr(x10); break;
3010 case Bytecodes::_fast_bputfield: // fall through
3011 case Bytecodes::_fast_zputfield: // fall through
3012 case Bytecodes::_fast_sputfield: // fall through
3013 case Bytecodes::_fast_cputfield: // fall through
3014 case Bytecodes::_fast_iputfield: __ pop_i(x10); break;
3015 case Bytecodes::_fast_dputfield: __ pop_d(); break;
3016 case Bytecodes::_fast_fputfield: __ pop_f(); break;
3017 case Bytecodes::_fast_lputfield: __ pop_l(x10); break;
3018 default: break;
3019 }
3020 __ bind(L2);
3021 }
3022 }
3023
3024 void TemplateTable::fast_storefield(TosState state) {
3025 transition(state, vtos);
3026
3027 ByteSize base = ConstantPoolCache::base_offset();
3028
3030
3031 // access constant pool cache
3032 __ load_field_entry(x12, x11);
3033
3034 // X11: field offset, X12: field holder, X13: flags
3035 load_resolved_field_entry(x12, x12, noreg, x11, x13);
3036 __ verify_field_offset(x11);
3037
3038 {
3039 Label notVolatile;
3040 __ test_bit(t0, x13, ResolvedFieldEntry::is_volatile_shift);
3041 __ beqz(t0, notVolatile);
3042 __ membar(MacroAssembler::StoreStore | MacroAssembler::LoadStore);
3043 __ bind(notVolatile);
3044 }
3045
3046 // Get object from stack
3047 pop_and_check_object(x12);
3048
3049 // field address
3050 __ add(x11, x12, x11);
3051 const Address field(x11, 0);
3052
3053 // access field, must not clobber x13 - flags
3054 switch (bytecode()) {
3055 case Bytecodes::_fast_aputfield:
3056 __ store_heap_oop(field, x10, x28, x29, x15, IN_HEAP);
3057 break;
3058 case Bytecodes::_fast_lputfield:
3059 __ access_store_at(T_LONG, IN_HEAP, field, x10, noreg, noreg, noreg);
3060 break;
3061 case Bytecodes::_fast_iputfield:
3062 __ access_store_at(T_INT, IN_HEAP, field, x10, noreg, noreg, noreg);
3063 break;
3064 case Bytecodes::_fast_zputfield:
3065 __ access_store_at(T_BOOLEAN, IN_HEAP, field, x10, noreg, noreg, noreg);
3066 break;
3067 case Bytecodes::_fast_bputfield:
3068 __ access_store_at(T_BYTE, IN_HEAP, field, x10, noreg, noreg, noreg);
3069 break;
3070 case Bytecodes::_fast_sputfield:
3071 __ access_store_at(T_SHORT, IN_HEAP, field, x10, noreg, noreg, noreg);
3072 break;
3073 case Bytecodes::_fast_cputfield:
3074 __ access_store_at(T_CHAR, IN_HEAP, field, x10, noreg, noreg, noreg);
3116 __ pop_ptr(x10); // restore object pointer
3117 __ bind(L1);
3118 }
3119
3120 // access constant pool cache
3121 __ load_field_entry(x12, x11);
3122
3123 __ load_sized_value(x11, Address(x12, in_bytes(ResolvedFieldEntry::field_offset_offset())), sizeof(int), true /*is_signed*/);
3124 __ verify_field_offset(x11);
3125
3126 __ load_unsigned_byte(x13, Address(x12, in_bytes(ResolvedFieldEntry::flags_offset())));
3127
3128 // x10: object
3129 __ verify_oop(x10);
3130 __ null_check(x10);
3131 __ add(x11, x10, x11);
3132 const Address field(x11, 0);
3133
3134 // access field
3135 switch (bytecode()) {
3136 case Bytecodes::_fast_agetfield:
3137 __ load_heap_oop(x10, field, x28, x29, IN_HEAP);
3138 __ verify_oop(x10);
3139 break;
3140 case Bytecodes::_fast_lgetfield:
3141 __ access_load_at(T_LONG, IN_HEAP, x10, field, noreg, noreg);
3142 break;
3143 case Bytecodes::_fast_igetfield:
3144 __ access_load_at(T_INT, IN_HEAP, x10, field, noreg, noreg);
3145 __ sext(x10, x10, 32);
3146 break;
3147 case Bytecodes::_fast_bgetfield:
3148 __ access_load_at(T_BYTE, IN_HEAP, x10, field, noreg, noreg);
3149 break;
3150 case Bytecodes::_fast_sgetfield:
3151 __ access_load_at(T_SHORT, IN_HEAP, x10, field, noreg, noreg);
3152 break;
3153 case Bytecodes::_fast_cgetfield:
3154 __ access_load_at(T_CHAR, IN_HEAP, x10, field, noreg, noreg);
3155 break;
3523 // This is done before loading InstanceKlass to be consistent with the order
3524 // how Constant Pool is update (see ConstantPool::klass_at_put)
3525 const int tags_offset = Array<u1>::base_offset_in_bytes();
3526 __ add(t0, x10, x13);
3527 __ la(t0, Address(t0, tags_offset));
3528 __ lbu(t0, t0);
3529 __ membar(MacroAssembler::LoadLoad | MacroAssembler::LoadStore);
3530 __ subi(t1, t0, (u1)JVM_CONSTANT_Class);
3531 __ bnez(t1, slow_case);
3532
3533 // get InstanceKlass
3534 __ load_resolved_klass_at_offset(x14, x13, x14, t0);
3535
3536 // make sure klass is initialized
3537 assert(VM_Version::supports_fast_class_init_checks(),
3538 "Optimization requires support for fast class initialization checks");
3539 __ clinit_barrier(x14, t0, nullptr /*L_fast_path*/, &slow_case);
3540
3541 // get instance_size in InstanceKlass (scaled to a count of bytes)
3542 __ lwu(x13, Address(x14, Klass::layout_helper_offset()));
3543 // test to see if is malformed in some way
3544 __ test_bit(t0, x13, exact_log2(Klass::_lh_instance_slow_path_bit));
3545 __ bnez(t0, slow_case);
3546
3547 // Allocate the instance:
3548 // If TLAB is enabled:
3549 // Try to allocate in the TLAB.
3550 // If fails, go to the slow path.
3551 // Initialize the allocation.
3552 // Exit.
3553 // Go to slow path.
3554
3555 if (UseTLAB) {
3556 __ tlab_allocate(x10, x13, 0, noreg, x11, slow_case);
3557
3558 if (ZeroTLAB) {
3559 // the fields have been already cleared
3560 __ j(initialize_header);
3561 }
3562
3563 // The object is initialized before the header. If the object size is
3564 // zero, go directly to the header initialization.
3565 if (UseCompactObjectHeaders) {
3566 assert(is_aligned(oopDesc::base_offset_in_bytes(), BytesPerLong), "oop base offset must be 8-byte-aligned");
3567 __ subi(x13, x13, oopDesc::base_offset_in_bytes());
3568 } else {
3569 __ subi(x13, x13, sizeof(oopDesc));
3570 }
3571 __ beqz(x13, initialize_header);
3572
3573 // Initialize object fields
3574 {
3575 if (UseCompactObjectHeaders) {
3576 assert(is_aligned(oopDesc::base_offset_in_bytes(), BytesPerLong), "oop base offset must be 8-byte-aligned");
3577 __ addi(x12, x10, oopDesc::base_offset_in_bytes());
3578 } else {
3579 __ addi(x12, x10, sizeof(oopDesc));
3580 }
3581 Label loop;
3582 __ bind(loop);
3583 __ sd(zr, Address(x12));
3584 __ addi(x12, x12, BytesPerLong);
3585 __ subi(x13, x13, BytesPerLong);
3586 __ bnez(x13, loop);
3587 }
3588
3589 // initialize object hader only.
3590 __ bind(initialize_header);
3591 if (UseCompactObjectHeaders) {
3592 __ ld(t0, Address(x14, Klass::prototype_header_offset()));
3593 __ sd(t0, Address(x10, oopDesc::mark_offset_in_bytes()));
3594 } else {
3595 __ mv(t0, (intptr_t)markWord::prototype().value());
3596 __ sd(t0, Address(x10, oopDesc::mark_offset_in_bytes()));
3597 __ store_klass_gap(x10, zr); // zero klass gap for compressed oops
3598 __ store_klass(x10, x14); // store klass last
3599 }
3600
3601 if (DTraceAllocProbes) {
3602 // Trigger dtrace event for fastpath
3603 __ push(atos); // save the return value
3604 __ call_VM_leaf(CAST_FROM_FN_PTR(address, static_cast<int (*)(oopDesc*)>(SharedRuntime::dtrace_object_alloc)), x10);
3605 __ pop(atos); // restore the return value
3606 }
3607 __ j(done);
3608 }
3609
3610 // slow case
3611 __ bind(slow_case);
3612 __ get_constant_pool(c_rarg1);
3613 __ get_unsigned_2_byte_index_at_bcp(c_rarg2, 1);
3614 __ call_VM_preemptable(x10, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), c_rarg1, c_rarg2);
3615 __ verify_oop(x10);
3616
3617 // continue
3618 __ bind(done);
3619 // Must prevent reordering of stores for object initialization with stores that publish the new object.
3620 __ membar(MacroAssembler::StoreStore);
3621 }
3622
3623 void TemplateTable::newarray() {
3624 transition(itos, atos);
3625 __ load_unsigned_byte(c_rarg1, at_bcp(1));
3672 __ bind(quicked);
3673 __ mv(x13, x10); // Save object in x13; x10 needed for subtype check
3674 __ load_resolved_klass_at_offset(x12, x9, x10, t0); // x10 = klass
3675
3676 __ bind(resolved);
3677 __ load_klass(x9, x13);
3678
3679 // Generate subtype check. Blows x12, x15. Object in x13.
3680 // Superklass in x10. Subklass in x9.
3681 __ gen_subtype_check(x9, ok_is_subtype);
3682
3683 // Come here on failure
3684 __ push_reg(x13);
3685 // object is at TOS
3686 __ j(RuntimeAddress(Interpreter::_throw_ClassCastException_entry));
3687
3688 // Come here on success
3689 __ bind(ok_is_subtype);
3690 __ mv(x10, x13); // Restore object in x13
3691
3692 // Collect counts on whether this test sees nulls a lot or not.
3693 if (ProfileInterpreter) {
3694 __ j(done);
3695 __ bind(is_null);
3696 __ profile_null_seen(x12);
3697 } else {
3698 __ bind(is_null); // same as 'done'
3699 }
3700 __ bind(done);
3701 }
3702
3703 void TemplateTable::instanceof() {
3704 transition(atos, itos);
3705 Label done, is_null, ok_is_subtype, quicked, resolved;
3706 __ beqz(x10, is_null);
3707
3708 // Get cpool & tags index
3709 __ get_cpool_and_tags(x12, x13); // x12=cpool, x13=tags array
3710 __ get_unsigned_2_byte_index_at_bcp(x9, 1); // x9=index
3711 // See if bytecode has already been quicked
3712 __ addi(t0, x13, Array<u1>::base_offset_in_bytes());
3713 __ add(x11, t0, x9);
3714 __ lbu(x11, x11);
3715 __ membar(MacroAssembler::LoadLoad | MacroAssembler::LoadStore);
3716 __ subi(t0, x11, (u1)JVM_CONSTANT_Class);
3717 __ beqz(t0, quicked);
3718
3799 // in the assembly code structure as well
3800 //
3801 // Stack layout:
3802 //
3803 // [expressions ] <--- esp = expression stack top
3804 // ..
3805 // [expressions ]
3806 // [monitor entry] <--- monitor block top = expression stack bot
3807 // ..
3808 // [monitor entry]
3809 // [frame data ] <--- monitor block bot
3810 // ...
3811 // [saved fp ] <--- fp
3812
3813 void TemplateTable::monitorenter() {
3814 transition(atos, vtos);
3815
3816 // check for null object
3817 __ null_check(x10);
3818
3819 const Address monitor_block_top(
3820 fp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
3821 const Address monitor_block_bot(
3822 fp, frame::interpreter_frame_initial_sp_offset * wordSize);
3823 const int entry_size = frame::interpreter_frame_monitor_size_in_bytes();
3824
3825 Label allocated;
3826
3827 // initialize entry pointer
3828 __ mv(c_rarg1, zr); // points to free slot or null
3829
3830 // find a free slot in the monitor block (result in c_rarg1)
3831 {
3832 Label entry, loop, exit, notUsed;
3833 __ ld(c_rarg3, monitor_block_top); // derelativize pointer
3834 __ shadd(c_rarg3, c_rarg3, fp, c_rarg3, LogBytesPerWord);
3835 // Now c_rarg3 points to current entry, starting with top-most entry
3836
3837 __ la(c_rarg2, monitor_block_bot); // points to word before bottom
3838
3898 // c_rarg1: points to monitor entry
3899 __ bind(allocated);
3900
3901 // Increment bcp to point to the next bytecode, so exception
3902 // handling for async. exceptions work correctly.
3903 // The object has already been popped from the stack, so the
3904 // expression stack looks correct.
3905 __ addi(xbcp, xbcp, 1);
3906
3907 // store object
3908 __ sd(x10, Address(c_rarg1, BasicObjectLock::obj_offset()));
3909 __ lock_object(c_rarg1);
3910
3911 // check to make sure this monitor doesn't cause stack overflow after locking
3912 __ save_bcp(); // in case of exception
3913 __ generate_stack_overflow_check(0);
3914
3915 // The bcp has already been incremented. Just need to dispatch to
3916 // next instruction.
3917 __ dispatch_next(vtos);
3918 }
3919
3920 void TemplateTable::monitorexit() {
3921 transition(atos, vtos);
3922
3923 // check for null object
3924 __ null_check(x10);
3925
3926 const Address monitor_block_top(
3927 fp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
3928 const Address monitor_block_bot(
3929 fp, frame::interpreter_frame_initial_sp_offset * wordSize);
3930 const int entry_size = frame::interpreter_frame_monitor_size_in_bytes();
3931
3932 Label found;
3933
3934 // find matching slot
3935 {
3936 Label entry, loop;
3937 __ ld(c_rarg1, monitor_block_top); // derelativize pointer
3938 __ shadd(c_rarg1, c_rarg1, fp, c_rarg1, LogBytesPerWord);
3939 // Now c_rarg1 points to current entry, starting with top-most entry
3940
3941 __ la(c_rarg2, monitor_block_bot); // points to word before bottom
3942 // of monitor block
3943 __ j(entry);
3944
3945 __ bind(loop);
|
26
27 #include "asm/macroAssembler.inline.hpp"
28 #include "compiler/disassembler.hpp"
29 #include "gc/shared/barrierSetAssembler.hpp"
30 #include "gc/shared/collectedHeap.hpp"
31 #include "gc/shared/tlab_globals.hpp"
32 #include "interpreter/interp_masm.hpp"
33 #include "interpreter/interpreter.hpp"
34 #include "interpreter/interpreterRuntime.hpp"
35 #include "interpreter/templateTable.hpp"
36 #include "memory/universe.hpp"
37 #include "oops/method.inline.hpp"
38 #include "oops/methodData.hpp"
39 #include "oops/objArrayKlass.hpp"
40 #include "oops/oop.inline.hpp"
41 #include "oops/resolvedFieldEntry.hpp"
42 #include "oops/resolvedIndyEntry.hpp"
43 #include "oops/resolvedMethodEntry.hpp"
44 #include "prims/jvmtiExport.hpp"
45 #include "prims/methodHandles.hpp"
46 #include "runtime/arguments.hpp"
47 #include "runtime/frame.inline.hpp"
48 #include "runtime/sharedRuntime.hpp"
49 #include "runtime/stubRoutines.hpp"
50 #include "runtime/synchronizer.hpp"
51 #include "utilities/powerOfTwo.hpp"
52
53 #define __ Disassembler::hook<InterpreterMacroAssembler>(__FILE__, __LINE__, _masm)->
54
55 // Address computation: local variables
56
57 static inline Address iaddress(int n) {
58 return Address(xlocals, Interpreter::local_offset_in_bytes(n));
59 }
60
61 static inline Address laddress(int n) {
62 return iaddress(n + 1);
63 }
64
65 static inline Address faddress(int n) {
66 return iaddress(n);
122 return Address(esp, Interpreter::expr_offset_in_bytes(4));
123 }
124
125 static inline Address at_tos_p5() {
126 return Address(esp, Interpreter::expr_offset_in_bytes(5));
127 }
128
129 Address TemplateTable::at_bcp(int offset) {
130 assert(_desc->uses_bcp(), "inconsistent uses_bcp information");
131 return Address(xbcp, offset);
132 }
133
134 void TemplateTable::patch_bytecode(Bytecodes::Code bc, Register bc_reg,
135 Register temp_reg, bool load_bc_into_bc_reg /*=true*/,
136 int byte_no) {
137 assert_different_registers(bc_reg, temp_reg);
138 if (!RewriteBytecodes) { return; }
139 Label L_patch_done;
140
141 switch (bc) {
142 case Bytecodes::_fast_vputfield: // fall through
143 case Bytecodes::_fast_aputfield: // fall through
144 case Bytecodes::_fast_bputfield: // fall through
145 case Bytecodes::_fast_zputfield: // fall through
146 case Bytecodes::_fast_cputfield: // fall through
147 case Bytecodes::_fast_dputfield: // fall through
148 case Bytecodes::_fast_fputfield: // fall through
149 case Bytecodes::_fast_iputfield: // fall through
150 case Bytecodes::_fast_lputfield: // fall through
151 case Bytecodes::_fast_sputfield: {
152 // We skip bytecode quickening for putfield instructions when
153 // the put_code written to the constant pool cache is zero.
154 // This is required so that every execution of this instruction
155 // calls out to InterpreterRuntime::resolve_get_put to do
156 // additional, required work.
157 assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
158 assert(load_bc_into_bc_reg, "we use bc_reg as temp");
159 __ load_field_entry(temp_reg, bc_reg);
160 if (byte_no == f1_byte) {
161 __ la(temp_reg, Address(temp_reg, in_bytes(ResolvedFieldEntry::get_code_offset())));
162 } else {
756
757 void TemplateTable::daload() {
758 transition(itos, dtos);
759 __ mv(x11, x10);
760 __ pop_ptr(x10);
761 // x10: array
762 // x11: index
763 index_check(x10, x11); // leaves index in x11
764 __ addi(x11, x11, arrayOopDesc::base_offset_in_bytes(T_DOUBLE) >> 3);
765 __ shadd(x10, x11, x10, t0, 3);
766 __ access_load_at(T_DOUBLE, IN_HEAP | IS_ARRAY, x10, Address(x10), noreg, noreg);
767 }
768
769 void TemplateTable::aaload() {
770 transition(itos, atos);
771 __ mv(x11, x10);
772 __ pop_ptr(x10);
773 // x10: array
774 // x11: index
775 index_check(x10, x11); // leaves index in x11
776 __ profile_array_type<ArrayLoadData>(x12, x10, x14);
777 if (UseArrayFlattening) {
778 Label is_flat_array, done;
779
780 __ test_flat_array_oop(x10, x28, is_flat_array);
781 __ addi(x11, x11, arrayOopDesc::base_offset_in_bytes(T_OBJECT) >> LogBytesPerHeapOop);
782 __ shadd(x10, x11, x10, t0, LogBytesPerHeapOop);
783 __ load_heap_oop(x10, Address(x10), x28, x29, IS_ARRAY);
784
785 __ j(done);
786 __ bind(is_flat_array);
787 __ call_VM(x10, CAST_FROM_FN_PTR(address, InterpreterRuntime::flat_array_load), x10, x11);
788 __ bind(done);
789 } else {
790 __ addi(x11, x11, arrayOopDesc::base_offset_in_bytes(T_OBJECT) >> LogBytesPerHeapOop);
791 __ shadd(x10, x11, x10, t0, LogBytesPerHeapOop);
792 __ load_heap_oop(x10, Address(x10), x28, x29, IS_ARRAY);
793 }
794 __ profile_element_type(x12, x10, x14);
795 }
796
797 void TemplateTable::baload() {
798 transition(itos, itos);
799 __ mv(x11, x10);
800 __ pop_ptr(x10);
801 // x10: array
802 // x11: index
803 index_check(x10, x11); // leaves index in x11
804 __ addi(x11, x11, arrayOopDesc::base_offset_in_bytes(T_BYTE) >> 0);
805 __ shadd(x10, x11, x10, t0, 0);
806 __ access_load_at(T_BYTE, IN_HEAP | IS_ARRAY, x10, Address(x10), noreg, noreg);
807 }
808
809 void TemplateTable::caload() {
810 transition(itos, itos);
811 __ mv(x11, x10);
812 __ pop_ptr(x10);
813 // x10: array
814 // x11: index
1048 index_check(x13, x11); // prefer index in x11
1049 __ addi(x11, x11, arrayOopDesc::base_offset_in_bytes(T_FLOAT) >> 2);
1050 __ shadd(t0, x11, x13, t0, 2);
1051 __ access_store_at(T_FLOAT, IN_HEAP | IS_ARRAY, Address(t0, 0), noreg /* ftos */, noreg, noreg, noreg);
1052 }
1053
1054 void TemplateTable::dastore() {
1055 transition(dtos, vtos);
1056 __ pop_i(x11);
1057 __ pop_ptr(x13);
1058 // f10: value
1059 // x11: index
1060 // x13: array
1061 index_check(x13, x11); // prefer index in x11
1062 __ addi(x11, x11, arrayOopDesc::base_offset_in_bytes(T_DOUBLE) >> 3);
1063 __ shadd(t0, x11, x13, t0, 3);
1064 __ access_store_at(T_DOUBLE, IN_HEAP | IS_ARRAY, Address(t0, 0), noreg /* dtos */, noreg, noreg, noreg);
1065 }
1066
1067 void TemplateTable::aastore() {
1068 Label is_null, is_flat_array, ok_is_subtype, done;
1069 transition(vtos, vtos);
1070 // stack: ..., array, index, value
1071 __ ld(x10, at_tos()); // value
1072 __ lw(x12, at_tos_p1()); // index
1073 __ ld(x13, at_tos_p2()); // array
1074
1075 index_check(x13, x12); // kills x11
1076
1077 __ profile_array_type<ArrayStoreData>(x14, x13, x15);
1078 __ profile_multiple_element_types(x14, x10, x15, x16);
1079
1080 __ addi(x14, x12, arrayOopDesc::base_offset_in_bytes(T_OBJECT) >> LogBytesPerHeapOop);
1081 __ shadd(x14, x14, x13, x14, LogBytesPerHeapOop);
1082
1083 Address element_address(x14, 0);
1084
1085 // do array store check - check for null value first
1086 __ beqz(x10, is_null);
1087
1088 // Move array class to x15
1089 __ load_klass(x15, x13);
1090
1091 if (UseArrayFlattening) {
1092 __ lwu(x16, Address(x15, Klass::layout_helper_offset()));
1093 __ test_flat_array_layout(x16, is_flat_array);
1094 }
1095
1096 // Move subklass into x11
1097 __ load_klass(x11, x10);
1098
1099 // Move array element superklass into x10
1100 __ ld(x10, Address(x15, ObjArrayKlass::element_klass_offset()));
1101 // Compress array + index * oopSize + 12 into a single register. Frees x12.
1102
1103 // Generate subtype check. Blows x12, x15
1104 // Superklass in x10. Subklass in x11.
1105
1106 // is "x11 <: x10" ? (value subclass <: array element superclass)
1107 __ gen_subtype_check(x11, ok_is_subtype, false);
1108
1109 // Come here on failure
1110 // object is at TOS
1111 __ j(RuntimeAddress(Interpreter::_throw_ArrayStoreException_entry));
1112
1113 // Come here on success
1114 __ bind(ok_is_subtype);
1115
1116 // Get the value we will store
1117 __ ld(x10, at_tos());
1118 // Now store using the appropriate barrier
1119 __ store_heap_oop(element_address, x10, x28, x29, x13, IS_ARRAY);
1120 __ j(done);
1121
1122 // Have a null in x10, x13=array, x12=index. Store null at ary[idx]
1123 __ bind(is_null);
1124 if (Arguments::is_valhalla_enabled()) {
1125 Label is_null_into_value_array_npe, store_null;
1126
1127 if (UseArrayFlattening) {
1128 __ test_flat_array_oop(x13, x28, is_flat_array);
1129 }
1130
1131 // No way to store null in a null-free array
1132 __ test_null_free_array_oop(x13, x28, is_null_into_value_array_npe);
1133 __ j(store_null);
1134
1135 __ bind(is_null_into_value_array_npe);
1136 __ j(ExternalAddress(Interpreter::_throw_NullPointerException_entry));
1137
1138 __ bind(store_null);
1139 }
1140
1141 // Store a null
1142 __ store_heap_oop(element_address, noreg, x28, x29, x13, IS_ARRAY);
1143 __ j(done);
1144
1145 if (UseArrayFlattening) {
1146 Label is_type_ok;
1147 __ bind(is_flat_array); // Store non-null value to flat
1148
1149 __ ld(x10, at_tos()); // value
1150 __ lw(x13, at_tos_p1()); // index
1151 __ ld(x12, at_tos_p2()); // array
1152 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::flat_array_store), x10, x12, x13);
1153 }
1154
1155 // Pop stack arguments
1156 __ bind(done);
1157 __ addi(esp, esp, 3 * Interpreter::stackElementSize);
1158 }
1159
1160 void TemplateTable::bastore() {
1161 transition(itos, vtos);
1162 __ pop_i(x11);
1163 __ pop_ptr(x13);
1164 // x10: value
1165 // x11: index
1166 // x13: array
1167 index_check(x13, x11); // prefer index in x11
1168
1169 // Need to check whether array is boolean or byte
1170 // since both types share the bastore bytecode.
1171 __ load_klass(x12, x13);
1172 __ lwu(x12, Address(x12, Klass::layout_helper_offset()));
1173 Label L_skip;
1890 __ profile_not_taken_branch(x10);
1891 }
1892
1893 void TemplateTable::if_nullcmp(Condition cc) {
1894 transition(atos, vtos);
1895 // assume branch is more often taken than not (loops use backward branches)
1896 Label not_taken;
1897 if (cc == equal) {
1898 __ bnez(x10, not_taken);
1899 } else {
1900 __ beqz(x10, not_taken);
1901 }
1902 branch(false, false);
1903 __ bind(not_taken);
1904 __ profile_not_taken_branch(x10);
1905 }
1906
1907 void TemplateTable::if_acmp(Condition cc) {
1908 transition(atos, vtos);
1909 // assume branch is more often taken than not (loops use backward branches)
1910 Label taken, not_taken;
1911 __ pop_ptr(x11);
1912
1913 __ profile_acmp(x12, x11, x10, x14);
1914
1915 Register is_inline_type_mask = t1;
1916 __ mv(is_inline_type_mask, markWord::inline_type_pattern);
1917
1918 if (Arguments::is_valhalla_enabled()) {
1919 // The substitutability test is only necessary if x11 and x10 are not the same...
1920 if (cc == equal) {
1921 __ beq(x11, x10, taken);
1922 } else {
1923 __ beq(x11, x10, not_taken);
1924 }
1925
1926 // ... neither are null...
1927 if (cc == equal) {
1928 __ beqz(x11, not_taken);
1929 __ beqz(x10, not_taken);
1930 } else {
1931 __ beqz(x11, taken);
1932 __ beqz(x10, taken);
1933 }
1934
1935 // ...and both are values...
1936 __ ld(x12, Address(x11, oopDesc::mark_offset_in_bytes()));
1937 __ andr(x12, x12, is_inline_type_mask);
1938 __ ld(x14, Address(x10, oopDesc::mark_offset_in_bytes()));
1939 __ andr(x14, x14, is_inline_type_mask);
1940 __ andr(x12, x12, x14);
1941 if (cc == equal) {
1942 __ bne(x12, is_inline_type_mask, not_taken);
1943 } else {
1944 __ bne(x12, is_inline_type_mask, taken);
1945 }
1946
1947 // ...with the same value klass
1948 __ load_metadata(x12, x11);
1949 __ load_metadata(x14, x10);
1950 if (cc == equal) {
1951 __ bne(x12, x14, not_taken);
1952 } else {
1953 __ bne(x12, x14, taken);
1954 }
1955
1956 // Know both are the same type, let's test for substitutability ...
1957 if (cc == equal) {
1958 invoke_is_substitutable(x10, x11, taken, not_taken);
1959 } else {
1960 invoke_is_substitutable(x10, x11, not_taken, taken);
1961 }
1962 __ stop("Not reachable");
1963 }
1964
1965 if (cc == equal) {
1966 __ bne(x11, x10, not_taken);
1967 } else {
1968 __ beq(x11, x10, not_taken);
1969 }
1970 __ bind(taken);
1971 branch(false, false);
1972 __ bind(not_taken);
1973 __ profile_not_taken_branch(x10, true);
1974 }
1975
1976 void TemplateTable::invoke_is_substitutable(Register aobj, Register bobj,
1977 Label& is_subst, Label& not_subst) {
1978 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::is_substitutable), aobj, bobj);
1979 // Restored ... x10 answer, jmp to outcome ...
1980 __ beqz(x10, not_subst);
1981 __ j(is_subst);
1982 }
1983
1984 void TemplateTable::ret() {
1985 transition(vtos, vtos);
1986 locals_index(x11);
1987 __ ld(x11, aaddress(x11, t1, _masm)); // get return bci, compute return bcp
1988 __ profile_ret(x11, x12);
1989 __ ld(xbcp, Address(xmethod, Method::const_offset()));
1990 __ add(xbcp, xbcp, x11);
1991 __ add(xbcp, xbcp, in_bytes(ConstMethod::codes_offset()));
1992 __ dispatch_next(vtos, 0, /*generate_poll*/true);
1993 }
1994
1995 void TemplateTable::wide_ret() {
1996 transition(vtos, vtos);
1997 locals_index_wide(x11);
1998 __ ld(x11, aaddress(x11, t0, _masm)); // get return bci, compute return bcp
1999 __ profile_ret(x11, x12);
2000 __ ld(xbcp, Address(xmethod, Method::const_offset()));
2001 __ add(xbcp, xbcp, x11);
2208 "inconsistent calls_vm information"); // call in remove_activation
2209
2210 if (_desc->bytecode() == Bytecodes::_return_register_finalizer) {
2211 assert(state == vtos, "only valid state");
2212
2213 __ ld(c_rarg1, aaddress(0));
2214 __ load_klass(x13, c_rarg1);
2215 __ lbu(x13, Address(x13, Klass::misc_flags_offset()));
2216 Label skip_register_finalizer;
2217 __ test_bit(t0, x13, exact_log2(KlassFlags::_misc_has_finalizer));
2218 __ beqz(t0, skip_register_finalizer);
2219
2220 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::register_finalizer), c_rarg1);
2221
2222 __ bind(skip_register_finalizer);
2223 }
2224
2225 // Issue a StoreStore barrier after all stores but before return
2226 // from any constructor for any class with a final field. We don't
2227 // know if this is a finalizer, so we always do so.
2228 if (_desc->bytecode() == Bytecodes::_return
2229 || _desc->bytecode() == Bytecodes::_return_register_finalizer) {
2230 __ membar(MacroAssembler::StoreStore);
2231 }
2232
2233 if (_desc->bytecode() != Bytecodes::_return_register_finalizer) {
2234 Label no_safepoint;
2235 __ ld(t0, Address(xthread, JavaThread::polling_word_offset()));
2236 __ test_bit(t0, t0, exact_log2(SafepointMechanism::poll_bit()));
2237 __ beqz(t0, no_safepoint);
2238 __ push(state);
2239 __ push_cont_fastpath(xthread);
2240 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint));
2241 __ pop_cont_fastpath(xthread);
2242 __ pop(state);
2243 __ bind(no_safepoint);
2244 }
2245
2246 // Narrow result if state is itos but result type is smaller.
2247 // Need to narrow in the return bytecode rather than in generate_return_entry
2248 // since compiled code callers expect the result to already be narrowed.
2249 if (state == itos) {
2607 __ ld(c_rarg1, at_tos()); // get object pointer without popping it
2608 __ verify_oop(c_rarg1);
2609 }
2610 // c_rarg1: object pointer or null
2611 // c_rarg2: cache entry pointer
2612 __ call_VM(noreg, CAST_FROM_FN_PTR(address,
2613 InterpreterRuntime::post_field_access),
2614 c_rarg1, c_rarg2);
2615 __ load_field_entry(cache, index);
2616 __ bind(L1);
2617 }
2618 }
2619
2620 void TemplateTable::pop_and_check_object(Register r) {
2621 __ pop_ptr(r);
2622 __ null_check(r); // for field access must check obj.
2623 __ verify_oop(r);
2624 }
2625
2626 void TemplateTable::getfield_or_static(int byte_no, bool is_static, RewriteControl rc) {
2627 const Register cache = x12;
2628 const Register obj = x14;
2629 const Register index = x13;
2630 const Register tos_state = x13;
2631 const Register off = x9;
2632 const Register flags = x16;
2633 const Register bc = x14; // uses same reg as obj, so don't mix them
2634
2635 resolve_cache_and_index_for_field(byte_no, cache, index);
2636 jvmti_post_field_access(cache, index, is_static, false);
2637
2638 load_resolved_field_entry(obj, cache, tos_state, off, flags, is_static);
2639
2640 if (!is_static) {
2641 // obj is on the stack
2642 pop_and_check_object(obj);
2643 }
2644
2645 __ add(off, obj, off);
2646 const Address field(off);
2647
2648 Label Done, notByte, notBool, notInt, notShort, notChar,
2649 notLong, notFloat, notObj, notDouble;
2650
2651 assert(btos == 0, "change code, btos != 0");
2652 __ bnez(tos_state, notByte);
2653
2654 // Don't rewrite getstatic, only getfield
2655 if (is_static) {
2656 rc = may_not_rewrite;
2657 }
2666 __ j(Done);
2667
2668 __ bind(notByte);
2669 __ subi(t0, tos_state, (u1)ztos);
2670 __ bnez(t0, notBool);
2671
2672 // ztos (same code as btos)
2673 __ access_load_at(T_BOOLEAN, IN_HEAP, x10, field, noreg, noreg);
2674 __ push(ztos);
2675 // Rewrite bytecode to be faster
2676 if (rc == may_rewrite) {
2677 // uses btos rewriting, no truncating to t/f bit is needed for getfield
2678 patch_bytecode(Bytecodes::_fast_bgetfield, bc, x11);
2679 }
2680 __ j(Done);
2681
2682 __ bind(notBool);
2683 __ subi(t0, tos_state, (u1)atos);
2684 __ bnez(t0, notObj);
2685 // atos
2686 if (!Arguments::is_valhalla_enabled()) {
2687 __ load_heap_oop(x10, field, x28, x29, IN_HEAP);
2688 __ push(atos);
2689 if (rc == may_rewrite) {
2690 patch_bytecode(Bytecodes::_fast_agetfield, bc, x11);
2691 }
2692 __ j(Done);
2693 } else { // Valhalla
2694 if (is_static) {
2695 __ load_heap_oop(x10, field, x28, x29);
2696 __ push(atos);
2697 __ j(Done);
2698 } else {
2699 Label is_flat;
2700 __ test_field_is_flat(flags, x28, is_flat);
2701 __ load_heap_oop(x10, field, x28, x29);
2702 __ push(atos);
2703 if (rc == may_rewrite) {
2704 patch_bytecode(Bytecodes::_fast_agetfield, bc, x11);
2705 }
2706 __ j(Done);
2707 __ bind(is_flat);
2708 // field is flat (null-free or nullable with a null-marker)
2709 __ mv(x10, obj);
2710 __ read_flat_field(cache, x10);
2711 __ verify_oop(x10);
2712 __ push(atos);
2713 if (rc == may_rewrite) {
2714 patch_bytecode(Bytecodes::_fast_vgetfield, bc, x11);
2715 }
2716 __ j(Done);
2717 }
2718 }
2719
2720 __ bind(notObj);
2721 __ subi(t0, tos_state, (u1)itos);
2722 __ bnez(t0, notInt);
2723 // itos
2724 __ access_load_at(T_INT, IN_HEAP, x10, field, noreg, noreg);
2725 __ sext(x10, x10, 32);
2726 __ push(itos);
2727 // Rewrite bytecode to be faster
2728 if (rc == may_rewrite) {
2729 patch_bytecode(Bytecodes::_fast_igetfield, bc, x11);
2730 }
2731 __ j(Done);
2732
2733 __ bind(notInt);
2734 __ subi(t0, tos_state, (u1)ctos);
2735 __ bnez(t0, notChar);
2736 // ctos
2737 __ access_load_at(T_CHAR, IN_HEAP, x10, field, noreg, noreg);
2738 __ push(ctos);
2858 // c_rarg1: object pointer set up above (null if static)
2859 // c_rarg2: cache entry pointer
2860 // c_rarg3: jvalue object on the stack
2861 __ call_VM(noreg,
2862 CAST_FROM_FN_PTR(address,
2863 InterpreterRuntime::post_field_modification),
2864 c_rarg1, c_rarg2, c_rarg3);
2865 __ load_field_entry(cache, index);
2866 __ bind(L1);
2867 }
2868 }
2869
2870 void TemplateTable::putfield_or_static(int byte_no, bool is_static, RewriteControl rc) {
2871 transition(vtos, vtos);
2872
2873 const Register cache = x12;
2874 const Register index = x13;
2875 const Register tos_state = x13;
2876 const Register obj = x12;
2877 const Register off = x9;
2878 const Register flags = x16;
2879 const Register bc = x14;
2880
2881 resolve_cache_and_index_for_field(byte_no, cache, index);
2882 jvmti_post_field_mod(cache, index, is_static);
2883 load_resolved_field_entry(obj, cache, tos_state, off, flags, is_static);
2884
2885 Label Done;
2886 {
2887 Label notVolatile;
2888 __ test_bit(t0, flags, ResolvedFieldEntry::is_volatile_shift);
2889 __ beqz(t0, notVolatile);
2890 __ membar(MacroAssembler::StoreStore | MacroAssembler::LoadStore);
2891 __ bind(notVolatile);
2892 }
2893
2894 Label notByte, notBool, notInt, notShort, notChar,
2895 notLong, notFloat, notObj, notDouble;
2896
2897 assert(btos == 0, "change code, btos != 0");
2898 __ bnez(tos_state, notByte);
2899
2900 // Don't rewrite putstatic, only putfield
2901 if (is_static) {
2902 rc = may_not_rewrite;
2903 }
2904
2905 // btos
2906 {
2907 __ pop(btos);
2908 // field address
2927 __ pop(ztos);
2928 // field address
2929 if (!is_static) {
2930 pop_and_check_object(obj);
2931 }
2932 __ add(off, obj, off); // if static, obj from cache, else obj from stack.
2933 const Address field(off, 0);
2934 __ access_store_at(T_BOOLEAN, IN_HEAP, field, x10, noreg, noreg, noreg);
2935 if (rc == may_rewrite) {
2936 patch_bytecode(Bytecodes::_fast_zputfield, bc, x11, true, byte_no);
2937 }
2938 __ j(Done);
2939 }
2940
2941 __ bind(notBool);
2942 __ subi(t0, tos_state, (u1)atos);
2943 __ bnez(t0, notObj);
2944
2945 // atos
2946 {
2947 if (!Arguments::is_valhalla_enabled()) {
2948 __ pop(atos);
2949 // field address
2950 if (!is_static) {
2951 pop_and_check_object(obj);
2952 }
2953 __ add(off, obj, off); // if static, obj from cache, else obj from stack.
2954 const Address field(off, 0);
2955 // Store into the field
2956 __ store_heap_oop(field, x10, x28, x29, x13, IN_HEAP);
2957 if (rc == may_rewrite) {
2958 patch_bytecode(Bytecodes::_fast_aputfield, bc, x11, true, byte_no);
2959 }
2960 __ j(Done);
2961 } else { // Valhalla
2962 __ pop(atos);
2963 if (is_static) {
2964 Label is_nullable;
2965 __ test_field_is_not_null_free_inline_type(flags, x28, is_nullable);
2966 __ null_check(x10); // FIXME JDK-8341120
2967 __ bind(is_nullable);
2968 // field address
2969 __ add(off, obj, off);
2970 const Address field(off, 0);
2971 __ store_heap_oop(field, x10, x28, x29, x13, IN_HEAP);
2972 __ j(Done);
2973 } else {
2974 Label null_free_reference, is_flat, rewrite_inline;
2975 __ test_field_is_flat(flags, x28, is_flat);
2976 __ test_field_is_null_free_inline_type(flags, x28, null_free_reference);
2977 pop_and_check_object(obj);
2978 {
2979 __ add(off, obj, off);
2980 const Address field(off, 0);
2981 // Store into the field
2982 __ store_heap_oop(field, x10, x28, x29, x13, IN_HEAP);
2983 }
2984 if (rc == may_rewrite) {
2985 patch_bytecode(Bytecodes::_fast_aputfield, bc, x9, true, byte_no);
2986 }
2987 __ j(Done);
2988 // Implementation of the inline type semantic
2989 __ bind(null_free_reference);
2990 __ null_check(x10); // FIXME JDK-8341120
2991 pop_and_check_object(obj);
2992 {
2993 // field address
2994 __ add(off, obj, off);
2995 const Address field(off, 0);
2996 // Store into the field
2997 __ store_heap_oop(field, x10, x28, x29, x13, IN_HEAP);
2998 }
2999 __ j(rewrite_inline);
3000 __ bind(is_flat);
3001 pop_and_check_object(x17);
3002 __ write_flat_field(cache, off, index, flags, x17);
3003 __ bind(rewrite_inline);
3004 if (rc == may_rewrite) {
3005 patch_bytecode(Bytecodes::_fast_vputfield, bc, x9, true, byte_no);
3006 }
3007 __ j(Done);
3008 }
3009 } // Valhalla
3010 }
3011
3012 __ bind(notObj);
3013 __ subi(t0, tos_state, (u1)itos);
3014 __ bnez(t0, notInt);
3015
3016 // itos
3017 {
3018 __ pop(itos);
3019 // field address
3020 if (!is_static) {
3021 pop_and_check_object(obj);
3022 }
3023 __ add(off, obj, off); // if static, obj from cache, else obj from stack.
3024 const Address field(off, 0);
3025 __ access_store_at(T_INT, IN_HEAP, field, x10, noreg, noreg, noreg);
3026 if (rc == may_rewrite) {
3027 patch_bytecode(Bytecodes::_fast_iputfield, bc, x11, true, byte_no);
3028 }
3029 __ j(Done);
3124 }
3125 __ add(off, obj, off); // if static, obj from cache, else obj from stack.
3126 const Address field(off, 0);
3127 __ access_store_at(T_DOUBLE, IN_HEAP, field, noreg /* dtos */, noreg, noreg, noreg);
3128 if (rc == may_rewrite) {
3129 patch_bytecode(Bytecodes::_fast_dputfield, bc, x11, true, byte_no);
3130 }
3131 }
3132
3133 #ifdef ASSERT
3134 __ j(Done);
3135
3136 __ bind(notDouble);
3137 __ stop("Bad state");
3138 #endif
3139
3140 __ bind(Done);
3141
3142 {
3143 Label notVolatile;
3144 __ test_bit(t0, flags, ResolvedFieldEntry::is_volatile_shift);
3145 __ beqz(t0, notVolatile);
3146 __ membar(MacroAssembler::StoreLoad | MacroAssembler::StoreStore);
3147 __ bind(notVolatile);
3148 }
3149 }
3150
3151 void TemplateTable::putfield(int byte_no) {
3152 putfield_or_static(byte_no, false);
3153 }
3154
3155 void TemplateTable::nofast_putfield(int byte_no) {
3156 putfield_or_static(byte_no, false, may_not_rewrite);
3157 }
3158
3159 void TemplateTable::putstatic(int byte_no) {
3160 putfield_or_static(byte_no, true);
3161 }
3162
3163 void TemplateTable::jvmti_post_fast_field_mod() {
3164 if (JvmtiExport::can_post_field_modification()) {
3165 // Check to see if a field modification watch has been set before
3166 // we take the time to call into the VM.
3167 Label L2;
3168 __ lwu(c_rarg3, ExternalAddress(JvmtiExport::get_field_modification_count_addr()));
3169 __ beqz(c_rarg3, L2);
3170
3171 __ pop_ptr(x9); // copy the object pointer from tos
3172 __ verify_oop(x9);
3173 __ push_ptr(x9); // put the object pointer back on tos
3174 // Save tos values before call_VM() clobbers them. Since we have
3175 // to do it for every data type, we use the saved values as the
3176 // jvalue object.
3177 switch (bytecode()) { // load values into the jvalue object
3178 case Bytecodes::_fast_vputfield: // fall through
3179 case Bytecodes::_fast_aputfield: __ push_ptr(x10); break;
3180 case Bytecodes::_fast_bputfield: // fall through
3181 case Bytecodes::_fast_zputfield: // fall through
3182 case Bytecodes::_fast_sputfield: // fall through
3183 case Bytecodes::_fast_cputfield: // fall through
3184 case Bytecodes::_fast_iputfield: __ push_i(x10); break;
3185 case Bytecodes::_fast_dputfield: __ push_d(); break;
3186 case Bytecodes::_fast_fputfield: __ push_f(); break;
3187 case Bytecodes::_fast_lputfield: __ push_l(x10); break;
3188
3189 default:
3190 ShouldNotReachHere();
3191 }
3192 __ mv(c_rarg3, esp); // points to jvalue on the stack
3193 // access constant pool cache entry
3194 __ load_field_entry(c_rarg2, x10);
3195 __ verify_oop(x9);
3196 // x9: object pointer copied above
3197 // c_rarg2: cache entry pointer
3198 // c_rarg3: jvalue object on the stack
3199 __ call_VM(noreg,
3200 CAST_FROM_FN_PTR(address,
3201 InterpreterRuntime::post_field_modification),
3202 x9, c_rarg2, c_rarg3);
3203
3204 switch (bytecode()) { // restore tos values
3205 case Bytecodes::_fast_vputfield: // fall through
3206 case Bytecodes::_fast_aputfield: __ pop_ptr(x10); break;
3207 case Bytecodes::_fast_bputfield: // fall through
3208 case Bytecodes::_fast_zputfield: // fall through
3209 case Bytecodes::_fast_sputfield: // fall through
3210 case Bytecodes::_fast_cputfield: // fall through
3211 case Bytecodes::_fast_iputfield: __ pop_i(x10); break;
3212 case Bytecodes::_fast_dputfield: __ pop_d(); break;
3213 case Bytecodes::_fast_fputfield: __ pop_f(); break;
3214 case Bytecodes::_fast_lputfield: __ pop_l(x10); break;
3215 default: break;
3216 }
3217 __ bind(L2);
3218 }
3219 }
3220
3221 void TemplateTable::fast_storefield(TosState state) {
3222 transition(state, vtos);
3223
3224 ByteSize base = ConstantPoolCache::base_offset();
3225
3227
3228 // access constant pool cache
3229 __ load_field_entry(x12, x11);
3230
3231 // X11: field offset, X12: field holder, X13: flags
3232 load_resolved_field_entry(x12, x12, noreg, x11, x13);
3233 __ verify_field_offset(x11);
3234
3235 {
3236 Label notVolatile;
3237 __ test_bit(t0, x13, ResolvedFieldEntry::is_volatile_shift);
3238 __ beqz(t0, notVolatile);
3239 __ membar(MacroAssembler::StoreStore | MacroAssembler::LoadStore);
3240 __ bind(notVolatile);
3241 }
3242
3243 // Get object from stack
3244 pop_and_check_object(x12);
3245
3246 // field address
3247 __ add(t1, x12, x11);
3248 const Address field(t1, 0);
3249
3250 // access field, must not clobber x13 - flags
3251 switch (bytecode()) {
3252 case Bytecodes::_fast_vputfield:
3253 {
3254 Label is_flat, done;
3255 __ test_field_is_flat(x13, x28, is_flat);
3256 __ null_check(x10);
3257 __ store_heap_oop(field, x10, x28, x29, x15, IN_HEAP);
3258 __ j(done);
3259 __ bind(is_flat);
3260 __ load_field_entry(x14, x13);
3261 // Re-shuffle registers because of VM calls calling convention
3262 __ mv(x9, x11);
3263 __ mv(x17, x12);
3264 __ write_flat_field(x14, x9, x16, x18, x17);
3265 __ bind(done);
3266 }
3267 break;
3268 case Bytecodes::_fast_aputfield:
3269 __ store_heap_oop(field, x10, x28, x29, x15, IN_HEAP);
3270 break;
3271 case Bytecodes::_fast_lputfield:
3272 __ access_store_at(T_LONG, IN_HEAP, field, x10, noreg, noreg, noreg);
3273 break;
3274 case Bytecodes::_fast_iputfield:
3275 __ access_store_at(T_INT, IN_HEAP, field, x10, noreg, noreg, noreg);
3276 break;
3277 case Bytecodes::_fast_zputfield:
3278 __ access_store_at(T_BOOLEAN, IN_HEAP, field, x10, noreg, noreg, noreg);
3279 break;
3280 case Bytecodes::_fast_bputfield:
3281 __ access_store_at(T_BYTE, IN_HEAP, field, x10, noreg, noreg, noreg);
3282 break;
3283 case Bytecodes::_fast_sputfield:
3284 __ access_store_at(T_SHORT, IN_HEAP, field, x10, noreg, noreg, noreg);
3285 break;
3286 case Bytecodes::_fast_cputfield:
3287 __ access_store_at(T_CHAR, IN_HEAP, field, x10, noreg, noreg, noreg);
3329 __ pop_ptr(x10); // restore object pointer
3330 __ bind(L1);
3331 }
3332
3333 // access constant pool cache
3334 __ load_field_entry(x12, x11);
3335
3336 __ load_sized_value(x11, Address(x12, in_bytes(ResolvedFieldEntry::field_offset_offset())), sizeof(int), true /*is_signed*/);
3337 __ verify_field_offset(x11);
3338
3339 __ load_unsigned_byte(x13, Address(x12, in_bytes(ResolvedFieldEntry::flags_offset())));
3340
3341 // x10: object
3342 __ verify_oop(x10);
3343 __ null_check(x10);
3344 __ add(x11, x10, x11);
3345 const Address field(x11, 0);
3346
3347 // access field
3348 switch (bytecode()) {
3349 case Bytecodes::_fast_vgetfield:
3350 {
3351 // field is flat
3352 __ read_flat_field(x12, x10);
3353 __ verify_oop(x10);
3354 }
3355 break;
3356 case Bytecodes::_fast_agetfield:
3357 __ load_heap_oop(x10, field, x28, x29, IN_HEAP);
3358 __ verify_oop(x10);
3359 break;
3360 case Bytecodes::_fast_lgetfield:
3361 __ access_load_at(T_LONG, IN_HEAP, x10, field, noreg, noreg);
3362 break;
3363 case Bytecodes::_fast_igetfield:
3364 __ access_load_at(T_INT, IN_HEAP, x10, field, noreg, noreg);
3365 __ sext(x10, x10, 32);
3366 break;
3367 case Bytecodes::_fast_bgetfield:
3368 __ access_load_at(T_BYTE, IN_HEAP, x10, field, noreg, noreg);
3369 break;
3370 case Bytecodes::_fast_sgetfield:
3371 __ access_load_at(T_SHORT, IN_HEAP, x10, field, noreg, noreg);
3372 break;
3373 case Bytecodes::_fast_cgetfield:
3374 __ access_load_at(T_CHAR, IN_HEAP, x10, field, noreg, noreg);
3375 break;
3743 // This is done before loading InstanceKlass to be consistent with the order
3744 // how Constant Pool is update (see ConstantPool::klass_at_put)
3745 const int tags_offset = Array<u1>::base_offset_in_bytes();
3746 __ add(t0, x10, x13);
3747 __ la(t0, Address(t0, tags_offset));
3748 __ lbu(t0, t0);
3749 __ membar(MacroAssembler::LoadLoad | MacroAssembler::LoadStore);
3750 __ subi(t1, t0, (u1)JVM_CONSTANT_Class);
3751 __ bnez(t1, slow_case);
3752
3753 // get InstanceKlass
3754 __ load_resolved_klass_at_offset(x14, x13, x14, t0);
3755
3756 // make sure klass is initialized
3757 assert(VM_Version::supports_fast_class_init_checks(),
3758 "Optimization requires support for fast class initialization checks");
3759 __ clinit_barrier(x14, t0, nullptr /*L_fast_path*/, &slow_case);
3760
3761 // get instance_size in InstanceKlass (scaled to a count of bytes)
3762 __ lwu(x13, Address(x14, Klass::layout_helper_offset()));
3763 // test to see if it is malformed in some way
3764 __ test_bit(t0, x13, exact_log2(Klass::_lh_instance_slow_path_bit));
3765 __ bnez(t0, slow_case);
3766
3767 // Allocate the instance:
3768 // If TLAB is enabled:
3769 // Try to allocate in the TLAB.
3770 // If fails, go to the slow path.
3771 // Initialize the allocation.
3772 // Exit.
3773 //
3774 // Go to slow path.
3775
3776 if (UseTLAB) {
3777 __ tlab_allocate(x10, x13, 0, noreg, x11, slow_case);
3778
3779 if (ZeroTLAB) {
3780 // the fields have been already cleared
3781 __ j(initialize_header);
3782 }
3783
3784 // The object is initialized before the header. If the object size is
3785 // zero, go directly to the header initialization.
3786 int header_size = oopDesc::header_size() * HeapWordSize;
3787 assert(is_aligned(header_size, BytesPerLong), "oop header size must be 8-byte-aligned");
3788 __ subi(x13, x13, header_size);
3789 __ beqz(x13, initialize_header);
3790
3791 #ifdef ASSERT
3792 // make sure instance_size was multiple of 8
3793 Label L;
3794 __ andi(t0, x13, 7);
3795 __ beqz(t0, L);
3796 __ stop("object size is not multiple of 8 - adjust this code");
3797 __ bind(L);
3798 // must be > 0, no extra check needed here
3799 #endif
3800
3801 // Initialize object fields
3802 {
3803 __ addi(x12, x10, header_size);
3804 Label loop;
3805 __ bind(loop);
3806 __ sd(zr, Address(x12, 0));
3807 __ addi(x12, x12, BytesPerLong);
3808 __ subi(x13, x13, BytesPerLong);
3809 __ bnez(x13, loop);
3810 }
3811
3812 // initialize object header only.
3813 __ bind(initialize_header);
3814 if (UseCompactObjectHeaders || Arguments::is_valhalla_enabled()) {
3815 __ ld(t1, Address(x14, Klass::prototype_header_offset()));
3816 __ sd(t1, Address(x10, oopDesc::mark_offset_in_bytes()));
3817 } else {
3818 __ mv(t1, (intptr_t)markWord::prototype().value());
3819 __ sd(t1, Address(x10, oopDesc::mark_offset_in_bytes()));
3820 }
3821 if (!UseCompactObjectHeaders) {
3822 __ store_klass_gap(x10, zr); // zero klass gap for compressed oops
3823 __ store_klass(x10, x14); // store klass last
3824 }
3825
3826 if (DTraceAllocProbes) {
3827 // Trigger dtrace event for fastpath
3828 __ push(atos); // save the return value
3829 __ call_VM_leaf(
3830 CAST_FROM_FN_PTR(address, static_cast<int (*)(oopDesc*)>(SharedRuntime::dtrace_object_alloc)), x10);
3831 __ pop(atos); // restore the return value
3832
3833 }
3834 __ j(done);
3835 }
3836
3837 // slow case
3838 __ bind(slow_case);
3839 __ get_constant_pool(c_rarg1);
3840 __ get_unsigned_2_byte_index_at_bcp(c_rarg2, 1);
3841 __ call_VM_preemptable(x10, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), c_rarg1, c_rarg2);
3842 __ verify_oop(x10);
3843
3844 // continue
3845 __ bind(done);
3846 // Must prevent reordering of stores for object initialization with stores that publish the new object.
3847 __ membar(MacroAssembler::StoreStore);
3848 }
3849
3850 void TemplateTable::newarray() {
3851 transition(itos, atos);
3852 __ load_unsigned_byte(c_rarg1, at_bcp(1));
3899 __ bind(quicked);
3900 __ mv(x13, x10); // Save object in x13; x10 needed for subtype check
3901 __ load_resolved_klass_at_offset(x12, x9, x10, t0); // x10 = klass
3902
3903 __ bind(resolved);
3904 __ load_klass(x9, x13);
3905
3906 // Generate subtype check. Blows x12, x15. Object in x13.
3907 // Superklass in x10. Subklass in x9.
3908 __ gen_subtype_check(x9, ok_is_subtype);
3909
3910 // Come here on failure
3911 __ push_reg(x13);
3912 // object is at TOS
3913 __ j(RuntimeAddress(Interpreter::_throw_ClassCastException_entry));
3914
3915 // Come here on success
3916 __ bind(ok_is_subtype);
3917 __ mv(x10, x13); // Restore object in x13
3918
3919 __ j(done);
3920 __ bind(is_null);
3921
3922 // Collect counts on whether this test sees nulls a lot or not.
3923 if (ProfileInterpreter) {
3924 __ profile_null_seen(x12);
3925 }
3926 __ bind(done);
3927 }
3928
3929 void TemplateTable::instanceof() {
3930 transition(atos, itos);
3931 Label done, is_null, ok_is_subtype, quicked, resolved;
3932 __ beqz(x10, is_null);
3933
3934 // Get cpool & tags index
3935 __ get_cpool_and_tags(x12, x13); // x12=cpool, x13=tags array
3936 __ get_unsigned_2_byte_index_at_bcp(x9, 1); // x9=index
3937 // See if bytecode has already been quicked
3938 __ addi(t0, x13, Array<u1>::base_offset_in_bytes());
3939 __ add(x11, t0, x9);
3940 __ lbu(x11, x11);
3941 __ membar(MacroAssembler::LoadLoad | MacroAssembler::LoadStore);
3942 __ subi(t0, x11, (u1)JVM_CONSTANT_Class);
3943 __ beqz(t0, quicked);
3944
4025 // in the assembly code structure as well
4026 //
4027 // Stack layout:
4028 //
4029 // [expressions ] <--- esp = expression stack top
4030 // ..
4031 // [expressions ]
4032 // [monitor entry] <--- monitor block top = expression stack bot
4033 // ..
4034 // [monitor entry]
4035 // [frame data ] <--- monitor block bot
4036 // ...
4037 // [saved fp ] <--- fp
4038
4039 void TemplateTable::monitorenter() {
4040 transition(atos, vtos);
4041
4042 // check for null object
4043 __ null_check(x10);
4044
4045 Label is_inline_type;
4046 __ ld(t0, Address(x10, oopDesc::mark_offset_in_bytes()));
4047 __ test_markword_is_inline_type(t0, is_inline_type);
4048
4049 const Address monitor_block_top(
4050 fp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
4051 const Address monitor_block_bot(
4052 fp, frame::interpreter_frame_initial_sp_offset * wordSize);
4053 const int entry_size = frame::interpreter_frame_monitor_size_in_bytes();
4054
4055 Label allocated;
4056
4057 // initialize entry pointer
4058 __ mv(c_rarg1, zr); // points to free slot or null
4059
4060 // find a free slot in the monitor block (result in c_rarg1)
4061 {
4062 Label entry, loop, exit, notUsed;
4063 __ ld(c_rarg3, monitor_block_top); // derelativize pointer
4064 __ shadd(c_rarg3, c_rarg3, fp, c_rarg3, LogBytesPerWord);
4065 // Now c_rarg3 points to current entry, starting with top-most entry
4066
4067 __ la(c_rarg2, monitor_block_bot); // points to word before bottom
4068
4128 // c_rarg1: points to monitor entry
4129 __ bind(allocated);
4130
4131 // Increment bcp to point to the next bytecode, so exception
4132 // handling for async. exceptions work correctly.
4133 // The object has already been popped from the stack, so the
4134 // expression stack looks correct.
4135 __ addi(xbcp, xbcp, 1);
4136
4137 // store object
4138 __ sd(x10, Address(c_rarg1, BasicObjectLock::obj_offset()));
4139 __ lock_object(c_rarg1);
4140
4141 // check to make sure this monitor doesn't cause stack overflow after locking
4142 __ save_bcp(); // in case of exception
4143 __ generate_stack_overflow_check(0);
4144
4145 // The bcp has already been incremented. Just need to dispatch to
4146 // next instruction.
4147 __ dispatch_next(vtos);
4148
4149 __ bind(is_inline_type);
4150 __ call_VM(noreg, CAST_FROM_FN_PTR(address,
4151 InterpreterRuntime::throw_identity_exception), x10);
4152 __ should_not_reach_here();
4153 }
4154
4155 void TemplateTable::monitorexit() {
4156 transition(atos, vtos);
4157
4158 // check for null object
4159 __ null_check(x10);
4160
4161 const int is_inline_type_mask = markWord::inline_type_pattern;
4162 Label has_identity;
4163 __ ld(t0, Address(x10, oopDesc::mark_offset_in_bytes()));
4164 __ mv(t1, is_inline_type_mask);
4165 __ andr(t0, t0, t1);
4166 __ bne(t0, t1, has_identity);
4167 __ call_VM(noreg, CAST_FROM_FN_PTR(address,
4168 InterpreterRuntime::throw_illegal_monitor_state_exception));
4169 __ should_not_reach_here();
4170 __ bind(has_identity);
4171
4172 const Address monitor_block_top(
4173 fp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
4174 const Address monitor_block_bot(
4175 fp, frame::interpreter_frame_initial_sp_offset * wordSize);
4176 const int entry_size = frame::interpreter_frame_monitor_size_in_bytes();
4177
4178 Label found;
4179
4180 // find matching slot
4181 {
4182 Label entry, loop;
4183 __ ld(c_rarg1, monitor_block_top); // derelativize pointer
4184 __ shadd(c_rarg1, c_rarg1, fp, c_rarg1, LogBytesPerWord);
4185 // Now c_rarg1 points to current entry, starting with top-most entry
4186
4187 __ la(c_rarg2, monitor_block_bot); // points to word before bottom
4188 // of monitor block
4189 __ j(entry);
4190
4191 __ bind(loop);
|