Mercurial > hg > truffle
annotate src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.cpp @ 10810:4e1db4c9d4c5
Support data patches for values larger than long.
author | Roland Schatz <roland.schatz@oracle.com> |
---|---|
date | Thu, 18 Jul 2013 15:37:02 +0200 |
parents | f2110083203d |
children | 9766f73e770d |
rev | line source |
---|---|
0 | 1 /* |
10405 | 2 * Copyright (c) 2002, 2013, Oracle and/or its affiliates. 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
579
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
579
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
579
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp" | |
27 #include "gc_implementation/parallelScavenge/psOldGen.hpp" | |
28 #include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp" | |
29 #include "gc_implementation/parallelScavenge/psScavenge.inline.hpp" | |
10405 | 30 #include "gc_implementation/shared/gcTrace.hpp" |
1972 | 31 #include "gc_implementation/shared/mutableSpace.hpp" |
32 #include "memory/memRegion.hpp" | |
33 #include "oops/oop.inline.hpp" | |
34 #include "oops/oop.psgc.inline.hpp" | |
0 | 35 |
36 PSPromotionManager** PSPromotionManager::_manager_array = NULL; | |
37 OopStarTaskQueueSet* PSPromotionManager::_stack_array_depth = NULL; | |
38 PSOldGen* PSPromotionManager::_old_gen = NULL; | |
39 MutableSpace* PSPromotionManager::_young_space = NULL; | |
40 | |
41 void PSPromotionManager::initialize() { | |
42 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); | |
43 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); | |
44 | |
45 _old_gen = heap->old_gen(); | |
46 _young_space = heap->young_gen()->to_space(); | |
47 | |
48 assert(_manager_array == NULL, "Attempt to initialize twice"); | |
6197 | 49 _manager_array = NEW_C_HEAP_ARRAY(PSPromotionManager*, ParallelGCThreads+1, mtGC); |
0 | 50 guarantee(_manager_array != NULL, "Could not initialize promotion manager"); |
51 | |
1706
9d7a8ab3736b
6962589: remove breadth first scanning code from parallel gc
tonyp
parents:
1665
diff
changeset
|
52 _stack_array_depth = new OopStarTaskQueueSet(ParallelGCThreads); |
10405 | 53 guarantee(_stack_array_depth != NULL, "Could not initialize promotion manager"); |
0 | 54 |
55 // Create and register the PSPromotionManager(s) for the worker threads. | |
56 for(uint i=0; i<ParallelGCThreads; i++) { | |
57 _manager_array[i] = new PSPromotionManager(); | |
58 guarantee(_manager_array[i] != NULL, "Could not create PSPromotionManager"); | |
1706
9d7a8ab3736b
6962589: remove breadth first scanning code from parallel gc
tonyp
parents:
1665
diff
changeset
|
59 stack_array_depth()->register_queue(i, _manager_array[i]->claimed_stack_depth()); |
0 | 60 } |
61 | |
62 // The VMThread gets its own PSPromotionManager, which is not available | |
63 // for work stealing. | |
64 _manager_array[ParallelGCThreads] = new PSPromotionManager(); | |
65 guarantee(_manager_array[ParallelGCThreads] != NULL, "Could not create PSPromotionManager"); | |
66 } | |
67 | |
68 PSPromotionManager* PSPromotionManager::gc_thread_promotion_manager(int index) { | |
69 assert(index >= 0 && index < (int)ParallelGCThreads, "index out of range"); | |
70 assert(_manager_array != NULL, "Sanity"); | |
71 return _manager_array[index]; | |
72 } | |
73 | |
74 PSPromotionManager* PSPromotionManager::vm_thread_promotion_manager() { | |
75 assert(_manager_array != NULL, "Sanity"); | |
76 return _manager_array[ParallelGCThreads]; | |
77 } | |
78 | |
79 void PSPromotionManager::pre_scavenge() { | |
80 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); | |
81 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); | |
82 | |
83 _young_space = heap->young_gen()->to_space(); | |
84 | |
85 for(uint i=0; i<ParallelGCThreads+1; i++) { | |
86 manager_array(i)->reset(); | |
87 } | |
88 } | |
89 | |
10405 | 90 bool PSPromotionManager::post_scavenge(YoungGCTracer& gc_tracer) { |
91 bool promotion_failure_occurred = false; | |
92 | |
1665 | 93 TASKQUEUE_STATS_ONLY(if (PrintGCDetails && ParallelGCVerbose) print_stats()); |
1638 | 94 for (uint i = 0; i < ParallelGCThreads + 1; i++) { |
0 | 95 PSPromotionManager* manager = manager_array(i); |
1706
9d7a8ab3736b
6962589: remove breadth first scanning code from parallel gc
tonyp
parents:
1665
diff
changeset
|
96 assert(manager->claimed_stack_depth()->is_empty(), "should be empty"); |
10405 | 97 if (manager->_promotion_failed_info.has_failed()) { |
98 gc_tracer.report_promotion_failed(manager->_promotion_failed_info); | |
99 promotion_failure_occurred = true; | |
100 } | |
0 | 101 manager->flush_labs(); |
102 } | |
10405 | 103 return promotion_failure_occurred; |
0 | 104 } |
105 | |
1665 | 106 #if TASKQUEUE_STATS |
0 | 107 void |
1665 | 108 PSPromotionManager::print_taskqueue_stats(uint i) const { |
109 tty->print("%3u ", i); | |
1706
9d7a8ab3736b
6962589: remove breadth first scanning code from parallel gc
tonyp
parents:
1665
diff
changeset
|
110 _claimed_stack_depth.stats.print(); |
1665 | 111 tty->cr(); |
0 | 112 } |
113 | |
114 void | |
1665 | 115 PSPromotionManager::print_local_stats(uint i) const { |
116 #define FMT " " SIZE_FORMAT_W(10) | |
117 tty->print_cr("%3u" FMT FMT FMT FMT, i, _masked_pushes, _masked_steals, | |
118 _arrays_chunked, _array_chunks_processed); | |
119 #undef FMT | |
120 } | |
121 | |
122 static const char* const pm_stats_hdr[] = { | |
123 " --------masked------- arrays array", | |
124 "thr push steal chunked chunks", | |
125 "--- ---------- ---------- ---------- ----------" | |
126 }; | |
127 | |
128 void | |
0 | 129 PSPromotionManager::print_stats() { |
1706
9d7a8ab3736b
6962589: remove breadth first scanning code from parallel gc
tonyp
parents:
1665
diff
changeset
|
130 tty->print_cr("== GC Tasks Stats, GC %3d", |
0 | 131 Universe::heap()->total_collections()); |
132 | |
1665 | 133 tty->print("thr "); TaskQueueStats::print_header(1); tty->cr(); |
134 tty->print("--- "); TaskQueueStats::print_header(2); tty->cr(); | |
135 for (uint i = 0; i < ParallelGCThreads + 1; ++i) { | |
136 manager_array(i)->print_taskqueue_stats(i); | |
137 } | |
138 | |
139 const uint hlines = sizeof(pm_stats_hdr) / sizeof(pm_stats_hdr[0]); | |
140 for (uint i = 0; i < hlines; ++i) tty->print_cr(pm_stats_hdr[i]); | |
141 for (uint i = 0; i < ParallelGCThreads + 1; ++i) { | |
142 manager_array(i)->print_local_stats(i); | |
0 | 143 } |
144 } | |
145 | |
1665 | 146 void |
147 PSPromotionManager::reset_stats() { | |
1706
9d7a8ab3736b
6962589: remove breadth first scanning code from parallel gc
tonyp
parents:
1665
diff
changeset
|
148 claimed_stack_depth()->stats.reset(); |
1665 | 149 _masked_pushes = _masked_steals = 0; |
150 _arrays_chunked = _array_chunks_processed = 0; | |
151 } | |
152 #endif // TASKQUEUE_STATS | |
0 | 153 |
154 PSPromotionManager::PSPromotionManager() { | |
155 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); | |
156 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); | |
157 | |
158 // We set the old lab's start array. | |
159 _old_lab.set_start_array(old_gen()->start_array()); | |
160 | |
161 uint queue_size; | |
1706
9d7a8ab3736b
6962589: remove breadth first scanning code from parallel gc
tonyp
parents:
1665
diff
changeset
|
162 claimed_stack_depth()->initialize(); |
9d7a8ab3736b
6962589: remove breadth first scanning code from parallel gc
tonyp
parents:
1665
diff
changeset
|
163 queue_size = claimed_stack_depth()->max_elems(); |
0 | 164 |
165 _totally_drain = (ParallelGCThreads == 1) || (GCDrainStackTargetSize == 0); | |
166 if (_totally_drain) { | |
167 _target_stack_size = 0; | |
168 } else { | |
169 // don't let the target stack size to be more than 1/4 of the entries | |
170 _target_stack_size = (uint) MIN2((uint) GCDrainStackTargetSize, | |
171 (uint) (queue_size / 4)); | |
172 } | |
173 | |
174 _array_chunk_size = ParGCArrayScanChunk; | |
175 // let's choose 1.5x the chunk size | |
176 _min_array_size_for_chunking = 3 * _array_chunk_size / 2; | |
177 | |
178 reset(); | |
179 } | |
180 | |
181 void PSPromotionManager::reset() { | |
1638 | 182 assert(stacks_empty(), "reset of non-empty stack"); |
0 | 183 |
184 // We need to get an assert in here to make sure the labs are always flushed. | |
185 | |
186 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); | |
187 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); | |
188 | |
189 // Do not prefill the LAB's, save heap wastage! | |
190 HeapWord* lab_base = young_space()->top(); | |
191 _young_lab.initialize(MemRegion(lab_base, (size_t)0)); | |
192 _young_gen_is_full = false; | |
193 | |
194 lab_base = old_gen()->object_space()->top(); | |
195 _old_lab.initialize(MemRegion(lab_base, (size_t)0)); | |
196 _old_gen_is_full = false; | |
197 | |
10405 | 198 _promotion_failed_info.reset(); |
199 | |
1665 | 200 TASKQUEUE_STATS_ONLY(reset_stats()); |
0 | 201 } |
202 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
203 |
0 | 204 void PSPromotionManager::drain_stacks_depth(bool totally_drain) { |
205 totally_drain = totally_drain || _totally_drain; | |
206 | |
207 #ifdef ASSERT | |
208 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); | |
209 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); | |
210 MutableSpace* to_space = heap->young_gen()->to_space(); | |
211 MutableSpace* old_space = heap->old_gen()->object_space(); | |
212 #endif /* ASSERT */ | |
213 | |
1638 | 214 OopStarTaskQueue* const tq = claimed_stack_depth(); |
0 | 215 do { |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
216 StarTask p; |
0 | 217 |
218 // Drain overflow stack first, so other threads can steal from | |
219 // claimed stack while we work. | |
1638 | 220 while (tq->pop_overflow(p)) { |
221 process_popped_location_depth(p); | |
0 | 222 } |
223 | |
224 if (totally_drain) { | |
1638 | 225 while (tq->pop_local(p)) { |
0 | 226 process_popped_location_depth(p); |
227 } | |
228 } else { | |
1638 | 229 while (tq->size() > _target_stack_size && tq->pop_local(p)) { |
0 | 230 process_popped_location_depth(p); |
231 } | |
232 } | |
1638 | 233 } while (totally_drain && !tq->taskqueue_empty() || !tq->overflow_empty()); |
0 | 234 |
1638 | 235 assert(!totally_drain || tq->taskqueue_empty(), "Sanity"); |
236 assert(totally_drain || tq->size() <= _target_stack_size, "Sanity"); | |
237 assert(tq->overflow_empty(), "Sanity"); | |
0 | 238 } |
239 | |
240 void PSPromotionManager::flush_labs() { | |
1638 | 241 assert(stacks_empty(), "Attempt to flush lab with live stack"); |
0 | 242 |
243 // If either promotion lab fills up, we can flush the | |
244 // lab but not refill it, so check first. | |
245 assert(!_young_lab.is_flushed() || _young_gen_is_full, "Sanity"); | |
246 if (!_young_lab.is_flushed()) | |
247 _young_lab.flush(); | |
248 | |
249 assert(!_old_lab.is_flushed() || _old_gen_is_full, "Sanity"); | |
250 if (!_old_lab.is_flushed()) | |
251 _old_lab.flush(); | |
252 | |
253 // Let PSScavenge know if we overflowed | |
254 if (_young_gen_is_full) { | |
255 PSScavenge::set_survivor_overflow(true); | |
256 } | |
257 } | |
258 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
259 template <class T> void PSPromotionManager::process_array_chunk_work( |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
260 oop obj, |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
261 int start, int end) { |
2366
1fb790245268
6820066: Check that -XX:ParGCArrayScanChunk has a value larger than zero.
jwilhelm
parents:
1972
diff
changeset
|
262 assert(start <= end, "invariant"); |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
263 T* const base = (T*)objArrayOop(obj)->base(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
264 T* p = base + start; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
265 T* const chunk_end = base + end; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
266 while (p < chunk_end) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
267 if (PSScavenge::should_scavenge(p)) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
268 claim_or_forward_depth(p); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
269 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
270 ++p; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
271 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
272 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
273 |
0 | 274 void PSPromotionManager::process_array_chunk(oop old) { |
275 assert(PSChunkLargeArrays, "invariant"); | |
276 assert(old->is_objArray(), "invariant"); | |
277 assert(old->is_forwarded(), "invariant"); | |
278 | |
1665 | 279 TASKQUEUE_STATS_ONLY(++_array_chunks_processed); |
0 | 280 |
281 oop const obj = old->forwardee(); | |
282 | |
283 int start; | |
284 int const end = arrayOop(old)->length(); | |
285 if (end > (int) _min_array_size_for_chunking) { | |
286 // we'll chunk more | |
287 start = end - _array_chunk_size; | |
288 assert(start > 0, "invariant"); | |
289 arrayOop(old)->set_length(start); | |
290 push_depth(mask_chunked_array_oop(old)); | |
1665 | 291 TASKQUEUE_STATS_ONLY(++_masked_pushes); |
0 | 292 } else { |
293 // this is the final chunk for this array | |
294 start = 0; | |
295 int const actual_length = arrayOop(obj)->length(); | |
296 arrayOop(old)->set_length(actual_length); | |
297 } | |
298 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
299 if (UseCompressedOops) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
300 process_array_chunk_work<narrowOop>(obj, start, end); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
301 } else { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
302 process_array_chunk_work<oop>(obj, start, end); |
0 | 303 } |
304 } | |
305 | |
306 oop PSPromotionManager::oop_promotion_failed(oop obj, markOop obj_mark) { | |
307 assert(_old_gen_is_full || PromotionFailureALot, "Sanity"); | |
308 | |
309 // Attempt to CAS in the header. | |
310 // This tests if the header is still the same as when | |
311 // this started. If it is the same (i.e., no forwarding | |
312 // pointer has been installed), then this thread owns | |
313 // it. | |
314 if (obj->cas_forward_to(obj, obj_mark)) { | |
315 // We won any races, we "own" this object. | |
316 assert(obj == obj->forwardee(), "Sanity"); | |
317 | |
10405 | 318 _promotion_failed_info.register_copy_failure(obj->size()); |
319 | |
1706
9d7a8ab3736b
6962589: remove breadth first scanning code from parallel gc
tonyp
parents:
1665
diff
changeset
|
320 obj->push_contents(this); |
0 | 321 |
322 // Save the mark if needed | |
323 PSScavenge::oop_promotion_failed(obj, obj_mark); | |
324 } else { | |
325 // We lost, someone else "owns" this object | |
326 guarantee(obj->is_forwarded(), "Object must be forwarded if the cas failed."); | |
327 | |
328 // No unallocation to worry about. | |
329 obj = obj->forwardee(); | |
330 } | |
331 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
332 #ifndef PRODUCT |
0 | 333 if (TraceScavenge) { |
334 gclog_or_tty->print_cr("{%s %s 0x%x (%d)}", | |
335 "promotion-failure", | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
336 obj->klass()->internal_name(), |
0 | 337 obj, obj->size()); |
338 | |
339 } | |
340 #endif | |
341 | |
342 return obj; | |
343 } |