annotate src/share/vm/gc_implementation/parallelScavenge/psCompactionManager.cpp @ 1638:b2a00dd3117c

6957084: simplify TaskQueue overflow handling Reviewed-by: ysr, jmasa
author jcoomes
date Thu, 01 Jul 2010 21:40:45 -0700
parents c18cbe5936b8
children 894b1d7c7e01
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1638
b2a00dd3117c 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 1552
diff changeset
2 * Copyright (c) 2005, 2010, 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
a61af66fc99e Initial load
duke
parents:
diff changeset
25 #include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 #include "incls/_psCompactionManager.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 PSOldGen* ParCompactionManager::_old_gen = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 ParCompactionManager** ParCompactionManager::_manager_array = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 OopTaskQueueSet* ParCompactionManager::_stack_array = NULL;
1311
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 948
diff changeset
31 ParCompactionManager::ObjArrayTaskQueueSet*
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 948
diff changeset
32 ParCompactionManager::_objarray_queues = NULL;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
33 ObjectStartArray* ParCompactionManager::_start_array = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 ParMarkBitMap* ParCompactionManager::_mark_bitmap = NULL;
1638
b2a00dd3117c 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 1552
diff changeset
35 RegionTaskQueueSet* ParCompactionManager::_region_array = NULL;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37 ParCompactionManager::ParCompactionManager() :
a61af66fc99e Initial load
duke
parents:
diff changeset
38 _action(CopyAndUpdate) {
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
a61af66fc99e Initial load
duke
parents:
diff changeset
41 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43 _old_gen = heap->old_gen();
a61af66fc99e Initial load
duke
parents:
diff changeset
44 _start_array = old_gen()->start_array();
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 marking_stack()->initialize();
1638
b2a00dd3117c 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 1552
diff changeset
47 _objarray_stack.initialize();
375
81cd571500b0 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 0
diff changeset
48 region_stack()->initialize();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 // Note that _revisit_klass_stack is allocated out of the
a61af66fc99e Initial load
duke
parents:
diff changeset
51 // C heap (as opposed to out of ResourceArena).
a61af66fc99e Initial load
duke
parents:
diff changeset
52 int size =
a61af66fc99e Initial load
duke
parents:
diff changeset
53 (SystemDictionary::number_of_classes() * 2) * 2 / ParallelGCThreads;
a61af66fc99e Initial load
duke
parents:
diff changeset
54 _revisit_klass_stack = new (ResourceObj::C_HEAP) GrowableArray<Klass*>(size, true);
941
8b46c4d82093 4957990: Perm heap bloat in JVM
ysr
parents: 470
diff changeset
55 // From some experiments (#klass/k)^2 for k = 10 seems a better fit, but this will
8b46c4d82093 4957990: Perm heap bloat in JVM
ysr
parents: 470
diff changeset
56 // have to do for now until we are able to investigate a more optimal setting.
8b46c4d82093 4957990: Perm heap bloat in JVM
ysr
parents: 470
diff changeset
57 _revisit_mdo_stack = new (ResourceObj::C_HEAP) GrowableArray<DataLayout*>(size*2, true);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
58 }
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 ParCompactionManager::~ParCompactionManager() {
a61af66fc99e Initial load
duke
parents:
diff changeset
61 delete _revisit_klass_stack;
941
8b46c4d82093 4957990: Perm heap bloat in JVM
ysr
parents: 470
diff changeset
62 delete _revisit_mdo_stack;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
63 // _manager_array and _stack_array are statics
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // shared with all instances of ParCompactionManager
a61af66fc99e Initial load
duke
parents:
diff changeset
65 // should not be deallocated.
a61af66fc99e Initial load
duke
parents:
diff changeset
66 }
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 void ParCompactionManager::initialize(ParMarkBitMap* mbm) {
a61af66fc99e Initial load
duke
parents:
diff changeset
69 assert(PSParallelCompact::gc_task_manager() != NULL,
a61af66fc99e Initial load
duke
parents:
diff changeset
70 "Needed for initialization");
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 _mark_bitmap = mbm;
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74 uint parallel_gc_threads = PSParallelCompact::gc_task_manager()->workers();
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 assert(_manager_array == NULL, "Attempt to initialize twice");
a61af66fc99e Initial load
duke
parents:
diff changeset
77 _manager_array = NEW_C_HEAP_ARRAY(ParCompactionManager*, parallel_gc_threads+1 );
1311
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 948
diff changeset
78 guarantee(_manager_array != NULL, "Could not allocate manager_array");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 _stack_array = new OopTaskQueueSet(parallel_gc_threads);
1311
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 948
diff changeset
81 guarantee(_stack_array != NULL, "Could not allocate stack_array");
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 948
diff changeset
82 _objarray_queues = new ObjArrayTaskQueueSet(parallel_gc_threads);
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 948
diff changeset
83 guarantee(_objarray_queues != NULL, "Could not allocate objarray_queues");
375
81cd571500b0 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 0
diff changeset
84 _region_array = new RegionTaskQueueSet(parallel_gc_threads);
1311
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 948
diff changeset
85 guarantee(_region_array != NULL, "Could not allocate region_array");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 // Create and register the ParCompactionManager(s) for the worker threads.
a61af66fc99e Initial load
duke
parents:
diff changeset
88 for(uint i=0; i<parallel_gc_threads; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
89 _manager_array[i] = new ParCompactionManager();
a61af66fc99e Initial load
duke
parents:
diff changeset
90 guarantee(_manager_array[i] != NULL, "Could not create ParCompactionManager");
a61af66fc99e Initial load
duke
parents:
diff changeset
91 stack_array()->register_queue(i, _manager_array[i]->marking_stack());
1638
b2a00dd3117c 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 1552
diff changeset
92 _objarray_queues->register_queue(i, &_manager_array[i]->_objarray_stack);
375
81cd571500b0 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 0
diff changeset
93 region_array()->register_queue(i, _manager_array[i]->region_stack());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
94 }
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 // The VMThread gets its own ParCompactionManager, which is not available
a61af66fc99e Initial load
duke
parents:
diff changeset
97 // for work stealing.
a61af66fc99e Initial load
duke
parents:
diff changeset
98 _manager_array[parallel_gc_threads] = new ParCompactionManager();
a61af66fc99e Initial load
duke
parents:
diff changeset
99 guarantee(_manager_array[parallel_gc_threads] != NULL,
a61af66fc99e Initial load
duke
parents:
diff changeset
100 "Could not create ParCompactionManager");
a61af66fc99e Initial load
duke
parents:
diff changeset
101 assert(PSParallelCompact::gc_task_manager()->workers() != 0,
a61af66fc99e Initial load
duke
parents:
diff changeset
102 "Not initialized?");
a61af66fc99e Initial load
duke
parents:
diff changeset
103 }
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 bool ParCompactionManager::should_update() {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 assert(action() != NotValid, "Action is not set");
a61af66fc99e Initial load
duke
parents:
diff changeset
107 return (action() == ParCompactionManager::Update) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
108 (action() == ParCompactionManager::CopyAndUpdate) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
109 (action() == ParCompactionManager::UpdateAndCopy);
a61af66fc99e Initial load
duke
parents:
diff changeset
110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
111
a61af66fc99e Initial load
duke
parents:
diff changeset
112 bool ParCompactionManager::should_copy() {
a61af66fc99e Initial load
duke
parents:
diff changeset
113 assert(action() != NotValid, "Action is not set");
a61af66fc99e Initial load
duke
parents:
diff changeset
114 return (action() == ParCompactionManager::Copy) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
115 (action() == ParCompactionManager::CopyAndUpdate) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
116 (action() == ParCompactionManager::UpdateAndCopy);
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 bool ParCompactionManager::should_verify_only() {
a61af66fc99e Initial load
duke
parents:
diff changeset
120 assert(action() != NotValid, "Action is not set");
a61af66fc99e Initial load
duke
parents:
diff changeset
121 return action() == ParCompactionManager::VerifyUpdate;
a61af66fc99e Initial load
duke
parents:
diff changeset
122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 bool ParCompactionManager::should_reset_only() {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 assert(action() != NotValid, "Action is not set");
a61af66fc99e Initial load
duke
parents:
diff changeset
126 return action() == ParCompactionManager::ResetObjects;
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 ParCompactionManager*
a61af66fc99e Initial load
duke
parents:
diff changeset
130 ParCompactionManager::gc_thread_compaction_manager(int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 assert(index >= 0 && index < (int)ParallelGCThreads, "index out of range");
a61af66fc99e Initial load
duke
parents:
diff changeset
132 assert(_manager_array != NULL, "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
133 return _manager_array[index];
a61af66fc99e Initial load
duke
parents:
diff changeset
134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 void ParCompactionManager::reset() {
a61af66fc99e Initial load
duke
parents:
diff changeset
137 for(uint i=0; i<ParallelGCThreads+1; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
138 manager_array(i)->revisit_klass_stack()->clear();
941
8b46c4d82093 4957990: Perm heap bloat in JVM
ysr
parents: 470
diff changeset
139 manager_array(i)->revisit_mdo_stack()->clear();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
140 }
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142
1311
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 948
diff changeset
143 void ParCompactionManager::follow_marking_stacks() {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
144 do {
1311
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 948
diff changeset
145 // Drain the overflow stack first, to allow stealing from the marking stack.
1315
c385bf94cfb8 6935839: excessive marking stack growth during full gcs
jcoomes
parents: 1311
diff changeset
146 oop obj;
1638
b2a00dd3117c 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 1552
diff changeset
147 while (marking_stack()->pop_overflow(obj)) {
b2a00dd3117c 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 1552
diff changeset
148 obj->follow_contents(this);
1311
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 948
diff changeset
149 }
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 948
diff changeset
150 while (marking_stack()->pop_local(obj)) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
151 obj->follow_contents(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
152 }
a61af66fc99e Initial load
duke
parents:
diff changeset
153
1315
c385bf94cfb8 6935839: excessive marking stack growth during full gcs
jcoomes
parents: 1311
diff changeset
154 // Process ObjArrays one at a time to avoid marking stack bloat.
1311
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 948
diff changeset
155 ObjArrayTask task;
1638
b2a00dd3117c 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 1552
diff changeset
156 if (_objarray_stack.pop_overflow(task)) {
1311
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 948
diff changeset
157 objArrayKlass* const k = (objArrayKlass*)task.obj()->blueprint();
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 948
diff changeset
158 k->oop_follow_contents(this, task.obj(), task.index());
1638
b2a00dd3117c 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 1552
diff changeset
159 } else if (_objarray_stack.pop_local(task)) {
1311
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 948
diff changeset
160 objArrayKlass* const k = (objArrayKlass*)task.obj()->blueprint();
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 948
diff changeset
161 k->oop_follow_contents(this, task.obj(), task.index());
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 948
diff changeset
162 }
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 948
diff changeset
163 } while (!marking_stacks_empty());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
164
1311
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 948
diff changeset
165 assert(marking_stacks_empty(), "Sanity");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
166 }
a61af66fc99e Initial load
duke
parents:
diff changeset
167
375
81cd571500b0 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 0
diff changeset
168 void ParCompactionManager::drain_region_stacks() {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
169 do {
1638
b2a00dd3117c 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 1552
diff changeset
170 // Drain overflow stack first so other threads can steal.
b2a00dd3117c 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 1552
diff changeset
171 size_t region_index;
b2a00dd3117c 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 1552
diff changeset
172 while (region_stack()->pop_overflow(region_index)) {
375
81cd571500b0 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 0
diff changeset
173 PSParallelCompact::fill_and_update_region(this, region_index);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
174 }
a61af66fc99e Initial load
duke
parents:
diff changeset
175
1638
b2a00dd3117c 6957084: simplify TaskQueue overflow handling
jcoomes
parents: 1552
diff changeset
176 while (region_stack()->pop_local(region_index)) {
375
81cd571500b0 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 0
diff changeset
177 PSParallelCompact::fill_and_update_region(this, region_index);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
178 }
375
81cd571500b0 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 0
diff changeset
179 } while (!region_stack()->is_empty());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181
a61af66fc99e Initial load
duke
parents:
diff changeset
182 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
183 bool ParCompactionManager::stacks_have_been_allocated() {
941
8b46c4d82093 4957990: Perm heap bloat in JVM
ysr
parents: 470
diff changeset
184 return (revisit_klass_stack()->data_addr() != NULL &&
8b46c4d82093 4957990: Perm heap bloat in JVM
ysr
parents: 470
diff changeset
185 revisit_mdo_stack()->data_addr() != NULL);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
186 }
a61af66fc99e Initial load
duke
parents:
diff changeset
187 #endif