1 /* 2 * Copyright (c) 2018, 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 // The copy_[load/store]_at functions are used by arraycopy stubs. Be careful to only use 52 // r10 (aka rscratch1) in a context where restore_arg_regs_using_thread has been used instead 53 // of the looser setup_arg_regs. Currently this is done when using type T_OBJECT. 54 virtual void copy_load_at(MacroAssembler* masm, 55 DecoratorSet decorators, 56 BasicType type, 57 size_t bytes, 58 Register dst, 59 Address src, 60 Register tmp); 61 62 virtual void copy_store_at(MacroAssembler* masm, 63 DecoratorSet decorators, 64 BasicType type, 65 size_t bytes, 66 Address dst, 67 Register src, 68 Register tmp); 69 70 virtual void copy_load_at(MacroAssembler* masm, 71 DecoratorSet decorators, 72 BasicType type, 73 size_t bytes, 74 XMMRegister dst, 75 Address src, 76 Register tmp, 77 XMMRegister xmm_tmp); 78 79 virtual void copy_store_at(MacroAssembler* masm, 80 DecoratorSet decorators, 81 BasicType type, 82 size_t bytes, 83 Address dst, 84 XMMRegister src, 85 Register tmp1, 86 Register tmp2, 87 XMMRegister xmm_tmp); 88 89 virtual bool supports_avx3_masked_arraycopy() { return true; } 90 91 // Support for jniFastGetField to try resolving a jobject/jweak in native 92 virtual void try_resolve_jobject_in_native(MacroAssembler* masm, Register jni_env, 93 Register obj, Register tmp, Label& slowpath); 94 95 virtual void tlab_allocate(MacroAssembler* masm, 96 Register thread, Register obj, 97 Register var_size_in_bytes, 98 int con_size_in_bytes, 99 Register t1, Register t2, 100 Label& slow_case); 101 102 virtual void barrier_stubs_init() {} 103 104 virtual void nmethod_entry_barrier(MacroAssembler* masm, Label* slow_path, Label* continuation); 105 virtual void c2i_entry_barrier(MacroAssembler* masm); 106 107 virtual void check_oop(MacroAssembler* masm, Register obj, Register tmp1, Register tmp2, Label& error); 108 109 #ifdef COMPILER2 110 OptoReg::Name refine_register(const Node* node, 111 OptoReg::Name opto_reg); 112 #endif // COMPILER2 113 }; 114 115 #ifdef COMPILER2 116 117 #ifdef _LP64 118 119 // This class saves and restores the registers that need to be preserved across 120 // the runtime call represented by a given C2 barrier stub. Use as follows: 121 // { 122 // SaveLiveRegisters save(masm, stub); 123 // .. 124 // __ call(RuntimeAddress(...); 125 // .. 126 // } 127 class SaveLiveRegisters { 128 private: 129 struct XMMRegisterData { 130 XMMRegister _reg; 131 int _size; 132 133 // Used by GrowableArray::find() 134 bool operator == (const XMMRegisterData& other) { 135 return _reg == other._reg; 136 } 137 }; 138 139 MacroAssembler* const _masm; 140 GrowableArray<Register> _gp_registers; 141 GrowableArray<KRegister> _opmask_registers; 142 GrowableArray<XMMRegisterData> _xmm_registers; 143 int _spill_size; 144 int _spill_offset; 145 146 static int xmm_compare_register_size(XMMRegisterData* left, XMMRegisterData* right); 147 static int xmm_slot_size(OptoReg::Name opto_reg); 148 static uint xmm_ideal_reg_for_size(int reg_size); 149 bool xmm_needs_vzeroupper() const; 150 void xmm_register_save(const XMMRegisterData& reg_data); 151 void xmm_register_restore(const XMMRegisterData& reg_data); 152 void gp_register_save(Register reg); 153 void opmask_register_save(KRegister reg); 154 void gp_register_restore(Register reg); 155 void opmask_register_restore(KRegister reg); 156 void initialize(BarrierStubC2* stub); 157 158 public: 159 SaveLiveRegisters(MacroAssembler* masm, BarrierStubC2* stub); 160 ~SaveLiveRegisters(); 161 }; 162 163 #endif // _LP64 164 165 #endif // COMPILER2 166 167 #endif // CPU_X86_GC_SHARED_BARRIERSETASSEMBLER_X86_HPP