author | jrose |
Wed, 23 Sep 2009 23:56:15 -0700 | |
changeset 3912 | 3aaaaad1ccb0 |
parent 3908 | 24b55ad4c228 |
parent 3696 | 9e5d9b5e1049 |
child 3913 | e049e6b81e11 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
670 | 2 |
* Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. |
1 | 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 |
||
3908
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
27 |
class CodeBlob; |
1 | 28 |
class ReferenceProcessor; |
3696 | 29 |
class DataLayout; |
1 | 30 |
|
1374
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
31 |
// Closure provides abortability. |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
32 |
|
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
33 |
class Closure : public StackObj { |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
34 |
protected: |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
35 |
bool _abort; |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
36 |
void set_abort() { _abort = true; } |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
37 |
public: |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
38 |
Closure() : _abort(false) {} |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
39 |
// A subtype can use this mechanism to indicate to some iterator mapping |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
40 |
// functions that the iteration should cease. |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
41 |
bool abort() { return _abort; } |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
42 |
void clear_abort() { _abort = false; } |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
43 |
}; |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
44 |
|
1 | 45 |
// OopClosure is used for iterating through roots (oop*) |
46 |
||
1374
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
47 |
class OopClosure : public Closure { |
1 | 48 |
public: |
49 |
ReferenceProcessor* _ref_processor; |
|
50 |
OopClosure(ReferenceProcessor* rp) : _ref_processor(rp) { } |
|
51 |
OopClosure() : _ref_processor(NULL) { } |
|
52 |
virtual void do_oop(oop* o) = 0; |
|
53 |
virtual void do_oop_v(oop* o) { do_oop(o); } |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
54 |
virtual void do_oop(narrowOop* o) = 0; |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
55 |
virtual void do_oop_v(narrowOop* o) { do_oop(o); } |
1 | 56 |
|
57 |
// In support of post-processing of weak links of KlassKlass objects; |
|
58 |
// see KlassKlass::oop_oop_iterate(). |
|
3690 | 59 |
|
60 |
virtual const bool should_remember_klasses() const { |
|
61 |
assert(!must_remember_klasses(), "Should have overriden this method."); |
|
62 |
return false; |
|
63 |
} |
|
64 |
||
1 | 65 |
virtual void remember_klass(Klass* k) { /* do nothing */ } |
66 |
||
3696 | 67 |
// In support of post-processing of weak references in |
68 |
// ProfileData (MethodDataOop) objects; see, for example, |
|
69 |
// VirtualCallData::oop_iterate(). |
|
70 |
virtual const bool should_remember_mdo() const { return false; } |
|
71 |
virtual void remember_mdo(DataLayout* v) { /* do nothing */ } |
|
72 |
||
1 | 73 |
// If "true", invoke on nmethods (when scanning compiled frames). |
74 |
virtual const bool do_nmethods() const { return false; } |
|
75 |
||
76 |
// The methods below control how object iterations invoking this closure |
|
77 |
// should be performed: |
|
78 |
||
79 |
// If "true", invoke on header klass field. |
|
80 |
bool do_header() { return true; } // Note that this is non-virtual. |
|
81 |
// Controls how prefetching is done for invocations of this closure. |
|
82 |
Prefetch::style prefetch_style() { // Note that this is non-virtual. |
|
83 |
return Prefetch::do_none; |
|
84 |
} |
|
1374
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
85 |
|
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
86 |
// True iff this closure may be safely applied more than once to an oop |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
87 |
// location without an intervening "major reset" (like the end of a GC). |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
88 |
virtual bool idempotent() { return false; } |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
89 |
virtual bool apply_to_weak_ref_discovered_field() { return false; } |
3690 | 90 |
|
91 |
#ifdef ASSERT |
|
92 |
static bool _must_remember_klasses; |
|
93 |
static bool must_remember_klasses(); |
|
94 |
static void set_must_remember_klasses(bool v); |
|
95 |
#endif |
|
1 | 96 |
}; |
97 |
||
98 |
// ObjectClosure is used for iterating through an object space |
|
99 |
||
1374
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
100 |
class ObjectClosure : public Closure { |
1 | 101 |
public: |
102 |
// Called for each object. |
|
103 |
virtual void do_object(oop obj) = 0; |
|
104 |
}; |
|
105 |
||
106 |
||
107 |
class BoolObjectClosure : public ObjectClosure { |
|
108 |
public: |
|
109 |
virtual bool do_object_b(oop obj) = 0; |
|
110 |
}; |
|
111 |
||
112 |
// Applies an oop closure to all ref fields in objects iterated over in an |
|
113 |
// object iteration. |
|
114 |
class ObjectToOopClosure: public ObjectClosure { |
|
115 |
OopClosure* _cl; |
|
116 |
public: |
|
117 |
void do_object(oop obj); |
|
118 |
ObjectToOopClosure(OopClosure* cl) : _cl(cl) {} |
|
119 |
}; |
|
120 |
||
121 |
// A version of ObjectClosure with "memory" (see _previous_address below) |
|
122 |
class UpwardsObjectClosure: public BoolObjectClosure { |
|
123 |
HeapWord* _previous_address; |
|
124 |
public: |
|
125 |
UpwardsObjectClosure() : _previous_address(NULL) { } |
|
126 |
void set_previous(HeapWord* addr) { _previous_address = addr; } |
|
127 |
HeapWord* previous() { return _previous_address; } |
|
128 |
// A return value of "true" can be used by the caller to decide |
|
129 |
// if this object's end should *NOT* be recorded in |
|
130 |
// _previous_address above. |
|
131 |
virtual bool do_object_bm(oop obj, MemRegion mr) = 0; |
|
132 |
}; |
|
133 |
||
134 |
// A version of ObjectClosure that is expected to be robust |
|
135 |
// in the face of possibly uninitialized objects. |
|
136 |
class ObjectClosureCareful : public ObjectClosure { |
|
137 |
public: |
|
138 |
virtual size_t do_object_careful_m(oop p, MemRegion mr) = 0; |
|
139 |
virtual size_t do_object_careful(oop p) = 0; |
|
140 |
}; |
|
141 |
||
142 |
// The following are used in CompactibleFreeListSpace and |
|
143 |
// ConcurrentMarkSweepGeneration. |
|
144 |
||
145 |
// Blk closure (abstract class) |
|
146 |
class BlkClosure : public StackObj { |
|
147 |
public: |
|
148 |
virtual size_t do_blk(HeapWord* addr) = 0; |
|
149 |
}; |
|
150 |
||
151 |
// A version of BlkClosure that is expected to be robust |
|
152 |
// in the face of possibly uninitialized objects. |
|
153 |
class BlkClosureCareful : public BlkClosure { |
|
154 |
public: |
|
155 |
size_t do_blk(HeapWord* addr) { |
|
156 |
guarantee(false, "call do_blk_careful instead"); |
|
157 |
return 0; |
|
158 |
} |
|
159 |
virtual size_t do_blk_careful(HeapWord* addr) = 0; |
|
160 |
}; |
|
161 |
||
162 |
// SpaceClosure is used for iterating over spaces |
|
163 |
||
164 |
class Space; |
|
165 |
class CompactibleSpace; |
|
166 |
||
167 |
class SpaceClosure : public StackObj { |
|
168 |
public: |
|
169 |
// Called for each space |
|
170 |
virtual void do_space(Space* s) = 0; |
|
171 |
}; |
|
172 |
||
173 |
class CompactibleSpaceClosure : public StackObj { |
|
174 |
public: |
|
175 |
// Called for each compactible space |
|
176 |
virtual void do_space(CompactibleSpace* s) = 0; |
|
177 |
}; |
|
178 |
||
179 |
||
3908
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
180 |
// CodeBlobClosure is used for iterating through code blobs |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
181 |
// in the code cache or on thread stacks |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
182 |
|
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
183 |
class CodeBlobClosure : public Closure { |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
184 |
public: |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
185 |
// Called for each code blob. |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
186 |
virtual void do_code_blob(CodeBlob* cb) = 0; |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
187 |
}; |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
188 |
|
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
189 |
|
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
190 |
class MarkingCodeBlobClosure : public CodeBlobClosure { |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
191 |
public: |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
192 |
// Called for each code blob, but at most once per unique blob. |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
193 |
virtual void do_newly_marked_nmethod(CodeBlob* cb) = 0; |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
194 |
|
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
195 |
virtual void do_code_blob(CodeBlob* cb); |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
196 |
// = { if (!nmethod(cb)->test_set_oops_do_mark()) do_newly_marked_nmethod(cb); } |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
197 |
|
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
198 |
class MarkScope : public StackObj { |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
199 |
protected: |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
200 |
bool _active; |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
201 |
public: |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
202 |
MarkScope(bool activate = true); |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
203 |
// = { if (active) nmethod::oops_do_marking_prologue(); } |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
204 |
~MarkScope(); |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
205 |
// = { if (active) nmethod::oops_do_marking_epilogue(); } |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
206 |
}; |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
207 |
}; |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
208 |
|
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
209 |
|
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
210 |
// Applies an oop closure to all ref fields in code blobs |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
211 |
// iterated over in an object iteration. |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
212 |
class CodeBlobToOopClosure: public MarkingCodeBlobClosure { |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
213 |
OopClosure* _cl; |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
214 |
bool _do_marking; |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
215 |
public: |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
216 |
virtual void do_newly_marked_nmethod(CodeBlob* cb); |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
217 |
// = { cb->oops_do(_cl); } |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
218 |
virtual void do_code_blob(CodeBlob* cb); |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
219 |
// = { if (_do_marking) super::do_code_blob(cb); else cb->oops_do(_cl); } |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
220 |
CodeBlobToOopClosure(OopClosure* cl, bool do_marking) |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
221 |
: _cl(cl), _do_marking(do_marking) {} |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
222 |
}; |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
223 |
|
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
224 |
|
1 | 225 |
|
226 |
// MonitorClosure is used for iterating over monitors in the monitors cache |
|
227 |
||
228 |
class ObjectMonitor; |
|
229 |
||
230 |
class MonitorClosure : public StackObj { |
|
231 |
public: |
|
232 |
// called for each monitor in cache |
|
233 |
virtual void do_monitor(ObjectMonitor* m) = 0; |
|
234 |
}; |
|
235 |
||
236 |
// A closure that is applied without any arguments. |
|
237 |
class VoidClosure : public StackObj { |
|
238 |
public: |
|
239 |
// I would have liked to declare this a pure virtual, but that breaks |
|
240 |
// in mysterious ways, for unknown reasons. |
|
241 |
virtual void do_void(); |
|
242 |
}; |
|
243 |
||
244 |
||
245 |
// YieldClosure is intended for use by iteration loops |
|
246 |
// to incrementalize their work, allowing interleaving |
|
247 |
// of an interruptable task so as to allow other |
|
248 |
// threads to run (which may not otherwise be able to access |
|
249 |
// exclusive resources, for instance). Additionally, the |
|
250 |
// closure also allows for aborting an ongoing iteration |
|
251 |
// by means of checking the return value from the polling |
|
252 |
// call. |
|
253 |
class YieldClosure : public StackObj { |
|
254 |
public: |
|
255 |
virtual bool should_return() = 0; |
|
256 |
}; |
|
257 |
||
258 |
// Abstract closure for serializing data (read or write). |
|
259 |
||
260 |
class SerializeOopClosure : public OopClosure { |
|
261 |
public: |
|
262 |
// Return bool indicating whether closure implements read or write. |
|
263 |
virtual bool reading() const = 0; |
|
264 |
||
265 |
// Read/write the int pointed to by i. |
|
266 |
virtual void do_int(int* i) = 0; |
|
267 |
||
268 |
// Read/write the size_t pointed to by i. |
|
269 |
virtual void do_size_t(size_t* i) = 0; |
|
270 |
||
271 |
// Read/write the void pointer pointed to by p. |
|
272 |
virtual void do_ptr(void** p) = 0; |
|
273 |
||
274 |
// Read/write the HeapWord pointer pointed to be p. |
|
275 |
virtual void do_ptr(HeapWord** p) = 0; |
|
276 |
||
277 |
// Read/write the region specified. |
|
278 |
virtual void do_region(u_char* start, size_t size) = 0; |
|
279 |
||
280 |
// Check/write the tag. If reading, then compare the tag against |
|
281 |
// the passed in value and fail is they don't match. This allows |
|
282 |
// for verification that sections of the serialized data are of the |
|
283 |
// correct length. |
|
284 |
virtual void do_tag(int tag) = 0; |
|
285 |
}; |
|
3690 | 286 |
|
287 |
#ifdef ASSERT |
|
288 |
// This class is used to flag phases of a collection that |
|
289 |
// can unload classes and which should override the |
|
290 |
// should_remember_klasses() and remember_klass() of OopClosure. |
|
291 |
// The _must_remember_klasses is set in the contructor and restored |
|
292 |
// in the destructor. _must_remember_klasses is checked in assertions |
|
293 |
// in the OopClosure implementations of should_remember_klasses() and |
|
294 |
// remember_klass() and the expectation is that the OopClosure |
|
295 |
// implementation should not be in use if _must_remember_klasses is set. |
|
296 |
// Instances of RememberKlassesChecker can be place in |
|
297 |
// marking phases of collections which can do class unloading. |
|
298 |
// RememberKlassesChecker can be passed "false" to turn off checking. |
|
299 |
// It is used by CMS when CMS yields to a different collector. |
|
300 |
class RememberKlassesChecker: StackObj { |
|
301 |
bool _state; |
|
302 |
bool _skip; |
|
303 |
public: |
|
304 |
RememberKlassesChecker(bool checking_on) : _state(false), _skip(false) { |
|
305 |
_skip = !(ClassUnloading && !UseConcMarkSweepGC || |
|
306 |
CMSClassUnloadingEnabled && UseConcMarkSweepGC); |
|
307 |
if (_skip) { |
|
308 |
return; |
|
309 |
} |
|
310 |
_state = OopClosure::must_remember_klasses(); |
|
311 |
OopClosure::set_must_remember_klasses(checking_on); |
|
312 |
} |
|
313 |
~RememberKlassesChecker() { |
|
314 |
if (_skip) { |
|
315 |
return; |
|
316 |
} |
|
317 |
OopClosure::set_must_remember_klasses(_state); |
|
318 |
} |
|
319 |
}; |
|
320 |
#endif // ASSERT |