0
|
1 /*
|
|
2 * Copyright 1997-2006 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 */
|
|
24
|
|
25 // The following classes are C++ `closures` for iterating over objects, roots and spaces
|
|
26
|
|
27 class ReferenceProcessor;
|
|
28
|
|
29 // OopClosure is used for iterating through roots (oop*)
|
|
30
|
|
31 class OopClosure : public StackObj {
|
|
32 public:
|
|
33 ReferenceProcessor* _ref_processor;
|
|
34 OopClosure(ReferenceProcessor* rp) : _ref_processor(rp) { }
|
|
35 OopClosure() : _ref_processor(NULL) { }
|
|
36 virtual void do_oop(oop* o) = 0;
|
|
37 virtual void do_oop_v(oop* o) { do_oop(o); }
|
|
38
|
|
39 // In support of post-processing of weak links of KlassKlass objects;
|
|
40 // see KlassKlass::oop_oop_iterate().
|
|
41 virtual const bool should_remember_klasses() const { return false; }
|
|
42 virtual void remember_klass(Klass* k) { /* do nothing */ }
|
|
43
|
|
44 // If "true", invoke on nmethods (when scanning compiled frames).
|
|
45 virtual const bool do_nmethods() const { return false; }
|
|
46
|
|
47 // The methods below control how object iterations invoking this closure
|
|
48 // should be performed:
|
|
49
|
|
50 // If "true", invoke on header klass field.
|
|
51 bool do_header() { return true; } // Note that this is non-virtual.
|
|
52 // Controls how prefetching is done for invocations of this closure.
|
|
53 Prefetch::style prefetch_style() { // Note that this is non-virtual.
|
|
54 return Prefetch::do_none;
|
|
55 }
|
|
56 };
|
|
57
|
|
58 // ObjectClosure is used for iterating through an object space
|
|
59
|
|
60 class ObjectClosure : public StackObj {
|
|
61 public:
|
|
62 // Called for each object.
|
|
63 virtual void do_object(oop obj) = 0;
|
|
64 };
|
|
65
|
|
66
|
|
67 class BoolObjectClosure : public ObjectClosure {
|
|
68 public:
|
|
69 virtual bool do_object_b(oop obj) = 0;
|
|
70 };
|
|
71
|
|
72 // Applies an oop closure to all ref fields in objects iterated over in an
|
|
73 // object iteration.
|
|
74 class ObjectToOopClosure: public ObjectClosure {
|
|
75 OopClosure* _cl;
|
|
76 public:
|
|
77 void do_object(oop obj);
|
|
78 ObjectToOopClosure(OopClosure* cl) : _cl(cl) {}
|
|
79 };
|
|
80
|
|
81 // A version of ObjectClosure with "memory" (see _previous_address below)
|
|
82 class UpwardsObjectClosure: public BoolObjectClosure {
|
|
83 HeapWord* _previous_address;
|
|
84 public:
|
|
85 UpwardsObjectClosure() : _previous_address(NULL) { }
|
|
86 void set_previous(HeapWord* addr) { _previous_address = addr; }
|
|
87 HeapWord* previous() { return _previous_address; }
|
|
88 // A return value of "true" can be used by the caller to decide
|
|
89 // if this object's end should *NOT* be recorded in
|
|
90 // _previous_address above.
|
|
91 virtual bool do_object_bm(oop obj, MemRegion mr) = 0;
|
|
92 };
|
|
93
|
|
94 // A version of ObjectClosure that is expected to be robust
|
|
95 // in the face of possibly uninitialized objects.
|
|
96 class ObjectClosureCareful : public ObjectClosure {
|
|
97 public:
|
|
98 virtual size_t do_object_careful_m(oop p, MemRegion mr) = 0;
|
|
99 virtual size_t do_object_careful(oop p) = 0;
|
|
100 };
|
|
101
|
|
102 // The following are used in CompactibleFreeListSpace and
|
|
103 // ConcurrentMarkSweepGeneration.
|
|
104
|
|
105 // Blk closure (abstract class)
|
|
106 class BlkClosure : public StackObj {
|
|
107 public:
|
|
108 virtual size_t do_blk(HeapWord* addr) = 0;
|
|
109 };
|
|
110
|
|
111 // A version of BlkClosure that is expected to be robust
|
|
112 // in the face of possibly uninitialized objects.
|
|
113 class BlkClosureCareful : public BlkClosure {
|
|
114 public:
|
|
115 size_t do_blk(HeapWord* addr) {
|
|
116 guarantee(false, "call do_blk_careful instead");
|
|
117 return 0;
|
|
118 }
|
|
119 virtual size_t do_blk_careful(HeapWord* addr) = 0;
|
|
120 };
|
|
121
|
|
122 // SpaceClosure is used for iterating over spaces
|
|
123
|
|
124 class Space;
|
|
125 class CompactibleSpace;
|
|
126
|
|
127 class SpaceClosure : public StackObj {
|
|
128 public:
|
|
129 // Called for each space
|
|
130 virtual void do_space(Space* s) = 0;
|
|
131 };
|
|
132
|
|
133 class CompactibleSpaceClosure : public StackObj {
|
|
134 public:
|
|
135 // Called for each compactible space
|
|
136 virtual void do_space(CompactibleSpace* s) = 0;
|
|
137 };
|
|
138
|
|
139
|
|
140
|
|
141 // MonitorClosure is used for iterating over monitors in the monitors cache
|
|
142
|
|
143 class ObjectMonitor;
|
|
144
|
|
145 class MonitorClosure : public StackObj {
|
|
146 public:
|
|
147 // called for each monitor in cache
|
|
148 virtual void do_monitor(ObjectMonitor* m) = 0;
|
|
149 };
|
|
150
|
|
151 // A closure that is applied without any arguments.
|
|
152 class VoidClosure : public StackObj {
|
|
153 public:
|
|
154 // I would have liked to declare this a pure virtual, but that breaks
|
|
155 // in mysterious ways, for unknown reasons.
|
|
156 virtual void do_void();
|
|
157 };
|
|
158
|
|
159
|
|
160 // YieldClosure is intended for use by iteration loops
|
|
161 // to incrementalize their work, allowing interleaving
|
|
162 // of an interruptable task so as to allow other
|
|
163 // threads to run (which may not otherwise be able to access
|
|
164 // exclusive resources, for instance). Additionally, the
|
|
165 // closure also allows for aborting an ongoing iteration
|
|
166 // by means of checking the return value from the polling
|
|
167 // call.
|
|
168 class YieldClosure : public StackObj {
|
|
169 public:
|
|
170 virtual bool should_return() = 0;
|
|
171 };
|
|
172
|
|
173 // Abstract closure for serializing data (read or write).
|
|
174
|
|
175 class SerializeOopClosure : public OopClosure {
|
|
176 public:
|
|
177 // Return bool indicating whether closure implements read or write.
|
|
178 virtual bool reading() const = 0;
|
|
179
|
|
180 // Read/write the int pointed to by i.
|
|
181 virtual void do_int(int* i) = 0;
|
|
182
|
|
183 // Read/write the size_t pointed to by i.
|
|
184 virtual void do_size_t(size_t* i) = 0;
|
|
185
|
|
186 // Read/write the void pointer pointed to by p.
|
|
187 virtual void do_ptr(void** p) = 0;
|
|
188
|
|
189 // Read/write the HeapWord pointer pointed to be p.
|
|
190 virtual void do_ptr(HeapWord** p) = 0;
|
|
191
|
|
192 // Read/write the region specified.
|
|
193 virtual void do_region(u_char* start, size_t size) = 0;
|
|
194
|
|
195 // Check/write the tag. If reading, then compare the tag against
|
|
196 // the passed in value and fail is they don't match. This allows
|
|
197 // for verification that sections of the serialized data are of the
|
|
198 // correct length.
|
|
199 virtual void do_tag(int tag) = 0;
|
|
200 };
|