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