1 /*
2 * Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2018, 2022, Red Hat, Inc. All rights reserved.
4 * Copyright (c) 2012, 2026 SAP SE. All rights reserved.
5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 *
7 * This code is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 only, as
9 * published by the Free Software Foundation.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 *
25 */
26
27 #ifndef CPU_PPC_GC_SHENANDOAH_SHENANDOAHBARRIERSETASSEMBLER_PPC_HPP
28 #define CPU_PPC_GC_SHENANDOAH_SHENANDOAHBARRIERSETASSEMBLER_PPC_HPP
29
30 #include "asm/macroAssembler.hpp"
31 #include "gc/shared/barrierSetAssembler.hpp"
32 #include "gc/shenandoah/shenandoahBarrierSet.hpp"
33
34 #ifdef COMPILER1
35
36 class LIR_Assembler;
37 class ShenandoahPreBarrierStub;
38 class ShenandoahLoadReferenceBarrierStub;
39 class StubAssembler;
40
41 #endif
42
43 #ifdef COMPILER2
44
45 class MachNode;
46
47 #endif
48
49 class StubCodeGenerator;
50
51 class ShenandoahBarrierSetAssembler: public BarrierSetAssembler {
52 private:
53
54 /* ==== Actual barrier implementations ==== */
55 void satb_barrier_impl(MacroAssembler* masm, DecoratorSet decorators,
56 Register base, RegisterOrConstant ind_or_offs,
57 Register pre_val,
58 Register tmp1, Register tmp2,
59 MacroAssembler::PreservationLevel preservation_level);
60
61 void card_barrier(MacroAssembler* masm,
62 Register base, RegisterOrConstant ind_or_offs,
63 Register tmp);
64
65 void load_reference_barrier_impl(MacroAssembler* masm, DecoratorSet decorators,
66 Register base, RegisterOrConstant ind_or_offs,
67 Register dst,
68 Register tmp1, Register tmp2,
69 MacroAssembler::PreservationLevel preservation_level);
70
71 /* ==== Helper methods for barrier implementations ==== */
72 void gen_write_ref_array_post_barrier(MacroAssembler* masm, DecoratorSet decorators,
73 Register addr, Register count,
74 Register preserve);
75
76 public:
77 virtual NMethodPatchingType nmethod_patching_type() { return NMethodPatchingType::conc_instruction_and_data_patch; }
78
79 /* ==== C1 stubs ==== */
80 #ifdef COMPILER1
81
82 void gen_pre_barrier_stub(LIR_Assembler* ce, ShenandoahPreBarrierStub* stub);
83
84 void gen_load_reference_barrier_stub(LIR_Assembler* ce, ShenandoahLoadReferenceBarrierStub* stub);
85
86 void generate_c1_pre_barrier_runtime_stub(StubAssembler* sasm);
87
88 void generate_c1_load_reference_barrier_runtime_stub(StubAssembler* sasm, DecoratorSet decorators);
89
90 #endif
91
92 /* ==== Available barriers (facades of the actual implementations) ==== */
93 void satb_barrier(MacroAssembler* masm,
94 Register base, RegisterOrConstant ind_or_offs,
95 Register tmp1, Register tmp2, Register tmp3,
96 MacroAssembler::PreservationLevel preservation_level);
97
98 void load_reference_barrier(MacroAssembler* masm, DecoratorSet decorators,
99 Register base, RegisterOrConstant ind_or_offs,
100 Register dst,
101 Register tmp1, Register tmp2,
102 MacroAssembler::PreservationLevel preservation_level);
103
104 /* ==== Access api ==== */
105 virtual void arraycopy_prologue(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
106 Register src, Register dst, Register count,
107 Register preserve1, Register preserve2);
108 virtual void arraycopy_epilogue(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
109 Register dst, Register count,
110 Register preserve);
111
112 virtual void store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
113 Register base, RegisterOrConstant ind_or_offs, Register val,
114 Register tmp1, Register tmp2, Register tmp3,
115 MacroAssembler::PreservationLevel preservation_level);
116
117 virtual void load_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
118 Register base, RegisterOrConstant ind_or_offs, Register dst,
119 Register tmp1, Register tmp2,
120 MacroAssembler::PreservationLevel preservation_level, Label* L_handle_null = nullptr);
121
122 virtual void try_resolve_jobject_in_native(MacroAssembler* masm, Register dst, Register jni_env,
123 Register obj, Register tmp, Label& slowpath);
124
125 virtual void try_peek_weak_handle_in_nmethod(MacroAssembler* masm, Register weak_handle, Register obj,
126 Register tmp, Label& slow_path);
127
128 #ifdef COMPILER2
129 // Barrier hotpatching
130 static address parse_stub_address(address pc);
131 static bool is_active(address pc);
132 static void patch_branch_to_nop(address pc);
133 static void patch_nop_to_branch(address pc, address stub_addr);
134
135 // Entry points from Matcher
136 void load_c2(const MachNode* node, MacroAssembler* masm, Register dst, Register addr, int disp, Register tmp1, Register tmp2, bool narrow, bool acquire);
137
138 void store_c2(const MachNode* node, MacroAssembler* masm,
139 Register dst, int disp, bool dst_narrow, Register src, bool src_narrow, Register tmp1, Register tmp2, Register tmp3);
140
141 void compare_and_set_c2(const MachNode* node, MacroAssembler* masm, Register res, Register addr, Register oldval,
142 Register newval, Register tmp1, Register tmp2, bool exchange, bool narrow, bool weak, bool acquire);
143
144 void get_and_set_c2(const MachNode* node, MacroAssembler* masm,
145 Register preval, Register newval, Register addr, Register tmp1, Register tmp2);
146 #endif // COMPILER2
147 };
148
149 #endif // CPU_PPC_GC_SHENANDOAH_SHENANDOAHBARRIERSETASSEMBLER_PPC_HPP