annotate src/share/vm/gc_implementation/shared/markSweep.cpp @ 12:6432c3bb6240

6668743: CMS: Consolidate block statistics reporting code Summary: Reduce the amount of related code replication and improve pretty printing. Reviewed-by: jmasa
author ysr
date Fri, 29 Feb 2008 14:42:56 -0800
parents a61af66fc99e
children ba764ed4b6f2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 1997-2005 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 #include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 #include "incls/_markSweep.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 GrowableArray<oop>* MarkSweep::_marking_stack = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 GrowableArray<Klass*>* MarkSweep::_revisit_klass_stack = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 GrowableArray<oop>* MarkSweep::_preserved_oop_stack = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 GrowableArray<markOop>* MarkSweep::_preserved_mark_stack= NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 size_t MarkSweep::_preserved_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 size_t MarkSweep::_preserved_count_max = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 PreservedMark* MarkSweep::_preserved_marks = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 ReferenceProcessor* MarkSweep::_ref_processor = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 #ifdef VALIDATE_MARK_SWEEP
a61af66fc99e Initial load
duke
parents:
diff changeset
39 GrowableArray<oop*>* MarkSweep::_root_refs_stack = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 GrowableArray<oop> * MarkSweep::_live_oops = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 GrowableArray<oop> * MarkSweep::_live_oops_moved_to = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 GrowableArray<size_t>* MarkSweep::_live_oops_size = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 size_t MarkSweep::_live_oops_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 size_t MarkSweep::_live_oops_index_at_perm = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 GrowableArray<oop*>* MarkSweep::_other_refs_stack = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 GrowableArray<oop*>* MarkSweep::_adjusted_pointers = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
47 bool MarkSweep::_pointer_tracking = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 bool MarkSweep::_root_tracking = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 GrowableArray<HeapWord*>* MarkSweep::_cur_gc_live_oops = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
51 GrowableArray<HeapWord*>* MarkSweep::_cur_gc_live_oops_moved_to = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
52 GrowableArray<size_t> * MarkSweep::_cur_gc_live_oops_size = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
53 GrowableArray<HeapWord*>* MarkSweep::_last_gc_live_oops = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
54 GrowableArray<HeapWord*>* MarkSweep::_last_gc_live_oops_moved_to = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 GrowableArray<size_t> * MarkSweep::_last_gc_live_oops_size = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58 void MarkSweep::revisit_weak_klass_link(Klass* k) {
a61af66fc99e Initial load
duke
parents:
diff changeset
59 _revisit_klass_stack->push(k);
a61af66fc99e Initial load
duke
parents:
diff changeset
60 }
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63 void MarkSweep::follow_weak_klass_links() {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // All klasses on the revisit stack are marked at this point.
a61af66fc99e Initial load
duke
parents:
diff changeset
65 // Update and follow all subklass, sibling and implementor links.
a61af66fc99e Initial load
duke
parents:
diff changeset
66 for (int i = 0; i < _revisit_klass_stack->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
67 _revisit_klass_stack->at(i)->follow_weak_klass_links(&is_alive,&keep_alive);
a61af66fc99e Initial load
duke
parents:
diff changeset
68 }
a61af66fc99e Initial load
duke
parents:
diff changeset
69 follow_stack();
a61af66fc99e Initial load
duke
parents:
diff changeset
70 }
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73 void MarkSweep::mark_and_follow(oop* p) {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 assert(Universe::heap()->is_in_reserved(p),
a61af66fc99e Initial load
duke
parents:
diff changeset
75 "we should only be traversing objects here");
a61af66fc99e Initial load
duke
parents:
diff changeset
76 oop m = *p;
a61af66fc99e Initial load
duke
parents:
diff changeset
77 if (m != NULL && !m->mark()->is_marked()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
78 mark_object(m);
a61af66fc99e Initial load
duke
parents:
diff changeset
79 m->follow_contents(); // Follow contents of the marked object
a61af66fc99e Initial load
duke
parents:
diff changeset
80 }
a61af66fc99e Initial load
duke
parents:
diff changeset
81 }
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 void MarkSweep::_mark_and_push(oop* p) {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // Push marked object, contents will be followed later
a61af66fc99e Initial load
duke
parents:
diff changeset
85 oop m = *p;
a61af66fc99e Initial load
duke
parents:
diff changeset
86 mark_object(m);
a61af66fc99e Initial load
duke
parents:
diff changeset
87 _marking_stack->push(m);
a61af66fc99e Initial load
duke
parents:
diff changeset
88 }
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 MarkSweep::MarkAndPushClosure MarkSweep::mark_and_push_closure;
a61af66fc99e Initial load
duke
parents:
diff changeset
91
a61af66fc99e Initial load
duke
parents:
diff changeset
92 void MarkSweep::follow_root(oop* p) {
a61af66fc99e Initial load
duke
parents:
diff changeset
93 assert(!Universe::heap()->is_in_reserved(p),
a61af66fc99e Initial load
duke
parents:
diff changeset
94 "roots shouldn't be things within the heap");
a61af66fc99e Initial load
duke
parents:
diff changeset
95 #ifdef VALIDATE_MARK_SWEEP
a61af66fc99e Initial load
duke
parents:
diff changeset
96 if (ValidateMarkSweep) {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 guarantee(!_root_refs_stack->contains(p), "should only be in here once");
a61af66fc99e Initial load
duke
parents:
diff changeset
98 _root_refs_stack->push(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
101 oop m = *p;
a61af66fc99e Initial load
duke
parents:
diff changeset
102 if (m != NULL && !m->mark()->is_marked()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
103 mark_object(m);
a61af66fc99e Initial load
duke
parents:
diff changeset
104 m->follow_contents(); // Follow contents of the marked object
a61af66fc99e Initial load
duke
parents:
diff changeset
105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
106 follow_stack();
a61af66fc99e Initial load
duke
parents:
diff changeset
107 }
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109 MarkSweep::FollowRootClosure MarkSweep::follow_root_closure;
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 void MarkSweep::follow_stack() {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 while (!_marking_stack->is_empty()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
113 oop obj = _marking_stack->pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
114 assert (obj->is_gc_marked(), "p must be marked");
a61af66fc99e Initial load
duke
parents:
diff changeset
115 obj->follow_contents();
a61af66fc99e Initial load
duke
parents:
diff changeset
116 }
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 MarkSweep::FollowStackClosure MarkSweep::follow_stack_closure;
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 // We preserve the mark which should be replaced at the end and the location that it
a61af66fc99e Initial load
duke
parents:
diff changeset
123 // will go. Note that the object that this markOop belongs to isn't currently at that
a61af66fc99e Initial load
duke
parents:
diff changeset
124 // address but it will be after phase4
a61af66fc99e Initial load
duke
parents:
diff changeset
125 void MarkSweep::preserve_mark(oop obj, markOop mark) {
a61af66fc99e Initial load
duke
parents:
diff changeset
126 // we try to store preserved marks in the to space of the new generation since this
a61af66fc99e Initial load
duke
parents:
diff changeset
127 // is storage which should be available. Most of the time this should be sufficient
a61af66fc99e Initial load
duke
parents:
diff changeset
128 // space for the marks we need to preserve but if it isn't we fall back in using
a61af66fc99e Initial load
duke
parents:
diff changeset
129 // GrowableArrays to keep track of the overflow.
a61af66fc99e Initial load
duke
parents:
diff changeset
130 if (_preserved_count < _preserved_count_max) {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 _preserved_marks[_preserved_count++].init(obj, mark);
a61af66fc99e Initial load
duke
parents:
diff changeset
132 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 if (_preserved_mark_stack == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
134 _preserved_mark_stack = new (ResourceObj::C_HEAP) GrowableArray<markOop>(40, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
135 _preserved_oop_stack = new (ResourceObj::C_HEAP) GrowableArray<oop>(40, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
137 _preserved_mark_stack->push(mark);
a61af66fc99e Initial load
duke
parents:
diff changeset
138 _preserved_oop_stack->push(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
140 }
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142 MarkSweep::AdjustPointerClosure MarkSweep::adjust_root_pointer_closure(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
143 MarkSweep::AdjustPointerClosure MarkSweep::adjust_pointer_closure(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
144
a61af66fc99e Initial load
duke
parents:
diff changeset
145 void MarkSweep::adjust_marks() {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 assert(_preserved_oop_stack == NULL ||
a61af66fc99e Initial load
duke
parents:
diff changeset
147 _preserved_oop_stack->length() == _preserved_mark_stack->length(),
a61af66fc99e Initial load
duke
parents:
diff changeset
148 "inconsistent preserved oop stacks");
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 // adjust the oops we saved earlier
a61af66fc99e Initial load
duke
parents:
diff changeset
151 for (size_t i = 0; i < _preserved_count; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 _preserved_marks[i].adjust_pointer();
a61af66fc99e Initial load
duke
parents:
diff changeset
153 }
a61af66fc99e Initial load
duke
parents:
diff changeset
154
a61af66fc99e Initial load
duke
parents:
diff changeset
155 // deal with the overflow stack
a61af66fc99e Initial load
duke
parents:
diff changeset
156 if (_preserved_oop_stack) {
a61af66fc99e Initial load
duke
parents:
diff changeset
157 for (int i = 0; i < _preserved_oop_stack->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
158 oop* p = _preserved_oop_stack->adr_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
159 adjust_pointer(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
160 }
a61af66fc99e Initial load
duke
parents:
diff changeset
161 }
a61af66fc99e Initial load
duke
parents:
diff changeset
162 }
a61af66fc99e Initial load
duke
parents:
diff changeset
163
a61af66fc99e Initial load
duke
parents:
diff changeset
164 void MarkSweep::restore_marks() {
a61af66fc99e Initial load
duke
parents:
diff changeset
165 assert(_preserved_oop_stack == NULL ||
a61af66fc99e Initial load
duke
parents:
diff changeset
166 _preserved_oop_stack->length() == _preserved_mark_stack->length(),
a61af66fc99e Initial load
duke
parents:
diff changeset
167 "inconsistent preserved oop stacks");
a61af66fc99e Initial load
duke
parents:
diff changeset
168 if (PrintGC && Verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
169 gclog_or_tty->print_cr("Restoring %d marks", _preserved_count +
a61af66fc99e Initial load
duke
parents:
diff changeset
170 (_preserved_oop_stack ? _preserved_oop_stack->length() : 0));
a61af66fc99e Initial load
duke
parents:
diff changeset
171 }
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 // restore the marks we saved earlier
a61af66fc99e Initial load
duke
parents:
diff changeset
174 for (size_t i = 0; i < _preserved_count; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
175 _preserved_marks[i].restore();
a61af66fc99e Initial load
duke
parents:
diff changeset
176 }
a61af66fc99e Initial load
duke
parents:
diff changeset
177
a61af66fc99e Initial load
duke
parents:
diff changeset
178 // deal with the overflow
a61af66fc99e Initial load
duke
parents:
diff changeset
179 if (_preserved_oop_stack) {
a61af66fc99e Initial load
duke
parents:
diff changeset
180 for (int i = 0; i < _preserved_oop_stack->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
181 oop obj = _preserved_oop_stack->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
182 markOop mark = _preserved_mark_stack->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
183 obj->set_mark(mark);
a61af66fc99e Initial load
duke
parents:
diff changeset
184 }
a61af66fc99e Initial load
duke
parents:
diff changeset
185 }
a61af66fc99e Initial load
duke
parents:
diff changeset
186 }
a61af66fc99e Initial load
duke
parents:
diff changeset
187
a61af66fc99e Initial load
duke
parents:
diff changeset
188 #ifdef VALIDATE_MARK_SWEEP
a61af66fc99e Initial load
duke
parents:
diff changeset
189
a61af66fc99e Initial load
duke
parents:
diff changeset
190 void MarkSweep::track_adjusted_pointer(oop* p, oop newobj, bool isroot) {
a61af66fc99e Initial load
duke
parents:
diff changeset
191 if (!ValidateMarkSweep)
a61af66fc99e Initial load
duke
parents:
diff changeset
192 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
193
a61af66fc99e Initial load
duke
parents:
diff changeset
194 if (!isroot) {
a61af66fc99e Initial load
duke
parents:
diff changeset
195 if (_pointer_tracking) {
a61af66fc99e Initial load
duke
parents:
diff changeset
196 guarantee(_adjusted_pointers->contains(p), "should have seen this pointer");
a61af66fc99e Initial load
duke
parents:
diff changeset
197 _adjusted_pointers->remove(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
198 }
a61af66fc99e Initial load
duke
parents:
diff changeset
199 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
200 ptrdiff_t index = _root_refs_stack->find(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
201 if (index != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
202 int l = _root_refs_stack->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
203 if (l > 0 && l - 1 != index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
204 oop* last = _root_refs_stack->pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
205 assert(last != p, "should be different");
a61af66fc99e Initial load
duke
parents:
diff changeset
206 _root_refs_stack->at_put(index, last);
a61af66fc99e Initial load
duke
parents:
diff changeset
207 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
208 _root_refs_stack->remove(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
209 }
a61af66fc99e Initial load
duke
parents:
diff changeset
210 }
a61af66fc99e Initial load
duke
parents:
diff changeset
211 }
a61af66fc99e Initial load
duke
parents:
diff changeset
212 }
a61af66fc99e Initial load
duke
parents:
diff changeset
213
a61af66fc99e Initial load
duke
parents:
diff changeset
214
a61af66fc99e Initial load
duke
parents:
diff changeset
215 void MarkSweep::check_adjust_pointer(oop* p) {
a61af66fc99e Initial load
duke
parents:
diff changeset
216 _adjusted_pointers->push(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
217 }
a61af66fc99e Initial load
duke
parents:
diff changeset
218
a61af66fc99e Initial load
duke
parents:
diff changeset
219
a61af66fc99e Initial load
duke
parents:
diff changeset
220 class AdjusterTracker: public OopClosure {
a61af66fc99e Initial load
duke
parents:
diff changeset
221 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
222 AdjusterTracker() {};
a61af66fc99e Initial load
duke
parents:
diff changeset
223 void do_oop(oop* o) { MarkSweep::check_adjust_pointer(o); }
a61af66fc99e Initial load
duke
parents:
diff changeset
224 };
a61af66fc99e Initial load
duke
parents:
diff changeset
225
a61af66fc99e Initial load
duke
parents:
diff changeset
226
a61af66fc99e Initial load
duke
parents:
diff changeset
227 void MarkSweep::track_interior_pointers(oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
228 if (ValidateMarkSweep) {
a61af66fc99e Initial load
duke
parents:
diff changeset
229 _adjusted_pointers->clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
230 _pointer_tracking = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
231
a61af66fc99e Initial load
duke
parents:
diff changeset
232 AdjusterTracker checker;
a61af66fc99e Initial load
duke
parents:
diff changeset
233 obj->oop_iterate(&checker);
a61af66fc99e Initial load
duke
parents:
diff changeset
234 }
a61af66fc99e Initial load
duke
parents:
diff changeset
235 }
a61af66fc99e Initial load
duke
parents:
diff changeset
236
a61af66fc99e Initial load
duke
parents:
diff changeset
237
a61af66fc99e Initial load
duke
parents:
diff changeset
238 void MarkSweep::check_interior_pointers() {
a61af66fc99e Initial load
duke
parents:
diff changeset
239 if (ValidateMarkSweep) {
a61af66fc99e Initial load
duke
parents:
diff changeset
240 _pointer_tracking = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
241 guarantee(_adjusted_pointers->length() == 0, "should have processed the same pointers");
a61af66fc99e Initial load
duke
parents:
diff changeset
242 }
a61af66fc99e Initial load
duke
parents:
diff changeset
243 }
a61af66fc99e Initial load
duke
parents:
diff changeset
244
a61af66fc99e Initial load
duke
parents:
diff changeset
245
a61af66fc99e Initial load
duke
parents:
diff changeset
246 void MarkSweep::reset_live_oop_tracking(bool at_perm) {
a61af66fc99e Initial load
duke
parents:
diff changeset
247 if (ValidateMarkSweep) {
a61af66fc99e Initial load
duke
parents:
diff changeset
248 guarantee((size_t)_live_oops->length() == _live_oops_index, "should be at end of live oops");
a61af66fc99e Initial load
duke
parents:
diff changeset
249 _live_oops_index = at_perm ? _live_oops_index_at_perm : 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
250 }
a61af66fc99e Initial load
duke
parents:
diff changeset
251 }
a61af66fc99e Initial load
duke
parents:
diff changeset
252
a61af66fc99e Initial load
duke
parents:
diff changeset
253
a61af66fc99e Initial load
duke
parents:
diff changeset
254 void MarkSweep::register_live_oop(oop p, size_t size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
255 if (ValidateMarkSweep) {
a61af66fc99e Initial load
duke
parents:
diff changeset
256 _live_oops->push(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
257 _live_oops_size->push(size);
a61af66fc99e Initial load
duke
parents:
diff changeset
258 _live_oops_index++;
a61af66fc99e Initial load
duke
parents:
diff changeset
259 }
a61af66fc99e Initial load
duke
parents:
diff changeset
260 }
a61af66fc99e Initial load
duke
parents:
diff changeset
261
a61af66fc99e Initial load
duke
parents:
diff changeset
262 void MarkSweep::validate_live_oop(oop p, size_t size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
263 if (ValidateMarkSweep) {
a61af66fc99e Initial load
duke
parents:
diff changeset
264 oop obj = _live_oops->at((int)_live_oops_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
265 guarantee(obj == p, "should be the same object");
a61af66fc99e Initial load
duke
parents:
diff changeset
266 guarantee(_live_oops_size->at((int)_live_oops_index) == size, "should be the same size");
a61af66fc99e Initial load
duke
parents:
diff changeset
267 _live_oops_index++;
a61af66fc99e Initial load
duke
parents:
diff changeset
268 }
a61af66fc99e Initial load
duke
parents:
diff changeset
269 }
a61af66fc99e Initial load
duke
parents:
diff changeset
270
a61af66fc99e Initial load
duke
parents:
diff changeset
271 void MarkSweep::live_oop_moved_to(HeapWord* q, size_t size,
a61af66fc99e Initial load
duke
parents:
diff changeset
272 HeapWord* compaction_top) {
a61af66fc99e Initial load
duke
parents:
diff changeset
273 assert(oop(q)->forwardee() == NULL || oop(q)->forwardee() == oop(compaction_top),
a61af66fc99e Initial load
duke
parents:
diff changeset
274 "should be moved to forwarded location");
a61af66fc99e Initial load
duke
parents:
diff changeset
275 if (ValidateMarkSweep) {
a61af66fc99e Initial load
duke
parents:
diff changeset
276 MarkSweep::validate_live_oop(oop(q), size);
a61af66fc99e Initial load
duke
parents:
diff changeset
277 _live_oops_moved_to->push(oop(compaction_top));
a61af66fc99e Initial load
duke
parents:
diff changeset
278 }
a61af66fc99e Initial load
duke
parents:
diff changeset
279 if (RecordMarkSweepCompaction) {
a61af66fc99e Initial load
duke
parents:
diff changeset
280 _cur_gc_live_oops->push(q);
a61af66fc99e Initial load
duke
parents:
diff changeset
281 _cur_gc_live_oops_moved_to->push(compaction_top);
a61af66fc99e Initial load
duke
parents:
diff changeset
282 _cur_gc_live_oops_size->push(size);
a61af66fc99e Initial load
duke
parents:
diff changeset
283 }
a61af66fc99e Initial load
duke
parents:
diff changeset
284 }
a61af66fc99e Initial load
duke
parents:
diff changeset
285
a61af66fc99e Initial load
duke
parents:
diff changeset
286
a61af66fc99e Initial load
duke
parents:
diff changeset
287 void MarkSweep::compaction_complete() {
a61af66fc99e Initial load
duke
parents:
diff changeset
288 if (RecordMarkSweepCompaction) {
a61af66fc99e Initial load
duke
parents:
diff changeset
289 GrowableArray<HeapWord*>* _tmp_live_oops = _cur_gc_live_oops;
a61af66fc99e Initial load
duke
parents:
diff changeset
290 GrowableArray<HeapWord*>* _tmp_live_oops_moved_to = _cur_gc_live_oops_moved_to;
a61af66fc99e Initial load
duke
parents:
diff changeset
291 GrowableArray<size_t> * _tmp_live_oops_size = _cur_gc_live_oops_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
292
a61af66fc99e Initial load
duke
parents:
diff changeset
293 _cur_gc_live_oops = _last_gc_live_oops;
a61af66fc99e Initial load
duke
parents:
diff changeset
294 _cur_gc_live_oops_moved_to = _last_gc_live_oops_moved_to;
a61af66fc99e Initial load
duke
parents:
diff changeset
295 _cur_gc_live_oops_size = _last_gc_live_oops_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
296 _last_gc_live_oops = _tmp_live_oops;
a61af66fc99e Initial load
duke
parents:
diff changeset
297 _last_gc_live_oops_moved_to = _tmp_live_oops_moved_to;
a61af66fc99e Initial load
duke
parents:
diff changeset
298 _last_gc_live_oops_size = _tmp_live_oops_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
299 }
a61af66fc99e Initial load
duke
parents:
diff changeset
300 }
a61af66fc99e Initial load
duke
parents:
diff changeset
301
a61af66fc99e Initial load
duke
parents:
diff changeset
302
a61af66fc99e Initial load
duke
parents:
diff changeset
303 void MarkSweep::print_new_location_of_heap_address(HeapWord* q) {
a61af66fc99e Initial load
duke
parents:
diff changeset
304 if (!RecordMarkSweepCompaction) {
a61af66fc99e Initial load
duke
parents:
diff changeset
305 tty->print_cr("Requires RecordMarkSweepCompaction to be enabled");
a61af66fc99e Initial load
duke
parents:
diff changeset
306 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
307 }
a61af66fc99e Initial load
duke
parents:
diff changeset
308
a61af66fc99e Initial load
duke
parents:
diff changeset
309 if (_last_gc_live_oops == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
310 tty->print_cr("No compaction information gathered yet");
a61af66fc99e Initial load
duke
parents:
diff changeset
311 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
312 }
a61af66fc99e Initial load
duke
parents:
diff changeset
313
a61af66fc99e Initial load
duke
parents:
diff changeset
314 for (int i = 0; i < _last_gc_live_oops->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
315 HeapWord* old_oop = _last_gc_live_oops->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
316 size_t sz = _last_gc_live_oops_size->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
317 if (old_oop <= q && q < (old_oop + sz)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
318 HeapWord* new_oop = _last_gc_live_oops_moved_to->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
319 size_t offset = (q - old_oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
320 tty->print_cr("Address " PTR_FORMAT, q);
a61af66fc99e Initial load
duke
parents:
diff changeset
321 tty->print_cr(" Was in oop " PTR_FORMAT ", size %d, at offset %d", old_oop, sz, offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
322 tty->print_cr(" Now in oop " PTR_FORMAT ", actual address " PTR_FORMAT, new_oop, new_oop + offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
323 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
324 }
a61af66fc99e Initial load
duke
parents:
diff changeset
325 }
a61af66fc99e Initial load
duke
parents:
diff changeset
326
a61af66fc99e Initial load
duke
parents:
diff changeset
327 tty->print_cr("Address " PTR_FORMAT " not found in live oop information from last GC", q);
a61af66fc99e Initial load
duke
parents:
diff changeset
328 }
a61af66fc99e Initial load
duke
parents:
diff changeset
329 #endif //VALIDATE_MARK_SWEEP
a61af66fc99e Initial load
duke
parents:
diff changeset
330
a61af66fc99e Initial load
duke
parents:
diff changeset
331 MarkSweep::IsAliveClosure MarkSweep::is_alive;
a61af66fc99e Initial load
duke
parents:
diff changeset
332
a61af66fc99e Initial load
duke
parents:
diff changeset
333 void MarkSweep::KeepAliveClosure::do_oop(oop* p) {
a61af66fc99e Initial load
duke
parents:
diff changeset
334 #ifdef VALIDATE_MARK_SWEEP
a61af66fc99e Initial load
duke
parents:
diff changeset
335 if (ValidateMarkSweep) {
a61af66fc99e Initial load
duke
parents:
diff changeset
336 if (!Universe::heap()->is_in_reserved(p)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
337 _root_refs_stack->push(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
338 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
339 _other_refs_stack->push(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
340 }
a61af66fc99e Initial load
duke
parents:
diff changeset
341 }
a61af66fc99e Initial load
duke
parents:
diff changeset
342 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
343 mark_and_push(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
344 }
a61af66fc99e Initial load
duke
parents:
diff changeset
345
a61af66fc99e Initial load
duke
parents:
diff changeset
346 MarkSweep::KeepAliveClosure MarkSweep::keep_alive;
a61af66fc99e Initial load
duke
parents:
diff changeset
347
a61af66fc99e Initial load
duke
parents:
diff changeset
348 void marksweep_init() { /* empty */ }
a61af66fc99e Initial load
duke
parents:
diff changeset
349
a61af66fc99e Initial load
duke
parents:
diff changeset
350 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
351
a61af66fc99e Initial load
duke
parents:
diff changeset
352 void MarkSweep::trace(const char* msg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
353 if (TraceMarkSweep)
a61af66fc99e Initial load
duke
parents:
diff changeset
354 gclog_or_tty->print("%s", msg);
a61af66fc99e Initial load
duke
parents:
diff changeset
355 }
a61af66fc99e Initial load
duke
parents:
diff changeset
356
a61af66fc99e Initial load
duke
parents:
diff changeset
357 #endif