src/share/vm/memory/genOopClosures.hpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_MEMORY_GENOOPCLOSURES_HPP
aoqi@0 26 #define SHARE_VM_MEMORY_GENOOPCLOSURES_HPP
aoqi@0 27
aoqi@0 28 #include "memory/iterator.hpp"
aoqi@0 29 #include "oops/oop.hpp"
aoqi@0 30
aoqi@0 31 class Generation;
aoqi@0 32 class HeapWord;
aoqi@0 33 class CardTableRS;
aoqi@0 34 class CardTableModRefBS;
aoqi@0 35 class DefNewGeneration;
aoqi@0 36 class KlassRemSet;
aoqi@0 37
aoqi@0 38 template<class E, MEMFLAGS F, unsigned int N> class GenericTaskQueue;
aoqi@0 39 typedef GenericTaskQueue<oop, mtGC, TASKQUEUE_SIZE> OopTaskQueue;
aoqi@0 40 template<class T, MEMFLAGS F> class GenericTaskQueueSet;
aoqi@0 41 typedef GenericTaskQueueSet<OopTaskQueue, mtGC> OopTaskQueueSet;
aoqi@0 42
aoqi@0 43 // Closure for iterating roots from a particular generation
aoqi@0 44 // Note: all classes deriving from this MUST call this do_barrier
aoqi@0 45 // method at the end of their own do_oop method!
aoqi@0 46 // Note: no do_oop defined, this is an abstract class.
aoqi@0 47
aoqi@0 48 class OopsInGenClosure : public ExtendedOopClosure {
aoqi@0 49 private:
aoqi@0 50 Generation* _orig_gen; // generation originally set in ctor
aoqi@0 51 Generation* _gen; // generation being scanned
aoqi@0 52
aoqi@0 53 protected:
aoqi@0 54 // Some subtypes need access.
aoqi@0 55 HeapWord* _gen_boundary; // start of generation
aoqi@0 56 CardTableRS* _rs; // remembered set
aoqi@0 57
aoqi@0 58 // For assertions
aoqi@0 59 Generation* generation() { return _gen; }
aoqi@0 60 CardTableRS* rs() { return _rs; }
aoqi@0 61
aoqi@0 62 // Derived classes that modify oops so that they might be old-to-young
aoqi@0 63 // pointers must call the method below.
aoqi@0 64 template <class T> void do_barrier(T* p);
aoqi@0 65
aoqi@0 66 // Version for use by closures that may be called in parallel code.
aoqi@0 67 template <class T> void par_do_barrier(T* p);
aoqi@0 68
aoqi@0 69 public:
aoqi@0 70 OopsInGenClosure() : ExtendedOopClosure(NULL),
aoqi@0 71 _orig_gen(NULL), _gen(NULL), _gen_boundary(NULL), _rs(NULL) {};
aoqi@0 72
aoqi@0 73 OopsInGenClosure(Generation* gen);
aoqi@0 74 void set_generation(Generation* gen);
aoqi@0 75
aoqi@0 76 void reset_generation() { _gen = _orig_gen; }
aoqi@0 77
aoqi@0 78 // Problem with static closures: must have _gen_boundary set at some point,
aoqi@0 79 // but cannot do this until after the heap is initialized.
aoqi@0 80 void set_orig_generation(Generation* gen) {
aoqi@0 81 _orig_gen = gen;
aoqi@0 82 set_generation(gen);
aoqi@0 83 }
aoqi@0 84
aoqi@0 85 HeapWord* gen_boundary() { return _gen_boundary; }
aoqi@0 86
aoqi@0 87 };
aoqi@0 88
aoqi@0 89 // Super class for scan closures. It contains code to dirty scanned Klasses.
aoqi@0 90 class OopsInKlassOrGenClosure: public OopsInGenClosure {
aoqi@0 91 Klass* _scanned_klass;
aoqi@0 92 public:
aoqi@0 93 OopsInKlassOrGenClosure(Generation* g) : OopsInGenClosure(g), _scanned_klass(NULL) {}
aoqi@0 94 void set_scanned_klass(Klass* k) {
aoqi@0 95 assert(k == NULL || _scanned_klass == NULL, "Must be");
aoqi@0 96 _scanned_klass = k;
aoqi@0 97 }
aoqi@0 98 bool is_scanning_a_klass() { return _scanned_klass != NULL; }
aoqi@0 99 void do_klass_barrier();
aoqi@0 100 };
aoqi@0 101
aoqi@0 102 // Closure for scanning DefNewGeneration.
aoqi@0 103 //
aoqi@0 104 // This closure will perform barrier store calls for ALL
aoqi@0 105 // pointers in scanned oops.
aoqi@0 106 class ScanClosure: public OopsInKlassOrGenClosure {
aoqi@0 107 protected:
aoqi@0 108 DefNewGeneration* _g;
aoqi@0 109 HeapWord* _boundary;
aoqi@0 110 bool _gc_barrier;
aoqi@0 111 template <class T> inline void do_oop_work(T* p);
aoqi@0 112 public:
aoqi@0 113 ScanClosure(DefNewGeneration* g, bool gc_barrier);
aoqi@0 114 virtual void do_oop(oop* p);
aoqi@0 115 virtual void do_oop(narrowOop* p);
aoqi@0 116 inline void do_oop_nv(oop* p);
aoqi@0 117 inline void do_oop_nv(narrowOop* p);
aoqi@0 118 Prefetch::style prefetch_style() {
aoqi@0 119 return Prefetch::do_write;
aoqi@0 120 }
aoqi@0 121 };
aoqi@0 122
aoqi@0 123 // Closure for scanning DefNewGeneration.
aoqi@0 124 //
aoqi@0 125 // This closure only performs barrier store calls on
aoqi@0 126 // pointers into the DefNewGeneration. This is less
aoqi@0 127 // precise, but faster, than a ScanClosure
aoqi@0 128 class FastScanClosure: public OopsInKlassOrGenClosure {
aoqi@0 129 protected:
aoqi@0 130 DefNewGeneration* _g;
aoqi@0 131 HeapWord* _boundary;
aoqi@0 132 bool _gc_barrier;
aoqi@0 133 template <class T> inline void do_oop_work(T* p);
aoqi@0 134 public:
aoqi@0 135 FastScanClosure(DefNewGeneration* g, bool gc_barrier);
aoqi@0 136 virtual void do_oop(oop* p);
aoqi@0 137 virtual void do_oop(narrowOop* p);
aoqi@0 138 inline void do_oop_nv(oop* p);
aoqi@0 139 inline void do_oop_nv(narrowOop* p);
aoqi@0 140 Prefetch::style prefetch_style() {
aoqi@0 141 return Prefetch::do_write;
aoqi@0 142 }
aoqi@0 143 };
aoqi@0 144
aoqi@0 145 class KlassScanClosure: public KlassClosure {
aoqi@0 146 OopsInKlassOrGenClosure* _scavenge_closure;
aoqi@0 147 // true if the the modified oops state should be saved.
aoqi@0 148 bool _accumulate_modified_oops;
aoqi@0 149 public:
aoqi@0 150 KlassScanClosure(OopsInKlassOrGenClosure* scavenge_closure,
aoqi@0 151 KlassRemSet* klass_rem_set_policy);
aoqi@0 152 void do_klass(Klass* k);
aoqi@0 153 };
aoqi@0 154
aoqi@0 155 class FilteringClosure: public ExtendedOopClosure {
aoqi@0 156 private:
aoqi@0 157 HeapWord* _boundary;
aoqi@0 158 ExtendedOopClosure* _cl;
aoqi@0 159 protected:
aoqi@0 160 template <class T> inline void do_oop_work(T* p) {
aoqi@0 161 T heap_oop = oopDesc::load_heap_oop(p);
aoqi@0 162 if (!oopDesc::is_null(heap_oop)) {
aoqi@0 163 oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
aoqi@0 164 if ((HeapWord*)obj < _boundary) {
aoqi@0 165 _cl->do_oop(p);
aoqi@0 166 }
aoqi@0 167 }
aoqi@0 168 }
aoqi@0 169 public:
aoqi@0 170 FilteringClosure(HeapWord* boundary, ExtendedOopClosure* cl) :
aoqi@0 171 ExtendedOopClosure(cl->_ref_processor), _boundary(boundary),
aoqi@0 172 _cl(cl) {}
aoqi@0 173 virtual void do_oop(oop* p);
aoqi@0 174 virtual void do_oop(narrowOop* p);
aoqi@0 175 inline void do_oop_nv(oop* p) { FilteringClosure::do_oop_work(p); }
aoqi@0 176 inline void do_oop_nv(narrowOop* p) { FilteringClosure::do_oop_work(p); }
aoqi@0 177 virtual bool do_metadata() { return do_metadata_nv(); }
aoqi@0 178 inline bool do_metadata_nv() { assert(!_cl->do_metadata(), "assumption broken, must change to 'return _cl->do_metadata()'"); return false; }
aoqi@0 179 };
aoqi@0 180
aoqi@0 181 // Closure for scanning DefNewGeneration's weak references.
aoqi@0 182 // NOTE: very much like ScanClosure but not derived from
aoqi@0 183 // OopsInGenClosure -- weak references are processed all
aoqi@0 184 // at once, with no notion of which generation they were in.
aoqi@0 185 class ScanWeakRefClosure: public OopClosure {
aoqi@0 186 protected:
aoqi@0 187 DefNewGeneration* _g;
aoqi@0 188 HeapWord* _boundary;
aoqi@0 189 template <class T> inline void do_oop_work(T* p);
aoqi@0 190 public:
aoqi@0 191 ScanWeakRefClosure(DefNewGeneration* g);
aoqi@0 192 virtual void do_oop(oop* p);
aoqi@0 193 virtual void do_oop(narrowOop* p);
aoqi@0 194 inline void do_oop_nv(oop* p);
aoqi@0 195 inline void do_oop_nv(narrowOop* p);
aoqi@0 196 };
aoqi@0 197
aoqi@0 198 class VerifyOopClosure: public OopClosure {
aoqi@0 199 protected:
aoqi@0 200 template <class T> inline void do_oop_work(T* p) {
aoqi@0 201 oop obj = oopDesc::load_decode_heap_oop(p);
aoqi@0 202 guarantee(obj->is_oop_or_null(), err_msg("invalid oop: " INTPTR_FORMAT, p2i((oopDesc*) obj)));
aoqi@0 203 }
aoqi@0 204 public:
aoqi@0 205 virtual void do_oop(oop* p);
aoqi@0 206 virtual void do_oop(narrowOop* p);
aoqi@0 207 static VerifyOopClosure verify_oop;
aoqi@0 208 };
aoqi@0 209
aoqi@0 210 #endif // SHARE_VM_MEMORY_GENOOPCLOSURES_HPP

mercurial