Path: blob/master/src/hotspot/share/gc/parallel/psPromotionLAB.cpp
41152 views
/*1* Copyright (c) 2002, 2018, 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/parallel/mutableSpace.hpp"26#include "gc/parallel/parallelScavengeHeap.hpp"27#include "gc/parallel/psPromotionLAB.hpp"28#include "memory/universe.hpp"29#include "oops/oop.inline.hpp"3031size_t PSPromotionLAB::filler_header_size;3233// This is the shared initialization code. It sets up the basic pointers,34// and allows enough extra space for a filler object. We call a virtual35// method, "lab_is_valid()" to handle the different asserts the old/young36// labs require.37void PSPromotionLAB::initialize(MemRegion lab) {38assert(lab_is_valid(lab), "Sanity");3940HeapWord* bottom = lab.start();41HeapWord* end = lab.end();4243set_bottom(bottom);44set_end(end);45set_top(bottom);4647// Initialize after VM starts up because header_size depends on compressed48// oops.49filler_header_size = align_object_size(typeArrayOopDesc::header_size(T_INT));5051// We can be initialized to a zero size!52if (free() > 0) {53if (ZapUnusedHeapArea) {54debug_only(Copy::fill_to_words(top(), free()/HeapWordSize, badHeapWord));55}5657// NOTE! We need to allow space for a filler object.58assert(lab.word_size() >= filler_header_size, "lab is too small");59end = end - filler_header_size;60set_end(end);6162_state = needs_flush;63} else {64_state = zero_size;65}6667assert(this->top() <= this->end(), "pointers out of order");68}6970// Fill all remaining lab space with an unreachable object.71// The goal is to leave a contiguous parseable span of objects.72void PSPromotionLAB::flush() {73assert(_state != flushed, "Attempt to flush PLAB twice");74assert(top() <= end(), "pointers out of order");7576// If we were initialized to a zero sized lab, there is77// nothing to flush78if (_state == zero_size)79return;8081// PLAB's never allocate the last aligned_header_size82// so they can always fill with an array.83HeapWord* tlab_end = end() + filler_header_size;84typeArrayOop filler_oop = (typeArrayOop) cast_to_oop(top());85filler_oop->set_mark(markWord::prototype());86filler_oop->set_klass(Universe::intArrayKlassObj());87const size_t array_length =88pointer_delta(tlab_end, top()) - typeArrayOopDesc::header_size(T_INT);89assert( (array_length * (HeapWordSize/sizeof(jint))) < (size_t)max_jint, "array too big in PSPromotionLAB");90filler_oop->set_length((int)(array_length * (HeapWordSize/sizeof(jint))));9192#ifdef ASSERT93// Note that we actually DO NOT want to use the aligned header size!94HeapWord* elt_words = cast_from_oop<HeapWord*>(filler_oop) + typeArrayOopDesc::header_size(T_INT);95Copy::fill_to_words(elt_words, array_length, 0xDEAABABE);96#endif9798set_bottom(NULL);99set_end(NULL);100set_top(NULL);101102_state = flushed;103}104105bool PSPromotionLAB::unallocate_object(HeapWord* obj, size_t obj_size) {106assert(ParallelScavengeHeap::heap()->is_in(obj), "Object outside heap");107108if (contains(obj)) {109HeapWord* object_end = obj + obj_size;110assert(object_end == top(), "Not matching last allocation");111112set_top(obj);113return true;114}115116return false;117}118119// Fill all remaining lab space with an unreachable object.120// The goal is to leave a contiguous parseable span of objects.121void PSOldPromotionLAB::flush() {122assert(_state != flushed, "Attempt to flush PLAB twice");123assert(top() <= end(), "pointers out of order");124125if (_state == zero_size)126return;127128HeapWord* obj = top();129130PSPromotionLAB::flush();131132assert(_start_array != NULL, "Sanity");133134_start_array->allocate_block(obj);135}136137#ifdef ASSERT138139bool PSYoungPromotionLAB::lab_is_valid(MemRegion lab) {140ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();141MutableSpace* to_space = heap->young_gen()->to_space();142MemRegion used = to_space->used_region();143if (used.contains(lab)) {144return true;145}146147return false;148}149150bool PSOldPromotionLAB::lab_is_valid(MemRegion lab) {151assert(_start_array->covered_region().contains(lab), "Sanity");152153ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();154PSOldGen* old_gen = heap->old_gen();155MemRegion used = old_gen->object_space()->used_region();156157if (used.contains(lab)) {158return true;159}160161return false;162}163164#endif /* ASSERT */165166167