annotate src/share/vm/gc_implementation/parallelScavenge/psTasks.cpp @ 210:05712c37c828

6676016: ParallelOldGC leaks memory Summary: ensure that GCTask threads release resource and handle memory Reviewed-by: jmasa, chrisphi
author jcoomes
date Wed, 18 Jun 2008 18:36:47 -0700
parents ba764ed4b6f2
children d1605aabd0a1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2002-2006 Sun Microsystems, Inc. All Rights Reserved.
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 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
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/_psTasks.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 //
a61af66fc99e Initial load
duke
parents:
diff changeset
29 // ScavengeRootsTask
a61af66fc99e Initial load
duke
parents:
diff changeset
30 //
a61af66fc99e Initial load
duke
parents:
diff changeset
31
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // Define before use
a61af66fc99e Initial load
duke
parents:
diff changeset
33 class PSScavengeRootsClosure: public OopClosure {
a61af66fc99e Initial load
duke
parents:
diff changeset
34 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
35 PSPromotionManager* _promotion_manager;
a61af66fc99e Initial load
duke
parents:
diff changeset
36
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
37 protected:
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
38 template <class T> void do_oop_work(T *p) {
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
39 if (PSScavenge::should_scavenge(p)) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // We never card mark roots, maybe call a func without test?
a61af66fc99e Initial load
duke
parents:
diff changeset
41 PSScavenge::copy_and_push_safe_barrier(_promotion_manager, p);
a61af66fc99e Initial load
duke
parents:
diff changeset
42 }
a61af66fc99e Initial load
duke
parents:
diff changeset
43 }
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
44 public:
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
45 PSScavengeRootsClosure(PSPromotionManager* pm) : _promotion_manager(pm) { }
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
46 void do_oop(oop* p) { PSScavengeRootsClosure::do_oop_work(p); }
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
47 void do_oop(narrowOop* p) { PSScavengeRootsClosure::do_oop_work(p); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
48 };
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 void ScavengeRootsTask::do_it(GCTaskManager* manager, uint which) {
a61af66fc99e Initial load
duke
parents:
diff changeset
51 assert(Universe::heap()->is_gc_active(), "called outside gc");
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 PSPromotionManager* pm = PSPromotionManager::gc_thread_promotion_manager(which);
a61af66fc99e Initial load
duke
parents:
diff changeset
54 PSScavengeRootsClosure roots_closure(pm);
a61af66fc99e Initial load
duke
parents:
diff changeset
55
a61af66fc99e Initial load
duke
parents:
diff changeset
56 switch (_root_type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
57 case universe:
a61af66fc99e Initial load
duke
parents:
diff changeset
58 Universe::oops_do(&roots_closure);
a61af66fc99e Initial load
duke
parents:
diff changeset
59 ReferenceProcessor::oops_do(&roots_closure);
a61af66fc99e Initial load
duke
parents:
diff changeset
60 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 case jni_handles:
a61af66fc99e Initial load
duke
parents:
diff changeset
63 JNIHandles::oops_do(&roots_closure);
a61af66fc99e Initial load
duke
parents:
diff changeset
64 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66 case threads:
a61af66fc99e Initial load
duke
parents:
diff changeset
67 {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 Threads::oops_do(&roots_closure);
a61af66fc99e Initial load
duke
parents:
diff changeset
70 }
a61af66fc99e Initial load
duke
parents:
diff changeset
71 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73 case object_synchronizer:
a61af66fc99e Initial load
duke
parents:
diff changeset
74 ObjectSynchronizer::oops_do(&roots_closure);
a61af66fc99e Initial load
duke
parents:
diff changeset
75 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77 case flat_profiler:
a61af66fc99e Initial load
duke
parents:
diff changeset
78 FlatProfiler::oops_do(&roots_closure);
a61af66fc99e Initial load
duke
parents:
diff changeset
79 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
80
a61af66fc99e Initial load
duke
parents:
diff changeset
81 case system_dictionary:
a61af66fc99e Initial load
duke
parents:
diff changeset
82 SystemDictionary::oops_do(&roots_closure);
a61af66fc99e Initial load
duke
parents:
diff changeset
83 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85 case management:
a61af66fc99e Initial load
duke
parents:
diff changeset
86 Management::oops_do(&roots_closure);
a61af66fc99e Initial load
duke
parents:
diff changeset
87 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89 case jvmti:
a61af66fc99e Initial load
duke
parents:
diff changeset
90 JvmtiExport::oops_do(&roots_closure);
a61af66fc99e Initial load
duke
parents:
diff changeset
91 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
92
a61af66fc99e Initial load
duke
parents:
diff changeset
93 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
94 fatal("Unknown root type");
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96
a61af66fc99e Initial load
duke
parents:
diff changeset
97 // Do the real work
a61af66fc99e Initial load
duke
parents:
diff changeset
98 pm->drain_stacks(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100
a61af66fc99e Initial load
duke
parents:
diff changeset
101 //
a61af66fc99e Initial load
duke
parents:
diff changeset
102 // ThreadRootsTask
a61af66fc99e Initial load
duke
parents:
diff changeset
103 //
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 void ThreadRootsTask::do_it(GCTaskManager* manager, uint which) {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 assert(Universe::heap()->is_gc_active(), "called outside gc");
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108 PSPromotionManager* pm = PSPromotionManager::gc_thread_promotion_manager(which);
a61af66fc99e Initial load
duke
parents:
diff changeset
109 PSScavengeRootsClosure roots_closure(pm);
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 if (_java_thread != NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
112 _java_thread->oops_do(&roots_closure);
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114 if (_vm_thread != NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
115 _vm_thread->oops_do(&roots_closure);
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 // Do the real work
a61af66fc99e Initial load
duke
parents:
diff changeset
118 pm->drain_stacks(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 //
a61af66fc99e Initial load
duke
parents:
diff changeset
122 // StealTask
a61af66fc99e Initial load
duke
parents:
diff changeset
123 //
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 StealTask::StealTask(ParallelTaskTerminator* t) :
a61af66fc99e Initial load
duke
parents:
diff changeset
126 _terminator(t) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128 void StealTask::do_it(GCTaskManager* manager, uint which) {
a61af66fc99e Initial load
duke
parents:
diff changeset
129 assert(Universe::heap()->is_gc_active(), "called outside gc");
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 PSPromotionManager* pm =
a61af66fc99e Initial load
duke
parents:
diff changeset
132 PSPromotionManager::gc_thread_promotion_manager(which);
a61af66fc99e Initial load
duke
parents:
diff changeset
133 pm->drain_stacks(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
134 guarantee(pm->stacks_empty(),
a61af66fc99e Initial load
duke
parents:
diff changeset
135 "stacks should be empty at this point");
a61af66fc99e Initial load
duke
parents:
diff changeset
136
a61af66fc99e Initial load
duke
parents:
diff changeset
137 int random_seed = 17;
a61af66fc99e Initial load
duke
parents:
diff changeset
138 if (pm->depth_first()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 while(true) {
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
140 StarTask p;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
141 if (PSPromotionManager::steal_depth(which, &random_seed, p)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
142 #if PS_PM_STATS
a61af66fc99e Initial load
duke
parents:
diff changeset
143 pm->increment_steals(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
144 #endif // PS_PM_STATS
a61af66fc99e Initial load
duke
parents:
diff changeset
145 pm->process_popped_location_depth(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
146 pm->drain_stacks_depth(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
147 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
148 if (terminator()->offer_termination()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
149 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
151 }
a61af66fc99e Initial load
duke
parents:
diff changeset
152 }
a61af66fc99e Initial load
duke
parents:
diff changeset
153 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
154 while(true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
155 oop obj;
a61af66fc99e Initial load
duke
parents:
diff changeset
156 if (PSPromotionManager::steal_breadth(which, &random_seed, obj)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
157 #if PS_PM_STATS
a61af66fc99e Initial load
duke
parents:
diff changeset
158 pm->increment_steals();
a61af66fc99e Initial load
duke
parents:
diff changeset
159 #endif // PS_PM_STATS
a61af66fc99e Initial load
duke
parents:
diff changeset
160 obj->copy_contents(pm);
a61af66fc99e Initial load
duke
parents:
diff changeset
161 pm->drain_stacks_breadth(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
162 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
163 if (terminator()->offer_termination()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
164 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
165 }
a61af66fc99e Initial load
duke
parents:
diff changeset
166 }
a61af66fc99e Initial load
duke
parents:
diff changeset
167 }
a61af66fc99e Initial load
duke
parents:
diff changeset
168 }
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
169 guarantee(pm->stacks_empty(), "stacks should be empty at this point");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
170 }
a61af66fc99e Initial load
duke
parents:
diff changeset
171
a61af66fc99e Initial load
duke
parents:
diff changeset
172 //
a61af66fc99e Initial load
duke
parents:
diff changeset
173 // SerialOldToYoungRootsTask
a61af66fc99e Initial load
duke
parents:
diff changeset
174 //
a61af66fc99e Initial load
duke
parents:
diff changeset
175
a61af66fc99e Initial load
duke
parents:
diff changeset
176 void SerialOldToYoungRootsTask::do_it(GCTaskManager* manager, uint which) {
a61af66fc99e Initial load
duke
parents:
diff changeset
177 assert(_gen != NULL, "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
178 assert(_gen->object_space()->contains(_gen_top) || _gen_top == _gen->object_space()->top(), "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
179
a61af66fc99e Initial load
duke
parents:
diff changeset
180 {
a61af66fc99e Initial load
duke
parents:
diff changeset
181 PSPromotionManager* pm = PSPromotionManager::gc_thread_promotion_manager(which);
a61af66fc99e Initial load
duke
parents:
diff changeset
182
a61af66fc99e Initial load
duke
parents:
diff changeset
183 assert(Universe::heap()->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
184 CardTableExtension* card_table = (CardTableExtension *)Universe::heap()->barrier_set();
a61af66fc99e Initial load
duke
parents:
diff changeset
185 // FIX ME! Assert that card_table is the type we believe it to be.
a61af66fc99e Initial load
duke
parents:
diff changeset
186
a61af66fc99e Initial load
duke
parents:
diff changeset
187 card_table->scavenge_contents(_gen->start_array(),
a61af66fc99e Initial load
duke
parents:
diff changeset
188 _gen->object_space(),
a61af66fc99e Initial load
duke
parents:
diff changeset
189 _gen_top,
a61af66fc99e Initial load
duke
parents:
diff changeset
190 pm);
a61af66fc99e Initial load
duke
parents:
diff changeset
191
a61af66fc99e Initial load
duke
parents:
diff changeset
192 // Do the real work
a61af66fc99e Initial load
duke
parents:
diff changeset
193 pm->drain_stacks(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
194 }
a61af66fc99e Initial load
duke
parents:
diff changeset
195 }
a61af66fc99e Initial load
duke
parents:
diff changeset
196
a61af66fc99e Initial load
duke
parents:
diff changeset
197 //
a61af66fc99e Initial load
duke
parents:
diff changeset
198 // OldToYoungRootsTask
a61af66fc99e Initial load
duke
parents:
diff changeset
199 //
a61af66fc99e Initial load
duke
parents:
diff changeset
200
a61af66fc99e Initial load
duke
parents:
diff changeset
201 void OldToYoungRootsTask::do_it(GCTaskManager* manager, uint which) {
a61af66fc99e Initial load
duke
parents:
diff changeset
202 assert(_gen != NULL, "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
203 assert(_gen->object_space()->contains(_gen_top) || _gen_top == _gen->object_space()->top(), "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
204 assert(_stripe_number < ParallelGCThreads, "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
205
a61af66fc99e Initial load
duke
parents:
diff changeset
206 {
a61af66fc99e Initial load
duke
parents:
diff changeset
207 PSPromotionManager* pm = PSPromotionManager::gc_thread_promotion_manager(which);
a61af66fc99e Initial load
duke
parents:
diff changeset
208
a61af66fc99e Initial load
duke
parents:
diff changeset
209 assert(Universe::heap()->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
210 CardTableExtension* card_table = (CardTableExtension *)Universe::heap()->barrier_set();
a61af66fc99e Initial load
duke
parents:
diff changeset
211 // FIX ME! Assert that card_table is the type we believe it to be.
a61af66fc99e Initial load
duke
parents:
diff changeset
212
a61af66fc99e Initial load
duke
parents:
diff changeset
213 card_table->scavenge_contents_parallel(_gen->start_array(),
a61af66fc99e Initial load
duke
parents:
diff changeset
214 _gen->object_space(),
a61af66fc99e Initial load
duke
parents:
diff changeset
215 _gen_top,
a61af66fc99e Initial load
duke
parents:
diff changeset
216 pm,
a61af66fc99e Initial load
duke
parents:
diff changeset
217 _stripe_number);
a61af66fc99e Initial load
duke
parents:
diff changeset
218
a61af66fc99e Initial load
duke
parents:
diff changeset
219 // Do the real work
a61af66fc99e Initial load
duke
parents:
diff changeset
220 pm->drain_stacks(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
221 }
a61af66fc99e Initial load
duke
parents:
diff changeset
222 }