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