Tue, 28 Sep 2010 15:56:15 -0700
6423256: GC stacks should use a better data structure
6942771: SEGV in ParScanThreadState::take_from_overflow_stack
Reviewed-by: apetrusenko, ysr, pbk
duke@435 | 1 | /* |
jcoomes@1993 | 2 | * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | #include "incls/_precompiled.incl" |
duke@435 | 26 | #include "incls/_psPromotionManager.cpp.incl" |
duke@435 | 27 | |
duke@435 | 28 | PSPromotionManager** PSPromotionManager::_manager_array = NULL; |
duke@435 | 29 | OopStarTaskQueueSet* PSPromotionManager::_stack_array_depth = NULL; |
duke@435 | 30 | PSOldGen* PSPromotionManager::_old_gen = NULL; |
duke@435 | 31 | MutableSpace* PSPromotionManager::_young_space = NULL; |
duke@435 | 32 | |
duke@435 | 33 | void PSPromotionManager::initialize() { |
duke@435 | 34 | ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); |
duke@435 | 35 | assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); |
duke@435 | 36 | |
duke@435 | 37 | _old_gen = heap->old_gen(); |
duke@435 | 38 | _young_space = heap->young_gen()->to_space(); |
duke@435 | 39 | |
duke@435 | 40 | assert(_manager_array == NULL, "Attempt to initialize twice"); |
duke@435 | 41 | _manager_array = NEW_C_HEAP_ARRAY(PSPromotionManager*, ParallelGCThreads+1 ); |
duke@435 | 42 | guarantee(_manager_array != NULL, "Could not initialize promotion manager"); |
duke@435 | 43 | |
tonyp@2061 | 44 | _stack_array_depth = new OopStarTaskQueueSet(ParallelGCThreads); |
tonyp@2061 | 45 | guarantee(_stack_array_depth != NULL, "Cound not initialize promotion manager"); |
duke@435 | 46 | |
duke@435 | 47 | // Create and register the PSPromotionManager(s) for the worker threads. |
duke@435 | 48 | for(uint i=0; i<ParallelGCThreads; i++) { |
duke@435 | 49 | _manager_array[i] = new PSPromotionManager(); |
duke@435 | 50 | guarantee(_manager_array[i] != NULL, "Could not create PSPromotionManager"); |
tonyp@2061 | 51 | stack_array_depth()->register_queue(i, _manager_array[i]->claimed_stack_depth()); |
duke@435 | 52 | } |
duke@435 | 53 | |
duke@435 | 54 | // The VMThread gets its own PSPromotionManager, which is not available |
duke@435 | 55 | // for work stealing. |
duke@435 | 56 | _manager_array[ParallelGCThreads] = new PSPromotionManager(); |
duke@435 | 57 | guarantee(_manager_array[ParallelGCThreads] != NULL, "Could not create PSPromotionManager"); |
duke@435 | 58 | } |
duke@435 | 59 | |
duke@435 | 60 | PSPromotionManager* PSPromotionManager::gc_thread_promotion_manager(int index) { |
duke@435 | 61 | assert(index >= 0 && index < (int)ParallelGCThreads, "index out of range"); |
duke@435 | 62 | assert(_manager_array != NULL, "Sanity"); |
duke@435 | 63 | return _manager_array[index]; |
duke@435 | 64 | } |
duke@435 | 65 | |
duke@435 | 66 | PSPromotionManager* PSPromotionManager::vm_thread_promotion_manager() { |
duke@435 | 67 | assert(_manager_array != NULL, "Sanity"); |
duke@435 | 68 | return _manager_array[ParallelGCThreads]; |
duke@435 | 69 | } |
duke@435 | 70 | |
duke@435 | 71 | void PSPromotionManager::pre_scavenge() { |
duke@435 | 72 | ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); |
duke@435 | 73 | assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); |
duke@435 | 74 | |
duke@435 | 75 | _young_space = heap->young_gen()->to_space(); |
duke@435 | 76 | |
duke@435 | 77 | for(uint i=0; i<ParallelGCThreads+1; i++) { |
duke@435 | 78 | manager_array(i)->reset(); |
duke@435 | 79 | } |
duke@435 | 80 | } |
duke@435 | 81 | |
duke@435 | 82 | void PSPromotionManager::post_scavenge() { |
jcoomes@2020 | 83 | TASKQUEUE_STATS_ONLY(if (PrintGCDetails && ParallelGCVerbose) print_stats()); |
jcoomes@1993 | 84 | for (uint i = 0; i < ParallelGCThreads + 1; i++) { |
duke@435 | 85 | PSPromotionManager* manager = manager_array(i); |
tonyp@2061 | 86 | assert(manager->claimed_stack_depth()->is_empty(), "should be empty"); |
duke@435 | 87 | manager->flush_labs(); |
duke@435 | 88 | } |
duke@435 | 89 | } |
duke@435 | 90 | |
jcoomes@2020 | 91 | #if TASKQUEUE_STATS |
duke@435 | 92 | void |
jcoomes@2020 | 93 | PSPromotionManager::print_taskqueue_stats(uint i) const { |
jcoomes@2020 | 94 | tty->print("%3u ", i); |
tonyp@2061 | 95 | _claimed_stack_depth.stats.print(); |
jcoomes@2020 | 96 | tty->cr(); |
duke@435 | 97 | } |
duke@435 | 98 | |
duke@435 | 99 | void |
jcoomes@2020 | 100 | PSPromotionManager::print_local_stats(uint i) const { |
jcoomes@2020 | 101 | #define FMT " " SIZE_FORMAT_W(10) |
jcoomes@2020 | 102 | tty->print_cr("%3u" FMT FMT FMT FMT, i, _masked_pushes, _masked_steals, |
jcoomes@2020 | 103 | _arrays_chunked, _array_chunks_processed); |
jcoomes@2020 | 104 | #undef FMT |
jcoomes@2020 | 105 | } |
jcoomes@2020 | 106 | |
jcoomes@2020 | 107 | static const char* const pm_stats_hdr[] = { |
jcoomes@2020 | 108 | " --------masked------- arrays array", |
jcoomes@2020 | 109 | "thr push steal chunked chunks", |
jcoomes@2020 | 110 | "--- ---------- ---------- ---------- ----------" |
jcoomes@2020 | 111 | }; |
jcoomes@2020 | 112 | |
jcoomes@2020 | 113 | void |
duke@435 | 114 | PSPromotionManager::print_stats() { |
tonyp@2061 | 115 | tty->print_cr("== GC Tasks Stats, GC %3d", |
duke@435 | 116 | Universe::heap()->total_collections()); |
duke@435 | 117 | |
jcoomes@2020 | 118 | tty->print("thr "); TaskQueueStats::print_header(1); tty->cr(); |
jcoomes@2020 | 119 | tty->print("--- "); TaskQueueStats::print_header(2); tty->cr(); |
jcoomes@2020 | 120 | for (uint i = 0; i < ParallelGCThreads + 1; ++i) { |
jcoomes@2020 | 121 | manager_array(i)->print_taskqueue_stats(i); |
jcoomes@2020 | 122 | } |
jcoomes@2020 | 123 | |
jcoomes@2020 | 124 | const uint hlines = sizeof(pm_stats_hdr) / sizeof(pm_stats_hdr[0]); |
jcoomes@2020 | 125 | for (uint i = 0; i < hlines; ++i) tty->print_cr(pm_stats_hdr[i]); |
jcoomes@2020 | 126 | for (uint i = 0; i < ParallelGCThreads + 1; ++i) { |
jcoomes@2020 | 127 | manager_array(i)->print_local_stats(i); |
duke@435 | 128 | } |
duke@435 | 129 | } |
duke@435 | 130 | |
jcoomes@2020 | 131 | void |
jcoomes@2020 | 132 | PSPromotionManager::reset_stats() { |
tonyp@2061 | 133 | claimed_stack_depth()->stats.reset(); |
jcoomes@2020 | 134 | _masked_pushes = _masked_steals = 0; |
jcoomes@2020 | 135 | _arrays_chunked = _array_chunks_processed = 0; |
jcoomes@2020 | 136 | } |
jcoomes@2020 | 137 | #endif // TASKQUEUE_STATS |
duke@435 | 138 | |
duke@435 | 139 | PSPromotionManager::PSPromotionManager() { |
duke@435 | 140 | ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); |
duke@435 | 141 | assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); |
duke@435 | 142 | |
duke@435 | 143 | // We set the old lab's start array. |
duke@435 | 144 | _old_lab.set_start_array(old_gen()->start_array()); |
duke@435 | 145 | |
duke@435 | 146 | uint queue_size; |
tonyp@2061 | 147 | claimed_stack_depth()->initialize(); |
tonyp@2061 | 148 | queue_size = claimed_stack_depth()->max_elems(); |
duke@435 | 149 | |
duke@435 | 150 | _totally_drain = (ParallelGCThreads == 1) || (GCDrainStackTargetSize == 0); |
duke@435 | 151 | if (_totally_drain) { |
duke@435 | 152 | _target_stack_size = 0; |
duke@435 | 153 | } else { |
duke@435 | 154 | // don't let the target stack size to be more than 1/4 of the entries |
duke@435 | 155 | _target_stack_size = (uint) MIN2((uint) GCDrainStackTargetSize, |
duke@435 | 156 | (uint) (queue_size / 4)); |
duke@435 | 157 | } |
duke@435 | 158 | |
duke@435 | 159 | _array_chunk_size = ParGCArrayScanChunk; |
duke@435 | 160 | // let's choose 1.5x the chunk size |
duke@435 | 161 | _min_array_size_for_chunking = 3 * _array_chunk_size / 2; |
duke@435 | 162 | |
duke@435 | 163 | reset(); |
duke@435 | 164 | } |
duke@435 | 165 | |
duke@435 | 166 | void PSPromotionManager::reset() { |
jcoomes@1993 | 167 | assert(stacks_empty(), "reset of non-empty stack"); |
duke@435 | 168 | |
duke@435 | 169 | // We need to get an assert in here to make sure the labs are always flushed. |
duke@435 | 170 | |
duke@435 | 171 | ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); |
duke@435 | 172 | assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); |
duke@435 | 173 | |
duke@435 | 174 | // Do not prefill the LAB's, save heap wastage! |
duke@435 | 175 | HeapWord* lab_base = young_space()->top(); |
duke@435 | 176 | _young_lab.initialize(MemRegion(lab_base, (size_t)0)); |
duke@435 | 177 | _young_gen_is_full = false; |
duke@435 | 178 | |
duke@435 | 179 | lab_base = old_gen()->object_space()->top(); |
duke@435 | 180 | _old_lab.initialize(MemRegion(lab_base, (size_t)0)); |
duke@435 | 181 | _old_gen_is_full = false; |
duke@435 | 182 | |
jcoomes@2020 | 183 | TASKQUEUE_STATS_ONLY(reset_stats()); |
duke@435 | 184 | } |
duke@435 | 185 | |
coleenp@548 | 186 | |
duke@435 | 187 | void PSPromotionManager::drain_stacks_depth(bool totally_drain) { |
duke@435 | 188 | totally_drain = totally_drain || _totally_drain; |
duke@435 | 189 | |
duke@435 | 190 | #ifdef ASSERT |
duke@435 | 191 | ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); |
duke@435 | 192 | assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); |
duke@435 | 193 | MutableSpace* to_space = heap->young_gen()->to_space(); |
duke@435 | 194 | MutableSpace* old_space = heap->old_gen()->object_space(); |
duke@435 | 195 | MutableSpace* perm_space = heap->perm_gen()->object_space(); |
duke@435 | 196 | #endif /* ASSERT */ |
duke@435 | 197 | |
jcoomes@1993 | 198 | OopStarTaskQueue* const tq = claimed_stack_depth(); |
duke@435 | 199 | do { |
coleenp@548 | 200 | StarTask p; |
duke@435 | 201 | |
duke@435 | 202 | // Drain overflow stack first, so other threads can steal from |
duke@435 | 203 | // claimed stack while we work. |
jcoomes@1993 | 204 | while (tq->pop_overflow(p)) { |
jcoomes@1993 | 205 | process_popped_location_depth(p); |
duke@435 | 206 | } |
duke@435 | 207 | |
duke@435 | 208 | if (totally_drain) { |
jcoomes@1993 | 209 | while (tq->pop_local(p)) { |
duke@435 | 210 | process_popped_location_depth(p); |
duke@435 | 211 | } |
duke@435 | 212 | } else { |
jcoomes@1993 | 213 | while (tq->size() > _target_stack_size && tq->pop_local(p)) { |
duke@435 | 214 | process_popped_location_depth(p); |
duke@435 | 215 | } |
duke@435 | 216 | } |
jcoomes@1993 | 217 | } while (totally_drain && !tq->taskqueue_empty() || !tq->overflow_empty()); |
duke@435 | 218 | |
jcoomes@1993 | 219 | assert(!totally_drain || tq->taskqueue_empty(), "Sanity"); |
jcoomes@1993 | 220 | assert(totally_drain || tq->size() <= _target_stack_size, "Sanity"); |
jcoomes@1993 | 221 | assert(tq->overflow_empty(), "Sanity"); |
duke@435 | 222 | } |
duke@435 | 223 | |
duke@435 | 224 | void PSPromotionManager::flush_labs() { |
jcoomes@1993 | 225 | assert(stacks_empty(), "Attempt to flush lab with live stack"); |
duke@435 | 226 | |
duke@435 | 227 | // If either promotion lab fills up, we can flush the |
duke@435 | 228 | // lab but not refill it, so check first. |
duke@435 | 229 | assert(!_young_lab.is_flushed() || _young_gen_is_full, "Sanity"); |
duke@435 | 230 | if (!_young_lab.is_flushed()) |
duke@435 | 231 | _young_lab.flush(); |
duke@435 | 232 | |
duke@435 | 233 | assert(!_old_lab.is_flushed() || _old_gen_is_full, "Sanity"); |
duke@435 | 234 | if (!_old_lab.is_flushed()) |
duke@435 | 235 | _old_lab.flush(); |
duke@435 | 236 | |
duke@435 | 237 | // Let PSScavenge know if we overflowed |
duke@435 | 238 | if (_young_gen_is_full) { |
duke@435 | 239 | PSScavenge::set_survivor_overflow(true); |
duke@435 | 240 | } |
duke@435 | 241 | } |
duke@435 | 242 | |
duke@435 | 243 | // |
duke@435 | 244 | // This method is pretty bulky. It would be nice to split it up |
duke@435 | 245 | // into smaller submethods, but we need to be careful not to hurt |
duke@435 | 246 | // performance. |
duke@435 | 247 | // |
duke@435 | 248 | |
tonyp@2061 | 249 | oop PSPromotionManager::copy_to_survivor_space(oop o) { |
coleenp@548 | 250 | assert(PSScavenge::should_scavenge(&o), "Sanity"); |
duke@435 | 251 | |
duke@435 | 252 | oop new_obj = NULL; |
duke@435 | 253 | |
duke@435 | 254 | // NOTE! We must be very careful with any methods that access the mark |
duke@435 | 255 | // in o. There may be multiple threads racing on it, and it may be forwarded |
duke@435 | 256 | // at any time. Do not use oop methods for accessing the mark! |
duke@435 | 257 | markOop test_mark = o->mark(); |
duke@435 | 258 | |
duke@435 | 259 | // The same test as "o->is_forwarded()" |
duke@435 | 260 | if (!test_mark->is_marked()) { |
duke@435 | 261 | bool new_obj_is_tenured = false; |
duke@435 | 262 | size_t new_obj_size = o->size(); |
duke@435 | 263 | |
duke@435 | 264 | // Find the objects age, MT safe. |
duke@435 | 265 | int age = (test_mark->has_displaced_mark_helper() /* o->has_displaced_mark() */) ? |
duke@435 | 266 | test_mark->displaced_mark_helper()->age() : test_mark->age(); |
duke@435 | 267 | |
duke@435 | 268 | // Try allocating obj in to-space (unless too old) |
duke@435 | 269 | if (age < PSScavenge::tenuring_threshold()) { |
duke@435 | 270 | new_obj = (oop) _young_lab.allocate(new_obj_size); |
duke@435 | 271 | if (new_obj == NULL && !_young_gen_is_full) { |
duke@435 | 272 | // Do we allocate directly, or flush and refill? |
duke@435 | 273 | if (new_obj_size > (YoungPLABSize / 2)) { |
duke@435 | 274 | // Allocate this object directly |
duke@435 | 275 | new_obj = (oop)young_space()->cas_allocate(new_obj_size); |
duke@435 | 276 | } else { |
duke@435 | 277 | // Flush and fill |
duke@435 | 278 | _young_lab.flush(); |
duke@435 | 279 | |
duke@435 | 280 | HeapWord* lab_base = young_space()->cas_allocate(YoungPLABSize); |
duke@435 | 281 | if (lab_base != NULL) { |
duke@435 | 282 | _young_lab.initialize(MemRegion(lab_base, YoungPLABSize)); |
duke@435 | 283 | // Try the young lab allocation again. |
duke@435 | 284 | new_obj = (oop) _young_lab.allocate(new_obj_size); |
duke@435 | 285 | } else { |
duke@435 | 286 | _young_gen_is_full = true; |
duke@435 | 287 | } |
duke@435 | 288 | } |
duke@435 | 289 | } |
duke@435 | 290 | } |
duke@435 | 291 | |
duke@435 | 292 | // Otherwise try allocating obj tenured |
duke@435 | 293 | if (new_obj == NULL) { |
duke@435 | 294 | #ifndef PRODUCT |
duke@435 | 295 | if (Universe::heap()->promotion_should_fail()) { |
duke@435 | 296 | return oop_promotion_failed(o, test_mark); |
duke@435 | 297 | } |
duke@435 | 298 | #endif // #ifndef PRODUCT |
duke@435 | 299 | |
duke@435 | 300 | new_obj = (oop) _old_lab.allocate(new_obj_size); |
duke@435 | 301 | new_obj_is_tenured = true; |
duke@435 | 302 | |
duke@435 | 303 | if (new_obj == NULL) { |
duke@435 | 304 | if (!_old_gen_is_full) { |
duke@435 | 305 | // Do we allocate directly, or flush and refill? |
duke@435 | 306 | if (new_obj_size > (OldPLABSize / 2)) { |
duke@435 | 307 | // Allocate this object directly |
duke@435 | 308 | new_obj = (oop)old_gen()->cas_allocate(new_obj_size); |
duke@435 | 309 | } else { |
duke@435 | 310 | // Flush and fill |
duke@435 | 311 | _old_lab.flush(); |
duke@435 | 312 | |
duke@435 | 313 | HeapWord* lab_base = old_gen()->cas_allocate(OldPLABSize); |
duke@435 | 314 | if(lab_base != NULL) { |
duke@435 | 315 | _old_lab.initialize(MemRegion(lab_base, OldPLABSize)); |
duke@435 | 316 | // Try the old lab allocation again. |
duke@435 | 317 | new_obj = (oop) _old_lab.allocate(new_obj_size); |
duke@435 | 318 | } |
duke@435 | 319 | } |
duke@435 | 320 | } |
duke@435 | 321 | |
duke@435 | 322 | // This is the promotion failed test, and code handling. |
duke@435 | 323 | // The code belongs here for two reasons. It is slightly |
duke@435 | 324 | // different thatn the code below, and cannot share the |
duke@435 | 325 | // CAS testing code. Keeping the code here also minimizes |
duke@435 | 326 | // the impact on the common case fast path code. |
duke@435 | 327 | |
duke@435 | 328 | if (new_obj == NULL) { |
duke@435 | 329 | _old_gen_is_full = true; |
duke@435 | 330 | return oop_promotion_failed(o, test_mark); |
duke@435 | 331 | } |
duke@435 | 332 | } |
duke@435 | 333 | } |
duke@435 | 334 | |
duke@435 | 335 | assert(new_obj != NULL, "allocation should have succeeded"); |
duke@435 | 336 | |
duke@435 | 337 | // Copy obj |
duke@435 | 338 | Copy::aligned_disjoint_words((HeapWord*)o, (HeapWord*)new_obj, new_obj_size); |
duke@435 | 339 | |
duke@435 | 340 | // Now we have to CAS in the header. |
duke@435 | 341 | if (o->cas_forward_to(new_obj, test_mark)) { |
duke@435 | 342 | // We won any races, we "own" this object. |
duke@435 | 343 | assert(new_obj == o->forwardee(), "Sanity"); |
duke@435 | 344 | |
duke@435 | 345 | // Increment age if obj still in new generation. Now that |
duke@435 | 346 | // we're dealing with a markOop that cannot change, it is |
duke@435 | 347 | // okay to use the non mt safe oop methods. |
duke@435 | 348 | if (!new_obj_is_tenured) { |
duke@435 | 349 | new_obj->incr_age(); |
duke@435 | 350 | assert(young_space()->contains(new_obj), "Attempt to push non-promoted obj"); |
duke@435 | 351 | } |
duke@435 | 352 | |
tonyp@2061 | 353 | // Do the size comparison first with new_obj_size, which we |
tonyp@2061 | 354 | // already have. Hopefully, only a few objects are larger than |
tonyp@2061 | 355 | // _min_array_size_for_chunking, and most of them will be arrays. |
tonyp@2061 | 356 | // So, the is->objArray() test would be very infrequent. |
tonyp@2061 | 357 | if (new_obj_size > _min_array_size_for_chunking && |
tonyp@2061 | 358 | new_obj->is_objArray() && |
tonyp@2061 | 359 | PSChunkLargeArrays) { |
tonyp@2061 | 360 | // we'll chunk it |
tonyp@2061 | 361 | oop* const masked_o = mask_chunked_array_oop(o); |
tonyp@2061 | 362 | push_depth(masked_o); |
tonyp@2061 | 363 | TASKQUEUE_STATS_ONLY(++_arrays_chunked; ++_masked_pushes); |
duke@435 | 364 | } else { |
tonyp@2061 | 365 | // we'll just push its contents |
tonyp@2061 | 366 | new_obj->push_contents(this); |
duke@435 | 367 | } |
duke@435 | 368 | } else { |
duke@435 | 369 | // We lost, someone else "owns" this object |
duke@435 | 370 | guarantee(o->is_forwarded(), "Object must be forwarded if the cas failed."); |
duke@435 | 371 | |
jcoomes@916 | 372 | // Try to deallocate the space. If it was directly allocated we cannot |
jcoomes@916 | 373 | // deallocate it, so we have to test. If the deallocation fails, |
jcoomes@916 | 374 | // overwrite with a filler object. |
duke@435 | 375 | if (new_obj_is_tenured) { |
duke@435 | 376 | if (!_old_lab.unallocate_object(new_obj)) { |
jcoomes@916 | 377 | CollectedHeap::fill_with_object((HeapWord*) new_obj, new_obj_size); |
duke@435 | 378 | } |
jcoomes@916 | 379 | } else if (!_young_lab.unallocate_object(new_obj)) { |
jcoomes@916 | 380 | CollectedHeap::fill_with_object((HeapWord*) new_obj, new_obj_size); |
duke@435 | 381 | } |
duke@435 | 382 | |
duke@435 | 383 | // don't update this before the unallocation! |
duke@435 | 384 | new_obj = o->forwardee(); |
duke@435 | 385 | } |
duke@435 | 386 | } else { |
duke@435 | 387 | assert(o->is_forwarded(), "Sanity"); |
duke@435 | 388 | new_obj = o->forwardee(); |
duke@435 | 389 | } |
duke@435 | 390 | |
duke@435 | 391 | #ifdef DEBUG |
duke@435 | 392 | // This code must come after the CAS test, or it will print incorrect |
duke@435 | 393 | // information. |
duke@435 | 394 | if (TraceScavenge) { |
coleenp@548 | 395 | gclog_or_tty->print_cr("{%s %s " PTR_FORMAT " -> " PTR_FORMAT " (" SIZE_FORMAT ")}", |
coleenp@548 | 396 | PSScavenge::should_scavenge(&new_obj) ? "copying" : "tenuring", |
duke@435 | 397 | new_obj->blueprint()->internal_name(), o, new_obj, new_obj->size()); |
duke@435 | 398 | } |
duke@435 | 399 | #endif |
duke@435 | 400 | |
duke@435 | 401 | return new_obj; |
duke@435 | 402 | } |
duke@435 | 403 | |
coleenp@548 | 404 | template <class T> void PSPromotionManager::process_array_chunk_work( |
coleenp@548 | 405 | oop obj, |
coleenp@548 | 406 | int start, int end) { |
coleenp@548 | 407 | assert(start < end, "invariant"); |
coleenp@548 | 408 | T* const base = (T*)objArrayOop(obj)->base(); |
coleenp@548 | 409 | T* p = base + start; |
coleenp@548 | 410 | T* const chunk_end = base + end; |
coleenp@548 | 411 | while (p < chunk_end) { |
coleenp@548 | 412 | if (PSScavenge::should_scavenge(p)) { |
coleenp@548 | 413 | claim_or_forward_depth(p); |
coleenp@548 | 414 | } |
coleenp@548 | 415 | ++p; |
coleenp@548 | 416 | } |
coleenp@548 | 417 | } |
coleenp@548 | 418 | |
duke@435 | 419 | void PSPromotionManager::process_array_chunk(oop old) { |
duke@435 | 420 | assert(PSChunkLargeArrays, "invariant"); |
duke@435 | 421 | assert(old->is_objArray(), "invariant"); |
duke@435 | 422 | assert(old->is_forwarded(), "invariant"); |
duke@435 | 423 | |
jcoomes@2020 | 424 | TASKQUEUE_STATS_ONLY(++_array_chunks_processed); |
duke@435 | 425 | |
duke@435 | 426 | oop const obj = old->forwardee(); |
duke@435 | 427 | |
duke@435 | 428 | int start; |
duke@435 | 429 | int const end = arrayOop(old)->length(); |
duke@435 | 430 | if (end > (int) _min_array_size_for_chunking) { |
duke@435 | 431 | // we'll chunk more |
duke@435 | 432 | start = end - _array_chunk_size; |
duke@435 | 433 | assert(start > 0, "invariant"); |
duke@435 | 434 | arrayOop(old)->set_length(start); |
duke@435 | 435 | push_depth(mask_chunked_array_oop(old)); |
jcoomes@2020 | 436 | TASKQUEUE_STATS_ONLY(++_masked_pushes); |
duke@435 | 437 | } else { |
duke@435 | 438 | // this is the final chunk for this array |
duke@435 | 439 | start = 0; |
duke@435 | 440 | int const actual_length = arrayOop(obj)->length(); |
duke@435 | 441 | arrayOop(old)->set_length(actual_length); |
duke@435 | 442 | } |
duke@435 | 443 | |
coleenp@548 | 444 | if (UseCompressedOops) { |
coleenp@548 | 445 | process_array_chunk_work<narrowOop>(obj, start, end); |
coleenp@548 | 446 | } else { |
coleenp@548 | 447 | process_array_chunk_work<oop>(obj, start, end); |
duke@435 | 448 | } |
duke@435 | 449 | } |
duke@435 | 450 | |
duke@435 | 451 | oop PSPromotionManager::oop_promotion_failed(oop obj, markOop obj_mark) { |
duke@435 | 452 | assert(_old_gen_is_full || PromotionFailureALot, "Sanity"); |
duke@435 | 453 | |
duke@435 | 454 | // Attempt to CAS in the header. |
duke@435 | 455 | // This tests if the header is still the same as when |
duke@435 | 456 | // this started. If it is the same (i.e., no forwarding |
duke@435 | 457 | // pointer has been installed), then this thread owns |
duke@435 | 458 | // it. |
duke@435 | 459 | if (obj->cas_forward_to(obj, obj_mark)) { |
duke@435 | 460 | // We won any races, we "own" this object. |
duke@435 | 461 | assert(obj == obj->forwardee(), "Sanity"); |
duke@435 | 462 | |
tonyp@2061 | 463 | obj->push_contents(this); |
duke@435 | 464 | |
duke@435 | 465 | // Save the mark if needed |
duke@435 | 466 | PSScavenge::oop_promotion_failed(obj, obj_mark); |
duke@435 | 467 | } else { |
duke@435 | 468 | // We lost, someone else "owns" this object |
duke@435 | 469 | guarantee(obj->is_forwarded(), "Object must be forwarded if the cas failed."); |
duke@435 | 470 | |
duke@435 | 471 | // No unallocation to worry about. |
duke@435 | 472 | obj = obj->forwardee(); |
duke@435 | 473 | } |
duke@435 | 474 | |
duke@435 | 475 | #ifdef DEBUG |
duke@435 | 476 | if (TraceScavenge) { |
duke@435 | 477 | gclog_or_tty->print_cr("{%s %s 0x%x (%d)}", |
duke@435 | 478 | "promotion-failure", |
duke@435 | 479 | obj->blueprint()->internal_name(), |
duke@435 | 480 | obj, obj->size()); |
duke@435 | 481 | |
duke@435 | 482 | } |
duke@435 | 483 | #endif |
duke@435 | 484 | |
duke@435 | 485 | return obj; |
duke@435 | 486 | } |