src/share/vm/memory/genOopClosures.hpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
equal deleted inserted replaced
-1:000000000000 0:f90c822e73f8
1 /*
2 * Copyright (c) 2001, 2014, 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_VM_MEMORY_GENOOPCLOSURES_HPP
26 #define SHARE_VM_MEMORY_GENOOPCLOSURES_HPP
27
28 #include "memory/iterator.hpp"
29 #include "oops/oop.hpp"
30
31 class Generation;
32 class HeapWord;
33 class CardTableRS;
34 class CardTableModRefBS;
35 class DefNewGeneration;
36 class KlassRemSet;
37
38 template<class E, MEMFLAGS F, unsigned int N> class GenericTaskQueue;
39 typedef GenericTaskQueue<oop, mtGC, TASKQUEUE_SIZE> OopTaskQueue;
40 template<class T, MEMFLAGS F> class GenericTaskQueueSet;
41 typedef GenericTaskQueueSet<OopTaskQueue, mtGC> OopTaskQueueSet;
42
43 // Closure for iterating roots from a particular generation
44 // Note: all classes deriving from this MUST call this do_barrier
45 // method at the end of their own do_oop method!
46 // Note: no do_oop defined, this is an abstract class.
47
48 class OopsInGenClosure : public ExtendedOopClosure {
49 private:
50 Generation* _orig_gen; // generation originally set in ctor
51 Generation* _gen; // generation being scanned
52
53 protected:
54 // Some subtypes need access.
55 HeapWord* _gen_boundary; // start of generation
56 CardTableRS* _rs; // remembered set
57
58 // For assertions
59 Generation* generation() { return _gen; }
60 CardTableRS* rs() { return _rs; }
61
62 // Derived classes that modify oops so that they might be old-to-young
63 // pointers must call the method below.
64 template <class T> void do_barrier(T* p);
65
66 // Version for use by closures that may be called in parallel code.
67 template <class T> void par_do_barrier(T* p);
68
69 public:
70 OopsInGenClosure() : ExtendedOopClosure(NULL),
71 _orig_gen(NULL), _gen(NULL), _gen_boundary(NULL), _rs(NULL) {};
72
73 OopsInGenClosure(Generation* gen);
74 void set_generation(Generation* gen);
75
76 void reset_generation() { _gen = _orig_gen; }
77
78 // Problem with static closures: must have _gen_boundary set at some point,
79 // but cannot do this until after the heap is initialized.
80 void set_orig_generation(Generation* gen) {
81 _orig_gen = gen;
82 set_generation(gen);
83 }
84
85 HeapWord* gen_boundary() { return _gen_boundary; }
86
87 };
88
89 // Super class for scan closures. It contains code to dirty scanned Klasses.
90 class OopsInKlassOrGenClosure: public OopsInGenClosure {
91 Klass* _scanned_klass;
92 public:
93 OopsInKlassOrGenClosure(Generation* g) : OopsInGenClosure(g), _scanned_klass(NULL) {}
94 void set_scanned_klass(Klass* k) {
95 assert(k == NULL || _scanned_klass == NULL, "Must be");
96 _scanned_klass = k;
97 }
98 bool is_scanning_a_klass() { return _scanned_klass != NULL; }
99 void do_klass_barrier();
100 };
101
102 // Closure for scanning DefNewGeneration.
103 //
104 // This closure will perform barrier store calls for ALL
105 // pointers in scanned oops.
106 class ScanClosure: public OopsInKlassOrGenClosure {
107 protected:
108 DefNewGeneration* _g;
109 HeapWord* _boundary;
110 bool _gc_barrier;
111 template <class T> inline void do_oop_work(T* p);
112 public:
113 ScanClosure(DefNewGeneration* g, bool gc_barrier);
114 virtual void do_oop(oop* p);
115 virtual void do_oop(narrowOop* p);
116 inline void do_oop_nv(oop* p);
117 inline void do_oop_nv(narrowOop* p);
118 Prefetch::style prefetch_style() {
119 return Prefetch::do_write;
120 }
121 };
122
123 // Closure for scanning DefNewGeneration.
124 //
125 // This closure only performs barrier store calls on
126 // pointers into the DefNewGeneration. This is less
127 // precise, but faster, than a ScanClosure
128 class FastScanClosure: public OopsInKlassOrGenClosure {
129 protected:
130 DefNewGeneration* _g;
131 HeapWord* _boundary;
132 bool _gc_barrier;
133 template <class T> inline void do_oop_work(T* p);
134 public:
135 FastScanClosure(DefNewGeneration* g, bool gc_barrier);
136 virtual void do_oop(oop* p);
137 virtual void do_oop(narrowOop* p);
138 inline void do_oop_nv(oop* p);
139 inline void do_oop_nv(narrowOop* p);
140 Prefetch::style prefetch_style() {
141 return Prefetch::do_write;
142 }
143 };
144
145 class KlassScanClosure: public KlassClosure {
146 OopsInKlassOrGenClosure* _scavenge_closure;
147 // true if the the modified oops state should be saved.
148 bool _accumulate_modified_oops;
149 public:
150 KlassScanClosure(OopsInKlassOrGenClosure* scavenge_closure,
151 KlassRemSet* klass_rem_set_policy);
152 void do_klass(Klass* k);
153 };
154
155 class FilteringClosure: public ExtendedOopClosure {
156 private:
157 HeapWord* _boundary;
158 ExtendedOopClosure* _cl;
159 protected:
160 template <class T> inline void do_oop_work(T* p) {
161 T heap_oop = oopDesc::load_heap_oop(p);
162 if (!oopDesc::is_null(heap_oop)) {
163 oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
164 if ((HeapWord*)obj < _boundary) {
165 _cl->do_oop(p);
166 }
167 }
168 }
169 public:
170 FilteringClosure(HeapWord* boundary, ExtendedOopClosure* cl) :
171 ExtendedOopClosure(cl->_ref_processor), _boundary(boundary),
172 _cl(cl) {}
173 virtual void do_oop(oop* p);
174 virtual void do_oop(narrowOop* p);
175 inline void do_oop_nv(oop* p) { FilteringClosure::do_oop_work(p); }
176 inline void do_oop_nv(narrowOop* p) { FilteringClosure::do_oop_work(p); }
177 virtual bool do_metadata() { return do_metadata_nv(); }
178 inline bool do_metadata_nv() { assert(!_cl->do_metadata(), "assumption broken, must change to 'return _cl->do_metadata()'"); return false; }
179 };
180
181 // Closure for scanning DefNewGeneration's weak references.
182 // NOTE: very much like ScanClosure but not derived from
183 // OopsInGenClosure -- weak references are processed all
184 // at once, with no notion of which generation they were in.
185 class ScanWeakRefClosure: public OopClosure {
186 protected:
187 DefNewGeneration* _g;
188 HeapWord* _boundary;
189 template <class T> inline void do_oop_work(T* p);
190 public:
191 ScanWeakRefClosure(DefNewGeneration* g);
192 virtual void do_oop(oop* p);
193 virtual void do_oop(narrowOop* p);
194 inline void do_oop_nv(oop* p);
195 inline void do_oop_nv(narrowOop* p);
196 };
197
198 class VerifyOopClosure: public OopClosure {
199 protected:
200 template <class T> inline void do_oop_work(T* p) {
201 oop obj = oopDesc::load_decode_heap_oop(p);
202 guarantee(obj->is_oop_or_null(), err_msg("invalid oop: " INTPTR_FORMAT, p2i((oopDesc*) obj)));
203 }
204 public:
205 virtual void do_oop(oop* p);
206 virtual void do_oop(narrowOop* p);
207 static VerifyOopClosure verify_oop;
208 };
209
210 #endif // SHARE_VM_MEMORY_GENOOPCLOSURES_HPP

mercurial