0N/A/*
1879N/A * Copyright (c) 2002, 2010, 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#include "precompiled.hpp"
1879N/A#include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
1879N/A#include "gc_implementation/parallelScavenge/psPromotionLAB.hpp"
1879N/A#include "gc_implementation/shared/mutableSpace.hpp"
1879N/A#include "oops/oop.inline.hpp"
0N/A
113N/Asize_t PSPromotionLAB::filler_header_size;
0N/A
0N/A// This is the shared initialization code. It sets up the basic pointers,
0N/A// and allows enough extra space for a filler object. We call a virtual
0N/A// method, "lab_is_valid()" to handle the different asserts the old/young
0N/A// labs require.
0N/Avoid PSPromotionLAB::initialize(MemRegion lab) {
0N/A assert(lab_is_valid(lab), "Sanity");
0N/A
0N/A HeapWord* bottom = lab.start();
0N/A HeapWord* end = lab.end();
0N/A
0N/A set_bottom(bottom);
0N/A set_end(end);
0N/A set_top(bottom);
0N/A
113N/A // Initialize after VM starts up because header_size depends on compressed
113N/A // oops.
113N/A filler_header_size = align_object_size(typeArrayOopDesc::header_size(T_INT));
113N/A
0N/A // We can be initialized to a zero size!
0N/A if (free() > 0) {
0N/A if (ZapUnusedHeapArea) {
0N/A debug_only(Copy::fill_to_words(top(), free()/HeapWordSize, badHeapWord));
0N/A }
0N/A
0N/A // NOTE! We need to allow space for a filler object.
0N/A assert(lab.word_size() >= filler_header_size, "lab is too small");
0N/A end = end - filler_header_size;
0N/A set_end(end);
0N/A
0N/A _state = needs_flush;
0N/A } else {
0N/A _state = zero_size;
0N/A }
0N/A
0N/A assert(this->top() <= this->end(), "pointers out of order");
0N/A}
0N/A
0N/A// Fill all remaining lab space with an unreachable object.
0N/A// The goal is to leave a contiguous parseable span of objects.
0N/Avoid PSPromotionLAB::flush() {
0N/A assert(_state != flushed, "Attempt to flush PLAB twice");
0N/A assert(top() <= end(), "pointers out of order");
0N/A
0N/A // If we were initialized to a zero sized lab, there is
0N/A // nothing to flush
0N/A if (_state == zero_size)
0N/A return;
0N/A
0N/A // PLAB's never allocate the last aligned_header_size
0N/A // so they can always fill with an array.
0N/A HeapWord* tlab_end = end() + filler_header_size;
0N/A typeArrayOop filler_oop = (typeArrayOop) top();
0N/A filler_oop->set_mark(markOopDesc::prototype());
0N/A filler_oop->set_klass(Universe::intArrayKlassObj());
0N/A const size_t array_length =
0N/A pointer_delta(tlab_end, top()) - typeArrayOopDesc::header_size(T_INT);
0N/A assert( (array_length * (HeapWordSize/sizeof(jint))) < (size_t)max_jint, "array too big in PSPromotionLAB");
0N/A filler_oop->set_length((int)(array_length * (HeapWordSize/sizeof(jint))));
0N/A
0N/A#ifdef ASSERT
0N/A // Note that we actually DO NOT want to use the aligned header size!
0N/A HeapWord* elt_words = ((HeapWord*)filler_oop) + typeArrayOopDesc::header_size(T_INT);
0N/A Copy::fill_to_words(elt_words, array_length, 0xDEAABABE);
0N/A#endif
0N/A
0N/A set_bottom(NULL);
0N/A set_end(NULL);
0N/A set_top(NULL);
0N/A
0N/A _state = flushed;
0N/A}
0N/A
2821N/Abool PSPromotionLAB::unallocate_object(HeapWord* obj, size_t obj_size) {
0N/A assert(Universe::heap()->is_in(obj), "Object outside heap");
0N/A
0N/A if (contains(obj)) {
2821N/A HeapWord* object_end = obj + obj_size;
2821N/A assert(object_end == top(), "Not matching last allocation");
0N/A
2821N/A set_top(obj);
2821N/A return true;
0N/A }
0N/A
0N/A return false;
0N/A}
0N/A
0N/A// Fill all remaining lab space with an unreachable object.
0N/A// The goal is to leave a contiguous parseable span of objects.
0N/Avoid PSOldPromotionLAB::flush() {
0N/A assert(_state != flushed, "Attempt to flush PLAB twice");
0N/A assert(top() <= end(), "pointers out of order");
0N/A
0N/A if (_state == zero_size)
0N/A return;
0N/A
0N/A HeapWord* obj = top();
0N/A
0N/A PSPromotionLAB::flush();
0N/A
0N/A assert(_start_array != NULL, "Sanity");
0N/A
0N/A _start_array->allocate_block(obj);
0N/A}
0N/A
0N/A#ifdef ASSERT
0N/A
0N/Abool PSYoungPromotionLAB::lab_is_valid(MemRegion lab) {
0N/A ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
0N/A assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
0N/A
0N/A MutableSpace* to_space = heap->young_gen()->to_space();
0N/A MemRegion used = to_space->used_region();
0N/A if (used.contains(lab)) {
0N/A return true;
0N/A }
0N/A
0N/A return false;
0N/A}
0N/A
0N/Abool PSOldPromotionLAB::lab_is_valid(MemRegion lab) {
0N/A ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
0N/A assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
0N/A assert(_start_array->covered_region().contains(lab), "Sanity");
0N/A
0N/A PSOldGen* old_gen = heap->old_gen();
0N/A MemRegion used = old_gen->object_space()->used_region();
0N/A
0N/A if (used.contains(lab)) {
0N/A return true;
0N/A }
0N/A
0N/A return false;
0N/A}
0N/A
0N/A#endif /* ASSERT */