1 /*
2 * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef CPU_AARCH64_GC_SHARED_BARRIERSETASSEMBLER_AARCH64_HPP
26 #define CPU_AARCH64_GC_SHARED_BARRIERSETASSEMBLER_AARCH64_HPP
27
28 #include "asm/macroAssembler.hpp"
29 #include "gc/shared/barrierSet.hpp"
30 #include "gc/shared/barrierSetNMethod.hpp"
31 #include "memory/allocation.hpp"
32 #include "oops/access.hpp"
33 #ifdef COMPILER2
34 #include "opto/optoreg.hpp"
35
36 class BarrierStubC2;
37 class Node;
38 #endif // COMPILER2
39
40 enum class NMethodPatchingType {
41 stw_instruction_and_data_patch,
42 conc_instruction_and_data_patch
43 };
44
45 class BarrierSetAssembler: public CHeapObj<mtGC> {
46 public:
47 virtual void arraycopy_prologue(MacroAssembler* masm, DecoratorSet decorators, bool is_oop,
48 Register src, Register dst, Register count, RegSet saved_regs) {}
49 virtual void arraycopy_epilogue(MacroAssembler* masm, DecoratorSet decorators, bool is_oop,
50 Register start, Register count, Register tmp, RegSet saved_regs) {}
51
52 virtual void copy_load_at(MacroAssembler* masm,
53 DecoratorSet decorators,
54 BasicType type,
55 size_t bytes,
56 Register dst1,
57 Register dst2,
58 Address src,
59 Register tmp);
60
61 virtual void copy_store_at(MacroAssembler* masm,
62 DecoratorSet decorators,
63 BasicType type,
64 size_t bytes,
65 Address dst,
66 Register src1,
67 Register src2,
68 Register tmp1,
69 Register tmp2,
70 Register tmp3);
71
72 virtual void copy_load_at(MacroAssembler* masm,
73 DecoratorSet decorators,
74 BasicType type,
75 size_t bytes,
76 FloatRegister dst1,
77 FloatRegister dst2,
78 Address src,
79 Register tmp1,
80 Register tmp2,
81 FloatRegister vec_tmp);
82
83 virtual void copy_store_at(MacroAssembler* masm,
84 DecoratorSet decorators,
85 BasicType type,
86 size_t bytes,
87 Address dst,
88 FloatRegister src1,
89 FloatRegister src2,
90 Register tmp1,
91 Register tmp2,
92 Register tmp3,
93 FloatRegister vec_tmp1,
94 FloatRegister vec_tmp2,
95 FloatRegister vec_tmp3);
96
97 virtual void load_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
98 Register dst, Address src, Register tmp1, Register tmp2);
99 virtual void store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
100 Address dst, Register val, Register tmp1, Register tmp2, Register tmp3);
101
102 virtual void flat_field_copy(MacroAssembler* masm, DecoratorSet decorators,
103 Register src, Register dst, Register inline_layout_info);
104
105 virtual void try_resolve_jobject_in_native(MacroAssembler* masm, Register jni_env,
106 Register obj, Register tmp, Label& slowpath);
107
108 virtual void tlab_allocate(MacroAssembler* masm,
109 Register obj, // result: pointer to object after successful allocation
110 Register var_size_in_bytes, // object size in bytes if unknown at compile time; invalid otherwise
111 int con_size_in_bytes, // object size in bytes if known at compile time
112 Register t1, // temp register
113 Register t2, // temp register
114 Label& slow_case // continuation point if fast allocation fails
115 );
116
117 virtual void barrier_stubs_init() {}
118
119 virtual NMethodPatchingType nmethod_patching_type() { return NMethodPatchingType::stw_instruction_and_data_patch; }
120
121 virtual void nmethod_entry_barrier(MacroAssembler* masm, Label* slow_path, Label* continuation, Label* guard);
122 virtual void c2i_entry_barrier(MacroAssembler* masm);
123
124 virtual void check_oop(MacroAssembler* masm, Register obj, Register tmp1, Register tmp2, Label& error);
125
126 virtual bool supports_instruction_patching() {
127 NMethodPatchingType patching_type = nmethod_patching_type();
128 return patching_type == NMethodPatchingType::conc_instruction_and_data_patch ||
129 patching_type == NMethodPatchingType::stw_instruction_and_data_patch;
130 }
131
132 static address patching_epoch_addr();
133 static void clear_patching_epoch();
134 static void increment_patching_epoch();
135
136 #ifdef COMPILER2
137 OptoReg::Name encode_float_vector_register_size(const Node* node,
138 OptoReg::Name opto_reg);
139 OptoReg::Name refine_register(const Node* node,
140 OptoReg::Name opto_reg);
141 #endif // COMPILER2
142 };
143
144 #ifdef COMPILER2
145
146 // This class saves and restores the registers that need to be preserved across
147 // the runtime call represented by a given C2 barrier stub. Use as follows:
148 // {
149 // SaveLiveRegisters save(masm, stub);
150 // ..
151 // __ blr(...);
152 // ..
153 // }
154 class SaveLiveRegisters {
155 private:
156 struct RegisterData {
157 VMReg _reg;
158 int _slots; // slots occupied once pushed into stack
159
160 // Used by GrowableArray::find()
161 bool operator == (const RegisterData& other) {
162 return _reg == other._reg;
163 }
164 };
165
166 MacroAssembler* const _masm;
167 RegSet _gp_regs;
168 FloatRegSet _fp_regs;
169 FloatRegSet _neon_regs;
170 FloatRegSet _sve_regs;
171 PRegSet _p_regs;
172
173 static enum RC rc_class(VMReg reg);
174 static bool is_same_register(VMReg reg1, VMReg reg2);
175 static int decode_float_vector_register_size(OptoReg::Name opto_reg);
176
177 public:
178 void initialize(BarrierStubC2* stub);
179 SaveLiveRegisters(MacroAssembler* masm, BarrierStubC2* stub);
180 ~SaveLiveRegisters();
181 };
182
183 #endif // COMPILER2
184
185 #endif // CPU_AARCH64_GC_SHARED_BARRIERSETASSEMBLER_AARCH64_HPP