aoqi@0: /* aoqi@0: * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPROMOTIONMANAGER_INLINE_HPP aoqi@0: #define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPROMOTIONMANAGER_INLINE_HPP aoqi@0: aoqi@0: #include "gc_implementation/parallelScavenge/psOldGen.hpp" aoqi@0: #include "gc_implementation/parallelScavenge/psPromotionManager.hpp" aoqi@0: #include "gc_implementation/parallelScavenge/psScavenge.hpp" aoqi@0: #include "oops/oop.psgc.inline.hpp" aoqi@0: aoqi@0: inline PSPromotionManager* PSPromotionManager::manager_array(int index) { aoqi@0: assert(_manager_array != NULL, "access of NULL manager_array"); aoqi@0: assert(index >= 0 && index <= (int)ParallelGCThreads, "out of range manager_array access"); aoqi@0: return &_manager_array[index]; aoqi@0: } aoqi@0: aoqi@0: template aoqi@0: inline void PSPromotionManager::claim_or_forward_internal_depth(T* p) { aoqi@0: if (p != NULL) { // XXX: error if p != NULL here aoqi@0: oop o = oopDesc::load_decode_heap_oop_not_null(p); aoqi@0: if (o->is_forwarded()) { aoqi@0: o = o->forwardee(); aoqi@0: // Card mark aoqi@0: if (PSScavenge::is_obj_in_young(o)) { aoqi@0: PSScavenge::card_table()->inline_write_ref_field_gc(p, o); aoqi@0: } aoqi@0: oopDesc::encode_store_heap_oop_not_null(p, o); aoqi@0: } else { aoqi@0: push_depth(p); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: template aoqi@0: inline void PSPromotionManager::claim_or_forward_depth(T* p) { aoqi@0: assert(PSScavenge::should_scavenge(p, true), "revisiting object?"); aoqi@0: assert(Universe::heap()->kind() == CollectedHeap::ParallelScavengeHeap, aoqi@0: "Sanity"); aoqi@0: assert(Universe::heap()->is_in(p), "pointer outside heap"); aoqi@0: aoqi@0: claim_or_forward_internal_depth(p); aoqi@0: } aoqi@0: aoqi@0: // aoqi@0: // This method is pretty bulky. It would be nice to split it up aoqi@0: // into smaller submethods, but we need to be careful not to hurt aoqi@0: // performance. aoqi@0: // aoqi@0: template aoqi@0: oop PSPromotionManager::copy_to_survivor_space(oop o) { aoqi@0: assert(PSScavenge::should_scavenge(&o), "Sanity"); aoqi@0: aoqi@0: oop new_obj = NULL; aoqi@0: aoqi@0: // NOTE! We must be very careful with any methods that access the mark aoqi@0: // in o. There may be multiple threads racing on it, and it may be forwarded aoqi@0: // at any time. Do not use oop methods for accessing the mark! aoqi@0: markOop test_mark = o->mark(); aoqi@0: aoqi@0: // The same test as "o->is_forwarded()" aoqi@0: if (!test_mark->is_marked()) { aoqi@0: bool new_obj_is_tenured = false; aoqi@0: size_t new_obj_size = o->size(); aoqi@0: aoqi@0: if (!promote_immediately) { aoqi@0: // Find the objects age, MT safe. aoqi@0: uint age = (test_mark->has_displaced_mark_helper() /* o->has_displaced_mark() */) ? aoqi@0: test_mark->displaced_mark_helper()->age() : test_mark->age(); aoqi@0: aoqi@0: // Try allocating obj in to-space (unless too old) aoqi@0: if (age < PSScavenge::tenuring_threshold()) { aoqi@0: new_obj = (oop) _young_lab.allocate(new_obj_size); aoqi@0: if (new_obj == NULL && !_young_gen_is_full) { aoqi@0: // Do we allocate directly, or flush and refill? aoqi@0: if (new_obj_size > (YoungPLABSize / 2)) { aoqi@0: // Allocate this object directly aoqi@0: new_obj = (oop)young_space()->cas_allocate(new_obj_size); aoqi@0: } else { aoqi@0: // Flush and fill aoqi@0: _young_lab.flush(); aoqi@0: aoqi@0: HeapWord* lab_base = young_space()->cas_allocate(YoungPLABSize); aoqi@0: if (lab_base != NULL) { aoqi@0: _young_lab.initialize(MemRegion(lab_base, YoungPLABSize)); aoqi@0: // Try the young lab allocation again. aoqi@0: new_obj = (oop) _young_lab.allocate(new_obj_size); aoqi@0: } else { aoqi@0: _young_gen_is_full = true; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Otherwise try allocating obj tenured aoqi@0: if (new_obj == NULL) { aoqi@0: #ifndef PRODUCT aoqi@0: if (Universe::heap()->promotion_should_fail()) { aoqi@0: return oop_promotion_failed(o, test_mark); aoqi@0: } aoqi@0: #endif // #ifndef PRODUCT aoqi@0: aoqi@0: new_obj = (oop) _old_lab.allocate(new_obj_size); aoqi@0: new_obj_is_tenured = true; aoqi@0: aoqi@0: if (new_obj == NULL) { aoqi@0: if (!_old_gen_is_full) { aoqi@0: // Do we allocate directly, or flush and refill? aoqi@0: if (new_obj_size > (OldPLABSize / 2)) { aoqi@0: // Allocate this object directly aoqi@0: new_obj = (oop)old_gen()->cas_allocate(new_obj_size); aoqi@0: } else { aoqi@0: // Flush and fill aoqi@0: _old_lab.flush(); aoqi@0: aoqi@0: HeapWord* lab_base = old_gen()->cas_allocate(OldPLABSize); aoqi@0: if(lab_base != NULL) { aoqi@0: #ifdef ASSERT aoqi@0: // Delay the initialization of the promotion lab (plab). aoqi@0: // This exposes uninitialized plabs to card table processing. aoqi@0: if (GCWorkerDelayMillis > 0) { aoqi@0: os::sleep(Thread::current(), GCWorkerDelayMillis, false); aoqi@0: } aoqi@0: #endif aoqi@0: _old_lab.initialize(MemRegion(lab_base, OldPLABSize)); aoqi@0: // Try the old lab allocation again. aoqi@0: new_obj = (oop) _old_lab.allocate(new_obj_size); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // This is the promotion failed test, and code handling. aoqi@0: // The code belongs here for two reasons. It is slightly aoqi@0: // different than the code below, and cannot share the aoqi@0: // CAS testing code. Keeping the code here also minimizes aoqi@0: // the impact on the common case fast path code. aoqi@0: aoqi@0: if (new_obj == NULL) { aoqi@0: _old_gen_is_full = true; aoqi@0: return oop_promotion_failed(o, test_mark); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: assert(new_obj != NULL, "allocation should have succeeded"); aoqi@0: aoqi@0: // Copy obj aoqi@0: Copy::aligned_disjoint_words((HeapWord*)o, (HeapWord*)new_obj, new_obj_size); aoqi@0: aoqi@0: // Now we have to CAS in the header. aoqi@0: if (o->cas_forward_to(new_obj, test_mark)) { aoqi@0: // We won any races, we "own" this object. aoqi@0: assert(new_obj == o->forwardee(), "Sanity"); aoqi@0: aoqi@0: // Increment age if obj still in new generation. Now that aoqi@0: // we're dealing with a markOop that cannot change, it is aoqi@0: // okay to use the non mt safe oop methods. aoqi@0: if (!new_obj_is_tenured) { aoqi@0: new_obj->incr_age(); aoqi@0: assert(young_space()->contains(new_obj), "Attempt to push non-promoted obj"); aoqi@0: } aoqi@0: aoqi@0: // Do the size comparison first with new_obj_size, which we aoqi@0: // already have. Hopefully, only a few objects are larger than aoqi@0: // _min_array_size_for_chunking, and most of them will be arrays. aoqi@0: // So, the is->objArray() test would be very infrequent. aoqi@0: if (new_obj_size > _min_array_size_for_chunking && aoqi@0: new_obj->is_objArray() && aoqi@0: PSChunkLargeArrays) { aoqi@0: // we'll chunk it aoqi@0: oop* const masked_o = mask_chunked_array_oop(o); aoqi@0: push_depth(masked_o); aoqi@0: TASKQUEUE_STATS_ONLY(++_arrays_chunked; ++_masked_pushes); aoqi@0: } else { aoqi@0: // we'll just push its contents aoqi@0: new_obj->push_contents(this); aoqi@0: } aoqi@0: } else { aoqi@0: // We lost, someone else "owns" this object aoqi@0: guarantee(o->is_forwarded(), "Object must be forwarded if the cas failed."); aoqi@0: aoqi@0: // Try to deallocate the space. If it was directly allocated we cannot aoqi@0: // deallocate it, so we have to test. If the deallocation fails, aoqi@0: // overwrite with a filler object. aoqi@0: if (new_obj_is_tenured) { aoqi@0: if (!_old_lab.unallocate_object((HeapWord*) new_obj, new_obj_size)) { aoqi@0: CollectedHeap::fill_with_object((HeapWord*) new_obj, new_obj_size); aoqi@0: } aoqi@0: } else if (!_young_lab.unallocate_object((HeapWord*) new_obj, new_obj_size)) { aoqi@0: CollectedHeap::fill_with_object((HeapWord*) new_obj, new_obj_size); aoqi@0: } aoqi@0: aoqi@0: // don't update this before the unallocation! aoqi@0: new_obj = o->forwardee(); aoqi@0: } aoqi@0: } else { aoqi@0: assert(o->is_forwarded(), "Sanity"); aoqi@0: new_obj = o->forwardee(); aoqi@0: } aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: // This code must come after the CAS test, or it will print incorrect aoqi@0: // information. aoqi@0: if (TraceScavenge) { aoqi@0: gclog_or_tty->print_cr("{%s %s " PTR_FORMAT " -> " PTR_FORMAT " (%d)}", aoqi@0: PSScavenge::should_scavenge(&new_obj) ? "copying" : "tenuring", aoqi@0: new_obj->klass()->internal_name(), p2i((void *)o), p2i((void *)new_obj), new_obj->size()); aoqi@0: } aoqi@0: #endif aoqi@0: aoqi@0: return new_obj; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: inline void PSPromotionManager::process_popped_location_depth(StarTask p) { aoqi@0: if (is_oop_masked(p)) { aoqi@0: assert(PSChunkLargeArrays, "invariant"); aoqi@0: oop const old = unmask_chunked_array_oop(p); aoqi@0: process_array_chunk(old); aoqi@0: } else { aoqi@0: if (p.is_narrow()) { aoqi@0: assert(UseCompressedOops, "Error"); aoqi@0: PSScavenge::copy_and_push_safe_barrier(this, p); aoqi@0: } else { aoqi@0: PSScavenge::copy_and_push_safe_barrier(this, p); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: #if TASKQUEUE_STATS aoqi@0: void PSPromotionManager::record_steal(StarTask& p) { aoqi@0: if (is_oop_masked(p)) { aoqi@0: ++_masked_steals; aoqi@0: } aoqi@0: } aoqi@0: #endif // TASKQUEUE_STATS aoqi@0: aoqi@0: #endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPROMOTIONMANAGER_INLINE_HPP