annotate src/share/vm/gc_implementation/shared/markSweep.cpp @ 14909:4ca6dc0799b6

Backout jdk9 merge
author Gilles Duboscq <duboscq@ssw.jku.at>
date Tue, 01 Apr 2014 13:57:07 +0200
parents d166675568f6
children 52b4284cb496
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
10265
92ef81e2f571 8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents: 10179
diff changeset
2 * Copyright (c) 1997, 2013, 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
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1836
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1836
diff changeset
26 #include "compiler/compileBroker.hpp"
10405
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10328
diff changeset
27 #include "gc_implementation/shared/gcTimer.hpp"
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10328
diff changeset
28 #include "gc_implementation/shared/gcTrace.hpp"
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1836
diff changeset
29 #include "gc_implementation/shared/markSweep.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1836
diff changeset
30 #include "gc_interface/collectedHeap.inline.hpp"
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
31 #include "oops/methodData.hpp"
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1836
diff changeset
32 #include "oops/objArrayKlass.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1836
diff changeset
33 #include "oops/oop.inline.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
34
10287
12f651e29f6b 6843347: Boundary values in some public GC options cause crashes
tschatzl
parents: 10179
diff changeset
35 uint MarkSweep::_total_invocations = 0;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
36
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 2426
diff changeset
37 Stack<oop, mtGC> MarkSweep::_marking_stack;
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 2426
diff changeset
38 Stack<ObjArrayTask, mtGC> MarkSweep::_objarray_stack;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
39
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 2426
diff changeset
40 Stack<oop, mtGC> MarkSweep::_preserved_oop_stack;
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 2426
diff changeset
41 Stack<markOop, mtGC> MarkSweep::_preserved_mark_stack;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
42 size_t MarkSweep::_preserved_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 size_t MarkSweep::_preserved_count_max = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 PreservedMark* MarkSweep::_preserved_marks = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 ReferenceProcessor* MarkSweep::_ref_processor = NULL;
10405
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10328
diff changeset
46 STWGCTimer* MarkSweep::_gc_timer = NULL;
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10328
diff changeset
47 SerialOldTracer* MarkSweep::_gc_tracer = NULL;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
48
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
49 MarkSweep::FollowRootClosure MarkSweep::follow_root_closure;
14909
4ca6dc0799b6 Backout jdk9 merge
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 14466
diff changeset
50 CodeBlobToOopClosure MarkSweep::follow_code_root_closure(&MarkSweep::follow_root_closure, /*do_marking=*/ true);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
51
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
52 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
53 void MarkSweep::FollowRootClosure::do_oop(narrowOop* p) { follow_root(p); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55 MarkSweep::MarkAndPushClosure MarkSweep::mark_and_push_closure;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
56 MarkSweep::FollowKlassClosure MarkSweep::follow_klass_closure;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
57 MarkSweep::AdjustKlassClosure MarkSweep::adjust_klass_closure;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
58
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
59 void MarkSweep::MarkAndPushClosure::do_oop(oop* p) { mark_and_push(p); }
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
60 void MarkSweep::MarkAndPushClosure::do_oop(narrowOop* p) { mark_and_push(p); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
61
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
62 void MarkSweep::FollowKlassClosure::do_klass(Klass* klass) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
63 klass->oops_do(&MarkSweep::mark_and_push_closure);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
64 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
65 void MarkSweep::AdjustKlassClosure::do_klass(Klass* klass) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
66 klass->oops_do(&MarkSweep::adjust_pointer_closure);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
67 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
68
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
69 void MarkSweep::follow_class_loader(ClassLoaderData* cld) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
70 cld->oops_do(&MarkSweep::mark_and_push_closure, &MarkSweep::follow_klass_closure, true);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
71 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
72
0
a61af66fc99e Initial load
duke
parents:
diff changeset
73 void MarkSweep::follow_stack() {
1311
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 1000
diff changeset
74 do {
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
75 while (!_marking_stack.is_empty()) {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
76 oop obj = _marking_stack.pop();
1311
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 1000
diff changeset
77 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
78 obj->follow_contents();
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 1000
diff changeset
79 }
1315
c385bf94cfb8 6935839: excessive marking stack growth during full gcs
jcoomes
parents: 1311
diff changeset
80 // 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
81 if (!_objarray_stack.is_empty()) {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
82 ObjArrayTask task = _objarray_stack.pop();
10265
92ef81e2f571 8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents: 10179
diff changeset
83 ObjArrayKlass* k = (ObjArrayKlass*)task.obj()->klass();
1311
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 1000
diff changeset
84 k->oop_follow_contents(task.obj(), task.index());
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 1000
diff changeset
85 }
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
86 } while (!_marking_stack.is_empty() || !_objarray_stack.is_empty());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
87 }
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89 MarkSweep::FollowStackClosure MarkSweep::follow_stack_closure;
a61af66fc99e Initial load
duke
parents:
diff changeset
90
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
91 void MarkSweep::FollowStackClosure::do_void() { follow_stack(); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
92
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
93 // 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
94 // 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
95 // currently at that address but it will be after phase4
0
a61af66fc99e Initial load
duke
parents:
diff changeset
96 void MarkSweep::preserve_mark(oop obj, markOop mark) {
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
97 // 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
98 // 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
99 // 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
100 // back to using Stacks to keep track of the overflow.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
101 if (_preserved_count < _preserved_count_max) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 _preserved_marks[_preserved_count++].init(obj, mark);
a61af66fc99e Initial load
duke
parents:
diff changeset
103 } else {
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
104 _preserved_mark_stack.push(mark);
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
105 _preserved_oop_stack.push(obj);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
106 }
a61af66fc99e Initial load
duke
parents:
diff changeset
107 }
a61af66fc99e Initial load
duke
parents:
diff changeset
108
10179
a08c80e9e1e5 8012687: Remove unused is_root checks and closures
stefank
parents: 7448
diff changeset
109 MarkSweep::AdjustPointerClosure MarkSweep::adjust_pointer_closure;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
110
10179
a08c80e9e1e5 8012687: Remove unused is_root checks and closures
stefank
parents: 7448
diff changeset
111 void MarkSweep::AdjustPointerClosure::do_oop(oop* p) { adjust_pointer(p); }
a08c80e9e1e5 8012687: Remove unused is_root checks and closures
stefank
parents: 7448
diff changeset
112 void MarkSweep::AdjustPointerClosure::do_oop(narrowOop* p) { adjust_pointer(p); }
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
113
0
a61af66fc99e Initial load
duke
parents:
diff changeset
114 void MarkSweep::adjust_marks() {
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
115 assert( _preserved_oop_stack.size() == _preserved_mark_stack.size(),
0
a61af66fc99e Initial load
duke
parents:
diff changeset
116 "inconsistent preserved oop stacks");
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 // adjust the oops we saved earlier
a61af66fc99e Initial load
duke
parents:
diff changeset
119 for (size_t i = 0; i < _preserved_count; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
120 _preserved_marks[i].adjust_pointer();
a61af66fc99e Initial load
duke
parents:
diff changeset
121 }
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123 // deal with the overflow stack
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 2426
diff changeset
124 StackIterator<oop, mtGC> iter(_preserved_oop_stack);
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
125 while (!iter.is_empty()) {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
126 oop* p = iter.next_addr();
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
127 adjust_pointer(p);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 void MarkSweep::restore_marks() {
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
132 assert(_preserved_oop_stack.size() == _preserved_mark_stack.size(),
0
a61af66fc99e Initial load
duke
parents:
diff changeset
133 "inconsistent preserved oop stacks");
a61af66fc99e Initial load
duke
parents:
diff changeset
134 if (PrintGC && Verbose) {
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
135 gclog_or_tty->print_cr("Restoring %d marks",
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
136 _preserved_count + _preserved_oop_stack.size());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 // restore the marks we saved earlier
a61af66fc99e Initial load
duke
parents:
diff changeset
140 for (size_t i = 0; i < _preserved_count; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 _preserved_marks[i].restore();
a61af66fc99e Initial load
duke
parents:
diff changeset
142 }
a61af66fc99e Initial load
duke
parents:
diff changeset
143
a61af66fc99e Initial load
duke
parents:
diff changeset
144 // deal with the overflow
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
145 while (!_preserved_oop_stack.is_empty()) {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
146 oop obj = _preserved_oop_stack.pop();
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
147 markOop mark = _preserved_mark_stack.pop();
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents: 1552
diff changeset
148 obj->set_mark(mark);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
149 }
a61af66fc99e Initial load
duke
parents:
diff changeset
150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
151
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
152 MarkSweep::IsAliveClosure MarkSweep::is_alive;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
153
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
154 bool MarkSweep::IsAliveClosure::do_object_b(oop p) { return p->is_gc_marked(); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
155
a61af66fc99e Initial load
duke
parents:
diff changeset
156 MarkSweep::KeepAliveClosure MarkSweep::keep_alive;
a61af66fc99e Initial load
duke
parents:
diff changeset
157
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
158 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
159 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
160
10405
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10328
diff changeset
161 void marksweep_init() {
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10328
diff changeset
162 MarkSweep::_gc_timer = new (ResourceObj::C_HEAP, mtGC) STWGCTimer();
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10328
diff changeset
163 MarkSweep::_gc_tracer = new (ResourceObj::C_HEAP, mtGC) SerialOldTracer();
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 10328
diff changeset
164 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
165
a61af66fc99e Initial load
duke
parents:
diff changeset
166 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
167
a61af66fc99e Initial load
duke
parents:
diff changeset
168 void MarkSweep::trace(const char* msg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
169 if (TraceMarkSweep)
a61af66fc99e Initial load
duke
parents:
diff changeset
170 gclog_or_tty->print("%s", msg);
a61af66fc99e Initial load
duke
parents:
diff changeset
171 }
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 #endif