Path: blob/master/src/hotspot/share/gc/parallel/psPromotionLAB.hpp
41149 views
/*1* Copyright (c) 2002, 2020, 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#ifndef SHARE_GC_PARALLEL_PSPROMOTIONLAB_HPP25#define SHARE_GC_PARALLEL_PSPROMOTIONLAB_HPP2627#include "gc/parallel/objectStartArray.hpp"28#include "gc/shared/collectedHeap.hpp"29#include "memory/allocation.hpp"3031//32// PSPromotionLAB is a parallel scavenge promotion lab. This class acts very33// much like a MutableSpace. We couldn't embed a MutableSpace, though, as34// it has a considerable number of asserts and invariants that are violated.35//3637class ObjectStartArray;3839class PSPromotionLAB : public CHeapObj<mtGC> {40protected:41static size_t filler_header_size;4243enum LabState {44needs_flush,45flushed,46zero_size47};4849HeapWord* _top;50HeapWord* _bottom;51HeapWord* _end;52LabState _state;5354void set_top(HeapWord* value) { _top = value; }55void set_bottom(HeapWord* value) { _bottom = value; }56void set_end(HeapWord* value) { _end = value; }5758// The shared initialize code invokes this.59debug_only(virtual bool lab_is_valid(MemRegion lab) { return false; });6061PSPromotionLAB() : _top(NULL), _bottom(NULL), _end(NULL), _state(zero_size) { }6263public:64// Filling and flushing.65void initialize(MemRegion lab);6667virtual void flush();6869// Accessors70HeapWord* bottom() const { return _bottom; }71HeapWord* end() const { return _end; }72HeapWord* top() const { return _top; }7374bool is_flushed() { return _state == flushed; }7576bool unallocate_object(HeapWord* obj, size_t obj_size);7778// Returns a subregion containing all objects in this space.79MemRegion used_region() { return MemRegion(bottom(), top()); }8081// Boolean queries.82bool is_empty() const { return used() == 0; }83bool not_empty() const { return used() > 0; }84bool contains(const void* p) const { return _bottom <= p && p < _end; }8586// Size computations. Sizes are in bytes.87size_t capacity() const { return byte_size(bottom(), end()); }88size_t used() const { return byte_size(bottom(), top()); }89size_t free() const { return byte_size(top(), end()); }90};9192class PSYoungPromotionLAB : public PSPromotionLAB {93public:94PSYoungPromotionLAB() { }9596// Not MT safe97inline HeapWord* allocate(size_t size);9899debug_only(virtual bool lab_is_valid(MemRegion lab);)100};101102class PSOldPromotionLAB : public PSPromotionLAB {103private:104ObjectStartArray* _start_array;105106public:107PSOldPromotionLAB() : _start_array(NULL) { }108PSOldPromotionLAB(ObjectStartArray* start_array) : _start_array(start_array) { }109110void set_start_array(ObjectStartArray* start_array) { _start_array = start_array; }111112void flush();113114// Not MT safe115HeapWord* allocate(size_t size) {116// Cannot test for this now that we're doing promotion failures117// assert(_state != flushed, "Sanity");118assert(_start_array != NULL, "Sanity");119HeapWord* obj = top();120if (size <= pointer_delta(end(), obj)) {121HeapWord* new_top = obj + size;122set_top(new_top);123assert(is_object_aligned(obj) && is_object_aligned(new_top),124"checking alignment");125_start_array->allocate_block(obj);126return obj;127}128129return NULL;130}131132debug_only(virtual bool lab_is_valid(MemRegion lab));133};134135#endif // SHARE_GC_PARALLEL_PSPROMOTIONLAB_HPP136137138