annotate src/share/vm/gc_implementation/parallelScavenge/psTasks.cpp @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children ba764ed4b6f2
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
a61af66fc99e Initial load
duke
parents:
diff changeset
37 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
38 PSScavengeRootsClosure(PSPromotionManager* pm) : _promotion_manager(pm) { }
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 virtual void do_oop(oop* p) {
a61af66fc99e Initial load
duke
parents:
diff changeset
41 if (PSScavenge::should_scavenge(*p)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // We never card mark roots, maybe call a func without test?
a61af66fc99e Initial load
duke
parents:
diff changeset
43 PSScavenge::copy_and_push_safe_barrier(_promotion_manager, p);
a61af66fc99e Initial load
duke
parents:
diff changeset
44 }
a61af66fc99e Initial load
duke
parents:
diff changeset
45 }
a61af66fc99e Initial load
duke
parents:
diff changeset
46 };
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48 void ScavengeRootsTask::do_it(GCTaskManager* manager, uint which) {
a61af66fc99e Initial load
duke
parents:
diff changeset
49 assert(Universe::heap()->is_gc_active(), "called outside gc");
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 PSPromotionManager* pm = PSPromotionManager::gc_thread_promotion_manager(which);
a61af66fc99e Initial load
duke
parents:
diff changeset
52 PSScavengeRootsClosure roots_closure(pm);
a61af66fc99e Initial load
duke
parents:
diff changeset
53
a61af66fc99e Initial load
duke
parents:
diff changeset
54 switch (_root_type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
55 case universe:
a61af66fc99e Initial load
duke
parents:
diff changeset
56 Universe::oops_do(&roots_closure);
a61af66fc99e Initial load
duke
parents:
diff changeset
57 ReferenceProcessor::oops_do(&roots_closure);
a61af66fc99e Initial load
duke
parents:
diff changeset
58 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 case jni_handles:
a61af66fc99e Initial load
duke
parents:
diff changeset
61 JNIHandles::oops_do(&roots_closure);
a61af66fc99e Initial load
duke
parents:
diff changeset
62 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 case threads:
a61af66fc99e Initial load
duke
parents:
diff changeset
65 {
a61af66fc99e Initial load
duke
parents:
diff changeset
66 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
67 Threads::oops_do(&roots_closure);
a61af66fc99e Initial load
duke
parents:
diff changeset
68 }
a61af66fc99e Initial load
duke
parents:
diff changeset
69 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71 case object_synchronizer:
a61af66fc99e Initial load
duke
parents:
diff changeset
72 ObjectSynchronizer::oops_do(&roots_closure);
a61af66fc99e Initial load
duke
parents:
diff changeset
73 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 case flat_profiler:
a61af66fc99e Initial load
duke
parents:
diff changeset
76 FlatProfiler::oops_do(&roots_closure);
a61af66fc99e Initial load
duke
parents:
diff changeset
77 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
78
a61af66fc99e Initial load
duke
parents:
diff changeset
79 case system_dictionary:
a61af66fc99e Initial load
duke
parents:
diff changeset
80 SystemDictionary::oops_do(&roots_closure);
a61af66fc99e Initial load
duke
parents:
diff changeset
81 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 case management:
a61af66fc99e Initial load
duke
parents:
diff changeset
84 Management::oops_do(&roots_closure);
a61af66fc99e Initial load
duke
parents:
diff changeset
85 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 case jvmti:
a61af66fc99e Initial load
duke
parents:
diff changeset
88 JvmtiExport::oops_do(&roots_closure);
a61af66fc99e Initial load
duke
parents:
diff changeset
89 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
92 fatal("Unknown root type");
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 // Do the real work
a61af66fc99e Initial load
duke
parents:
diff changeset
96 pm->drain_stacks(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
97 }
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 //
a61af66fc99e Initial load
duke
parents:
diff changeset
100 // ThreadRootsTask
a61af66fc99e Initial load
duke
parents:
diff changeset
101 //
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 void ThreadRootsTask::do_it(GCTaskManager* manager, uint which) {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 assert(Universe::heap()->is_gc_active(), "called outside gc");
a61af66fc99e Initial load
duke
parents:
diff changeset
105
a61af66fc99e Initial load
duke
parents:
diff changeset
106 PSPromotionManager* pm = PSPromotionManager::gc_thread_promotion_manager(which);
a61af66fc99e Initial load
duke
parents:
diff changeset
107 PSScavengeRootsClosure roots_closure(pm);
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109 if (_java_thread != NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
110 _java_thread->oops_do(&roots_closure);
a61af66fc99e Initial load
duke
parents:
diff changeset
111
a61af66fc99e Initial load
duke
parents:
diff changeset
112 if (_vm_thread != NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
113 _vm_thread->oops_do(&roots_closure);
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 // Do the real work
a61af66fc99e Initial load
duke
parents:
diff changeset
116 pm->drain_stacks(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 //
a61af66fc99e Initial load
duke
parents:
diff changeset
120 // StealTask
a61af66fc99e Initial load
duke
parents:
diff changeset
121 //
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123 StealTask::StealTask(ParallelTaskTerminator* t) :
a61af66fc99e Initial load
duke
parents:
diff changeset
124 _terminator(t) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 void StealTask::do_it(GCTaskManager* manager, uint which) {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 assert(Universe::heap()->is_gc_active(), "called outside gc");
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 PSPromotionManager* pm =
a61af66fc99e Initial load
duke
parents:
diff changeset
130 PSPromotionManager::gc_thread_promotion_manager(which);
a61af66fc99e Initial load
duke
parents:
diff changeset
131 pm->drain_stacks(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
132 guarantee(pm->stacks_empty(),
a61af66fc99e Initial load
duke
parents:
diff changeset
133 "stacks should be empty at this point");
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135 int random_seed = 17;
a61af66fc99e Initial load
duke
parents:
diff changeset
136 if (pm->depth_first()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
137 while(true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
138 oop* p;
a61af66fc99e Initial load
duke
parents:
diff changeset
139 if (PSPromotionManager::steal_depth(which, &random_seed, p)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
140 #if PS_PM_STATS
a61af66fc99e Initial load
duke
parents:
diff changeset
141 pm->increment_steals(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
142 #endif // PS_PM_STATS
a61af66fc99e Initial load
duke
parents:
diff changeset
143 pm->process_popped_location_depth(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
144 pm->drain_stacks_depth(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
145 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 if (terminator()->offer_termination()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
147 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
148 }
a61af66fc99e Initial load
duke
parents:
diff changeset
149 }
a61af66fc99e Initial load
duke
parents:
diff changeset
150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
151 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 while(true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
153 oop obj;
a61af66fc99e Initial load
duke
parents:
diff changeset
154 if (PSPromotionManager::steal_breadth(which, &random_seed, obj)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
155 #if PS_PM_STATS
a61af66fc99e Initial load
duke
parents:
diff changeset
156 pm->increment_steals();
a61af66fc99e Initial load
duke
parents:
diff changeset
157 #endif // PS_PM_STATS
a61af66fc99e Initial load
duke
parents:
diff changeset
158 obj->copy_contents(pm);
a61af66fc99e Initial load
duke
parents:
diff changeset
159 pm->drain_stacks_breadth(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
160 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
161 if (terminator()->offer_termination()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
162 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
163 }
a61af66fc99e Initial load
duke
parents:
diff changeset
164 }
a61af66fc99e Initial load
duke
parents:
diff changeset
165 }
a61af66fc99e Initial load
duke
parents:
diff changeset
166 }
a61af66fc99e Initial load
duke
parents:
diff changeset
167 guarantee(pm->stacks_empty(),
a61af66fc99e Initial load
duke
parents:
diff changeset
168 "stacks should be empty at this point");
a61af66fc99e Initial load
duke
parents:
diff changeset
169 }
a61af66fc99e Initial load
duke
parents:
diff changeset
170
a61af66fc99e Initial load
duke
parents:
diff changeset
171 //
a61af66fc99e Initial load
duke
parents:
diff changeset
172 // SerialOldToYoungRootsTask
a61af66fc99e Initial load
duke
parents:
diff changeset
173 //
a61af66fc99e Initial load
duke
parents:
diff changeset
174
a61af66fc99e Initial load
duke
parents:
diff changeset
175 void SerialOldToYoungRootsTask::do_it(GCTaskManager* manager, uint which) {
a61af66fc99e Initial load
duke
parents:
diff changeset
176 assert(_gen != NULL, "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
177 assert(_gen->object_space()->contains(_gen_top) || _gen_top == _gen->object_space()->top(), "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
178
a61af66fc99e Initial load
duke
parents:
diff changeset
179 {
a61af66fc99e Initial load
duke
parents:
diff changeset
180 PSPromotionManager* pm = PSPromotionManager::gc_thread_promotion_manager(which);
a61af66fc99e Initial load
duke
parents:
diff changeset
181
a61af66fc99e Initial load
duke
parents:
diff changeset
182 assert(Universe::heap()->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
183 CardTableExtension* card_table = (CardTableExtension *)Universe::heap()->barrier_set();
a61af66fc99e Initial load
duke
parents:
diff changeset
184 // FIX ME! Assert that card_table is the type we believe it to be.
a61af66fc99e Initial load
duke
parents:
diff changeset
185
a61af66fc99e Initial load
duke
parents:
diff changeset
186 card_table->scavenge_contents(_gen->start_array(),
a61af66fc99e Initial load
duke
parents:
diff changeset
187 _gen->object_space(),
a61af66fc99e Initial load
duke
parents:
diff changeset
188 _gen_top,
a61af66fc99e Initial load
duke
parents:
diff changeset
189 pm);
a61af66fc99e Initial load
duke
parents:
diff changeset
190
a61af66fc99e Initial load
duke
parents:
diff changeset
191 // Do the real work
a61af66fc99e Initial load
duke
parents:
diff changeset
192 pm->drain_stacks(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
193 }
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 // OldToYoungRootsTask
a61af66fc99e Initial load
duke
parents:
diff changeset
198 //
a61af66fc99e Initial load
duke
parents:
diff changeset
199
a61af66fc99e Initial load
duke
parents:
diff changeset
200 void OldToYoungRootsTask::do_it(GCTaskManager* manager, uint which) {
a61af66fc99e Initial load
duke
parents:
diff changeset
201 assert(_gen != NULL, "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
202 assert(_gen->object_space()->contains(_gen_top) || _gen_top == _gen->object_space()->top(), "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
203 assert(_stripe_number < ParallelGCThreads, "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
204
a61af66fc99e Initial load
duke
parents:
diff changeset
205 {
a61af66fc99e Initial load
duke
parents:
diff changeset
206 PSPromotionManager* pm = PSPromotionManager::gc_thread_promotion_manager(which);
a61af66fc99e Initial load
duke
parents:
diff changeset
207
a61af66fc99e Initial load
duke
parents:
diff changeset
208 assert(Universe::heap()->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
209 CardTableExtension* card_table = (CardTableExtension *)Universe::heap()->barrier_set();
a61af66fc99e Initial load
duke
parents:
diff changeset
210 // FIX ME! Assert that card_table is the type we believe it to be.
a61af66fc99e Initial load
duke
parents:
diff changeset
211
a61af66fc99e Initial load
duke
parents:
diff changeset
212 card_table->scavenge_contents_parallel(_gen->start_array(),
a61af66fc99e Initial load
duke
parents:
diff changeset
213 _gen->object_space(),
a61af66fc99e Initial load
duke
parents:
diff changeset
214 _gen_top,
a61af66fc99e Initial load
duke
parents:
diff changeset
215 pm,
a61af66fc99e Initial load
duke
parents:
diff changeset
216 _stripe_number);
a61af66fc99e Initial load
duke
parents:
diff changeset
217
a61af66fc99e Initial load
duke
parents:
diff changeset
218 // Do the real work
a61af66fc99e Initial load
duke
parents:
diff changeset
219 pm->drain_stacks(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
220 }
a61af66fc99e Initial load
duke
parents:
diff changeset
221 }