comparison src/share/vm/gc_implementation/shared/markSweep.hpp @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children ba764ed4b6f2
comparison
equal deleted inserted replaced
-1:000000000000 0:a61af66fc99e
1 /*
2 * Copyright 1997-2007 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 class ReferenceProcessor;
26
27 // MarkSweep takes care of global mark-compact garbage collection for a
28 // GenCollectedHeap using a four-phase pointer forwarding algorithm. All
29 // generations are assumed to support marking; those that can also support
30 // compaction.
31 //
32 // Class unloading will only occur when a full gc is invoked.
33
34 // If VALIDATE_MARK_SWEEP is defined, the -XX:+ValidateMarkSweep flag will
35 // be operational, and will provide slow but comprehensive self-checks within
36 // the GC. This is not enabled by default in product or release builds,
37 // since the extra call to track_adjusted_pointer() in _adjust_pointer()
38 // would be too much overhead, and would disturb performance measurement.
39 // However, debug builds are sometimes way too slow to run GC tests!
40 #ifdef ASSERT
41 #define VALIDATE_MARK_SWEEP 1
42 #endif
43 #ifdef VALIDATE_MARK_SWEEP
44 #define VALIDATE_MARK_SWEEP_ONLY(code) code
45 #else
46 #define VALIDATE_MARK_SWEEP_ONLY(code)
47 #endif
48
49
50 // declared at end
51 class PreservedMark;
52
53 class MarkSweep : AllStatic {
54 //
55 // In line closure decls
56 //
57
58 class FollowRootClosure: public OopsInGenClosure{
59 public:
60 void do_oop(oop* p) { follow_root(p); }
61 virtual const bool do_nmethods() const { return true; }
62 };
63
64 class MarkAndPushClosure: public OopClosure {
65 public:
66 void do_oop(oop* p) { mark_and_push(p); }
67 virtual const bool do_nmethods() const { return true; }
68 };
69
70 class FollowStackClosure: public VoidClosure {
71 public:
72 void do_void() { follow_stack(); }
73 };
74
75 class AdjustPointerClosure: public OopsInGenClosure {
76 bool _is_root;
77 public:
78 AdjustPointerClosure(bool is_root) : _is_root(is_root) {}
79 void do_oop(oop* p) { _adjust_pointer(p, _is_root); }
80 };
81
82 // Used for java/lang/ref handling
83 class IsAliveClosure: public BoolObjectClosure {
84 public:
85 void do_object(oop p) { assert(false, "don't call"); }
86 bool do_object_b(oop p) { return p->is_gc_marked(); }
87 };
88
89 class KeepAliveClosure: public OopClosure {
90 public:
91 void do_oop(oop* p);
92 };
93
94 //
95 // Friend decls
96 //
97
98 friend class AdjustPointerClosure;
99 friend class KeepAliveClosure;
100 friend class VM_MarkSweep;
101 friend void marksweep_init();
102
103 //
104 // Vars
105 //
106 protected:
107 // Traversal stack used during phase1
108 static GrowableArray<oop>* _marking_stack;
109 // Stack for live klasses to revisit at end of marking phase
110 static GrowableArray<Klass*>* _revisit_klass_stack;
111
112 // Space for storing/restoring mark word
113 static GrowableArray<markOop>* _preserved_mark_stack;
114 static GrowableArray<oop>* _preserved_oop_stack;
115 static size_t _preserved_count;
116 static size_t _preserved_count_max;
117 static PreservedMark* _preserved_marks;
118
119 // Reference processing (used in ...follow_contents)
120 static ReferenceProcessor* _ref_processor;
121
122 #ifdef VALIDATE_MARK_SWEEP
123 static GrowableArray<oop*>* _root_refs_stack;
124 static GrowableArray<oop> * _live_oops;
125 static GrowableArray<oop> * _live_oops_moved_to;
126 static GrowableArray<size_t>* _live_oops_size;
127 static size_t _live_oops_index;
128 static size_t _live_oops_index_at_perm;
129 static GrowableArray<oop*>* _other_refs_stack;
130 static GrowableArray<oop*>* _adjusted_pointers;
131 static bool _pointer_tracking;
132 static bool _root_tracking;
133
134 // The following arrays are saved since the time of the last GC and
135 // assist in tracking down problems where someone has done an errant
136 // store into the heap, usually to an oop that wasn't properly
137 // handleized across a GC. If we crash or otherwise fail before the
138 // next GC, we can query these arrays to find out the object we had
139 // intended to do the store to (assuming it is still alive) and the
140 // offset within that object. Covered under RecordMarkSweepCompaction.
141 static GrowableArray<HeapWord*> * _cur_gc_live_oops;
142 static GrowableArray<HeapWord*> * _cur_gc_live_oops_moved_to;
143 static GrowableArray<size_t>* _cur_gc_live_oops_size;
144 static GrowableArray<HeapWord*> * _last_gc_live_oops;
145 static GrowableArray<HeapWord*> * _last_gc_live_oops_moved_to;
146 static GrowableArray<size_t>* _last_gc_live_oops_size;
147 #endif
148
149
150 // Non public closures
151 static IsAliveClosure is_alive;
152 static KeepAliveClosure keep_alive;
153
154 // Class unloading. Update subklass/sibling/implementor links at end of marking phase.
155 static void follow_weak_klass_links();
156
157 // Debugging
158 static void trace(const char* msg) PRODUCT_RETURN;
159
160 public:
161 // Public closures
162 static FollowRootClosure follow_root_closure;
163 static MarkAndPushClosure mark_and_push_closure;
164 static FollowStackClosure follow_stack_closure;
165 static AdjustPointerClosure adjust_root_pointer_closure;
166 static AdjustPointerClosure adjust_pointer_closure;
167
168 // Reference Processing
169 static ReferenceProcessor* const ref_processor() { return _ref_processor; }
170
171 // Call backs for marking
172 static void mark_object(oop obj);
173 static void follow_root(oop* p); // Mark pointer and follow contents. Empty marking
174
175 // stack afterwards.
176
177 static void mark_and_follow(oop* p); // Mark pointer and follow contents.
178 static void _mark_and_push(oop* p); // Mark pointer and push obj on
179 // marking stack.
180
181
182 static void mark_and_push(oop* p) { // Check mark and maybe push on
183 // marking stack
184 // assert(Universe::is_reserved_heap((oop)p), "we should only be traversing objects here");
185 oop m = *p;
186 if (m != NULL && !m->mark()->is_marked()) {
187 _mark_and_push(p);
188 }
189 }
190
191 static void follow_stack(); // Empty marking stack.
192
193
194 static void preserve_mark(oop p, markOop mark); // Save the mark word so it can be restored later
195 static void adjust_marks(); // Adjust the pointers in the preserved marks table
196 static void restore_marks(); // Restore the marks that we saved in preserve_mark
197
198 static void _adjust_pointer(oop* p, bool isroot);
199
200 static void adjust_root_pointer(oop* p) { _adjust_pointer(p, true); }
201 static void adjust_pointer(oop* p) { _adjust_pointer(p, false); }
202
203 #ifdef VALIDATE_MARK_SWEEP
204 static void track_adjusted_pointer(oop* p, oop newobj, bool isroot);
205 static void check_adjust_pointer(oop* p); // Adjust this pointer
206 static void track_interior_pointers(oop obj);
207 static void check_interior_pointers();
208
209 static void reset_live_oop_tracking(bool at_perm);
210 static void register_live_oop(oop p, size_t size);
211 static void validate_live_oop(oop p, size_t size);
212 static void live_oop_moved_to(HeapWord* q, size_t size, HeapWord* compaction_top);
213 static void compaction_complete();
214
215 // Querying operation of RecordMarkSweepCompaction results.
216 // Finds and prints the current base oop and offset for a word
217 // within an oop that was live during the last GC. Helpful for
218 // tracking down heap stomps.
219 static void print_new_location_of_heap_address(HeapWord* q);
220 #endif
221
222 // Call backs for class unloading
223 static void revisit_weak_klass_link(Klass* k); // Update subklass/sibling/implementor links at end of marking.
224 };
225
226
227 class PreservedMark VALUE_OBJ_CLASS_SPEC {
228 private:
229 oop _obj;
230 markOop _mark;
231
232 public:
233 void init(oop obj, markOop mark) {
234 _obj = obj;
235 _mark = mark;
236 }
237
238 void adjust_pointer() {
239 MarkSweep::adjust_pointer(&_obj);
240 }
241
242 void restore() {
243 _obj->set_mark(_mark);
244 }
245 };