1 /*
  2  * Copyright (c) 2001, 2018, 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_VM_GC_G1_G1SATBCARDTABLEMODREFBS_HPP
 26 #define SHARE_VM_GC_G1_G1SATBCARDTABLEMODREFBS_HPP
 27 
 28 #include "gc/g1/g1RegionToSpaceMapper.hpp"
 29 #include "gc/shared/cardTableModRefBS.hpp"
 30 #include "memory/memRegion.hpp"
 31 #include "oops/oop.hpp"
 32 #include "utilities/macros.hpp"
 33 
 34 class DirtyCardQueueSet;
 35 class G1SATBCardTableLoggingModRefBS;
 36 class CardTable;
 37 class G1CardTable;
 38 
 39 // This barrier is specialized to use a logging barrier to support
 40 // snapshot-at-the-beginning marking.
 41 
 42 class G1SATBCardTableModRefBS: public CardTableModRefBS {
 43   friend class VMStructs;
 44 protected:
 45   G1SATBCardTableModRefBS(G1CardTable* table, const BarrierSet::FakeRtti& fake_rtti);
 46   ~G1SATBCardTableModRefBS() { }
 47 
 48 public:
 49   // Add "pre_val" to a set of objects that may have been disconnected from the
 50   // pre-marking object graph.
 51   static void enqueue(oop pre_val);
 52 
 53   static void enqueue_if_weak_or_archive(DecoratorSet decorators, oop value);
 54 
 55   template <class T> void write_ref_array_pre_work(T* dst, int count);
 56   virtual void write_ref_array_pre(oop* dst, int count, bool dest_uninitialized);
 57   virtual void write_ref_array_pre(narrowOop* dst, int count, bool dest_uninitialized);
 58 
 59   template <DecoratorSet decorators, typename T>
 60   void write_ref_field_pre(T* field);
 61 };
 62 
 63 template<>
 64 struct BarrierSet::GetName<G1SATBCardTableModRefBS> {
 65   static const BarrierSet::Name value = BarrierSet::G1SATBCT;
 66 };
 67 
 68 template<>
 69 struct BarrierSet::GetType<BarrierSet::G1SATBCT> {
 70   typedef G1SATBCardTableModRefBS type;
 71 };
 72 
 73 // Adds card-table logging to the post-barrier.
 74 // Usual invariant: all dirty cards are logged in the DirtyCardQueueSet.
 75 class G1SATBCardTableLoggingModRefBS: public G1SATBCardTableModRefBS {
 76  private:
 77   DirtyCardQueueSet& _dcqs;
 78 
 79  public:
 80   G1SATBCardTableLoggingModRefBS(G1CardTable* card_table);
 81 
 82   // NB: if you do a whole-heap invalidation, the "usual invariant" defined
 83   // above no longer applies.
 84   void invalidate(MemRegion mr);
 85 
 86   void write_region(MemRegion mr)         { invalidate(mr); }
 87   void write_ref_array_work(MemRegion mr) { invalidate(mr); }
 88 
 89   template <DecoratorSet decorators, typename T>
 90   void write_ref_field_post(T* field, oop new_val);
 91   void write_ref_field_post_slow(volatile jbyte* byte);
 92 
 93   virtual void on_thread_attach(JavaThread* thread);
 94   virtual void on_thread_detach(JavaThread* thread);
 95 
 96   // Callbacks for runtime accesses.
 97   template <DecoratorSet decorators, typename BarrierSetT = G1SATBCardTableLoggingModRefBS>
 98   class AccessBarrier: public ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT> {
 99     typedef ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT> ModRef;
100     typedef BarrierSet::AccessBarrier<decorators, BarrierSetT> Raw;
101 
102   public:
103     // Needed for loads on non-heap weak references
104     template <typename T>
105     static oop oop_load_not_in_heap(T* addr);
106 
107     // Needed for non-heap stores
108     template <typename T>
109     static void oop_store_not_in_heap(T* addr, oop new_value);
110 
111     // Needed for weak references
112     static oop oop_load_in_heap_at(oop base, ptrdiff_t offset);
113 
114     // Defensive: will catch weak oops at addresses in heap
115     template <typename T>
116     static oop oop_load_in_heap(T* addr);
117   };
118 };
119 
120 template<>
121 struct BarrierSet::GetName<G1SATBCardTableLoggingModRefBS> {
122   static const BarrierSet::Name value = BarrierSet::G1SATBCTLogging;
123 };
124 
125 template<>
126 struct BarrierSet::GetType<BarrierSet::G1SATBCTLogging> {
127   typedef G1SATBCardTableLoggingModRefBS type;
128 };
129 
130 #endif // SHARE_VM_GC_G1_G1SATBCARDTABLEMODREFBS_HPP