1 /*
2 * Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2013, 2025 SAP SE. 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.
23 *
85 DecoratorSet decorators) {
86 assert_different_registers(base, tmp1, tmp2);
87 assert_different_registers(dst, tmp1, tmp2);
88 __ load_heap_oop(dst, offset, base, tmp1, tmp2, MacroAssembler::PRESERVATION_NONE, decorators);
89 }
90
91 Address TemplateTable::at_bcp(int offset) {
92 // Not used on ppc.
93 ShouldNotReachHere();
94 return Address();
95 }
96
97 // Patches the current bytecode (ptr to it located in bcp)
98 // in the bytecode stream with a new one.
99 void TemplateTable::patch_bytecode(Bytecodes::Code new_bc, Register Rnew_bc, Register Rtemp, bool load_bc_into_bc_reg /*=true*/, int byte_no) {
100 // With sharing on, may need to test method flag.
101 if (!RewriteBytecodes) return;
102 Label L_patch_done;
103
104 switch (new_bc) {
105 case Bytecodes::_fast_aputfield:
106 case Bytecodes::_fast_bputfield:
107 case Bytecodes::_fast_zputfield:
108 case Bytecodes::_fast_cputfield:
109 case Bytecodes::_fast_dputfield:
110 case Bytecodes::_fast_fputfield:
111 case Bytecodes::_fast_iputfield:
112 case Bytecodes::_fast_lputfield:
113 case Bytecodes::_fast_sputfield:
114 {
115 // We skip bytecode quickening for putfield instructions when
116 // the put_code written to the constant pool cache is zero.
117 // This is required so that every execution of this instruction
118 // calls out to InterpreterRuntime::resolve_get_put to do
119 // additional, required work.
120 assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
121 assert(load_bc_into_bc_reg, "we use bc_reg as temp");
122 __ load_field_entry(Rtemp, Rnew_bc);
123 int code_offset = (byte_no == f1_byte) ? in_bytes(ResolvedFieldEntry::get_code_offset())
124 : in_bytes(ResolvedFieldEntry::put_code_offset());
667 void TemplateTable::daload() {
668 transition(itos, dtos);
669
670 const Register Rload_addr = R3_ARG1,
671 Rarray = R4_ARG2,
672 Rtemp = R5_ARG3;
673 __ index_check(Rarray, R17_tos /* index */, LogBytesPerLong, Rtemp, Rload_addr);
674 __ lfd(F15_ftos, arrayOopDesc::base_offset_in_bytes(T_DOUBLE), Rload_addr);
675 }
676
677 void TemplateTable::aaload() {
678 transition(itos, atos);
679
680 // tos: index
681 // result tos: array
682 const Register Rload_addr = R3_ARG1,
683 Rarray = R4_ARG2,
684 Rtemp = R5_ARG3,
685 Rtemp2 = R31;
686 __ index_check(Rarray, R17_tos /* index */, UseCompressedOops ? 2 : LogBytesPerWord, Rtemp, Rload_addr);
687 do_oop_load(_masm, Rload_addr, arrayOopDesc::base_offset_in_bytes(T_OBJECT), R17_tos, Rtemp, Rtemp2,
688 IS_ARRAY);
689 __ verify_oop(R17_tos);
690 //__ dcbt(R17_tos); // prefetch
691 }
692
693 void TemplateTable::baload() {
694 transition(itos, itos);
695
696 const Register Rload_addr = R3_ARG1,
697 Rarray = R4_ARG2,
698 Rtemp = R5_ARG3;
699 __ index_check(Rarray, R17_tos /* index */, 0, Rtemp, Rload_addr);
700 __ lbz(R17_tos, arrayOopDesc::base_offset_in_bytes(T_BYTE), Rload_addr);
701 __ extsb(R17_tos, R17_tos);
702 }
703
704 void TemplateTable::caload() {
705 transition(itos, itos);
706
707 const Register Rload_addr = R3_ARG1,
708 Rarray = R4_ARG2,
709 Rtemp = R5_ARG3;
956 __ index_check(Rarray, Rindex, LogBytesPerInt, Rtemp, Rstore_addr);
957 __ stfs(F15_ftos, arrayOopDesc::base_offset_in_bytes(T_FLOAT), Rstore_addr);
958 }
959
960 void TemplateTable::dastore() {
961 transition(dtos, vtos);
962
963 const Register Rindex = R3_ARG1,
964 Rstore_addr = R4_ARG2,
965 Rarray = R5_ARG3,
966 Rtemp = R6_ARG4;
967 __ pop_i(Rindex);
968 __ index_check(Rarray, Rindex, LogBytesPerLong, Rtemp, Rstore_addr);
969 __ stfd(F15_ftos, arrayOopDesc::base_offset_in_bytes(T_DOUBLE), Rstore_addr);
970 }
971
972 // Pop 3 values from the stack and...
973 void TemplateTable::aastore() {
974 transition(vtos, vtos);
975
976 Label Lstore_ok, Lis_null, Ldone;
977 const Register Rindex = R3_ARG1,
978 Rarray = R4_ARG2,
979 Rscratch = R11_scratch1,
980 Rscratch2 = R12_scratch2,
981 Rarray_klass = R5_ARG3,
982 Rarray_element_klass = Rarray_klass,
983 Rvalue_klass = R6_ARG4,
984 Rstore_addr = R31; // Use register which survives VM call.
985
986 __ ld(R17_tos, Interpreter::expr_offset_in_bytes(0), R15_esp); // Get value to store.
987 __ lwz(Rindex, Interpreter::expr_offset_in_bytes(1), R15_esp); // Get index.
988 __ ld(Rarray, Interpreter::expr_offset_in_bytes(2), R15_esp); // Get array.
989
990 __ verify_oop(R17_tos);
991 __ index_check_without_pop(Rarray, Rindex, UseCompressedOops ? 2 : LogBytesPerWord, Rscratch, Rstore_addr);
992 // Rindex is dead!
993 Register Rscratch3 = Rindex;
994
995 // Do array store check - check for null value first.
996 __ cmpdi(CR0, R17_tos, 0);
997 __ beq(CR0, Lis_null);
998
999 __ load_klass(Rarray_klass, Rarray);
1000 __ load_klass(Rvalue_klass, R17_tos);
1001
1002 // Do fast instanceof cache test.
1003 __ ld(Rarray_element_klass, in_bytes(ObjArrayKlass::element_klass_offset()), Rarray_klass);
1004
1005 // Generate a fast subtype check. Branch to store_ok if no failure. Throw if failure.
1006 __ gen_subtype_check(Rvalue_klass /*subklass*/, Rarray_element_klass /*superklass*/, Rscratch, Rscratch2, Rscratch3, Lstore_ok);
1007
1008 // Fell through: subtype check failed => throw an exception.
1009 __ load_dispatch_table(R11_scratch1, (address*)Interpreter::_throw_ArrayStoreException_entry);
1010 __ mtctr(R11_scratch1);
1011 __ bctr();
1012
1013 __ bind(Lis_null);
1014 do_oop_store(_masm, Rstore_addr, arrayOopDesc::base_offset_in_bytes(T_OBJECT), noreg /* 0 */,
1015 Rscratch, Rscratch2, Rscratch3, IS_ARRAY);
1016 __ profile_null_seen(Rscratch, Rscratch2);
1017 __ b(Ldone);
1018
1019 // Store is OK.
1020 __ bind(Lstore_ok);
1021 do_oop_store(_masm, Rstore_addr, arrayOopDesc::base_offset_in_bytes(T_OBJECT), R17_tos /* value */,
1022 Rscratch, Rscratch2, Rscratch3, IS_ARRAY | IS_NOT_NULL);
1023
1024 __ bind(Ldone);
1025 // Adjust sp (pops array, index and value).
1026 __ addi(R15_esp, R15_esp, 3 * Interpreter::stackElementSize);
1027 }
1028
1029 void TemplateTable::bastore() {
1030 transition(itos, vtos);
1031
1032 const Register Rindex = R11_scratch1,
1033 Rarray = R12_scratch2,
1034 Rscratch = R3_ARG1;
1035 __ pop_i(Rindex);
1036 __ pop_ptr(Rarray);
1037 // tos: val
1038
1039 // Need to check whether array is boolean or byte
1736 __ reset_last_Java_frame();
1737 // OSR buffer is in ARG1.
1738
1739 // Remove the interpreter frame.
1740 __ merge_frames(/*top_frame_sp*/ R21_sender_SP, /*return_pc*/ R12_scratch2, R11_scratch1, R0);
1741 JFR_ONLY(__ leave_jfr_critical_section();)
1742
1743 // Jump to the osr code.
1744 __ ld(R11_scratch1, nmethod::osr_entry_point_offset(), osr_nmethod);
1745 __ mtlr(R12_scratch2);
1746 __ mtctr(R11_scratch1);
1747 __ bctr();
1748
1749 __ bind(Lforward);
1750 }
1751 __ dispatch_next(vtos, 0, true);
1752 }
1753
1754 // Helper function for if_cmp* methods below.
1755 // Factored out common compare and branch code.
1756 void TemplateTable::if_cmp_common(Register Rfirst, Register Rsecond, Register Rscratch1, Register Rscratch2, Condition cc, bool is_jint, bool cmp0) {
1757 Label Lnot_taken;
1758 // Note: The condition code we get is the condition under which we
1759 // *fall through*! So we have to inverse the CC here.
1760
1761 if (is_jint) {
1762 if (cmp0) {
1763 __ cmpwi(CR0, Rfirst, 0);
1764 } else {
1765 __ cmpw(CR0, Rfirst, Rsecond);
1766 }
1767 } else {
1768 if (cmp0) {
1769 __ cmpdi(CR0, Rfirst, 0);
1770 } else {
1771 __ cmpd(CR0, Rfirst, Rsecond);
1772 }
1773 }
1774 branch_conditional(CR0, cc, Lnot_taken, /*invert*/ true);
1775
1776 // Conition is false => Jump!
1777 branch(false, false);
1778
1779 // Condition is not true => Continue.
1780 __ align(32, 12);
1781 __ bind(Lnot_taken);
1782 __ profile_not_taken_branch(Rscratch1, Rscratch2);
1783 }
1784
1785 // Compare integer values with zero and fall through if CC holds, branch away otherwise.
1786 void TemplateTable::if_0cmp(Condition cc) {
1787 transition(itos, vtos);
1788
1789 if_cmp_common(R17_tos, noreg, R11_scratch1, R12_scratch2, cc, true, true);
1790 }
1791
1792 // Compare integer values and fall through if CC holds, branch away otherwise.
1793 //
1794 // Interface:
1795 // - Rfirst: First operand (older stack value)
1796 // - tos: Second operand (younger stack value)
1797 void TemplateTable::if_icmp(Condition cc) {
1798 transition(itos, vtos);
1799
1800 const Register Rfirst = R0,
1801 Rsecond = R17_tos;
1802
1803 __ pop_i(Rfirst);
1804 if_cmp_common(Rfirst, Rsecond, R11_scratch1, R12_scratch2, cc, true, false);
1805 }
1806
1807 void TemplateTable::if_nullcmp(Condition cc) {
1808 transition(atos, vtos);
1809
1810 if_cmp_common(R17_tos, noreg, R11_scratch1, R12_scratch2, cc, false, true);
1811 }
1812
1813 void TemplateTable::if_acmp(Condition cc) {
1814 transition(atos, vtos);
1815
1816 const Register Rfirst = R0,
1817 Rsecond = R17_tos;
1818
1819 __ pop_ptr(Rfirst);
1820 if_cmp_common(Rfirst, Rsecond, R11_scratch1, R12_scratch2, cc, false, false);
1821 }
1822
1823 void TemplateTable::ret() {
1824 locals_index(R11_scratch1);
1825 __ load_local_ptr(R17_tos, R11_scratch1, R11_scratch1);
1826
1827 __ profile_ret(vtos, R17_tos, R11_scratch1, R12_scratch2);
1828
1829 __ ld(R11_scratch1, in_bytes(Method::const_offset()), R19_method);
1830 __ add(R11_scratch1, R17_tos, R11_scratch1);
1831 __ addi(R14_bcp, R11_scratch1, in_bytes(ConstMethod::codes_offset()));
1832 __ dispatch_next(vtos, 0, true);
1833 }
1834
1835 void TemplateTable::wide_ret() {
1836 transition(vtos, vtos);
1837
1838 const Register Rindex = R3_ARG1,
1839 Rscratch1 = R11_scratch1,
1840 Rscratch2 = R12_scratch2;
2720 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode()));
2721
2722 __ align(32, 28, 28); // Align load.
2723 // __ bind(Lstos);
2724 __ fence(); // Volatile entry point (one instruction before non-volatile_entry point).
2725 assert(branch_table[stos] == nullptr, "can't compute twice");
2726 branch_table[stos] = __ pc(); // non-volatile_entry point
2727 __ lhax(R17_tos, Rclass_or_obj, Roffset);
2728 __ push(stos);
2729 if (!is_static && rc == may_rewrite) {
2730 patch_bytecode(Bytecodes::_fast_sgetfield, Rbc, Rscratch);
2731 }
2732 __ beq(CR2, Lacquire); // Volatile?
2733 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode()));
2734
2735 __ align(32, 28, 28); // Align load.
2736 // __ bind(Latos);
2737 __ fence(); // Volatile entry point (one instruction before non-volatile_entry point).
2738 assert(branch_table[atos] == nullptr, "can't compute twice");
2739 branch_table[atos] = __ pc(); // non-volatile_entry point
2740 do_oop_load(_masm, Rclass_or_obj, Roffset, R17_tos, Rscratch, /* nv temp */ Rflags, IN_HEAP);
2741 __ verify_oop(R17_tos);
2742 __ push(atos);
2743 //__ dcbt(R17_tos); // prefetch
2744 if (!is_static && rc == may_rewrite) {
2745 patch_bytecode(Bytecodes::_fast_agetfield, Rbc, Rscratch);
2746 }
2747 __ beq(CR2, Lacquire); // Volatile?
2748 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode()));
2749
2750 __ align(32, 12);
2751 __ bind(Lacquire);
2752 __ twi_0(R17_tos);
2753 __ bind(Lisync);
2754 __ isync(); // acquire
2755
2756 #ifdef ASSERT
2757 for (int i = 0; i<number_of_states; ++i) {
2758 assert(branch_table[i], "get initialization");
2759 //tty->print_cr("get: %s_branch_table[%d] = 0x%llx (opcode 0x%llx)",
2760 // is_static ? "static" : "field", i, branch_table[i], *((unsigned int*)branch_table[i]));
2761 }
2762 #endif
2763 }
2764
2765 void TemplateTable::getfield(int byte_no) {
2766 getfield_or_static(byte_no, false);
2767 }
2768
2769 void TemplateTable::nofast_getfield(int byte_no) {
2770 getfield_or_static(byte_no, false, may_not_rewrite);
2771 }
2772
2773 void TemplateTable::getstatic(int byte_no) {
2774 getfield_or_static(byte_no, true);
2775 }
2776
2777 // The registers cache and index expected to be set before call.
2778 // The function may destroy various registers, just not the cache and index registers.
2779 void TemplateTable::jvmti_post_field_mod(Register Rcache, Register Rscratch, bool is_static) {
2780
2781 assert_different_registers(Rcache, Rscratch, R6_ARG4);
2782
2783 if (JvmtiExport::can_post_field_modification()) {
2784 Label Lno_field_mod_post;
2785
2786 // Check if post field access in enabled.
2787 int offs = __ load_const_optimized(Rscratch, JvmtiExport::get_field_modification_count_addr(), R0, true);
2788 __ lwz(Rscratch, offs, Rscratch);
2789
2790 __ cmpwi(CR0, Rscratch, 0);
2791 __ beq(CR0, Lno_field_mod_post);
2792
2793 // Do the post
2794 const Register Robj = Rscratch;
2795
2796 if (is_static) {
2797 // Life is simple. Null out the object pointer.
2798 __ li(Robj, 0);
2799 } else {
2800 // In case of the fast versions, value lives in registers => put it back on tos.
2801 int offs = Interpreter::expr_offset_in_bytes(0);
2802 Register base = R15_esp;
2803 switch(bytecode()) {
2804 case Bytecodes::_fast_aputfield: __ push_ptr(); offs+= Interpreter::stackElementSize; break;
2805 case Bytecodes::_fast_iputfield: // Fall through
2806 case Bytecodes::_fast_bputfield: // Fall through
2807 case Bytecodes::_fast_zputfield: // Fall through
2808 case Bytecodes::_fast_cputfield: // Fall through
2809 case Bytecodes::_fast_sputfield: __ push_i(); offs+= Interpreter::stackElementSize; break;
2810 case Bytecodes::_fast_lputfield: __ push_l(); offs+=2*Interpreter::stackElementSize; break;
2811 case Bytecodes::_fast_fputfield: __ push_f(); offs+= Interpreter::stackElementSize; break;
2812 case Bytecodes::_fast_dputfield: __ push_d(); offs+=2*Interpreter::stackElementSize; break;
2813 default: {
2814 offs = 0;
2815 base = Robj;
2816 const Register Rtos_state = Robj;
2817 Label is_one_slot;
2818 // Life is harder. The stack holds the value on top, followed by the
2819 // object. We don't know the size of the value, though; it could be
2820 // one or two words depending on its type. As a result, we must find
2821 // the type to determine where the object is.
2822 __ lbz(Rtos_state, in_bytes(ResolvedFieldEntry::type_offset()), Rcache);
2823
2824 __ cmpwi(CR0, Rtos_state, ltos);
2825 __ cmpwi(CR1, Rtos_state, dtos);
2826 __ addi(base, R15_esp, Interpreter::expr_offset_in_bytes(1));
2827 __ crnor(CR0, Assembler::equal, CR1, Assembler::equal);
2828 __ beq(CR0, is_one_slot);
2829 __ addi(base, R15_esp, Interpreter::expr_offset_in_bytes(2));
2830 __ bind(is_one_slot);
2831 break;
2832 }
2833 }
2834 __ ld(Robj, offs, base);
2835 __ verify_oop(Robj);
2836 }
2837
2838 __ addi(R6_ARG4, R15_esp, Interpreter::expr_offset_in_bytes(0));
2839 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification), Robj, Rcache, R6_ARG4);
2840 __ load_field_entry(Rcache, Rscratch);
2841
2842 // In case of the fast versions, value lives in registers => put it back on tos.
2843 switch(bytecode()) {
2844 case Bytecodes::_fast_aputfield: __ pop_ptr(); break;
2845 case Bytecodes::_fast_iputfield: // Fall through
2846 case Bytecodes::_fast_bputfield: // Fall through
2847 case Bytecodes::_fast_zputfield: // Fall through
2848 case Bytecodes::_fast_cputfield: // Fall through
2849 case Bytecodes::_fast_sputfield: __ pop_i(); break;
2850 case Bytecodes::_fast_lputfield: __ pop_l(); break;
2851 case Bytecodes::_fast_fputfield: __ pop_f(); break;
2852 case Bytecodes::_fast_dputfield: __ pop_d(); break;
2853 default: break; // Nothin' to do.
2854 }
2855
2856 __ align(32, 12);
2857 __ bind(Lno_field_mod_post);
2858 }
2859 }
2860
2861 // PPC64: implement volatile stores as release-store (return bytecode contains an additional release).
2862 void TemplateTable::putfield_or_static(int byte_no, bool is_static, RewriteControl rc) {
2863 Label Lvolatile;
2864
2865 const Register Rcache = R5_ARG3, // Do not use ARG1/2 (causes trouble in jvmti_post_field_mod).
2866 Rclass_or_obj = R31, // Needs to survive C call.
2867 Roffset = R22_tmp2, // Needs to survive C call.
2868 Rtos_state = R23_tmp3, // Needs to survive C call.
2869 Rflags = R30, // Needs to survive C call.
2870 Rbtable = R4_ARG2,
2871 Rscratch = R11_scratch1, // used by load_field_cp_cache_entry
2872 Rscratch2 = R12_scratch2, // used by load_field_cp_cache_entry
2873 Rscratch3 = R6_ARG4,
2874 Rbc = Rscratch3;
2875 const ConditionRegister CR_is_vol = CR2; // Non-volatile condition register (survives runtime call in do_oop_store).
2876
2877 static address field_rw_branch_table[number_of_states],
2878 field_norw_branch_table[number_of_states],
2879 static_branch_table[number_of_states];
2880
2881 address* branch_table = is_static ? static_branch_table :
2882 (rc == may_rewrite ? field_rw_branch_table : field_norw_branch_table);
2883
2884 // Stack (grows up):
2885 // value
2886 // obj
2887
2888 // Load the field offset.
2889 resolve_cache_and_index_for_field(byte_no, Rcache, Rscratch);
2890 jvmti_post_field_mod(Rcache, Rscratch, is_static);
2891 load_resolved_field_entry(Rclass_or_obj, Rcache, Rtos_state, Roffset, Rflags, is_static); // Uses R11, R12
2892
2893 // Load pointer to branch table.
3047 __ release(); // Volatile entry point (one instruction before non-volatile_entry point).
3048 assert(branch_table[stos] == nullptr, "can't compute twice");
3049 branch_table[stos] = __ pc(); // non-volatile_entry point
3050 __ pop(stos);
3051 if (!is_static) { pop_and_check_object(Rclass_or_obj); } // Kills R11_scratch1.
3052 __ sthx(R17_tos, Rclass_or_obj, Roffset);
3053 if (!is_static && rc == may_rewrite) {
3054 patch_bytecode(Bytecodes::_fast_sputfield, Rbc, Rscratch, true, byte_no);
3055 }
3056 if (!support_IRIW_for_not_multiple_copy_atomic_cpu) {
3057 __ beq(CR_is_vol, Lvolatile); // Volatile?
3058 }
3059 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode()));
3060
3061 __ align(32, 28, 28); // Align pop.
3062 // __ bind(Latos);
3063 __ release(); // Volatile entry point (one instruction before non-volatile_entry point).
3064 assert(branch_table[atos] == nullptr, "can't compute twice");
3065 branch_table[atos] = __ pc(); // non-volatile_entry point
3066 __ pop(atos);
3067 if (!is_static) { pop_and_check_object(Rclass_or_obj); } // kills R11_scratch1
3068 do_oop_store(_masm, Rclass_or_obj, Roffset, R17_tos, Rscratch, Rscratch2, Rscratch3, IN_HEAP);
3069 if (!is_static && rc == may_rewrite) {
3070 patch_bytecode(Bytecodes::_fast_aputfield, Rbc, Rscratch, true, byte_no);
3071 }
3072 if (!support_IRIW_for_not_multiple_copy_atomic_cpu) {
3073 __ beq(CR_is_vol, Lvolatile); // Volatile?
3074 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode()));
3075
3076 __ align(32, 12);
3077 __ bind(Lvolatile);
3078 __ fence();
3079 }
3080 // fallthru: __ b(Lexit);
3081
3082 #ifdef ASSERT
3083 for (int i = 0; i<number_of_states; ++i) {
3084 assert(branch_table[i], "put initialization");
3085 //tty->print_cr("put: %s_branch_table[%d] = 0x%llx (opcode 0x%llx)",
3086 // is_static ? "static" : "field", i, branch_table[i], *((unsigned int*)branch_table[i]));
3087 }
3088 #endif
3089 }
3090
3091 void TemplateTable::putfield(int byte_no) {
3092 putfield_or_static(byte_no, false);
3093 }
3094
3095 void TemplateTable::nofast_putfield(int byte_no) {
3096 putfield_or_static(byte_no, false, may_not_rewrite);
3097 }
3098
3099 void TemplateTable::putstatic(int byte_no) {
3100 putfield_or_static(byte_no, true);
3101 }
3102
3103 // On PPC64, we have a different jvmti_post_field_mod which does the job.
3104 void TemplateTable::jvmti_post_fast_field_mod() {
3105 __ should_not_reach_here();
3106 }
3107
3108 void TemplateTable::fast_storefield(TosState state) {
3109 transition(state, vtos);
3110
3111 const Register Rcache = R5_ARG3, // Do not use ARG1/2 (causes trouble in jvmti_post_field_mod).
3112 Rclass_or_obj = R31, // Needs to survive C call.
3113 Roffset = R22_tmp2, // Needs to survive C call.
3114 Rflags = R3_ARG1,
3115 Rscratch = R11_scratch1, // used by load_field_cp_cache_entry
3116 Rscratch2 = R12_scratch2, // used by load_field_cp_cache_entry
3117 Rscratch3 = R4_ARG2;
3118 const ConditionRegister CR_is_vol = CR2; // Non-volatile condition register (survives runtime call in do_oop_store).
3119
3120 // Constant pool already resolved => Load flags and offset of field.
3121 __ load_field_entry(Rcache, Rscratch, 1, /* for_fast_bytecode */ true);
3122 jvmti_post_field_mod(Rcache, Rscratch, false /* not static */);
3123 load_resolved_field_entry(noreg, Rcache, noreg, Roffset, Rflags, false); // Uses R11, R12
3124
3125 // Get the obj and the final store addr.
3126 pop_and_check_object(Rclass_or_obj); // Kills R11_scratch1.
3127
3128 // Get volatile flag.
3129 __ rldicl_(Rscratch, Rflags, 64-ResolvedFieldEntry::is_volatile_shift, 63); // Extract volatile bit.
3130 if (!support_IRIW_for_not_multiple_copy_atomic_cpu) { __ cmpdi(CR_is_vol, Rscratch, 1); }
3131 {
3132 Label LnotVolatile;
3133 __ beq(CR0, LnotVolatile);
3134 __ release();
3135 __ align(32, 12);
3136 __ bind(LnotVolatile);
3137 }
3138
3139 // Do the store and fencing.
3140 switch(bytecode()) {
3141 case Bytecodes::_fast_aputfield:
3142 // Store into the field.
3143 do_oop_store(_masm, Rclass_or_obj, Roffset, R17_tos, Rscratch, Rscratch2, Rscratch3, IN_HEAP);
3144 break;
3145
3146 case Bytecodes::_fast_iputfield:
3147 __ stwx(R17_tos, Rclass_or_obj, Roffset);
3148 break;
3149
3150 case Bytecodes::_fast_lputfield:
3151 __ stdx(R17_tos, Rclass_or_obj, Roffset);
3152 break;
3153
3154 case Bytecodes::_fast_zputfield:
3155 __ andi(R17_tos, R17_tos, 0x1); // boolean is true if LSB is 1
3156 // fall through to bputfield
3157 case Bytecodes::_fast_bputfield:
3158 __ stbx(R17_tos, Rclass_or_obj, Roffset);
3159 break;
3160
3196 Roffset = R22_tmp2,
3197 Rflags = R23_tmp3,
3198 Rscratch = R11_scratch1; // used by load_field_cp_cache_entry
3199 // R12_scratch2 used by load_field_cp_cache_entry
3200
3201 // Constant pool already resolved. Get the field offset.
3202 __ load_field_entry(Rcache, Rscratch, 1, /* for_fast_bytecode */ true);
3203 load_resolved_field_entry(noreg, Rcache, noreg, Roffset, Rflags, false); // Uses R11, R12
3204
3205 // JVMTI support
3206 jvmti_post_field_access(Rcache, Rscratch, false, true);
3207
3208 // Get the load address.
3209 __ null_check_throw(Rclass_or_obj, -1, Rscratch);
3210
3211 // Get volatile flag.
3212 __ rldicl_(Rscratch, Rflags, 64-ResolvedFieldEntry::is_volatile_shift, 63); // Extract volatile bit.
3213 __ bne(CR0, LisVolatile);
3214
3215 switch(bytecode()) {
3216 case Bytecodes::_fast_agetfield:
3217 {
3218 do_oop_load(_masm, Rclass_or_obj, Roffset, R17_tos, Rscratch, /* nv temp */ Rflags, IN_HEAP);
3219 __ verify_oop(R17_tos);
3220 __ dispatch_epilog(state, Bytecodes::length_for(bytecode()));
3221
3222 __ bind(LisVolatile);
3223 if (support_IRIW_for_not_multiple_copy_atomic_cpu) { __ fence(); }
3224 do_oop_load(_masm, Rclass_or_obj, Roffset, R17_tos, Rscratch, /* nv temp */ Rflags, IN_HEAP);
3225 __ verify_oop(R17_tos);
3226 __ twi_0(R17_tos);
3227 __ isync();
3228 break;
3229 }
3230 case Bytecodes::_fast_igetfield:
3231 {
3232 __ lwax(R17_tos, Rclass_or_obj, Roffset);
3233 __ dispatch_epilog(state, Bytecodes::length_for(bytecode()));
3234
3235 __ bind(LisVolatile);
3825
3826 __ std(RnewTopValue, in_bytes(JavaThread::tlab_top_offset()), R16_thread);
3827
3828 if (!ZeroTLAB) {
3829 // --------------------------------------------------------------------------
3830 // Init1: Zero out newly allocated memory.
3831 // Initialize remaining object fields.
3832 Register Rbase = Rtags;
3833 int header_size = oopDesc::header_size() * HeapWordSize;
3834 __ addi(Rinstance_size, Rinstance_size, 7 - header_size);
3835 __ addi(Rbase, RallocatedObject, header_size);
3836 __ srdi(Rinstance_size, Rinstance_size, 3);
3837
3838 // Clear out object skipping header. Takes also care of the zero length case.
3839 __ clear_memory_doubleword(Rbase, Rinstance_size);
3840 }
3841
3842 // --------------------------------------------------------------------------
3843 // Init2: Initialize the header: mark, klass
3844 // Init mark.
3845 if (UseCompactObjectHeaders) {
3846 __ ld(Rscratch, in_bytes(Klass::prototype_header_offset()), RinstanceKlass);
3847 __ std(Rscratch, oopDesc::mark_offset_in_bytes(), RallocatedObject);
3848 } else {
3849 __ load_const_optimized(Rscratch, markWord::prototype().value(), R0);
3850 __ std(Rscratch, oopDesc::mark_offset_in_bytes(), RallocatedObject);
3851 __ store_klass_gap(RallocatedObject);
3852 __ store_klass(RallocatedObject, RinstanceKlass, Rscratch);
3853 }
3854
3855 __ b(Ldone);
3856 }
3857
3858 // --------------------------------------------------------------------------
3859 // slow case
3860 __ bind(Lslow_case);
3861 __ call_VM_preemptable(R17_tos, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), Rcpool, Rindex);
3862
3863 // continue
3864 __ bind(Ldone);
3865
3866 // Must prevent reordering of stores for object initialization with stores that publish the new object.
3867 __ membar(Assembler::StoreStore);
3868 }
3869
3870 void TemplateTable::newarray() {
4093 Rcurrent_obj = R4_ARG2,
4094 Robj_to_lock = R17_tos,
4095 Rscratch1 = R11_scratch1,
4096 Rscratch2 = R12_scratch2,
4097 Rbot = R5_ARG3,
4098 Rfree_slot = R6_ARG4;
4099
4100 Label Lfound, Lallocate_new;
4101
4102 __ ld(Rscratch1, _abi0(callers_sp), R1_SP); // load FP
4103 __ li(Rfree_slot, 0); // Points to free slot or null.
4104
4105 // Set up search loop - start with topmost monitor.
4106 __ mr(Rcurrent_monitor, R26_monitor);
4107 __ addi(Rbot, Rscratch1, -frame::ijava_state_size);
4108
4109 // ------------------------------------------------------------------------------
4110 // Null pointer exception.
4111 __ null_check_throw(Robj_to_lock, -1, Rscratch1);
4112
4113 // Check if any slot is present => short cut to allocation if not.
4114 __ cmpld(CR0, Rcurrent_monitor, Rbot);
4115 __ beq(CR0, Lallocate_new);
4116
4117 // ------------------------------------------------------------------------------
4118 // Find a free slot in the monitor block.
4119 // Note: The order of the monitors is important for C2 OSR which derives the
4120 // unlock order from it (see comments for interpreter_frame_monitor_*).
4121 {
4122 Label Lloop, LnotFree, Lexit;
4123
4124 __ bind(Lloop);
4125 __ ld(Rcurrent_obj, in_bytes(BasicObjectLock::obj_offset()), Rcurrent_monitor);
4126 // Exit if current entry is for same object; this guarantees, that new monitor
4127 // used for recursive lock is above the older one.
4128 __ cmpd(CR0, Rcurrent_obj, Robj_to_lock);
4129 __ beq(CR0, Lexit); // recursive locking
4130
4131 __ cmpdi(CR0, Rcurrent_obj, 0);
4132 __ bne(CR0, LnotFree);
4149 __ add_monitor_to_stack(false, Rscratch1, Rscratch2);
4150 __ mr(Rfree_slot, R26_monitor);
4151
4152 // ------------------------------------------------------------------------------
4153 // We now have a slot to lock.
4154 __ bind(Lfound);
4155
4156 // Increment bcp to point to the next bytecode, so exception handling for async. exceptions work correctly.
4157 // The object has already been popped from the stack, so the expression stack looks correct.
4158 __ addi(R14_bcp, R14_bcp, 1);
4159
4160 __ std(Robj_to_lock, in_bytes(BasicObjectLock::obj_offset()), Rfree_slot);
4161 __ lock_object(Rfree_slot, Robj_to_lock);
4162
4163 // Check if there's enough space on the stack for the monitors after locking.
4164 // This emits a single store.
4165 __ generate_stack_overflow_check(0);
4166
4167 // The bcp has already been incremented. Just need to dispatch to next instruction.
4168 __ dispatch_next(vtos);
4169 }
4170
4171 void TemplateTable::monitorexit() {
4172 transition(atos, vtos);
4173 __ verify_oop(R17_tos);
4174
4175 Register Rcurrent_monitor = R3_ARG1,
4176 Rcurrent_obj = R4_ARG2,
4177 Robj_to_lock = R17_tos,
4178 Rscratch = R11_scratch1,
4179 Rbot = R12_scratch2;
4180
4181 Label Lfound, Lillegal_monitor_state;
4182
4183 __ ld(Rscratch, _abi0(callers_sp), R1_SP); // load FP
4184
4185 // Set up search loop - start with topmost monitor.
4186 __ mr(Rcurrent_monitor, R26_monitor);
4187 __ addi(Rbot, Rscratch, -frame::ijava_state_size);
4188
4189 // Null pointer check.
4190 __ null_check_throw(Robj_to_lock, -1, Rscratch);
4191
4192 // Check corner case: unbalanced monitorEnter / Exit.
4193 __ cmpld(CR0, Rcurrent_monitor, Rbot);
4194 __ beq(CR0, Lillegal_monitor_state);
4195
4196 // Find the corresponding slot in the monitors stack section.
4197 {
4198 Label Lloop;
4199
4200 __ bind(Lloop);
4201 __ ld(Rcurrent_obj, in_bytes(BasicObjectLock::obj_offset()), Rcurrent_monitor);
4202 // Is this entry for same obj?
4203 __ cmpd(CR0, Rcurrent_obj, Robj_to_lock);
4204 __ beq(CR0, Lfound);
4205
4206 __ addi(Rcurrent_monitor, Rcurrent_monitor, frame::interpreter_frame_monitor_size_in_bytes());
4207 __ cmpld(CR0, Rcurrent_monitor, Rbot);
4208 __ bne(CR0, Lloop);
4209 }
4210
4211 // Fell through without finding the basic obj lock => throw up!
|
1 /*
2 * Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2013, 2026 SAP SE. 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.
23 *
85 DecoratorSet decorators) {
86 assert_different_registers(base, tmp1, tmp2);
87 assert_different_registers(dst, tmp1, tmp2);
88 __ load_heap_oop(dst, offset, base, tmp1, tmp2, MacroAssembler::PRESERVATION_NONE, decorators);
89 }
90
91 Address TemplateTable::at_bcp(int offset) {
92 // Not used on ppc.
93 ShouldNotReachHere();
94 return Address();
95 }
96
97 // Patches the current bytecode (ptr to it located in bcp)
98 // in the bytecode stream with a new one.
99 void TemplateTable::patch_bytecode(Bytecodes::Code new_bc, Register Rnew_bc, Register Rtemp, bool load_bc_into_bc_reg /*=true*/, int byte_no) {
100 // With sharing on, may need to test method flag.
101 if (!RewriteBytecodes) return;
102 Label L_patch_done;
103
104 switch (new_bc) {
105 case Bytecodes::_fast_vputfield:
106 case Bytecodes::_fast_aputfield:
107 case Bytecodes::_fast_bputfield:
108 case Bytecodes::_fast_zputfield:
109 case Bytecodes::_fast_cputfield:
110 case Bytecodes::_fast_dputfield:
111 case Bytecodes::_fast_fputfield:
112 case Bytecodes::_fast_iputfield:
113 case Bytecodes::_fast_lputfield:
114 case Bytecodes::_fast_sputfield:
115 {
116 // We skip bytecode quickening for putfield instructions when
117 // the put_code written to the constant pool cache is zero.
118 // This is required so that every execution of this instruction
119 // calls out to InterpreterRuntime::resolve_get_put to do
120 // additional, required work.
121 assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
122 assert(load_bc_into_bc_reg, "we use bc_reg as temp");
123 __ load_field_entry(Rtemp, Rnew_bc);
124 int code_offset = (byte_no == f1_byte) ? in_bytes(ResolvedFieldEntry::get_code_offset())
125 : in_bytes(ResolvedFieldEntry::put_code_offset());
668 void TemplateTable::daload() {
669 transition(itos, dtos);
670
671 const Register Rload_addr = R3_ARG1,
672 Rarray = R4_ARG2,
673 Rtemp = R5_ARG3;
674 __ index_check(Rarray, R17_tos /* index */, LogBytesPerLong, Rtemp, Rload_addr);
675 __ lfd(F15_ftos, arrayOopDesc::base_offset_in_bytes(T_DOUBLE), Rload_addr);
676 }
677
678 void TemplateTable::aaload() {
679 transition(itos, atos);
680
681 // tos: index
682 // result tos: array
683 const Register Rload_addr = R3_ARG1,
684 Rarray = R4_ARG2,
685 Rtemp = R5_ARG3,
686 Rtemp2 = R31;
687 __ index_check(Rarray, R17_tos /* index */, UseCompressedOops ? 2 : LogBytesPerWord, Rtemp, Rload_addr);
688 __ profile_array_type<ArrayLoadData>(Rarray, R11_scratch1, R12_scratch2);
689 if (UseArrayFlattening) {
690 Label is_flat_array, cont;
691
692 __ test_flat_array_oop(Rarray, Rtemp, is_flat_array);
693 do_oop_load(_masm, Rload_addr, arrayOopDesc::base_offset_in_bytes(T_OBJECT), R17_tos, Rtemp, Rtemp2,
694 IS_ARRAY);
695 __ verify_oop(R17_tos);
696 __ b(cont);
697
698 __ bind(is_flat_array);
699 __ call_VM(R17_tos, CAST_FROM_FN_PTR(address, InterpreterRuntime::flat_array_load), Rarray, R17_tos);
700 __ bind(cont);
701 } else {
702 do_oop_load(_masm, Rload_addr, arrayOopDesc::base_offset_in_bytes(T_OBJECT), R17_tos, Rtemp, Rtemp2,
703 IS_ARRAY);
704 __ verify_oop(R17_tos);
705 }
706 __ profile_element_type(R17_tos, Rtemp, Rtemp2);
707
708 //__ dcbt(R17_tos); // prefetch
709 }
710
711 void TemplateTable::baload() {
712 transition(itos, itos);
713
714 const Register Rload_addr = R3_ARG1,
715 Rarray = R4_ARG2,
716 Rtemp = R5_ARG3;
717 __ index_check(Rarray, R17_tos /* index */, 0, Rtemp, Rload_addr);
718 __ lbz(R17_tos, arrayOopDesc::base_offset_in_bytes(T_BYTE), Rload_addr);
719 __ extsb(R17_tos, R17_tos);
720 }
721
722 void TemplateTable::caload() {
723 transition(itos, itos);
724
725 const Register Rload_addr = R3_ARG1,
726 Rarray = R4_ARG2,
727 Rtemp = R5_ARG3;
974 __ index_check(Rarray, Rindex, LogBytesPerInt, Rtemp, Rstore_addr);
975 __ stfs(F15_ftos, arrayOopDesc::base_offset_in_bytes(T_FLOAT), Rstore_addr);
976 }
977
978 void TemplateTable::dastore() {
979 transition(dtos, vtos);
980
981 const Register Rindex = R3_ARG1,
982 Rstore_addr = R4_ARG2,
983 Rarray = R5_ARG3,
984 Rtemp = R6_ARG4;
985 __ pop_i(Rindex);
986 __ index_check(Rarray, Rindex, LogBytesPerLong, Rtemp, Rstore_addr);
987 __ stfd(F15_ftos, arrayOopDesc::base_offset_in_bytes(T_DOUBLE), Rstore_addr);
988 }
989
990 // Pop 3 values from the stack and...
991 void TemplateTable::aastore() {
992 transition(vtos, vtos);
993
994 Label Lstore_ok, Lis_null, Lis_flat_array, Lwrite_null_to_null_free_array, Ldone;
995 const Register Rindex = R6_ARG4,
996 Rarray = R5_ARG3,
997 Rscratch = R11_scratch1,
998 Rscratch2 = R12_scratch2,
999 Rarray_klass = R4_ARG2,
1000 Rarray_element_klass = Rarray_klass,
1001 Rvalue_klass = R3_ARG1,
1002 Rstore_addr = R31; // Use register which survives VM call.
1003
1004 __ ld(R17_tos, Interpreter::expr_offset_in_bytes(0), R15_esp); // Get value to store.
1005 __ lwz(Rindex, Interpreter::expr_offset_in_bytes(1), R15_esp); // Get index.
1006 __ ld(Rarray, Interpreter::expr_offset_in_bytes(2), R15_esp); // Get array.
1007
1008 __ verify_oop(R17_tos);
1009 __ index_check_without_pop(Rarray, Rindex, UseCompressedOops ? 2 : LogBytesPerWord, Rscratch, Rstore_addr);
1010
1011 __ profile_array_type<ArrayStoreData>(Rarray, Rscratch, Rscratch2);
1012 __ profile_multiple_element_types(R17_tos, Rscratch, Rscratch2, /* temp */ Rarray_klass);
1013
1014 if (UseArrayFlattening) {
1015 __ load_klass(Rarray_klass, Rarray);
1016 __ lwz(Rscratch, in_bytes(Klass::layout_helper_offset()), Rarray_klass);
1017 __ test_flat_array_layout(Rscratch, Lis_flat_array);
1018 }
1019
1020 // Do array store check - check for null value first.
1021 __ cmpdi(CR0, R17_tos, 0);
1022 __ beq(CR0, Lis_null);
1023
1024 // Rindex is dead!
1025 Register Rscratch3 = Rindex;
1026
1027 if (!UseArrayFlattening) {
1028 __ load_klass(Rarray_klass, Rarray); // haven't done this above
1029 }
1030 __ load_klass(Rvalue_klass, R17_tos);
1031
1032 // Do fast instanceof cache test.
1033 __ ld(Rarray_element_klass, in_bytes(ObjArrayKlass::element_klass_offset()), Rarray_klass);
1034
1035 // Generate a fast subtype check. Branch to store_ok if no failure. Throw if failure.
1036 __ gen_subtype_check(Rvalue_klass /*subklass*/, Rarray_element_klass /*superklass*/,
1037 Rscratch, Rscratch2, Rscratch3, Lstore_ok, false);
1038
1039 // Fell through: subtype check failed => throw an exception.
1040 __ load_dispatch_table(R11_scratch1, (address*)Interpreter::_throw_ArrayStoreException_entry);
1041 __ mtctr(R11_scratch1);
1042 __ bctr();
1043
1044 if (UseArrayFlattening) {
1045 __ bind(Lis_flat_array); // Store non-null value to flat
1046 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::flat_array_store), R17_tos, Rarray, Rindex);
1047 __ b(Ldone);
1048 }
1049
1050 __ bind(Lis_null);
1051 if (Arguments::is_valhalla_enabled()) {
1052 // No way to store null in null-free array
1053 __ test_null_free_array_oop(Rarray, Rscratch, Lwrite_null_to_null_free_array);
1054 }
1055 do_oop_store(_masm, Rstore_addr, arrayOopDesc::base_offset_in_bytes(T_OBJECT), noreg /* 0 */,
1056 Rscratch, Rscratch2, Rscratch3, IS_ARRAY);
1057 __ b(Ldone);
1058
1059 if (Arguments::is_valhalla_enabled()) {
1060 __ bind(Lwrite_null_to_null_free_array);
1061 __ load_dispatch_table(Rscratch, (address*)Interpreter::_throw_NullPointerException_entry);
1062 __ mtctr(Rscratch);
1063 __ bctr();
1064 }
1065
1066 // Store is OK.
1067 __ align(32, 12);
1068 __ bind(Lstore_ok);
1069 do_oop_store(_masm, Rstore_addr, arrayOopDesc::base_offset_in_bytes(T_OBJECT), R17_tos /* value */,
1070 Rscratch, Rscratch2, Rscratch3, IS_ARRAY | IS_NOT_NULL);
1071
1072 __ bind(Ldone);
1073 // Adjust sp (pops array, index and value).
1074 __ addi(R15_esp, R15_esp, 3 * Interpreter::stackElementSize);
1075 }
1076
1077 void TemplateTable::bastore() {
1078 transition(itos, vtos);
1079
1080 const Register Rindex = R11_scratch1,
1081 Rarray = R12_scratch2,
1082 Rscratch = R3_ARG1;
1083 __ pop_i(Rindex);
1084 __ pop_ptr(Rarray);
1085 // tos: val
1086
1087 // Need to check whether array is boolean or byte
1784 __ reset_last_Java_frame();
1785 // OSR buffer is in ARG1.
1786
1787 // Remove the interpreter frame.
1788 __ merge_frames(/*top_frame_sp*/ R21_sender_SP, /*return_pc*/ R12_scratch2, R11_scratch1, R0);
1789 JFR_ONLY(__ leave_jfr_critical_section();)
1790
1791 // Jump to the osr code.
1792 __ ld(R11_scratch1, nmethod::osr_entry_point_offset(), osr_nmethod);
1793 __ mtlr(R12_scratch2);
1794 __ mtctr(R11_scratch1);
1795 __ bctr();
1796
1797 __ bind(Lforward);
1798 }
1799 __ dispatch_next(vtos, 0, true);
1800 }
1801
1802 // Helper function for if_cmp* methods below.
1803 // Factored out common compare and branch code.
1804 void TemplateTable::if_cmp_common(Register Rfirst, Register Rsecond, Register Rscratch1, Register Rscratch2, Condition cc, bool is_jint, bool is_acmp) {
1805 Label Lnot_taken;
1806 // Note: The condition code we get is the condition under which we
1807 // *fall through*! So we have to inverse the CC here.
1808
1809 if (is_jint) {
1810 if (Rsecond == noreg) {
1811 __ cmpwi(CR0, Rfirst, 0);
1812 } else {
1813 __ cmpw(CR0, Rfirst, Rsecond);
1814 }
1815 } else {
1816 if (Rsecond == noreg) {
1817 __ cmpdi(CR0, Rfirst, 0);
1818 } else {
1819 __ cmpd(CR0, Rfirst, Rsecond);
1820 }
1821 }
1822 branch_conditional(CR0, cc, Lnot_taken, /*invert*/ true);
1823
1824 // Conition is false => Jump!
1825 branch(false, false);
1826
1827 // Condition is not true => Continue.
1828 __ align(32, 12);
1829 __ bind(Lnot_taken);
1830 __ profile_not_taken_branch(Rscratch1, Rscratch2, is_acmp);
1831 }
1832
1833 // Compare integer values with zero and fall through if CC holds, branch away otherwise.
1834 void TemplateTable::if_0cmp(Condition cc) {
1835 transition(itos, vtos);
1836
1837 if_cmp_common(R17_tos, noreg, R11_scratch1, R12_scratch2, cc, true);
1838 }
1839
1840 // Compare integer values and fall through if CC holds, branch away otherwise.
1841 //
1842 // Interface:
1843 // - Rfirst: First operand (older stack value)
1844 // - tos: Second operand (younger stack value)
1845 void TemplateTable::if_icmp(Condition cc) {
1846 transition(itos, vtos);
1847
1848 const Register Rfirst = R0,
1849 Rsecond = R17_tos;
1850
1851 __ pop_i(Rfirst);
1852 if_cmp_common(Rfirst, Rsecond, R11_scratch1, R12_scratch2, cc, true);
1853 }
1854
1855 void TemplateTable::if_nullcmp(Condition cc) {
1856 transition(atos, vtos);
1857
1858 if_cmp_common(R17_tos, noreg, R11_scratch1, R12_scratch2, cc, false);
1859 }
1860
1861 void TemplateTable::if_acmp(Condition cc) {
1862 transition(atos, vtos);
1863
1864 const Register Rfirst = R31,
1865 Rsecond = R17_tos;
1866
1867 __ pop_ptr(Rfirst);
1868
1869 __ profile_acmp(Rsecond, Rfirst, R11_scratch1, R12_scratch2);
1870
1871 const int is_inline_type_mask = markWord::inline_type_pattern;
1872 if (Arguments::is_valhalla_enabled()) {
1873 Label taken, not_taken;
1874 __ cmpd(CR0, Rfirst, Rsecond);
1875 __ beq(CR0, (cc == equal) ? taken : not_taken);
1876
1877 // test if any input is null
1878 __ cmpdi(CR0, Rfirst, 0);
1879 __ cmpdi(CR1, Rsecond, 0);
1880 __ cror(CR0, Assembler::equal, CR1, Assembler::equal);
1881 __ beq(CR0, (cc == equal) ? not_taken : taken);
1882
1883 // and both are values ?
1884 __ ld(R11_scratch1, oopDesc::mark_offset_in_bytes(), Rfirst);
1885 __ ld(R12_scratch2, oopDesc::mark_offset_in_bytes(), Rsecond);
1886 __ andr(R11_scratch1, R11_scratch1, R12_scratch2);
1887 __ andi(R11_scratch1, R11_scratch1, is_inline_type_mask);
1888 __ cmpdi(CR0, R11_scratch1, is_inline_type_mask);
1889 __ bne(CR0, (cc == equal) ? not_taken : taken);
1890
1891 // same value klass ?
1892 __ load_metadata(R11_scratch1, Rfirst);
1893 __ load_metadata(R12_scratch2, Rsecond);
1894 __ cmpd(CR0, R11_scratch1, R12_scratch2);
1895 __ bne(CR0, (cc == equal) ? not_taken : taken);
1896
1897 // Know both are the same type, let's test for substitutability...
1898 if (cc == equal) {
1899 invoke_is_substitutable(Rfirst, Rsecond, taken, not_taken);
1900 } else {
1901 invoke_is_substitutable(Rfirst, Rsecond, not_taken, taken);
1902 }
1903 DEBUG_ONLY( __ stop("Not reachable"); )
1904
1905 // Conition is false => Jump!
1906 __ align(32, 12);
1907 __ bind(taken);
1908 branch(false, false);
1909
1910 // Condition is not true => Continue.
1911 __ align(32, 12);
1912 __ bind(not_taken);
1913 __ profile_not_taken_branch(R11_scratch1, R12_scratch2, true);
1914
1915 } else {
1916 if_cmp_common(Rfirst, Rsecond, R11_scratch1, R12_scratch2, cc, false, true);
1917 }
1918 }
1919
1920 void TemplateTable::invoke_is_substitutable(Register aobj, Register bobj, Label& is_subst, Label& not_subst) {
1921 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::is_substitutable), aobj, bobj);
1922 __ cmpwi(CR0, R3_RET, 0);
1923 __ beq(CR0, not_subst);
1924 __ b(is_subst);
1925 }
1926
1927 void TemplateTable::ret() {
1928 locals_index(R11_scratch1);
1929 __ load_local_ptr(R17_tos, R11_scratch1, R11_scratch1);
1930
1931 __ profile_ret(vtos, R17_tos, R11_scratch1, R12_scratch2);
1932
1933 __ ld(R11_scratch1, in_bytes(Method::const_offset()), R19_method);
1934 __ add(R11_scratch1, R17_tos, R11_scratch1);
1935 __ addi(R14_bcp, R11_scratch1, in_bytes(ConstMethod::codes_offset()));
1936 __ dispatch_next(vtos, 0, true);
1937 }
1938
1939 void TemplateTable::wide_ret() {
1940 transition(vtos, vtos);
1941
1942 const Register Rindex = R3_ARG1,
1943 Rscratch1 = R11_scratch1,
1944 Rscratch2 = R12_scratch2;
2824 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode()));
2825
2826 __ align(32, 28, 28); // Align load.
2827 // __ bind(Lstos);
2828 __ fence(); // Volatile entry point (one instruction before non-volatile_entry point).
2829 assert(branch_table[stos] == nullptr, "can't compute twice");
2830 branch_table[stos] = __ pc(); // non-volatile_entry point
2831 __ lhax(R17_tos, Rclass_or_obj, Roffset);
2832 __ push(stos);
2833 if (!is_static && rc == may_rewrite) {
2834 patch_bytecode(Bytecodes::_fast_sgetfield, Rbc, Rscratch);
2835 }
2836 __ beq(CR2, Lacquire); // Volatile?
2837 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode()));
2838
2839 __ align(32, 28, 28); // Align load.
2840 // __ bind(Latos);
2841 __ fence(); // Volatile entry point (one instruction before non-volatile_entry point).
2842 assert(branch_table[atos] == nullptr, "can't compute twice");
2843 branch_table[atos] = __ pc(); // non-volatile_entry point
2844 if (!Arguments::is_valhalla_enabled()) {
2845 do_oop_load(_masm, Rclass_or_obj, Roffset, R17_tos, Rscratch, /* nv temp */ Rflags, IN_HEAP);
2846 __ verify_oop(R17_tos);
2847 __ push(atos);
2848 //__ dcbt(R17_tos); // prefetch
2849 if (!is_static && rc == may_rewrite) {
2850 patch_bytecode(Bytecodes::_fast_agetfield, Rbc, Rscratch);
2851 }
2852 } else { // Valhalla
2853 if (is_static) {
2854 do_oop_load(_masm, Rclass_or_obj, Roffset, R17_tos, Rscratch, /* nv temp */ Rflags, IN_HEAP);
2855 __ verify_oop(R17_tos);
2856 __ push(atos);
2857 } else {
2858 Label is_flat;
2859 __ test_field_is_flat(Rflags, is_flat);
2860 do_oop_load(_masm, Rclass_or_obj, Roffset, R17_tos, Rscratch, /* nv temp */ Rflags, IN_HEAP);
2861 __ verify_oop(R17_tos);
2862 __ push(atos);
2863 if (rc == may_rewrite) {
2864 patch_bytecode(Bytecodes::_fast_agetfield, Rbc, Rscratch);
2865 }
2866 __ beq(CR2, Lacquire); // Volatile?
2867 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode()));
2868
2869 __ bind(is_flat);
2870 // field is flat (null-free or nullable with a null-marker)
2871 __ mr(R17_tos, Rclass_or_obj);
2872 __ read_flat_field(Rcache, R17_tos);
2873 __ verify_oop(R17_tos);
2874 __ push(atos);
2875 if (rc == may_rewrite) {
2876 patch_bytecode(Bytecodes::_fast_vgetfield, Rbc, Rscratch);
2877 }
2878 }
2879 }
2880 __ beq(CR2, Lacquire); // Volatile?
2881 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode()));
2882
2883 __ align(32, 12);
2884 __ bind(Lacquire);
2885 __ twi_0(R17_tos);
2886 __ bind(Lisync);
2887 __ isync(); // acquire
2888
2889 #ifdef ASSERT
2890 for (int i = 0; i<number_of_states; ++i) {
2891 assert(branch_table[i], "get initialization");
2892 //tty->print_cr("get: %s_branch_table[%d] = 0x%llx (opcode 0x%llx)",
2893 // is_static ? "static" : "field", i, branch_table[i], *((unsigned int*)branch_table[i]));
2894 }
2895 #endif
2896 }
2897
2898 void TemplateTable::getfield(int byte_no) {
2899 getfield_or_static(byte_no, false);
2900 }
2901
2902 void TemplateTable::nofast_getfield(int byte_no) {
2903 getfield_or_static(byte_no, false, may_not_rewrite);
2904 }
2905
2906 void TemplateTable::getstatic(int byte_no) {
2907 getfield_or_static(byte_no, true);
2908 }
2909
2910 // The registers cache and index expected to be set before call.
2911 // The function may destroy various registers, just not the cache and index registers.
2912 void TemplateTable::jvmti_post_field_mod(Register Rcache, Register Rscratch, bool is_static) {
2913
2914 assert_different_registers(Rcache, Rscratch);
2915
2916 if (JvmtiExport::can_post_field_modification()) {
2917 Label Lno_field_mod_post;
2918
2919 // Check if post field access in enabled.
2920 int offs = __ load_const_optimized(Rscratch, JvmtiExport::get_field_modification_count_addr(), R0, true);
2921 __ lwz(Rscratch, offs, Rscratch);
2922
2923 __ cmpwi(CR0, Rscratch, 0);
2924 __ beq(CR0, Lno_field_mod_post);
2925
2926 // Do the post
2927 const Register Robj = Rscratch;
2928
2929 if (is_static) {
2930 // Life is simple. Null out the object pointer.
2931 __ li(Robj, 0);
2932 } else {
2933 // In case of the fast versions, value lives in registers => put it back on tos.
2934 int offs = Interpreter::expr_offset_in_bytes(0);
2935 Register base = R15_esp;
2936 switch(bytecode()) {
2937 case Bytecodes::_fast_vputfield: // fall through
2938 case Bytecodes::_fast_aputfield: __ push_ptr(); offs+= Interpreter::stackElementSize; break;
2939 case Bytecodes::_fast_iputfield: // Fall through
2940 case Bytecodes::_fast_bputfield: // Fall through
2941 case Bytecodes::_fast_zputfield: // Fall through
2942 case Bytecodes::_fast_cputfield: // Fall through
2943 case Bytecodes::_fast_sputfield: __ push_i(); offs+= Interpreter::stackElementSize; break;
2944 case Bytecodes::_fast_lputfield: __ push_l(); offs+=2*Interpreter::stackElementSize; break;
2945 case Bytecodes::_fast_fputfield: __ push_f(); offs+= Interpreter::stackElementSize; break;
2946 case Bytecodes::_fast_dputfield: __ push_d(); offs+=2*Interpreter::stackElementSize; break;
2947 default: {
2948 offs = 0;
2949 base = Robj;
2950 const Register Rtos_state = Robj;
2951 Label is_one_slot;
2952 // Life is harder. The stack holds the value on top, followed by the
2953 // object. We don't know the size of the value, though; it could be
2954 // one or two words depending on its type. As a result, we must find
2955 // the type to determine where the object is.
2956 __ lbz(Rtos_state, in_bytes(ResolvedFieldEntry::type_offset()), Rcache);
2957
2958 __ cmpwi(CR0, Rtos_state, ltos);
2959 __ cmpwi(CR1, Rtos_state, dtos);
2960 __ addi(base, R15_esp, Interpreter::expr_offset_in_bytes(1));
2961 __ crnor(CR0, Assembler::equal, CR1, Assembler::equal);
2962 __ beq(CR0, is_one_slot);
2963 __ addi(base, R15_esp, Interpreter::expr_offset_in_bytes(2));
2964 __ bind(is_one_slot);
2965 break;
2966 }
2967 }
2968 __ ld(Robj, offs, base);
2969 __ verify_oop(Robj);
2970 }
2971
2972 // Pass arguments without register clashes (R16_thread passed by call_VM)
2973 __ mr_if_needed(R4_ARG2, Robj);
2974 assert(Rcache != R4_ARG2, "smashed argument");
2975 __ mr_if_needed(R5_ARG3, Rcache);
2976 __ addi(R6_ARG4, R15_esp, Interpreter::expr_offset_in_bytes(0)); // set R6_ARG4 last (may use same reg as other args)
2977 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification));
2978 __ load_field_entry(Rcache, Rscratch);
2979
2980 // In case of the fast versions, value lives in registers => put it back on tos.
2981 switch(bytecode()) {
2982 case Bytecodes::_fast_vputfield: // fall through
2983 case Bytecodes::_fast_aputfield: __ pop_ptr(); break;
2984 case Bytecodes::_fast_iputfield: // Fall through
2985 case Bytecodes::_fast_bputfield: // Fall through
2986 case Bytecodes::_fast_zputfield: // Fall through
2987 case Bytecodes::_fast_cputfield: // Fall through
2988 case Bytecodes::_fast_sputfield: __ pop_i(); break;
2989 case Bytecodes::_fast_lputfield: __ pop_l(); break;
2990 case Bytecodes::_fast_fputfield: __ pop_f(); break;
2991 case Bytecodes::_fast_dputfield: __ pop_d(); break;
2992 default: break; // Nothin' to do.
2993 }
2994
2995 __ align(32, 12);
2996 __ bind(Lno_field_mod_post);
2997 }
2998 }
2999
3000 // PPC64: implement volatile stores as release-store (return bytecode contains an additional release).
3001 void TemplateTable::putfield_or_static(int byte_no, bool is_static, RewriteControl rc) {
3002 Label Lvolatile;
3003
3004 const Register Rcache = R6_ARG4, // Do not use ARG1-3 (causes trouble in jvmti_post_field_mod or write_flat_field).
3005 Rclass_or_obj = R31, // Needs to survive C call.
3006 Roffset = R22_tmp2, // Needs to survive C call.
3007 Rtos_state = R23_tmp3, // Needs to survive C call.
3008 Rflags = R30, // Needs to survive C call.
3009 Rbtable = R4_ARG2,
3010 Rscratch = R11_scratch1, // used by load_field_cp_cache_entry
3011 Rscratch2 = R12_scratch2, // used by load_field_cp_cache_entry
3012 Rscratch3 = R10_ARG8,
3013 Rbc = Rscratch3;
3014 const ConditionRegister CR_is_vol = CR2; // Non-volatile condition register (survives runtime call in do_oop_store).
3015
3016 static address field_rw_branch_table[number_of_states],
3017 field_norw_branch_table[number_of_states],
3018 static_branch_table[number_of_states];
3019
3020 address* branch_table = is_static ? static_branch_table :
3021 (rc == may_rewrite ? field_rw_branch_table : field_norw_branch_table);
3022
3023 // Stack (grows up):
3024 // value
3025 // obj
3026
3027 // Load the field offset.
3028 resolve_cache_and_index_for_field(byte_no, Rcache, Rscratch);
3029 jvmti_post_field_mod(Rcache, Rscratch, is_static);
3030 load_resolved_field_entry(Rclass_or_obj, Rcache, Rtos_state, Roffset, Rflags, is_static); // Uses R11, R12
3031
3032 // Load pointer to branch table.
3186 __ release(); // Volatile entry point (one instruction before non-volatile_entry point).
3187 assert(branch_table[stos] == nullptr, "can't compute twice");
3188 branch_table[stos] = __ pc(); // non-volatile_entry point
3189 __ pop(stos);
3190 if (!is_static) { pop_and_check_object(Rclass_or_obj); } // Kills R11_scratch1.
3191 __ sthx(R17_tos, Rclass_or_obj, Roffset);
3192 if (!is_static && rc == may_rewrite) {
3193 patch_bytecode(Bytecodes::_fast_sputfield, Rbc, Rscratch, true, byte_no);
3194 }
3195 if (!support_IRIW_for_not_multiple_copy_atomic_cpu) {
3196 __ beq(CR_is_vol, Lvolatile); // Volatile?
3197 }
3198 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode()));
3199
3200 __ align(32, 28, 28); // Align pop.
3201 // __ bind(Latos);
3202 __ release(); // Volatile entry point (one instruction before non-volatile_entry point).
3203 assert(branch_table[atos] == nullptr, "can't compute twice");
3204 branch_table[atos] = __ pc(); // non-volatile_entry point
3205 __ pop(atos);
3206 if (!Arguments::is_valhalla_enabled()) {
3207 if (!is_static) { pop_and_check_object(Rclass_or_obj); } // kills R11_scratch1
3208 do_oop_store(_masm, Rclass_or_obj, Roffset, R17_tos, Rscratch, Rscratch2, Rscratch3, IN_HEAP);
3209 if (!is_static && rc == may_rewrite) {
3210 patch_bytecode(Bytecodes::_fast_aputfield, Rbc, Rscratch, true, byte_no);
3211 }
3212 } else { // Valhalla
3213 if (is_static) {
3214 Label is_nullable;
3215 __ test_field_is_not_null_free_inline_type(Rflags, is_nullable);
3216 __ null_check_throw(R17_tos, -1, Rscratch);
3217 __ align(32, 12);
3218 __ bind(is_nullable);
3219 do_oop_store(_masm, Rclass_or_obj, Roffset, R17_tos, Rscratch, Rscratch2, Rscratch3, IN_HEAP);
3220 } else {
3221 Label null_free_reference, is_flat, rewrite_inline;
3222 __ test_field_is_flat(Rflags, is_flat);
3223 __ test_field_is_null_free_inline_type(Rflags, null_free_reference);
3224 pop_and_check_object(Rclass_or_obj);
3225 // Store into the field
3226 do_oop_store(_masm, Rclass_or_obj, Roffset, R17_tos, Rscratch, Rscratch2, Rscratch3, IN_HEAP);
3227 if (rc == may_rewrite) {
3228 patch_bytecode(Bytecodes::_fast_aputfield, Rbc, Rscratch, true, byte_no);
3229 }
3230 if (!support_IRIW_for_not_multiple_copy_atomic_cpu) {
3231 __ beq(CR_is_vol, Lvolatile); // Volatile?
3232 }
3233 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode()));
3234
3235 // Implementation of the inline type semantic
3236 __ bind(null_free_reference);
3237 __ null_check_throw(R17_tos, -1, Rscratch);
3238 pop_and_check_object(Rclass_or_obj);
3239 // Store into the field
3240 do_oop_store(_masm, Rclass_or_obj, Roffset, R17_tos, Rscratch, Rscratch2, Rscratch3, IN_HEAP);
3241 __ b(rewrite_inline);
3242
3243 __ bind(is_flat);
3244 pop_and_check_object(Rclass_or_obj);
3245 __ write_flat_field(Rcache, Rscratch, Rscratch2, Rclass_or_obj, Roffset, R17_tos);
3246 __ bind(rewrite_inline);
3247 if (rc == may_rewrite) {
3248 patch_bytecode(Bytecodes::_fast_vputfield, Rbc, Rscratch, true, byte_no);
3249 }
3250 }
3251 } // Valhalla
3252 if (!support_IRIW_for_not_multiple_copy_atomic_cpu) {
3253 __ beq(CR_is_vol, Lvolatile); // Volatile?
3254 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode()));
3255
3256 __ align(32, 12);
3257 __ bind(Lvolatile);
3258 __ fence();
3259 }
3260 // fallthru: __ b(Lexit);
3261
3262 #ifdef ASSERT
3263 for (int i = 0; i<number_of_states; ++i) {
3264 assert(branch_table[i], "put initialization");
3265 //tty->print_cr("put: %s_branch_table[%d] = 0x%llx (opcode 0x%llx)",
3266 // is_static ? "static" : "field", i, branch_table[i], *((unsigned int*)branch_table[i]));
3267 }
3268 #endif
3269 }
3270
3271 void TemplateTable::putfield(int byte_no) {
3272 putfield_or_static(byte_no, false);
3273 }
3274
3275 void TemplateTable::nofast_putfield(int byte_no) {
3276 putfield_or_static(byte_no, false, may_not_rewrite);
3277 }
3278
3279 void TemplateTable::putstatic(int byte_no) {
3280 putfield_or_static(byte_no, true);
3281 }
3282
3283 // On PPC64, we have a different jvmti_post_field_mod which does the job.
3284 void TemplateTable::jvmti_post_fast_field_mod() {
3285 __ should_not_reach_here();
3286 }
3287
3288 void TemplateTable::fast_storefield(TosState state) {
3289 transition(state, vtos);
3290
3291 const Register Rcache = R6_ARG4, // Do not use ARG1-3 (causes trouble in jvmti_post_field_mod or write_flat_field).
3292 Rclass_or_obj = R31, // Needs to survive C call.
3293 Roffset = R22_tmp2, // Needs to survive C call.
3294 Rflags = R3_ARG1,
3295 Rscratch = R11_scratch1, // used by load_field_cp_cache_entry
3296 Rscratch2 = R12_scratch2, // used by load_field_cp_cache_entry
3297 Rscratch3 = R4_ARG2;
3298 const ConditionRegister CR_is_vol = CR2; // Non-volatile condition register (survives runtime call in do_oop_store).
3299
3300 // Constant pool already resolved => Load flags and offset of field.
3301 __ load_field_entry(Rcache, Rscratch, 1, /* for_fast_bytecode */ true);
3302 jvmti_post_field_mod(Rcache, Rscratch, false /* not static */);
3303 load_resolved_field_entry(noreg, Rcache, noreg, Roffset, Rflags, false); // Uses R11, R12
3304
3305 // Get the obj and the final store addr.
3306 pop_and_check_object(Rclass_or_obj); // Kills R11_scratch1.
3307
3308 // Get volatile flag.
3309 __ rldicl_(Rscratch, Rflags, 64-ResolvedFieldEntry::is_volatile_shift, 63); // Extract volatile bit.
3310 if (!support_IRIW_for_not_multiple_copy_atomic_cpu) { __ cmpdi(CR_is_vol, Rscratch, 1); }
3311 {
3312 Label LnotVolatile;
3313 __ beq(CR0, LnotVolatile);
3314 __ release();
3315 __ align(32, 12);
3316 __ bind(LnotVolatile);
3317 }
3318
3319 // Do the store and fencing.
3320 switch(bytecode()) {
3321 case Bytecodes::_fast_vputfield:
3322 {
3323 Label is_flat, done;
3324 __ test_field_is_flat(Rflags, is_flat);
3325 __ null_check_throw(Rclass_or_obj, -1, Rscratch);
3326 do_oop_store(_masm, Rclass_or_obj, Roffset, R17_tos, Rscratch, Rscratch2, Rscratch3, IN_HEAP);
3327 __ b(done);
3328 __ bind(is_flat);
3329 __ write_flat_field(Rcache, Rscratch, Rscratch2, Rclass_or_obj, Roffset, R17_tos);
3330 __ bind(done);
3331 break;
3332 }
3333
3334 case Bytecodes::_fast_aputfield:
3335 // Store into the field.
3336 do_oop_store(_masm, Rclass_or_obj, Roffset, R17_tos, Rscratch, Rscratch2, Rscratch3, IN_HEAP);
3337 break;
3338
3339 case Bytecodes::_fast_iputfield:
3340 __ stwx(R17_tos, Rclass_or_obj, Roffset);
3341 break;
3342
3343 case Bytecodes::_fast_lputfield:
3344 __ stdx(R17_tos, Rclass_or_obj, Roffset);
3345 break;
3346
3347 case Bytecodes::_fast_zputfield:
3348 __ andi(R17_tos, R17_tos, 0x1); // boolean is true if LSB is 1
3349 // fall through to bputfield
3350 case Bytecodes::_fast_bputfield:
3351 __ stbx(R17_tos, Rclass_or_obj, Roffset);
3352 break;
3353
3389 Roffset = R22_tmp2,
3390 Rflags = R23_tmp3,
3391 Rscratch = R11_scratch1; // used by load_field_cp_cache_entry
3392 // R12_scratch2 used by load_field_cp_cache_entry
3393
3394 // Constant pool already resolved. Get the field offset.
3395 __ load_field_entry(Rcache, Rscratch, 1, /* for_fast_bytecode */ true);
3396 load_resolved_field_entry(noreg, Rcache, noreg, Roffset, Rflags, false); // Uses R11, R12
3397
3398 // JVMTI support
3399 jvmti_post_field_access(Rcache, Rscratch, false, true);
3400
3401 // Get the load address.
3402 __ null_check_throw(Rclass_or_obj, -1, Rscratch);
3403
3404 // Get volatile flag.
3405 __ rldicl_(Rscratch, Rflags, 64-ResolvedFieldEntry::is_volatile_shift, 63); // Extract volatile bit.
3406 __ bne(CR0, LisVolatile);
3407
3408 switch(bytecode()) {
3409 case Bytecodes::_fast_vgetfield:
3410 {
3411 // field is flat
3412 __ read_flat_field(Rcache, R17_tos);
3413 __ verify_oop(R17_tos);
3414 __ dispatch_epilog(state, Bytecodes::length_for(bytecode()));
3415
3416 __ bind(LisVolatile);
3417 if (support_IRIW_for_not_multiple_copy_atomic_cpu) { __ fence(); }
3418 __ read_flat_field(Rcache, R17_tos);
3419 __ verify_oop(R17_tos);
3420 // memory barrier in read_flat_field
3421 break;
3422 }
3423 case Bytecodes::_fast_agetfield:
3424 {
3425 do_oop_load(_masm, Rclass_or_obj, Roffset, R17_tos, Rscratch, /* nv temp */ Rflags, IN_HEAP);
3426 __ verify_oop(R17_tos);
3427 __ dispatch_epilog(state, Bytecodes::length_for(bytecode()));
3428
3429 __ bind(LisVolatile);
3430 if (support_IRIW_for_not_multiple_copy_atomic_cpu) { __ fence(); }
3431 do_oop_load(_masm, Rclass_or_obj, Roffset, R17_tos, Rscratch, /* nv temp */ Rflags, IN_HEAP);
3432 __ verify_oop(R17_tos);
3433 __ twi_0(R17_tos);
3434 __ isync();
3435 break;
3436 }
3437 case Bytecodes::_fast_igetfield:
3438 {
3439 __ lwax(R17_tos, Rclass_or_obj, Roffset);
3440 __ dispatch_epilog(state, Bytecodes::length_for(bytecode()));
3441
3442 __ bind(LisVolatile);
4032
4033 __ std(RnewTopValue, in_bytes(JavaThread::tlab_top_offset()), R16_thread);
4034
4035 if (!ZeroTLAB) {
4036 // --------------------------------------------------------------------------
4037 // Init1: Zero out newly allocated memory.
4038 // Initialize remaining object fields.
4039 Register Rbase = Rtags;
4040 int header_size = oopDesc::header_size() * HeapWordSize;
4041 __ addi(Rinstance_size, Rinstance_size, 7 - header_size);
4042 __ addi(Rbase, RallocatedObject, header_size);
4043 __ srdi(Rinstance_size, Rinstance_size, 3);
4044
4045 // Clear out object skipping header. Takes also care of the zero length case.
4046 __ clear_memory_doubleword(Rbase, Rinstance_size);
4047 }
4048
4049 // --------------------------------------------------------------------------
4050 // Init2: Initialize the header: mark, klass
4051 // Init mark.
4052 if (UseCompactObjectHeaders || Arguments::is_valhalla_enabled()) {
4053 __ ld(Rscratch, in_bytes(Klass::prototype_header_offset()), RinstanceKlass);
4054 } else {
4055 __ load_const_optimized(Rscratch, markWord::prototype().value(), R0);
4056 }
4057 __ std(Rscratch, oopDesc::mark_offset_in_bytes(), RallocatedObject);
4058
4059 if (!UseCompactObjectHeaders) {
4060 __ store_klass_gap(RallocatedObject);
4061 __ store_klass(RallocatedObject, RinstanceKlass, Rscratch);
4062 }
4063
4064 __ b(Ldone);
4065 }
4066
4067 // --------------------------------------------------------------------------
4068 // slow case
4069 __ bind(Lslow_case);
4070 __ call_VM_preemptable(R17_tos, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), Rcpool, Rindex);
4071
4072 // continue
4073 __ bind(Ldone);
4074
4075 // Must prevent reordering of stores for object initialization with stores that publish the new object.
4076 __ membar(Assembler::StoreStore);
4077 }
4078
4079 void TemplateTable::newarray() {
4302 Rcurrent_obj = R4_ARG2,
4303 Robj_to_lock = R17_tos,
4304 Rscratch1 = R11_scratch1,
4305 Rscratch2 = R12_scratch2,
4306 Rbot = R5_ARG3,
4307 Rfree_slot = R6_ARG4;
4308
4309 Label Lfound, Lallocate_new;
4310
4311 __ ld(Rscratch1, _abi0(callers_sp), R1_SP); // load FP
4312 __ li(Rfree_slot, 0); // Points to free slot or null.
4313
4314 // Set up search loop - start with topmost monitor.
4315 __ mr(Rcurrent_monitor, R26_monitor);
4316 __ addi(Rbot, Rscratch1, -frame::ijava_state_size);
4317
4318 // ------------------------------------------------------------------------------
4319 // Null pointer exception.
4320 __ null_check_throw(Robj_to_lock, -1, Rscratch1);
4321
4322 Label is_inline_type;
4323 __ ld(Rscratch1, oopDesc::mark_offset_in_bytes(), Robj_to_lock);
4324 __ test_markword_is_inline_type(Rscratch1, is_inline_type);
4325
4326 // Check if any slot is present => short cut to allocation if not.
4327 __ cmpld(CR0, Rcurrent_monitor, Rbot);
4328 __ beq(CR0, Lallocate_new);
4329
4330 // ------------------------------------------------------------------------------
4331 // Find a free slot in the monitor block.
4332 // Note: The order of the monitors is important for C2 OSR which derives the
4333 // unlock order from it (see comments for interpreter_frame_monitor_*).
4334 {
4335 Label Lloop, LnotFree, Lexit;
4336
4337 __ bind(Lloop);
4338 __ ld(Rcurrent_obj, in_bytes(BasicObjectLock::obj_offset()), Rcurrent_monitor);
4339 // Exit if current entry is for same object; this guarantees, that new monitor
4340 // used for recursive lock is above the older one.
4341 __ cmpd(CR0, Rcurrent_obj, Robj_to_lock);
4342 __ beq(CR0, Lexit); // recursive locking
4343
4344 __ cmpdi(CR0, Rcurrent_obj, 0);
4345 __ bne(CR0, LnotFree);
4362 __ add_monitor_to_stack(false, Rscratch1, Rscratch2);
4363 __ mr(Rfree_slot, R26_monitor);
4364
4365 // ------------------------------------------------------------------------------
4366 // We now have a slot to lock.
4367 __ bind(Lfound);
4368
4369 // Increment bcp to point to the next bytecode, so exception handling for async. exceptions work correctly.
4370 // The object has already been popped from the stack, so the expression stack looks correct.
4371 __ addi(R14_bcp, R14_bcp, 1);
4372
4373 __ std(Robj_to_lock, in_bytes(BasicObjectLock::obj_offset()), Rfree_slot);
4374 __ lock_object(Rfree_slot, Robj_to_lock);
4375
4376 // Check if there's enough space on the stack for the monitors after locking.
4377 // This emits a single store.
4378 __ generate_stack_overflow_check(0);
4379
4380 // The bcp has already been incremented. Just need to dispatch to next instruction.
4381 __ dispatch_next(vtos);
4382
4383 __ bind(is_inline_type);
4384 __ call_VM(noreg, CAST_FROM_FN_PTR(address,
4385 InterpreterRuntime::throw_identity_exception), Robj_to_lock);
4386 __ should_not_reach_here();
4387 }
4388
4389 void TemplateTable::monitorexit() {
4390 transition(atos, vtos);
4391 __ verify_oop(R17_tos);
4392
4393 Register Rcurrent_monitor = R3_ARG1,
4394 Rcurrent_obj = R4_ARG2,
4395 Robj_to_lock = R17_tos,
4396 Rscratch = R11_scratch1,
4397 Rbot = R12_scratch2;
4398
4399 Label Lfound, Lillegal_monitor_state;
4400
4401 __ ld(Rscratch, _abi0(callers_sp), R1_SP); // load FP
4402
4403 // Set up search loop - start with topmost monitor.
4404 __ mr(Rcurrent_monitor, R26_monitor);
4405 __ addi(Rbot, Rscratch, -frame::ijava_state_size);
4406
4407 // Null pointer check.
4408 __ null_check_throw(Robj_to_lock, -1, Rscratch);
4409
4410 const int is_inline_type_mask = markWord::inline_type_pattern;
4411 __ ld(Rscratch, oopDesc::mark_offset_in_bytes(), Robj_to_lock);
4412 __ andi(Rscratch, Rscratch, is_inline_type_mask);
4413 __ cmpwi(CR0, Rscratch, is_inline_type_mask);
4414 __ beq(CR0, Lillegal_monitor_state);
4415
4416 // Check corner case: unbalanced monitorEnter / Exit.
4417 __ cmpld(CR0, Rcurrent_monitor, Rbot);
4418 __ beq(CR0, Lillegal_monitor_state);
4419
4420 // Find the corresponding slot in the monitors stack section.
4421 {
4422 Label Lloop;
4423
4424 __ bind(Lloop);
4425 __ ld(Rcurrent_obj, in_bytes(BasicObjectLock::obj_offset()), Rcurrent_monitor);
4426 // Is this entry for same obj?
4427 __ cmpd(CR0, Rcurrent_obj, Robj_to_lock);
4428 __ beq(CR0, Lfound);
4429
4430 __ addi(Rcurrent_monitor, Rcurrent_monitor, frame::interpreter_frame_monitor_size_in_bytes());
4431 __ cmpld(CR0, Rcurrent_monitor, Rbot);
4432 __ bne(CR0, Lloop);
4433 }
4434
4435 // Fell through without finding the basic obj lock => throw up!
|