duke@435: /* sla@5237: * Copyright (c) 2002, 2013, Oracle and/or its affiliates. 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: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPROMOTIONMANAGER_INLINE_HPP stefank@2314: #define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPROMOTIONMANAGER_INLINE_HPP stefank@2314: nloodin@3665: #include "gc_implementation/parallelScavenge/psOldGen.hpp" stefank@2314: #include "gc_implementation/parallelScavenge/psPromotionManager.hpp" stefank@2314: #include "gc_implementation/parallelScavenge/psScavenge.hpp" stefank@2314: duke@435: inline PSPromotionManager* PSPromotionManager::manager_array(int index) { duke@435: assert(_manager_array != NULL, "access of NULL manager_array"); duke@435: assert(index >= 0 && index <= (int)ParallelGCThreads, "out of range manager_array access"); stefank@5515: return &_manager_array[index]; duke@435: } duke@435: coleenp@548: template coleenp@548: inline void PSPromotionManager::claim_or_forward_internal_depth(T* p) { coleenp@548: if (p != NULL) { // XXX: error if p != NULL here coleenp@548: oop o = oopDesc::load_decode_heap_oop_not_null(p); duke@435: if (o->is_forwarded()) { duke@435: o = o->forwardee(); duke@435: // Card mark stefank@5202: if (PSScavenge::is_obj_in_young(o)) { duke@435: PSScavenge::card_table()->inline_write_ref_field_gc(p, o); duke@435: } coleenp@548: oopDesc::encode_store_heap_oop_not_null(p, o); duke@435: } else { duke@435: push_depth(p); duke@435: } duke@435: } duke@435: } duke@435: coleenp@548: template coleenp@548: inline void PSPromotionManager::claim_or_forward_depth(T* p) { coleenp@548: assert(PSScavenge::should_scavenge(p, true), "revisiting object?"); coleenp@548: assert(Universe::heap()->kind() == CollectedHeap::ParallelScavengeHeap, coleenp@548: "Sanity"); duke@435: assert(Universe::heap()->is_in(p), "pointer outside heap"); duke@435: duke@435: claim_or_forward_internal_depth(p); duke@435: } duke@435: iveresov@3536: // iveresov@3536: // This method is pretty bulky. It would be nice to split it up iveresov@3536: // into smaller submethods, but we need to be careful not to hurt iveresov@3536: // performance. iveresov@3536: // iveresov@3536: template iveresov@3536: oop PSPromotionManager::copy_to_survivor_space(oop o) { iveresov@3536: assert(PSScavenge::should_scavenge(&o), "Sanity"); iveresov@3536: iveresov@3536: oop new_obj = NULL; iveresov@3536: iveresov@3536: // NOTE! We must be very careful with any methods that access the mark iveresov@3536: // in o. There may be multiple threads racing on it, and it may be forwarded iveresov@3536: // at any time. Do not use oop methods for accessing the mark! iveresov@3536: markOop test_mark = o->mark(); iveresov@3536: iveresov@3536: // The same test as "o->is_forwarded()" iveresov@3536: if (!test_mark->is_marked()) { iveresov@3536: bool new_obj_is_tenured = false; iveresov@3536: size_t new_obj_size = o->size(); iveresov@3536: iveresov@3536: if (!promote_immediately) { iveresov@3536: // Find the objects age, MT safe. jwilhelm@4129: uint age = (test_mark->has_displaced_mark_helper() /* o->has_displaced_mark() */) ? iveresov@3536: test_mark->displaced_mark_helper()->age() : test_mark->age(); iveresov@3536: iveresov@3536: // Try allocating obj in to-space (unless too old) iveresov@3536: if (age < PSScavenge::tenuring_threshold()) { iveresov@3536: new_obj = (oop) _young_lab.allocate(new_obj_size); iveresov@3536: if (new_obj == NULL && !_young_gen_is_full) { iveresov@3536: // Do we allocate directly, or flush and refill? iveresov@3536: if (new_obj_size > (YoungPLABSize / 2)) { iveresov@3536: // Allocate this object directly iveresov@3536: new_obj = (oop)young_space()->cas_allocate(new_obj_size); iveresov@3536: } else { iveresov@3536: // Flush and fill iveresov@3536: _young_lab.flush(); iveresov@3536: iveresov@3536: HeapWord* lab_base = young_space()->cas_allocate(YoungPLABSize); iveresov@3536: if (lab_base != NULL) { iveresov@3536: _young_lab.initialize(MemRegion(lab_base, YoungPLABSize)); iveresov@3536: // Try the young lab allocation again. iveresov@3536: new_obj = (oop) _young_lab.allocate(new_obj_size); iveresov@3536: } else { iveresov@3536: _young_gen_is_full = true; iveresov@3536: } iveresov@3536: } iveresov@3536: } iveresov@3536: } iveresov@3536: } iveresov@3536: iveresov@3536: // Otherwise try allocating obj tenured iveresov@3536: if (new_obj == NULL) { iveresov@3536: #ifndef PRODUCT iveresov@3536: if (Universe::heap()->promotion_should_fail()) { iveresov@3536: return oop_promotion_failed(o, test_mark); iveresov@3536: } iveresov@3536: #endif // #ifndef PRODUCT iveresov@3536: iveresov@3536: new_obj = (oop) _old_lab.allocate(new_obj_size); iveresov@3536: new_obj_is_tenured = true; iveresov@3536: iveresov@3536: if (new_obj == NULL) { iveresov@3536: if (!_old_gen_is_full) { iveresov@3536: // Do we allocate directly, or flush and refill? iveresov@3536: if (new_obj_size > (OldPLABSize / 2)) { iveresov@3536: // Allocate this object directly iveresov@3536: new_obj = (oop)old_gen()->cas_allocate(new_obj_size); iveresov@3536: } else { iveresov@3536: // Flush and fill iveresov@3536: _old_lab.flush(); iveresov@3536: iveresov@3536: HeapWord* lab_base = old_gen()->cas_allocate(OldPLABSize); iveresov@3536: if(lab_base != NULL) { jmasa@4128: #ifdef ASSERT jmasa@4128: // Delay the initialization of the promotion lab (plab). jmasa@4128: // This exposes uninitialized plabs to card table processing. jmasa@4128: if (GCWorkerDelayMillis > 0) { jmasa@4128: os::sleep(Thread::current(), GCWorkerDelayMillis, false); jmasa@4128: } jmasa@4128: #endif iveresov@3536: _old_lab.initialize(MemRegion(lab_base, OldPLABSize)); iveresov@3536: // Try the old lab allocation again. iveresov@3536: new_obj = (oop) _old_lab.allocate(new_obj_size); iveresov@3536: } iveresov@3536: } iveresov@3536: } iveresov@3536: iveresov@3536: // This is the promotion failed test, and code handling. iveresov@3536: // The code belongs here for two reasons. It is slightly sla@5237: // different than the code below, and cannot share the iveresov@3536: // CAS testing code. Keeping the code here also minimizes iveresov@3536: // the impact on the common case fast path code. iveresov@3536: iveresov@3536: if (new_obj == NULL) { iveresov@3536: _old_gen_is_full = true; iveresov@3536: return oop_promotion_failed(o, test_mark); iveresov@3536: } iveresov@3536: } iveresov@3536: } iveresov@3536: iveresov@3536: assert(new_obj != NULL, "allocation should have succeeded"); iveresov@3536: iveresov@3536: // Copy obj iveresov@3536: Copy::aligned_disjoint_words((HeapWord*)o, (HeapWord*)new_obj, new_obj_size); iveresov@3536: iveresov@3536: // Now we have to CAS in the header. iveresov@3536: if (o->cas_forward_to(new_obj, test_mark)) { iveresov@3536: // We won any races, we "own" this object. iveresov@3536: assert(new_obj == o->forwardee(), "Sanity"); iveresov@3536: iveresov@3536: // Increment age if obj still in new generation. Now that iveresov@3536: // we're dealing with a markOop that cannot change, it is iveresov@3536: // okay to use the non mt safe oop methods. iveresov@3536: if (!new_obj_is_tenured) { iveresov@3536: new_obj->incr_age(); iveresov@3536: assert(young_space()->contains(new_obj), "Attempt to push non-promoted obj"); iveresov@3536: } iveresov@3536: iveresov@3536: // Do the size comparison first with new_obj_size, which we iveresov@3536: // already have. Hopefully, only a few objects are larger than iveresov@3536: // _min_array_size_for_chunking, and most of them will be arrays. iveresov@3536: // So, the is->objArray() test would be very infrequent. iveresov@3536: if (new_obj_size > _min_array_size_for_chunking && iveresov@3536: new_obj->is_objArray() && iveresov@3536: PSChunkLargeArrays) { iveresov@3536: // we'll chunk it iveresov@3536: oop* const masked_o = mask_chunked_array_oop(o); iveresov@3536: push_depth(masked_o); iveresov@3536: TASKQUEUE_STATS_ONLY(++_arrays_chunked; ++_masked_pushes); iveresov@3536: } else { iveresov@3536: // we'll just push its contents iveresov@3536: new_obj->push_contents(this); iveresov@3536: } iveresov@3536: } else { iveresov@3536: // We lost, someone else "owns" this object iveresov@3536: guarantee(o->is_forwarded(), "Object must be forwarded if the cas failed."); iveresov@3536: iveresov@3536: // Try to deallocate the space. If it was directly allocated we cannot iveresov@3536: // deallocate it, so we have to test. If the deallocation fails, iveresov@3536: // overwrite with a filler object. iveresov@3536: if (new_obj_is_tenured) { iveresov@3536: if (!_old_lab.unallocate_object((HeapWord*) new_obj, new_obj_size)) { iveresov@3536: CollectedHeap::fill_with_object((HeapWord*) new_obj, new_obj_size); iveresov@3536: } iveresov@3536: } else if (!_young_lab.unallocate_object((HeapWord*) new_obj, new_obj_size)) { iveresov@3536: CollectedHeap::fill_with_object((HeapWord*) new_obj, new_obj_size); iveresov@3536: } iveresov@3536: iveresov@3536: // don't update this before the unallocation! iveresov@3536: new_obj = o->forwardee(); iveresov@3536: } iveresov@3536: } else { iveresov@3536: assert(o->is_forwarded(), "Sanity"); iveresov@3536: new_obj = o->forwardee(); iveresov@3536: } iveresov@3536: coleenp@4037: #ifndef PRODUCT iveresov@3536: // This code must come after the CAS test, or it will print incorrect iveresov@3536: // information. iveresov@3536: if (TraceScavenge) { coleenp@4037: gclog_or_tty->print_cr("{%s %s " PTR_FORMAT " -> " PTR_FORMAT " (%d)}", iveresov@3536: PSScavenge::should_scavenge(&new_obj) ? "copying" : "tenuring", hseigel@5784: new_obj->klass()->internal_name(), (void *)o, (void *)new_obj, new_obj->size()); iveresov@3536: } iveresov@3536: #endif iveresov@3536: iveresov@3536: return new_obj; iveresov@3536: } iveresov@3536: iveresov@3536: coleenp@548: inline void PSPromotionManager::process_popped_location_depth(StarTask p) { duke@435: if (is_oop_masked(p)) { duke@435: assert(PSChunkLargeArrays, "invariant"); duke@435: oop const old = unmask_chunked_array_oop(p); duke@435: process_array_chunk(old); duke@435: } else { coleenp@548: if (p.is_narrow()) { ysr@1280: assert(UseCompressedOops, "Error"); iveresov@3536: PSScavenge::copy_and_push_safe_barrier(this, p); coleenp@548: } else { iveresov@3536: PSScavenge::copy_and_push_safe_barrier(this, p); coleenp@548: } duke@435: } duke@435: } jcoomes@2020: jcoomes@2020: #if TASKQUEUE_STATS jcoomes@2020: void PSPromotionManager::record_steal(StarTask& p) { jcoomes@2020: if (is_oop_masked(p)) { jcoomes@2020: ++_masked_steals; jcoomes@2020: } jcoomes@2020: } jcoomes@2020: #endif // TASKQUEUE_STATS stefank@2314: stefank@2314: #endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPROMOTIONMANAGER_INLINE_HPP