Mercurial > hg > graal-jvmci-8
annotate src/share/vm/memory/iterator.hpp @ 935:05f89f00a864
6798898: CMS: bugs related to class unloading
Summary: Override should_remember_klasses() and remember_klass() as needed.
Reviewed-by: ysr, jcoomes
author | jmasa |
---|---|
date | Mon, 24 Aug 2009 10:36:31 -0700 |
parents | 1ee8caae33af |
children | 8b46c4d82093 |
rev | line source |
---|---|
0 | 1 /* |
196 | 2 * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. |
0 | 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 // The following classes are C++ `closures` for iterating over objects, roots and spaces | |
26 | |
27 class ReferenceProcessor; | |
28 | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
29 // Closure provides abortability. |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
30 |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
31 class Closure : public StackObj { |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
32 protected: |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
33 bool _abort; |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
34 void set_abort() { _abort = true; } |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
35 public: |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
36 Closure() : _abort(false) {} |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
37 // A subtype can use this mechanism to indicate to some iterator mapping |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
38 // functions that the iteration should cease. |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
39 bool abort() { return _abort; } |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
40 void clear_abort() { _abort = false; } |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
41 }; |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
42 |
0 | 43 // OopClosure is used for iterating through roots (oop*) |
44 | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
45 class OopClosure : public Closure { |
0 | 46 public: |
47 ReferenceProcessor* _ref_processor; | |
48 OopClosure(ReferenceProcessor* rp) : _ref_processor(rp) { } | |
49 OopClosure() : _ref_processor(NULL) { } | |
50 virtual void do_oop(oop* o) = 0; | |
51 virtual void do_oop_v(oop* o) { do_oop(o); } | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
52 virtual void do_oop(narrowOop* o) = 0; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
53 virtual void do_oop_v(narrowOop* o) { do_oop(o); } |
0 | 54 |
55 // In support of post-processing of weak links of KlassKlass objects; | |
56 // see KlassKlass::oop_oop_iterate(). | |
935 | 57 |
58 virtual const bool should_remember_klasses() const { | |
59 assert(!must_remember_klasses(), "Should have overriden this method."); | |
60 return false; | |
61 } | |
62 | |
0 | 63 virtual void remember_klass(Klass* k) { /* do nothing */ } |
64 | |
65 // If "true", invoke on nmethods (when scanning compiled frames). | |
66 virtual const bool do_nmethods() const { return false; } | |
67 | |
68 // The methods below control how object iterations invoking this closure | |
69 // should be performed: | |
70 | |
71 // If "true", invoke on header klass field. | |
72 bool do_header() { return true; } // Note that this is non-virtual. | |
73 // Controls how prefetching is done for invocations of this closure. | |
74 Prefetch::style prefetch_style() { // Note that this is non-virtual. | |
75 return Prefetch::do_none; | |
76 } | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
77 |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
78 // True iff this closure may be safely applied more than once to an oop |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
79 // location without an intervening "major reset" (like the end of a GC). |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
80 virtual bool idempotent() { return false; } |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
81 virtual bool apply_to_weak_ref_discovered_field() { return false; } |
935 | 82 |
83 #ifdef ASSERT | |
84 static bool _must_remember_klasses; | |
85 static bool must_remember_klasses(); | |
86 static void set_must_remember_klasses(bool v); | |
87 #endif | |
0 | 88 }; |
89 | |
90 // ObjectClosure is used for iterating through an object space | |
91 | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
92 class ObjectClosure : public Closure { |
0 | 93 public: |
94 // Called for each object. | |
95 virtual void do_object(oop obj) = 0; | |
96 }; | |
97 | |
98 | |
99 class BoolObjectClosure : public ObjectClosure { | |
100 public: | |
101 virtual bool do_object_b(oop obj) = 0; | |
102 }; | |
103 | |
104 // Applies an oop closure to all ref fields in objects iterated over in an | |
105 // object iteration. | |
106 class ObjectToOopClosure: public ObjectClosure { | |
107 OopClosure* _cl; | |
108 public: | |
109 void do_object(oop obj); | |
110 ObjectToOopClosure(OopClosure* cl) : _cl(cl) {} | |
111 }; | |
112 | |
113 // A version of ObjectClosure with "memory" (see _previous_address below) | |
114 class UpwardsObjectClosure: public BoolObjectClosure { | |
115 HeapWord* _previous_address; | |
116 public: | |
117 UpwardsObjectClosure() : _previous_address(NULL) { } | |
118 void set_previous(HeapWord* addr) { _previous_address = addr; } | |
119 HeapWord* previous() { return _previous_address; } | |
120 // A return value of "true" can be used by the caller to decide | |
121 // if this object's end should *NOT* be recorded in | |
122 // _previous_address above. | |
123 virtual bool do_object_bm(oop obj, MemRegion mr) = 0; | |
124 }; | |
125 | |
126 // A version of ObjectClosure that is expected to be robust | |
127 // in the face of possibly uninitialized objects. | |
128 class ObjectClosureCareful : public ObjectClosure { | |
129 public: | |
130 virtual size_t do_object_careful_m(oop p, MemRegion mr) = 0; | |
131 virtual size_t do_object_careful(oop p) = 0; | |
132 }; | |
133 | |
134 // The following are used in CompactibleFreeListSpace and | |
135 // ConcurrentMarkSweepGeneration. | |
136 | |
137 // Blk closure (abstract class) | |
138 class BlkClosure : public StackObj { | |
139 public: | |
140 virtual size_t do_blk(HeapWord* addr) = 0; | |
141 }; | |
142 | |
143 // A version of BlkClosure that is expected to be robust | |
144 // in the face of possibly uninitialized objects. | |
145 class BlkClosureCareful : public BlkClosure { | |
146 public: | |
147 size_t do_blk(HeapWord* addr) { | |
148 guarantee(false, "call do_blk_careful instead"); | |
149 return 0; | |
150 } | |
151 virtual size_t do_blk_careful(HeapWord* addr) = 0; | |
152 }; | |
153 | |
154 // SpaceClosure is used for iterating over spaces | |
155 | |
156 class Space; | |
157 class CompactibleSpace; | |
158 | |
159 class SpaceClosure : public StackObj { | |
160 public: | |
161 // Called for each space | |
162 virtual void do_space(Space* s) = 0; | |
163 }; | |
164 | |
165 class CompactibleSpaceClosure : public StackObj { | |
166 public: | |
167 // Called for each compactible space | |
168 virtual void do_space(CompactibleSpace* s) = 0; | |
169 }; | |
170 | |
171 | |
172 | |
173 // MonitorClosure is used for iterating over monitors in the monitors cache | |
174 | |
175 class ObjectMonitor; | |
176 | |
177 class MonitorClosure : public StackObj { | |
178 public: | |
179 // called for each monitor in cache | |
180 virtual void do_monitor(ObjectMonitor* m) = 0; | |
181 }; | |
182 | |
183 // A closure that is applied without any arguments. | |
184 class VoidClosure : public StackObj { | |
185 public: | |
186 // I would have liked to declare this a pure virtual, but that breaks | |
187 // in mysterious ways, for unknown reasons. | |
188 virtual void do_void(); | |
189 }; | |
190 | |
191 | |
192 // YieldClosure is intended for use by iteration loops | |
193 // to incrementalize their work, allowing interleaving | |
194 // of an interruptable task so as to allow other | |
195 // threads to run (which may not otherwise be able to access | |
196 // exclusive resources, for instance). Additionally, the | |
197 // closure also allows for aborting an ongoing iteration | |
198 // by means of checking the return value from the polling | |
199 // call. | |
200 class YieldClosure : public StackObj { | |
201 public: | |
202 virtual bool should_return() = 0; | |
203 }; | |
204 | |
205 // Abstract closure for serializing data (read or write). | |
206 | |
207 class SerializeOopClosure : public OopClosure { | |
208 public: | |
209 // Return bool indicating whether closure implements read or write. | |
210 virtual bool reading() const = 0; | |
211 | |
212 // Read/write the int pointed to by i. | |
213 virtual void do_int(int* i) = 0; | |
214 | |
215 // Read/write the size_t pointed to by i. | |
216 virtual void do_size_t(size_t* i) = 0; | |
217 | |
218 // Read/write the void pointer pointed to by p. | |
219 virtual void do_ptr(void** p) = 0; | |
220 | |
221 // Read/write the HeapWord pointer pointed to be p. | |
222 virtual void do_ptr(HeapWord** p) = 0; | |
223 | |
224 // Read/write the region specified. | |
225 virtual void do_region(u_char* start, size_t size) = 0; | |
226 | |
227 // Check/write the tag. If reading, then compare the tag against | |
228 // the passed in value and fail is they don't match. This allows | |
229 // for verification that sections of the serialized data are of the | |
230 // correct length. | |
231 virtual void do_tag(int tag) = 0; | |
232 }; | |
935 | 233 |
234 #ifdef ASSERT | |
235 // This class is used to flag phases of a collection that | |
236 // can unload classes and which should override the | |
237 // should_remember_klasses() and remember_klass() of OopClosure. | |
238 // The _must_remember_klasses is set in the contructor and restored | |
239 // in the destructor. _must_remember_klasses is checked in assertions | |
240 // in the OopClosure implementations of should_remember_klasses() and | |
241 // remember_klass() and the expectation is that the OopClosure | |
242 // implementation should not be in use if _must_remember_klasses is set. | |
243 // Instances of RememberKlassesChecker can be place in | |
244 // marking phases of collections which can do class unloading. | |
245 // RememberKlassesChecker can be passed "false" to turn off checking. | |
246 // It is used by CMS when CMS yields to a different collector. | |
247 class RememberKlassesChecker: StackObj { | |
248 bool _state; | |
249 bool _skip; | |
250 public: | |
251 RememberKlassesChecker(bool checking_on) : _state(false), _skip(false) { | |
252 _skip = !(ClassUnloading && !UseConcMarkSweepGC || | |
253 CMSClassUnloadingEnabled && UseConcMarkSweepGC); | |
254 if (_skip) { | |
255 return; | |
256 } | |
257 _state = OopClosure::must_remember_klasses(); | |
258 OopClosure::set_must_remember_klasses(checking_on); | |
259 } | |
260 ~RememberKlassesChecker() { | |
261 if (_skip) { | |
262 return; | |
263 } | |
264 OopClosure::set_must_remember_klasses(_state); | |
265 } | |
266 }; | |
267 #endif // ASSERT |