1 #ifdef USE_PRAGMA_IDENT_HDR 2 #pragma ident "@(#)mutableSpace.hpp 1.22 07/05/05 17:05:35 JVM" 3 #endif 4 /* 5 * Copyright 2001-2007 Sun Microsystems, Inc. All Rights Reserved. 6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7 * 8 * This code is free software; you can redistribute it and/or modify it 9 * under the terms of the GNU General Public License version 2 only, as 10 * published by the Free Software Foundation. 11 * 12 * This code is distributed in the hope that it will be useful, but WITHOUT 13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 * version 2 for more details (a copy is included in the LICENSE file that 16 * accompanied this code). 17 * 18 * You should have received a copy of the GNU General Public License version 19 * 2 along with this work; if not, write to the Free Software Foundation, 20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 21 * 22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 23 * CA 95054 USA or visit www.sun.com if you need additional information or 24 * have any questions. 25 * 26 */ 27 28 // A MutableSpace is a subtype of ImmutableSpace that supports the 29 // concept of allocation. This includes the concepts that a space may 30 // be only partially full, and the querry methods that go with such 31 // an assumption. 32 // 33 // Invariant: (ImmutableSpace +) bottom() <= top() <= end() 34 // top() is inclusive and end() is exclusive. 35 36 class MutableSpace: public ImmutableSpace { 37 friend class VMStructs; 38 protected: 39 HeapWord* _top; 40 41 public: 42 virtual ~MutableSpace() {} 43 MutableSpace() { _top = NULL; } 44 // Accessors 45 HeapWord* top() const { return _top; } 46 virtual void set_top(HeapWord* value) { _top = value; } 47 48 HeapWord** top_addr() { return &_top; } 49 HeapWord** end_addr() { return &_end; } 50 51 virtual void set_bottom(HeapWord* value) { _bottom = value; } 52 virtual void set_end(HeapWord* value) { _end = value; } 53 54 // Returns a subregion containing all objects in this space. 55 MemRegion used_region() { return MemRegion(bottom(), top()); } 56 57 // Initialization 58 virtual void initialize(MemRegion mr, bool clear_space); 59 virtual void clear(); 60 virtual void update() { } 61 virtual void accumulate_statistics() { } 62 63 // Overwrites the unused portion of this space. Note that some collectors 64 // may use this "scratch" space during collections. 65 virtual void mangle_unused_area() { 66 mangle_region(MemRegion(_top, _end)); 67 } 68 virtual void ensure_parsability() { } 69 70 void mangle_region(MemRegion mr) { 71 debug_only(Copy::fill_to_words(mr.start(), mr.word_size(), badHeapWord)); 72 } 73 74 // Boolean querries. 75 bool is_empty() const { return used_in_words() == 0; } 76 bool not_empty() const { return used_in_words() > 0; } 77 bool contains(const void* p) const { return _bottom <= p && p < _end; } 78 79 // Size computations. Sizes are in bytes. 80 size_t used_in_bytes() const { return used_in_words() * HeapWordSize; } 81 size_t free_in_bytes() const { return free_in_words() * HeapWordSize; } 82 83 // Size computations. Sizes are in heapwords. 84 virtual size_t used_in_words() const { return pointer_delta(top(), bottom()); } 85 virtual size_t free_in_words() const { return pointer_delta(end(), top()); } 86 virtual size_t tlab_capacity(Thread* thr) const { return capacity_in_bytes(); } 87 virtual size_t unsafe_max_tlab_alloc(Thread* thr) const { return free_in_bytes(); } 88 89 // Allocation (return NULL if full) 90 virtual HeapWord* allocate(size_t word_size); 91 virtual HeapWord* cas_allocate(size_t word_size); 92 // Optional deallocation. Used in NUMA-allocator. 93 bool cas_deallocate(HeapWord *obj, size_t size); 94 95 // Iteration. 96 void oop_iterate(OopClosure* cl); 97 void object_iterate(ObjectClosure* cl); 98 99 // Debugging 100 virtual void print() const; 101 virtual void print_on(outputStream* st) const; 102 virtual void print_short() const; 103 virtual void print_short_on(outputStream* st) const; 104 virtual void verify(bool allow_dirty) const; 105 };