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 // Closure for iterating roots from a particular generation 38 // Note: all classes deriving from this MUST call this do_barrier 39 // method at the end of their own do_oop method! 40 // Note: no do_oop defined, this is an abstract class. 41 42 class OopsInGenClosure : public OopIterateClosure { 43 private: 44 Generation* _orig_gen; // generation originally set in ctor 45 Generation* _gen; // generation being scanned 46 47 protected: 48 // Some subtypes need access. 49 HeapWord* _gen_boundary; // start of generation 50 CardTableRS* _rs; // remembered set 51 52 // For assertions 53 Generation* generation() { return _gen; } 54 CardTableRS* rs() { return _rs; } 55 56 // Derived classes that modify oops so that they might be old-to-young 57 // pointers must call the method below. 58 template <class T> void do_barrier(T* p); 59 60 public: 61 OopsInGenClosure(Generation* gen); 62 void set_generation(Generation* gen); 63 64 void reset_generation() { _gen = _orig_gen; } 65 66 HeapWord* gen_boundary() { return _gen_boundary; } 67 }; 68 69 class BasicOopsInGenClosure: public OopsInGenClosure { 70 public: 71 BasicOopsInGenClosure(Generation* gen); 72 73 virtual bool do_metadata() { return false; } 74 virtual void do_klass(Klass* k) { ShouldNotReachHere(); } 75 virtual void do_cld(ClassLoaderData* cld) { ShouldNotReachHere(); } 76 }; 77 78 // Super class for scan closures. It contains code to dirty scanned class loader data. 79 class OopsInClassLoaderDataOrGenClosure: public BasicOopsInGenClosure { 80 ClassLoaderData* _scanned_cld; 81 public: 82 OopsInClassLoaderDataOrGenClosure(Generation* g) : BasicOopsInGenClosure(g), _scanned_cld(NULL) {} 83 void set_scanned_cld(ClassLoaderData* cld) { 84 assert(cld == NULL || _scanned_cld == NULL, "Must be"); 85 _scanned_cld = cld; 86 } 87 bool is_scanning_a_cld() { return _scanned_cld != NULL; } 88 void do_cld_barrier(); 89 }; 90 91 #if INCLUDE_SERIALGC 92 93 // Closure for scanning DefNewGeneration. 94 // 95 // This closure only performs barrier store calls on 96 // pointers into the DefNewGeneration. 97 class FastScanClosure: public OopsInClassLoaderDataOrGenClosure { 98 protected: 99 DefNewGeneration* _g; 100 HeapWord* _boundary; 101 bool _gc_barrier; 102 template <class T> inline void do_oop_work(T* p); 103 public: 104 FastScanClosure(DefNewGeneration* g, bool gc_barrier); 105 virtual void do_oop(oop* p); 106 virtual void do_oop(narrowOop* p); 107 }; 108 109 #endif // INCLUDE_SERIALGC 110 111 class CLDScanClosure: public CLDClosure { 112 OopsInClassLoaderDataOrGenClosure* _scavenge_closure; 113 // true if the the modified oops state should be saved. 114 bool _accumulate_modified_oops; 115 public: 116 CLDScanClosure(OopsInClassLoaderDataOrGenClosure* scavenge_closure, 117 bool accumulate_modified_oops) : 118 _scavenge_closure(scavenge_closure), _accumulate_modified_oops(accumulate_modified_oops) {} 119 void do_cld(ClassLoaderData* cld); 120 }; 121 122 class FilteringClosure: public OopIterateClosure { 123 private: 124 HeapWord* _boundary; 125 OopIterateClosure* _cl; 126 protected: 127 template <class T> inline void do_oop_work(T* p); 128 public: 129 FilteringClosure(HeapWord* boundary, OopIterateClosure* cl) : 130 OopIterateClosure(cl->ref_discoverer()), _boundary(boundary), 131 _cl(cl) {} 132 virtual void do_oop(oop* p); 133 virtual void do_oop(narrowOop* p); 134 virtual bool do_metadata() { assert(!_cl->do_metadata(), "assumption broken, must change to 'return _cl->do_metadata()'"); return false; } 135 virtual void do_klass(Klass*) { ShouldNotReachHere(); } 136 virtual void do_cld(ClassLoaderData*) { ShouldNotReachHere(); } 137 }; 138 139 #if INCLUDE_SERIALGC 140 141 // Closure for scanning DefNewGeneration's weak references. 142 // -- weak references are processed all at once, 143 // with no notion of which generation they were in. 144 class ScanWeakRefClosure: public OopClosure { 145 protected: 146 DefNewGeneration* _g; 147 HeapWord* _boundary; 148 template <class T> inline void do_oop_work(T* p); 149 public: 150 ScanWeakRefClosure(DefNewGeneration* g); 151 virtual void do_oop(oop* p); 152 virtual void do_oop(narrowOop* p); 153 }; 154 155 #endif // INCLUDE_SERIALGC 156 157 #endif // SHARE_GC_SHARED_GENOOPCLOSURES_HPP