duke@435: /* xdono@631: * Copyright 2002-2008 Sun Microsystems, Inc. All Rights Reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: #include "incls/_precompiled.incl" duke@435: #include "incls/_psPromotionManager.cpp.incl" duke@435: duke@435: PSPromotionManager** PSPromotionManager::_manager_array = NULL; duke@435: OopStarTaskQueueSet* PSPromotionManager::_stack_array_depth = NULL; duke@435: OopTaskQueueSet* PSPromotionManager::_stack_array_breadth = NULL; duke@435: PSOldGen* PSPromotionManager::_old_gen = NULL; duke@435: MutableSpace* PSPromotionManager::_young_space = NULL; duke@435: duke@435: void PSPromotionManager::initialize() { duke@435: ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); duke@435: assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); duke@435: duke@435: _old_gen = heap->old_gen(); duke@435: _young_space = heap->young_gen()->to_space(); duke@435: duke@435: assert(_manager_array == NULL, "Attempt to initialize twice"); duke@435: _manager_array = NEW_C_HEAP_ARRAY(PSPromotionManager*, ParallelGCThreads+1 ); duke@435: guarantee(_manager_array != NULL, "Could not initialize promotion manager"); duke@435: duke@435: if (UseDepthFirstScavengeOrder) { duke@435: _stack_array_depth = new OopStarTaskQueueSet(ParallelGCThreads); duke@435: guarantee(_stack_array_depth != NULL, "Count not initialize promotion manager"); duke@435: } else { duke@435: _stack_array_breadth = new OopTaskQueueSet(ParallelGCThreads); duke@435: guarantee(_stack_array_breadth != NULL, "Count not initialize promotion manager"); duke@435: } duke@435: duke@435: // Create and register the PSPromotionManager(s) for the worker threads. duke@435: for(uint i=0; iregister_queue(i, _manager_array[i]->claimed_stack_depth()); duke@435: } else { duke@435: stack_array_breadth()->register_queue(i, _manager_array[i]->claimed_stack_breadth()); duke@435: } duke@435: } duke@435: duke@435: // The VMThread gets its own PSPromotionManager, which is not available duke@435: // for work stealing. duke@435: _manager_array[ParallelGCThreads] = new PSPromotionManager(); duke@435: guarantee(_manager_array[ParallelGCThreads] != NULL, "Could not create PSPromotionManager"); duke@435: } duke@435: duke@435: PSPromotionManager* PSPromotionManager::gc_thread_promotion_manager(int index) { duke@435: assert(index >= 0 && index < (int)ParallelGCThreads, "index out of range"); duke@435: assert(_manager_array != NULL, "Sanity"); duke@435: return _manager_array[index]; duke@435: } duke@435: duke@435: PSPromotionManager* PSPromotionManager::vm_thread_promotion_manager() { duke@435: assert(_manager_array != NULL, "Sanity"); duke@435: return _manager_array[ParallelGCThreads]; duke@435: } duke@435: duke@435: void PSPromotionManager::pre_scavenge() { duke@435: ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); duke@435: assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); duke@435: duke@435: _young_space = heap->young_gen()->to_space(); duke@435: duke@435: for(uint i=0; ireset(); duke@435: } duke@435: } duke@435: duke@435: void PSPromotionManager::post_scavenge() { duke@435: #if PS_PM_STATS duke@435: print_stats(); duke@435: #endif // PS_PM_STATS duke@435: duke@435: for(uint i=0; ioverflow_stack_depth()->length() <= 0), duke@435: "promotion manager overflow stack must be empty"); duke@435: guarantee((UseDepthFirstScavengeOrder || duke@435: manager->overflow_stack_breadth()->length() <= 0), duke@435: "promotion manager overflow stack must be empty"); duke@435: duke@435: guarantee((!UseDepthFirstScavengeOrder || duke@435: manager->claimed_stack_depth()->size() <= 0), duke@435: "promotion manager claimed stack must be empty"); duke@435: guarantee((UseDepthFirstScavengeOrder || duke@435: manager->claimed_stack_breadth()->size() <= 0), duke@435: "promotion manager claimed stack must be empty"); duke@435: } else { duke@435: guarantee((!UseDepthFirstScavengeOrder || duke@435: manager->overflow_stack_depth()->length() <= 0), duke@435: "VM Thread promotion manager overflow stack " duke@435: "must be empty"); duke@435: guarantee((UseDepthFirstScavengeOrder || duke@435: manager->overflow_stack_breadth()->length() <= 0), duke@435: "VM Thread promotion manager overflow stack " duke@435: "must be empty"); duke@435: duke@435: guarantee((!UseDepthFirstScavengeOrder || duke@435: manager->claimed_stack_depth()->size() <= 0), duke@435: "VM Thread promotion manager claimed stack " duke@435: "must be empty"); duke@435: guarantee((UseDepthFirstScavengeOrder || duke@435: manager->claimed_stack_breadth()->size() <= 0), duke@435: "VM Thread promotion manager claimed stack " duke@435: "must be empty"); duke@435: } duke@435: duke@435: manager->flush_labs(); duke@435: } duke@435: } duke@435: duke@435: #if PS_PM_STATS duke@435: duke@435: void duke@435: PSPromotionManager::print_stats(uint i) { duke@435: tty->print_cr("---- GC Worker %2d Stats", i); duke@435: tty->print_cr(" total pushes %8d", _total_pushes); duke@435: tty->print_cr(" masked pushes %8d", _masked_pushes); duke@435: tty->print_cr(" overflow pushes %8d", _overflow_pushes); duke@435: tty->print_cr(" max overflow length %8d", _max_overflow_length); duke@435: tty->print_cr(""); duke@435: tty->print_cr(" arrays chunked %8d", _arrays_chunked); duke@435: tty->print_cr(" array chunks processed %8d", _array_chunks_processed); duke@435: tty->print_cr(""); duke@435: tty->print_cr(" total steals %8d", _total_steals); duke@435: tty->print_cr(" masked steals %8d", _masked_steals); duke@435: tty->print_cr(""); duke@435: } duke@435: duke@435: void duke@435: PSPromotionManager::print_stats() { duke@435: tty->print_cr("== GC Tasks Stats (%s), GC %3d", duke@435: (UseDepthFirstScavengeOrder) ? "Depth-First" : "Breadth-First", duke@435: Universe::heap()->total_collections()); duke@435: duke@435: for (uint i = 0; i < ParallelGCThreads+1; ++i) { duke@435: PSPromotionManager* manager = manager_array(i); duke@435: manager->print_stats(i); duke@435: } duke@435: } duke@435: duke@435: #endif // PS_PM_STATS duke@435: duke@435: PSPromotionManager::PSPromotionManager() { duke@435: ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); duke@435: assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); duke@435: _depth_first = UseDepthFirstScavengeOrder; duke@435: duke@435: // We set the old lab's start array. duke@435: _old_lab.set_start_array(old_gen()->start_array()); duke@435: duke@435: uint queue_size; duke@435: if (depth_first()) { duke@435: claimed_stack_depth()->initialize(); duke@435: queue_size = claimed_stack_depth()->max_elems(); duke@435: // We want the overflow stack to be permanent coleenp@548: _overflow_stack_depth = new (ResourceObj::C_HEAP) GrowableArray(10, true); duke@435: _overflow_stack_breadth = NULL; duke@435: } else { duke@435: claimed_stack_breadth()->initialize(); duke@435: queue_size = claimed_stack_breadth()->max_elems(); duke@435: // We want the overflow stack to be permanent duke@435: _overflow_stack_breadth = new (ResourceObj::C_HEAP) GrowableArray(10, true); duke@435: _overflow_stack_depth = NULL; duke@435: } duke@435: duke@435: _totally_drain = (ParallelGCThreads == 1) || (GCDrainStackTargetSize == 0); duke@435: if (_totally_drain) { duke@435: _target_stack_size = 0; duke@435: } else { duke@435: // don't let the target stack size to be more than 1/4 of the entries duke@435: _target_stack_size = (uint) MIN2((uint) GCDrainStackTargetSize, duke@435: (uint) (queue_size / 4)); duke@435: } duke@435: duke@435: _array_chunk_size = ParGCArrayScanChunk; duke@435: // let's choose 1.5x the chunk size duke@435: _min_array_size_for_chunking = 3 * _array_chunk_size / 2; duke@435: duke@435: reset(); duke@435: } duke@435: duke@435: void PSPromotionManager::reset() { duke@435: assert(claimed_stack_empty(), "reset of non-empty claimed stack"); duke@435: assert(overflow_stack_empty(), "reset of non-empty overflow stack"); duke@435: duke@435: // We need to get an assert in here to make sure the labs are always flushed. duke@435: duke@435: ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); duke@435: assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); duke@435: duke@435: // Do not prefill the LAB's, save heap wastage! duke@435: HeapWord* lab_base = young_space()->top(); duke@435: _young_lab.initialize(MemRegion(lab_base, (size_t)0)); duke@435: _young_gen_is_full = false; duke@435: duke@435: lab_base = old_gen()->object_space()->top(); duke@435: _old_lab.initialize(MemRegion(lab_base, (size_t)0)); duke@435: _old_gen_is_full = false; duke@435: duke@435: _prefetch_queue.clear(); duke@435: duke@435: #if PS_PM_STATS duke@435: _total_pushes = 0; duke@435: _masked_pushes = 0; duke@435: _overflow_pushes = 0; duke@435: _max_overflow_length = 0; duke@435: _arrays_chunked = 0; duke@435: _array_chunks_processed = 0; duke@435: _total_steals = 0; duke@435: _masked_steals = 0; duke@435: #endif // PS_PM_STATS duke@435: } duke@435: coleenp@548: duke@435: void PSPromotionManager::drain_stacks_depth(bool totally_drain) { duke@435: assert(depth_first(), "invariant"); duke@435: assert(overflow_stack_depth() != NULL, "invariant"); duke@435: totally_drain = totally_drain || _totally_drain; duke@435: duke@435: #ifdef ASSERT duke@435: ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); duke@435: assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); duke@435: MutableSpace* to_space = heap->young_gen()->to_space(); duke@435: MutableSpace* old_space = heap->old_gen()->object_space(); duke@435: MutableSpace* perm_space = heap->perm_gen()->object_space(); duke@435: #endif /* ASSERT */ duke@435: duke@435: do { coleenp@548: StarTask p; duke@435: duke@435: // Drain overflow stack first, so other threads can steal from duke@435: // claimed stack while we work. duke@435: while(!overflow_stack_depth()->is_empty()) { coleenp@548: // linux compiler wants different overloaded operator= in taskqueue to coleenp@548: // assign to p that the other compilers don't like. coleenp@548: StarTask ptr = overflow_stack_depth()->pop(); coleenp@548: process_popped_location_depth(ptr); duke@435: } duke@435: duke@435: if (totally_drain) { duke@435: while (claimed_stack_depth()->pop_local(p)) { duke@435: process_popped_location_depth(p); duke@435: } duke@435: } else { duke@435: while (claimed_stack_depth()->size() > _target_stack_size && duke@435: claimed_stack_depth()->pop_local(p)) { duke@435: process_popped_location_depth(p); duke@435: } duke@435: } duke@435: } while( (totally_drain && claimed_stack_depth()->size() > 0) || duke@435: (overflow_stack_depth()->length() > 0) ); duke@435: duke@435: assert(!totally_drain || claimed_stack_empty(), "Sanity"); duke@435: assert(totally_drain || duke@435: claimed_stack_depth()->size() <= _target_stack_size, duke@435: "Sanity"); duke@435: assert(overflow_stack_empty(), "Sanity"); duke@435: } duke@435: duke@435: void PSPromotionManager::drain_stacks_breadth(bool totally_drain) { duke@435: assert(!depth_first(), "invariant"); duke@435: assert(overflow_stack_breadth() != NULL, "invariant"); duke@435: totally_drain = totally_drain || _totally_drain; duke@435: duke@435: #ifdef ASSERT duke@435: ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); duke@435: assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); duke@435: MutableSpace* to_space = heap->young_gen()->to_space(); duke@435: MutableSpace* old_space = heap->old_gen()->object_space(); duke@435: MutableSpace* perm_space = heap->perm_gen()->object_space(); duke@435: #endif /* ASSERT */ duke@435: duke@435: do { duke@435: oop obj; duke@435: duke@435: // Drain overflow stack first, so other threads can steal from duke@435: // claimed stack while we work. duke@435: while(!overflow_stack_breadth()->is_empty()) { duke@435: obj = overflow_stack_breadth()->pop(); duke@435: obj->copy_contents(this); duke@435: } duke@435: duke@435: if (totally_drain) { duke@435: // obj is a reference!!! duke@435: while (claimed_stack_breadth()->pop_local(obj)) { duke@435: // It would be nice to assert about the type of objects we might duke@435: // pop, but they can come from anywhere, unfortunately. duke@435: obj->copy_contents(this); duke@435: } duke@435: } else { duke@435: // obj is a reference!!! duke@435: while (claimed_stack_breadth()->size() > _target_stack_size && duke@435: claimed_stack_breadth()->pop_local(obj)) { duke@435: // It would be nice to assert about the type of objects we might duke@435: // pop, but they can come from anywhere, unfortunately. duke@435: obj->copy_contents(this); duke@435: } duke@435: } duke@435: duke@435: // If we could not find any other work, flush the prefetch queue duke@435: if (claimed_stack_breadth()->size() == 0 && duke@435: (overflow_stack_breadth()->length() == 0)) { duke@435: flush_prefetch_queue(); duke@435: } duke@435: } while((totally_drain && claimed_stack_breadth()->size() > 0) || duke@435: (overflow_stack_breadth()->length() > 0)); duke@435: duke@435: assert(!totally_drain || claimed_stack_empty(), "Sanity"); duke@435: assert(totally_drain || duke@435: claimed_stack_breadth()->size() <= _target_stack_size, duke@435: "Sanity"); duke@435: assert(overflow_stack_empty(), "Sanity"); duke@435: } duke@435: duke@435: void PSPromotionManager::flush_labs() { duke@435: assert(claimed_stack_empty(), "Attempt to flush lab with live stack"); duke@435: assert(overflow_stack_empty(), "Attempt to flush lab with live overflow stack"); duke@435: duke@435: // If either promotion lab fills up, we can flush the duke@435: // lab but not refill it, so check first. duke@435: assert(!_young_lab.is_flushed() || _young_gen_is_full, "Sanity"); duke@435: if (!_young_lab.is_flushed()) duke@435: _young_lab.flush(); duke@435: duke@435: assert(!_old_lab.is_flushed() || _old_gen_is_full, "Sanity"); duke@435: if (!_old_lab.is_flushed()) duke@435: _old_lab.flush(); duke@435: duke@435: // Let PSScavenge know if we overflowed duke@435: if (_young_gen_is_full) { duke@435: PSScavenge::set_survivor_overflow(true); duke@435: } duke@435: } duke@435: duke@435: // duke@435: // This method is pretty bulky. It would be nice to split it up duke@435: // into smaller submethods, but we need to be careful not to hurt duke@435: // performance. duke@435: // duke@435: duke@435: oop PSPromotionManager::copy_to_survivor_space(oop o, bool depth_first) { coleenp@548: assert(PSScavenge::should_scavenge(&o), "Sanity"); duke@435: duke@435: oop new_obj = NULL; duke@435: duke@435: // NOTE! We must be very careful with any methods that access the mark duke@435: // in o. There may be multiple threads racing on it, and it may be forwarded duke@435: // at any time. Do not use oop methods for accessing the mark! duke@435: markOop test_mark = o->mark(); duke@435: duke@435: // The same test as "o->is_forwarded()" duke@435: if (!test_mark->is_marked()) { duke@435: bool new_obj_is_tenured = false; duke@435: size_t new_obj_size = o->size(); duke@435: duke@435: // Find the objects age, MT safe. duke@435: int age = (test_mark->has_displaced_mark_helper() /* o->has_displaced_mark() */) ? duke@435: test_mark->displaced_mark_helper()->age() : test_mark->age(); duke@435: duke@435: // Try allocating obj in to-space (unless too old) duke@435: if (age < PSScavenge::tenuring_threshold()) { duke@435: new_obj = (oop) _young_lab.allocate(new_obj_size); duke@435: if (new_obj == NULL && !_young_gen_is_full) { duke@435: // Do we allocate directly, or flush and refill? duke@435: if (new_obj_size > (YoungPLABSize / 2)) { duke@435: // Allocate this object directly duke@435: new_obj = (oop)young_space()->cas_allocate(new_obj_size); duke@435: } else { duke@435: // Flush and fill duke@435: _young_lab.flush(); duke@435: duke@435: HeapWord* lab_base = young_space()->cas_allocate(YoungPLABSize); duke@435: if (lab_base != NULL) { duke@435: _young_lab.initialize(MemRegion(lab_base, YoungPLABSize)); duke@435: // Try the young lab allocation again. duke@435: new_obj = (oop) _young_lab.allocate(new_obj_size); duke@435: } else { duke@435: _young_gen_is_full = true; duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: // Otherwise try allocating obj tenured duke@435: if (new_obj == NULL) { duke@435: #ifndef PRODUCT duke@435: if (Universe::heap()->promotion_should_fail()) { duke@435: return oop_promotion_failed(o, test_mark); duke@435: } duke@435: #endif // #ifndef PRODUCT duke@435: duke@435: new_obj = (oop) _old_lab.allocate(new_obj_size); duke@435: new_obj_is_tenured = true; duke@435: duke@435: if (new_obj == NULL) { duke@435: if (!_old_gen_is_full) { duke@435: // Do we allocate directly, or flush and refill? duke@435: if (new_obj_size > (OldPLABSize / 2)) { duke@435: // Allocate this object directly duke@435: new_obj = (oop)old_gen()->cas_allocate(new_obj_size); duke@435: } else { duke@435: // Flush and fill duke@435: _old_lab.flush(); duke@435: duke@435: HeapWord* lab_base = old_gen()->cas_allocate(OldPLABSize); duke@435: if(lab_base != NULL) { duke@435: _old_lab.initialize(MemRegion(lab_base, OldPLABSize)); duke@435: // Try the old lab allocation again. duke@435: new_obj = (oop) _old_lab.allocate(new_obj_size); duke@435: } duke@435: } duke@435: } duke@435: duke@435: // This is the promotion failed test, and code handling. duke@435: // The code belongs here for two reasons. It is slightly duke@435: // different thatn the code below, and cannot share the duke@435: // CAS testing code. Keeping the code here also minimizes duke@435: // the impact on the common case fast path code. duke@435: duke@435: if (new_obj == NULL) { duke@435: _old_gen_is_full = true; duke@435: return oop_promotion_failed(o, test_mark); duke@435: } duke@435: } duke@435: } duke@435: duke@435: assert(new_obj != NULL, "allocation should have succeeded"); duke@435: duke@435: // Copy obj duke@435: Copy::aligned_disjoint_words((HeapWord*)o, (HeapWord*)new_obj, new_obj_size); duke@435: duke@435: // Now we have to CAS in the header. duke@435: if (o->cas_forward_to(new_obj, test_mark)) { duke@435: // We won any races, we "own" this object. duke@435: assert(new_obj == o->forwardee(), "Sanity"); duke@435: duke@435: // Increment age if obj still in new generation. Now that duke@435: // we're dealing with a markOop that cannot change, it is duke@435: // okay to use the non mt safe oop methods. duke@435: if (!new_obj_is_tenured) { duke@435: new_obj->incr_age(); duke@435: assert(young_space()->contains(new_obj), "Attempt to push non-promoted obj"); duke@435: } duke@435: duke@435: if (depth_first) { duke@435: // Do the size comparison first with new_obj_size, which we duke@435: // already have. Hopefully, only a few objects are larger than duke@435: // _min_array_size_for_chunking, and most of them will be arrays. duke@435: // So, the is->objArray() test would be very infrequent. duke@435: if (new_obj_size > _min_array_size_for_chunking && duke@435: new_obj->is_objArray() && duke@435: PSChunkLargeArrays) { duke@435: // we'll chunk it duke@435: #if PS_PM_STATS duke@435: ++_arrays_chunked; duke@435: #endif // PS_PM_STATS duke@435: oop* const masked_o = mask_chunked_array_oop(o); duke@435: push_depth(masked_o); duke@435: #if PS_PM_STATS duke@435: ++_masked_pushes; duke@435: #endif // PS_PM_STATS duke@435: } else { duke@435: // we'll just push its contents duke@435: new_obj->push_contents(this); duke@435: } duke@435: } else { duke@435: push_breadth(new_obj); duke@435: } duke@435: } else { duke@435: // We lost, someone else "owns" this object duke@435: guarantee(o->is_forwarded(), "Object must be forwarded if the cas failed."); duke@435: duke@435: // Unallocate the space used. NOTE! We may have directly allocated duke@435: // the object. If so, we cannot deallocate it, so we have to test! duke@435: if (new_obj_is_tenured) { duke@435: if (!_old_lab.unallocate_object(new_obj)) { duke@435: // The promotion lab failed to unallocate the object. duke@435: // We need to overwrite the object with a filler that duke@435: // contains no interior pointers. duke@435: MemRegion mr((HeapWord*)new_obj, new_obj_size); duke@435: // Clean this up and move to oopFactory (see bug 4718422) duke@435: SharedHeap::fill_region_with_object(mr); duke@435: } duke@435: } else { duke@435: if (!_young_lab.unallocate_object(new_obj)) { duke@435: // The promotion lab failed to unallocate the object. duke@435: // We need to overwrite the object with a filler that duke@435: // contains no interior pointers. duke@435: MemRegion mr((HeapWord*)new_obj, new_obj_size); duke@435: // Clean this up and move to oopFactory (see bug 4718422) duke@435: SharedHeap::fill_region_with_object(mr); duke@435: } duke@435: } duke@435: duke@435: // don't update this before the unallocation! duke@435: new_obj = o->forwardee(); duke@435: } duke@435: } else { duke@435: assert(o->is_forwarded(), "Sanity"); duke@435: new_obj = o->forwardee(); duke@435: } duke@435: duke@435: #ifdef DEBUG duke@435: // This code must come after the CAS test, or it will print incorrect duke@435: // information. duke@435: if (TraceScavenge) { coleenp@548: gclog_or_tty->print_cr("{%s %s " PTR_FORMAT " -> " PTR_FORMAT " (" SIZE_FORMAT ")}", coleenp@548: PSScavenge::should_scavenge(&new_obj) ? "copying" : "tenuring", duke@435: new_obj->blueprint()->internal_name(), o, new_obj, new_obj->size()); duke@435: } duke@435: #endif duke@435: duke@435: return new_obj; duke@435: } duke@435: coleenp@548: template void PSPromotionManager::process_array_chunk_work( coleenp@548: oop obj, coleenp@548: int start, int end) { coleenp@548: assert(start < end, "invariant"); coleenp@548: T* const base = (T*)objArrayOop(obj)->base(); coleenp@548: T* p = base + start; coleenp@548: T* const chunk_end = base + end; coleenp@548: while (p < chunk_end) { coleenp@548: if (PSScavenge::should_scavenge(p)) { coleenp@548: claim_or_forward_depth(p); coleenp@548: } coleenp@548: ++p; coleenp@548: } coleenp@548: } coleenp@548: duke@435: void PSPromotionManager::process_array_chunk(oop old) { duke@435: assert(PSChunkLargeArrays, "invariant"); duke@435: assert(old->is_objArray(), "invariant"); duke@435: assert(old->is_forwarded(), "invariant"); duke@435: duke@435: #if PS_PM_STATS duke@435: ++_array_chunks_processed; duke@435: #endif // PS_PM_STATS duke@435: duke@435: oop const obj = old->forwardee(); duke@435: duke@435: int start; duke@435: int const end = arrayOop(old)->length(); duke@435: if (end > (int) _min_array_size_for_chunking) { duke@435: // we'll chunk more duke@435: start = end - _array_chunk_size; duke@435: assert(start > 0, "invariant"); duke@435: arrayOop(old)->set_length(start); duke@435: push_depth(mask_chunked_array_oop(old)); duke@435: #if PS_PM_STATS duke@435: ++_masked_pushes; duke@435: #endif // PS_PM_STATS duke@435: } else { duke@435: // this is the final chunk for this array duke@435: start = 0; duke@435: int const actual_length = arrayOop(obj)->length(); duke@435: arrayOop(old)->set_length(actual_length); duke@435: } duke@435: coleenp@548: if (UseCompressedOops) { coleenp@548: process_array_chunk_work(obj, start, end); coleenp@548: } else { coleenp@548: process_array_chunk_work(obj, start, end); duke@435: } duke@435: } duke@435: duke@435: oop PSPromotionManager::oop_promotion_failed(oop obj, markOop obj_mark) { duke@435: assert(_old_gen_is_full || PromotionFailureALot, "Sanity"); duke@435: duke@435: // Attempt to CAS in the header. duke@435: // This tests if the header is still the same as when duke@435: // this started. If it is the same (i.e., no forwarding duke@435: // pointer has been installed), then this thread owns duke@435: // it. duke@435: if (obj->cas_forward_to(obj, obj_mark)) { duke@435: // We won any races, we "own" this object. duke@435: assert(obj == obj->forwardee(), "Sanity"); duke@435: duke@435: if (depth_first()) { duke@435: obj->push_contents(this); duke@435: } else { duke@435: // Don't bother incrementing the age, just push duke@435: // onto the claimed_stack.. duke@435: push_breadth(obj); duke@435: } duke@435: duke@435: // Save the mark if needed duke@435: PSScavenge::oop_promotion_failed(obj, obj_mark); duke@435: } else { duke@435: // We lost, someone else "owns" this object duke@435: guarantee(obj->is_forwarded(), "Object must be forwarded if the cas failed."); duke@435: duke@435: // No unallocation to worry about. duke@435: obj = obj->forwardee(); duke@435: } duke@435: duke@435: #ifdef DEBUG duke@435: if (TraceScavenge) { duke@435: gclog_or_tty->print_cr("{%s %s 0x%x (%d)}", duke@435: "promotion-failure", duke@435: obj->blueprint()->internal_name(), duke@435: obj, obj->size()); duke@435: duke@435: } duke@435: #endif duke@435: duke@435: return obj; duke@435: }