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_SHARED_GENOOPCLOSURES_HPP
  26 #define SHARE_GC_SHARED_GENOOPCLOSURES_HPP
  27 
  28 #include "memory/iterator.hpp"
  29 #include "oops/oop.hpp"
  30 
  31 class Generation;
  32 class CardTableRS;
  33 class CardTableBarrierSet;
  34 class DefNewGeneration;
  35 class KlassRemSet;
  36 
  37 #if INCLUDE_SERIALGC
  38 
  39 // Super closure class for scanning DefNewGeneration.
  40 //
  41 // - Derived: The derived type provides necessary barrier
  42 //            after an oop has been updated.
  43 template <typename Derived>
  44 class FastScanClosure : public BasicOopIterateClosure {
  45 private:
  46   DefNewGeneration* _young_gen;
  47   HeapWord*         _young_gen_end;
  48 
  49   template <typename T>
  50   void do_oop_work(T* p);
  51 
  52 protected:
  53   FastScanClosure(DefNewGeneration* g);
  54 
  55 public:
  56   virtual void do_oop(oop* p);
  57   virtual void do_oop(narrowOop* p);
  58 };
  59 
  60 // Closure for scanning DefNewGeneration when iterating over the old generation.
  61 //
  62 // This closure performs barrier store calls on pointers into the DefNewGeneration.
  63 class DefNewYoungerGenClosure : public FastScanClosure<DefNewYoungerGenClosure> {
  64 private:
  65   Generation*  _old_gen;
  66   HeapWord*    _old_gen_start;
  67   CardTableRS* _rs;
  68 
  69 public:
  70   DefNewYoungerGenClosure(DefNewGeneration* young_gen, Generation* old_gen);
  71 
  72   template <typename T>
  73   void barrier(T* p);
  74 };
  75 
  76 // Closure for scanning DefNewGeneration when *not* iterating over the old generation.
  77 //
  78 // This closures records changes to oops in CLDs.
  79 class DefNewScanClosure : public FastScanClosure<DefNewScanClosure> {
  80   ClassLoaderData* _scanned_cld;
  81 
  82 public:
  83   DefNewScanClosure(DefNewGeneration* g);
  84 
  85   void set_scanned_cld(ClassLoaderData* cld) {
  86     assert(cld == NULL || _scanned_cld == NULL, "Must be");
  87     _scanned_cld = cld;
  88   }
  89 
  90   template <typename T>
  91   void barrier(T* p);
  92 };
  93 
  94 class CLDScanClosure: public CLDClosure {
  95   DefNewScanClosure* _scavenge_closure;
  96   // true if the the modified oops state should be saved.
  97   bool               _accumulate_modified_oops;
  98  public:
  99   CLDScanClosure(DefNewScanClosure* scavenge_closure,
 100                  bool accumulate_modified_oops) :
 101        _scavenge_closure(scavenge_closure), _accumulate_modified_oops(accumulate_modified_oops) {}
 102   void do_cld(ClassLoaderData* cld);
 103 };
 104 
 105 #endif // INCLUDE_SERIALGC
 106 
 107 class FilteringClosure: public OopIterateClosure {
 108  private:
 109   HeapWord*   _boundary;
 110   OopIterateClosure* _cl;
 111  protected:
 112   template <class T> inline void do_oop_work(T* p);
 113  public:
 114   FilteringClosure(HeapWord* boundary, OopIterateClosure* cl) :
 115     OopIterateClosure(cl->ref_discoverer()), _boundary(boundary),
 116     _cl(cl) {}
 117   virtual void do_oop(oop* p);
 118   virtual void do_oop(narrowOop* p);
 119   virtual bool do_metadata()            { assert(!_cl->do_metadata(), "assumption broken, must change to 'return _cl->do_metadata()'"); return false; }
 120   virtual void do_klass(Klass*)         { ShouldNotReachHere(); }
 121   virtual void do_cld(ClassLoaderData*) { ShouldNotReachHere(); }
 122 };
 123 
 124 #if INCLUDE_SERIALGC
 125 
 126 // Closure for scanning DefNewGeneration's weak references.
 127 //  -- weak references are processed all at once,
 128 //  with no notion of which generation they were in.
 129 class ScanWeakRefClosure: public OopClosure {
 130  protected:
 131   DefNewGeneration* _g;
 132   HeapWord*         _boundary;
 133   template <class T> inline void do_oop_work(T* p);
 134  public:
 135   ScanWeakRefClosure(DefNewGeneration* g);
 136   virtual void do_oop(oop* p);
 137   virtual void do_oop(narrowOop* p);
 138 };
 139 
 140 #endif // INCLUDE_SERIALGC
 141 
 142 #endif // SHARE_GC_SHARED_GENOOPCLOSURES_HPP