1 /*
2 * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef CPU_X86_GC_SHARED_BARRIERSETASSEMBLER_X86_HPP
26 #define CPU_X86_GC_SHARED_BARRIERSETASSEMBLER_X86_HPP
27
28 #include "asm/macroAssembler.hpp"
29 #include "memory/allocation.hpp"
30 #include "oops/access.hpp"
31 #ifdef COMPILER2
32 #include "opto/optoreg.hpp"
33
34 class BarrierStubC2;
35 class Node;
36 #endif // COMPILER2
37 class InterpreterMacroAssembler;
38
39 class BarrierSetAssembler: public CHeapObj<mtGC> {
40 public:
41 virtual void arraycopy_prologue(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
42 Register src, Register dst, Register count) {}
43 virtual void arraycopy_epilogue(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
44 Register src, Register dst, Register count) {}
45
46 virtual void load_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
47 Register dst, Address src, Register tmp1);
48 virtual void store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
49 Address dst, Register val, Register tmp1, Register tmp2, Register tmp3);
50
51 virtual void flat_field_copy(MacroAssembler* masm, DecoratorSet decorators,
52 Register src, Register dst, Register inline_layout_info);
53
54 // The copy_[load/store]_at functions are used by arraycopy stubs. Be careful to only use
55 // r10 (aka rscratch1) in a context where restore_arg_regs_using_thread has been used instead
56 // of the looser setup_arg_regs. Currently this is done when using type T_OBJECT.
57 virtual void copy_load_at(MacroAssembler* masm,
58 DecoratorSet decorators,
59 BasicType type,
60 size_t bytes,
61 Register dst,
62 Address src,
63 Register tmp);
64
65 virtual void copy_store_at(MacroAssembler* masm,
66 DecoratorSet decorators,
67 BasicType type,
68 size_t bytes,
69 Address dst,
70 Register src,
71 Register tmp);
72
73 virtual void copy_load_at(MacroAssembler* masm,
74 DecoratorSet decorators,
75 BasicType type,
76 size_t bytes,
77 XMMRegister dst,
78 Address src,
79 Register tmp,
80 XMMRegister xmm_tmp);
81
82 virtual void copy_store_at(MacroAssembler* masm,
83 DecoratorSet decorators,
84 BasicType type,
85 size_t bytes,
86 Address dst,
87 XMMRegister src,
88 Register tmp1,
89 Register tmp2,
90 XMMRegister xmm_tmp);
91
92 virtual bool supports_avx3_masked_arraycopy() { return true; }
93
94 // Support for jniFastGetField to try resolving a jobject/jweak in native
95 virtual void try_resolve_jobject_in_native(MacroAssembler* masm, Register jni_env,
96 Register obj, Register tmp, Label& slowpath);
97
98 virtual void tlab_allocate(MacroAssembler* masm,
99 Register obj,
100 Register var_size_in_bytes,
101 int con_size_in_bytes,
102 Register t1, Register t2,
103 Label& slow_case);
104
105 virtual void barrier_stubs_init() {}
106
107 virtual void nmethod_entry_barrier(MacroAssembler* masm, Label* slow_path, Label* continuation);
108 virtual void c2i_entry_barrier(MacroAssembler* masm);
109
110 virtual void check_oop(MacroAssembler* masm, Register obj, Register tmp1, Register tmp2, Label& error);
111
112 #ifdef COMPILER2
113 OptoReg::Name refine_register(const Node* node,
114 OptoReg::Name opto_reg);
115 #endif // COMPILER2
116 };
117
118 #ifdef COMPILER2
119
120 // This class saves and restores the registers that need to be preserved across
121 // the runtime call represented by a given C2 barrier stub. Use as follows:
122 // {
123 // SaveLiveRegisters save(masm, stub);
124 // ..
125 // __ call(RuntimeAddress(...);
126 // ..
127 // }
128 class SaveLiveRegisters {
129 private:
130 struct XMMRegisterData {
131 XMMRegister _reg;
132 int _size;
133
134 // Used by GrowableArray::find()
135 bool operator == (const XMMRegisterData& other) {
136 return _reg == other._reg;
137 }
138 };
139
140 MacroAssembler* const _masm;
141 GrowableArray<Register> _gp_registers;
142 GrowableArray<KRegister> _opmask_registers;
143 GrowableArray<XMMRegisterData> _xmm_registers;
144 int _spill_size;
145 int _spill_offset;
146
147 static int xmm_compare_register_size(XMMRegisterData* left, XMMRegisterData* right);
148 static int xmm_slot_size(OptoReg::Name opto_reg);
149 static uint xmm_ideal_reg_for_size(int reg_size);
150 bool xmm_needs_vzeroupper() const;
151 void xmm_register_save(const XMMRegisterData& reg_data);
152 void xmm_register_restore(const XMMRegisterData& reg_data);
153 void gp_register_save(Register reg);
154 void opmask_register_save(KRegister reg);
155 void gp_register_restore(Register reg);
156 void opmask_register_restore(KRegister reg);
157 void initialize(BarrierStubC2* stub);
158
159 public:
160 SaveLiveRegisters(MacroAssembler* masm, BarrierStubC2* stub);
161 ~SaveLiveRegisters();
162 };
163
164 #endif // COMPILER2
165
166 #endif // CPU_X86_GC_SHARED_BARRIERSETASSEMBLER_X86_HPP