author | david |
Fri, 27 Mar 2015 15:29:19 +0100 | |
changeset 29800 | fa5f7a2bf717 |
parent 29792 | 8c6fa07f0869 |
child 30150 | d9c940aa42ef |
permissions | -rw-r--r-- |
1 | 1 |
/* |
29701
f638fc81a3d0
8075803: Fix GC includes and forward declarations
stefank
parents:
25492
diff
changeset
|
2 |
* Copyright (c) 1997, 2015, 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" |
|
18025 | 27 |
#include "gc_implementation/shared/gcTimer.hpp" |
28 |
#include "gc_implementation/shared/gcTrace.hpp" |
|
7397 | 29 |
#include "gc_implementation/shared/markSweep.inline.hpp" |
30 |
#include "gc_interface/collectedHeap.inline.hpp" |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
31 |
#include "oops/methodData.hpp" |
7397 | 32 |
#include "oops/objArrayKlass.inline.hpp" |
33 |
#include "oops/oop.inline.hpp" |
|
1 | 34 |
|
17392
2f967c0e4246
6843347: Boundary values in some public GC options cause crashes
tschatzl
parents:
17105
diff
changeset
|
35 |
uint MarkSweep::_total_invocations = 0; |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
36 |
|
13195 | 37 |
Stack<oop, mtGC> MarkSweep::_marking_stack; |
38 |
Stack<ObjArrayTask, mtGC> MarkSweep::_objarray_stack; |
|
1 | 39 |
|
13195 | 40 |
Stack<oop, mtGC> MarkSweep::_preserved_oop_stack; |
41 |
Stack<markOop, mtGC> MarkSweep::_preserved_mark_stack; |
|
1 | 42 |
size_t MarkSweep::_preserved_count = 0; |
43 |
size_t MarkSweep::_preserved_count_max = 0; |
|
44 |
PreservedMark* MarkSweep::_preserved_marks = NULL; |
|
45 |
ReferenceProcessor* MarkSweep::_ref_processor = NULL; |
|
18025 | 46 |
STWGCTimer* MarkSweep::_gc_timer = NULL; |
47 |
SerialOldTracer* MarkSweep::_gc_tracer = NULL; |
|
1 | 48 |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
49 |
MarkSweep::FollowRootClosure MarkSweep::follow_root_closure; |
1 | 50 |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
51 |
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
|
52 |
void MarkSweep::FollowRootClosure::do_oop(narrowOop* p) { follow_root(p); } |
1 | 53 |
|
54 |
MarkSweep::MarkAndPushClosure MarkSweep::mark_and_push_closure; |
|
25492
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
55 |
CLDToOopClosure MarkSweep::follow_cld_closure(&mark_and_push_closure); |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
56 |
CLDToOopClosure MarkSweep::adjust_cld_closure(&adjust_pointer_closure); |
1 | 57 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
58 |
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
|
59 |
void MarkSweep::MarkAndPushClosure::do_oop(narrowOop* p) { mark_and_push(p); } |
1 | 60 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
61 |
void MarkSweep::follow_class_loader(ClassLoaderData* cld) { |
25492
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
62 |
MarkSweep::follow_cld_closure.do_cld(cld); |
13728
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 |
|
29792
8c6fa07f0869
8075957: Reduce calls to the GC specific object visitors in oopDesc
stefank
parents:
29701
diff
changeset
|
65 |
void MarkSweep::follow_array(objArrayOop array, int index) { |
8c6fa07f0869
8075957: Reduce calls to the GC specific object visitors in oopDesc
stefank
parents:
29701
diff
changeset
|
66 |
ObjArrayKlass* k = (ObjArrayKlass*)array->klass(); |
8c6fa07f0869
8075957: Reduce calls to the GC specific object visitors in oopDesc
stefank
parents:
29701
diff
changeset
|
67 |
k->oop_follow_contents(array, index); |
8c6fa07f0869
8075957: Reduce calls to the GC specific object visitors in oopDesc
stefank
parents:
29701
diff
changeset
|
68 |
} |
8c6fa07f0869
8075957: Reduce calls to the GC specific object visitors in oopDesc
stefank
parents:
29701
diff
changeset
|
69 |
|
1 | 70 |
void MarkSweep::follow_stack() { |
5076
8b74a4b60b31
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
3919
diff
changeset
|
71 |
do { |
6762
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
72 |
while (!_marking_stack.is_empty()) { |
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
73 |
oop obj = _marking_stack.pop(); |
5076
8b74a4b60b31
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
3919
diff
changeset
|
74 |
assert (obj->is_gc_marked(), "p must be marked"); |
29792
8c6fa07f0869
8075957: Reduce calls to the GC specific object visitors in oopDesc
stefank
parents:
29701
diff
changeset
|
75 |
follow_object(obj); |
5076
8b74a4b60b31
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
3919
diff
changeset
|
76 |
} |
5080
eff0cc882603
6935839: excessive marking stack growth during full gcs
jcoomes
parents:
5076
diff
changeset
|
77 |
// 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
|
78 |
if (!_objarray_stack.is_empty()) { |
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
79 |
ObjArrayTask task = _objarray_stack.pop(); |
29792
8c6fa07f0869
8075957: Reduce calls to the GC specific object visitors in oopDesc
stefank
parents:
29701
diff
changeset
|
80 |
follow_array(objArrayOop(task.obj()), task.index()); |
5076
8b74a4b60b31
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
3919
diff
changeset
|
81 |
} |
6762
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
82 |
} while (!_marking_stack.is_empty() || !_objarray_stack.is_empty()); |
1 | 83 |
} |
84 |
||
85 |
MarkSweep::FollowStackClosure MarkSweep::follow_stack_closure; |
|
86 |
||
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
87 |
void MarkSweep::FollowStackClosure::do_void() { follow_stack(); } |
1 | 88 |
|
29701
f638fc81a3d0
8075803: Fix GC includes and forward declarations
stefank
parents:
25492
diff
changeset
|
89 |
void PreservedMark::adjust_pointer() { |
f638fc81a3d0
8075803: Fix GC includes and forward declarations
stefank
parents:
25492
diff
changeset
|
90 |
MarkSweep::adjust_pointer(&_obj); |
f638fc81a3d0
8075803: Fix GC includes and forward declarations
stefank
parents:
25492
diff
changeset
|
91 |
} |
f638fc81a3d0
8075803: Fix GC includes and forward declarations
stefank
parents:
25492
diff
changeset
|
92 |
|
f638fc81a3d0
8075803: Fix GC includes and forward declarations
stefank
parents:
25492
diff
changeset
|
93 |
void PreservedMark::restore() { |
f638fc81a3d0
8075803: Fix GC includes and forward declarations
stefank
parents:
25492
diff
changeset
|
94 |
_obj->set_mark(_mark); |
f638fc81a3d0
8075803: Fix GC includes and forward declarations
stefank
parents:
25492
diff
changeset
|
95 |
} |
f638fc81a3d0
8075803: Fix GC includes and forward declarations
stefank
parents:
25492
diff
changeset
|
96 |
|
6762
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
97 |
// 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
|
98 |
// 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
|
99 |
// currently at that address but it will be after phase4 |
1 | 100 |
void MarkSweep::preserve_mark(oop obj, markOop mark) { |
6762
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
101 |
// 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
|
102 |
// 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
|
103 |
// 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
|
104 |
// back to using Stacks to keep track of the overflow. |
1 | 105 |
if (_preserved_count < _preserved_count_max) { |
106 |
_preserved_marks[_preserved_count++].init(obj, mark); |
|
107 |
} else { |
|
6762
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
108 |
_preserved_mark_stack.push(mark); |
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
109 |
_preserved_oop_stack.push(obj); |
1 | 110 |
} |
111 |
} |
|
112 |
||
17105
25b392a7740d
8012687: Remove unused is_root checks and closures
stefank
parents:
15088
diff
changeset
|
113 |
MarkSweep::AdjustPointerClosure MarkSweep::adjust_pointer_closure; |
1 | 114 |
|
17105
25b392a7740d
8012687: Remove unused is_root checks and closures
stefank
parents:
15088
diff
changeset
|
115 |
void MarkSweep::AdjustPointerClosure::do_oop(oop* p) { adjust_pointer(p); } |
25b392a7740d
8012687: Remove unused is_root checks and closures
stefank
parents:
15088
diff
changeset
|
116 |
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
|
117 |
|
1 | 118 |
void MarkSweep::adjust_marks() { |
6762
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
119 |
assert( _preserved_oop_stack.size() == _preserved_mark_stack.size(), |
1 | 120 |
"inconsistent preserved oop stacks"); |
121 |
||
122 |
// adjust the oops we saved earlier |
|
123 |
for (size_t i = 0; i < _preserved_count; i++) { |
|
124 |
_preserved_marks[i].adjust_pointer(); |
|
125 |
} |
|
126 |
||
127 |
// deal with the overflow stack |
|
13195 | 128 |
StackIterator<oop, mtGC> iter(_preserved_oop_stack); |
6762
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
129 |
while (!iter.is_empty()) { |
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
130 |
oop* p = iter.next_addr(); |
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
131 |
adjust_pointer(p); |
1 | 132 |
} |
133 |
} |
|
134 |
||
135 |
void MarkSweep::restore_marks() { |
|
6762
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
136 |
assert(_preserved_oop_stack.size() == _preserved_mark_stack.size(), |
1 | 137 |
"inconsistent preserved oop stacks"); |
138 |
if (PrintGC && Verbose) { |
|
24092
e274d864545a
8039743: Use correct format specifier to print size_t values and pointers in the GC code
stefank
parents:
22882
diff
changeset
|
139 |
gclog_or_tty->print_cr("Restoring " SIZE_FORMAT " marks", |
6762
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
140 |
_preserved_count + _preserved_oop_stack.size()); |
1 | 141 |
} |
142 |
||
143 |
// restore the marks we saved earlier |
|
144 |
for (size_t i = 0; i < _preserved_count; i++) { |
|
145 |
_preserved_marks[i].restore(); |
|
146 |
} |
|
147 |
||
148 |
// deal with the overflow |
|
6762
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
149 |
while (!_preserved_oop_stack.is_empty()) { |
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
150 |
oop obj = _preserved_oop_stack.pop(); |
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
151 |
markOop mark = _preserved_mark_stack.pop(); |
f8d1b560700e
6423256: GC stacks should use a better data structure
jcoomes
parents:
5547
diff
changeset
|
152 |
obj->set_mark(mark); |
1 | 153 |
} |
154 |
} |
|
155 |
||
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
156 |
MarkSweep::IsAliveClosure MarkSweep::is_alive; |
1 | 157 |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
158 |
bool MarkSweep::IsAliveClosure::do_object_b(oop p) { return p->is_gc_marked(); } |
1 | 159 |
|
160 |
MarkSweep::KeepAliveClosure MarkSweep::keep_alive; |
|
161 |
||
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
162 |
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
|
163 |
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
|
164 |
|
18025 | 165 |
void marksweep_init() { |
166 |
MarkSweep::_gc_timer = new (ResourceObj::C_HEAP, mtGC) STWGCTimer(); |
|
167 |
MarkSweep::_gc_tracer = new (ResourceObj::C_HEAP, mtGC) SerialOldTracer(); |
|
168 |
} |
|
1 | 169 |
|
170 |
#ifndef PRODUCT |
|
171 |
||
172 |
void MarkSweep::trace(const char* msg) { |
|
173 |
if (TraceMarkSweep) |
|
174 |
gclog_or_tty->print("%s", msg); |
|
175 |
} |
|
176 |
||
177 |
#endif |