Mercurial > hg > graal-compiler
annotate src/share/vm/memory/iterator.hpp @ 948:89e0543e1737
6884624: Update copyright year
Summary: Update copyright for files that have been modified in 2009 through Septermber
Reviewed-by: tbell, ohair
author | xdono |
---|---|
date | Tue, 22 Sep 2009 14:06:10 -0700 |
parents | 8b46c4d82093 |
children | a1423fe86a18 |
rev | line source |
---|---|
0 | 1 /* |
948 | 2 * Copyright 1997-2009 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; | |
941 | 28 class DataLayout; |
0 | 29 |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
30 // Closure provides abortability. |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
31 |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
32 class Closure : public StackObj { |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
33 protected: |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
34 bool _abort; |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
35 void set_abort() { _abort = true; } |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
36 public: |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
37 Closure() : _abort(false) {} |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
38 // 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
|
39 // functions that the iteration should cease. |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
40 bool abort() { return _abort; } |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
41 void clear_abort() { _abort = false; } |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
42 }; |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
43 |
0 | 44 // OopClosure is used for iterating through roots (oop*) |
45 | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
46 class OopClosure : public Closure { |
0 | 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); } | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
53 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
|
54 virtual void do_oop_v(narrowOop* o) { do_oop(o); } |
0 | 55 |
56 // In support of post-processing of weak links of KlassKlass objects; | |
57 // see KlassKlass::oop_oop_iterate(). | |
935 | 58 |
59 virtual const bool should_remember_klasses() const { | |
60 assert(!must_remember_klasses(), "Should have overriden this method."); | |
61 return false; | |
62 } | |
63 | |
0 | 64 virtual void remember_klass(Klass* k) { /* do nothing */ } |
65 | |
941 | 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 */ } | |
71 | |
0 | 72 // If "true", invoke on nmethods (when scanning compiled frames). |
73 virtual const bool do_nmethods() const { return false; } | |
74 | |
75 // The methods below control how object iterations invoking this closure | |
76 // should be performed: | |
77 | |
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 } | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
84 |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
85 // 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
|
86 // 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
|
87 virtual bool idempotent() { return false; } |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
88 virtual bool apply_to_weak_ref_discovered_field() { return false; } |
935 | 89 |
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 | |
0 | 95 }; |
96 | |
97 // ObjectClosure is used for iterating through an object space | |
98 | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
99 class ObjectClosure : public Closure { |
0 | 100 public: |
101 // Called for each object. | |
102 virtual void do_object(oop obj) = 0; | |
103 }; | |
104 | |
105 | |
106 class BoolObjectClosure : public ObjectClosure { | |
107 public: | |
108 virtual bool do_object_b(oop obj) = 0; | |
109 }; | |
110 | |
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 }; | |
119 | |
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 }; | |
132 | |
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 }; | |
140 | |
141 // The following are used in CompactibleFreeListSpace and | |
142 // ConcurrentMarkSweepGeneration. | |
143 | |
144 // Blk closure (abstract class) | |
145 class BlkClosure : public StackObj { | |
146 public: | |
147 virtual size_t do_blk(HeapWord* addr) = 0; | |
148 }; | |
149 | |
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 }; | |
160 | |
161 // SpaceClosure is used for iterating over spaces | |
162 | |
163 class Space; | |
164 class CompactibleSpace; | |
165 | |
166 class SpaceClosure : public StackObj { | |
167 public: | |
168 // Called for each space | |
169 virtual void do_space(Space* s) = 0; | |
170 }; | |
171 | |
172 class CompactibleSpaceClosure : public StackObj { | |
173 public: | |
174 // Called for each compactible space | |
175 virtual void do_space(CompactibleSpace* s) = 0; | |
176 }; | |
177 | |
178 | |
179 | |
180 // MonitorClosure is used for iterating over monitors in the monitors cache | |
181 | |
182 class ObjectMonitor; | |
183 | |
184 class MonitorClosure : public StackObj { | |
185 public: | |
186 // called for each monitor in cache | |
187 virtual void do_monitor(ObjectMonitor* m) = 0; | |
188 }; | |
189 | |
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 }; | |
197 | |
198 | |
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 }; | |
211 | |
212 // Abstract closure for serializing data (read or write). | |
213 | |
214 class SerializeOopClosure : public OopClosure { | |
215 public: | |
216 // Return bool indicating whether closure implements read or write. | |
217 virtual bool reading() const = 0; | |
218 | |
219 // Read/write the int pointed to by i. | |
220 virtual void do_int(int* i) = 0; | |
221 | |
222 // Read/write the size_t pointed to by i. | |
223 virtual void do_size_t(size_t* i) = 0; | |
224 | |
225 // Read/write the void pointer pointed to by p. | |
226 virtual void do_ptr(void** p) = 0; | |
227 | |
228 // Read/write the HeapWord pointer pointed to be p. | |
229 virtual void do_ptr(HeapWord** p) = 0; | |
230 | |
231 // Read/write the region specified. | |
232 virtual void do_region(u_char* start, size_t size) = 0; | |
233 | |
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 }; | |
935 | 240 |
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 |