author | ysr |
Sat, 28 Mar 2009 15:47:29 -0700 | |
changeset 2346 | 3aa355016e90 |
parent 2105 | 347008ce7984 |
child 2362 | 5e1bfddf919e |
permissions | -rw-r--r-- |
1 | 1 |
/* |
2105 | 2 |
* Copyright 2001-2009 Sun Microsystems, Inc. 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 |
* |
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
21 |
* have any questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
# include "incls/_precompiled.incl" |
|
26 |
# include "incls/_parNewGeneration.cpp.incl" |
|
27 |
||
28 |
#ifdef _MSC_VER |
|
29 |
#pragma warning( push ) |
|
30 |
#pragma warning( disable:4355 ) // 'this' : used in base member initializer list |
|
31 |
#endif |
|
32 |
ParScanThreadState::ParScanThreadState(Space* to_space_, |
|
33 |
ParNewGeneration* gen_, |
|
34 |
Generation* old_gen_, |
|
35 |
int thread_num_, |
|
36 |
ObjToScanQueueSet* work_queue_set_, |
|
37 |
size_t desired_plab_sz_, |
|
38 |
ParallelTaskTerminator& term_) : |
|
2346
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
39 |
_to_space(to_space_), _old_gen(old_gen_), _young_gen(gen_), _thread_num(thread_num_), |
1 | 40 |
_work_queue(work_queue_set_->queue(thread_num_)), _to_space_full(false), |
41 |
_ageTable(false), // false ==> not the global age table, no perf data. |
|
42 |
_to_space_alloc_buffer(desired_plab_sz_), |
|
43 |
_to_space_closure(gen_, this), _old_gen_closure(gen_, this), |
|
44 |
_to_space_root_closure(gen_, this), _old_gen_root_closure(gen_, this), |
|
45 |
_older_gen_closure(gen_, this), |
|
46 |
_evacuate_followers(this, &_to_space_closure, &_old_gen_closure, |
|
47 |
&_to_space_root_closure, gen_, &_old_gen_root_closure, |
|
48 |
work_queue_set_, &term_), |
|
49 |
_is_alive_closure(gen_), _scan_weak_ref_closure(gen_, this), |
|
50 |
_keep_alive_closure(&_scan_weak_ref_closure), |
|
51 |
_pushes(0), _pops(0), _steals(0), _steal_attempts(0), _term_attempts(0), |
|
52 |
_strong_roots_time(0.0), _term_time(0.0) |
|
53 |
{ |
|
54 |
_survivor_chunk_array = |
|
55 |
(ChunkArray*) old_gen()->get_data_recorder(thread_num()); |
|
56 |
_hash_seed = 17; // Might want to take time-based random value. |
|
57 |
_start = os::elapsedTime(); |
|
58 |
_old_gen_closure.set_generation(old_gen_); |
|
59 |
_old_gen_root_closure.set_generation(old_gen_); |
|
2346
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
60 |
if (UseCompressedOops) { |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
61 |
_overflow_stack = new (ResourceObj::C_HEAP) GrowableArray<oop>(512, true); |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
62 |
} else { |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
63 |
_overflow_stack = NULL; |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
64 |
} |
1 | 65 |
} |
66 |
#ifdef _MSC_VER |
|
67 |
#pragma warning( pop ) |
|
68 |
#endif |
|
69 |
||
70 |
void ParScanThreadState::record_survivor_plab(HeapWord* plab_start, |
|
71 |
size_t plab_word_size) { |
|
72 |
ChunkArray* sca = survivor_chunk_array(); |
|
73 |
if (sca != NULL) { |
|
74 |
// A non-null SCA implies that we want the PLAB data recorded. |
|
75 |
sca->record_sample(plab_start, plab_word_size); |
|
76 |
} |
|
77 |
} |
|
78 |
||
79 |
bool ParScanThreadState::should_be_partially_scanned(oop new_obj, oop old_obj) const { |
|
80 |
return new_obj->is_objArray() && |
|
81 |
arrayOop(new_obj)->length() > ParGCArrayScanChunk && |
|
82 |
new_obj != old_obj; |
|
83 |
} |
|
84 |
||
85 |
void ParScanThreadState::scan_partial_array_and_push_remainder(oop old) { |
|
86 |
assert(old->is_objArray(), "must be obj array"); |
|
87 |
assert(old->is_forwarded(), "must be forwarded"); |
|
88 |
assert(Universe::heap()->is_in_reserved(old), "must be in heap."); |
|
2346
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
89 |
assert(!old_gen()->is_in(old), "must be in young generation."); |
1 | 90 |
|
91 |
objArrayOop obj = objArrayOop(old->forwardee()); |
|
92 |
// Process ParGCArrayScanChunk elements now |
|
93 |
// and push the remainder back onto queue |
|
94 |
int start = arrayOop(old)->length(); |
|
95 |
int end = obj->length(); |
|
96 |
int remainder = end - start; |
|
97 |
assert(start <= end, "just checking"); |
|
98 |
if (remainder > 2 * ParGCArrayScanChunk) { |
|
99 |
// Test above combines last partial chunk with a full chunk |
|
100 |
end = start + ParGCArrayScanChunk; |
|
101 |
arrayOop(old)->set_length(end); |
|
102 |
// Push remainder. |
|
103 |
bool ok = work_queue()->push(old); |
|
104 |
assert(ok, "just popped, push must be okay"); |
|
105 |
note_push(); |
|
106 |
} else { |
|
107 |
// Restore length so that it can be used if there |
|
108 |
// is a promotion failure and forwarding pointers |
|
109 |
// must be removed. |
|
110 |
arrayOop(old)->set_length(end); |
|
111 |
} |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
112 |
|
1 | 113 |
// process our set of indices (include header in first chunk) |
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
114 |
// should make sure end is even (aligned to HeapWord in case of compressed oops) |
1 | 115 |
if ((HeapWord *)obj < young_old_boundary()) { |
116 |
// object is in to_space |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
117 |
obj->oop_iterate_range(&_to_space_closure, start, end); |
1 | 118 |
} else { |
119 |
// object is in old generation |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
120 |
obj->oop_iterate_range(&_old_gen_closure, start, end); |
1 | 121 |
} |
122 |
} |
|
123 |
||
124 |
||
125 |
void ParScanThreadState::trim_queues(int max_size) { |
|
126 |
ObjToScanQueue* queue = work_queue(); |
|
2346
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
127 |
do { |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
128 |
while (queue->size() > (juint)max_size) { |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
129 |
oop obj_to_scan; |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
130 |
if (queue->pop_local(obj_to_scan)) { |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
131 |
note_pop(); |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
132 |
if ((HeapWord *)obj_to_scan < young_old_boundary()) { |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
133 |
if (obj_to_scan->is_objArray() && |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
134 |
obj_to_scan->is_forwarded() && |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
135 |
obj_to_scan->forwardee() != obj_to_scan) { |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
136 |
scan_partial_array_and_push_remainder(obj_to_scan); |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
137 |
} else { |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
138 |
// object is in to_space |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
139 |
obj_to_scan->oop_iterate(&_to_space_closure); |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
140 |
} |
1 | 141 |
} else { |
2346
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
142 |
// object is in old generation |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
143 |
obj_to_scan->oop_iterate(&_old_gen_closure); |
1 | 144 |
} |
145 |
} |
|
146 |
} |
|
2346
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
147 |
// For the case of compressed oops, we have a private, non-shared |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
148 |
// overflow stack, so we eagerly drain it so as to more evenly |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
149 |
// distribute load early. Note: this may be good to do in |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
150 |
// general rather than delay for the final stealing phase. |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
151 |
// If applicable, we'll transfer a set of objects over to our |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
152 |
// work queue, allowing them to be stolen and draining our |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
153 |
// private overflow stack. |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
154 |
} while (ParGCTrimOverflow && young_gen()->take_from_overflow_list(this)); |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
155 |
} |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
156 |
|
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
157 |
bool ParScanThreadState::take_from_overflow_stack() { |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
158 |
assert(UseCompressedOops, "Else should not call"); |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
159 |
assert(young_gen()->overflow_list() == NULL, "Error"); |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
160 |
ObjToScanQueue* queue = work_queue(); |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
161 |
GrowableArray<oop>* of_stack = overflow_stack(); |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
162 |
uint num_overflow_elems = of_stack->length(); |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
163 |
uint num_take_elems = MIN2(MIN2((queue->max_elems() - queue->size())/4, |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
164 |
(juint)ParGCDesiredObjsFromOverflowList), |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
165 |
num_overflow_elems); |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
166 |
// Transfer the most recent num_take_elems from the overflow |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
167 |
// stack to our work queue. |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
168 |
for (size_t i = 0; i != num_take_elems; i++) { |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
169 |
oop cur = of_stack->pop(); |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
170 |
oop obj_to_push = cur->forwardee(); |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
171 |
assert(Universe::heap()->is_in_reserved(cur), "Should be in heap"); |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
172 |
assert(!old_gen()->is_in_reserved(cur), "Should be in young gen"); |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
173 |
assert(Universe::heap()->is_in_reserved(obj_to_push), "Should be in heap"); |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
174 |
if (should_be_partially_scanned(obj_to_push, cur)) { |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
175 |
assert(arrayOop(cur)->length() == 0, "entire array remaining to be scanned"); |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
176 |
obj_to_push = cur; |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
177 |
} |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
178 |
bool ok = queue->push(obj_to_push); |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
179 |
assert(ok, "Should have succeeded"); |
1 | 180 |
} |
2346
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
181 |
assert(young_gen()->overflow_list() == NULL, "Error"); |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
182 |
return num_take_elems > 0; // was something transferred? |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
183 |
} |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
184 |
|
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
185 |
void ParScanThreadState::push_on_overflow_stack(oop p) { |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
186 |
assert(UseCompressedOops, "Else should not call"); |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
187 |
overflow_stack()->push(p); |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
188 |
assert(young_gen()->overflow_list() == NULL, "Error"); |
1 | 189 |
} |
190 |
||
191 |
HeapWord* ParScanThreadState::alloc_in_to_space_slow(size_t word_sz) { |
|
192 |
||
193 |
// Otherwise, if the object is small enough, try to reallocate the |
|
194 |
// buffer. |
|
195 |
HeapWord* obj = NULL; |
|
196 |
if (!_to_space_full) { |
|
197 |
ParGCAllocBuffer* const plab = to_space_alloc_buffer(); |
|
198 |
Space* const sp = to_space(); |
|
199 |
if (word_sz * 100 < |
|
200 |
ParallelGCBufferWastePct * plab->word_sz()) { |
|
201 |
// Is small enough; abandon this buffer and start a new one. |
|
202 |
plab->retire(false, false); |
|
203 |
size_t buf_size = plab->word_sz(); |
|
204 |
HeapWord* buf_space = sp->par_allocate(buf_size); |
|
205 |
if (buf_space == NULL) { |
|
206 |
const size_t min_bytes = |
|
207 |
ParGCAllocBuffer::min_size() << LogHeapWordSize; |
|
208 |
size_t free_bytes = sp->free(); |
|
209 |
while(buf_space == NULL && free_bytes >= min_bytes) { |
|
210 |
buf_size = free_bytes >> LogHeapWordSize; |
|
211 |
assert(buf_size == (size_t)align_object_size(buf_size), |
|
212 |
"Invariant"); |
|
213 |
buf_space = sp->par_allocate(buf_size); |
|
214 |
free_bytes = sp->free(); |
|
215 |
} |
|
216 |
} |
|
217 |
if (buf_space != NULL) { |
|
218 |
plab->set_word_size(buf_size); |
|
219 |
plab->set_buf(buf_space); |
|
220 |
record_survivor_plab(buf_space, buf_size); |
|
221 |
obj = plab->allocate(word_sz); |
|
222 |
// Note that we cannot compare buf_size < word_sz below |
|
223 |
// because of AlignmentReserve (see ParGCAllocBuffer::allocate()). |
|
224 |
assert(obj != NULL || plab->words_remaining() < word_sz, |
|
225 |
"Else should have been able to allocate"); |
|
226 |
// It's conceivable that we may be able to use the |
|
227 |
// buffer we just grabbed for subsequent small requests |
|
228 |
// even if not for this one. |
|
229 |
} else { |
|
230 |
// We're used up. |
|
231 |
_to_space_full = true; |
|
232 |
} |
|
233 |
||
234 |
} else { |
|
235 |
// Too large; allocate the object individually. |
|
236 |
obj = sp->par_allocate(word_sz); |
|
237 |
} |
|
238 |
} |
|
239 |
return obj; |
|
240 |
} |
|
241 |
||
242 |
||
243 |
void ParScanThreadState::undo_alloc_in_to_space(HeapWord* obj, |
|
244 |
size_t word_sz) { |
|
245 |
// Is the alloc in the current alloc buffer? |
|
246 |
if (to_space_alloc_buffer()->contains(obj)) { |
|
247 |
assert(to_space_alloc_buffer()->contains(obj + word_sz - 1), |
|
248 |
"Should contain whole object."); |
|
249 |
to_space_alloc_buffer()->undo_allocation(obj, word_sz); |
|
250 |
} else { |
|
1668
8ec481b8f514
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
1610
diff
changeset
|
251 |
CollectedHeap::fill_with_object(obj, word_sz); |
1 | 252 |
} |
253 |
} |
|
254 |
||
255 |
class ParScanThreadStateSet: private ResourceArray { |
|
256 |
public: |
|
257 |
// Initializes states for the specified number of threads; |
|
258 |
ParScanThreadStateSet(int num_threads, |
|
259 |
Space& to_space, |
|
260 |
ParNewGeneration& gen, |
|
261 |
Generation& old_gen, |
|
262 |
ObjToScanQueueSet& queue_set, |
|
263 |
size_t desired_plab_sz, |
|
264 |
ParallelTaskTerminator& term); |
|
265 |
inline ParScanThreadState& thread_sate(int i); |
|
266 |
int pushes() { return _pushes; } |
|
267 |
int pops() { return _pops; } |
|
268 |
int steals() { return _steals; } |
|
269 |
void reset(); |
|
270 |
void flush(); |
|
271 |
private: |
|
272 |
ParallelTaskTerminator& _term; |
|
273 |
ParNewGeneration& _gen; |
|
274 |
Generation& _next_gen; |
|
275 |
// staticstics |
|
276 |
int _pushes; |
|
277 |
int _pops; |
|
278 |
int _steals; |
|
279 |
}; |
|
280 |
||
281 |
||
282 |
ParScanThreadStateSet::ParScanThreadStateSet( |
|
283 |
int num_threads, Space& to_space, ParNewGeneration& gen, |
|
284 |
Generation& old_gen, ObjToScanQueueSet& queue_set, |
|
285 |
size_t desired_plab_sz, ParallelTaskTerminator& term) |
|
286 |
: ResourceArray(sizeof(ParScanThreadState), num_threads), |
|
287 |
_gen(gen), _next_gen(old_gen), _term(term), |
|
288 |
_pushes(0), _pops(0), _steals(0) |
|
289 |
{ |
|
290 |
assert(num_threads > 0, "sanity check!"); |
|
291 |
// Initialize states. |
|
292 |
for (int i = 0; i < num_threads; ++i) { |
|
293 |
new ((ParScanThreadState*)_data + i) |
|
294 |
ParScanThreadState(&to_space, &gen, &old_gen, i, &queue_set, |
|
295 |
desired_plab_sz, term); |
|
296 |
} |
|
297 |
} |
|
298 |
||
299 |
inline ParScanThreadState& ParScanThreadStateSet::thread_sate(int i) |
|
300 |
{ |
|
301 |
assert(i >= 0 && i < length(), "sanity check!"); |
|
302 |
return ((ParScanThreadState*)_data)[i]; |
|
303 |
} |
|
304 |
||
305 |
||
306 |
void ParScanThreadStateSet::reset() |
|
307 |
{ |
|
308 |
_term.reset_for_reuse(); |
|
309 |
} |
|
310 |
||
311 |
void ParScanThreadStateSet::flush() |
|
312 |
{ |
|
313 |
for (int i = 0; i < length(); ++i) { |
|
314 |
ParScanThreadState& par_scan_state = thread_sate(i); |
|
315 |
||
316 |
// Flush stats related to To-space PLAB activity and |
|
317 |
// retire the last buffer. |
|
318 |
par_scan_state.to_space_alloc_buffer()-> |
|
319 |
flush_stats_and_retire(_gen.plab_stats(), |
|
320 |
false /* !retain */); |
|
321 |
||
322 |
// Every thread has its own age table. We need to merge |
|
323 |
// them all into one. |
|
324 |
ageTable *local_table = par_scan_state.age_table(); |
|
325 |
_gen.age_table()->merge(local_table); |
|
326 |
||
327 |
// Inform old gen that we're done. |
|
328 |
_next_gen.par_promote_alloc_done(i); |
|
329 |
_next_gen.par_oop_since_save_marks_iterate_done(i); |
|
330 |
||
331 |
// Flush stats related to work queue activity (push/pop/steal) |
|
332 |
// This could conceivably become a bottleneck; if so, we'll put the |
|
333 |
// stat's gathering under the flag. |
|
334 |
if (PAR_STATS_ENABLED) { |
|
335 |
_pushes += par_scan_state.pushes(); |
|
336 |
_pops += par_scan_state.pops(); |
|
337 |
_steals += par_scan_state.steals(); |
|
338 |
if (ParallelGCVerbose) { |
|
339 |
gclog_or_tty->print("Thread %d complete:\n" |
|
340 |
" Pushes: %7d Pops: %7d Steals %7d (in %d attempts)\n", |
|
341 |
i, par_scan_state.pushes(), par_scan_state.pops(), |
|
342 |
par_scan_state.steals(), par_scan_state.steal_attempts()); |
|
343 |
if (par_scan_state.overflow_pushes() > 0 || |
|
344 |
par_scan_state.overflow_refills() > 0) { |
|
345 |
gclog_or_tty->print(" Overflow pushes: %7d " |
|
346 |
"Overflow refills: %7d for %d objs.\n", |
|
347 |
par_scan_state.overflow_pushes(), |
|
348 |
par_scan_state.overflow_refills(), |
|
349 |
par_scan_state.overflow_refill_objs()); |
|
350 |
} |
|
351 |
||
352 |
double elapsed = par_scan_state.elapsed(); |
|
353 |
double strong_roots = par_scan_state.strong_roots_time(); |
|
354 |
double term = par_scan_state.term_time(); |
|
355 |
gclog_or_tty->print( |
|
356 |
" Elapsed: %7.2f ms.\n" |
|
357 |
" Strong roots: %7.2f ms (%6.2f%%)\n" |
|
358 |
" Termination: %7.2f ms (%6.2f%%) (in %d entries)\n", |
|
359 |
elapsed * 1000.0, |
|
360 |
strong_roots * 1000.0, (strong_roots*100.0/elapsed), |
|
361 |
term * 1000.0, (term*100.0/elapsed), |
|
362 |
par_scan_state.term_attempts()); |
|
363 |
} |
|
364 |
} |
|
365 |
} |
|
366 |
} |
|
367 |
||
368 |
ParScanClosure::ParScanClosure(ParNewGeneration* g, |
|
369 |
ParScanThreadState* par_scan_state) : |
|
370 |
OopsInGenClosure(g), _par_scan_state(par_scan_state), _g(g) |
|
371 |
{ |
|
372 |
assert(_g->level() == 0, "Optimized for youngest generation"); |
|
373 |
_boundary = _g->reserved().end(); |
|
374 |
} |
|
375 |
||
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
376 |
void ParScanWithBarrierClosure::do_oop(oop* p) { ParScanClosure::do_oop_work(p, true, false); } |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
377 |
void ParScanWithBarrierClosure::do_oop(narrowOop* p) { ParScanClosure::do_oop_work(p, true, false); } |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
378 |
|
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
379 |
void ParScanWithoutBarrierClosure::do_oop(oop* p) { ParScanClosure::do_oop_work(p, false, false); } |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
380 |
void ParScanWithoutBarrierClosure::do_oop(narrowOop* p) { ParScanClosure::do_oop_work(p, false, false); } |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
381 |
|
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
382 |
void ParRootScanWithBarrierTwoGensClosure::do_oop(oop* p) { ParScanClosure::do_oop_work(p, true, true); } |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
383 |
void ParRootScanWithBarrierTwoGensClosure::do_oop(narrowOop* p) { ParScanClosure::do_oop_work(p, true, true); } |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
384 |
|
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
385 |
void ParRootScanWithoutBarrierClosure::do_oop(oop* p) { ParScanClosure::do_oop_work(p, false, true); } |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
386 |
void ParRootScanWithoutBarrierClosure::do_oop(narrowOop* p) { ParScanClosure::do_oop_work(p, false, true); } |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
387 |
|
1 | 388 |
ParScanWeakRefClosure::ParScanWeakRefClosure(ParNewGeneration* g, |
389 |
ParScanThreadState* par_scan_state) |
|
390 |
: ScanWeakRefClosure(g), _par_scan_state(par_scan_state) |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
391 |
{} |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
392 |
|
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
393 |
void ParScanWeakRefClosure::do_oop(oop* p) { ParScanWeakRefClosure::do_oop_work(p); } |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
394 |
void ParScanWeakRefClosure::do_oop(narrowOop* p) { ParScanWeakRefClosure::do_oop_work(p); } |
1 | 395 |
|
396 |
#ifdef WIN32 |
|
397 |
#pragma warning(disable: 4786) /* identifier was truncated to '255' characters in the browser information */ |
|
398 |
#endif |
|
399 |
||
400 |
ParEvacuateFollowersClosure::ParEvacuateFollowersClosure( |
|
401 |
ParScanThreadState* par_scan_state_, |
|
402 |
ParScanWithoutBarrierClosure* to_space_closure_, |
|
403 |
ParScanWithBarrierClosure* old_gen_closure_, |
|
404 |
ParRootScanWithoutBarrierClosure* to_space_root_closure_, |
|
405 |
ParNewGeneration* par_gen_, |
|
406 |
ParRootScanWithBarrierTwoGensClosure* old_gen_root_closure_, |
|
407 |
ObjToScanQueueSet* task_queues_, |
|
408 |
ParallelTaskTerminator* terminator_) : |
|
409 |
||
410 |
_par_scan_state(par_scan_state_), |
|
411 |
_to_space_closure(to_space_closure_), |
|
412 |
_old_gen_closure(old_gen_closure_), |
|
413 |
_to_space_root_closure(to_space_root_closure_), |
|
414 |
_old_gen_root_closure(old_gen_root_closure_), |
|
415 |
_par_gen(par_gen_), |
|
416 |
_task_queues(task_queues_), |
|
417 |
_terminator(terminator_) |
|
418 |
{} |
|
419 |
||
420 |
void ParEvacuateFollowersClosure::do_void() { |
|
421 |
ObjToScanQueue* work_q = par_scan_state()->work_queue(); |
|
422 |
||
423 |
while (true) { |
|
424 |
||
425 |
// Scan to-space and old-gen objs until we run out of both. |
|
426 |
oop obj_to_scan; |
|
427 |
par_scan_state()->trim_queues(0); |
|
428 |
||
429 |
// We have no local work, attempt to steal from other threads. |
|
430 |
||
431 |
// attempt to steal work from promoted. |
|
432 |
par_scan_state()->note_steal_attempt(); |
|
433 |
if (task_queues()->steal(par_scan_state()->thread_num(), |
|
434 |
par_scan_state()->hash_seed(), |
|
435 |
obj_to_scan)) { |
|
436 |
par_scan_state()->note_steal(); |
|
437 |
bool res = work_q->push(obj_to_scan); |
|
438 |
assert(res, "Empty queue should have room for a push."); |
|
439 |
||
440 |
par_scan_state()->note_push(); |
|
441 |
// if successful, goto Start. |
|
442 |
continue; |
|
443 |
||
444 |
// try global overflow list. |
|
445 |
} else if (par_gen()->take_from_overflow_list(par_scan_state())) { |
|
446 |
continue; |
|
447 |
} |
|
448 |
||
449 |
// Otherwise, offer termination. |
|
450 |
par_scan_state()->start_term_time(); |
|
451 |
if (terminator()->offer_termination()) break; |
|
452 |
par_scan_state()->end_term_time(); |
|
453 |
} |
|
1910 | 454 |
assert(par_gen()->_overflow_list == NULL && par_gen()->_num_par_pushes == 0, |
455 |
"Broken overflow list?"); |
|
1 | 456 |
// Finish the last termination pause. |
457 |
par_scan_state()->end_term_time(); |
|
458 |
} |
|
459 |
||
460 |
ParNewGenTask::ParNewGenTask(ParNewGeneration* gen, Generation* next_gen, |
|
461 |
HeapWord* young_old_boundary, ParScanThreadStateSet* state_set) : |
|
462 |
AbstractGangTask("ParNewGeneration collection"), |
|
463 |
_gen(gen), _next_gen(next_gen), |
|
464 |
_young_old_boundary(young_old_boundary), |
|
465 |
_state_set(state_set) |
|
466 |
{} |
|
467 |
||
468 |
void ParNewGenTask::work(int i) { |
|
469 |
GenCollectedHeap* gch = GenCollectedHeap::heap(); |
|
470 |
// Since this is being done in a separate thread, need new resource |
|
471 |
// and handle marks. |
|
472 |
ResourceMark rm; |
|
473 |
HandleMark hm; |
|
474 |
// We would need multiple old-gen queues otherwise. |
|
2346
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
475 |
assert(gch->n_gens() == 2, "Par young collection currently only works with one older gen."); |
1 | 476 |
|
477 |
Generation* old_gen = gch->next_gen(_gen); |
|
478 |
||
479 |
ParScanThreadState& par_scan_state = _state_set->thread_sate(i); |
|
480 |
par_scan_state.set_young_old_boundary(_young_old_boundary); |
|
481 |
||
482 |
par_scan_state.start_strong_roots(); |
|
483 |
gch->gen_process_strong_roots(_gen->level(), |
|
484 |
true, // Process younger gens, if any, |
|
485 |
// as strong roots. |
|
486 |
false,// not collecting perm generation. |
|
487 |
SharedHeap::SO_AllClasses, |
|
488 |
&par_scan_state.older_gen_closure(), |
|
489 |
&par_scan_state.to_space_root_closure()); |
|
490 |
par_scan_state.end_strong_roots(); |
|
491 |
||
492 |
// "evacuate followers". |
|
493 |
par_scan_state.evacuate_followers_closure().do_void(); |
|
494 |
} |
|
495 |
||
496 |
#ifdef _MSC_VER |
|
497 |
#pragma warning( push ) |
|
498 |
#pragma warning( disable:4355 ) // 'this' : used in base member initializer list |
|
499 |
#endif |
|
500 |
ParNewGeneration:: |
|
501 |
ParNewGeneration(ReservedSpace rs, size_t initial_byte_size, int level) |
|
502 |
: DefNewGeneration(rs, initial_byte_size, level, "PCopy"), |
|
503 |
_overflow_list(NULL), |
|
504 |
_is_alive_closure(this), |
|
505 |
_plab_stats(YoungPLABSize, PLABWeight) |
|
506 |
{ |
|
1910 | 507 |
NOT_PRODUCT(_overflow_counter = ParGCWorkQueueOverflowInterval;) |
508 |
NOT_PRODUCT(_num_par_pushes = 0;) |
|
1 | 509 |
_task_queues = new ObjToScanQueueSet(ParallelGCThreads); |
510 |
guarantee(_task_queues != NULL, "task_queues allocation failure."); |
|
511 |
||
512 |
for (uint i1 = 0; i1 < ParallelGCThreads; i1++) { |
|
513 |
ObjToScanQueuePadded *q_padded = new ObjToScanQueuePadded(); |
|
514 |
guarantee(q_padded != NULL, "work_queue Allocation failure."); |
|
515 |
||
516 |
_task_queues->register_queue(i1, &q_padded->work_queue); |
|
517 |
} |
|
518 |
||
519 |
for (uint i2 = 0; i2 < ParallelGCThreads; i2++) |
|
520 |
_task_queues->queue(i2)->initialize(); |
|
521 |
||
522 |
if (UsePerfData) { |
|
523 |
EXCEPTION_MARK; |
|
524 |
ResourceMark rm; |
|
525 |
||
526 |
const char* cname = |
|
527 |
PerfDataManager::counter_name(_gen_counters->name_space(), "threads"); |
|
528 |
PerfDataManager::create_constant(SUN_GC, cname, PerfData::U_None, |
|
529 |
ParallelGCThreads, CHECK); |
|
530 |
} |
|
531 |
} |
|
532 |
#ifdef _MSC_VER |
|
533 |
#pragma warning( pop ) |
|
534 |
#endif |
|
535 |
||
536 |
// ParNewGeneration:: |
|
537 |
ParKeepAliveClosure::ParKeepAliveClosure(ParScanWeakRefClosure* cl) : |
|
538 |
DefNewGeneration::KeepAliveClosure(cl), _par_cl(cl) {} |
|
539 |
||
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
540 |
template <class T> |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
541 |
void /*ParNewGeneration::*/ParKeepAliveClosure::do_oop_work(T* p) { |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
542 |
#ifdef ASSERT |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
543 |
{ |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
544 |
assert(!oopDesc::is_null(*p), "expected non-null ref"); |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
545 |
oop obj = oopDesc::load_decode_heap_oop_not_null(p); |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
546 |
// We never expect to see a null reference being processed |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
547 |
// as a weak reference. |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
548 |
assert(obj->is_oop(), "expected an oop while scanning weak refs"); |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
549 |
} |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
550 |
#endif // ASSERT |
1 | 551 |
|
552 |
_par_cl->do_oop_nv(p); |
|
553 |
||
554 |
if (Universe::heap()->is_in_reserved(p)) { |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
555 |
oop obj = oopDesc::load_decode_heap_oop_not_null(p); |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
556 |
_rs->write_ref_field_gc_par(p, obj); |
1 | 557 |
} |
558 |
} |
|
559 |
||
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
560 |
void /*ParNewGeneration::*/ParKeepAliveClosure::do_oop(oop* p) { ParKeepAliveClosure::do_oop_work(p); } |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
561 |
void /*ParNewGeneration::*/ParKeepAliveClosure::do_oop(narrowOop* p) { ParKeepAliveClosure::do_oop_work(p); } |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
562 |
|
1 | 563 |
// ParNewGeneration:: |
564 |
KeepAliveClosure::KeepAliveClosure(ScanWeakRefClosure* cl) : |
|
565 |
DefNewGeneration::KeepAliveClosure(cl) {} |
|
566 |
||
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
567 |
template <class T> |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
568 |
void /*ParNewGeneration::*/KeepAliveClosure::do_oop_work(T* p) { |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
569 |
#ifdef ASSERT |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
570 |
{ |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
571 |
assert(!oopDesc::is_null(*p), "expected non-null ref"); |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
572 |
oop obj = oopDesc::load_decode_heap_oop_not_null(p); |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
573 |
// We never expect to see a null reference being processed |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
574 |
// as a weak reference. |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
575 |
assert(obj->is_oop(), "expected an oop while scanning weak refs"); |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
576 |
} |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
577 |
#endif // ASSERT |
1 | 578 |
|
579 |
_cl->do_oop_nv(p); |
|
580 |
||
581 |
if (Universe::heap()->is_in_reserved(p)) { |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
582 |
oop obj = oopDesc::load_decode_heap_oop_not_null(p); |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
583 |
_rs->write_ref_field_gc_par(p, obj); |
1 | 584 |
} |
585 |
} |
|
586 |
||
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
587 |
void /*ParNewGeneration::*/KeepAliveClosure::do_oop(oop* p) { KeepAliveClosure::do_oop_work(p); } |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
588 |
void /*ParNewGeneration::*/KeepAliveClosure::do_oop(narrowOop* p) { KeepAliveClosure::do_oop_work(p); } |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
589 |
|
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
590 |
template <class T> void ScanClosureWithParBarrier::do_oop_work(T* p) { |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
591 |
T heap_oop = oopDesc::load_heap_oop(p); |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
592 |
if (!oopDesc::is_null(heap_oop)) { |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
593 |
oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); |
1 | 594 |
if ((HeapWord*)obj < _boundary) { |
595 |
assert(!_g->to()->is_in_reserved(obj), "Scanning field twice?"); |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
596 |
oop new_obj = obj->is_forwarded() |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
597 |
? obj->forwardee() |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
598 |
: _g->DefNewGeneration::copy_to_survivor_space(obj); |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
599 |
oopDesc::encode_store_heap_oop_not_null(p, new_obj); |
1 | 600 |
} |
601 |
if (_gc_barrier) { |
|
602 |
// If p points to a younger generation, mark the card. |
|
603 |
if ((HeapWord*)obj < _gen_boundary) { |
|
604 |
_rs->write_ref_field_gc_par(p, obj); |
|
605 |
} |
|
606 |
} |
|
607 |
} |
|
608 |
} |
|
609 |
||
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
610 |
void ScanClosureWithParBarrier::do_oop(oop* p) { ScanClosureWithParBarrier::do_oop_work(p); } |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
611 |
void ScanClosureWithParBarrier::do_oop(narrowOop* p) { ScanClosureWithParBarrier::do_oop_work(p); } |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
179
diff
changeset
|
612 |
|
1 | 613 |
class ParNewRefProcTaskProxy: public AbstractGangTask { |
614 |
typedef AbstractRefProcTaskExecutor::ProcessTask ProcessTask; |
|
615 |
public: |
|
616 |
ParNewRefProcTaskProxy(ProcessTask& task, ParNewGeneration& gen, |
|
617 |
Generation& next_gen, |
|
618 |
HeapWord* young_old_boundary, |
|
619 |
ParScanThreadStateSet& state_set); |
|
620 |
||
621 |
private: |
|
622 |
virtual void work(int i); |
|
623 |
||
624 |
private: |
|
625 |
ParNewGeneration& _gen; |
|
626 |
ProcessTask& _task; |
|
627 |
Generation& _next_gen; |
|
628 |
HeapWord* _young_old_boundary; |
|
629 |
ParScanThreadStateSet& _state_set; |
|
630 |
}; |
|
631 |
||
632 |
ParNewRefProcTaskProxy::ParNewRefProcTaskProxy( |
|
633 |
ProcessTask& task, ParNewGeneration& gen, |
|
634 |
Generation& next_gen, |
|
635 |
HeapWord* young_old_boundary, |
|
636 |
ParScanThreadStateSet& state_set) |
|
637 |
: AbstractGangTask("ParNewGeneration parallel reference processing"), |
|
638 |
_gen(gen), |
|
639 |
_task(task), |
|
640 |
_next_gen(next_gen), |
|
641 |
_young_old_boundary(young_old_boundary), |
|
642 |
_state_set(state_set) |
|
643 |
{ |
|
644 |
} |
|
645 |
||
646 |
void ParNewRefProcTaskProxy::work(int i) |
|
647 |
{ |
|
648 |
ResourceMark rm; |
|
649 |
HandleMark hm; |
|
650 |
ParScanThreadState& par_scan_state = _state_set.thread_sate(i); |
|
651 |
par_scan_state.set_young_old_boundary(_young_old_boundary); |
|
652 |
_task.work(i, par_scan_state.is_alive_closure(), |
|
653 |
par_scan_state.keep_alive_closure(), |
|
654 |
par_scan_state.evacuate_followers_closure()); |
|
655 |
} |
|
656 |
||
657 |
class ParNewRefEnqueueTaskProxy: public AbstractGangTask { |
|
658 |
typedef AbstractRefProcTaskExecutor::EnqueueTask EnqueueTask; |
|
659 |
EnqueueTask& _task; |
|
660 |
||
661 |
public: |
|
662 |
ParNewRefEnqueueTaskProxy(EnqueueTask& task) |
|
663 |
: AbstractGangTask("ParNewGeneration parallel reference enqueue"), |
|
664 |
_task(task) |
|
665 |
{ } |
|
666 |
||
667 |
virtual void work(int i) |
|
668 |
{ |
|
669 |
_task.work(i); |
|
670 |
} |
|
671 |
}; |
|
672 |
||
673 |
||
674 |
void ParNewRefProcTaskExecutor::execute(ProcessTask& task) |
|
675 |
{ |
|
676 |
GenCollectedHeap* gch = GenCollectedHeap::heap(); |
|
677 |
assert(gch->kind() == CollectedHeap::GenCollectedHeap, |
|
678 |
"not a generational heap"); |
|
679 |
WorkGang* workers = gch->workers(); |
|
680 |
assert(workers != NULL, "Need parallel worker threads."); |
|
681 |
ParNewRefProcTaskProxy rp_task(task, _generation, *_generation.next_gen(), |
|
682 |
_generation.reserved().end(), _state_set); |
|
683 |
workers->run_task(&rp_task); |
|
684 |
_state_set.reset(); |
|
685 |
} |
|
686 |
||
687 |
void ParNewRefProcTaskExecutor::execute(EnqueueTask& task) |
|
688 |
{ |
|
689 |
GenCollectedHeap* gch = GenCollectedHeap::heap(); |
|
690 |
WorkGang* workers = gch->workers(); |
|
691 |
assert(workers != NULL, "Need parallel worker threads."); |
|
692 |
ParNewRefEnqueueTaskProxy enq_task(task); |
|
693 |
workers->run_task(&enq_task); |
|
694 |
} |
|
695 |
||
696 |
void ParNewRefProcTaskExecutor::set_single_threaded_mode() |
|
697 |
{ |
|
698 |
_state_set.flush(); |
|
699 |
GenCollectedHeap* gch = GenCollectedHeap::heap(); |
|
700 |
gch->set_par_threads(0); // 0 ==> non-parallel. |
|
701 |
gch->save_marks(); |
|
702 |
} |
|
703 |
||
704 |
ScanClosureWithParBarrier:: |
|
705 |
ScanClosureWithParBarrier(ParNewGeneration* g, bool gc_barrier) : |
|
706 |
ScanClosure(g, gc_barrier) {} |
|
707 |
||
708 |
EvacuateFollowersClosureGeneral:: |
|
709 |
EvacuateFollowersClosureGeneral(GenCollectedHeap* gch, int level, |
|
710 |
OopsInGenClosure* cur, |
|
711 |
OopsInGenClosure* older) : |
|
712 |
_gch(gch), _level(level), |
|
713 |
_scan_cur_or_nonheap(cur), _scan_older(older) |
|
714 |
{} |
|
715 |
||
716 |
void EvacuateFollowersClosureGeneral::do_void() { |
|
717 |
do { |
|
718 |
// Beware: this call will lead to closure applications via virtual |
|
719 |
// calls. |
|
720 |
_gch->oop_since_save_marks_iterate(_level, |
|
721 |
_scan_cur_or_nonheap, |
|
722 |
_scan_older); |
|
723 |
} while (!_gch->no_allocs_since_save_marks(_level)); |
|
724 |
} |
|
725 |
||
726 |
||
727 |
bool ParNewGeneration::_avoid_promotion_undo = false; |
|
728 |
||
729 |
void ParNewGeneration::adjust_desired_tenuring_threshold() { |
|
730 |
// Set the desired survivor size to half the real survivor space |
|
731 |
_tenuring_threshold = |
|
732 |
age_table()->compute_tenuring_threshold(to()->capacity()/HeapWordSize); |
|
733 |
} |
|
734 |
||
735 |
// A Generation that does parallel young-gen collection. |
|
736 |
||
737 |
void ParNewGeneration::collect(bool full, |
|
738 |
bool clear_all_soft_refs, |
|
739 |
size_t size, |
|
740 |
bool is_tlab) { |
|
741 |
assert(full || size > 0, "otherwise we don't want to collect"); |
|
742 |
GenCollectedHeap* gch = GenCollectedHeap::heap(); |
|
743 |
assert(gch->kind() == CollectedHeap::GenCollectedHeap, |
|
744 |
"not a CMS generational heap"); |
|
745 |
AdaptiveSizePolicy* size_policy = gch->gen_policy()->size_policy(); |
|
746 |
WorkGang* workers = gch->workers(); |
|
747 |
_next_gen = gch->next_gen(this); |
|
748 |
assert(_next_gen != NULL, |
|
749 |
"This must be the youngest gen, and not the only gen"); |
|
750 |
assert(gch->n_gens() == 2, |
|
751 |
"Par collection currently only works with single older gen."); |
|
752 |
// Do we have to avoid promotion_undo? |
|
753 |
if (gch->collector_policy()->is_concurrent_mark_sweep_policy()) { |
|
754 |
set_avoid_promotion_undo(true); |
|
755 |
} |
|
756 |
||
757 |
// If the next generation is too full to accomodate worst-case promotion |
|
758 |
// from this generation, pass on collection; let the next generation |
|
759 |
// do it. |
|
760 |
if (!collection_attempt_is_safe()) { |
|
761 |
gch->set_incremental_collection_will_fail(); |
|
762 |
return; |
|
763 |
} |
|
764 |
assert(to()->is_empty(), "Else not collection_attempt_is_safe"); |
|
765 |
||
766 |
init_assuming_no_promotion_failure(); |
|
767 |
||
768 |
if (UseAdaptiveSizePolicy) { |
|
769 |
set_survivor_overflow(false); |
|
770 |
size_policy->minor_collection_begin(); |
|
771 |
} |
|
772 |
||
773 |
TraceTime t1("GC", PrintGC && !PrintGCDetails, true, gclog_or_tty); |
|
774 |
// Capture heap used before collection (for printing). |
|
775 |
size_t gch_prev_used = gch->used(); |
|
776 |
||
777 |
SpecializationStats::clear(); |
|
778 |
||
779 |
age_table()->clear(); |
|
971
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
593
diff
changeset
|
780 |
to()->clear(SpaceDecorator::Mangle); |
1 | 781 |
|
782 |
gch->save_marks(); |
|
783 |
assert(workers != NULL, "Need parallel worker threads."); |
|
784 |
ParallelTaskTerminator _term(workers->total_workers(), task_queues()); |
|
785 |
ParScanThreadStateSet thread_state_set(workers->total_workers(), |
|
786 |
*to(), *this, *_next_gen, *task_queues(), |
|
787 |
desired_plab_sz(), _term); |
|
788 |
||
789 |
ParNewGenTask tsk(this, _next_gen, reserved().end(), &thread_state_set); |
|
790 |
int n_workers = workers->total_workers(); |
|
791 |
gch->set_par_threads(n_workers); |
|
792 |
gch->change_strong_roots_parity(); |
|
793 |
gch->rem_set()->prepare_for_younger_refs_iterate(true); |
|
794 |
// It turns out that even when we're using 1 thread, doing the work in a |
|
795 |
// separate thread causes wide variance in run times. We can't help this |
|
796 |
// in the multi-threaded case, but we special-case n=1 here to get |
|
797 |
// repeatable measurements of the 1-thread overhead of the parallel code. |
|
798 |
if (n_workers > 1) { |
|
799 |
workers->run_task(&tsk); |
|
800 |
} else { |
|
801 |
tsk.work(0); |
|
802 |
} |
|
803 |
thread_state_set.reset(); |
|
804 |
||
805 |
if (PAR_STATS_ENABLED && ParallelGCVerbose) { |
|
806 |
gclog_or_tty->print("Thread totals:\n" |
|
807 |
" Pushes: %7d Pops: %7d Steals %7d (sum = %7d).\n", |
|
808 |
thread_state_set.pushes(), thread_state_set.pops(), |
|
809 |
thread_state_set.steals(), |
|
810 |
thread_state_set.pops()+thread_state_set.steals()); |
|
811 |
} |
|
1606
dcf9714addbe
6684579: SoftReference processing can be made more efficient
ysr
parents:
977
diff
changeset
|
812 |
assert(thread_state_set.pushes() == thread_state_set.pops() |
dcf9714addbe
6684579: SoftReference processing can be made more efficient
ysr
parents:
977
diff
changeset
|
813 |
+ thread_state_set.steals(), |
1 | 814 |
"Or else the queues are leaky."); |
815 |
||
816 |
// Process (weak) reference objects found during scavenge. |
|
1606
dcf9714addbe
6684579: SoftReference processing can be made more efficient
ysr
parents:
977
diff
changeset
|
817 |
ReferenceProcessor* rp = ref_processor(); |
1 | 818 |
IsAliveClosure is_alive(this); |
819 |
ScanWeakRefClosure scan_weak_ref(this); |
|
820 |
KeepAliveClosure keep_alive(&scan_weak_ref); |
|
821 |
ScanClosure scan_without_gc_barrier(this, false); |
|
822 |
ScanClosureWithParBarrier scan_with_gc_barrier(this, true); |
|
823 |
set_promo_failure_scan_stack_closure(&scan_without_gc_barrier); |
|
824 |
EvacuateFollowersClosureGeneral evacuate_followers(gch, _level, |
|
825 |
&scan_without_gc_barrier, &scan_with_gc_barrier); |
|
1610
5dddd195cc86
6778647: snap(), snap_policy() should be renamed setup(), setup_policy()
ysr
parents:
1607
diff
changeset
|
826 |
rp->setup_policy(clear_all_soft_refs); |
1606
dcf9714addbe
6684579: SoftReference processing can be made more efficient
ysr
parents:
977
diff
changeset
|
827 |
if (rp->processing_is_mt()) { |
1 | 828 |
ParNewRefProcTaskExecutor task_executor(*this, thread_state_set); |
1606
dcf9714addbe
6684579: SoftReference processing can be made more efficient
ysr
parents:
977
diff
changeset
|
829 |
rp->process_discovered_references(&is_alive, &keep_alive, |
dcf9714addbe
6684579: SoftReference processing can be made more efficient
ysr
parents:
977
diff
changeset
|
830 |
&evacuate_followers, &task_executor); |
1 | 831 |
} else { |
832 |
thread_state_set.flush(); |
|
833 |
gch->set_par_threads(0); // 0 ==> non-parallel. |
|
834 |
gch->save_marks(); |
|
1606
dcf9714addbe
6684579: SoftReference processing can be made more efficient
ysr
parents:
977
diff
changeset
|
835 |
rp->process_discovered_references(&is_alive, &keep_alive, |
dcf9714addbe
6684579: SoftReference processing can be made more efficient
ysr
parents:
977
diff
changeset
|
836 |
&evacuate_followers, NULL); |
1 | 837 |
} |
838 |
if (!promotion_failed()) { |
|
839 |
// Swap the survivor spaces. |
|
971
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
593
diff
changeset
|
840 |
eden()->clear(SpaceDecorator::Mangle); |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
593
diff
changeset
|
841 |
from()->clear(SpaceDecorator::Mangle); |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
593
diff
changeset
|
842 |
if (ZapUnusedHeapArea) { |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
593
diff
changeset
|
843 |
// This is now done here because of the piece-meal mangling which |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
593
diff
changeset
|
844 |
// can check for valid mangling at intermediate points in the |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
593
diff
changeset
|
845 |
// collection(s). When a minor collection fails to collect |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
593
diff
changeset
|
846 |
// sufficient space resizing of the young generation can occur |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
593
diff
changeset
|
847 |
// an redistribute the spaces in the young generation. Mangle |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
593
diff
changeset
|
848 |
// here so that unzapped regions don't get distributed to |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
593
diff
changeset
|
849 |
// other spaces. |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
593
diff
changeset
|
850 |
to()->mangle_unused_area(); |
f0b20be4165d
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
593
diff
changeset
|
851 |
} |
1 | 852 |
swap_spaces(); |
853 |
||
854 |
assert(to()->is_empty(), "to space should be empty now"); |
|
855 |
} else { |
|
856 |
assert(HandlePromotionFailure, |
|
857 |
"Should only be here if promotion failure handling is on"); |
|
858 |
if (_promo_failure_scan_stack != NULL) { |
|
859 |
// Can be non-null because of reference processing. |
|
860 |
// Free stack with its elements. |
|
861 |
delete _promo_failure_scan_stack; |
|
862 |
_promo_failure_scan_stack = NULL; |
|
863 |
} |
|
864 |
remove_forwarding_pointers(); |
|
865 |
if (PrintGCDetails) { |
|
866 |
gclog_or_tty->print(" (promotion failed)"); |
|
867 |
} |
|
868 |
// All the spaces are in play for mark-sweep. |
|
869 |
swap_spaces(); // Make life simpler for CMS || rescan; see 6483690. |
|
870 |
from()->set_next_compaction_space(to()); |
|
871 |
gch->set_incremental_collection_will_fail(); |
|
179
59e3abf83f72
6624765: Guarantee failure "Unexpected dirty card found"
jmasa
parents:
1
diff
changeset
|
872 |
|
59e3abf83f72
6624765: Guarantee failure "Unexpected dirty card found"
jmasa
parents:
1
diff
changeset
|
873 |
// Reset the PromotionFailureALot counters. |
59e3abf83f72
6624765: Guarantee failure "Unexpected dirty card found"
jmasa
parents:
1
diff
changeset
|
874 |
NOT_PRODUCT(Universe::heap()->reset_promotion_should_fail();) |
1 | 875 |
} |
876 |
// set new iteration safe limit for the survivor spaces |
|
877 |
from()->set_concurrent_iteration_safe_limit(from()->top()); |
|
878 |
to()->set_concurrent_iteration_safe_limit(to()->top()); |
|
879 |
||
880 |
adjust_desired_tenuring_threshold(); |
|
881 |
if (ResizePLAB) { |
|
882 |
plab_stats()->adjust_desired_plab_sz(); |
|
883 |
} |
|
884 |
||
885 |
if (PrintGC && !PrintGCDetails) { |
|
886 |
gch->print_heap_change(gch_prev_used); |
|
887 |
} |
|
888 |
||
889 |
if (UseAdaptiveSizePolicy) { |
|
890 |
size_policy->minor_collection_end(gch->gc_cause()); |
|
891 |
size_policy->avg_survived()->sample(from()->used()); |
|
892 |
} |
|
893 |
||
894 |
update_time_of_last_gc(os::javaTimeMillis()); |
|
895 |
||
896 |
SpecializationStats::print(); |
|
897 |
||
1606
dcf9714addbe
6684579: SoftReference processing can be made more efficient
ysr
parents:
977
diff
changeset
|
898 |
rp->set_enqueuing_is_done(true); |
dcf9714addbe
6684579: SoftReference processing can be made more efficient
ysr
parents:
977
diff
changeset
|
899 |
if (rp->processing_is_mt()) { |
1 | 900 |
ParNewRefProcTaskExecutor task_executor(*this, thread_state_set); |
1606
dcf9714addbe
6684579: SoftReference processing can be made more efficient
ysr
parents:
977
diff
changeset
|
901 |
rp->enqueue_discovered_references(&task_executor); |
1 | 902 |
} else { |
1606
dcf9714addbe
6684579: SoftReference processing can be made more efficient
ysr
parents:
977
diff
changeset
|
903 |
rp->enqueue_discovered_references(NULL); |
1 | 904 |
} |
1606
dcf9714addbe
6684579: SoftReference processing can be made more efficient
ysr
parents:
977
diff
changeset
|
905 |
rp->verify_no_references_recorded(); |
1 | 906 |
} |
907 |
||
908 |
static int sum; |
|
909 |
void ParNewGeneration::waste_some_time() { |
|
910 |
for (int i = 0; i < 100; i++) { |
|
911 |
sum += i; |
|
912 |
} |
|
913 |
} |
|
914 |
||
915 |
static const oop ClaimedForwardPtr = oop(0x4); |
|
916 |
||
917 |
// Because of concurrency, there are times where an object for which |
|
918 |
// "is_forwarded()" is true contains an "interim" forwarding pointer |
|
919 |
// value. Such a value will soon be overwritten with a real value. |
|
920 |
// This method requires "obj" to have a forwarding pointer, and waits, if |
|
921 |
// necessary for a real one to be inserted, and returns it. |
|
922 |
||
923 |
oop ParNewGeneration::real_forwardee(oop obj) { |
|
924 |
oop forward_ptr = obj->forwardee(); |
|
925 |
if (forward_ptr != ClaimedForwardPtr) { |
|
926 |
return forward_ptr; |
|
927 |
} else { |
|
928 |
return real_forwardee_slow(obj); |
|
929 |
} |
|
930 |
} |
|
931 |
||
932 |
oop ParNewGeneration::real_forwardee_slow(oop obj) { |
|
933 |
// Spin-read if it is claimed but not yet written by another thread. |
|
934 |
oop forward_ptr = obj->forwardee(); |
|
935 |
while (forward_ptr == ClaimedForwardPtr) { |
|
936 |
waste_some_time(); |
|
937 |
assert(obj->is_forwarded(), "precondition"); |
|
938 |
forward_ptr = obj->forwardee(); |
|
939 |
} |
|
940 |
return forward_ptr; |
|
941 |
} |
|
942 |
||
943 |
#ifdef ASSERT |
|
944 |
bool ParNewGeneration::is_legal_forward_ptr(oop p) { |
|
945 |
return |
|
946 |
(_avoid_promotion_undo && p == ClaimedForwardPtr) |
|
947 |
|| Universe::heap()->is_in_reserved(p); |
|
948 |
} |
|
949 |
#endif |
|
950 |
||
951 |
void ParNewGeneration::preserve_mark_if_necessary(oop obj, markOop m) { |
|
952 |
if ((m != markOopDesc::prototype()) && |
|
953 |
(!UseBiasedLocking || (m != markOopDesc::biased_locking_prototype()))) { |
|
954 |
MutexLocker ml(ParGCRareEvent_lock); |
|
955 |
DefNewGeneration::preserve_mark_if_necessary(obj, m); |
|
956 |
} |
|
957 |
} |
|
958 |
||
959 |
// Multiple GC threads may try to promote an object. If the object |
|
960 |
// is successfully promoted, a forwarding pointer will be installed in |
|
961 |
// the object in the young generation. This method claims the right |
|
962 |
// to install the forwarding pointer before it copies the object, |
|
963 |
// thus avoiding the need to undo the copy as in |
|
964 |
// copy_to_survivor_space_avoiding_with_undo. |
|
965 |
||
966 |
oop ParNewGeneration::copy_to_survivor_space_avoiding_promotion_undo( |
|
967 |
ParScanThreadState* par_scan_state, oop old, size_t sz, markOop m) { |
|
968 |
// In the sequential version, this assert also says that the object is |
|
969 |
// not forwarded. That might not be the case here. It is the case that |
|
970 |
// the caller observed it to be not forwarded at some time in the past. |
|
971 |
assert(is_in_reserved(old), "shouldn't be scavenging this oop"); |
|
972 |
||
973 |
// The sequential code read "old->age()" below. That doesn't work here, |
|
974 |
// since the age is in the mark word, and that might be overwritten with |
|
975 |
// a forwarding pointer by a parallel thread. So we must save the mark |
|
976 |
// word in a local and then analyze it. |
|
977 |
oopDesc dummyOld; |
|
978 |
dummyOld.set_mark(m); |
|
979 |
assert(!dummyOld.is_forwarded(), |
|
980 |
"should not be called with forwarding pointer mark word."); |
|
981 |
||
982 |
oop new_obj = NULL; |
|
983 |
oop forward_ptr; |
|
984 |
||
985 |
// Try allocating obj in to-space (unless too old) |
|
986 |
if (dummyOld.age() < tenuring_threshold()) { |
|
987 |
new_obj = (oop)par_scan_state->alloc_in_to_space(sz); |
|
988 |
if (new_obj == NULL) { |
|
989 |
set_survivor_overflow(true); |
|
990 |
} |
|
991 |
} |
|
992 |
||
993 |
if (new_obj == NULL) { |
|
994 |
// Either to-space is full or we decided to promote |
|
995 |
// try allocating obj tenured |
|
996 |
||
997 |
// Attempt to install a null forwarding pointer (atomically), |
|
998 |
// to claim the right to install the real forwarding pointer. |
|
999 |
forward_ptr = old->forward_to_atomic(ClaimedForwardPtr); |
|
1000 |
if (forward_ptr != NULL) { |
|
1001 |
// someone else beat us to it. |
|
1002 |
return real_forwardee(old); |
|
1003 |
} |
|
1004 |
||
1005 |
new_obj = _next_gen->par_promote(par_scan_state->thread_num(), |
|
1006 |
old, m, sz); |
|
1007 |
||
1008 |
if (new_obj == NULL) { |
|
1009 |
if (!HandlePromotionFailure) { |
|
1010 |
// A failed promotion likely means the MaxLiveObjectEvacuationRatio flag |
|
1011 |
// is incorrectly set. In any case, its seriously wrong to be here! |
|
1012 |
vm_exit_out_of_memory(sz*wordSize, "promotion"); |
|
1013 |
} |
|
1014 |
// promotion failed, forward to self |
|
1015 |
_promotion_failed = true; |
|
1016 |
new_obj = old; |
|
1017 |
||
1018 |
preserve_mark_if_necessary(old, m); |
|
1019 |
} |
|
1020 |
||
1021 |
old->forward_to(new_obj); |
|
1022 |
forward_ptr = NULL; |
|
1023 |
} else { |
|
1024 |
// Is in to-space; do copying ourselves. |
|
1025 |
Copy::aligned_disjoint_words((HeapWord*)old, (HeapWord*)new_obj, sz); |
|
1026 |
forward_ptr = old->forward_to_atomic(new_obj); |
|
1027 |
// Restore the mark word copied above. |
|
1028 |
new_obj->set_mark(m); |
|
1029 |
// Increment age if obj still in new generation |
|
1030 |
new_obj->incr_age(); |
|
1031 |
par_scan_state->age_table()->add(new_obj, sz); |
|
1032 |
} |
|
1033 |
assert(new_obj != NULL, "just checking"); |
|
1034 |
||
1035 |
if (forward_ptr == NULL) { |
|
1036 |
oop obj_to_push = new_obj; |
|
1037 |
if (par_scan_state->should_be_partially_scanned(obj_to_push, old)) { |
|
1038 |
// Length field used as index of next element to be scanned. |
|
1039 |
// Real length can be obtained from real_forwardee() |
|
1040 |
arrayOop(old)->set_length(0); |
|
1041 |
obj_to_push = old; |
|
1042 |
assert(obj_to_push->is_forwarded() && obj_to_push->forwardee() != obj_to_push, |
|
1043 |
"push forwarded object"); |
|
1044 |
} |
|
1045 |
// Push it on one of the queues of to-be-scanned objects. |
|
1910 | 1046 |
bool simulate_overflow = false; |
1047 |
NOT_PRODUCT( |
|
1048 |
if (ParGCWorkQueueOverflowALot && should_simulate_overflow()) { |
|
1049 |
// simulate a stack overflow |
|
1050 |
simulate_overflow = true; |
|
1051 |
} |
|
1052 |
) |
|
1053 |
if (simulate_overflow || !par_scan_state->work_queue()->push(obj_to_push)) { |
|
1 | 1054 |
// Add stats for overflow pushes. |
1055 |
if (Verbose && PrintGCDetails) { |
|
1056 |
gclog_or_tty->print("queue overflow!\n"); |
|
1057 |
} |
|
1910 | 1058 |
push_on_overflow_list(old, par_scan_state); |
1 | 1059 |
par_scan_state->note_overflow_push(); |
1060 |
} |
|
1061 |
par_scan_state->note_push(); |
|
1062 |
||
1063 |
return new_obj; |
|
1064 |
} |
|
1065 |
||
1066 |
// Oops. Someone beat us to it. Undo the allocation. Where did we |
|
1067 |
// allocate it? |
|
1068 |
if (is_in_reserved(new_obj)) { |
|
1069 |
// Must be in to_space. |
|
1070 |
assert(to()->is_in_reserved(new_obj), "Checking"); |
|
1071 |
if (forward_ptr == ClaimedForwardPtr) { |
|
1072 |
// Wait to get the real forwarding pointer value. |
|
1073 |
forward_ptr = real_forwardee(old); |
|
1074 |
} |
|
1075 |
par_scan_state->undo_alloc_in_to_space((HeapWord*)new_obj, sz); |
|
1076 |
} |
|
1077 |
||
1078 |
return forward_ptr; |
|
1079 |
} |
|
1080 |
||
1081 |
||
1082 |
// Multiple GC threads may try to promote the same object. If two |
|
1083 |
// or more GC threads copy the object, only one wins the race to install |
|
1084 |
// the forwarding pointer. The other threads have to undo their copy. |
|
1085 |
||
1086 |
oop ParNewGeneration::copy_to_survivor_space_with_undo( |
|
1087 |
ParScanThreadState* par_scan_state, oop old, size_t sz, markOop m) { |
|
1088 |
||
1089 |
// In the sequential version, this assert also says that the object is |
|
1090 |
// not forwarded. That might not be the case here. It is the case that |
|
1091 |
// the caller observed it to be not forwarded at some time in the past. |
|
1092 |
assert(is_in_reserved(old), "shouldn't be scavenging this oop"); |
|
1093 |
||
1094 |
// The sequential code read "old->age()" below. That doesn't work here, |
|
1095 |
// since the age is in the mark word, and that might be overwritten with |
|
1096 |
// a forwarding pointer by a parallel thread. So we must save the mark |
|
1097 |
// word here, install it in a local oopDesc, and then analyze it. |
|
1098 |
oopDesc dummyOld; |
|
1099 |
dummyOld.set_mark(m); |
|
1100 |
assert(!dummyOld.is_forwarded(), |
|
1101 |
"should not be called with forwarding pointer mark word."); |
|
1102 |
||
1103 |
bool failed_to_promote = false; |
|
1104 |
oop new_obj = NULL; |
|
1105 |
oop forward_ptr; |
|
1106 |
||
1107 |
// Try allocating obj in to-space (unless too old) |
|
1108 |
if (dummyOld.age() < tenuring_threshold()) { |
|
1109 |
new_obj = (oop)par_scan_state->alloc_in_to_space(sz); |
|
1110 |
if (new_obj == NULL) { |
|
1111 |
set_survivor_overflow(true); |
|
1112 |
} |
|
1113 |
} |
|
1114 |
||
1115 |
if (new_obj == NULL) { |
|
1116 |
// Either to-space is full or we decided to promote |
|
1117 |
// try allocating obj tenured |
|
1118 |
new_obj = _next_gen->par_promote(par_scan_state->thread_num(), |
|
1119 |
old, m, sz); |
|
1120 |
||
1121 |
if (new_obj == NULL) { |
|
1122 |
if (!HandlePromotionFailure) { |
|
1123 |
// A failed promotion likely means the MaxLiveObjectEvacuationRatio |
|
1124 |
// flag is incorrectly set. In any case, its seriously wrong to be |
|
1125 |
// here! |
|
1126 |
vm_exit_out_of_memory(sz*wordSize, "promotion"); |
|
1127 |
} |
|
1128 |
// promotion failed, forward to self |
|
1129 |
forward_ptr = old->forward_to_atomic(old); |
|
1130 |
new_obj = old; |
|
1131 |
||
1132 |
if (forward_ptr != NULL) { |
|
1133 |
return forward_ptr; // someone else succeeded |
|
1134 |
} |
|
1135 |
||
1136 |
_promotion_failed = true; |
|
1137 |
failed_to_promote = true; |
|
1138 |
||
1139 |
preserve_mark_if_necessary(old, m); |
|
1140 |
} |
|
1141 |
} else { |
|
1142 |
// Is in to-space; do copying ourselves. |
|
1143 |
Copy::aligned_disjoint_words((HeapWord*)old, (HeapWord*)new_obj, sz); |
|
1144 |
// Restore the mark word copied above. |
|
1145 |
new_obj->set_mark(m); |
|
1146 |
// Increment age if new_obj still in new generation |
|
1147 |
new_obj->incr_age(); |
|
1148 |
par_scan_state->age_table()->add(new_obj, sz); |
|
1149 |
} |
|
1150 |
assert(new_obj != NULL, "just checking"); |
|
1151 |
||
1152 |
// Now attempt to install the forwarding pointer (atomically). |
|
1153 |
// We have to copy the mark word before overwriting with forwarding |
|
1154 |
// ptr, so we can restore it below in the copy. |
|
1155 |
if (!failed_to_promote) { |
|
1156 |
forward_ptr = old->forward_to_atomic(new_obj); |
|
1157 |
} |
|
1158 |
||
1159 |
if (forward_ptr == NULL) { |
|
1160 |
oop obj_to_push = new_obj; |
|
1161 |
if (par_scan_state->should_be_partially_scanned(obj_to_push, old)) { |
|
1162 |
// Length field used as index of next element to be scanned. |
|
1163 |
// Real length can be obtained from real_forwardee() |
|
1164 |
arrayOop(old)->set_length(0); |
|
1165 |
obj_to_push = old; |
|
1166 |
assert(obj_to_push->is_forwarded() && obj_to_push->forwardee() != obj_to_push, |
|
1167 |
"push forwarded object"); |
|
1168 |
} |
|
1169 |
// Push it on one of the queues of to-be-scanned objects. |
|
1910 | 1170 |
bool simulate_overflow = false; |
1171 |
NOT_PRODUCT( |
|
1172 |
if (ParGCWorkQueueOverflowALot && should_simulate_overflow()) { |
|
1173 |
// simulate a stack overflow |
|
1174 |
simulate_overflow = true; |
|
1175 |
} |
|
1176 |
) |
|
1177 |
if (simulate_overflow || !par_scan_state->work_queue()->push(obj_to_push)) { |
|
1 | 1178 |
// Add stats for overflow pushes. |
1910 | 1179 |
push_on_overflow_list(old, par_scan_state); |
1 | 1180 |
par_scan_state->note_overflow_push(); |
1181 |
} |
|
1182 |
par_scan_state->note_push(); |
|
1183 |
||
1184 |
return new_obj; |
|
1185 |
} |
|
1186 |
||
1187 |
// Oops. Someone beat us to it. Undo the allocation. Where did we |
|
1188 |
// allocate it? |
|
1189 |
if (is_in_reserved(new_obj)) { |
|
1190 |
// Must be in to_space. |
|
1191 |
assert(to()->is_in_reserved(new_obj), "Checking"); |
|
1192 |
par_scan_state->undo_alloc_in_to_space((HeapWord*)new_obj, sz); |
|
1193 |
} else { |
|
1194 |
assert(!_avoid_promotion_undo, "Should not be here if avoiding."); |
|
1195 |
_next_gen->par_promote_alloc_undo(par_scan_state->thread_num(), |
|
1196 |
(HeapWord*)new_obj, sz); |
|
1197 |
} |
|
1198 |
||
1199 |
return forward_ptr; |
|
1200 |
} |
|
1201 |
||
1910 | 1202 |
#ifndef PRODUCT |
1203 |
// It's OK to call this multi-threaded; the worst thing |
|
1204 |
// that can happen is that we'll get a bunch of closely |
|
1205 |
// spaced simulated oveflows, but that's OK, in fact |
|
1206 |
// probably good as it would exercise the overflow code |
|
1207 |
// under contention. |
|
1208 |
bool ParNewGeneration::should_simulate_overflow() { |
|
1209 |
if (_overflow_counter-- <= 0) { // just being defensive |
|
1210 |
_overflow_counter = ParGCWorkQueueOverflowInterval; |
|
1211 |
return true; |
|
1212 |
} else { |
|
1213 |
return false; |
|
1214 |
} |
|
1215 |
} |
|
1216 |
#endif |
|
1217 |
||
2346
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1218 |
// In case we are using compressed oops, we need to be careful. |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1219 |
// If the object being pushed is an object array, then its length |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1220 |
// field keeps track of the "grey boundary" at which the next |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1221 |
// incremental scan will be done (see ParGCArrayScanChunk). |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1222 |
// When using compressed oops, this length field is kept in the |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1223 |
// lower 32 bits of the erstwhile klass word and cannot be used |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1224 |
// for the overflow chaining pointer (OCP below). As such the OCP |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1225 |
// would itself need to be compressed into the top 32-bits in this |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1226 |
// case. Unfortunately, see below, in the event that we have a |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1227 |
// promotion failure, the node to be pushed on the list can be |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1228 |
// outside of the Java heap, so the heap-based pointer compression |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1229 |
// would not work (we would have potential aliasing between C-heap |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1230 |
// and Java-heap pointers). For this reason, when using compressed |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1231 |
// oops, we simply use a worker-thread-local, non-shared overflow |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1232 |
// list in the form of a growable array, with a slightly different |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1233 |
// overflow stack draining strategy. If/when we start using fat |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1234 |
// stacks here, we can go back to using (fat) pointer chains |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1235 |
// (although some performance comparisons would be useful since |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1236 |
// single global lists have their own performance disadvantages |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1237 |
// as we were made painfully aware not long ago, see 6786503). |
1910 | 1238 |
#define BUSY (oop(0x1aff1aff)) |
1239 |
void ParNewGeneration::push_on_overflow_list(oop from_space_obj, ParScanThreadState* par_scan_state) { |
|
2346
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1240 |
assert(is_in_reserved(from_space_obj), "Should be from this generation"); |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1241 |
if (UseCompressedOops) { |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1242 |
// In the case of compressed oops, we use a private, not-shared |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1243 |
// overflow stack. |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1244 |
par_scan_state->push_on_overflow_stack(from_space_obj); |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1245 |
} else { |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1246 |
// if the object has been forwarded to itself, then we cannot |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1247 |
// use the klass pointer for the linked list. Instead we have |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1248 |
// to allocate an oopDesc in the C-Heap and use that for the linked list. |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1249 |
// XXX This is horribly inefficient when a promotion failure occurs |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1250 |
// and should be fixed. XXX FIX ME !!! |
1910 | 1251 |
#ifndef PRODUCT |
2346
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1252 |
Atomic::inc_ptr(&_num_par_pushes); |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1253 |
assert(_num_par_pushes > 0, "Tautology"); |
1910 | 1254 |
#endif |
2346
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1255 |
if (from_space_obj->forwardee() == from_space_obj) { |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1256 |
oopDesc* listhead = NEW_C_HEAP_ARRAY(oopDesc, 1); |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1257 |
listhead->forward_to(from_space_obj); |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1258 |
from_space_obj = listhead; |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1259 |
} |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1260 |
oop observed_overflow_list = _overflow_list; |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1261 |
oop cur_overflow_list; |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1262 |
do { |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1263 |
cur_overflow_list = observed_overflow_list; |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1264 |
if (cur_overflow_list != BUSY) { |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1265 |
from_space_obj->set_klass_to_list_ptr(cur_overflow_list); |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1266 |
} else { |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1267 |
from_space_obj->set_klass_to_list_ptr(NULL); |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1268 |
} |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1269 |
observed_overflow_list = |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1270 |
(oop)Atomic::cmpxchg_ptr(from_space_obj, &_overflow_list, cur_overflow_list); |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1271 |
} while (cur_overflow_list != observed_overflow_list); |
1 | 1272 |
} |
1273 |
} |
|
1274 |
||
2346
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1275 |
bool ParNewGeneration::take_from_overflow_list(ParScanThreadState* par_scan_state) { |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1276 |
bool res; |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1277 |
|
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1278 |
if (UseCompressedOops) { |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1279 |
res = par_scan_state->take_from_overflow_stack(); |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1280 |
} else { |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1281 |
res = take_from_overflow_list_work(par_scan_state); |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1282 |
} |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1283 |
return res; |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1284 |
} |
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1285 |
|
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1286 |
|
1910 | 1287 |
// *NOTE*: The overflow list manipulation code here and |
1288 |
// in CMSCollector:: are very similar in shape, |
|
1289 |
// except that in the CMS case we thread the objects |
|
1290 |
// directly into the list via their mark word, and do |
|
1291 |
// not need to deal with special cases below related |
|
1292 |
// to chunking of object arrays and promotion failure |
|
1293 |
// handling. |
|
1294 |
// CR 6797058 has been filed to attempt consolidation of |
|
1295 |
// the common code. |
|
1296 |
// Because of the common code, if you make any changes in |
|
1297 |
// the code below, please check the CMS version to see if |
|
1298 |
// similar changes might be needed. |
|
1299 |
// See CMSCollector::par_take_from_overflow_list() for |
|
1300 |
// more extensive documentation comments. |
|
2346
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1301 |
bool ParNewGeneration::take_from_overflow_list_work(ParScanThreadState* par_scan_state) { |
1 | 1302 |
ObjToScanQueue* work_q = par_scan_state->work_queue(); |
1303 |
// How many to take? |
|
2346
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1304 |
size_t objsFromOverflow = MIN2((size_t)(work_q->max_elems() - work_q->size())/4, |
1910 | 1305 |
(size_t)ParGCDesiredObjsFromOverflowList); |
1 | 1306 |
|
2346
3aa355016e90
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
2105
diff
changeset
|
1307 |
assert(par_scan_state->overflow_stack() == NULL, "Error"); |
1 | 1308 |
if (_overflow_list == NULL) return false; |
1309 |
||
1310 |
// Otherwise, there was something there; try claiming the list. |
|
1910 | 1311 |
oop prefix = (oop)Atomic::xchg_ptr(BUSY, &_overflow_list); |
1312 |
// Trim off a prefix of at most objsFromOverflow items |
|
1313 |
Thread* tid = Thread::current(); |
|
1314 |
size_t spin_count = (size_t)ParallelGCThreads; |
|
1315 |
size_t sleep_time_millis = MAX2((size_t)1, objsFromOverflow/100); |
|
1316 |
for (size_t spin = 0; prefix == BUSY && spin < spin_count; spin++) { |
|
1317 |
// someone grabbed it before we did ... |
|
1318 |
// ... we spin for a short while... |
|
1319 |
os::sleep(tid, sleep_time_millis, false); |
|
1320 |
if (_overflow_list == NULL) { |
|
1321 |
// nothing left to take |
|
1322 |
return false; |
|
1323 |
} else if (_overflow_list != BUSY) { |
|
1324 |
// try and grab the prefix |
|
1325 |
prefix = (oop)Atomic::xchg_ptr(BUSY, &_overflow_list); |
|
1326 |
} |
|
1 | 1327 |
} |
1910 | 1328 |
if (prefix == NULL || prefix == BUSY) { |
1329 |
// Nothing to take or waited long enough |
|
1330 |
if (prefix == NULL) { |
|
1331 |
// Write back the NULL in case we overwrote it with BUSY above |
|
1332 |
// and it is still the same value. |
|
1333 |
(void) Atomic::cmpxchg_ptr(NULL, &_overflow_list, BUSY); |
|
1334 |
} |
|
1335 |
return false; |
|
1336 |
} |
|
1337 |
assert(prefix != NULL && prefix != BUSY, "Error"); |
|
1338 |
size_t i = 1; |
|
1 | 1339 |
oop cur = prefix; |
593
803947e176bd
6696264: assert("narrow oop can never be zero") for GCBasher & ParNewGC
coleenp
parents:
360
diff
changeset
|
1340 |
while (i < objsFromOverflow && cur->klass_or_null() != NULL) { |
1 | 1341 |
i++; cur = oop(cur->klass()); |
1342 |
} |
|
1343 |
||
1344 |
// Reattach remaining (suffix) to overflow list |
|
1910 | 1345 |
if (cur->klass_or_null() == NULL) { |
1346 |
// Write back the NULL in lieu of the BUSY we wrote |
|
1347 |
// above and it is still the same value. |
|
1348 |
if (_overflow_list == BUSY) { |
|
1349 |
(void) Atomic::cmpxchg_ptr(NULL, &_overflow_list, BUSY); |
|
1 | 1350 |
} |
1910 | 1351 |
} else { |
1352 |
assert(cur->klass_or_null() != BUSY, "Error"); |
|
1353 |
oop suffix = oop(cur->klass()); // suffix will be put back on global list |
|
1354 |
cur->set_klass_to_list_ptr(NULL); // break off suffix |
|
1355 |
// It's possible that the list is still in the empty(busy) state |
|
1356 |
// we left it in a short while ago; in that case we may be |
|
1357 |
// able to place back the suffix. |
|
1358 |
oop observed_overflow_list = _overflow_list; |
|
1359 |
oop cur_overflow_list = observed_overflow_list; |
|
1360 |
bool attached = false; |
|
1361 |
while (observed_overflow_list == BUSY || observed_overflow_list == NULL) { |
|
1362 |
observed_overflow_list = |
|
1363 |
(oop) Atomic::cmpxchg_ptr(suffix, &_overflow_list, cur_overflow_list); |
|
1364 |
if (cur_overflow_list == observed_overflow_list) { |
|
1365 |
attached = true; |
|
1366 |
break; |
|
1367 |
} else cur_overflow_list = observed_overflow_list; |
|
1368 |
} |
|
1369 |
if (!attached) { |
|
1370 |
// Too bad, someone else got in in between; we'll need to do a splice. |
|
1371 |
// Find the last item of suffix list |
|
1372 |
oop last = suffix; |
|
1373 |
while (last->klass_or_null() != NULL) { |
|
1374 |
last = oop(last->klass()); |
|
1375 |
} |
|
1376 |
// Atomically prepend suffix to current overflow list |
|
1377 |
observed_overflow_list = _overflow_list; |
|
1378 |
do { |
|
1379 |
cur_overflow_list = observed_overflow_list; |
|
1380 |
if (cur_overflow_list != BUSY) { |
|
1381 |
// Do the splice ... |
|
1382 |
last->set_klass_to_list_ptr(cur_overflow_list); |
|
1383 |
} else { // cur_overflow_list == BUSY |
|
1384 |
last->set_klass_to_list_ptr(NULL); |
|
1385 |
} |
|
1386 |
observed_overflow_list = |
|
1387 |
(oop)Atomic::cmpxchg_ptr(suffix, &_overflow_list, cur_overflow_list); |
|
1388 |
} while (cur_overflow_list != observed_overflow_list); |
|
1 | 1389 |
} |
1390 |
} |
|
1391 |
||
1392 |
// Push objects on prefix list onto this thread's work queue |
|
1910 | 1393 |
assert(prefix != NULL && prefix != BUSY, "program logic"); |
1 | 1394 |
cur = prefix; |
1910 | 1395 |
ssize_t n = 0; |
1 | 1396 |
while (cur != NULL) { |
1397 |
oop obj_to_push = cur->forwardee(); |
|
1607
be7d05bc07b2
6774607: SIGSEGV or (!is_null(v),"oop value can never be zero") assertion when running with CMS and COOPs
ysr
parents:
1606
diff
changeset
|
1398 |
oop next = oop(cur->klass_or_null()); |
1 | 1399 |
cur->set_klass(obj_to_push->klass()); |
1910 | 1400 |
// This may be an array object that is self-forwarded. In that case, the list pointer |
1401 |
// space, cur, is not in the Java heap, but rather in the C-heap and should be freed. |
|
1402 |
if (!is_in_reserved(cur)) { |
|
1403 |
// This can become a scaling bottleneck when there is work queue overflow coincident |
|
1404 |
// with promotion failure. |
|
1405 |
oopDesc* f = cur; |
|
1406 |
FREE_C_HEAP_ARRAY(oopDesc, f); |
|
1407 |
} else if (par_scan_state->should_be_partially_scanned(obj_to_push, cur)) { |
|
1 | 1408 |
assert(arrayOop(cur)->length() == 0, "entire array remaining to be scanned"); |
1910 | 1409 |
obj_to_push = cur; |
1 | 1410 |
} |
1910 | 1411 |
bool ok = work_q->push(obj_to_push); |
1412 |
assert(ok, "Should have succeeded"); |
|
1 | 1413 |
cur = next; |
1414 |
n++; |
|
1415 |
} |
|
1416 |
par_scan_state->note_overflow_refill(n); |
|
1910 | 1417 |
#ifndef PRODUCT |
1418 |
assert(_num_par_pushes >= n, "Too many pops?"); |
|
1419 |
Atomic::add_ptr(-(intptr_t)n, &_num_par_pushes); |
|
1420 |
#endif |
|
1 | 1421 |
return true; |
1422 |
} |
|
1910 | 1423 |
#undef BUSY |
1 | 1424 |
|
1425 |
void ParNewGeneration::ref_processor_init() |
|
1426 |
{ |
|
1427 |
if (_ref_processor == NULL) { |
|
1428 |
// Allocate and initialize a reference processor |
|
1429 |
_ref_processor = ReferenceProcessor::create_ref_processor( |
|
1430 |
_reserved, // span |
|
1431 |
refs_discovery_is_atomic(), // atomic_discovery |
|
1432 |
refs_discovery_is_mt(), // mt_discovery |
|
1433 |
NULL, // is_alive_non_header |
|
1434 |
ParallelGCThreads, |
|
1435 |
ParallelRefProcEnabled); |
|
1436 |
} |
|
1437 |
} |
|
1438 |
||
1439 |
const char* ParNewGeneration::name() const { |
|
1440 |
return "par new generation"; |
|
1441 |
} |