author | minqi |
Fri, 10 May 2013 08:27:30 -0700 | |
changeset 17370 | 59a0620561fa |
parent 17105 | 25b392a7740d |
child 17398 | f7db0551c9eb |
permissions | -rw-r--r-- |
1 | 1 |
/* |
17370
59a0620561fa
8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents:
17105
diff
changeset
|
2 |
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5080
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5080
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5080
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "compiler/compileBroker.hpp" |
|
27 |
#include "gc_implementation/shared/markSweep.inline.hpp" |
|
28 |
#include "gc_interface/collectedHeap.inline.hpp" |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
29 |
#include "oops/methodData.hpp" |
7397 | 30 |
#include "oops/objArrayKlass.inline.hpp" |
31 |
#include "oops/oop.inline.hpp" |
|
1 | 32 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
33 |
unsigned int MarkSweep::_total_invocations = 0; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
34 |
|
13195 | 35 |
Stack<oop, mtGC> MarkSweep::_marking_stack; |
36 |
Stack<ObjArrayTask, mtGC> MarkSweep::_objarray_stack; |
|
1 | 37 |
|
13195 | 38 |
Stack<oop, mtGC> MarkSweep::_preserved_oop_stack; |
39 |
Stack<markOop, mtGC> MarkSweep::_preserved_mark_stack; |
|
1 | 40 |
size_t MarkSweep::_preserved_count = 0; |
41 |
size_t MarkSweep::_preserved_count_max = 0; |
|
42 |
PreservedMark* MarkSweep::_preserved_marks = NULL; |
|
43 |
ReferenceProcessor* MarkSweep::_ref_processor = NULL; |
|
44 |
||
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
45 |
MarkSweep::FollowRootClosure MarkSweep::follow_root_closure; |
3908
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
670
diff
changeset
|
46 |
CodeBlobToOopClosure MarkSweep::follow_code_root_closure(&MarkSweep::follow_root_closure, /*do_marking=*/ true); |
1 | 47 |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
48 |
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
|
49 |
void MarkSweep::FollowRootClosure::do_oop(narrowOop* p) { follow_root(p); } |
1 | 50 |
|
51 |
MarkSweep::MarkAndPushClosure MarkSweep::mark_and_push_closure; |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
52 |
MarkSweep::FollowKlassClosure MarkSweep::follow_klass_closure; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
53 |
MarkSweep::AdjustKlassClosure MarkSweep::adjust_klass_closure; |
1 | 54 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
55 |
void MarkSweep::MarkAndPushClosure::do_oop(oop* p) { mark_and_push(p); } |
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
56 |
void MarkSweep::MarkAndPushClosure::do_oop(narrowOop* p) { mark_and_push(p); } |
1 | 57 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
58 |
void MarkSweep::FollowKlassClosure::do_klass(Klass* klass) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
59 |
klass->oops_do(&MarkSweep::mark_and_push_closure); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
60 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
61 |
void MarkSweep::AdjustKlassClosure::do_klass(Klass* klass) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
62 |
klass->oops_do(&MarkSweep::adjust_pointer_closure); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
63 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
64 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
65 |
void MarkSweep::follow_klass(Klass* klass) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
66 |
ClassLoaderData* cld = klass->class_loader_data(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
67 |
// The actual processing of the klass is done when we |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
68 |
// traverse the list of Klasses in the class loader data. |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
69 |
MarkSweep::follow_class_loader(cld); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
70 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
71 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
72 |
void MarkSweep::adjust_klass(Klass* klass) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
73 |
ClassLoaderData* cld = klass->class_loader_data(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
74 |
// The actual processing of the klass is done when we |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
75 |
// traverse the list of Klasses in the class loader data. |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
76 |
MarkSweep::adjust_class_loader(cld); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
77 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
78 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
79 |
void MarkSweep::follow_class_loader(ClassLoaderData* cld) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
80 |
cld->oops_do(&MarkSweep::mark_and_push_closure, &MarkSweep::follow_klass_closure, true); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
81 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
82 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
83 |
void MarkSweep::adjust_class_loader(ClassLoaderData* cld) { |
17105
25b392a7740d
8012687: Remove unused is_root checks and closures
stefank
parents:
15088
diff
changeset
|
84 |
cld->oops_do(&MarkSweep::adjust_pointer_closure, &MarkSweep::adjust_klass_closure, true); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
85 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
86 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
87 |
|
1 | 88 |
void MarkSweep::follow_stack() { |
5076
8b74a4b60b31
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
3919
diff
changeset
|
89 |
do { |
6762
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
90 |
while (!_marking_stack.is_empty()) { |
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
91 |
oop obj = _marking_stack.pop(); |
5076
8b74a4b60b31
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
3919
diff
changeset
|
92 |
assert (obj->is_gc_marked(), "p must be marked"); |
8b74a4b60b31
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
3919
diff
changeset
|
93 |
obj->follow_contents(); |
8b74a4b60b31
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
3919
diff
changeset
|
94 |
} |
5080
eff0cc882603
6935839: excessive marking stack growth during full gcs
jcoomes
parents:
5076
diff
changeset
|
95 |
// Process ObjArrays one at a time to avoid marking stack bloat. |
6762
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
96 |
if (!_objarray_stack.is_empty()) { |
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
97 |
ObjArrayTask task = _objarray_stack.pop(); |
17370
59a0620561fa
8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents:
17105
diff
changeset
|
98 |
ObjArrayKlass* k = (ObjArrayKlass*)task.obj()->klass(); |
5076
8b74a4b60b31
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
3919
diff
changeset
|
99 |
k->oop_follow_contents(task.obj(), task.index()); |
8b74a4b60b31
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
3919
diff
changeset
|
100 |
} |
6762
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
101 |
} while (!_marking_stack.is_empty() || !_objarray_stack.is_empty()); |
1 | 102 |
} |
103 |
||
104 |
MarkSweep::FollowStackClosure MarkSweep::follow_stack_closure; |
|
105 |
||
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
106 |
void MarkSweep::FollowStackClosure::do_void() { follow_stack(); } |
1 | 107 |
|
6762
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
108 |
// We preserve the mark which should be replaced at the end and the location |
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
109 |
// that it will go. Note that the object that this markOop belongs to isn't |
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
110 |
// currently at that address but it will be after phase4 |
1 | 111 |
void MarkSweep::preserve_mark(oop obj, markOop mark) { |
6762
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
112 |
// We try to store preserved marks in the to space of the new generation since |
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
113 |
// this is storage which should be available. Most of the time this should be |
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
114 |
// sufficient space for the marks we need to preserve but if it isn't we fall |
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
115 |
// back to using Stacks to keep track of the overflow. |
1 | 116 |
if (_preserved_count < _preserved_count_max) { |
117 |
_preserved_marks[_preserved_count++].init(obj, mark); |
|
118 |
} else { |
|
6762
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
119 |
_preserved_mark_stack.push(mark); |
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
120 |
_preserved_oop_stack.push(obj); |
1 | 121 |
} |
122 |
} |
|
123 |
||
17105
25b392a7740d
8012687: Remove unused is_root checks and closures
stefank
parents:
15088
diff
changeset
|
124 |
MarkSweep::AdjustPointerClosure MarkSweep::adjust_pointer_closure; |
1 | 125 |
|
17105
25b392a7740d
8012687: Remove unused is_root checks and closures
stefank
parents:
15088
diff
changeset
|
126 |
void MarkSweep::AdjustPointerClosure::do_oop(oop* p) { adjust_pointer(p); } |
25b392a7740d
8012687: Remove unused is_root checks and closures
stefank
parents:
15088
diff
changeset
|
127 |
void MarkSweep::AdjustPointerClosure::do_oop(narrowOop* p) { adjust_pointer(p); } |
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
128 |
|
1 | 129 |
void MarkSweep::adjust_marks() { |
6762
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
130 |
assert( _preserved_oop_stack.size() == _preserved_mark_stack.size(), |
1 | 131 |
"inconsistent preserved oop stacks"); |
132 |
||
133 |
// adjust the oops we saved earlier |
|
134 |
for (size_t i = 0; i < _preserved_count; i++) { |
|
135 |
_preserved_marks[i].adjust_pointer(); |
|
136 |
} |
|
137 |
||
138 |
// deal with the overflow stack |
|
13195 | 139 |
StackIterator<oop, mtGC> iter(_preserved_oop_stack); |
6762
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
140 |
while (!iter.is_empty()) { |
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
141 |
oop* p = iter.next_addr(); |
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
142 |
adjust_pointer(p); |
1 | 143 |
} |
144 |
} |
|
145 |
||
146 |
void MarkSweep::restore_marks() { |
|
6762
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
147 |
assert(_preserved_oop_stack.size() == _preserved_mark_stack.size(), |
1 | 148 |
"inconsistent preserved oop stacks"); |
149 |
if (PrintGC && Verbose) { |
|
6762
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
150 |
gclog_or_tty->print_cr("Restoring %d marks", |
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
151 |
_preserved_count + _preserved_oop_stack.size()); |
1 | 152 |
} |
153 |
||
154 |
// restore the marks we saved earlier |
|
155 |
for (size_t i = 0; i < _preserved_count; i++) { |
|
156 |
_preserved_marks[i].restore(); |
|
157 |
} |
|
158 |
||
159 |
// deal with the overflow |
|
6762
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
160 |
while (!_preserved_oop_stack.is_empty()) { |
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
161 |
oop obj = _preserved_oop_stack.pop(); |
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
162 |
markOop mark = _preserved_mark_stack.pop(); |
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
163 |
obj->set_mark(mark); |
1 | 164 |
} |
165 |
} |
|
166 |
||
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
167 |
MarkSweep::IsAliveClosure MarkSweep::is_alive; |
1 | 168 |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
169 |
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
|
170 |
bool MarkSweep::IsAliveClosure::do_object_b(oop p) { return p->is_gc_marked(); } |
1 | 171 |
|
172 |
MarkSweep::KeepAliveClosure MarkSweep::keep_alive; |
|
173 |
||
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
174 |
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
|
175 |
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
|
176 |
|
1 | 177 |
void marksweep_init() { /* empty */ } |
178 |
||
179 |
#ifndef PRODUCT |
|
180 |
||
181 |
void MarkSweep::trace(const char* msg) { |
|
182 |
if (TraceMarkSweep) |
|
183 |
gclog_or_tty->print("%s", msg); |
|
184 |
} |
|
185 |
||
186 |
#endif |