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 flat_field_copy(MacroAssembler* masm, DecoratorSet decorators,
64 Register src, Register dst, Register inline_layout_info);
65
66 virtual void resolve_jobject(MacroAssembler* masm, Register value,
67 Register tmp1, Register tmp2,
68 MacroAssembler::PreservationLevel preservation_level);
69 virtual void resolve_global_jobject(MacroAssembler* masm, Register value,
70 Register tmp1, Register tmp2,
71 MacroAssembler::PreservationLevel preservation_level);
72
73 virtual void try_resolve_jobject_in_native(MacroAssembler* masm, Register dst, Register jni_env,
74 Register obj, Register tmp, Label& slowpath);
75
76 // See AS_NO_KEEPALIVE for peek semantics
77 // weak_handle and obj may alias
78 virtual void try_peek_weak_handle_in_nmethod(MacroAssembler* masm, Register weak_handle, Register obj,
79 Register tmp, Label& slow_path);
80
81 virtual void barrier_stubs_init() {}
82
83 virtual NMethodPatchingType nmethod_patching_type() { return NMethodPatchingType::stw_instruction_and_data_patch; }
84
85 virtual void nmethod_entry_barrier(MacroAssembler* masm, Register tmp);
86 virtual void c2i_entry_barrier(MacroAssembler* masm, Register tmp1, Register tmp2, Register tmp3);
87
88 virtual void check_oop(MacroAssembler *masm, Register oop, const char* msg);
89
90 #ifdef COMPILER2
91 OptoReg::Name refine_register(const Node* node, OptoReg::Name opto_reg) const;
92 #endif // COMPILER2
93 };
94
95 #ifdef COMPILER2
96
97 // This class saves and restores the registers that need to be preserved across
98 // the runtime call represented by a given C2 barrier stub. Use as follows:
99 // {
100 // SaveLiveRegisters save(masm, stub);
101 // ..
102 // __ call_VM_leaf(...);
103 // ..
104 // }
105 class SaveLiveRegisters {
106 MacroAssembler* _masm;
107 RegMask _reg_mask;
108 int _frame_size;
109
110 public:
111 SaveLiveRegisters(MacroAssembler *masm, BarrierStubC2 *stub);
112
113 ~SaveLiveRegisters();
114
115 private:
116 enum IterationAction : int {
117 ACTION_SAVE,
118 ACTION_RESTORE,
119 ACTION_COUNT_ONLY
120 };
121
122 int iterate_over_register_mask(IterationAction action, int offset = 0);
123 };
124
125 #endif // COMPILER2
126
127 #endif // CPU_PPC_GC_SHARED_BARRIERSETASSEMBLER_PPC_HPP