annotate src/share/vm/gc_implementation/shared/markSweep.cpp @ 1941:79d04223b8a5

Added caching for resolved types and resolved fields. This is crucial, because the local load elimination will lead to wrong results, if field equality (of two RiField objects with the same object and the same RiType) is not given. The caching makes sure that the default equals implementation is sufficient.
author Thomas Wuerthinger <wuerthinger@ssw.jku.at>
date Tue, 28 Dec 2010 18:33:26 +0100
parents 894b1d7c7e01
children f95d63e2154a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1315
diff changeset
2 * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved.
0
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 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1315
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1315
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1315
diff changeset
21 * questions.
0
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
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
28 Stack<oop> MarkSweep::_marking_stack;
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
29 Stack<DataLayout*> MarkSweep::_revisit_mdo_stack;
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
30 Stack<Klass*> MarkSweep::_revisit_klass_stack;
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
31 Stack<ObjArrayTask> MarkSweep::_objarray_stack;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
32
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
33 Stack<oop> MarkSweep::_preserved_oop_stack;
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
34 Stack<markOop> MarkSweep::_preserved_mark_stack;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
35 size_t MarkSweep::_preserved_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 size_t MarkSweep::_preserved_count_max = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 PreservedMark* MarkSweep::_preserved_marks = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 ReferenceProcessor* MarkSweep::_ref_processor = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 #ifdef VALIDATE_MARK_SWEEP
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
41 GrowableArray<void*>* MarkSweep::_root_refs_stack = NULL;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
42 GrowableArray<oop> * MarkSweep::_live_oops = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 GrowableArray<oop> * MarkSweep::_live_oops_moved_to = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 GrowableArray<size_t>* MarkSweep::_live_oops_size = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 size_t MarkSweep::_live_oops_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 size_t MarkSweep::_live_oops_index_at_perm = 0;
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
47 GrowableArray<void*>* MarkSweep::_other_refs_stack = NULL;
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
48 GrowableArray<void*>* MarkSweep::_adjusted_pointers = NULL;
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
49 bool MarkSweep::_pointer_tracking = false;
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
50 bool MarkSweep::_root_tracking = true;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 GrowableArray<HeapWord*>* MarkSweep::_cur_gc_live_oops = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
53 GrowableArray<HeapWord*>* MarkSweep::_cur_gc_live_oops_moved_to = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
54 GrowableArray<size_t> * MarkSweep::_cur_gc_live_oops_size = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 GrowableArray<HeapWord*>* MarkSweep::_last_gc_live_oops = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 GrowableArray<HeapWord*>* MarkSweep::_last_gc_live_oops_moved_to = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
57 GrowableArray<size_t> * MarkSweep::_last_gc_live_oops_size = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
58 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 void MarkSweep::revisit_weak_klass_link(Klass* k) {
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
61 _revisit_klass_stack.push(k);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
62 }
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 void MarkSweep::follow_weak_klass_links() {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 // All klasses on the revisit stack are marked at this point.
a61af66fc99e Initial load
duke
parents:
diff changeset
66 // Update and follow all subklass, sibling and implementor links.
941
8b46c4d82093 4957990: Perm heap bloat in JVM
ysr
parents: 196
diff changeset
67 if (PrintRevisitStats) {
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
68 gclog_or_tty->print_cr("#classes in system dictionary = %d",
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
69 SystemDictionary::number_of_classes());
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
70 gclog_or_tty->print_cr("Revisit klass stack size = " SIZE_FORMAT,
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
71 _revisit_klass_stack.size());
941
8b46c4d82093 4957990: Perm heap bloat in JVM
ysr
parents: 196
diff changeset
72 }
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
73 while (!_revisit_klass_stack.is_empty()) {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
74 Klass* const k = _revisit_klass_stack.pop();
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
75 k->follow_weak_klass_links(&is_alive, &keep_alive);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
76 }
a61af66fc99e Initial load
duke
parents:
diff changeset
77 follow_stack();
a61af66fc99e Initial load
duke
parents:
diff changeset
78 }
a61af66fc99e Initial load
duke
parents:
diff changeset
79
941
8b46c4d82093 4957990: Perm heap bloat in JVM
ysr
parents: 196
diff changeset
80 void MarkSweep::revisit_mdo(DataLayout* p) {
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
81 _revisit_mdo_stack.push(p);
941
8b46c4d82093 4957990: Perm heap bloat in JVM
ysr
parents: 196
diff changeset
82 }
8b46c4d82093 4957990: Perm heap bloat in JVM
ysr
parents: 196
diff changeset
83
8b46c4d82093 4957990: Perm heap bloat in JVM
ysr
parents: 196
diff changeset
84 void MarkSweep::follow_mdo_weak_refs() {
8b46c4d82093 4957990: Perm heap bloat in JVM
ysr
parents: 196
diff changeset
85 // All strongly reachable oops have been marked at this point;
8b46c4d82093 4957990: Perm heap bloat in JVM
ysr
parents: 196
diff changeset
86 // we can visit and clear any weak references from MDO's which
8b46c4d82093 4957990: Perm heap bloat in JVM
ysr
parents: 196
diff changeset
87 // we memoized during the strong marking phase.
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
88 assert(_marking_stack.is_empty(), "Marking stack should be empty");
941
8b46c4d82093 4957990: Perm heap bloat in JVM
ysr
parents: 196
diff changeset
89 if (PrintRevisitStats) {
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
90 gclog_or_tty->print_cr("#classes in system dictionary = %d",
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
91 SystemDictionary::number_of_classes());
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
92 gclog_or_tty->print_cr("Revisit MDO stack size = " SIZE_FORMAT,
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
93 _revisit_mdo_stack.size());
941
8b46c4d82093 4957990: Perm heap bloat in JVM
ysr
parents: 196
diff changeset
94 }
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
95 while (!_revisit_mdo_stack.is_empty()) {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
96 _revisit_mdo_stack.pop()->follow_weak_refs(&is_alive);
941
8b46c4d82093 4957990: Perm heap bloat in JVM
ysr
parents: 196
diff changeset
97 }
8b46c4d82093 4957990: Perm heap bloat in JVM
ysr
parents: 196
diff changeset
98 follow_stack();
8b46c4d82093 4957990: Perm heap bloat in JVM
ysr
parents: 196
diff changeset
99 }
8b46c4d82093 4957990: Perm heap bloat in JVM
ysr
parents: 196
diff changeset
100
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
101 MarkSweep::FollowRootClosure MarkSweep::follow_root_closure;
989
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 196
diff changeset
102 CodeBlobToOopClosure MarkSweep::follow_code_root_closure(&MarkSweep::follow_root_closure, /*do_marking=*/ true);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
103
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
104 void MarkSweep::FollowRootClosure::do_oop(oop* p) { follow_root(p); }
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
105 void MarkSweep::FollowRootClosure::do_oop(narrowOop* p) { follow_root(p); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
106
a61af66fc99e Initial load
duke
parents:
diff changeset
107 MarkSweep::MarkAndPushClosure MarkSweep::mark_and_push_closure;
a61af66fc99e Initial load
duke
parents:
diff changeset
108
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
109 void MarkSweep::MarkAndPushClosure::do_oop(oop* p) { mark_and_push(p); }
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
110 void MarkSweep::MarkAndPushClosure::do_oop(narrowOop* p) { mark_and_push(p); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
111
a61af66fc99e Initial load
duke
parents:
diff changeset
112 void MarkSweep::follow_stack() {
1311
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 1000
diff changeset
113 do {
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
114 while (!_marking_stack.is_empty()) {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
115 oop obj = _marking_stack.pop();
1311
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 1000
diff changeset
116 assert (obj->is_gc_marked(), "p must be marked");
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 1000
diff changeset
117 obj->follow_contents();
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 1000
diff changeset
118 }
1315
c385bf94cfb8 6935839: excessive marking stack growth during full gcs
jcoomes
parents: 1311
diff changeset
119 // Process ObjArrays one at a time to avoid marking stack bloat.
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
120 if (!_objarray_stack.is_empty()) {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
121 ObjArrayTask task = _objarray_stack.pop();
1311
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 1000
diff changeset
122 objArrayKlass* const k = (objArrayKlass*)task.obj()->blueprint();
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 1000
diff changeset
123 k->oop_follow_contents(task.obj(), task.index());
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 1000
diff changeset
124 }
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
125 } while (!_marking_stack.is_empty() || !_objarray_stack.is_empty());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
126 }
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128 MarkSweep::FollowStackClosure MarkSweep::follow_stack_closure;
a61af66fc99e Initial load
duke
parents:
diff changeset
129
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
130 void MarkSweep::FollowStackClosure::do_void() { follow_stack(); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
131
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
132 // We preserve the mark which should be replaced at the end and the location
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
133 // that it will go. Note that the object that this markOop belongs to isn't
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
134 // currently at that address but it will be after phase4
0
a61af66fc99e Initial load
duke
parents:
diff changeset
135 void MarkSweep::preserve_mark(oop obj, markOop mark) {
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
136 // We try to store preserved marks in the to space of the new generation since
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
137 // this is storage which should be available. Most of the time this should be
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
138 // sufficient space for the marks we need to preserve but if it isn't we fall
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
139 // back to using Stacks to keep track of the overflow.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
140 if (_preserved_count < _preserved_count_max) {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 _preserved_marks[_preserved_count++].init(obj, mark);
a61af66fc99e Initial load
duke
parents:
diff changeset
142 } else {
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
143 _preserved_mark_stack.push(mark);
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
144 _preserved_oop_stack.push(obj);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
145 }
a61af66fc99e Initial load
duke
parents:
diff changeset
146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
147
a61af66fc99e Initial load
duke
parents:
diff changeset
148 MarkSweep::AdjustPointerClosure MarkSweep::adjust_root_pointer_closure(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
149 MarkSweep::AdjustPointerClosure MarkSweep::adjust_pointer_closure(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
150
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
151 void MarkSweep::AdjustPointerClosure::do_oop(oop* p) { adjust_pointer(p, _is_root); }
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
152 void MarkSweep::AdjustPointerClosure::do_oop(narrowOop* p) { adjust_pointer(p, _is_root); }
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
153
0
a61af66fc99e Initial load
duke
parents:
diff changeset
154 void MarkSweep::adjust_marks() {
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
155 assert( _preserved_oop_stack.size() == _preserved_mark_stack.size(),
0
a61af66fc99e Initial load
duke
parents:
diff changeset
156 "inconsistent preserved oop stacks");
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158 // adjust the oops we saved earlier
a61af66fc99e Initial load
duke
parents:
diff changeset
159 for (size_t i = 0; i < _preserved_count; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
160 _preserved_marks[i].adjust_pointer();
a61af66fc99e Initial load
duke
parents:
diff changeset
161 }
a61af66fc99e Initial load
duke
parents:
diff changeset
162
a61af66fc99e Initial load
duke
parents:
diff changeset
163 // deal with the overflow stack
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
164 StackIterator<oop> iter(_preserved_oop_stack);
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
165 while (!iter.is_empty()) {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
166 oop* p = iter.next_addr();
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
167 adjust_pointer(p);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
168 }
a61af66fc99e Initial load
duke
parents:
diff changeset
169 }
a61af66fc99e Initial load
duke
parents:
diff changeset
170
a61af66fc99e Initial load
duke
parents:
diff changeset
171 void MarkSweep::restore_marks() {
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
172 assert(_preserved_oop_stack.size() == _preserved_mark_stack.size(),
0
a61af66fc99e Initial load
duke
parents:
diff changeset
173 "inconsistent preserved oop stacks");
a61af66fc99e Initial load
duke
parents:
diff changeset
174 if (PrintGC && Verbose) {
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
175 gclog_or_tty->print_cr("Restoring %d marks",
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
176 _preserved_count + _preserved_oop_stack.size());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
177 }
a61af66fc99e Initial load
duke
parents:
diff changeset
178
a61af66fc99e Initial load
duke
parents:
diff changeset
179 // restore the marks we saved earlier
a61af66fc99e Initial load
duke
parents:
diff changeset
180 for (size_t i = 0; i < _preserved_count; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
181 _preserved_marks[i].restore();
a61af66fc99e Initial load
duke
parents:
diff changeset
182 }
a61af66fc99e Initial load
duke
parents:
diff changeset
183
a61af66fc99e Initial load
duke
parents:
diff changeset
184 // deal with the overflow
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
185 while (!_preserved_oop_stack.is_empty()) {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
186 oop obj = _preserved_oop_stack.pop();
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
187 markOop mark = _preserved_mark_stack.pop();
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
188 obj->set_mark(mark);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
189 }
a61af66fc99e Initial load
duke
parents:
diff changeset
190 }
a61af66fc99e Initial load
duke
parents:
diff changeset
191
a61af66fc99e Initial load
duke
parents:
diff changeset
192 #ifdef VALIDATE_MARK_SWEEP
a61af66fc99e Initial load
duke
parents:
diff changeset
193
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
194 void MarkSweep::track_adjusted_pointer(void* p, bool isroot) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
195 if (!ValidateMarkSweep)
a61af66fc99e Initial load
duke
parents:
diff changeset
196 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
197
a61af66fc99e Initial load
duke
parents:
diff changeset
198 if (!isroot) {
a61af66fc99e Initial load
duke
parents:
diff changeset
199 if (_pointer_tracking) {
a61af66fc99e Initial load
duke
parents:
diff changeset
200 guarantee(_adjusted_pointers->contains(p), "should have seen this pointer");
a61af66fc99e Initial load
duke
parents:
diff changeset
201 _adjusted_pointers->remove(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }
a61af66fc99e Initial load
duke
parents:
diff changeset
203 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
204 ptrdiff_t index = _root_refs_stack->find(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
205 if (index != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
206 int l = _root_refs_stack->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
207 if (l > 0 && l - 1 != index) {
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
208 void* last = _root_refs_stack->pop();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
209 assert(last != p, "should be different");
a61af66fc99e Initial load
duke
parents:
diff changeset
210 _root_refs_stack->at_put(index, last);
a61af66fc99e Initial load
duke
parents:
diff changeset
211 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
212 _root_refs_stack->remove(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
213 }
a61af66fc99e Initial load
duke
parents:
diff changeset
214 }
a61af66fc99e Initial load
duke
parents:
diff changeset
215 }
a61af66fc99e Initial load
duke
parents:
diff changeset
216 }
a61af66fc99e Initial load
duke
parents:
diff changeset
217
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
218 void MarkSweep::check_adjust_pointer(void* p) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
219 _adjusted_pointers->push(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
220 }
a61af66fc99e Initial load
duke
parents:
diff changeset
221
a61af66fc99e Initial load
duke
parents:
diff changeset
222 class AdjusterTracker: public OopClosure {
a61af66fc99e Initial load
duke
parents:
diff changeset
223 public:
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
224 AdjusterTracker() {}
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
225 void do_oop(oop* o) { MarkSweep::check_adjust_pointer(o); }
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
226 void do_oop(narrowOop* o) { MarkSweep::check_adjust_pointer(o); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
227 };
a61af66fc99e Initial load
duke
parents:
diff changeset
228
a61af66fc99e Initial load
duke
parents:
diff changeset
229 void MarkSweep::track_interior_pointers(oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
230 if (ValidateMarkSweep) {
a61af66fc99e Initial load
duke
parents:
diff changeset
231 _adjusted_pointers->clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
232 _pointer_tracking = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
233
a61af66fc99e Initial load
duke
parents:
diff changeset
234 AdjusterTracker checker;
a61af66fc99e Initial load
duke
parents:
diff changeset
235 obj->oop_iterate(&checker);
a61af66fc99e Initial load
duke
parents:
diff changeset
236 }
a61af66fc99e Initial load
duke
parents:
diff changeset
237 }
a61af66fc99e Initial load
duke
parents:
diff changeset
238
a61af66fc99e Initial load
duke
parents:
diff changeset
239 void MarkSweep::check_interior_pointers() {
a61af66fc99e Initial load
duke
parents:
diff changeset
240 if (ValidateMarkSweep) {
a61af66fc99e Initial load
duke
parents:
diff changeset
241 _pointer_tracking = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
242 guarantee(_adjusted_pointers->length() == 0, "should have processed the same pointers");
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 void MarkSweep::register_live_oop(oop p, size_t size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
254 if (ValidateMarkSweep) {
a61af66fc99e Initial load
duke
parents:
diff changeset
255 _live_oops->push(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
256 _live_oops_size->push(size);
a61af66fc99e Initial load
duke
parents:
diff changeset
257 _live_oops_index++;
a61af66fc99e Initial load
duke
parents:
diff changeset
258 }
a61af66fc99e Initial load
duke
parents:
diff changeset
259 }
a61af66fc99e Initial load
duke
parents:
diff changeset
260
a61af66fc99e Initial load
duke
parents:
diff changeset
261 void MarkSweep::validate_live_oop(oop p, size_t size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
262 if (ValidateMarkSweep) {
a61af66fc99e Initial load
duke
parents:
diff changeset
263 oop obj = _live_oops->at((int)_live_oops_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
264 guarantee(obj == p, "should be the same object");
a61af66fc99e Initial load
duke
parents:
diff changeset
265 guarantee(_live_oops_size->at((int)_live_oops_index) == size, "should be the same size");
a61af66fc99e Initial load
duke
parents:
diff changeset
266 _live_oops_index++;
a61af66fc99e Initial load
duke
parents:
diff changeset
267 }
a61af66fc99e Initial load
duke
parents:
diff changeset
268 }
a61af66fc99e Initial load
duke
parents:
diff changeset
269
a61af66fc99e Initial load
duke
parents:
diff changeset
270 void MarkSweep::live_oop_moved_to(HeapWord* q, size_t size,
a61af66fc99e Initial load
duke
parents:
diff changeset
271 HeapWord* compaction_top) {
a61af66fc99e Initial load
duke
parents:
diff changeset
272 assert(oop(q)->forwardee() == NULL || oop(q)->forwardee() == oop(compaction_top),
a61af66fc99e Initial load
duke
parents:
diff changeset
273 "should be moved to forwarded location");
a61af66fc99e Initial load
duke
parents:
diff changeset
274 if (ValidateMarkSweep) {
a61af66fc99e Initial load
duke
parents:
diff changeset
275 MarkSweep::validate_live_oop(oop(q), size);
a61af66fc99e Initial load
duke
parents:
diff changeset
276 _live_oops_moved_to->push(oop(compaction_top));
a61af66fc99e Initial load
duke
parents:
diff changeset
277 }
a61af66fc99e Initial load
duke
parents:
diff changeset
278 if (RecordMarkSweepCompaction) {
a61af66fc99e Initial load
duke
parents:
diff changeset
279 _cur_gc_live_oops->push(q);
a61af66fc99e Initial load
duke
parents:
diff changeset
280 _cur_gc_live_oops_moved_to->push(compaction_top);
a61af66fc99e Initial load
duke
parents:
diff changeset
281 _cur_gc_live_oops_size->push(size);
a61af66fc99e Initial load
duke
parents:
diff changeset
282 }
a61af66fc99e Initial load
duke
parents:
diff changeset
283 }
a61af66fc99e Initial load
duke
parents:
diff changeset
284
a61af66fc99e Initial load
duke
parents:
diff changeset
285 void MarkSweep::compaction_complete() {
a61af66fc99e Initial load
duke
parents:
diff changeset
286 if (RecordMarkSweepCompaction) {
a61af66fc99e Initial load
duke
parents:
diff changeset
287 GrowableArray<HeapWord*>* _tmp_live_oops = _cur_gc_live_oops;
a61af66fc99e Initial load
duke
parents:
diff changeset
288 GrowableArray<HeapWord*>* _tmp_live_oops_moved_to = _cur_gc_live_oops_moved_to;
a61af66fc99e Initial load
duke
parents:
diff changeset
289 GrowableArray<size_t> * _tmp_live_oops_size = _cur_gc_live_oops_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
290
a61af66fc99e Initial load
duke
parents:
diff changeset
291 _cur_gc_live_oops = _last_gc_live_oops;
a61af66fc99e Initial load
duke
parents:
diff changeset
292 _cur_gc_live_oops_moved_to = _last_gc_live_oops_moved_to;
a61af66fc99e Initial load
duke
parents:
diff changeset
293 _cur_gc_live_oops_size = _last_gc_live_oops_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
294 _last_gc_live_oops = _tmp_live_oops;
a61af66fc99e Initial load
duke
parents:
diff changeset
295 _last_gc_live_oops_moved_to = _tmp_live_oops_moved_to;
a61af66fc99e Initial load
duke
parents:
diff changeset
296 _last_gc_live_oops_size = _tmp_live_oops_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
297 }
a61af66fc99e Initial load
duke
parents:
diff changeset
298 }
a61af66fc99e Initial load
duke
parents:
diff changeset
299
a61af66fc99e Initial load
duke
parents:
diff changeset
300 void MarkSweep::print_new_location_of_heap_address(HeapWord* q) {
a61af66fc99e Initial load
duke
parents:
diff changeset
301 if (!RecordMarkSweepCompaction) {
a61af66fc99e Initial load
duke
parents:
diff changeset
302 tty->print_cr("Requires RecordMarkSweepCompaction to be enabled");
a61af66fc99e Initial load
duke
parents:
diff changeset
303 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
304 }
a61af66fc99e Initial load
duke
parents:
diff changeset
305
a61af66fc99e Initial load
duke
parents:
diff changeset
306 if (_last_gc_live_oops == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
307 tty->print_cr("No compaction information gathered yet");
a61af66fc99e Initial load
duke
parents:
diff changeset
308 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
309 }
a61af66fc99e Initial load
duke
parents:
diff changeset
310
a61af66fc99e Initial load
duke
parents:
diff changeset
311 for (int i = 0; i < _last_gc_live_oops->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
312 HeapWord* old_oop = _last_gc_live_oops->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
313 size_t sz = _last_gc_live_oops_size->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
314 if (old_oop <= q && q < (old_oop + sz)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
315 HeapWord* new_oop = _last_gc_live_oops_moved_to->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
316 size_t offset = (q - old_oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
317 tty->print_cr("Address " PTR_FORMAT, q);
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
318 tty->print_cr(" Was in oop " PTR_FORMAT ", size " SIZE_FORMAT ", at offset " SIZE_FORMAT, old_oop, sz, offset);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
319 tty->print_cr(" Now in oop " PTR_FORMAT ", actual address " PTR_FORMAT, new_oop, new_oop + offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
320 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
321 }
a61af66fc99e Initial load
duke
parents:
diff changeset
322 }
a61af66fc99e Initial load
duke
parents:
diff changeset
323
a61af66fc99e Initial load
duke
parents:
diff changeset
324 tty->print_cr("Address " PTR_FORMAT " not found in live oop information from last GC", q);
a61af66fc99e Initial load
duke
parents:
diff changeset
325 }
a61af66fc99e Initial load
duke
parents:
diff changeset
326 #endif //VALIDATE_MARK_SWEEP
a61af66fc99e Initial load
duke
parents:
diff changeset
327
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
328 MarkSweep::IsAliveClosure MarkSweep::is_alive;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
329
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
330 void MarkSweep::IsAliveClosure::do_object(oop p) { ShouldNotReachHere(); }
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
331 bool MarkSweep::IsAliveClosure::do_object_b(oop p) { return p->is_gc_marked(); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
332
a61af66fc99e Initial load
duke
parents:
diff changeset
333 MarkSweep::KeepAliveClosure MarkSweep::keep_alive;
a61af66fc99e Initial load
duke
parents:
diff changeset
334
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
335 void MarkSweep::KeepAliveClosure::do_oop(oop* p) { MarkSweep::KeepAliveClosure::do_oop_work(p); }
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
336 void MarkSweep::KeepAliveClosure::do_oop(narrowOop* p) { MarkSweep::KeepAliveClosure::do_oop_work(p); }
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
337
0
a61af66fc99e Initial load
duke
parents:
diff changeset
338 void marksweep_init() { /* empty */ }
a61af66fc99e Initial load
duke
parents:
diff changeset
339
a61af66fc99e Initial load
duke
parents:
diff changeset
340 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
341
a61af66fc99e Initial load
duke
parents:
diff changeset
342 void MarkSweep::trace(const char* msg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
343 if (TraceMarkSweep)
a61af66fc99e Initial load
duke
parents:
diff changeset
344 gclog_or_tty->print("%s", msg);
a61af66fc99e Initial load
duke
parents:
diff changeset
345 }
a61af66fc99e Initial load
duke
parents:
diff changeset
346
a61af66fc99e Initial load
duke
parents:
diff changeset
347 #endif