annotate src/share/vm/gc_implementation/parallelScavenge/psTasks.cpp @ 4095:bca17e38de00

6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads Summary: Select number of GC threads dynamically based on heap usage and number of Java threads Reviewed-by: johnc, ysr, jcoomes
author jmasa
date Tue, 09 Aug 2011 10:16:01 -0700
parents c2bf0120ee5d
children 95f6641e38e0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
2426
1d1603768966 7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents: 2379
diff changeset
2 * Copyright (c) 2002, 2011, 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: 989
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 989
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: 989
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: 1706
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1706
diff changeset
26 #include "classfile/systemDictionary.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1706
diff changeset
27 #include "code/codeCache.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1706
diff changeset
28 #include "gc_implementation/parallelScavenge/cardTableExtension.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1706
diff changeset
29 #include "gc_implementation/parallelScavenge/gcTaskManager.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1706
diff changeset
30 #include "gc_implementation/parallelScavenge/psMarkSweep.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1706
diff changeset
31 #include "gc_implementation/parallelScavenge/psPromotionManager.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1706
diff changeset
32 #include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp"
2379
b099aaf51bf8 6962931: move interned strings out of the perm gen
jcoomes
parents: 1972
diff changeset
33 #include "gc_implementation/parallelScavenge/psScavenge.inline.hpp"
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1706
diff changeset
34 #include "gc_implementation/parallelScavenge/psTasks.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1706
diff changeset
35 #include "memory/iterator.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1706
diff changeset
36 #include "memory/universe.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1706
diff changeset
37 #include "oops/oop.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1706
diff changeset
38 #include "oops/oop.psgc.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1706
diff changeset
39 #include "runtime/fprofiler.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1706
diff changeset
40 #include "runtime/thread.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1706
diff changeset
41 #include "runtime/vmThread.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1706
diff changeset
42 #include "services/management.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1706
diff changeset
43 #include "utilities/taskqueue.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 //
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // ScavengeRootsTask
a61af66fc99e Initial load
duke
parents:
diff changeset
47 //
a61af66fc99e Initial load
duke
parents:
diff changeset
48
a61af66fc99e Initial load
duke
parents:
diff changeset
49 void ScavengeRootsTask::do_it(GCTaskManager* manager, uint which) {
a61af66fc99e Initial load
duke
parents:
diff changeset
50 assert(Universe::heap()->is_gc_active(), "called outside gc");
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 PSPromotionManager* pm = PSPromotionManager::gc_thread_promotion_manager(which);
a61af66fc99e Initial load
duke
parents:
diff changeset
53 PSScavengeRootsClosure roots_closure(pm);
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55 switch (_root_type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
56 case universe:
a61af66fc99e Initial load
duke
parents:
diff changeset
57 Universe::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;
989
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 196
diff changeset
67 Threads::oops_do(&roots_closure, NULL);
0
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
989
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 196
diff changeset
91
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 196
diff changeset
92 case code_cache:
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 196
diff changeset
93 {
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 196
diff changeset
94 CodeBlobToOopClosure each_scavengable_code_blob(&roots_closure, /*do_marking=*/ true);
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 196
diff changeset
95 CodeCache::scavenge_root_nmethods_do(&each_scavengable_code_blob);
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 196
diff changeset
96 }
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 196
diff changeset
97 break;
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 196
diff changeset
98
0
a61af66fc99e Initial load
duke
parents:
diff changeset
99 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
100 fatal("Unknown root type");
a61af66fc99e Initial load
duke
parents:
diff changeset
101 }
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 // Do the real work
a61af66fc99e Initial load
duke
parents:
diff changeset
104 pm->drain_stacks(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
106
a61af66fc99e Initial load
duke
parents:
diff changeset
107 //
a61af66fc99e Initial load
duke
parents:
diff changeset
108 // ThreadRootsTask
a61af66fc99e Initial load
duke
parents:
diff changeset
109 //
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 void ThreadRootsTask::do_it(GCTaskManager* manager, uint which) {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 assert(Universe::heap()->is_gc_active(), "called outside gc");
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114 PSPromotionManager* pm = PSPromotionManager::gc_thread_promotion_manager(which);
a61af66fc99e Initial load
duke
parents:
diff changeset
115 PSScavengeRootsClosure roots_closure(pm);
989
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 196
diff changeset
116 CodeBlobToOopClosure roots_in_blobs(&roots_closure, /*do_marking=*/ true);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 if (_java_thread != NULL)
989
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 196
diff changeset
119 _java_thread->oops_do(&roots_closure, &roots_in_blobs);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 if (_vm_thread != NULL)
989
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 196
diff changeset
122 _vm_thread->oops_do(&roots_closure, &roots_in_blobs);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 // Do the real work
a61af66fc99e Initial load
duke
parents:
diff changeset
125 pm->drain_stacks(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
126 }
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128 //
a61af66fc99e Initial load
duke
parents:
diff changeset
129 // StealTask
a61af66fc99e Initial load
duke
parents:
diff changeset
130 //
a61af66fc99e Initial load
duke
parents:
diff changeset
131
a61af66fc99e Initial load
duke
parents:
diff changeset
132 StealTask::StealTask(ParallelTaskTerminator* t) :
a61af66fc99e Initial load
duke
parents:
diff changeset
133 _terminator(t) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135 void StealTask::do_it(GCTaskManager* manager, uint which) {
a61af66fc99e Initial load
duke
parents:
diff changeset
136 assert(Universe::heap()->is_gc_active(), "called outside gc");
a61af66fc99e Initial load
duke
parents:
diff changeset
137
a61af66fc99e Initial load
duke
parents:
diff changeset
138 PSPromotionManager* pm =
a61af66fc99e Initial load
duke
parents:
diff changeset
139 PSPromotionManager::gc_thread_promotion_manager(which);
a61af66fc99e Initial load
duke
parents:
diff changeset
140 pm->drain_stacks(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
141 guarantee(pm->stacks_empty(),
a61af66fc99e Initial load
duke
parents:
diff changeset
142 "stacks should be empty at this point");
a61af66fc99e Initial load
duke
parents:
diff changeset
143
a61af66fc99e Initial load
duke
parents:
diff changeset
144 int random_seed = 17;
1706
9d7a8ab3736b 6962589: remove breadth first scanning code from parallel gc
tonyp
parents: 1665
diff changeset
145 while(true) {
9d7a8ab3736b 6962589: remove breadth first scanning code from parallel gc
tonyp
parents: 1665
diff changeset
146 StarTask p;
9d7a8ab3736b 6962589: remove breadth first scanning code from parallel gc
tonyp
parents: 1665
diff changeset
147 if (PSPromotionManager::steal_depth(which, &random_seed, p)) {
9d7a8ab3736b 6962589: remove breadth first scanning code from parallel gc
tonyp
parents: 1665
diff changeset
148 TASKQUEUE_STATS_ONLY(pm->record_steal(p));
9d7a8ab3736b 6962589: remove breadth first scanning code from parallel gc
tonyp
parents: 1665
diff changeset
149 pm->process_popped_location_depth(p);
9d7a8ab3736b 6962589: remove breadth first scanning code from parallel gc
tonyp
parents: 1665
diff changeset
150 pm->drain_stacks_depth(true);
9d7a8ab3736b 6962589: remove breadth first scanning code from parallel gc
tonyp
parents: 1665
diff changeset
151 } else {
9d7a8ab3736b 6962589: remove breadth first scanning code from parallel gc
tonyp
parents: 1665
diff changeset
152 if (terminator()->offer_termination()) {
9d7a8ab3736b 6962589: remove breadth first scanning code from parallel gc
tonyp
parents: 1665
diff changeset
153 break;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
154 }
a61af66fc99e Initial load
duke
parents:
diff changeset
155 }
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
157 guarantee(pm->stacks_empty(), "stacks should be empty at this point");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
158 }
a61af66fc99e Initial load
duke
parents:
diff changeset
159
a61af66fc99e Initial load
duke
parents:
diff changeset
160 //
a61af66fc99e Initial load
duke
parents:
diff changeset
161 // SerialOldToYoungRootsTask
a61af66fc99e Initial load
duke
parents:
diff changeset
162 //
a61af66fc99e Initial load
duke
parents:
diff changeset
163
a61af66fc99e Initial load
duke
parents:
diff changeset
164 void SerialOldToYoungRootsTask::do_it(GCTaskManager* manager, uint which) {
a61af66fc99e Initial load
duke
parents:
diff changeset
165 assert(_gen != NULL, "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
166 assert(_gen->object_space()->contains(_gen_top) || _gen_top == _gen->object_space()->top(), "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
167
a61af66fc99e Initial load
duke
parents:
diff changeset
168 {
a61af66fc99e Initial load
duke
parents:
diff changeset
169 PSPromotionManager* pm = PSPromotionManager::gc_thread_promotion_manager(which);
a61af66fc99e Initial load
duke
parents:
diff changeset
170
a61af66fc99e Initial load
duke
parents:
diff changeset
171 assert(Universe::heap()->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
172 CardTableExtension* card_table = (CardTableExtension *)Universe::heap()->barrier_set();
a61af66fc99e Initial load
duke
parents:
diff changeset
173 // FIX ME! Assert that card_table is the type we believe it to be.
a61af66fc99e Initial load
duke
parents:
diff changeset
174
a61af66fc99e Initial load
duke
parents:
diff changeset
175 card_table->scavenge_contents(_gen->start_array(),
a61af66fc99e Initial load
duke
parents:
diff changeset
176 _gen->object_space(),
a61af66fc99e Initial load
duke
parents:
diff changeset
177 _gen_top,
a61af66fc99e Initial load
duke
parents:
diff changeset
178 pm);
a61af66fc99e Initial load
duke
parents:
diff changeset
179
a61af66fc99e Initial load
duke
parents:
diff changeset
180 // Do the real work
a61af66fc99e Initial load
duke
parents:
diff changeset
181 pm->drain_stacks(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
182 }
a61af66fc99e Initial load
duke
parents:
diff changeset
183 }
a61af66fc99e Initial load
duke
parents:
diff changeset
184
a61af66fc99e Initial load
duke
parents:
diff changeset
185 //
a61af66fc99e Initial load
duke
parents:
diff changeset
186 // OldToYoungRootsTask
a61af66fc99e Initial load
duke
parents:
diff changeset
187 //
a61af66fc99e Initial load
duke
parents:
diff changeset
188
a61af66fc99e Initial load
duke
parents:
diff changeset
189 void OldToYoungRootsTask::do_it(GCTaskManager* manager, uint which) {
a61af66fc99e Initial load
duke
parents:
diff changeset
190 assert(_gen != NULL, "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
191 assert(_gen->object_space()->contains(_gen_top) || _gen_top == _gen->object_space()->top(), "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
192 assert(_stripe_number < ParallelGCThreads, "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
193
a61af66fc99e Initial load
duke
parents:
diff changeset
194 {
a61af66fc99e Initial load
duke
parents:
diff changeset
195 PSPromotionManager* pm = PSPromotionManager::gc_thread_promotion_manager(which);
a61af66fc99e Initial load
duke
parents:
diff changeset
196
a61af66fc99e Initial load
duke
parents:
diff changeset
197 assert(Universe::heap()->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
198 CardTableExtension* card_table = (CardTableExtension *)Universe::heap()->barrier_set();
a61af66fc99e Initial load
duke
parents:
diff changeset
199 // FIX ME! Assert that card_table is the type we believe it to be.
a61af66fc99e Initial load
duke
parents:
diff changeset
200
a61af66fc99e Initial load
duke
parents:
diff changeset
201 card_table->scavenge_contents_parallel(_gen->start_array(),
a61af66fc99e Initial load
duke
parents:
diff changeset
202 _gen->object_space(),
a61af66fc99e Initial load
duke
parents:
diff changeset
203 _gen_top,
a61af66fc99e Initial load
duke
parents:
diff changeset
204 pm,
4095
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3915
diff changeset
205 _stripe_number,
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3915
diff changeset
206 _stripe_total);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
207
a61af66fc99e Initial load
duke
parents:
diff changeset
208 // Do the real work
a61af66fc99e Initial load
duke
parents:
diff changeset
209 pm->drain_stacks(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
210 }
a61af66fc99e Initial load
duke
parents:
diff changeset
211 }