1
|
1 |
/*
|
|
2 |
* Copyright 1997-2005 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 |
// ReservedSpace is a data structure for reserving a contiguous address range.
|
|
26 |
|
|
27 |
class ReservedSpace VALUE_OBJ_CLASS_SPEC {
|
|
28 |
friend class VMStructs;
|
|
29 |
private:
|
|
30 |
char* _base;
|
|
31 |
size_t _size;
|
|
32 |
size_t _alignment;
|
|
33 |
bool _special;
|
|
34 |
|
|
35 |
// ReservedSpace
|
|
36 |
ReservedSpace(char* base, size_t size, size_t alignment, bool special);
|
|
37 |
void initialize(size_t size, size_t alignment, bool large,
|
|
38 |
char* requested_address = NULL);
|
|
39 |
|
|
40 |
// Release parts of an already-reserved memory region [addr, addr + len) to
|
|
41 |
// get a new region that has "compound alignment." Return the start of the
|
|
42 |
// resulting region, or NULL on failure.
|
|
43 |
//
|
|
44 |
// The region is logically divided into a prefix and a suffix. The prefix
|
|
45 |
// starts at the result address, which is aligned to prefix_align. The suffix
|
|
46 |
// starts at result address + prefix_size, which is aligned to suffix_align.
|
|
47 |
// The total size of the result region is size prefix_size + suffix_size.
|
|
48 |
char* align_reserved_region(char* addr, const size_t len,
|
|
49 |
const size_t prefix_size,
|
|
50 |
const size_t prefix_align,
|
|
51 |
const size_t suffix_size,
|
|
52 |
const size_t suffix_align);
|
|
53 |
|
|
54 |
// Reserve memory, call align_reserved_region() to alignment it and return the
|
|
55 |
// result.
|
|
56 |
char* reserve_and_align(const size_t reserve_size,
|
|
57 |
const size_t prefix_size,
|
|
58 |
const size_t prefix_align,
|
|
59 |
const size_t suffix_size,
|
|
60 |
const size_t suffix_align);
|
|
61 |
|
|
62 |
public:
|
|
63 |
// Constructor
|
|
64 |
ReservedSpace(size_t size);
|
|
65 |
ReservedSpace(size_t size, size_t alignment, bool large,
|
|
66 |
char* requested_address = NULL);
|
|
67 |
ReservedSpace(const size_t prefix_size, const size_t prefix_align,
|
|
68 |
const size_t suffix_size, const size_t suffix_align);
|
|
69 |
|
|
70 |
// Accessors
|
|
71 |
char* base() const { return _base; }
|
|
72 |
size_t size() const { return _size; }
|
|
73 |
size_t alignment() const { return _alignment; }
|
|
74 |
bool special() const { return _special; }
|
|
75 |
|
|
76 |
bool is_reserved() const { return _base != NULL; }
|
|
77 |
void release();
|
|
78 |
|
|
79 |
// Splitting
|
|
80 |
ReservedSpace first_part(size_t partition_size, size_t alignment,
|
|
81 |
bool split = false, bool realloc = true);
|
|
82 |
ReservedSpace last_part (size_t partition_size, size_t alignment);
|
|
83 |
|
|
84 |
// These simply call the above using the default alignment.
|
|
85 |
inline ReservedSpace first_part(size_t partition_size,
|
|
86 |
bool split = false, bool realloc = true);
|
|
87 |
inline ReservedSpace last_part (size_t partition_size);
|
|
88 |
|
|
89 |
// Alignment
|
|
90 |
static size_t page_align_size_up(size_t size);
|
|
91 |
static size_t page_align_size_down(size_t size);
|
|
92 |
static size_t allocation_align_size_up(size_t size);
|
|
93 |
static size_t allocation_align_size_down(size_t size);
|
|
94 |
};
|
|
95 |
|
|
96 |
ReservedSpace
|
|
97 |
ReservedSpace::first_part(size_t partition_size, bool split, bool realloc)
|
|
98 |
{
|
|
99 |
return first_part(partition_size, alignment(), split, realloc);
|
|
100 |
}
|
|
101 |
|
|
102 |
ReservedSpace ReservedSpace::last_part(size_t partition_size)
|
|
103 |
{
|
|
104 |
return last_part(partition_size, alignment());
|
|
105 |
}
|
|
106 |
|
|
107 |
// VirtualSpace is data structure for committing a previously reserved address range in smaller chunks.
|
|
108 |
|
|
109 |
class VirtualSpace VALUE_OBJ_CLASS_SPEC {
|
|
110 |
friend class VMStructs;
|
|
111 |
private:
|
|
112 |
// Reserved area
|
|
113 |
char* _low_boundary;
|
|
114 |
char* _high_boundary;
|
|
115 |
|
|
116 |
// Committed area
|
|
117 |
char* _low;
|
|
118 |
char* _high;
|
|
119 |
|
|
120 |
// The entire space has been committed and pinned in memory, no
|
|
121 |
// os::commit_memory() or os::uncommit_memory().
|
|
122 |
bool _special;
|
|
123 |
|
|
124 |
// MPSS Support
|
|
125 |
// Each virtualspace region has a lower, middle, and upper region.
|
|
126 |
// Each region has an end boundary and a high pointer which is the
|
|
127 |
// high water mark for the last allocated byte.
|
|
128 |
// The lower and upper unaligned to LargePageSizeInBytes uses default page.
|
|
129 |
// size. The middle region uses large page size.
|
|
130 |
char* _lower_high;
|
|
131 |
char* _middle_high;
|
|
132 |
char* _upper_high;
|
|
133 |
|
|
134 |
char* _lower_high_boundary;
|
|
135 |
char* _middle_high_boundary;
|
|
136 |
char* _upper_high_boundary;
|
|
137 |
|
|
138 |
size_t _lower_alignment;
|
|
139 |
size_t _middle_alignment;
|
|
140 |
size_t _upper_alignment;
|
|
141 |
|
|
142 |
// MPSS Accessors
|
|
143 |
char* lower_high() const { return _lower_high; }
|
|
144 |
char* middle_high() const { return _middle_high; }
|
|
145 |
char* upper_high() const { return _upper_high; }
|
|
146 |
|
|
147 |
char* lower_high_boundary() const { return _lower_high_boundary; }
|
|
148 |
char* middle_high_boundary() const { return _middle_high_boundary; }
|
|
149 |
char* upper_high_boundary() const { return _upper_high_boundary; }
|
|
150 |
|
|
151 |
size_t lower_alignment() const { return _lower_alignment; }
|
|
152 |
size_t middle_alignment() const { return _middle_alignment; }
|
|
153 |
size_t upper_alignment() const { return _upper_alignment; }
|
|
154 |
|
|
155 |
public:
|
|
156 |
// Committed area
|
|
157 |
char* low() const { return _low; }
|
|
158 |
char* high() const { return _high; }
|
|
159 |
|
|
160 |
// Reserved area
|
|
161 |
char* low_boundary() const { return _low_boundary; }
|
|
162 |
char* high_boundary() const { return _high_boundary; }
|
|
163 |
|
|
164 |
bool special() const { return _special; }
|
|
165 |
|
|
166 |
public:
|
|
167 |
// Initialization
|
|
168 |
VirtualSpace();
|
|
169 |
bool initialize(ReservedSpace rs, size_t committed_byte_size);
|
|
170 |
|
|
171 |
// Destruction
|
|
172 |
~VirtualSpace();
|
|
173 |
|
|
174 |
// Testers (all sizes are byte sizes)
|
|
175 |
size_t committed_size() const;
|
|
176 |
size_t reserved_size() const;
|
|
177 |
size_t uncommitted_size() const;
|
|
178 |
bool contains(const void* p) const;
|
|
179 |
|
|
180 |
// Operations
|
|
181 |
// returns true on success, false otherwise
|
|
182 |
bool expand_by(size_t bytes, bool pre_touch = false);
|
|
183 |
void shrink_by(size_t bytes);
|
|
184 |
void release();
|
|
185 |
|
|
186 |
void check_for_contiguity() PRODUCT_RETURN;
|
|
187 |
|
|
188 |
// Debugging
|
|
189 |
void print() PRODUCT_RETURN;
|
|
190 |
};
|