author | jcoomes |
Thu, 01 Jul 2010 21:40:45 -0700 | |
changeset 5918 | 73b96456819a |
parent 5547 | f4b087cbb361 |
child 6762 | f8d1b560700e |
permissions | -rw-r--r-- |
1 | 1 |
/* |
5918 | 2 |
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5080
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5080
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5080
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
25 |
#include "incls/_precompiled.incl" |
|
26 |
#include "incls/_psCompactionManager.cpp.incl" |
|
27 |
||
28 |
PSOldGen* ParCompactionManager::_old_gen = NULL; |
|
29 |
ParCompactionManager** ParCompactionManager::_manager_array = NULL; |
|
30 |
OopTaskQueueSet* ParCompactionManager::_stack_array = NULL; |
|
5076
8b74a4b60b31
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
3795
diff
changeset
|
31 |
ParCompactionManager::ObjArrayTaskQueueSet* |
8b74a4b60b31
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
3795
diff
changeset
|
32 |
ParCompactionManager::_objarray_queues = NULL; |
1 | 33 |
ObjectStartArray* ParCompactionManager::_start_array = NULL; |
34 |
ParMarkBitMap* ParCompactionManager::_mark_bitmap = NULL; |
|
5918 | 35 |
RegionTaskQueueSet* ParCompactionManager::_region_array = NULL; |
1 | 36 |
|
37 |
ParCompactionManager::ParCompactionManager() : |
|
38 |
_action(CopyAndUpdate) { |
|
39 |
||
40 |
ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); |
|
41 |
assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); |
|
42 |
||
43 |
_old_gen = heap->old_gen(); |
|
44 |
_start_array = old_gen()->start_array(); |
|
45 |
||
46 |
marking_stack()->initialize(); |
|
5918 | 47 |
_objarray_stack.initialize(); |
1407
9006b01ba3fd
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
1
diff
changeset
|
48 |
region_stack()->initialize(); |
1 | 49 |
|
50 |
// Note that _revisit_klass_stack is allocated out of the |
|
51 |
// C heap (as opposed to out of ResourceArena). |
|
52 |
int size = |
|
53 |
(SystemDictionary::number_of_classes() * 2) * 2 / ParallelGCThreads; |
|
54 |
_revisit_klass_stack = new (ResourceObj::C_HEAP) GrowableArray<Klass*>(size, true); |
|
3696 | 55 |
// From some experiments (#klass/k)^2 for k = 10 seems a better fit, but this will |
56 |
// have to do for now until we are able to investigate a more optimal setting. |
|
57 |
_revisit_mdo_stack = new (ResourceObj::C_HEAP) GrowableArray<DataLayout*>(size*2, true); |
|
1 | 58 |
} |
59 |
||
60 |
ParCompactionManager::~ParCompactionManager() { |
|
61 |
delete _revisit_klass_stack; |
|
3696 | 62 |
delete _revisit_mdo_stack; |
1 | 63 |
// _manager_array and _stack_array are statics |
64 |
// shared with all instances of ParCompactionManager |
|
65 |
// should not be deallocated. |
|
66 |
} |
|
67 |
||
68 |
void ParCompactionManager::initialize(ParMarkBitMap* mbm) { |
|
69 |
assert(PSParallelCompact::gc_task_manager() != NULL, |
|
70 |
"Needed for initialization"); |
|
71 |
||
72 |
_mark_bitmap = mbm; |
|
73 |
||
74 |
uint parallel_gc_threads = PSParallelCompact::gc_task_manager()->workers(); |
|
75 |
||
76 |
assert(_manager_array == NULL, "Attempt to initialize twice"); |
|
77 |
_manager_array = NEW_C_HEAP_ARRAY(ParCompactionManager*, parallel_gc_threads+1 ); |
|
5076
8b74a4b60b31
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
3795
diff
changeset
|
78 |
guarantee(_manager_array != NULL, "Could not allocate manager_array"); |
1 | 79 |
|
80 |
_stack_array = new OopTaskQueueSet(parallel_gc_threads); |
|
5076
8b74a4b60b31
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
3795
diff
changeset
|
81 |
guarantee(_stack_array != NULL, "Could not allocate stack_array"); |
8b74a4b60b31
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
3795
diff
changeset
|
82 |
_objarray_queues = new ObjArrayTaskQueueSet(parallel_gc_threads); |
8b74a4b60b31
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
3795
diff
changeset
|
83 |
guarantee(_objarray_queues != NULL, "Could not allocate objarray_queues"); |
1407
9006b01ba3fd
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
1
diff
changeset
|
84 |
_region_array = new RegionTaskQueueSet(parallel_gc_threads); |
5076
8b74a4b60b31
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
3795
diff
changeset
|
85 |
guarantee(_region_array != NULL, "Could not allocate region_array"); |
1 | 86 |
|
87 |
// Create and register the ParCompactionManager(s) for the worker threads. |
|
88 |
for(uint i=0; i<parallel_gc_threads; i++) { |
|
89 |
_manager_array[i] = new ParCompactionManager(); |
|
90 |
guarantee(_manager_array[i] != NULL, "Could not create ParCompactionManager"); |
|
91 |
stack_array()->register_queue(i, _manager_array[i]->marking_stack()); |
|
5918 | 92 |
_objarray_queues->register_queue(i, &_manager_array[i]->_objarray_stack); |
1407
9006b01ba3fd
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
1
diff
changeset
|
93 |
region_array()->register_queue(i, _manager_array[i]->region_stack()); |
1 | 94 |
} |
95 |
||
96 |
// The VMThread gets its own ParCompactionManager, which is not available |
|
97 |
// for work stealing. |
|
98 |
_manager_array[parallel_gc_threads] = new ParCompactionManager(); |
|
99 |
guarantee(_manager_array[parallel_gc_threads] != NULL, |
|
100 |
"Could not create ParCompactionManager"); |
|
101 |
assert(PSParallelCompact::gc_task_manager()->workers() != 0, |
|
102 |
"Not initialized?"); |
|
103 |
} |
|
104 |
||
105 |
bool ParCompactionManager::should_update() { |
|
106 |
assert(action() != NotValid, "Action is not set"); |
|
107 |
return (action() == ParCompactionManager::Update) || |
|
108 |
(action() == ParCompactionManager::CopyAndUpdate) || |
|
109 |
(action() == ParCompactionManager::UpdateAndCopy); |
|
110 |
} |
|
111 |
||
112 |
bool ParCompactionManager::should_copy() { |
|
113 |
assert(action() != NotValid, "Action is not set"); |
|
114 |
return (action() == ParCompactionManager::Copy) || |
|
115 |
(action() == ParCompactionManager::CopyAndUpdate) || |
|
116 |
(action() == ParCompactionManager::UpdateAndCopy); |
|
117 |
} |
|
118 |
||
119 |
bool ParCompactionManager::should_verify_only() { |
|
120 |
assert(action() != NotValid, "Action is not set"); |
|
121 |
return action() == ParCompactionManager::VerifyUpdate; |
|
122 |
} |
|
123 |
||
124 |
bool ParCompactionManager::should_reset_only() { |
|
125 |
assert(action() != NotValid, "Action is not set"); |
|
126 |
return action() == ParCompactionManager::ResetObjects; |
|
127 |
} |
|
128 |
||
129 |
ParCompactionManager* |
|
130 |
ParCompactionManager::gc_thread_compaction_manager(int index) { |
|
131 |
assert(index >= 0 && index < (int)ParallelGCThreads, "index out of range"); |
|
132 |
assert(_manager_array != NULL, "Sanity"); |
|
133 |
return _manager_array[index]; |
|
134 |
} |
|
135 |
||
136 |
void ParCompactionManager::reset() { |
|
137 |
for(uint i=0; i<ParallelGCThreads+1; i++) { |
|
138 |
manager_array(i)->revisit_klass_stack()->clear(); |
|
3696 | 139 |
manager_array(i)->revisit_mdo_stack()->clear(); |
1 | 140 |
} |
141 |
} |
|
142 |
||
5076
8b74a4b60b31
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
3795
diff
changeset
|
143 |
void ParCompactionManager::follow_marking_stacks() { |
1 | 144 |
do { |
5076
8b74a4b60b31
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
3795
diff
changeset
|
145 |
// Drain the overflow stack first, to allow stealing from the marking stack. |
5080
eff0cc882603
6935839: excessive marking stack growth during full gcs
jcoomes
parents:
5076
diff
changeset
|
146 |
oop obj; |
5918 | 147 |
while (marking_stack()->pop_overflow(obj)) { |
148 |
obj->follow_contents(this); |
|
5076
8b74a4b60b31
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
3795
diff
changeset
|
149 |
} |
8b74a4b60b31
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
3795
diff
changeset
|
150 |
while (marking_stack()->pop_local(obj)) { |
1 | 151 |
obj->follow_contents(this); |
152 |
} |
|
153 |
||
5080
eff0cc882603
6935839: excessive marking stack growth during full gcs
jcoomes
parents:
5076
diff
changeset
|
154 |
// Process ObjArrays one at a time to avoid marking stack bloat. |
5076
8b74a4b60b31
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
3795
diff
changeset
|
155 |
ObjArrayTask task; |
5918 | 156 |
if (_objarray_stack.pop_overflow(task)) { |
5076
8b74a4b60b31
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
3795
diff
changeset
|
157 |
objArrayKlass* const k = (objArrayKlass*)task.obj()->blueprint(); |
8b74a4b60b31
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
3795
diff
changeset
|
158 |
k->oop_follow_contents(this, task.obj(), task.index()); |
5918 | 159 |
} else if (_objarray_stack.pop_local(task)) { |
5076
8b74a4b60b31
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
3795
diff
changeset
|
160 |
objArrayKlass* const k = (objArrayKlass*)task.obj()->blueprint(); |
8b74a4b60b31
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
3795
diff
changeset
|
161 |
k->oop_follow_contents(this, task.obj(), task.index()); |
8b74a4b60b31
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
3795
diff
changeset
|
162 |
} |
8b74a4b60b31
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
3795
diff
changeset
|
163 |
} while (!marking_stacks_empty()); |
1 | 164 |
|
5076
8b74a4b60b31
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
3795
diff
changeset
|
165 |
assert(marking_stacks_empty(), "Sanity"); |
1 | 166 |
} |
167 |
||
1407
9006b01ba3fd
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
1
diff
changeset
|
168 |
void ParCompactionManager::drain_region_stacks() { |
1 | 169 |
do { |
5918 | 170 |
// Drain overflow stack first so other threads can steal. |
171 |
size_t region_index; |
|
172 |
while (region_stack()->pop_overflow(region_index)) { |
|
1407
9006b01ba3fd
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
1
diff
changeset
|
173 |
PSParallelCompact::fill_and_update_region(this, region_index); |
1 | 174 |
} |
175 |
||
5918 | 176 |
while (region_stack()->pop_local(region_index)) { |
1407
9006b01ba3fd
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
1
diff
changeset
|
177 |
PSParallelCompact::fill_and_update_region(this, region_index); |
1 | 178 |
} |
1407
9006b01ba3fd
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
1
diff
changeset
|
179 |
} while (!region_stack()->is_empty()); |
1 | 180 |
} |
181 |
||
182 |
#ifdef ASSERT |
|
183 |
bool ParCompactionManager::stacks_have_been_allocated() { |
|
3696 | 184 |
return (revisit_klass_stack()->data_addr() != NULL && |
185 |
revisit_mdo_stack()->data_addr() != NULL); |
|
1 | 186 |
} |
187 |
#endif |