Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionLAB.cpp
38920 views
/*1* Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"26#include "gc_implementation/parallelScavenge/psPromotionLAB.hpp"27#include "gc_implementation/shared/mutableSpace.hpp"28#include "oops/oop.inline.hpp"2930size_t PSPromotionLAB::filler_header_size;3132// This is the shared initialization code. It sets up the basic pointers,33// and allows enough extra space for a filler object. We call a virtual34// method, "lab_is_valid()" to handle the different asserts the old/young35// labs require.36void PSPromotionLAB::initialize(MemRegion lab) {37assert(lab_is_valid(lab), "Sanity");3839HeapWord* bottom = lab.start();40HeapWord* end = lab.end();4142set_bottom(bottom);43set_end(end);44set_top(bottom);4546// Initialize after VM starts up because header_size depends on compressed47// oops.48filler_header_size = align_object_size(typeArrayOopDesc::header_size(T_INT));4950// We can be initialized to a zero size!51if (free() > 0) {52if (ZapUnusedHeapArea) {53debug_only(Copy::fill_to_words(top(), free()/HeapWordSize, badHeapWord));54}5556// NOTE! We need to allow space for a filler object.57assert(lab.word_size() >= filler_header_size, "lab is too small");58end = end - filler_header_size;59set_end(end);6061_state = needs_flush;62} else {63_state = zero_size;64}6566assert(this->top() <= this->end(), "pointers out of order");67}6869// Fill all remaining lab space with an unreachable object.70// The goal is to leave a contiguous parseable span of objects.71void PSPromotionLAB::flush() {72assert(_state != flushed, "Attempt to flush PLAB twice");73assert(top() <= end(), "pointers out of order");7475// If we were initialized to a zero sized lab, there is76// nothing to flush77if (_state == zero_size)78return;7980// PLAB's never allocate the last aligned_header_size81// so they can always fill with an array.82HeapWord* tlab_end = end() + filler_header_size;83typeArrayOop filler_oop = (typeArrayOop) top();84filler_oop->set_mark(markOopDesc::prototype());85filler_oop->set_klass(Universe::intArrayKlassObj());86const size_t array_length =87pointer_delta(tlab_end, top()) - typeArrayOopDesc::header_size(T_INT);88assert( (array_length * (HeapWordSize/sizeof(jint))) < (size_t)max_jint, "array too big in PSPromotionLAB");89filler_oop->set_length((int)(array_length * (HeapWordSize/sizeof(jint))));9091#ifdef ASSERT92// Note that we actually DO NOT want to use the aligned header size!93HeapWord* elt_words = ((HeapWord*)filler_oop) + typeArrayOopDesc::header_size(T_INT);94Copy::fill_to_words(elt_words, array_length, 0xDEAABABE);95#endif9697set_bottom(NULL);98set_end(NULL);99set_top(NULL);100101_state = flushed;102}103104bool PSPromotionLAB::unallocate_object(HeapWord* obj, size_t obj_size) {105assert(Universe::heap()->is_in(obj), "Object outside heap");106107if (contains(obj)) {108HeapWord* object_end = obj + obj_size;109assert(object_end == top(), "Not matching last allocation");110111set_top(obj);112return true;113}114115return false;116}117118// Fill all remaining lab space with an unreachable object.119// The goal is to leave a contiguous parseable span of objects.120void PSOldPromotionLAB::flush() {121assert(_state != flushed, "Attempt to flush PLAB twice");122assert(top() <= end(), "pointers out of order");123124if (_state == zero_size)125return;126127HeapWord* obj = top();128129PSPromotionLAB::flush();130131assert(_start_array != NULL, "Sanity");132133_start_array->allocate_block(obj);134}135136#ifdef ASSERT137138bool PSYoungPromotionLAB::lab_is_valid(MemRegion lab) {139ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();140assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");141142MutableSpace* to_space = heap->young_gen()->to_space();143MemRegion used = to_space->used_region();144if (used.contains(lab)) {145return true;146}147148return false;149}150151bool PSOldPromotionLAB::lab_is_valid(MemRegion lab) {152ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();153assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");154assert(_start_array->covered_region().contains(lab), "Sanity");155156PSOldGen* old_gen = heap->old_gen();157MemRegion used = old_gen->object_space()->used_region();158159if (used.contains(lab)) {160return true;161}162163return false;164}165166#endif /* ASSERT */167168169