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 resolve_forward_pointer_not_null(MacroAssembler* masm, Register dst, Register tmp);
 73 
 74   void gen_write_ref_array_post_barrier(MacroAssembler* masm, DecoratorSet decorators,
 75                                         Register addr, Register count,
 76                                         Register preserve);
 77 
 78 public:
 79   virtual NMethodPatchingType nmethod_patching_type() { return NMethodPatchingType::conc_instruction_and_data_patch; }
 80 
 81   /* ==== C1 stubs ==== */
 82 #ifdef COMPILER1
 83 
 84   void gen_pre_barrier_stub(LIR_Assembler* ce, ShenandoahPreBarrierStub* stub);
 85 
 86   void gen_load_reference_barrier_stub(LIR_Assembler* ce, ShenandoahLoadReferenceBarrierStub* stub);
 87 
 88   void generate_c1_pre_barrier_runtime_stub(StubAssembler* sasm);
 89 
 90   void generate_c1_load_reference_barrier_runtime_stub(StubAssembler* sasm, DecoratorSet decorators);
 91 
 92 #endif
 93 
 94   /* ==== Available barriers (facades of the actual implementations) ==== */
 95   void satb_barrier(MacroAssembler* masm,
 96                     Register base, RegisterOrConstant ind_or_offs,
 97                     Register tmp1, Register tmp2, Register tmp3,
 98                     MacroAssembler::PreservationLevel preservation_level);
 99 
100   void load_reference_barrier(MacroAssembler* masm, DecoratorSet decorators,
101                               Register base, RegisterOrConstant ind_or_offs,
102                               Register dst,
103                               Register tmp1, Register tmp2,
104                               MacroAssembler::PreservationLevel preservation_level);
105 
106   /* ==== Helper methods used by C1 and C2 ==== */
107   void cmpxchg_oop(MacroAssembler* masm, Register base_addr, Register expected, Register new_val,
108                    Register tmp1, Register tmp2,
109                    bool is_cae, Register result);
110 
111   /* ==== Access api ==== */
112   virtual void arraycopy_prologue(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
113                                   Register src, Register dst, Register count,
114                                   Register preserve1, Register preserve2);
115   virtual void arraycopy_epilogue(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
116                                   Register dst, Register count,
117                                   Register preserve);
118 
119   virtual void store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
120                         Register base, RegisterOrConstant ind_or_offs, Register val,
121                         Register tmp1, Register tmp2, Register tmp3,
122                         MacroAssembler::PreservationLevel preservation_level);
123 
124   virtual void load_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
125                        Register base, RegisterOrConstant ind_or_offs, Register dst,
126                        Register tmp1, Register tmp2,
127                        MacroAssembler::PreservationLevel preservation_level, Label* L_handle_null = nullptr);
128 
129   virtual void try_resolve_jobject_in_native(MacroAssembler* masm, Register dst, Register jni_env,
130                                              Register obj, Register tmp, Label& slowpath);
131 
132   virtual void try_resolve_weak_handle(MacroAssembler* masm, Register obj, Register tmp, Label& slow_path);
133 
134 #ifdef COMPILER2
135   // Entry points from Matcher
136   void load_c2(const MachNode* node, MacroAssembler* masm,
137                Register dst, Address addr);
138 
139   void store_c2(const MachNode* node, MacroAssembler* masm,
140                 Address dst, bool dst_narrow, Register src, bool src_narrow);
141 
142   void compare_and_set_c2(const MachNode* node, MacroAssembler* masm,
143                           Register res, Register addr, Register oldval,
144                           Register newval, bool exchange, bool narrow, bool weak);
145 
146   void get_and_set_c2(const MachNode* node, MacroAssembler* masm,
147                       Register preval, Register newval, Register addr);
148 
149   void card_barrier_c2(const MachNode* node, MacroAssembler* masm,
150                        Address addr);
151 #endif // COMPILER2
152 };
153 
154 #endif // CPU_PPC_GC_SHENANDOAH_SHENANDOAHBARRIERSETASSEMBLER_PPC_HPP