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