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