annotate src/share/vm/gc_implementation/parallelScavenge/psVirtualspace.cpp @ 237:1fdb98a17101

6716785: implicit null checks not triggering with CompressedOops Summary: allocate alignment-sized page(s) below java heap so that memory accesses at heap_base+1page give signal and cause an implicit null check Reviewed-by: kvn, jmasa, phh, jcoomes
author coleenp
date Sat, 19 Jul 2008 17:38:22 -0400
parents a61af66fc99e
children 9ee9cf798b59
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 #include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 #include "incls/_psVirtualspace.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 // PSVirtualSpace
a61af66fc99e Initial load
duke
parents:
diff changeset
29
a61af66fc99e Initial load
duke
parents:
diff changeset
30 PSVirtualSpace::PSVirtualSpace(ReservedSpace rs, size_t alignment) :
a61af66fc99e Initial load
duke
parents:
diff changeset
31 _alignment(alignment)
a61af66fc99e Initial load
duke
parents:
diff changeset
32 {
a61af66fc99e Initial load
duke
parents:
diff changeset
33 set_reserved(rs);
a61af66fc99e Initial load
duke
parents:
diff changeset
34 set_committed(reserved_low_addr(), reserved_low_addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
35 DEBUG_ONLY(verify());
a61af66fc99e Initial load
duke
parents:
diff changeset
36 }
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 PSVirtualSpace::PSVirtualSpace(ReservedSpace rs) :
a61af66fc99e Initial load
duke
parents:
diff changeset
39 _alignment(os::vm_page_size())
a61af66fc99e Initial load
duke
parents:
diff changeset
40 {
a61af66fc99e Initial load
duke
parents:
diff changeset
41 set_reserved(rs);
a61af66fc99e Initial load
duke
parents:
diff changeset
42 set_committed(reserved_low_addr(), reserved_low_addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
43 DEBUG_ONLY(verify());
a61af66fc99e Initial load
duke
parents:
diff changeset
44 }
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // Deprecated.
a61af66fc99e Initial load
duke
parents:
diff changeset
47 PSVirtualSpace::PSVirtualSpace(): _alignment(os::vm_page_size()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
48 }
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 // Deprecated.
a61af66fc99e Initial load
duke
parents:
diff changeset
51 bool PSVirtualSpace::initialize(ReservedSpace rs,
a61af66fc99e Initial load
duke
parents:
diff changeset
52 size_t commit_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 set_reserved(rs);
a61af66fc99e Initial load
duke
parents:
diff changeset
54 set_committed(reserved_low_addr(), reserved_low_addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
55
a61af66fc99e Initial load
duke
parents:
diff changeset
56 // Commit to initial size.
a61af66fc99e Initial load
duke
parents:
diff changeset
57 assert(commit_size <= rs.size(), "commit_size too big");
a61af66fc99e Initial load
duke
parents:
diff changeset
58 bool result = commit_size > 0 ? expand_by(commit_size) : true;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 DEBUG_ONLY(verify());
a61af66fc99e Initial load
duke
parents:
diff changeset
60 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 }
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63 PSVirtualSpace::~PSVirtualSpace() {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 release();
a61af66fc99e Initial load
duke
parents:
diff changeset
65 }
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 bool PSVirtualSpace::contains(void* p) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 char* const cp = (char*)p;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 return cp >= committed_low_addr() && cp < committed_high_addr();
a61af66fc99e Initial load
duke
parents:
diff changeset
70 }
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 void PSVirtualSpace::release() {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
237
1fdb98a17101 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 0
diff changeset
74 // This may not release memory it didn't reserve.
1fdb98a17101 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 0
diff changeset
75 // Use rs.release() to release the underlying memory instead.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
76 _reserved_low_addr = _reserved_high_addr = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
77 _committed_low_addr = _committed_high_addr = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
78 _special = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
79 }
a61af66fc99e Initial load
duke
parents:
diff changeset
80
a61af66fc99e Initial load
duke
parents:
diff changeset
81 bool PSVirtualSpace::expand_by(size_t bytes, bool pre_touch) {
a61af66fc99e Initial load
duke
parents:
diff changeset
82 assert(is_aligned(bytes), "arg not aligned");
a61af66fc99e Initial load
duke
parents:
diff changeset
83 DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85 if (uncommitted_size() < bytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
87 }
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89 char* const base_addr = committed_high_addr();
a61af66fc99e Initial load
duke
parents:
diff changeset
90 bool result = special() || os::commit_memory(base_addr, bytes, alignment());
a61af66fc99e Initial load
duke
parents:
diff changeset
91 if (result) {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 _committed_high_addr += bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 if (pre_touch || AlwaysPreTouch) {
a61af66fc99e Initial load
duke
parents:
diff changeset
96 for (char* curr = base_addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 curr < _committed_high_addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
98 curr += os::vm_page_size()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
99 char tmp = *curr;
a61af66fc99e Initial load
duke
parents:
diff changeset
100 *curr = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
101 }
a61af66fc99e Initial load
duke
parents:
diff changeset
102 }
a61af66fc99e Initial load
duke
parents:
diff changeset
103
a61af66fc99e Initial load
duke
parents:
diff changeset
104 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
106
a61af66fc99e Initial load
duke
parents:
diff changeset
107 bool PSVirtualSpace::shrink_by(size_t bytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 assert(is_aligned(bytes), "arg not aligned");
a61af66fc99e Initial load
duke
parents:
diff changeset
109 DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 if (committed_size() < bytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 }
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 char* const base_addr = committed_high_addr() - bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 bool result = special() || os::uncommit_memory(base_addr, bytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
117 if (result) {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 _committed_high_addr -= bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 size_t
a61af66fc99e Initial load
duke
parents:
diff changeset
125 PSVirtualSpace::expand_into(PSVirtualSpace* other_space, size_t bytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
126 assert(is_aligned(bytes), "arg not aligned");
a61af66fc99e Initial load
duke
parents:
diff changeset
127 assert(grows_up(), "this space must grow up");
a61af66fc99e Initial load
duke
parents:
diff changeset
128 assert(other_space->grows_down(), "other space must grow down");
a61af66fc99e Initial load
duke
parents:
diff changeset
129 assert(reserved_high_addr() == other_space->reserved_low_addr(),
a61af66fc99e Initial load
duke
parents:
diff changeset
130 "spaces not contiguous");
a61af66fc99e Initial load
duke
parents:
diff changeset
131 assert(special() == other_space->special(), "one space is special, the other is not");
a61af66fc99e Initial load
duke
parents:
diff changeset
132 DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
a61af66fc99e Initial load
duke
parents:
diff changeset
133 DEBUG_ONLY(PSVirtualSpaceVerifier other_verifier(other_space));
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135 size_t bytes_needed = bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
136
a61af66fc99e Initial load
duke
parents:
diff changeset
137 // First use the uncommitted region in this space.
a61af66fc99e Initial load
duke
parents:
diff changeset
138 size_t tmp_bytes = MIN2(uncommitted_size(), bytes_needed);
a61af66fc99e Initial load
duke
parents:
diff changeset
139 if (tmp_bytes > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
140 if (expand_by(tmp_bytes)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 bytes_needed -= tmp_bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
142 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
143 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
144 }
a61af66fc99e Initial load
duke
parents:
diff changeset
145 }
a61af66fc99e Initial load
duke
parents:
diff changeset
146
a61af66fc99e Initial load
duke
parents:
diff changeset
147 // Next take from the uncommitted region in the other space, and commit it.
a61af66fc99e Initial load
duke
parents:
diff changeset
148 tmp_bytes = MIN2(other_space->uncommitted_size(), bytes_needed);
a61af66fc99e Initial load
duke
parents:
diff changeset
149 if (tmp_bytes > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
150 char* const commit_base = committed_high_addr();
a61af66fc99e Initial load
duke
parents:
diff changeset
151 if (other_space->special() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
152 os::commit_memory(commit_base, tmp_bytes, alignment())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
153 // Reduce the reserved region in the other space.
a61af66fc99e Initial load
duke
parents:
diff changeset
154 other_space->set_reserved(other_space->reserved_low_addr() + tmp_bytes,
a61af66fc99e Initial load
duke
parents:
diff changeset
155 other_space->reserved_high_addr(),
a61af66fc99e Initial load
duke
parents:
diff changeset
156 other_space->special());
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158 // Grow both reserved and committed in this space.
a61af66fc99e Initial load
duke
parents:
diff changeset
159 _reserved_high_addr += tmp_bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
160 _committed_high_addr += tmp_bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
161 bytes_needed -= tmp_bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
162 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
163 return bytes - bytes_needed;
a61af66fc99e Initial load
duke
parents:
diff changeset
164 }
a61af66fc99e Initial load
duke
parents:
diff changeset
165 }
a61af66fc99e Initial load
duke
parents:
diff changeset
166
a61af66fc99e Initial load
duke
parents:
diff changeset
167 // Finally take from the already committed region in the other space.
a61af66fc99e Initial load
duke
parents:
diff changeset
168 tmp_bytes = bytes_needed;
a61af66fc99e Initial load
duke
parents:
diff changeset
169 if (tmp_bytes > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
170 // Reduce both committed and reserved in the other space.
a61af66fc99e Initial load
duke
parents:
diff changeset
171 other_space->set_committed(other_space->committed_low_addr() + tmp_bytes,
a61af66fc99e Initial load
duke
parents:
diff changeset
172 other_space->committed_high_addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
173 other_space->set_reserved(other_space->reserved_low_addr() + tmp_bytes,
a61af66fc99e Initial load
duke
parents:
diff changeset
174 other_space->reserved_high_addr(),
a61af66fc99e Initial load
duke
parents:
diff changeset
175 other_space->special());
a61af66fc99e Initial load
duke
parents:
diff changeset
176
a61af66fc99e Initial load
duke
parents:
diff changeset
177 // Grow both reserved and committed in this space.
a61af66fc99e Initial load
duke
parents:
diff changeset
178 _reserved_high_addr += tmp_bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
179 _committed_high_addr += tmp_bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181
a61af66fc99e Initial load
duke
parents:
diff changeset
182 return bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
183 }
a61af66fc99e Initial load
duke
parents:
diff changeset
184
a61af66fc99e Initial load
duke
parents:
diff changeset
185 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
186 bool PSVirtualSpace::is_aligned(size_t value, size_t align) {
a61af66fc99e Initial load
duke
parents:
diff changeset
187 const size_t tmp_value = value + align - 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
188 const size_t mask = ~(align - 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
189 return (tmp_value & mask) == value;
a61af66fc99e Initial load
duke
parents:
diff changeset
190 }
a61af66fc99e Initial load
duke
parents:
diff changeset
191
a61af66fc99e Initial load
duke
parents:
diff changeset
192 bool PSVirtualSpace::is_aligned(size_t value) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
193 return is_aligned(value, alignment());
a61af66fc99e Initial load
duke
parents:
diff changeset
194 }
a61af66fc99e Initial load
duke
parents:
diff changeset
195
a61af66fc99e Initial load
duke
parents:
diff changeset
196 bool PSVirtualSpace::is_aligned(char* value) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
197 return is_aligned((size_t)value);
a61af66fc99e Initial load
duke
parents:
diff changeset
198 }
a61af66fc99e Initial load
duke
parents:
diff changeset
199
a61af66fc99e Initial load
duke
parents:
diff changeset
200 void PSVirtualSpace::verify() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
201 assert(is_aligned(alignment(), os::vm_page_size()), "bad alignment");
a61af66fc99e Initial load
duke
parents:
diff changeset
202 assert(is_aligned(reserved_low_addr()), "bad reserved_low_addr");
a61af66fc99e Initial load
duke
parents:
diff changeset
203 assert(is_aligned(reserved_high_addr()), "bad reserved_high_addr");
a61af66fc99e Initial load
duke
parents:
diff changeset
204 assert(is_aligned(committed_low_addr()), "bad committed_low_addr");
a61af66fc99e Initial load
duke
parents:
diff changeset
205 assert(is_aligned(committed_high_addr()), "bad committed_high_addr");
a61af66fc99e Initial load
duke
parents:
diff changeset
206
a61af66fc99e Initial load
duke
parents:
diff changeset
207 // Reserved region must be non-empty or both addrs must be 0.
a61af66fc99e Initial load
duke
parents:
diff changeset
208 assert(reserved_low_addr() < reserved_high_addr() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
209 reserved_low_addr() == NULL && reserved_high_addr() == NULL,
a61af66fc99e Initial load
duke
parents:
diff changeset
210 "bad reserved addrs");
a61af66fc99e Initial load
duke
parents:
diff changeset
211 assert(committed_low_addr() <= committed_high_addr(), "bad committed addrs");
a61af66fc99e Initial load
duke
parents:
diff changeset
212
a61af66fc99e Initial load
duke
parents:
diff changeset
213 if (grows_up()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
214 assert(reserved_low_addr() == committed_low_addr(), "bad low addrs");
a61af66fc99e Initial load
duke
parents:
diff changeset
215 assert(reserved_high_addr() >= committed_high_addr(), "bad high addrs");
a61af66fc99e Initial load
duke
parents:
diff changeset
216 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
217 assert(reserved_high_addr() == committed_high_addr(), "bad high addrs");
a61af66fc99e Initial load
duke
parents:
diff changeset
218 assert(reserved_low_addr() <= committed_low_addr(), "bad low addrs");
a61af66fc99e Initial load
duke
parents:
diff changeset
219 }
a61af66fc99e Initial load
duke
parents:
diff changeset
220 }
a61af66fc99e Initial load
duke
parents:
diff changeset
221
a61af66fc99e Initial load
duke
parents:
diff changeset
222 void PSVirtualSpace::print() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
223 gclog_or_tty->print_cr("virtual space [" PTR_FORMAT "]: alignment="
a61af66fc99e Initial load
duke
parents:
diff changeset
224 SIZE_FORMAT "K grows %s%s",
a61af66fc99e Initial load
duke
parents:
diff changeset
225 this, alignment() / K, grows_up() ? "up" : "down",
a61af66fc99e Initial load
duke
parents:
diff changeset
226 special() ? " (pinned in memory)" : "");
a61af66fc99e Initial load
duke
parents:
diff changeset
227 gclog_or_tty->print_cr(" reserved=" SIZE_FORMAT "K"
a61af66fc99e Initial load
duke
parents:
diff changeset
228 " [" PTR_FORMAT "," PTR_FORMAT "]"
a61af66fc99e Initial load
duke
parents:
diff changeset
229 " committed=" SIZE_FORMAT "K"
a61af66fc99e Initial load
duke
parents:
diff changeset
230 " [" PTR_FORMAT "," PTR_FORMAT "]",
a61af66fc99e Initial load
duke
parents:
diff changeset
231 reserved_size() / K,
a61af66fc99e Initial load
duke
parents:
diff changeset
232 reserved_low_addr(), reserved_high_addr(),
a61af66fc99e Initial load
duke
parents:
diff changeset
233 committed_size() / K,
a61af66fc99e Initial load
duke
parents:
diff changeset
234 committed_low_addr(), committed_high_addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
235 }
a61af66fc99e Initial load
duke
parents:
diff changeset
236 #endif // #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
237
a61af66fc99e Initial load
duke
parents:
diff changeset
238 void PSVirtualSpace::print_space_boundaries_on(outputStream* st) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
239 st->print_cr(" [" PTR_FORMAT ", " PTR_FORMAT ", " PTR_FORMAT ")",
a61af66fc99e Initial load
duke
parents:
diff changeset
240 low_boundary(), high(), high_boundary());
a61af66fc99e Initial load
duke
parents:
diff changeset
241 }
a61af66fc99e Initial load
duke
parents:
diff changeset
242
a61af66fc99e Initial load
duke
parents:
diff changeset
243 PSVirtualSpaceHighToLow::PSVirtualSpaceHighToLow(ReservedSpace rs,
a61af66fc99e Initial load
duke
parents:
diff changeset
244 size_t alignment) :
a61af66fc99e Initial load
duke
parents:
diff changeset
245 PSVirtualSpace(alignment)
a61af66fc99e Initial load
duke
parents:
diff changeset
246 {
a61af66fc99e Initial load
duke
parents:
diff changeset
247 set_reserved(rs);
a61af66fc99e Initial load
duke
parents:
diff changeset
248 set_committed(reserved_high_addr(), reserved_high_addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
249 DEBUG_ONLY(verify());
a61af66fc99e Initial load
duke
parents:
diff changeset
250 }
a61af66fc99e Initial load
duke
parents:
diff changeset
251
a61af66fc99e Initial load
duke
parents:
diff changeset
252 PSVirtualSpaceHighToLow::PSVirtualSpaceHighToLow(ReservedSpace rs) {
a61af66fc99e Initial load
duke
parents:
diff changeset
253 set_reserved(rs);
a61af66fc99e Initial load
duke
parents:
diff changeset
254 set_committed(reserved_high_addr(), reserved_high_addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
255 DEBUG_ONLY(verify());
a61af66fc99e Initial load
duke
parents:
diff changeset
256 }
a61af66fc99e Initial load
duke
parents:
diff changeset
257
a61af66fc99e Initial load
duke
parents:
diff changeset
258 bool PSVirtualSpaceHighToLow::expand_by(size_t bytes, bool pre_touch) {
a61af66fc99e Initial load
duke
parents:
diff changeset
259 assert(is_aligned(bytes), "arg not aligned");
a61af66fc99e Initial load
duke
parents:
diff changeset
260 DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
a61af66fc99e Initial load
duke
parents:
diff changeset
261
a61af66fc99e Initial load
duke
parents:
diff changeset
262 if (uncommitted_size() < bytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
263 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
264 }
a61af66fc99e Initial load
duke
parents:
diff changeset
265
a61af66fc99e Initial load
duke
parents:
diff changeset
266 char* const base_addr = committed_low_addr() - bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
267 bool result = special() || os::commit_memory(base_addr, bytes, alignment());
a61af66fc99e Initial load
duke
parents:
diff changeset
268 if (result) {
a61af66fc99e Initial load
duke
parents:
diff changeset
269 _committed_low_addr -= bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
270 }
a61af66fc99e Initial load
duke
parents:
diff changeset
271
a61af66fc99e Initial load
duke
parents:
diff changeset
272 if (pre_touch || AlwaysPreTouch) {
a61af66fc99e Initial load
duke
parents:
diff changeset
273 for (char* curr = base_addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
274 curr < _committed_high_addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
275 curr += os::vm_page_size()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
276 char tmp = *curr;
a61af66fc99e Initial load
duke
parents:
diff changeset
277 *curr = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
278 }
a61af66fc99e Initial load
duke
parents:
diff changeset
279 }
a61af66fc99e Initial load
duke
parents:
diff changeset
280
a61af66fc99e Initial load
duke
parents:
diff changeset
281 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
282 }
a61af66fc99e Initial load
duke
parents:
diff changeset
283
a61af66fc99e Initial load
duke
parents:
diff changeset
284 bool PSVirtualSpaceHighToLow::shrink_by(size_t bytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
285 assert(is_aligned(bytes), "arg not aligned");
a61af66fc99e Initial load
duke
parents:
diff changeset
286 DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
a61af66fc99e Initial load
duke
parents:
diff changeset
287
a61af66fc99e Initial load
duke
parents:
diff changeset
288 if (committed_size() < bytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
289 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
290 }
a61af66fc99e Initial load
duke
parents:
diff changeset
291
a61af66fc99e Initial load
duke
parents:
diff changeset
292 char* const base_addr = committed_low_addr();
a61af66fc99e Initial load
duke
parents:
diff changeset
293 bool result = special() || os::uncommit_memory(base_addr, bytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
294 if (result) {
a61af66fc99e Initial load
duke
parents:
diff changeset
295 _committed_low_addr += bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
296 }
a61af66fc99e Initial load
duke
parents:
diff changeset
297
a61af66fc99e Initial load
duke
parents:
diff changeset
298 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
299 }
a61af66fc99e Initial load
duke
parents:
diff changeset
300
a61af66fc99e Initial load
duke
parents:
diff changeset
301 size_t PSVirtualSpaceHighToLow::expand_into(PSVirtualSpace* other_space,
a61af66fc99e Initial load
duke
parents:
diff changeset
302 size_t bytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
303 assert(is_aligned(bytes), "arg not aligned");
a61af66fc99e Initial load
duke
parents:
diff changeset
304 assert(grows_down(), "this space must grow down");
a61af66fc99e Initial load
duke
parents:
diff changeset
305 assert(other_space->grows_up(), "other space must grow up");
a61af66fc99e Initial load
duke
parents:
diff changeset
306 assert(reserved_low_addr() == other_space->reserved_high_addr(),
a61af66fc99e Initial load
duke
parents:
diff changeset
307 "spaces not contiguous");
a61af66fc99e Initial load
duke
parents:
diff changeset
308 assert(special() == other_space->special(), "one space is special in memory, the other is not");
a61af66fc99e Initial load
duke
parents:
diff changeset
309 DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
a61af66fc99e Initial load
duke
parents:
diff changeset
310 DEBUG_ONLY(PSVirtualSpaceVerifier other_verifier(other_space));
a61af66fc99e Initial load
duke
parents:
diff changeset
311
a61af66fc99e Initial load
duke
parents:
diff changeset
312 size_t bytes_needed = bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
313
a61af66fc99e Initial load
duke
parents:
diff changeset
314 // First use the uncommitted region in this space.
a61af66fc99e Initial load
duke
parents:
diff changeset
315 size_t tmp_bytes = MIN2(uncommitted_size(), bytes_needed);
a61af66fc99e Initial load
duke
parents:
diff changeset
316 if (tmp_bytes > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
317 if (expand_by(tmp_bytes)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
318 bytes_needed -= tmp_bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
319 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
320 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
321 }
a61af66fc99e Initial load
duke
parents:
diff changeset
322 }
a61af66fc99e Initial load
duke
parents:
diff changeset
323
a61af66fc99e Initial load
duke
parents:
diff changeset
324 // Next take from the uncommitted region in the other space, and commit it.
a61af66fc99e Initial load
duke
parents:
diff changeset
325 tmp_bytes = MIN2(other_space->uncommitted_size(), bytes_needed);
a61af66fc99e Initial load
duke
parents:
diff changeset
326 if (tmp_bytes > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
327 char* const commit_base = committed_low_addr() - tmp_bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
328 if (other_space->special() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
329 os::commit_memory(commit_base, tmp_bytes, alignment())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
330 // Reduce the reserved region in the other space.
a61af66fc99e Initial load
duke
parents:
diff changeset
331 other_space->set_reserved(other_space->reserved_low_addr(),
a61af66fc99e Initial load
duke
parents:
diff changeset
332 other_space->reserved_high_addr() - tmp_bytes,
a61af66fc99e Initial load
duke
parents:
diff changeset
333 other_space->special());
a61af66fc99e Initial load
duke
parents:
diff changeset
334
a61af66fc99e Initial load
duke
parents:
diff changeset
335 // Grow both reserved and committed in this space.
a61af66fc99e Initial load
duke
parents:
diff changeset
336 _reserved_low_addr -= tmp_bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
337 _committed_low_addr -= tmp_bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
338 bytes_needed -= tmp_bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
339 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
340 return bytes - bytes_needed;
a61af66fc99e Initial load
duke
parents:
diff changeset
341 }
a61af66fc99e Initial load
duke
parents:
diff changeset
342 }
a61af66fc99e Initial load
duke
parents:
diff changeset
343
a61af66fc99e Initial load
duke
parents:
diff changeset
344 // Finally take from the already committed region in the other space.
a61af66fc99e Initial load
duke
parents:
diff changeset
345 tmp_bytes = bytes_needed;
a61af66fc99e Initial load
duke
parents:
diff changeset
346 if (tmp_bytes > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
347 // Reduce both committed and reserved in the other space.
a61af66fc99e Initial load
duke
parents:
diff changeset
348 other_space->set_committed(other_space->committed_low_addr(),
a61af66fc99e Initial load
duke
parents:
diff changeset
349 other_space->committed_high_addr() - tmp_bytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
350 other_space->set_reserved(other_space->reserved_low_addr(),
a61af66fc99e Initial load
duke
parents:
diff changeset
351 other_space->reserved_high_addr() - tmp_bytes,
a61af66fc99e Initial load
duke
parents:
diff changeset
352 other_space->special());
a61af66fc99e Initial load
duke
parents:
diff changeset
353
a61af66fc99e Initial load
duke
parents:
diff changeset
354 // Grow both reserved and committed in this space.
a61af66fc99e Initial load
duke
parents:
diff changeset
355 _reserved_low_addr -= tmp_bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
356 _committed_low_addr -= tmp_bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
357 }
a61af66fc99e Initial load
duke
parents:
diff changeset
358
a61af66fc99e Initial load
duke
parents:
diff changeset
359 return bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
360 }
a61af66fc99e Initial load
duke
parents:
diff changeset
361
a61af66fc99e Initial load
duke
parents:
diff changeset
362 void
a61af66fc99e Initial load
duke
parents:
diff changeset
363 PSVirtualSpaceHighToLow::print_space_boundaries_on(outputStream* st) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
364 st->print_cr(" (" PTR_FORMAT ", " PTR_FORMAT ", " PTR_FORMAT "]",
a61af66fc99e Initial load
duke
parents:
diff changeset
365 high_boundary(), low(), low_boundary());
a61af66fc99e Initial load
duke
parents:
diff changeset
366 }