1 /*
   2  * Copyright (c) 2015, 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_SHENANDOAHOOPCLOSURES_HPP
  25 #define SHARE_VM_GC_SHENANDOAH_SHENANDOAHOOPCLOSURES_HPP
  26 
  27 #include "gc/shared/referenceProcessor.hpp"
  28 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
  29 #include "gc/shenandoah/shenandoahStrDedupQueue.hpp"
  30 #include "gc/shenandoah/shenandoahTaskqueue.hpp"
  31 #include "memory/iterator.hpp"
  32 #include "runtime/thread.hpp"
  33 
  34 enum UpdateRefsMode {
  35   NONE,       // No reference updating
  36   RESOLVE,    // Only a resolve (no reference updating)
  37   SIMPLE,     // Reference updating using simple store
  38   CONCURRENT  // Reference updating using CAS
  39 };
  40 
  41 enum StringDedupMode {
  42   NO_DEDUP,      // Do not do anything for String deduplication
  43   ENQUEUE_DEDUP  // Enqueue candidate Strings for deduplication
  44 };
  45 
  46 class ShenandoahMarkRefsSuperClosure : public MetadataVisitingOopIterateClosure {
  47 private:
  48   ShenandoahObjToScanQueue* _queue;
  49   ShenandoahHeap* _heap;
  50   ShenandoahMarkingContext* const _mark_context;
  51 
  52 protected:
  53   template <class T, UpdateRefsMode UPDATE_MODE, StringDedupMode STRING_DEDUP>
  54   void work(T *p);
  55 
  56 public:
  57   ShenandoahMarkRefsSuperClosure(ShenandoahObjToScanQueue* q, ReferenceProcessor* rp);
  58 };
  59 
  60 class ShenandoahMarkUpdateRefsClosure : public ShenandoahMarkRefsSuperClosure {
  61 private:
  62   template <class T>
  63   inline void do_oop_work(T* p)     { work<T, CONCURRENT, NO_DEDUP>(p); }
  64 
  65 public:
  66   ShenandoahMarkUpdateRefsClosure(ShenandoahObjToScanQueue* q, ReferenceProcessor* rp) :
  67           ShenandoahMarkRefsSuperClosure(q, rp) {};
  68 
  69   virtual void do_oop(narrowOop* p) { do_oop_work(p); }
  70   virtual void do_oop(oop* p)       { do_oop_work(p); }
  71   virtual bool do_metadata()        { return false; }
  72 };
  73 
  74 class ShenandoahMarkUpdateRefsDedupClosure : public ShenandoahMarkRefsSuperClosure {
  75 private:
  76   template <class T>
  77   inline void do_oop_work(T* p)     { work<T, CONCURRENT, ENQUEUE_DEDUP>(p); }
  78 
  79 public:
  80   ShenandoahMarkUpdateRefsDedupClosure(ShenandoahObjToScanQueue* q, ReferenceProcessor* rp) :
  81           ShenandoahMarkRefsSuperClosure(q, rp) {};
  82 
  83   virtual void do_oop(narrowOop* p) { do_oop_work(p); }
  84   virtual void do_oop(oop* p)       { do_oop_work(p); }
  85   virtual bool do_metadata()        { return false; }
  86 };
  87 
  88 class ShenandoahMarkUpdateRefsMetadataClosure : public ShenandoahMarkRefsSuperClosure {
  89 private:
  90   template <class T>
  91   inline void do_oop_work(T* p)     { work<T, CONCURRENT, NO_DEDUP>(p); }
  92 
  93 public:
  94   ShenandoahMarkUpdateRefsMetadataClosure(ShenandoahObjToScanQueue* q, ReferenceProcessor* rp) :
  95     ShenandoahMarkRefsSuperClosure(q, rp) {};
  96 
  97   virtual void do_oop(narrowOop* p) { do_oop_work(p); }
  98   virtual void do_oop(oop* p)       { do_oop_work(p); }
  99   virtual bool do_metadata()        { return true; }
 100 };
 101 
 102 class ShenandoahMarkUpdateRefsMetadataDedupClosure : public ShenandoahMarkRefsSuperClosure {
 103 private:
 104   template <class T>
 105   inline void do_oop_work(T* p)     { work<T, CONCURRENT, ENQUEUE_DEDUP>(p); }
 106 
 107 public:
 108   ShenandoahMarkUpdateRefsMetadataDedupClosure(ShenandoahObjToScanQueue* q, ReferenceProcessor* rp) :
 109   ShenandoahMarkRefsSuperClosure(q, rp) {};
 110 
 111   virtual void do_oop(narrowOop* p) { do_oop_work(p); }
 112   virtual void do_oop(oop* p)       { do_oop_work(p); }
 113   virtual bool do_metadata()        { return true; }
 114 };
 115 
 116 class ShenandoahMarkRefsClosure : public ShenandoahMarkRefsSuperClosure {
 117 private:
 118   template <class T>
 119   inline void do_oop_work(T* p)     { work<T, NONE, NO_DEDUP>(p); }
 120 
 121 public:
 122   ShenandoahMarkRefsClosure(ShenandoahObjToScanQueue* q, ReferenceProcessor* rp) :
 123     ShenandoahMarkRefsSuperClosure(q, rp) {};
 124 
 125   virtual void do_oop(narrowOop* p) { do_oop_work(p); }
 126   virtual void do_oop(oop* p)       { do_oop_work(p); }
 127   virtual bool do_metadata()        { return false; }
 128 };
 129 
 130 class ShenandoahMarkRefsDedupClosure : public ShenandoahMarkRefsSuperClosure {
 131 private:
 132   template <class T>
 133   inline void do_oop_work(T* p)     { work<T, NONE, ENQUEUE_DEDUP>(p); }
 134 
 135 public:
 136   ShenandoahMarkRefsDedupClosure(ShenandoahObjToScanQueue* q, ReferenceProcessor* rp) :
 137     ShenandoahMarkRefsSuperClosure(q, rp) {};
 138 
 139   virtual void do_oop(narrowOop* p) { do_oop_work(p); }
 140   virtual void do_oop(oop* p)       { do_oop_work(p); }
 141   virtual bool do_metadata()        { return false; }
 142 };
 143 
 144 class ShenandoahMarkResolveRefsClosure : public ShenandoahMarkRefsSuperClosure {
 145 private:
 146   template <class T>
 147   inline void do_oop_work(T* p)     { work<T, RESOLVE, NO_DEDUP>(p); }
 148 
 149 public:
 150   ShenandoahMarkResolveRefsClosure(ShenandoahObjToScanQueue* q, ReferenceProcessor* rp) :
 151     ShenandoahMarkRefsSuperClosure(q, rp) {};
 152 
 153   virtual void do_oop(narrowOop* p) { do_oop_work(p); }
 154   virtual void do_oop(oop* p)       { do_oop_work(p); }
 155   virtual bool do_metadata()        { return false; }
 156 };
 157 
 158 class ShenandoahMarkRefsMetadataClosure : public ShenandoahMarkRefsSuperClosure {
 159 private:
 160   template <class T>
 161   inline void do_oop_work(T* p)     { work<T, NONE, NO_DEDUP>(p); }
 162 
 163 public:
 164   ShenandoahMarkRefsMetadataClosure(ShenandoahObjToScanQueue* q, ReferenceProcessor* rp) :
 165     ShenandoahMarkRefsSuperClosure(q, rp) {};
 166 
 167   virtual void do_oop(narrowOop* p) { do_oop_work(p); }
 168   virtual void do_oop(oop* p)       { do_oop_work(p); }
 169   virtual bool do_metadata()        { return true; }
 170 };
 171 
 172 class ShenandoahMarkRefsMetadataDedupClosure : public ShenandoahMarkRefsSuperClosure {
 173 private:
 174   template <class T>
 175   inline void do_oop_work(T* p)     { work<T, NONE, ENQUEUE_DEDUP>(p); }
 176 
 177 public:
 178   ShenandoahMarkRefsMetadataDedupClosure(ShenandoahObjToScanQueue* q, ReferenceProcessor* rp) :
 179     ShenandoahMarkRefsSuperClosure(q, rp) {};
 180 
 181   virtual void do_oop(narrowOop* p) { do_oop_work(p); }
 182   virtual void do_oop(oop* p)       { do_oop_work(p); }
 183   virtual bool do_metadata()        { return true; }
 184 };
 185 
 186 class ShenandoahUpdateHeapRefsClosure : public BasicOopIterateClosure {
 187 private:
 188   ShenandoahHeap* _heap;
 189 
 190   template <class T>
 191   void do_oop_work(T* p);
 192 
 193 public:
 194   ShenandoahUpdateHeapRefsClosure() :
 195     _heap(ShenandoahHeap::heap()) {}
 196 
 197   virtual void do_oop(narrowOop* p) { do_oop_work(p); }
 198   virtual void do_oop(oop* p)       { do_oop_work(p); }
 199 };
 200 
 201 #endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAHOOPCLOSURES_HPP