author | jrose |
Tue, 15 Sep 2009 21:53:47 -0700 | |
changeset 3908 | 24b55ad4c228 |
parent 1388 | 3677f5f3d66b |
child 3912 | 3aaaaad1ccb0 |
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; |
29 |
||
1374
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
30 |
// Closure provides abortability. |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
31 |
|
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
32 |
class Closure : public StackObj { |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
33 |
protected: |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
34 |
bool _abort; |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
35 |
void set_abort() { _abort = true; } |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
36 |
public: |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
37 |
Closure() : _abort(false) {} |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
38 |
// 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
|
39 |
// functions that the iteration should cease. |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
40 |
bool abort() { return _abort; } |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
41 |
void clear_abort() { _abort = false; } |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
42 |
}; |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
43 |
|
1 | 44 |
// OopClosure is used for iterating through roots (oop*) |
45 |
||
1374
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
46 |
class OopClosure : public Closure { |
1 | 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); } |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
53 |
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
|
54 |
virtual void do_oop_v(narrowOop* o) { do_oop(o); } |
1 | 55 |
|
56 |
// In support of post-processing of weak links of KlassKlass objects; |
|
57 |
// see KlassKlass::oop_oop_iterate(). |
|
58 |
virtual const bool should_remember_klasses() const { return false; } |
|
59 |
virtual void remember_klass(Klass* k) { /* do nothing */ } |
|
60 |
||
61 |
// The methods below control how object iterations invoking this closure |
|
62 |
// should be performed: |
|
63 |
||
64 |
// If "true", invoke on header klass field. |
|
65 |
bool do_header() { return true; } // Note that this is non-virtual. |
|
66 |
// Controls how prefetching is done for invocations of this closure. |
|
67 |
Prefetch::style prefetch_style() { // Note that this is non-virtual. |
|
68 |
return Prefetch::do_none; |
|
69 |
} |
|
1374
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
70 |
|
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
71 |
// 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
|
72 |
// 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
|
73 |
virtual bool idempotent() { return false; } |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
74 |
virtual bool apply_to_weak_ref_discovered_field() { return false; } |
1 | 75 |
}; |
76 |
||
77 |
// ObjectClosure is used for iterating through an object space |
|
78 |
||
1374
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
79 |
class ObjectClosure : public Closure { |
1 | 80 |
public: |
81 |
// Called for each object. |
|
82 |
virtual void do_object(oop obj) = 0; |
|
83 |
}; |
|
84 |
||
85 |
||
86 |
class BoolObjectClosure : public ObjectClosure { |
|
87 |
public: |
|
88 |
virtual bool do_object_b(oop obj) = 0; |
|
89 |
}; |
|
90 |
||
91 |
// Applies an oop closure to all ref fields in objects iterated over in an |
|
92 |
// object iteration. |
|
93 |
class ObjectToOopClosure: public ObjectClosure { |
|
94 |
OopClosure* _cl; |
|
95 |
public: |
|
96 |
void do_object(oop obj); |
|
97 |
ObjectToOopClosure(OopClosure* cl) : _cl(cl) {} |
|
98 |
}; |
|
99 |
||
100 |
// A version of ObjectClosure with "memory" (see _previous_address below) |
|
101 |
class UpwardsObjectClosure: public BoolObjectClosure { |
|
102 |
HeapWord* _previous_address; |
|
103 |
public: |
|
104 |
UpwardsObjectClosure() : _previous_address(NULL) { } |
|
105 |
void set_previous(HeapWord* addr) { _previous_address = addr; } |
|
106 |
HeapWord* previous() { return _previous_address; } |
|
107 |
// A return value of "true" can be used by the caller to decide |
|
108 |
// if this object's end should *NOT* be recorded in |
|
109 |
// _previous_address above. |
|
110 |
virtual bool do_object_bm(oop obj, MemRegion mr) = 0; |
|
111 |
}; |
|
112 |
||
113 |
// A version of ObjectClosure that is expected to be robust |
|
114 |
// in the face of possibly uninitialized objects. |
|
115 |
class ObjectClosureCareful : public ObjectClosure { |
|
116 |
public: |
|
117 |
virtual size_t do_object_careful_m(oop p, MemRegion mr) = 0; |
|
118 |
virtual size_t do_object_careful(oop p) = 0; |
|
119 |
}; |
|
120 |
||
121 |
// The following are used in CompactibleFreeListSpace and |
|
122 |
// ConcurrentMarkSweepGeneration. |
|
123 |
||
124 |
// Blk closure (abstract class) |
|
125 |
class BlkClosure : public StackObj { |
|
126 |
public: |
|
127 |
virtual size_t do_blk(HeapWord* addr) = 0; |
|
128 |
}; |
|
129 |
||
130 |
// A version of BlkClosure that is expected to be robust |
|
131 |
// in the face of possibly uninitialized objects. |
|
132 |
class BlkClosureCareful : public BlkClosure { |
|
133 |
public: |
|
134 |
size_t do_blk(HeapWord* addr) { |
|
135 |
guarantee(false, "call do_blk_careful instead"); |
|
136 |
return 0; |
|
137 |
} |
|
138 |
virtual size_t do_blk_careful(HeapWord* addr) = 0; |
|
139 |
}; |
|
140 |
||
141 |
// SpaceClosure is used for iterating over spaces |
|
142 |
||
143 |
class Space; |
|
144 |
class CompactibleSpace; |
|
145 |
||
146 |
class SpaceClosure : public StackObj { |
|
147 |
public: |
|
148 |
// Called for each space |
|
149 |
virtual void do_space(Space* s) = 0; |
|
150 |
}; |
|
151 |
||
152 |
class CompactibleSpaceClosure : public StackObj { |
|
153 |
public: |
|
154 |
// Called for each compactible space |
|
155 |
virtual void do_space(CompactibleSpace* s) = 0; |
|
156 |
}; |
|
157 |
||
158 |
||
3908
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
159 |
// 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
|
160 |
// 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
|
161 |
|
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
162 |
class CodeBlobClosure : public Closure { |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
163 |
public: |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
164 |
// Called for each code blob. |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
165 |
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
|
166 |
}; |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
167 |
|
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
168 |
|
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
169 |
class MarkingCodeBlobClosure : public CodeBlobClosure { |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
170 |
public: |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
171 |
// 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
|
172 |
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
|
173 |
|
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
174 |
virtual void do_code_blob(CodeBlob* cb); |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
175 |
// = { 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
|
176 |
|
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
177 |
class MarkScope : public StackObj { |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
178 |
protected: |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
179 |
bool _active; |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
180 |
public: |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
181 |
MarkScope(bool activate = true); |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
182 |
// = { if (active) nmethod::oops_do_marking_prologue(); } |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
183 |
~MarkScope(); |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
184 |
// = { if (active) nmethod::oops_do_marking_epilogue(); } |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
185 |
}; |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
186 |
}; |
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 |
// 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
|
190 |
// iterated over in an object iteration. |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
191 |
class CodeBlobToOopClosure: public MarkingCodeBlobClosure { |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
192 |
OopClosure* _cl; |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
193 |
bool _do_marking; |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
194 |
public: |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
195 |
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
|
196 |
// = { cb->oops_do(_cl); } |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
197 |
virtual void do_code_blob(CodeBlob* cb); |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
198 |
// = { 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
|
199 |
CodeBlobToOopClosure(OopClosure* cl, bool do_marking) |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
200 |
: _cl(cl), _do_marking(do_marking) {} |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
201 |
}; |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
202 |
|
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
1388
diff
changeset
|
203 |
|
1 | 204 |
|
205 |
// MonitorClosure is used for iterating over monitors in the monitors cache |
|
206 |
||
207 |
class ObjectMonitor; |
|
208 |
||
209 |
class MonitorClosure : public StackObj { |
|
210 |
public: |
|
211 |
// called for each monitor in cache |
|
212 |
virtual void do_monitor(ObjectMonitor* m) = 0; |
|
213 |
}; |
|
214 |
||
215 |
// A closure that is applied without any arguments. |
|
216 |
class VoidClosure : public StackObj { |
|
217 |
public: |
|
218 |
// I would have liked to declare this a pure virtual, but that breaks |
|
219 |
// in mysterious ways, for unknown reasons. |
|
220 |
virtual void do_void(); |
|
221 |
}; |
|
222 |
||
223 |
||
224 |
// YieldClosure is intended for use by iteration loops |
|
225 |
// to incrementalize their work, allowing interleaving |
|
226 |
// of an interruptable task so as to allow other |
|
227 |
// threads to run (which may not otherwise be able to access |
|
228 |
// exclusive resources, for instance). Additionally, the |
|
229 |
// closure also allows for aborting an ongoing iteration |
|
230 |
// by means of checking the return value from the polling |
|
231 |
// call. |
|
232 |
class YieldClosure : public StackObj { |
|
233 |
public: |
|
234 |
virtual bool should_return() = 0; |
|
235 |
}; |
|
236 |
||
237 |
// Abstract closure for serializing data (read or write). |
|
238 |
||
239 |
class SerializeOopClosure : public OopClosure { |
|
240 |
public: |
|
241 |
// Return bool indicating whether closure implements read or write. |
|
242 |
virtual bool reading() const = 0; |
|
243 |
||
244 |
// Read/write the int pointed to by i. |
|
245 |
virtual void do_int(int* i) = 0; |
|
246 |
||
247 |
// Read/write the size_t pointed to by i. |
|
248 |
virtual void do_size_t(size_t* i) = 0; |
|
249 |
||
250 |
// Read/write the void pointer pointed to by p. |
|
251 |
virtual void do_ptr(void** p) = 0; |
|
252 |
||
253 |
// Read/write the HeapWord pointer pointed to be p. |
|
254 |
virtual void do_ptr(HeapWord** p) = 0; |
|
255 |
||
256 |
// Read/write the region specified. |
|
257 |
virtual void do_region(u_char* start, size_t size) = 0; |
|
258 |
||
259 |
// Check/write the tag. If reading, then compare the tag against |
|
260 |
// the passed in value and fail is they don't match. This allows |
|
261 |
// for verification that sections of the serialized data are of the |
|
262 |
// correct length. |
|
263 |
virtual void do_tag(int tag) = 0; |
|
264 |
}; |