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