1 /*
  2  * Copyright (c) 2018, 2026, Oracle and/or its affiliates. All rights reserved.
  3  * Copyright (c) 2018, 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  *
 24  */
 25 
 26 #ifndef CPU_PPC_GC_SHARED_BARRIERSETASSEMBLER_PPC_HPP
 27 #define CPU_PPC_GC_SHARED_BARRIERSETASSEMBLER_PPC_HPP
 28 
 29 #include "asm/macroAssembler.hpp"
 30 #include "memory/allocation.hpp"
 31 #include "oops/access.hpp"
 32 #ifdef COMPILER2
 33 #include "code/vmreg.hpp"
 34 #include "opto/optoreg.hpp"
 35 #include "opto/regmask.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, BasicType type,
 49                                   Register src, Register dst, Register count, Register preserve1, Register preserve2) {}
 50   virtual void arraycopy_epilogue(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
 51                                   Register dst, Register count, Register preserve) {}
 52 
 53   virtual void store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
 54                         Register base, RegisterOrConstant ind_or_offs, Register val,
 55                         Register tmp1, Register tmp2, Register tmp3,
 56                         MacroAssembler::PreservationLevel preservation_level);
 57 
 58   virtual void load_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
 59                        Register base, RegisterOrConstant ind_or_offs, Register dst,
 60                        Register tmp1, Register tmp2,
 61                        MacroAssembler::PreservationLevel preservation_level, Label *L_handle_null = nullptr);
 62 
 63   virtual void resolve_jobject(MacroAssembler* masm, Register value,
 64                                Register tmp1, Register tmp2,
 65                                MacroAssembler::PreservationLevel preservation_level);
 66   virtual void resolve_global_jobject(MacroAssembler* masm, Register value,
 67                                       Register tmp1, Register tmp2,
 68                                       MacroAssembler::PreservationLevel preservation_level);
 69 
 70   virtual void try_resolve_jobject_in_native(MacroAssembler* masm, Register dst, Register jni_env,
 71                                              Register obj, Register tmp, Label& slowpath);
 72 
 73   // See AS_NO_KEEPALIVE for peek semantics
 74   // weak_handle and obj may alias
 75   virtual void try_peek_weak_handle_in_nmethod(MacroAssembler* masm, Register weak_handle, Register obj,
 76                                                Register tmp, Label& slow_path);
 77 
 78   virtual void barrier_stubs_init() {}
 79 
 80   virtual NMethodPatchingType nmethod_patching_type() { return NMethodPatchingType::stw_instruction_and_data_patch; }
 81 
 82   virtual void nmethod_entry_barrier(MacroAssembler* masm, Register tmp);
 83   virtual void c2i_entry_barrier(MacroAssembler* masm, Register tmp1, Register tmp2, Register tmp3);
 84 
 85   virtual void check_oop(MacroAssembler *masm, Register oop, const char* msg);
 86 
 87 #ifdef COMPILER2
 88   OptoReg::Name refine_register(const Node* node, OptoReg::Name opto_reg) const;
 89 #endif // COMPILER2
 90 };
 91 
 92 #ifdef COMPILER2
 93 
 94 // This class saves and restores the registers that need to be preserved across
 95 // the runtime call represented by a given C2 barrier stub. Use as follows:
 96 // {
 97 //   SaveLiveRegisters save(masm, stub);
 98 //   ..
 99 //   __ call_VM_leaf(...);
100 //   ..
101 // }
102 class SaveLiveRegisters {
103   MacroAssembler* _masm;
104   RegMask _reg_mask;
105   int _frame_size;
106 
107  public:
108   SaveLiveRegisters(MacroAssembler *masm, BarrierStubC2 *stub);
109 
110   ~SaveLiveRegisters();
111 
112  private:
113   enum IterationAction : int {
114     ACTION_SAVE,
115     ACTION_RESTORE,
116     ACTION_COUNT_ONLY
117   };
118 
119   int iterate_over_register_mask(IterationAction action, int offset = 0);
120 };
121 
122 #endif // COMPILER2
123 
124 #endif // CPU_PPC_GC_SHARED_BARRIERSETASSEMBLER_PPC_HPP