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   // We export this to make it available in cases where the static
  95   // type of the barrier set is known.  Note that it is non-virtual.
  96   template <class T> inline void inline_write_ref_field_pre(T* field, oop newVal);
  97 
  98   // These are the more general virtual versions.
  99   void write_ref_field_pre_work(oop* field, oop new_val);
 100   void write_ref_field_pre_work(narrowOop* field, oop new_val);
 101   void write_ref_field_pre_work(void* field, oop new_val) shenandoah_not_implemented;
 102 
 103   void write_ref_field_work(void* v, oop o, bool release = false);
 104   void write_region_work(MemRegion mr);
 105 
 106   static inline oop resolve_forwarded_not_null(oop p);
 107   static inline oop resolve_forwarded(oop p);
 108 
 109   void storeval_barrier(oop obj);
 110   void keep_alive_barrier(oop obj);
 111 
 112   oop load_reference_barrier(oop obj);
 113   oop load_reference_barrier_mutator(oop obj);
 114   oop load_reference_barrier_not_null(oop obj);
 115 
 116   oop oop_atomic_cmpxchg_in_heap(oop new_value, volatile HeapWord* dest, oop compare_value);
 117 
 118   void enqueue(oop obj);
 119 
 120 private:
 121   inline bool need_update_refs_barrier();
 122 
 123   template <class T, bool STOREVAL_EVAC_BARRIER>
 124   void write_ref_array_loop(HeapWord* start, size_t count);
 125 
 126   oop load_reference_barrier_impl(oop obj);
 127 
 128   oop atomic_compare_exchange_oop(oop exchange_value,
 129                                   volatile HeapWord *dest,
 130                                   oop compare_value);
 131 };
 132 
 133 #endif //SHARE_VM_GC_SHENANDOAH_SHENANDOAHBARRIERSET_HPP