Wed, 02 Jul 2008 12:55:16 -0700
6719955: Update copyright year
Summary: Update copyright year for files that have been modified in 2008
Reviewed-by: ohair, tbell
1 /*
2 * Copyright 2002-2008 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 */
25 //
26 // PSPromotionLAB is a parallel scavenge promotion lab. This class acts very
27 // much like a MutableSpace. We couldn't embed a MutableSpace, though, as
28 // it has a considerable number of asserts and invariants that are violated.
29 //
31 class ObjectStartArray;
33 class PSPromotionLAB : public CHeapObj {
34 protected:
35 static size_t filler_header_size;
37 enum LabState {
38 needs_flush,
39 flushed,
40 zero_size
41 };
43 HeapWord* _top;
44 HeapWord* _bottom;
45 HeapWord* _end;
46 LabState _state;
48 void set_top(HeapWord* value) { _top = value; }
49 void set_bottom(HeapWord* value) { _bottom = value; }
50 void set_end(HeapWord* value) { _end = value; }
52 // The shared initialize code invokes this.
53 debug_only(virtual bool lab_is_valid(MemRegion lab) { return false; });
55 PSPromotionLAB() : _top(NULL), _bottom(NULL), _end(NULL) { }
57 public:
58 // Filling and flushing.
59 void initialize(MemRegion lab);
61 virtual void flush();
63 // Accessors
64 HeapWord* bottom() const { return _bottom; }
65 HeapWord* end() const { return _end; }
66 HeapWord* top() const { return _top; }
68 bool is_flushed() { return _state == flushed; }
70 bool unallocate_object(oop obj);
72 // Returns a subregion containing all objects in this space.
73 MemRegion used_region() { return MemRegion(bottom(), top()); }
75 // Boolean querries.
76 bool is_empty() const { return used() == 0; }
77 bool not_empty() const { return used() > 0; }
78 bool contains(const void* p) const { return _bottom <= p && p < _end; }
80 // Size computations. Sizes are in bytes.
81 size_t capacity() const { return byte_size(bottom(), end()); }
82 size_t used() const { return byte_size(bottom(), top()); }
83 size_t free() const { return byte_size(top(), end()); }
84 };
86 class PSYoungPromotionLAB : public PSPromotionLAB {
87 public:
88 PSYoungPromotionLAB() { }
90 // Not MT safe
91 HeapWord* allocate(size_t size) {
92 // Can't assert this, when young fills, we keep the LAB around, but flushed.
93 // assert(_state != flushed, "Sanity");
94 HeapWord* obj = top();
95 HeapWord* new_top = obj + size;
96 // The 'new_top>obj' check is needed to detect overflow of obj+size.
97 if (new_top > obj && new_top <= end()) {
98 set_top(new_top);
99 assert(is_object_aligned((intptr_t)obj) && is_object_aligned((intptr_t)new_top),
100 "checking alignment");
101 return obj;
102 }
104 return NULL;
105 }
107 debug_only(virtual bool lab_is_valid(MemRegion lab));
108 };
110 class PSOldPromotionLAB : public PSPromotionLAB {
111 private:
112 ObjectStartArray* _start_array;
114 public:
115 PSOldPromotionLAB() : _start_array(NULL) { }
116 PSOldPromotionLAB(ObjectStartArray* start_array) : _start_array(start_array) { }
118 void set_start_array(ObjectStartArray* start_array) { _start_array = start_array; }
120 void flush();
122 // Not MT safe
123 HeapWord* allocate(size_t size) {
124 // Cannot test for this now that we're doing promotion failures
125 // assert(_state != flushed, "Sanity");
126 assert(_start_array != NULL, "Sanity");
127 HeapWord* obj = top();
128 HeapWord* new_top = obj + size;
129 // The 'new_top>obj' check is needed to detect overflow of obj+size.
130 if (new_top > obj && new_top <= end()) {
131 set_top(new_top);
132 assert(is_object_aligned((intptr_t)obj) && is_object_aligned((intptr_t)new_top),
133 "checking alignment");
134 _start_array->allocate_block(obj);
135 return obj;
136 }
138 return NULL;
139 }
141 debug_only(virtual bool lab_is_valid(MemRegion lab));
142 };