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