1 /* 2 * Copyright (c) 2018, 2019, Red Hat, Inc. 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 SHARE_GC_SHENANDOAH_C1_SHENANDOAHBARRIERSETC1_HPP 26 #define SHARE_GC_SHENANDOAH_C1_SHENANDOAHBARRIERSETC1_HPP 27 28 #include "c1/c1_CodeStubs.hpp" 29 #include "gc/shared/c1/barrierSetC1.hpp" 30 31 class ShenandoahPreBarrierStub: public CodeStub { 32 friend class ShenandoahBarrierSetC1; 33 private: 34 bool _do_load; 35 LIR_Opr _addr; 36 LIR_Opr _pre_val; 37 LIR_PatchCode _patch_code; 38 CodeEmitInfo* _info; 39 40 public: 41 // Version that _does_ generate a load of the previous value from addr. 42 // addr (the address of the field to be read) must be a LIR_Address 43 // pre_val (a temporary register) must be a register; 44 ShenandoahPreBarrierStub(LIR_Opr addr, LIR_Opr pre_val, LIR_PatchCode patch_code, CodeEmitInfo* info) : 45 _do_load(true), _addr(addr), _pre_val(pre_val), 46 _patch_code(patch_code), _info(info) 47 { 48 assert(_pre_val->is_register(), "should be temporary register"); 49 assert(_addr->is_address(), "should be the address of the field"); 50 } 51 52 // Version that _does not_ generate load of the previous value; the 53 // previous value is assumed to have already been loaded into pre_val. 54 ShenandoahPreBarrierStub(LIR_Opr pre_val) : 55 _do_load(false), _addr(LIR_OprFact::illegalOpr), _pre_val(pre_val), 56 _patch_code(lir_patch_none), _info(NULL) 57 { 58 assert(_pre_val->is_register(), "should be a register"); 59 } 60 61 LIR_Opr addr() const { return _addr; } 62 LIR_Opr pre_val() const { return _pre_val; } 63 LIR_PatchCode patch_code() const { return _patch_code; } 64 CodeEmitInfo* info() const { return _info; } 65 bool do_load() const { return _do_load; } 66 67 virtual void emit_code(LIR_Assembler* e); 68 virtual void visit(LIR_OpVisitState* visitor) { 69 if (_do_load) { 70 // don't pass in the code emit info since it's processed in the fast 71 // path 72 if (_info != NULL) 73 visitor->do_slow_case(_info); 74 else 75 visitor->do_slow_case(); 76 77 visitor->do_input(_addr); 78 visitor->do_temp(_pre_val); 79 } else { 80 visitor->do_slow_case(); 81 visitor->do_input(_pre_val); 82 } 83 } 84 #ifndef PRODUCT 85 virtual void print_name(outputStream* out) const { out->print("ShenandoahPreBarrierStub"); } 86 #endif // PRODUCT 87 }; 88 89 class ShenandoahLoadReferenceBarrierStub: public CodeStub { 90 friend class ShenandoahBarrierSetC1; 91 private: 92 LIR_Opr _obj; 93 LIR_Opr _addr; 94 LIR_Opr _result; 95 LIR_Opr _tmp1; 96 LIR_Opr _tmp2; 97 98 public: 99 ShenandoahLoadReferenceBarrierStub(LIR_Opr obj, LIR_Opr addr, LIR_Opr result, LIR_Opr tmp1, LIR_Opr tmp2) : 100 _obj(obj), _addr(addr), _result(result), _tmp1(tmp1), _tmp2(tmp2) 101 { 102 assert(_obj->is_register(), "should be register"); 103 assert(_addr->is_register(), "should be register"); 104 assert(_result->is_register(), "should be register"); 105 assert(_tmp1->is_register(), "should be register"); 106 assert(_tmp2->is_register(), "should be register"); 107 } 108 109 LIR_Opr obj() const { return _obj; } 110 LIR_Opr addr() const { return _addr; } 111 LIR_Opr result() const { return _result; } 112 LIR_Opr tmp1() const { return _tmp1; } 113 LIR_Opr tmp2() const { return _tmp2; } 114 115 virtual void emit_code(LIR_Assembler* e); 116 virtual void visit(LIR_OpVisitState* visitor) { 117 visitor->do_slow_case(); 118 visitor->do_input(_obj); 119 visitor->do_temp(_obj); 120 visitor->do_input(_addr); 121 visitor->do_temp(_addr); 122 visitor->do_temp(_result); 123 visitor->do_temp(_tmp1); 124 visitor->do_temp(_tmp2); 125 } 126 #ifndef PRODUCT 127 virtual void print_name(outputStream* out) const { out->print("ShenandoahLoadReferenceBarrierStub"); } 128 #endif // PRODUCT 129 }; 130 131 class LIR_OpShenandoahCompareAndSwap : public LIR_Op { 132 friend class LIR_OpVisitState; 133 134 private: 135 LIR_Opr _addr; 136 LIR_Opr _cmp_value; 137 LIR_Opr _new_value; 138 LIR_Opr _tmp1; 139 LIR_Opr _tmp2; 140 141 public: 142 LIR_OpShenandoahCompareAndSwap(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value, 143 LIR_Opr t1, LIR_Opr t2, LIR_Opr result) 144 : LIR_Op(lir_none, result, NULL) // no info 145 , _addr(addr) 146 , _cmp_value(cmp_value) 147 , _new_value(new_value) 148 , _tmp1(t1) 149 , _tmp2(t2) { } 150 151 LIR_Opr addr() const { return _addr; } 152 LIR_Opr cmp_value() const { return _cmp_value; } 153 LIR_Opr new_value() const { return _new_value; } 154 LIR_Opr tmp1() const { return _tmp1; } 155 LIR_Opr tmp2() const { return _tmp2; } 156 157 virtual void visit(LIR_OpVisitState* state) { 158 assert(_addr->is_valid(), "used"); 159 assert(_cmp_value->is_valid(), "used"); 160 assert(_new_value->is_valid(), "used"); 161 if (_info) state->do_info(_info); 162 state->do_input(_addr); 163 state->do_temp(_addr); 164 state->do_input(_cmp_value); 165 state->do_temp(_cmp_value); 166 state->do_input(_new_value); 167 state->do_temp(_new_value); 168 if (_tmp1->is_valid()) state->do_temp(_tmp1); 169 if (_tmp2->is_valid()) state->do_temp(_tmp2); 170 if (_result->is_valid()) state->do_output(_result); 171 } 172 173 virtual void emit_code(LIR_Assembler* masm); 174 175 virtual void print_instr(outputStream* out) const { 176 addr()->print(out); out->print(" "); 177 cmp_value()->print(out); out->print(" "); 178 new_value()->print(out); out->print(" "); 179 tmp1()->print(out); out->print(" "); 180 tmp2()->print(out); out->print(" "); 181 } 182 #ifndef PRODUCT 183 virtual const char* name() const { 184 return "shenandoah_cas_obj"; 185 } 186 #endif // PRODUCT 187 }; 188 189 class ShenandoahBarrierSetC1 : public BarrierSetC1 { 190 private: 191 CodeBlob* _pre_barrier_c1_runtime_code_blob; 192 CodeBlob* _load_reference_barrier_rt_code_blob; 193 194 void pre_barrier(LIRGenerator* gen, CodeEmitInfo* info, DecoratorSet decorators, LIR_Opr addr_opr, LIR_Opr pre_val); 195 196 LIR_Opr load_reference_barrier(LIRGenerator* gen, LIR_Opr obj, LIR_Opr addr); 197 LIR_Opr storeval_barrier(LIRGenerator* gen, LIR_Opr obj, CodeEmitInfo* info, DecoratorSet decorators); 198 199 LIR_Opr load_reference_barrier_impl(LIRGenerator* gen, LIR_Opr obj, LIR_Opr addr); 200 201 LIR_Opr ensure_in_register(LIRGenerator* gen, LIR_Opr obj, BasicType type); 202 203 public: 204 ShenandoahBarrierSetC1(); 205 206 CodeBlob* pre_barrier_c1_runtime_code_blob() { 207 assert(_pre_barrier_c1_runtime_code_blob != NULL, ""); 208 return _pre_barrier_c1_runtime_code_blob; 209 } 210 211 CodeBlob* load_reference_barrier_rt_code_blob() { 212 assert(_load_reference_barrier_rt_code_blob != NULL, ""); 213 return _load_reference_barrier_rt_code_blob; 214 } 215 216 protected: 217 218 virtual void store_at_resolved(LIRAccess& access, LIR_Opr value); 219 virtual LIR_Opr resolve_address(LIRAccess& access, bool resolve_in_register); 220 virtual void load_at_resolved(LIRAccess& access, LIR_Opr result); 221 222 virtual LIR_Opr atomic_cmpxchg_at_resolved(LIRAccess& access, LIRItem& cmp_value, LIRItem& new_value); 223 224 virtual LIR_Opr atomic_xchg_at_resolved(LIRAccess& access, LIRItem& value); 225 226 public: 227 228 virtual void generate_c1_runtime_stubs(BufferBlob* buffer_blob); 229 virtual const char* rtcall_name_for_address(address entry); 230 }; 231 232 #endif // SHARE_GC_SHENANDOAH_C1_SHENANDOAHBARRIERSETC1_HPP