1 /*
  2  * Copyright (c) 2001, 2020, 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  public:
 97   CLDScanClosure(DefNewScanClosure* scavenge_closure) :
 98        _scavenge_closure(scavenge_closure) {}
 99   void do_cld(ClassLoaderData* cld);
100 };
101 
102 #endif // INCLUDE_SERIALGC
103 
104 class FilteringClosure: public OopIterateClosure {
105  private:
106   HeapWord*   _boundary;
107   OopIterateClosure* _cl;
108  protected:
109   template <class T> inline void do_oop_work(T* p);
110  public:
111   FilteringClosure(HeapWord* boundary, OopIterateClosure* cl) :
112     OopIterateClosure(cl->ref_discoverer()), _boundary(boundary),
113     _cl(cl) {}
114   virtual void do_oop(oop* p);
115   virtual void do_oop(narrowOop* p);
116   virtual bool do_metadata()            { assert(!_cl->do_metadata(), "assumption broken, must change to 'return _cl->do_metadata()'"); return false; }
117   virtual void do_klass(Klass*)         { ShouldNotReachHere(); }
118   virtual void do_cld(ClassLoaderData*) { ShouldNotReachHere(); }
119 };
120 
121 #if INCLUDE_SERIALGC
122 
123 // Closure for scanning DefNewGeneration's weak references.
124 //  -- weak references are processed all at once,
125 //  with no notion of which generation they were in.
126 class ScanWeakRefClosure: public OopClosure {
127  protected:
128   DefNewGeneration* _g;
129   HeapWord*         _boundary;
130   template <class T> inline void do_oop_work(T* p);
131  public:
132   ScanWeakRefClosure(DefNewGeneration* g);
133   virtual void do_oop(oop* p);
134   virtual void do_oop(narrowOop* p);
135 };
136 
137 #endif // INCLUDE_SERIALGC
138 
139 #endif // SHARE_GC_SHARED_GENOOPCLOSURES_HPP