Mercurial > hg > truffle
annotate src/share/vm/gc_implementation/parNew/parNewGeneration.cpp @ 997:46b819ba120b
Merge
author | jrose |
---|---|
date | Wed, 30 Sep 2009 13:25:39 -0700 |
parents | 148e5441d916 |
children | e018e6884bd8 |
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(), | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
695
diff
changeset
|
483 true, // Process younger gens, if any, |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
695
diff
changeset
|
484 // as strong roots. |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
695
diff
changeset
|
485 false, // no scope; this is parallel code |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
695
diff
changeset
|
486 false, // not collecting perm generation. |
0 | 487 SharedHeap::SO_AllClasses, |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
695
diff
changeset
|
488 &par_scan_state.to_space_root_closure(), |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
695
diff
changeset
|
489 true, // walk *all* scavengable nmethods |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
695
diff
changeset
|
490 &par_scan_state.older_gen_closure()); |
0 | 491 par_scan_state.end_strong_roots(); |
492 | |
493 // "evacuate followers". | |
494 par_scan_state.evacuate_followers_closure().do_void(); | |
495 } | |
496 | |
497 #ifdef _MSC_VER | |
498 #pragma warning( push ) | |
499 #pragma warning( disable:4355 ) // 'this' : used in base member initializer list | |
500 #endif | |
501 ParNewGeneration:: | |
502 ParNewGeneration(ReservedSpace rs, size_t initial_byte_size, int level) | |
503 : DefNewGeneration(rs, initial_byte_size, level, "PCopy"), | |
504 _overflow_list(NULL), | |
505 _is_alive_closure(this), | |
506 _plab_stats(YoungPLABSize, PLABWeight) | |
507 { | |
534 | 508 NOT_PRODUCT(_overflow_counter = ParGCWorkQueueOverflowInterval;) |
509 NOT_PRODUCT(_num_par_pushes = 0;) | |
0 | 510 _task_queues = new ObjToScanQueueSet(ParallelGCThreads); |
511 guarantee(_task_queues != NULL, "task_queues allocation failure."); | |
512 | |
513 for (uint i1 = 0; i1 < ParallelGCThreads; i1++) { | |
514 ObjToScanQueuePadded *q_padded = new ObjToScanQueuePadded(); | |
515 guarantee(q_padded != NULL, "work_queue Allocation failure."); | |
516 | |
517 _task_queues->register_queue(i1, &q_padded->work_queue); | |
518 } | |
519 | |
520 for (uint i2 = 0; i2 < ParallelGCThreads; i2++) | |
521 _task_queues->queue(i2)->initialize(); | |
522 | |
695 | 523 _overflow_stacks = NEW_C_HEAP_ARRAY(GrowableArray<oop>*, ParallelGCThreads); |
524 guarantee(_overflow_stacks != NULL, "Overflow stack set allocation failure"); | |
525 for (uint i = 0; i < ParallelGCThreads; i++) { | |
526 if (ParGCUseLocalOverflow) { | |
527 _overflow_stacks[i] = new (ResourceObj::C_HEAP) GrowableArray<oop>(512, true); | |
528 guarantee(_overflow_stacks[i] != NULL, "Overflow Stack allocation failure."); | |
529 } else { | |
530 _overflow_stacks[i] = NULL; | |
531 } | |
532 } | |
533 | |
0 | 534 if (UsePerfData) { |
535 EXCEPTION_MARK; | |
536 ResourceMark rm; | |
537 | |
538 const char* cname = | |
539 PerfDataManager::counter_name(_gen_counters->name_space(), "threads"); | |
540 PerfDataManager::create_constant(SUN_GC, cname, PerfData::U_None, | |
541 ParallelGCThreads, CHECK); | |
542 } | |
543 } | |
544 #ifdef _MSC_VER | |
545 #pragma warning( pop ) | |
546 #endif | |
547 | |
548 // ParNewGeneration:: | |
549 ParKeepAliveClosure::ParKeepAliveClosure(ParScanWeakRefClosure* cl) : | |
550 DefNewGeneration::KeepAliveClosure(cl), _par_cl(cl) {} | |
551 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
6
diff
changeset
|
552 template <class T> |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
6
diff
changeset
|
553 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
|
554 #ifdef ASSERT |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
6
diff
changeset
|
555 { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
6
diff
changeset
|
556 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
|
557 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
|
558 // 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
|
559 // as a weak reference. |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
6
diff
changeset
|
560 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
|
561 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
6
diff
changeset
|
562 #endif // ASSERT |
0 | 563 |
564 _par_cl->do_oop_nv(p); | |
565 | |
566 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
|
567 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
|
568 _rs->write_ref_field_gc_par(p, obj); |
0 | 569 } |
570 } | |
571 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
6
diff
changeset
|
572 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
|
573 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
|
574 |
0 | 575 // ParNewGeneration:: |
576 KeepAliveClosure::KeepAliveClosure(ScanWeakRefClosure* cl) : | |
577 DefNewGeneration::KeepAliveClosure(cl) {} | |
578 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
6
diff
changeset
|
579 template <class T> |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
6
diff
changeset
|
580 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
|
581 #ifdef ASSERT |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
6
diff
changeset
|
582 { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
6
diff
changeset
|
583 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
|
584 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
|
585 // 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
|
586 // as a weak reference. |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
6
diff
changeset
|
587 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
|
588 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
6
diff
changeset
|
589 #endif // ASSERT |
0 | 590 |
591 _cl->do_oop_nv(p); | |
592 | |
593 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
|
594 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
|
595 _rs->write_ref_field_gc_par(p, obj); |
0 | 596 } |
597 } | |
598 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
6
diff
changeset
|
599 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
|
600 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
|
601 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
6
diff
changeset
|
602 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
|
603 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
|
604 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
|
605 oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); |
0 | 606 if ((HeapWord*)obj < _boundary) { |
607 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
|
608 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
|
609 ? obj->forwardee() |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
6
diff
changeset
|
610 : _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
|
611 oopDesc::encode_store_heap_oop_not_null(p, new_obj); |
0 | 612 } |
613 if (_gc_barrier) { | |
614 // If p points to a younger generation, mark the card. | |
615 if ((HeapWord*)obj < _gen_boundary) { | |
616 _rs->write_ref_field_gc_par(p, obj); | |
617 } | |
618 } | |
619 } | |
620 } | |
621 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
6
diff
changeset
|
622 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
|
623 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
|
624 |
0 | 625 class ParNewRefProcTaskProxy: public AbstractGangTask { |
626 typedef AbstractRefProcTaskExecutor::ProcessTask ProcessTask; | |
627 public: | |
628 ParNewRefProcTaskProxy(ProcessTask& task, ParNewGeneration& gen, | |
629 Generation& next_gen, | |
630 HeapWord* young_old_boundary, | |
631 ParScanThreadStateSet& state_set); | |
632 | |
633 private: | |
634 virtual void work(int i); | |
635 | |
636 private: | |
637 ParNewGeneration& _gen; | |
638 ProcessTask& _task; | |
639 Generation& _next_gen; | |
640 HeapWord* _young_old_boundary; | |
641 ParScanThreadStateSet& _state_set; | |
642 }; | |
643 | |
644 ParNewRefProcTaskProxy::ParNewRefProcTaskProxy( | |
645 ProcessTask& task, ParNewGeneration& gen, | |
646 Generation& next_gen, | |
647 HeapWord* young_old_boundary, | |
648 ParScanThreadStateSet& state_set) | |
649 : AbstractGangTask("ParNewGeneration parallel reference processing"), | |
650 _gen(gen), | |
651 _task(task), | |
652 _next_gen(next_gen), | |
653 _young_old_boundary(young_old_boundary), | |
654 _state_set(state_set) | |
655 { | |
656 } | |
657 | |
658 void ParNewRefProcTaskProxy::work(int i) | |
659 { | |
660 ResourceMark rm; | |
661 HandleMark hm; | |
662 ParScanThreadState& par_scan_state = _state_set.thread_sate(i); | |
663 par_scan_state.set_young_old_boundary(_young_old_boundary); | |
664 _task.work(i, par_scan_state.is_alive_closure(), | |
665 par_scan_state.keep_alive_closure(), | |
666 par_scan_state.evacuate_followers_closure()); | |
667 } | |
668 | |
669 class ParNewRefEnqueueTaskProxy: public AbstractGangTask { | |
670 typedef AbstractRefProcTaskExecutor::EnqueueTask EnqueueTask; | |
671 EnqueueTask& _task; | |
672 | |
673 public: | |
674 ParNewRefEnqueueTaskProxy(EnqueueTask& task) | |
675 : AbstractGangTask("ParNewGeneration parallel reference enqueue"), | |
676 _task(task) | |
677 { } | |
678 | |
679 virtual void work(int i) | |
680 { | |
681 _task.work(i); | |
682 } | |
683 }; | |
684 | |
685 | |
686 void ParNewRefProcTaskExecutor::execute(ProcessTask& task) | |
687 { | |
688 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
689 assert(gch->kind() == CollectedHeap::GenCollectedHeap, | |
690 "not a generational heap"); | |
691 WorkGang* workers = gch->workers(); | |
692 assert(workers != NULL, "Need parallel worker threads."); | |
693 ParNewRefProcTaskProxy rp_task(task, _generation, *_generation.next_gen(), | |
694 _generation.reserved().end(), _state_set); | |
695 workers->run_task(&rp_task); | |
696 _state_set.reset(); | |
697 } | |
698 | |
699 void ParNewRefProcTaskExecutor::execute(EnqueueTask& task) | |
700 { | |
701 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
702 WorkGang* workers = gch->workers(); | |
703 assert(workers != NULL, "Need parallel worker threads."); | |
704 ParNewRefEnqueueTaskProxy enq_task(task); | |
705 workers->run_task(&enq_task); | |
706 } | |
707 | |
708 void ParNewRefProcTaskExecutor::set_single_threaded_mode() | |
709 { | |
710 _state_set.flush(); | |
711 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
712 gch->set_par_threads(0); // 0 ==> non-parallel. | |
713 gch->save_marks(); | |
714 } | |
715 | |
716 ScanClosureWithParBarrier:: | |
717 ScanClosureWithParBarrier(ParNewGeneration* g, bool gc_barrier) : | |
718 ScanClosure(g, gc_barrier) {} | |
719 | |
720 EvacuateFollowersClosureGeneral:: | |
721 EvacuateFollowersClosureGeneral(GenCollectedHeap* gch, int level, | |
722 OopsInGenClosure* cur, | |
723 OopsInGenClosure* older) : | |
724 _gch(gch), _level(level), | |
725 _scan_cur_or_nonheap(cur), _scan_older(older) | |
726 {} | |
727 | |
728 void EvacuateFollowersClosureGeneral::do_void() { | |
729 do { | |
730 // Beware: this call will lead to closure applications via virtual | |
731 // calls. | |
732 _gch->oop_since_save_marks_iterate(_level, | |
733 _scan_cur_or_nonheap, | |
734 _scan_older); | |
735 } while (!_gch->no_allocs_since_save_marks(_level)); | |
736 } | |
737 | |
738 | |
739 bool ParNewGeneration::_avoid_promotion_undo = false; | |
740 | |
741 void ParNewGeneration::adjust_desired_tenuring_threshold() { | |
742 // Set the desired survivor size to half the real survivor space | |
743 _tenuring_threshold = | |
744 age_table()->compute_tenuring_threshold(to()->capacity()/HeapWordSize); | |
745 } | |
746 | |
747 // A Generation that does parallel young-gen collection. | |
748 | |
749 void ParNewGeneration::collect(bool full, | |
750 bool clear_all_soft_refs, | |
751 size_t size, | |
752 bool is_tlab) { | |
753 assert(full || size > 0, "otherwise we don't want to collect"); | |
754 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
755 assert(gch->kind() == CollectedHeap::GenCollectedHeap, | |
756 "not a CMS generational heap"); | |
757 AdaptiveSizePolicy* size_policy = gch->gen_policy()->size_policy(); | |
758 WorkGang* workers = gch->workers(); | |
759 _next_gen = gch->next_gen(this); | |
760 assert(_next_gen != NULL, | |
761 "This must be the youngest gen, and not the only gen"); | |
762 assert(gch->n_gens() == 2, | |
763 "Par collection currently only works with single older gen."); | |
764 // Do we have to avoid promotion_undo? | |
765 if (gch->collector_policy()->is_concurrent_mark_sweep_policy()) { | |
766 set_avoid_promotion_undo(true); | |
767 } | |
768 | |
769 // If the next generation is too full to accomodate worst-case promotion | |
770 // from this generation, pass on collection; let the next generation | |
771 // do it. | |
772 if (!collection_attempt_is_safe()) { | |
773 gch->set_incremental_collection_will_fail(); | |
774 return; | |
775 } | |
776 assert(to()->is_empty(), "Else not collection_attempt_is_safe"); | |
777 | |
778 init_assuming_no_promotion_failure(); | |
779 | |
780 if (UseAdaptiveSizePolicy) { | |
781 set_survivor_overflow(false); | |
782 size_policy->minor_collection_begin(); | |
783 } | |
784 | |
785 TraceTime t1("GC", PrintGC && !PrintGCDetails, true, gclog_or_tty); | |
786 // Capture heap used before collection (for printing). | |
787 size_t gch_prev_used = gch->used(); | |
788 | |
789 SpecializationStats::clear(); | |
790 | |
791 age_table()->clear(); | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
167
diff
changeset
|
792 to()->clear(SpaceDecorator::Mangle); |
0 | 793 |
794 gch->save_marks(); | |
795 assert(workers != NULL, "Need parallel worker threads."); | |
796 ParallelTaskTerminator _term(workers->total_workers(), task_queues()); | |
797 ParScanThreadStateSet thread_state_set(workers->total_workers(), | |
798 *to(), *this, *_next_gen, *task_queues(), | |
695 | 799 _overflow_stacks, desired_plab_sz(), _term); |
0 | 800 |
801 ParNewGenTask tsk(this, _next_gen, reserved().end(), &thread_state_set); | |
802 int n_workers = workers->total_workers(); | |
803 gch->set_par_threads(n_workers); | |
804 gch->rem_set()->prepare_for_younger_refs_iterate(true); | |
805 // It turns out that even when we're using 1 thread, doing the work in a | |
806 // separate thread causes wide variance in run times. We can't help this | |
807 // in the multi-threaded case, but we special-case n=1 here to get | |
808 // repeatable measurements of the 1-thread overhead of the parallel code. | |
809 if (n_workers > 1) { | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
695
diff
changeset
|
810 GenCollectedHeap::StrongRootsScope srs(gch); |
0 | 811 workers->run_task(&tsk); |
812 } else { | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
695
diff
changeset
|
813 GenCollectedHeap::StrongRootsScope srs(gch); |
0 | 814 tsk.work(0); |
815 } | |
816 thread_state_set.reset(); | |
817 | |
818 if (PAR_STATS_ENABLED && ParallelGCVerbose) { | |
819 gclog_or_tty->print("Thread totals:\n" | |
820 " Pushes: %7d Pops: %7d Steals %7d (sum = %7d).\n", | |
821 thread_state_set.pushes(), thread_state_set.pops(), | |
822 thread_state_set.steals(), | |
823 thread_state_set.pops()+thread_state_set.steals()); | |
824 } | |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
269
diff
changeset
|
825 assert(thread_state_set.pushes() == thread_state_set.pops() |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
269
diff
changeset
|
826 + thread_state_set.steals(), |
0 | 827 "Or else the queues are leaky."); |
828 | |
829 // Process (weak) reference objects found during scavenge. | |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
269
diff
changeset
|
830 ReferenceProcessor* rp = ref_processor(); |
0 | 831 IsAliveClosure is_alive(this); |
832 ScanWeakRefClosure scan_weak_ref(this); | |
833 KeepAliveClosure keep_alive(&scan_weak_ref); | |
834 ScanClosure scan_without_gc_barrier(this, false); | |
835 ScanClosureWithParBarrier scan_with_gc_barrier(this, true); | |
836 set_promo_failure_scan_stack_closure(&scan_without_gc_barrier); | |
837 EvacuateFollowersClosureGeneral evacuate_followers(gch, _level, | |
838 &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
|
839 rp->setup_policy(clear_all_soft_refs); |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
269
diff
changeset
|
840 if (rp->processing_is_mt()) { |
0 | 841 ParNewRefProcTaskExecutor task_executor(*this, thread_state_set); |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
269
diff
changeset
|
842 rp->process_discovered_references(&is_alive, &keep_alive, |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
269
diff
changeset
|
843 &evacuate_followers, &task_executor); |
0 | 844 } else { |
845 thread_state_set.flush(); | |
846 gch->set_par_threads(0); // 0 ==> non-parallel. | |
847 gch->save_marks(); | |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
269
diff
changeset
|
848 rp->process_discovered_references(&is_alive, &keep_alive, |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
269
diff
changeset
|
849 &evacuate_followers, NULL); |
0 | 850 } |
851 if (!promotion_failed()) { | |
852 // Swap the survivor spaces. | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
167
diff
changeset
|
853 eden()->clear(SpaceDecorator::Mangle); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
167
diff
changeset
|
854 from()->clear(SpaceDecorator::Mangle); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
167
diff
changeset
|
855 if (ZapUnusedHeapArea) { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
167
diff
changeset
|
856 // 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
|
857 // 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
|
858 // 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
|
859 // 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
|
860 // 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
|
861 // 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
|
862 // other spaces. |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
167
diff
changeset
|
863 to()->mangle_unused_area(); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
167
diff
changeset
|
864 } |
0 | 865 swap_spaces(); |
866 | |
867 assert(to()->is_empty(), "to space should be empty now"); | |
868 } else { | |
869 assert(HandlePromotionFailure, | |
870 "Should only be here if promotion failure handling is on"); | |
871 if (_promo_failure_scan_stack != NULL) { | |
872 // Can be non-null because of reference processing. | |
873 // Free stack with its elements. | |
874 delete _promo_failure_scan_stack; | |
875 _promo_failure_scan_stack = NULL; | |
876 } | |
877 remove_forwarding_pointers(); | |
878 if (PrintGCDetails) { | |
879 gclog_or_tty->print(" (promotion failed)"); | |
880 } | |
881 // All the spaces are in play for mark-sweep. | |
882 swap_spaces(); // Make life simpler for CMS || rescan; see 6483690. | |
883 from()->set_next_compaction_space(to()); | |
884 gch->set_incremental_collection_will_fail(); | |
6
73e96e5c30df
6624765: Guarantee failure "Unexpected dirty card found"
jmasa
parents:
0
diff
changeset
|
885 |
73e96e5c30df
6624765: Guarantee failure "Unexpected dirty card found"
jmasa
parents:
0
diff
changeset
|
886 // Reset the PromotionFailureALot counters. |
73e96e5c30df
6624765: Guarantee failure "Unexpected dirty card found"
jmasa
parents:
0
diff
changeset
|
887 NOT_PRODUCT(Universe::heap()->reset_promotion_should_fail();) |
0 | 888 } |
889 // set new iteration safe limit for the survivor spaces | |
890 from()->set_concurrent_iteration_safe_limit(from()->top()); | |
891 to()->set_concurrent_iteration_safe_limit(to()->top()); | |
892 | |
893 adjust_desired_tenuring_threshold(); | |
894 if (ResizePLAB) { | |
895 plab_stats()->adjust_desired_plab_sz(); | |
896 } | |
897 | |
898 if (PrintGC && !PrintGCDetails) { | |
899 gch->print_heap_change(gch_prev_used); | |
900 } | |
901 | |
902 if (UseAdaptiveSizePolicy) { | |
903 size_policy->minor_collection_end(gch->gc_cause()); | |
904 size_policy->avg_survived()->sample(from()->used()); | |
905 } | |
906 | |
907 update_time_of_last_gc(os::javaTimeMillis()); | |
908 | |
909 SpecializationStats::print(); | |
910 | |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
269
diff
changeset
|
911 rp->set_enqueuing_is_done(true); |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
269
diff
changeset
|
912 if (rp->processing_is_mt()) { |
0 | 913 ParNewRefProcTaskExecutor task_executor(*this, thread_state_set); |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
269
diff
changeset
|
914 rp->enqueue_discovered_references(&task_executor); |
0 | 915 } else { |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
269
diff
changeset
|
916 rp->enqueue_discovered_references(NULL); |
0 | 917 } |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
269
diff
changeset
|
918 rp->verify_no_references_recorded(); |
0 | 919 } |
920 | |
921 static int sum; | |
922 void ParNewGeneration::waste_some_time() { | |
923 for (int i = 0; i < 100; i++) { | |
924 sum += i; | |
925 } | |
926 } | |
927 | |
928 static const oop ClaimedForwardPtr = oop(0x4); | |
929 | |
930 // Because of concurrency, there are times where an object for which | |
931 // "is_forwarded()" is true contains an "interim" forwarding pointer | |
932 // value. Such a value will soon be overwritten with a real value. | |
933 // This method requires "obj" to have a forwarding pointer, and waits, if | |
934 // necessary for a real one to be inserted, and returns it. | |
935 | |
936 oop ParNewGeneration::real_forwardee(oop obj) { | |
937 oop forward_ptr = obj->forwardee(); | |
938 if (forward_ptr != ClaimedForwardPtr) { | |
939 return forward_ptr; | |
940 } else { | |
941 return real_forwardee_slow(obj); | |
942 } | |
943 } | |
944 | |
945 oop ParNewGeneration::real_forwardee_slow(oop obj) { | |
946 // Spin-read if it is claimed but not yet written by another thread. | |
947 oop forward_ptr = obj->forwardee(); | |
948 while (forward_ptr == ClaimedForwardPtr) { | |
949 waste_some_time(); | |
950 assert(obj->is_forwarded(), "precondition"); | |
951 forward_ptr = obj->forwardee(); | |
952 } | |
953 return forward_ptr; | |
954 } | |
955 | |
956 #ifdef ASSERT | |
957 bool ParNewGeneration::is_legal_forward_ptr(oop p) { | |
958 return | |
959 (_avoid_promotion_undo && p == ClaimedForwardPtr) | |
960 || Universe::heap()->is_in_reserved(p); | |
961 } | |
962 #endif | |
963 | |
964 void ParNewGeneration::preserve_mark_if_necessary(oop obj, markOop m) { | |
965 if ((m != markOopDesc::prototype()) && | |
966 (!UseBiasedLocking || (m != markOopDesc::biased_locking_prototype()))) { | |
967 MutexLocker ml(ParGCRareEvent_lock); | |
968 DefNewGeneration::preserve_mark_if_necessary(obj, m); | |
969 } | |
970 } | |
971 | |
972 // Multiple GC threads may try to promote an object. If the object | |
973 // is successfully promoted, a forwarding pointer will be installed in | |
974 // the object in the young generation. This method claims the right | |
975 // to install the forwarding pointer before it copies the object, | |
976 // thus avoiding the need to undo the copy as in | |
977 // copy_to_survivor_space_avoiding_with_undo. | |
978 | |
979 oop ParNewGeneration::copy_to_survivor_space_avoiding_promotion_undo( | |
980 ParScanThreadState* par_scan_state, oop old, size_t sz, markOop m) { | |
981 // In the sequential version, this assert also says that the object is | |
982 // not forwarded. That might not be the case here. It is the case that | |
983 // the caller observed it to be not forwarded at some time in the past. | |
984 assert(is_in_reserved(old), "shouldn't be scavenging this oop"); | |
985 | |
986 // The sequential code read "old->age()" below. That doesn't work here, | |
987 // since the age is in the mark word, and that might be overwritten with | |
988 // a forwarding pointer by a parallel thread. So we must save the mark | |
989 // word in a local and then analyze it. | |
990 oopDesc dummyOld; | |
991 dummyOld.set_mark(m); | |
992 assert(!dummyOld.is_forwarded(), | |
993 "should not be called with forwarding pointer mark word."); | |
994 | |
995 oop new_obj = NULL; | |
996 oop forward_ptr; | |
997 | |
998 // Try allocating obj in to-space (unless too old) | |
999 if (dummyOld.age() < tenuring_threshold()) { | |
1000 new_obj = (oop)par_scan_state->alloc_in_to_space(sz); | |
1001 if (new_obj == NULL) { | |
1002 set_survivor_overflow(true); | |
1003 } | |
1004 } | |
1005 | |
1006 if (new_obj == NULL) { | |
1007 // Either to-space is full or we decided to promote | |
1008 // try allocating obj tenured | |
1009 | |
1010 // Attempt to install a null forwarding pointer (atomically), | |
1011 // to claim the right to install the real forwarding pointer. | |
1012 forward_ptr = old->forward_to_atomic(ClaimedForwardPtr); | |
1013 if (forward_ptr != NULL) { | |
1014 // someone else beat us to it. | |
1015 return real_forwardee(old); | |
1016 } | |
1017 | |
1018 new_obj = _next_gen->par_promote(par_scan_state->thread_num(), | |
1019 old, m, sz); | |
1020 | |
1021 if (new_obj == NULL) { | |
1022 if (!HandlePromotionFailure) { | |
1023 // A failed promotion likely means the MaxLiveObjectEvacuationRatio flag | |
1024 // is incorrectly set. In any case, its seriously wrong to be here! | |
1025 vm_exit_out_of_memory(sz*wordSize, "promotion"); | |
1026 } | |
1027 // promotion failed, forward to self | |
1028 _promotion_failed = true; | |
1029 new_obj = old; | |
1030 | |
1031 preserve_mark_if_necessary(old, m); | |
1032 } | |
1033 | |
1034 old->forward_to(new_obj); | |
1035 forward_ptr = NULL; | |
1036 } else { | |
1037 // Is in to-space; do copying ourselves. | |
1038 Copy::aligned_disjoint_words((HeapWord*)old, (HeapWord*)new_obj, sz); | |
1039 forward_ptr = old->forward_to_atomic(new_obj); | |
1040 // Restore the mark word copied above. | |
1041 new_obj->set_mark(m); | |
1042 // Increment age if obj still in new generation | |
1043 new_obj->incr_age(); | |
1044 par_scan_state->age_table()->add(new_obj, sz); | |
1045 } | |
1046 assert(new_obj != NULL, "just checking"); | |
1047 | |
1048 if (forward_ptr == NULL) { | |
1049 oop obj_to_push = new_obj; | |
1050 if (par_scan_state->should_be_partially_scanned(obj_to_push, old)) { | |
1051 // Length field used as index of next element to be scanned. | |
1052 // Real length can be obtained from real_forwardee() | |
1053 arrayOop(old)->set_length(0); | |
1054 obj_to_push = old; | |
1055 assert(obj_to_push->is_forwarded() && obj_to_push->forwardee() != obj_to_push, | |
1056 "push forwarded object"); | |
1057 } | |
1058 // Push it on one of the queues of to-be-scanned objects. | |
534 | 1059 bool simulate_overflow = false; |
1060 NOT_PRODUCT( | |
1061 if (ParGCWorkQueueOverflowALot && should_simulate_overflow()) { | |
1062 // simulate a stack overflow | |
1063 simulate_overflow = true; | |
1064 } | |
1065 ) | |
1066 if (simulate_overflow || !par_scan_state->work_queue()->push(obj_to_push)) { | |
0 | 1067 // Add stats for overflow pushes. |
1068 if (Verbose && PrintGCDetails) { | |
1069 gclog_or_tty->print("queue overflow!\n"); | |
1070 } | |
534 | 1071 push_on_overflow_list(old, par_scan_state); |
0 | 1072 par_scan_state->note_overflow_push(); |
1073 } | |
1074 par_scan_state->note_push(); | |
1075 | |
1076 return new_obj; | |
1077 } | |
1078 | |
1079 // Oops. Someone beat us to it. Undo the allocation. Where did we | |
1080 // allocate it? | |
1081 if (is_in_reserved(new_obj)) { | |
1082 // Must be in to_space. | |
1083 assert(to()->is_in_reserved(new_obj), "Checking"); | |
1084 if (forward_ptr == ClaimedForwardPtr) { | |
1085 // Wait to get the real forwarding pointer value. | |
1086 forward_ptr = real_forwardee(old); | |
1087 } | |
1088 par_scan_state->undo_alloc_in_to_space((HeapWord*)new_obj, sz); | |
1089 } | |
1090 | |
1091 return forward_ptr; | |
1092 } | |
1093 | |
1094 | |
1095 // Multiple GC threads may try to promote the same object. If two | |
1096 // or more GC threads copy the object, only one wins the race to install | |
1097 // the forwarding pointer. The other threads have to undo their copy. | |
1098 | |
1099 oop ParNewGeneration::copy_to_survivor_space_with_undo( | |
1100 ParScanThreadState* par_scan_state, oop old, size_t sz, markOop m) { | |
1101 | |
1102 // In the sequential version, this assert also says that the object is | |
1103 // not forwarded. That might not be the case here. It is the case that | |
1104 // the caller observed it to be not forwarded at some time in the past. | |
1105 assert(is_in_reserved(old), "shouldn't be scavenging this oop"); | |
1106 | |
1107 // The sequential code read "old->age()" below. That doesn't work here, | |
1108 // since the age is in the mark word, and that might be overwritten with | |
1109 // a forwarding pointer by a parallel thread. So we must save the mark | |
1110 // word here, install it in a local oopDesc, and then analyze it. | |
1111 oopDesc dummyOld; | |
1112 dummyOld.set_mark(m); | |
1113 assert(!dummyOld.is_forwarded(), | |
1114 "should not be called with forwarding pointer mark word."); | |
1115 | |
1116 bool failed_to_promote = false; | |
1117 oop new_obj = NULL; | |
1118 oop forward_ptr; | |
1119 | |
1120 // Try allocating obj in to-space (unless too old) | |
1121 if (dummyOld.age() < tenuring_threshold()) { | |
1122 new_obj = (oop)par_scan_state->alloc_in_to_space(sz); | |
1123 if (new_obj == NULL) { | |
1124 set_survivor_overflow(true); | |
1125 } | |
1126 } | |
1127 | |
1128 if (new_obj == NULL) { | |
1129 // Either to-space is full or we decided to promote | |
1130 // try allocating obj tenured | |
1131 new_obj = _next_gen->par_promote(par_scan_state->thread_num(), | |
1132 old, m, sz); | |
1133 | |
1134 if (new_obj == NULL) { | |
1135 if (!HandlePromotionFailure) { | |
1136 // A failed promotion likely means the MaxLiveObjectEvacuationRatio | |
1137 // flag is incorrectly set. In any case, its seriously wrong to be | |
1138 // here! | |
1139 vm_exit_out_of_memory(sz*wordSize, "promotion"); | |
1140 } | |
1141 // promotion failed, forward to self | |
1142 forward_ptr = old->forward_to_atomic(old); | |
1143 new_obj = old; | |
1144 | |
1145 if (forward_ptr != NULL) { | |
1146 return forward_ptr; // someone else succeeded | |
1147 } | |
1148 | |
1149 _promotion_failed = true; | |
1150 failed_to_promote = true; | |
1151 | |
1152 preserve_mark_if_necessary(old, m); | |
1153 } | |
1154 } else { | |
1155 // Is in to-space; do copying ourselves. | |
1156 Copy::aligned_disjoint_words((HeapWord*)old, (HeapWord*)new_obj, sz); | |
1157 // Restore the mark word copied above. | |
1158 new_obj->set_mark(m); | |
1159 // Increment age if new_obj still in new generation | |
1160 new_obj->incr_age(); | |
1161 par_scan_state->age_table()->add(new_obj, sz); | |
1162 } | |
1163 assert(new_obj != NULL, "just checking"); | |
1164 | |
1165 // Now attempt to install the forwarding pointer (atomically). | |
1166 // We have to copy the mark word before overwriting with forwarding | |
1167 // ptr, so we can restore it below in the copy. | |
1168 if (!failed_to_promote) { | |
1169 forward_ptr = old->forward_to_atomic(new_obj); | |
1170 } | |
1171 | |
1172 if (forward_ptr == NULL) { | |
1173 oop obj_to_push = new_obj; | |
1174 if (par_scan_state->should_be_partially_scanned(obj_to_push, old)) { | |
1175 // Length field used as index of next element to be scanned. | |
1176 // Real length can be obtained from real_forwardee() | |
1177 arrayOop(old)->set_length(0); | |
1178 obj_to_push = old; | |
1179 assert(obj_to_push->is_forwarded() && obj_to_push->forwardee() != obj_to_push, | |
1180 "push forwarded object"); | |
1181 } | |
1182 // Push it on one of the queues of to-be-scanned objects. | |
534 | 1183 bool simulate_overflow = false; |
1184 NOT_PRODUCT( | |
1185 if (ParGCWorkQueueOverflowALot && should_simulate_overflow()) { | |
1186 // simulate a stack overflow | |
1187 simulate_overflow = true; | |
1188 } | |
1189 ) | |
1190 if (simulate_overflow || !par_scan_state->work_queue()->push(obj_to_push)) { | |
0 | 1191 // Add stats for overflow pushes. |
534 | 1192 push_on_overflow_list(old, par_scan_state); |
0 | 1193 par_scan_state->note_overflow_push(); |
1194 } | |
1195 par_scan_state->note_push(); | |
1196 | |
1197 return new_obj; | |
1198 } | |
1199 | |
1200 // Oops. Someone beat us to it. Undo the allocation. Where did we | |
1201 // allocate it? | |
1202 if (is_in_reserved(new_obj)) { | |
1203 // Must be in to_space. | |
1204 assert(to()->is_in_reserved(new_obj), "Checking"); | |
1205 par_scan_state->undo_alloc_in_to_space((HeapWord*)new_obj, sz); | |
1206 } else { | |
1207 assert(!_avoid_promotion_undo, "Should not be here if avoiding."); | |
1208 _next_gen->par_promote_alloc_undo(par_scan_state->thread_num(), | |
1209 (HeapWord*)new_obj, sz); | |
1210 } | |
1211 | |
1212 return forward_ptr; | |
1213 } | |
1214 | |
534 | 1215 #ifndef PRODUCT |
1216 // It's OK to call this multi-threaded; the worst thing | |
1217 // that can happen is that we'll get a bunch of closely | |
1218 // spaced simulated oveflows, but that's OK, in fact | |
1219 // probably good as it would exercise the overflow code | |
1220 // under contention. | |
1221 bool ParNewGeneration::should_simulate_overflow() { | |
1222 if (_overflow_counter-- <= 0) { // just being defensive | |
1223 _overflow_counter = ParGCWorkQueueOverflowInterval; | |
1224 return true; | |
1225 } else { | |
1226 return false; | |
1227 } | |
1228 } | |
1229 #endif | |
1230 | |
679
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
579
diff
changeset
|
1231 // 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
|
1232 // 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
|
1233 // 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
|
1234 // 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
|
1235 // 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
|
1236 // 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
|
1237 // 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
|
1238 // 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
|
1239 // 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
|
1240 // 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
|
1241 // 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
|
1242 // 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
|
1243 // 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
|
1244 // 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
|
1245 // 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
|
1246 // 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
|
1247 // 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
|
1248 // (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
|
1249 // 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
|
1250 // as we were made painfully aware not long ago, see 6786503). |
534 | 1251 #define BUSY (oop(0x1aff1aff)) |
1252 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
|
1253 assert(is_in_reserved(from_space_obj), "Should be from this generation"); |
695 | 1254 if (ParGCUseLocalOverflow) { |
679
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
579
diff
changeset
|
1255 // 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
|
1256 // overflow stack. |
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
579
diff
changeset
|
1257 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
|
1258 } else { |
695 | 1259 assert(!UseCompressedOops, "Error"); |
679
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
579
diff
changeset
|
1260 // 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
|
1261 // 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
|
1262 // 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
|
1263 // 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
|
1264 // and should be fixed. XXX FIX ME !!! |
534 | 1265 #ifndef PRODUCT |
679
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
579
diff
changeset
|
1266 Atomic::inc_ptr(&_num_par_pushes); |
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
579
diff
changeset
|
1267 assert(_num_par_pushes > 0, "Tautology"); |
534 | 1268 #endif |
679
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
579
diff
changeset
|
1269 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
|
1270 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
|
1271 listhead->forward_to(from_space_obj); |
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
579
diff
changeset
|
1272 from_space_obj = listhead; |
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
579
diff
changeset
|
1273 } |
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
579
diff
changeset
|
1274 oop observed_overflow_list = _overflow_list; |
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
579
diff
changeset
|
1275 oop cur_overflow_list; |
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
579
diff
changeset
|
1276 do { |
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
579
diff
changeset
|
1277 cur_overflow_list = observed_overflow_list; |
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
579
diff
changeset
|
1278 if (cur_overflow_list != BUSY) { |
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
579
diff
changeset
|
1279 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
|
1280 } else { |
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
579
diff
changeset
|
1281 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
|
1282 } |
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
579
diff
changeset
|
1283 observed_overflow_list = |
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
579
diff
changeset
|
1284 (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
|
1285 } while (cur_overflow_list != observed_overflow_list); |
0 | 1286 } |
1287 } | |
1288 | |
679
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
579
diff
changeset
|
1289 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
|
1290 bool res; |
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
579
diff
changeset
|
1291 |
695 | 1292 if (ParGCUseLocalOverflow) { |
679
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
579
diff
changeset
|
1293 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
|
1294 } else { |
695 | 1295 assert(!UseCompressedOops, "Error"); |
679
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
579
diff
changeset
|
1296 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
|
1297 } |
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
579
diff
changeset
|
1298 return res; |
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
579
diff
changeset
|
1299 } |
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
579
diff
changeset
|
1300 |
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
579
diff
changeset
|
1301 |
534 | 1302 // *NOTE*: The overflow list manipulation code here and |
1303 // in CMSCollector:: are very similar in shape, | |
1304 // except that in the CMS case we thread the objects | |
1305 // directly into the list via their mark word, and do | |
1306 // not need to deal with special cases below related | |
1307 // to chunking of object arrays and promotion failure | |
1308 // handling. | |
1309 // CR 6797058 has been filed to attempt consolidation of | |
1310 // the common code. | |
1311 // Because of the common code, if you make any changes in | |
1312 // the code below, please check the CMS version to see if | |
1313 // similar changes might be needed. | |
1314 // See CMSCollector::par_take_from_overflow_list() for | |
1315 // more extensive documentation comments. | |
679
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
579
diff
changeset
|
1316 bool ParNewGeneration::take_from_overflow_list_work(ParScanThreadState* par_scan_state) { |
0 | 1317 ObjToScanQueue* work_q = par_scan_state->work_queue(); |
1318 // How many to take? | |
679
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
579
diff
changeset
|
1319 size_t objsFromOverflow = MIN2((size_t)(work_q->max_elems() - work_q->size())/4, |
534 | 1320 (size_t)ParGCDesiredObjsFromOverflowList); |
0 | 1321 |
679
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
579
diff
changeset
|
1322 assert(par_scan_state->overflow_stack() == NULL, "Error"); |
695 | 1323 assert(!UseCompressedOops, "Error"); |
0 | 1324 if (_overflow_list == NULL) return false; |
1325 | |
1326 // Otherwise, there was something there; try claiming the list. | |
534 | 1327 oop prefix = (oop)Atomic::xchg_ptr(BUSY, &_overflow_list); |
1328 // Trim off a prefix of at most objsFromOverflow items | |
1329 Thread* tid = Thread::current(); | |
1330 size_t spin_count = (size_t)ParallelGCThreads; | |
1331 size_t sleep_time_millis = MAX2((size_t)1, objsFromOverflow/100); | |
1332 for (size_t spin = 0; prefix == BUSY && spin < spin_count; spin++) { | |
1333 // someone grabbed it before we did ... | |
1334 // ... we spin for a short while... | |
1335 os::sleep(tid, sleep_time_millis, false); | |
1336 if (_overflow_list == NULL) { | |
1337 // nothing left to take | |
1338 return false; | |
1339 } else if (_overflow_list != BUSY) { | |
1340 // try and grab the prefix | |
1341 prefix = (oop)Atomic::xchg_ptr(BUSY, &_overflow_list); | |
1342 } | |
0 | 1343 } |
534 | 1344 if (prefix == NULL || prefix == BUSY) { |
1345 // Nothing to take or waited long enough | |
1346 if (prefix == NULL) { | |
1347 // Write back the NULL in case we overwrote it with BUSY above | |
1348 // and it is still the same value. | |
1349 (void) Atomic::cmpxchg_ptr(NULL, &_overflow_list, BUSY); | |
1350 } | |
1351 return false; | |
1352 } | |
1353 assert(prefix != NULL && prefix != BUSY, "Error"); | |
1354 size_t i = 1; | |
0 | 1355 oop cur = prefix; |
167
feeb96a45707
6696264: assert("narrow oop can never be zero") for GCBasher & ParNewGC
coleenp
parents:
113
diff
changeset
|
1356 while (i < objsFromOverflow && cur->klass_or_null() != NULL) { |
0 | 1357 i++; cur = oop(cur->klass()); |
1358 } | |
1359 | |
1360 // Reattach remaining (suffix) to overflow list | |
534 | 1361 if (cur->klass_or_null() == NULL) { |
1362 // Write back the NULL in lieu of the BUSY we wrote | |
1363 // above and it is still the same value. | |
1364 if (_overflow_list == BUSY) { | |
1365 (void) Atomic::cmpxchg_ptr(NULL, &_overflow_list, BUSY); | |
0 | 1366 } |
534 | 1367 } else { |
1368 assert(cur->klass_or_null() != BUSY, "Error"); | |
1369 oop suffix = oop(cur->klass()); // suffix will be put back on global list | |
1370 cur->set_klass_to_list_ptr(NULL); // break off suffix | |
1371 // It's possible that the list is still in the empty(busy) state | |
1372 // we left it in a short while ago; in that case we may be | |
1373 // able to place back the suffix. | |
1374 oop observed_overflow_list = _overflow_list; | |
1375 oop cur_overflow_list = observed_overflow_list; | |
1376 bool attached = false; | |
1377 while (observed_overflow_list == BUSY || observed_overflow_list == NULL) { | |
1378 observed_overflow_list = | |
1379 (oop) Atomic::cmpxchg_ptr(suffix, &_overflow_list, cur_overflow_list); | |
1380 if (cur_overflow_list == observed_overflow_list) { | |
1381 attached = true; | |
1382 break; | |
1383 } else cur_overflow_list = observed_overflow_list; | |
1384 } | |
1385 if (!attached) { | |
1386 // Too bad, someone else got in in between; we'll need to do a splice. | |
1387 // Find the last item of suffix list | |
1388 oop last = suffix; | |
1389 while (last->klass_or_null() != NULL) { | |
1390 last = oop(last->klass()); | |
1391 } | |
1392 // Atomically prepend suffix to current overflow list | |
1393 observed_overflow_list = _overflow_list; | |
1394 do { | |
1395 cur_overflow_list = observed_overflow_list; | |
1396 if (cur_overflow_list != BUSY) { | |
1397 // Do the splice ... | |
1398 last->set_klass_to_list_ptr(cur_overflow_list); | |
1399 } else { // cur_overflow_list == BUSY | |
1400 last->set_klass_to_list_ptr(NULL); | |
1401 } | |
1402 observed_overflow_list = | |
1403 (oop)Atomic::cmpxchg_ptr(suffix, &_overflow_list, cur_overflow_list); | |
1404 } while (cur_overflow_list != observed_overflow_list); | |
0 | 1405 } |
1406 } | |
1407 | |
1408 // Push objects on prefix list onto this thread's work queue | |
534 | 1409 assert(prefix != NULL && prefix != BUSY, "program logic"); |
0 | 1410 cur = prefix; |
534 | 1411 ssize_t n = 0; |
0 | 1412 while (cur != NULL) { |
1413 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
|
1414 oop next = oop(cur->klass_or_null()); |
0 | 1415 cur->set_klass(obj_to_push->klass()); |
534 | 1416 // This may be an array object that is self-forwarded. In that case, the list pointer |
1417 // space, cur, is not in the Java heap, but rather in the C-heap and should be freed. | |
1418 if (!is_in_reserved(cur)) { | |
1419 // This can become a scaling bottleneck when there is work queue overflow coincident | |
1420 // with promotion failure. | |
1421 oopDesc* f = cur; | |
1422 FREE_C_HEAP_ARRAY(oopDesc, f); | |
1423 } else if (par_scan_state->should_be_partially_scanned(obj_to_push, cur)) { | |
0 | 1424 assert(arrayOop(cur)->length() == 0, "entire array remaining to be scanned"); |
534 | 1425 obj_to_push = cur; |
0 | 1426 } |
534 | 1427 bool ok = work_q->push(obj_to_push); |
1428 assert(ok, "Should have succeeded"); | |
0 | 1429 cur = next; |
1430 n++; | |
1431 } | |
1432 par_scan_state->note_overflow_refill(n); | |
534 | 1433 #ifndef PRODUCT |
1434 assert(_num_par_pushes >= n, "Too many pops?"); | |
1435 Atomic::add_ptr(-(intptr_t)n, &_num_par_pushes); | |
1436 #endif | |
0 | 1437 return true; |
1438 } | |
534 | 1439 #undef BUSY |
0 | 1440 |
1441 void ParNewGeneration::ref_processor_init() | |
1442 { | |
1443 if (_ref_processor == NULL) { | |
1444 // Allocate and initialize a reference processor | |
1445 _ref_processor = ReferenceProcessor::create_ref_processor( | |
1446 _reserved, // span | |
1447 refs_discovery_is_atomic(), // atomic_discovery | |
1448 refs_discovery_is_mt(), // mt_discovery | |
1449 NULL, // is_alive_non_header | |
1450 ParallelGCThreads, | |
1451 ParallelRefProcEnabled); | |
1452 } | |
1453 } | |
1454 | |
1455 const char* ParNewGeneration::name() const { | |
1456 return "par new generation"; | |
1457 } |