1 /*
   2  * Copyright (c) 2013, 2015, Red Hat, Inc. and/or its affiliates.
   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_VM_GC_SHENANDOAH_SHENANDOAHBARRIERSET_HPP
  25 #define SHARE_VM_GC_SHENANDOAH_SHENANDOAHBARRIERSET_HPP
  26 
  27 #include "memory/barrierSet.hpp"
  28 
  29 class ShenandoahHeap;
  30 
  31 class ShenandoahBarrierSet: public BarrierSet {
  32 private:
  33 
  34   ShenandoahHeap* _heap;
  35 
  36 public:
  37 
  38   ShenandoahBarrierSet(ShenandoahHeap* heap);
  39 
  40   inline static ShenandoahBarrierSet* barrier_set() {
  41     BarrierSet *bs = oopDesc::bs();
  42     assert(bs->kind() == BarrierSet::ShenandoahBarrierSet, "sanity");
  43     return (ShenandoahBarrierSet*)bs;
  44   }
  45 
  46   void print_on(outputStream* st) const;
  47 
  48   bool is_a(BarrierSet::Name bsn);
  49 
  50   bool has_read_prim_array_opt();
  51   bool has_read_prim_barrier();
  52   bool has_read_ref_array_opt();
  53   bool has_read_ref_barrier();
  54   bool has_read_region_opt();
  55   bool has_write_prim_array_opt();
  56   bool has_write_prim_barrier();
  57   bool has_write_ref_array_opt();
  58   bool has_write_ref_barrier();
  59   bool has_write_ref_pre_barrier();
  60   bool has_write_region_opt();
  61   bool is_aligned(HeapWord* hw);
  62   void read_prim_array(MemRegion mr);
  63   void read_prim_field(HeapWord* hw, size_t s);
  64   bool read_prim_needs_barrier(HeapWord* hw, size_t s);
  65   void read_ref_array(MemRegion mr);
  66 
  67   void read_ref_field(void* v);
  68 
  69   bool read_ref_needs_barrier(void* v);
  70   void read_region(MemRegion mr);
  71   void resize_covered_region(MemRegion mr);
  72   void write_prim_array(MemRegion mr);
  73   void write_prim_field(HeapWord* hw, size_t s , juint x, juint y);
  74   bool write_prim_needs_barrier(HeapWord* hw, size_t s, juint x, juint y);
  75   void write_ref_array(HeapWord* start, size_t count);
  76   void write_ref_array_work(MemRegion r);
  77 
  78   template <class T> void
  79   write_ref_array_pre_work(T* dst, size_t count);
  80 
  81   void write_ref_array_pre(oop* dst, int count, bool dest_uninitialized);
  82 
  83   void write_ref_array_pre(narrowOop* dst, int count, bool dest_uninitialized);
  84 
  85 
  86   template <class T> static void write_ref_field_pre_static(T* field, oop newVal);
  87 
  88   // We export this to make it available in cases where the static
  89   // type of the barrier set is known.  Note that it is non-virtual.
  90   template <class T> inline void inline_write_ref_field_pre(T* field, oop newVal);
  91 
  92   // These are the more general virtual versions.
  93   void write_ref_field_pre_work(oop* field, oop new_val);
  94   void write_ref_field_pre_work(narrowOop* field, oop new_val);
  95   void write_ref_field_pre_work(void* field, oop new_val);
  96 
  97   void write_ref_field_work(void* v, oop o, bool release = false);
  98   void write_region_work(MemRegion mr);
  99 
 100   virtual oop read_barrier(oop src);
 101 
 102   static inline oop resolve_forwarded_not_null(oop p);
 103   static inline oop resolve_forwarded(oop p);
 104 
 105   virtual oop write_barrier(oop obj);
 106   static oopDesc* write_barrier_IRT(oopDesc* src);
 107   static oopDesc* write_barrier_JRT(oopDesc* src);
 108 
 109   oop write_barrier_mutator(oop obj);
 110 
 111   bool obj_equals(oop obj1, oop obj2);
 112   bool obj_equals(narrowOop obj1, narrowOop obj2);
 113 
 114   void enqueue(oop obj);
 115 
 116 private:
 117   inline bool need_update_refs_barrier();
 118 
 119   template <class T>
 120   void write_ref_array_loop(HeapWord* start, size_t count);
 121 
 122 #ifndef CC_INTERP
 123 public:
 124   virtual void interpreter_read_barrier(MacroAssembler* masm, Register dst);
 125   virtual void interpreter_read_barrier_not_null(MacroAssembler* masm, Register dst);
 126   void interpreter_write_barrier(MacroAssembler* masm, Register dst);
 127   void asm_acmp_barrier(MacroAssembler* masm, Register op1, Register op2);
 128 
 129 #endif
 130 };
 131 
 132 #endif //SHARE_VM_GC_SHENANDOAH_SHENANDOAHBARRIERSET_HPP