Tue, 22 Sep 2009 14:06:10 -0700
6884624: Update copyright year
Summary: Update copyright for files that have been modified in 2009 through Septermber
Reviewed-by: tbell, ohair
1 /*
2 * Copyright 1997-2009 Sun Microsystems, Inc. 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 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 */
25 // The following classes are C++ `closures` for iterating over objects, roots and spaces
27 class ReferenceProcessor;
28 class DataLayout;
30 // Closure provides abortability.
32 class Closure : public StackObj {
33 protected:
34 bool _abort;
35 void set_abort() { _abort = true; }
36 public:
37 Closure() : _abort(false) {}
38 // A subtype can use this mechanism to indicate to some iterator mapping
39 // functions that the iteration should cease.
40 bool abort() { return _abort; }
41 void clear_abort() { _abort = false; }
42 };
44 // OopClosure is used for iterating through roots (oop*)
46 class OopClosure : public Closure {
47 public:
48 ReferenceProcessor* _ref_processor;
49 OopClosure(ReferenceProcessor* rp) : _ref_processor(rp) { }
50 OopClosure() : _ref_processor(NULL) { }
51 virtual void do_oop(oop* o) = 0;
52 virtual void do_oop_v(oop* o) { do_oop(o); }
53 virtual void do_oop(narrowOop* o) = 0;
54 virtual void do_oop_v(narrowOop* o) { do_oop(o); }
56 // In support of post-processing of weak links of KlassKlass objects;
57 // see KlassKlass::oop_oop_iterate().
59 virtual const bool should_remember_klasses() const {
60 assert(!must_remember_klasses(), "Should have overriden this method.");
61 return false;
62 }
64 virtual void remember_klass(Klass* k) { /* do nothing */ }
66 // In support of post-processing of weak references in
67 // ProfileData (MethodDataOop) objects; see, for example,
68 // VirtualCallData::oop_iterate().
69 virtual const bool should_remember_mdo() const { return false; }
70 virtual void remember_mdo(DataLayout* v) { /* do nothing */ }
72 // If "true", invoke on nmethods (when scanning compiled frames).
73 virtual const bool do_nmethods() const { return false; }
75 // The methods below control how object iterations invoking this closure
76 // should be performed:
78 // If "true", invoke on header klass field.
79 bool do_header() { return true; } // Note that this is non-virtual.
80 // Controls how prefetching is done for invocations of this closure.
81 Prefetch::style prefetch_style() { // Note that this is non-virtual.
82 return Prefetch::do_none;
83 }
85 // True iff this closure may be safely applied more than once to an oop
86 // location without an intervening "major reset" (like the end of a GC).
87 virtual bool idempotent() { return false; }
88 virtual bool apply_to_weak_ref_discovered_field() { return false; }
90 #ifdef ASSERT
91 static bool _must_remember_klasses;
92 static bool must_remember_klasses();
93 static void set_must_remember_klasses(bool v);
94 #endif
95 };
97 // ObjectClosure is used for iterating through an object space
99 class ObjectClosure : public Closure {
100 public:
101 // Called for each object.
102 virtual void do_object(oop obj) = 0;
103 };
106 class BoolObjectClosure : public ObjectClosure {
107 public:
108 virtual bool do_object_b(oop obj) = 0;
109 };
111 // Applies an oop closure to all ref fields in objects iterated over in an
112 // object iteration.
113 class ObjectToOopClosure: public ObjectClosure {
114 OopClosure* _cl;
115 public:
116 void do_object(oop obj);
117 ObjectToOopClosure(OopClosure* cl) : _cl(cl) {}
118 };
120 // A version of ObjectClosure with "memory" (see _previous_address below)
121 class UpwardsObjectClosure: public BoolObjectClosure {
122 HeapWord* _previous_address;
123 public:
124 UpwardsObjectClosure() : _previous_address(NULL) { }
125 void set_previous(HeapWord* addr) { _previous_address = addr; }
126 HeapWord* previous() { return _previous_address; }
127 // A return value of "true" can be used by the caller to decide
128 // if this object's end should *NOT* be recorded in
129 // _previous_address above.
130 virtual bool do_object_bm(oop obj, MemRegion mr) = 0;
131 };
133 // A version of ObjectClosure that is expected to be robust
134 // in the face of possibly uninitialized objects.
135 class ObjectClosureCareful : public ObjectClosure {
136 public:
137 virtual size_t do_object_careful_m(oop p, MemRegion mr) = 0;
138 virtual size_t do_object_careful(oop p) = 0;
139 };
141 // The following are used in CompactibleFreeListSpace and
142 // ConcurrentMarkSweepGeneration.
144 // Blk closure (abstract class)
145 class BlkClosure : public StackObj {
146 public:
147 virtual size_t do_blk(HeapWord* addr) = 0;
148 };
150 // A version of BlkClosure that is expected to be robust
151 // in the face of possibly uninitialized objects.
152 class BlkClosureCareful : public BlkClosure {
153 public:
154 size_t do_blk(HeapWord* addr) {
155 guarantee(false, "call do_blk_careful instead");
156 return 0;
157 }
158 virtual size_t do_blk_careful(HeapWord* addr) = 0;
159 };
161 // SpaceClosure is used for iterating over spaces
163 class Space;
164 class CompactibleSpace;
166 class SpaceClosure : public StackObj {
167 public:
168 // Called for each space
169 virtual void do_space(Space* s) = 0;
170 };
172 class CompactibleSpaceClosure : public StackObj {
173 public:
174 // Called for each compactible space
175 virtual void do_space(CompactibleSpace* s) = 0;
176 };
180 // MonitorClosure is used for iterating over monitors in the monitors cache
182 class ObjectMonitor;
184 class MonitorClosure : public StackObj {
185 public:
186 // called for each monitor in cache
187 virtual void do_monitor(ObjectMonitor* m) = 0;
188 };
190 // A closure that is applied without any arguments.
191 class VoidClosure : public StackObj {
192 public:
193 // I would have liked to declare this a pure virtual, but that breaks
194 // in mysterious ways, for unknown reasons.
195 virtual void do_void();
196 };
199 // YieldClosure is intended for use by iteration loops
200 // to incrementalize their work, allowing interleaving
201 // of an interruptable task so as to allow other
202 // threads to run (which may not otherwise be able to access
203 // exclusive resources, for instance). Additionally, the
204 // closure also allows for aborting an ongoing iteration
205 // by means of checking the return value from the polling
206 // call.
207 class YieldClosure : public StackObj {
208 public:
209 virtual bool should_return() = 0;
210 };
212 // Abstract closure for serializing data (read or write).
214 class SerializeOopClosure : public OopClosure {
215 public:
216 // Return bool indicating whether closure implements read or write.
217 virtual bool reading() const = 0;
219 // Read/write the int pointed to by i.
220 virtual void do_int(int* i) = 0;
222 // Read/write the size_t pointed to by i.
223 virtual void do_size_t(size_t* i) = 0;
225 // Read/write the void pointer pointed to by p.
226 virtual void do_ptr(void** p) = 0;
228 // Read/write the HeapWord pointer pointed to be p.
229 virtual void do_ptr(HeapWord** p) = 0;
231 // Read/write the region specified.
232 virtual void do_region(u_char* start, size_t size) = 0;
234 // Check/write the tag. If reading, then compare the tag against
235 // the passed in value and fail is they don't match. This allows
236 // for verification that sections of the serialized data are of the
237 // correct length.
238 virtual void do_tag(int tag) = 0;
239 };
241 #ifdef ASSERT
242 // This class is used to flag phases of a collection that
243 // can unload classes and which should override the
244 // should_remember_klasses() and remember_klass() of OopClosure.
245 // The _must_remember_klasses is set in the contructor and restored
246 // in the destructor. _must_remember_klasses is checked in assertions
247 // in the OopClosure implementations of should_remember_klasses() and
248 // remember_klass() and the expectation is that the OopClosure
249 // implementation should not be in use if _must_remember_klasses is set.
250 // Instances of RememberKlassesChecker can be place in
251 // marking phases of collections which can do class unloading.
252 // RememberKlassesChecker can be passed "false" to turn off checking.
253 // It is used by CMS when CMS yields to a different collector.
254 class RememberKlassesChecker: StackObj {
255 bool _state;
256 bool _skip;
257 public:
258 RememberKlassesChecker(bool checking_on) : _state(false), _skip(false) {
259 _skip = !(ClassUnloading && !UseConcMarkSweepGC ||
260 CMSClassUnloadingEnabled && UseConcMarkSweepGC);
261 if (_skip) {
262 return;
263 }
264 _state = OopClosure::must_remember_klasses();
265 OopClosure::set_must_remember_klasses(checking_on);
266 }
267 ~RememberKlassesChecker() {
268 if (_skip) {
269 return;
270 }
271 OopClosure::set_must_remember_klasses(_state);
272 }
273 };
274 #endif // ASSERT