duke@435: /* duke@435: * Copyright 2002 Sun Microsystems, Inc. All Rights Reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: // duke@435: // PSPromotionLAB is a parallel scavenge promotion lab. This class acts very duke@435: // much like a MutableSpace. We couldn't embed a MutableSpace, though, as duke@435: // it has a considerable number of asserts and invariants that are violated. duke@435: // duke@435: duke@435: class ObjectStartArray; duke@435: duke@435: class PSPromotionLAB : public CHeapObj { duke@435: protected: coleenp@548: static size_t filler_header_size; duke@435: duke@435: enum LabState { duke@435: needs_flush, duke@435: flushed, duke@435: zero_size duke@435: }; duke@435: duke@435: HeapWord* _top; duke@435: HeapWord* _bottom; duke@435: HeapWord* _end; duke@435: LabState _state; duke@435: duke@435: void set_top(HeapWord* value) { _top = value; } duke@435: void set_bottom(HeapWord* value) { _bottom = value; } duke@435: void set_end(HeapWord* value) { _end = value; } duke@435: duke@435: // The shared initialize code invokes this. duke@435: debug_only(virtual bool lab_is_valid(MemRegion lab) { return false; }); duke@435: duke@435: PSPromotionLAB() : _top(NULL), _bottom(NULL), _end(NULL) { } duke@435: duke@435: public: duke@435: // Filling and flushing. duke@435: void initialize(MemRegion lab); duke@435: duke@435: virtual void flush(); duke@435: duke@435: // Accessors duke@435: HeapWord* bottom() const { return _bottom; } duke@435: HeapWord* end() const { return _end; } duke@435: HeapWord* top() const { return _top; } duke@435: duke@435: bool is_flushed() { return _state == flushed; } duke@435: duke@435: bool unallocate_object(oop obj); duke@435: duke@435: // Returns a subregion containing all objects in this space. duke@435: MemRegion used_region() { return MemRegion(bottom(), top()); } duke@435: duke@435: // Boolean querries. duke@435: bool is_empty() const { return used() == 0; } duke@435: bool not_empty() const { return used() > 0; } duke@435: bool contains(const void* p) const { return _bottom <= p && p < _end; } duke@435: duke@435: // Size computations. Sizes are in bytes. duke@435: size_t capacity() const { return byte_size(bottom(), end()); } duke@435: size_t used() const { return byte_size(bottom(), top()); } duke@435: size_t free() const { return byte_size(top(), end()); } duke@435: }; duke@435: duke@435: class PSYoungPromotionLAB : public PSPromotionLAB { duke@435: public: duke@435: PSYoungPromotionLAB() { } duke@435: duke@435: // Not MT safe duke@435: HeapWord* allocate(size_t size) { duke@435: // Can't assert this, when young fills, we keep the LAB around, but flushed. duke@435: // assert(_state != flushed, "Sanity"); duke@435: HeapWord* obj = top(); duke@435: HeapWord* new_top = obj + size; duke@435: // The 'new_top>obj' check is needed to detect overflow of obj+size. duke@435: if (new_top > obj && new_top <= end()) { duke@435: set_top(new_top); duke@435: assert(is_object_aligned((intptr_t)obj) && is_object_aligned((intptr_t)new_top), duke@435: "checking alignment"); duke@435: return obj; duke@435: } duke@435: duke@435: return NULL; duke@435: } duke@435: duke@435: debug_only(virtual bool lab_is_valid(MemRegion lab)); duke@435: }; duke@435: duke@435: class PSOldPromotionLAB : public PSPromotionLAB { duke@435: private: duke@435: ObjectStartArray* _start_array; duke@435: duke@435: public: duke@435: PSOldPromotionLAB() : _start_array(NULL) { } duke@435: PSOldPromotionLAB(ObjectStartArray* start_array) : _start_array(start_array) { } duke@435: duke@435: void set_start_array(ObjectStartArray* start_array) { _start_array = start_array; } duke@435: duke@435: void flush(); duke@435: duke@435: // Not MT safe duke@435: HeapWord* allocate(size_t size) { duke@435: // Cannot test for this now that we're doing promotion failures duke@435: // assert(_state != flushed, "Sanity"); duke@435: assert(_start_array != NULL, "Sanity"); duke@435: HeapWord* obj = top(); duke@435: HeapWord* new_top = obj + size; duke@435: // The 'new_top>obj' check is needed to detect overflow of obj+size. duke@435: if (new_top > obj && new_top <= end()) { duke@435: set_top(new_top); duke@435: assert(is_object_aligned((intptr_t)obj) && is_object_aligned((intptr_t)new_top), duke@435: "checking alignment"); duke@435: _start_array->allocate_block(obj); duke@435: return obj; duke@435: } duke@435: duke@435: return NULL; duke@435: } duke@435: duke@435: debug_only(virtual bool lab_is_valid(MemRegion lab)); duke@435: };