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, Register tmp_thread); 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 thread, 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 #ifdef _LP64 121 122 // This class saves and restores the registers that need to be preserved across 123 // the runtime call represented by a given C2 barrier stub. Use as follows: 124 // { 125 // SaveLiveRegisters save(masm, stub); 126 // .. 127 // __ call(RuntimeAddress(...); 128 // .. 129 // } 130 class SaveLiveRegisters { 131 private: 132 struct XMMRegisterData { 133 XMMRegister _reg; 134 int _size; 135 136 // Used by GrowableArray::find() 137 bool operator == (const XMMRegisterData& other) { 138 return _reg == other._reg; 139 } 140 }; 141 142 MacroAssembler* const _masm; 143 GrowableArray<Register> _gp_registers; 144 GrowableArray<KRegister> _opmask_registers; 145 GrowableArray<XMMRegisterData> _xmm_registers; 146 int _spill_size; 147 int _spill_offset; 148 149 static int xmm_compare_register_size(XMMRegisterData* left, XMMRegisterData* right); 150 static int xmm_slot_size(OptoReg::Name opto_reg); 151 static uint xmm_ideal_reg_for_size(int reg_size); 152 bool xmm_needs_vzeroupper() const; 153 void xmm_register_save(const XMMRegisterData& reg_data); 154 void xmm_register_restore(const XMMRegisterData& reg_data); 155 void gp_register_save(Register reg); 156 void opmask_register_save(KRegister reg); 157 void gp_register_restore(Register reg); 158 void opmask_register_restore(KRegister reg); 159 void initialize(BarrierStubC2* stub); 160 161 public: 162 SaveLiveRegisters(MacroAssembler* masm, BarrierStubC2* stub); 163 ~SaveLiveRegisters(); 164 }; 165 166 #endif // _LP64 167 168 #endif // COMPILER2 169 170 #endif // CPU_X86_GC_SHARED_BARRIERSETASSEMBLER_X86_HPP