1 /*
2 * Copyright (c) 2018, 2026, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2020, 2023, Huawei Technologies Co., Ltd. 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 *
24 */
25
26 #ifndef CPU_RISCV_GC_SHARED_BARRIERSETASSEMBLER_RISCV_HPP
27 #define CPU_RISCV_GC_SHARED_BARRIERSETASSEMBLER_RISCV_HPP
28
29 #include "asm/macroAssembler.hpp"
30 #include "gc/shared/barrierSet.hpp"
31 #include "gc/shared/barrierSetNMethod.hpp"
32 #include "memory/allocation.hpp"
33 #include "oops/access.hpp"
34 #ifdef COMPILER2
35 #include "opto/optoreg.hpp"
36
37 class BarrierStubC2;
38 class Node;
39 #endif // COMPILER2
40
41 enum class NMethodPatchingType {
42 stw_instruction_and_data_patch,
43 conc_instruction_and_data_patch
44 };
45
46 class BarrierSetAssembler: public CHeapObj<mtGC> {
47 public:
48 virtual void arraycopy_prologue(MacroAssembler* masm, DecoratorSet decorators, bool is_oop,
49 Register src, Register dst, Register count, RegSet saved_regs) {}
50 virtual void arraycopy_epilogue(MacroAssembler* masm, DecoratorSet decorators, bool is_oop,
51 Register start, Register count, Register tmp) {}
52
53 virtual void copy_load_at(MacroAssembler* masm,
54 DecoratorSet decorators,
55 BasicType type,
56 size_t bytes,
57 Register dst,
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 src,
67 Register tmp1,
68 Register tmp2,
69 Register tmp3);
70
71 virtual bool supports_rvv_arraycopy() { return true; }
72
73 virtual void load_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
74 Register dst, Address src, Register tmp1, Register tmp2);
75 virtual void store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
76 Address dst, Register val, Register tmp1, Register tmp2, Register tmp3);
77
78 virtual void flat_field_copy(MacroAssembler* masm, DecoratorSet decorators,
79 Register src, Register dst, Register inline_layout_info);
80
81 virtual void try_resolve_jobject_in_native(MacroAssembler* masm, Register jni_env,
82 Register obj, Register tmp, Label& slowpath);
83
84 virtual void tlab_allocate(MacroAssembler* masm,
85 Register obj, // result: pointer to object after successful allocation
86 Register var_size_in_bytes, // object size in bytes if unknown at compile time; invalid otherwise
87 int con_size_in_bytes, // object size in bytes if known at compile time
88 Register tmp1, // temp register
89 Register tmp2, // temp register
90 Label& slow_case, // continuation point if fast allocation fails
91 bool is_far = false
92 );
93
94 virtual void barrier_stubs_init() {}
95
96 virtual NMethodPatchingType nmethod_patching_type() { return NMethodPatchingType::stw_instruction_and_data_patch; }
97
98 virtual void nmethod_entry_barrier(MacroAssembler* masm, Label* slow_path, Label* continuation, Label* guard);
99 virtual void c2i_entry_barrier(MacroAssembler* masm);
100
101 virtual void check_oop(MacroAssembler* masm, Register obj, Register tmp1, Register tmp2, Label& error);
102
103 virtual bool supports_instruction_patching() {
104 NMethodPatchingType patching_type = nmethod_patching_type();
105 return patching_type == NMethodPatchingType::conc_instruction_and_data_patch ||
106 patching_type == NMethodPatchingType::stw_instruction_and_data_patch;
107 }
108
109 static address patching_epoch_addr();
110 static void clear_patching_epoch();
111 static void increment_patching_epoch();
112
113 // See AS_NO_KEEPALIVE for peek semantics
114 // weak_handle and obj may alias
115 virtual void try_peek_weak_handle_in_nmethod(MacroAssembler* masm, Register weak_handle, Register obj,
116 Register tmp, Label& slow_path);
117
118 #ifdef COMPILER2
119 OptoReg::Name refine_register(const Node* node,
120 OptoReg::Name opto_reg);
121 #endif // COMPILER2
122 };
123
124 #ifdef COMPILER2
125
126 // This class saves and restores the registers that need to be preserved across
127 // the runtime call represented by a given C2 barrier stub. Use as follows:
128 // {
129 // SaveLiveRegisters save(masm, stub);
130 // ..
131 // __ jalr(...);
132 // ..
133 // }
134 class SaveLiveRegisters {
135 private:
136 MacroAssembler* const _masm;
137 RegSet _gp_regs;
138 FloatRegSet _fp_regs;
139 VectorRegSet _vp_regs;
140
141 public:
142 void initialize(BarrierStubC2* stub);
143 SaveLiveRegisters(MacroAssembler* masm, BarrierStubC2* stub);
144 ~SaveLiveRegisters();
145 };
146
147 #endif // COMPILER2
148
149 #endif // CPU_RISCV_GC_SHARED_BARRIERSETASSEMBLER_RISCV_HPP