1 /*
   2  * Copyright (c) 2018, Red Hat, Inc. All rights reserved.
   3  *
   4  * This code is free software; you can redistribute it and/or modify it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.
   7  *
   8  * This code is distributed in the hope that it will be useful, but WITHOUT
   9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11  * version 2 for more details (a copy is included in the LICENSE file that
  12  * accompanied this code).
  13  *
  14  * You should have received a copy of the GNU General Public License version
  15  * 2 along with this work; if not, write to the Free Software Foundation,
  16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  17  *
  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  *
  22  */
  23 
  24 #ifndef SHARE_GC_SHENANDOAH_C1_SHENANDOAHBARRIERSETC1_HPP
  25 #define SHARE_GC_SHENANDOAH_C1_SHENANDOAHBARRIERSETC1_HPP
  26 
  27 #include "c1/c1_CodeStubs.hpp"
  28 #include "memory/allocation.hpp"
  29 
  30 class LIRGenerator;
  31 
  32 class ShenandoahLoadReferenceBarrierStub: public CodeStub {
  33   friend class ShenandoahBarrierSetC1;
  34 private:
  35   LIR_Opr _obj;
  36   LIR_Opr _result;
  37   CodeEmitInfo* _info;
  38   bool _needs_null_check;
  39 
  40 public:
  41   ShenandoahLoadReferenceBarrierStub(LIR_Opr obj, LIR_Opr result, CodeEmitInfo* info, bool needs_null_check) :
  42     _obj(obj), _result(result), _info(info), _needs_null_check(needs_null_check)
  43   {
  44     assert(_obj->is_register(), "should be register");
  45     assert(_result->is_register(), "should be register");
  46   }
  47 
  48   LIR_Opr obj() const { return _obj; }
  49   LIR_Opr result() const { return _result; }
  50   CodeEmitInfo* info() const { return _info; }
  51   bool needs_null_check() const { return _needs_null_check; }
  52 
  53   virtual void emit_code(LIR_Assembler* e);
  54   virtual void visit(LIR_OpVisitState* visitor) {
  55     visitor->do_slow_case();
  56     visitor->do_input(_obj);
  57     visitor->do_temp(_result);
  58   }
  59 #ifndef PRODUCT
  60   virtual void print_name(outputStream* out) const { out->print("ShenandoahLoadReferenceBarrierStub"); }
  61 #endif // PRODUCT
  62 };
  63 
  64 class ShenandoahBarrierSetC1  : public CHeapObj<mtGC>{
  65 private:
  66   CodeBlob* _pre_barrier_c1_runtime_code_blob;
  67 public:
  68   static ShenandoahBarrierSetC1* bsc1();
  69 
  70   LIR_Opr load_reference_barrier(LIRGenerator* gen, LIR_Opr obj, CodeEmitInfo* info, bool need_null_check);
  71   LIR_Opr storeval_barrier(LIRGenerator* gen, LIR_Opr obj, CodeEmitInfo* info, bool patch);
  72 private:
  73   LIR_Opr load_reference_barrier_impl(LIRGenerator* gen, LIR_Opr obj, CodeEmitInfo* info, bool need_null_check);
  74   LIR_Opr ensure_in_register(LIRGenerator* gen, LIR_Opr obj);
  75 
  76 };
  77 
  78 #endif // SHARE_GC_SHENANDOAH_C1_SHENANDOAHBARRIERSETC1_HPP