author | trims |
Fri, 09 Oct 2009 15:18:52 -0700 | |
changeset 3919 | b15d85d98b61 |
parent 3829 | 4903de895f0c |
parent 3916 | 9acd7f9d4f52 |
child 5076 | 8b74a4b60b31 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
3795 | 2 |
* Copyright 1997-2009 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 |
#include "incls/_precompiled.incl" |
|
26 |
#include "incls/_markSweep.cpp.incl" |
|
27 |
||
28 |
GrowableArray<oop>* MarkSweep::_marking_stack = NULL; |
|
29 |
GrowableArray<Klass*>* MarkSweep::_revisit_klass_stack = NULL; |
|
3696 | 30 |
GrowableArray<DataLayout*>* MarkSweep::_revisit_mdo_stack = NULL; |
1 | 31 |
|
32 |
GrowableArray<oop>* MarkSweep::_preserved_oop_stack = NULL; |
|
33 |
GrowableArray<markOop>* MarkSweep::_preserved_mark_stack= NULL; |
|
34 |
size_t MarkSweep::_preserved_count = 0; |
|
35 |
size_t MarkSweep::_preserved_count_max = 0; |
|
36 |
PreservedMark* MarkSweep::_preserved_marks = NULL; |
|
37 |
ReferenceProcessor* MarkSweep::_ref_processor = NULL; |
|
38 |
||
39 |
#ifdef VALIDATE_MARK_SWEEP |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
40 |
GrowableArray<void*>* MarkSweep::_root_refs_stack = NULL; |
1 | 41 |
GrowableArray<oop> * MarkSweep::_live_oops = NULL; |
42 |
GrowableArray<oop> * MarkSweep::_live_oops_moved_to = NULL; |
|
43 |
GrowableArray<size_t>* MarkSweep::_live_oops_size = NULL; |
|
44 |
size_t MarkSweep::_live_oops_index = 0; |
|
45 |
size_t MarkSweep::_live_oops_index_at_perm = 0; |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
46 |
GrowableArray<void*>* MarkSweep::_other_refs_stack = NULL; |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
47 |
GrowableArray<void*>* MarkSweep::_adjusted_pointers = NULL; |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
48 |
bool MarkSweep::_pointer_tracking = false; |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
49 |
bool MarkSweep::_root_tracking = true; |
1 | 50 |
|
51 |
GrowableArray<HeapWord*>* MarkSweep::_cur_gc_live_oops = NULL; |
|
52 |
GrowableArray<HeapWord*>* MarkSweep::_cur_gc_live_oops_moved_to = NULL; |
|
53 |
GrowableArray<size_t> * MarkSweep::_cur_gc_live_oops_size = NULL; |
|
54 |
GrowableArray<HeapWord*>* MarkSweep::_last_gc_live_oops = NULL; |
|
55 |
GrowableArray<HeapWord*>* MarkSweep::_last_gc_live_oops_moved_to = NULL; |
|
56 |
GrowableArray<size_t> * MarkSweep::_last_gc_live_oops_size = NULL; |
|
57 |
#endif |
|
58 |
||
59 |
void MarkSweep::revisit_weak_klass_link(Klass* k) { |
|
60 |
_revisit_klass_stack->push(k); |
|
61 |
} |
|
62 |
||
63 |
void MarkSweep::follow_weak_klass_links() { |
|
64 |
// All klasses on the revisit stack are marked at this point. |
|
65 |
// Update and follow all subklass, sibling and implementor links. |
|
3696 | 66 |
if (PrintRevisitStats) { |
67 |
gclog_or_tty->print_cr("#classes in system dictionary = %d", SystemDictionary::number_of_classes()); |
|
68 |
gclog_or_tty->print_cr("Revisit klass stack length = %d", _revisit_klass_stack->length()); |
|
69 |
} |
|
1 | 70 |
for (int i = 0; i < _revisit_klass_stack->length(); i++) { |
71 |
_revisit_klass_stack->at(i)->follow_weak_klass_links(&is_alive,&keep_alive); |
|
72 |
} |
|
73 |
follow_stack(); |
|
74 |
} |
|
75 |
||
3696 | 76 |
void MarkSweep::revisit_mdo(DataLayout* p) { |
77 |
_revisit_mdo_stack->push(p); |
|
78 |
} |
|
79 |
||
80 |
void MarkSweep::follow_mdo_weak_refs() { |
|
81 |
// All strongly reachable oops have been marked at this point; |
|
82 |
// we can visit and clear any weak references from MDO's which |
|
83 |
// we memoized during the strong marking phase. |
|
84 |
assert(_marking_stack->is_empty(), "Marking stack should be empty"); |
|
85 |
if (PrintRevisitStats) { |
|
86 |
gclog_or_tty->print_cr("#classes in system dictionary = %d", SystemDictionary::number_of_classes()); |
|
87 |
gclog_or_tty->print_cr("Revisit MDO stack length = %d", _revisit_mdo_stack->length()); |
|
88 |
} |
|
89 |
for (int i = 0; i < _revisit_mdo_stack->length(); i++) { |
|
90 |
_revisit_mdo_stack->at(i)->follow_weak_refs(&is_alive); |
|
91 |
} |
|
92 |
follow_stack(); |
|
93 |
} |
|
94 |
||
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
95 |
MarkSweep::FollowRootClosure MarkSweep::follow_root_closure; |
3908
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
670
diff
changeset
|
96 |
CodeBlobToOopClosure MarkSweep::follow_code_root_closure(&MarkSweep::follow_root_closure, /*do_marking=*/ true); |
1 | 97 |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
98 |
void MarkSweep::FollowRootClosure::do_oop(oop* p) { follow_root(p); } |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
99 |
void MarkSweep::FollowRootClosure::do_oop(narrowOop* p) { follow_root(p); } |
1 | 100 |
|
101 |
MarkSweep::MarkAndPushClosure MarkSweep::mark_and_push_closure; |
|
102 |
||
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
103 |
void MarkSweep::MarkAndPushClosure::do_oop(oop* p) { mark_and_push(p); } |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
104 |
void MarkSweep::MarkAndPushClosure::do_oop(narrowOop* p) { mark_and_push(p); } |
1 | 105 |
|
106 |
void MarkSweep::follow_stack() { |
|
107 |
while (!_marking_stack->is_empty()) { |
|
108 |
oop obj = _marking_stack->pop(); |
|
109 |
assert (obj->is_gc_marked(), "p must be marked"); |
|
110 |
obj->follow_contents(); |
|
111 |
} |
|
112 |
} |
|
113 |
||
114 |
MarkSweep::FollowStackClosure MarkSweep::follow_stack_closure; |
|
115 |
||
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
116 |
void MarkSweep::FollowStackClosure::do_void() { follow_stack(); } |
1 | 117 |
|
118 |
// We preserve the mark which should be replaced at the end and the location that it |
|
119 |
// will go. Note that the object that this markOop belongs to isn't currently at that |
|
120 |
// address but it will be after phase4 |
|
121 |
void MarkSweep::preserve_mark(oop obj, markOop mark) { |
|
122 |
// we try to store preserved marks in the to space of the new generation since this |
|
123 |
// is storage which should be available. Most of the time this should be sufficient |
|
124 |
// space for the marks we need to preserve but if it isn't we fall back in using |
|
125 |
// GrowableArrays to keep track of the overflow. |
|
126 |
if (_preserved_count < _preserved_count_max) { |
|
127 |
_preserved_marks[_preserved_count++].init(obj, mark); |
|
128 |
} else { |
|
129 |
if (_preserved_mark_stack == NULL) { |
|
130 |
_preserved_mark_stack = new (ResourceObj::C_HEAP) GrowableArray<markOop>(40, true); |
|
131 |
_preserved_oop_stack = new (ResourceObj::C_HEAP) GrowableArray<oop>(40, true); |
|
132 |
} |
|
133 |
_preserved_mark_stack->push(mark); |
|
134 |
_preserved_oop_stack->push(obj); |
|
135 |
} |
|
136 |
} |
|
137 |
||
138 |
MarkSweep::AdjustPointerClosure MarkSweep::adjust_root_pointer_closure(true); |
|
139 |
MarkSweep::AdjustPointerClosure MarkSweep::adjust_pointer_closure(false); |
|
140 |
||
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
141 |
void MarkSweep::AdjustPointerClosure::do_oop(oop* p) { adjust_pointer(p, _is_root); } |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
142 |
void MarkSweep::AdjustPointerClosure::do_oop(narrowOop* p) { adjust_pointer(p, _is_root); } |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
143 |
|
1 | 144 |
void MarkSweep::adjust_marks() { |
145 |
assert(_preserved_oop_stack == NULL || |
|
146 |
_preserved_oop_stack->length() == _preserved_mark_stack->length(), |
|
147 |
"inconsistent preserved oop stacks"); |
|
148 |
||
149 |
// adjust the oops we saved earlier |
|
150 |
for (size_t i = 0; i < _preserved_count; i++) { |
|
151 |
_preserved_marks[i].adjust_pointer(); |
|
152 |
} |
|
153 |
||
154 |
// deal with the overflow stack |
|
155 |
if (_preserved_oop_stack) { |
|
156 |
for (int i = 0; i < _preserved_oop_stack->length(); i++) { |
|
157 |
oop* p = _preserved_oop_stack->adr_at(i); |
|
158 |
adjust_pointer(p); |
|
159 |
} |
|
160 |
} |
|
161 |
} |
|
162 |
||
163 |
void MarkSweep::restore_marks() { |
|
164 |
assert(_preserved_oop_stack == NULL || |
|
165 |
_preserved_oop_stack->length() == _preserved_mark_stack->length(), |
|
166 |
"inconsistent preserved oop stacks"); |
|
167 |
if (PrintGC && Verbose) { |
|
168 |
gclog_or_tty->print_cr("Restoring %d marks", _preserved_count + |
|
169 |
(_preserved_oop_stack ? _preserved_oop_stack->length() : 0)); |
|
170 |
} |
|
171 |
||
172 |
// restore the marks we saved earlier |
|
173 |
for (size_t i = 0; i < _preserved_count; i++) { |
|
174 |
_preserved_marks[i].restore(); |
|
175 |
} |
|
176 |
||
177 |
// deal with the overflow |
|
178 |
if (_preserved_oop_stack) { |
|
179 |
for (int i = 0; i < _preserved_oop_stack->length(); i++) { |
|
180 |
oop obj = _preserved_oop_stack->at(i); |
|
181 |
markOop mark = _preserved_mark_stack->at(i); |
|
182 |
obj->set_mark(mark); |
|
183 |
} |
|
184 |
} |
|
185 |
} |
|
186 |
||
187 |
#ifdef VALIDATE_MARK_SWEEP |
|
188 |
||
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
189 |
void MarkSweep::track_adjusted_pointer(void* p, bool isroot) { |
1 | 190 |
if (!ValidateMarkSweep) |
191 |
return; |
|
192 |
||
193 |
if (!isroot) { |
|
194 |
if (_pointer_tracking) { |
|
195 |
guarantee(_adjusted_pointers->contains(p), "should have seen this pointer"); |
|
196 |
_adjusted_pointers->remove(p); |
|
197 |
} |
|
198 |
} else { |
|
199 |
ptrdiff_t index = _root_refs_stack->find(p); |
|
200 |
if (index != -1) { |
|
201 |
int l = _root_refs_stack->length(); |
|
202 |
if (l > 0 && l - 1 != index) { |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
203 |
void* last = _root_refs_stack->pop(); |
1 | 204 |
assert(last != p, "should be different"); |
205 |
_root_refs_stack->at_put(index, last); |
|
206 |
} else { |
|
207 |
_root_refs_stack->remove(p); |
|
208 |
} |
|
209 |
} |
|
210 |
} |
|
211 |
} |
|
212 |
||
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
213 |
void MarkSweep::check_adjust_pointer(void* p) { |
1 | 214 |
_adjusted_pointers->push(p); |
215 |
} |
|
216 |
||
217 |
class AdjusterTracker: public OopClosure { |
|
218 |
public: |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
219 |
AdjusterTracker() {} |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
220 |
void do_oop(oop* o) { MarkSweep::check_adjust_pointer(o); } |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
221 |
void do_oop(narrowOop* o) { MarkSweep::check_adjust_pointer(o); } |
1 | 222 |
}; |
223 |
||
224 |
void MarkSweep::track_interior_pointers(oop obj) { |
|
225 |
if (ValidateMarkSweep) { |
|
226 |
_adjusted_pointers->clear(); |
|
227 |
_pointer_tracking = true; |
|
228 |
||
229 |
AdjusterTracker checker; |
|
230 |
obj->oop_iterate(&checker); |
|
231 |
} |
|
232 |
} |
|
233 |
||
234 |
void MarkSweep::check_interior_pointers() { |
|
235 |
if (ValidateMarkSweep) { |
|
236 |
_pointer_tracking = false; |
|
237 |
guarantee(_adjusted_pointers->length() == 0, "should have processed the same pointers"); |
|
238 |
} |
|
239 |
} |
|
240 |
||
241 |
void MarkSweep::reset_live_oop_tracking(bool at_perm) { |
|
242 |
if (ValidateMarkSweep) { |
|
243 |
guarantee((size_t)_live_oops->length() == _live_oops_index, "should be at end of live oops"); |
|
244 |
_live_oops_index = at_perm ? _live_oops_index_at_perm : 0; |
|
245 |
} |
|
246 |
} |
|
247 |
||
248 |
void MarkSweep::register_live_oop(oop p, size_t size) { |
|
249 |
if (ValidateMarkSweep) { |
|
250 |
_live_oops->push(p); |
|
251 |
_live_oops_size->push(size); |
|
252 |
_live_oops_index++; |
|
253 |
} |
|
254 |
} |
|
255 |
||
256 |
void MarkSweep::validate_live_oop(oop p, size_t size) { |
|
257 |
if (ValidateMarkSweep) { |
|
258 |
oop obj = _live_oops->at((int)_live_oops_index); |
|
259 |
guarantee(obj == p, "should be the same object"); |
|
260 |
guarantee(_live_oops_size->at((int)_live_oops_index) == size, "should be the same size"); |
|
261 |
_live_oops_index++; |
|
262 |
} |
|
263 |
} |
|
264 |
||
265 |
void MarkSweep::live_oop_moved_to(HeapWord* q, size_t size, |
|
266 |
HeapWord* compaction_top) { |
|
267 |
assert(oop(q)->forwardee() == NULL || oop(q)->forwardee() == oop(compaction_top), |
|
268 |
"should be moved to forwarded location"); |
|
269 |
if (ValidateMarkSweep) { |
|
270 |
MarkSweep::validate_live_oop(oop(q), size); |
|
271 |
_live_oops_moved_to->push(oop(compaction_top)); |
|
272 |
} |
|
273 |
if (RecordMarkSweepCompaction) { |
|
274 |
_cur_gc_live_oops->push(q); |
|
275 |
_cur_gc_live_oops_moved_to->push(compaction_top); |
|
276 |
_cur_gc_live_oops_size->push(size); |
|
277 |
} |
|
278 |
} |
|
279 |
||
280 |
void MarkSweep::compaction_complete() { |
|
281 |
if (RecordMarkSweepCompaction) { |
|
282 |
GrowableArray<HeapWord*>* _tmp_live_oops = _cur_gc_live_oops; |
|
283 |
GrowableArray<HeapWord*>* _tmp_live_oops_moved_to = _cur_gc_live_oops_moved_to; |
|
284 |
GrowableArray<size_t> * _tmp_live_oops_size = _cur_gc_live_oops_size; |
|
285 |
||
286 |
_cur_gc_live_oops = _last_gc_live_oops; |
|
287 |
_cur_gc_live_oops_moved_to = _last_gc_live_oops_moved_to; |
|
288 |
_cur_gc_live_oops_size = _last_gc_live_oops_size; |
|
289 |
_last_gc_live_oops = _tmp_live_oops; |
|
290 |
_last_gc_live_oops_moved_to = _tmp_live_oops_moved_to; |
|
291 |
_last_gc_live_oops_size = _tmp_live_oops_size; |
|
292 |
} |
|
293 |
} |
|
294 |
||
295 |
void MarkSweep::print_new_location_of_heap_address(HeapWord* q) { |
|
296 |
if (!RecordMarkSweepCompaction) { |
|
297 |
tty->print_cr("Requires RecordMarkSweepCompaction to be enabled"); |
|
298 |
return; |
|
299 |
} |
|
300 |
||
301 |
if (_last_gc_live_oops == NULL) { |
|
302 |
tty->print_cr("No compaction information gathered yet"); |
|
303 |
return; |
|
304 |
} |
|
305 |
||
306 |
for (int i = 0; i < _last_gc_live_oops->length(); i++) { |
|
307 |
HeapWord* old_oop = _last_gc_live_oops->at(i); |
|
308 |
size_t sz = _last_gc_live_oops_size->at(i); |
|
309 |
if (old_oop <= q && q < (old_oop + sz)) { |
|
310 |
HeapWord* new_oop = _last_gc_live_oops_moved_to->at(i); |
|
311 |
size_t offset = (q - old_oop); |
|
312 |
tty->print_cr("Address " PTR_FORMAT, q); |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
313 |
tty->print_cr(" Was in oop " PTR_FORMAT ", size " SIZE_FORMAT ", at offset " SIZE_FORMAT, old_oop, sz, offset); |
1 | 314 |
tty->print_cr(" Now in oop " PTR_FORMAT ", actual address " PTR_FORMAT, new_oop, new_oop + offset); |
315 |
return; |
|
316 |
} |
|
317 |
} |
|
318 |
||
319 |
tty->print_cr("Address " PTR_FORMAT " not found in live oop information from last GC", q); |
|
320 |
} |
|
321 |
#endif //VALIDATE_MARK_SWEEP |
|
322 |
||
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
323 |
MarkSweep::IsAliveClosure MarkSweep::is_alive; |
1 | 324 |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
325 |
void MarkSweep::IsAliveClosure::do_object(oop p) { ShouldNotReachHere(); } |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
326 |
bool MarkSweep::IsAliveClosure::do_object_b(oop p) { return p->is_gc_marked(); } |
1 | 327 |
|
328 |
MarkSweep::KeepAliveClosure MarkSweep::keep_alive; |
|
329 |
||
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
330 |
void MarkSweep::KeepAliveClosure::do_oop(oop* p) { MarkSweep::KeepAliveClosure::do_oop_work(p); } |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
331 |
void MarkSweep::KeepAliveClosure::do_oop(narrowOop* p) { MarkSweep::KeepAliveClosure::do_oop_work(p); } |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
332 |
|
1 | 333 |
void marksweep_init() { /* empty */ } |
334 |
||
335 |
#ifndef PRODUCT |
|
336 |
||
337 |
void MarkSweep::trace(const char* msg) { |
|
338 |
if (TraceMarkSweep) |
|
339 |
gclog_or_tty->print("%s", msg); |
|
340 |
} |
|
341 |
||
342 |
#endif |