1 /*
   2  * Copyright (c) 2001, 2019, Oracle and/or its affiliates. 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_G1_G1BARRIERSET_HPP
  26 #define SHARE_GC_G1_G1BARRIERSET_HPP
  27 
  28 #include "gc/g1/g1DirtyCardQueue.hpp"
  29 #include "gc/g1/g1SATBMarkQueueSet.hpp"
  30 #include "gc/shared/cardTable.hpp"
  31 #include "gc/shared/cardTableBarrierSet.hpp"
  32 
  33 class G1CardTable;
  34 
  35 // This barrier is specialized to use a logging barrier to support
  36 // snapshot-at-the-beginning marking.
  37 
  38 class G1BarrierSet: public CardTableBarrierSet {
  39   friend class VMStructs;
  40  private:
  41   BufferNode::Allocator _satb_mark_queue_buffer_allocator;
  42   BufferNode::Allocator _dirty_card_queue_buffer_allocator;
  43   G1SATBMarkQueueSet _satb_mark_queue_set;
  44   G1DirtyCardQueueSet _dirty_card_queue_set;
  45 
  46   static G1BarrierSet* g1_barrier_set() {
  47     return barrier_set_cast<G1BarrierSet>(BarrierSet::barrier_set());
  48   }
  49 
  50  public:
  51   G1BarrierSet(G1CardTable* table);
  52   ~G1BarrierSet() { }
  53 
  54   // Add "pre_val" to a set of objects that may have been disconnected from the
  55   // pre-marking object graph.
  56   static void enqueue(oop pre_val);
  57 
  58   static void enqueue_if_weak(DecoratorSet decorators, oop value);
  59 
  60   template <class T> void write_ref_array_pre_work(T* dst, size_t count);
  61   virtual void write_ref_array_pre(oop* dst, size_t count, bool dest_uninitialized);
  62   virtual void write_ref_array_pre(narrowOop* dst, size_t count, bool dest_uninitialized);
  63 
  64   template <DecoratorSet decorators, typename T>
  65   void write_ref_field_pre(T* field);
  66 
  67   // NB: if you do a whole-heap invalidation, the "usual invariant" defined
  68   // above no longer applies.
  69   void invalidate(MemRegion mr);
  70 
  71   void write_region(MemRegion mr)         { invalidate(mr); }
  72   void write_ref_array_work(MemRegion mr) { invalidate(mr); }
  73 
  74   template <DecoratorSet decorators, typename T>
  75   void write_ref_field_post(T* field, oop new_val);
  76   void write_ref_field_post_slow(volatile CardValue* byte);
  77 
  78   virtual void on_thread_create(Thread* thread);
  79   virtual void on_thread_destroy(Thread* thread);
  80   virtual void on_thread_attach(Thread* thread);
  81   virtual void on_thread_detach(Thread* thread);
  82 
  83   BufferNode::Allocator& satb_mark_queue_buffer_allocator();
  84   BufferNode::Allocator& dirty_card_queue_buffer_allocator();
  85 
  86   static G1SATBMarkQueueSet& satb_mark_queue_set() {
  87     return g1_barrier_set()->_satb_mark_queue_set;
  88   }
  89 
  90   static G1DirtyCardQueueSet& dirty_card_queue_set() {
  91     return g1_barrier_set()->_dirty_card_queue_set;
  92   }
  93 
  94   // Callbacks for runtime accesses.
  95   template <DecoratorSet decorators, typename BarrierSetT = G1BarrierSet>
  96   class AccessBarrier: public ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT> {
  97     typedef ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT> ModRef;
  98     typedef BarrierSet::AccessBarrier<decorators, BarrierSetT> Raw;
  99 
 100   public:
 101     // Needed for loads on non-heap weak references
 102     template <typename T>
 103     static oop oop_load_not_in_heap(T* addr);
 104 
 105     // Needed for non-heap stores
 106     template <typename T>
 107     static void oop_store_not_in_heap(T* addr, oop new_value);
 108 
 109     // Needed for weak references
 110     static oop oop_load_in_heap_at(oop base, ptrdiff_t offset);
 111 
 112     // Defensive: will catch weak oops at addresses in heap
 113     template <typename T>
 114     static oop oop_load_in_heap(T* addr);
 115   };
 116 };
 117 
 118 template<>
 119 struct BarrierSet::GetName<G1BarrierSet> {
 120   static const BarrierSet::Name value = BarrierSet::G1BarrierSet;
 121 };
 122 
 123 template<>
 124 struct BarrierSet::GetType<BarrierSet::G1BarrierSet> {
 125   typedef ::G1BarrierSet type;
 126 };
 127 
 128 #endif // SHARE_GC_G1_G1BARRIERSET_HPP