annotate src/share/vm/gc_implementation/parallelScavenge/psVirtualspace.cpp @ 18041:52b4284cb496

Merge with jdk8u20-b26
author Gilles Duboscq <duboscq@ssw.jku.at>
date Wed, 15 Oct 2014 16:02:50 +0200
parents 4ca6dc0799b6 78bbf4d43a14
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
17937
78bbf4d43a14 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 14411
diff changeset
2 * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
0
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 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 579
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 579
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 579
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #include "gc_implementation/parallelScavenge/psVirtualspace.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27 #include "runtime/os.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "runtime/virtualspace.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #ifdef TARGET_OS_FAMILY_linux
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30 # include "os_linux.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
31 #endif
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
32 #ifdef TARGET_OS_FAMILY_solaris
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
33 # include "os_solaris.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
34 #endif
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
35 #ifdef TARGET_OS_FAMILY_windows
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
36 # include "os_windows.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
37 #endif
14411
bdd155477289 8023033: PPC64 (part 13): basic changes for AIX
goetz
parents: 10969
diff changeset
38 #ifdef TARGET_OS_FAMILY_aix
bdd155477289 8023033: PPC64 (part 13): basic changes for AIX
goetz
parents: 10969
diff changeset
39 # include "os_aix.inline.hpp"
bdd155477289 8023033: PPC64 (part 13): basic changes for AIX
goetz
parents: 10969
diff changeset
40 #endif
3960
f08d439fab8c 7089790: integrate bsd-port changes
never
parents: 1972
diff changeset
41 #ifdef TARGET_OS_FAMILY_bsd
f08d439fab8c 7089790: integrate bsd-port changes
never
parents: 1972
diff changeset
42 # include "os_bsd.inline.hpp"
f08d439fab8c 7089790: integrate bsd-port changes
never
parents: 1972
diff changeset
43 #endif
0
a61af66fc99e Initial load
duke
parents:
diff changeset
44
17937
78bbf4d43a14 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 14411
diff changeset
45 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
78bbf4d43a14 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 14411
diff changeset
46
0
a61af66fc99e Initial load
duke
parents:
diff changeset
47 // PSVirtualSpace
a61af66fc99e Initial load
duke
parents:
diff changeset
48
a61af66fc99e Initial load
duke
parents:
diff changeset
49 PSVirtualSpace::PSVirtualSpace(ReservedSpace rs, size_t alignment) :
a61af66fc99e Initial load
duke
parents:
diff changeset
50 _alignment(alignment)
a61af66fc99e Initial load
duke
parents:
diff changeset
51 {
a61af66fc99e Initial load
duke
parents:
diff changeset
52 set_reserved(rs);
a61af66fc99e Initial load
duke
parents:
diff changeset
53 set_committed(reserved_low_addr(), reserved_low_addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
54 DEBUG_ONLY(verify());
a61af66fc99e Initial load
duke
parents:
diff changeset
55 }
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 PSVirtualSpace::PSVirtualSpace(ReservedSpace rs) :
a61af66fc99e Initial load
duke
parents:
diff changeset
58 _alignment(os::vm_page_size())
a61af66fc99e Initial load
duke
parents:
diff changeset
59 {
a61af66fc99e Initial load
duke
parents:
diff changeset
60 set_reserved(rs);
a61af66fc99e Initial load
duke
parents:
diff changeset
61 set_committed(reserved_low_addr(), reserved_low_addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
62 DEBUG_ONLY(verify());
a61af66fc99e Initial load
duke
parents:
diff changeset
63 }
a61af66fc99e Initial load
duke
parents:
diff changeset
64
a61af66fc99e Initial load
duke
parents:
diff changeset
65 // Deprecated.
a61af66fc99e Initial load
duke
parents:
diff changeset
66 PSVirtualSpace::PSVirtualSpace(): _alignment(os::vm_page_size()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
67 }
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 // Deprecated.
a61af66fc99e Initial load
duke
parents:
diff changeset
70 bool PSVirtualSpace::initialize(ReservedSpace rs,
a61af66fc99e Initial load
duke
parents:
diff changeset
71 size_t commit_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
72 set_reserved(rs);
a61af66fc99e Initial load
duke
parents:
diff changeset
73 set_committed(reserved_low_addr(), reserved_low_addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 // Commit to initial size.
a61af66fc99e Initial load
duke
parents:
diff changeset
76 assert(commit_size <= rs.size(), "commit_size too big");
a61af66fc99e Initial load
duke
parents:
diff changeset
77 bool result = commit_size > 0 ? expand_by(commit_size) : true;
a61af66fc99e Initial load
duke
parents:
diff changeset
78 DEBUG_ONLY(verify());
a61af66fc99e Initial load
duke
parents:
diff changeset
79 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
80 }
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82 PSVirtualSpace::~PSVirtualSpace() {
a61af66fc99e Initial load
duke
parents:
diff changeset
83 release();
a61af66fc99e Initial load
duke
parents:
diff changeset
84 }
a61af66fc99e Initial load
duke
parents:
diff changeset
85
a61af66fc99e Initial load
duke
parents:
diff changeset
86 bool PSVirtualSpace::contains(void* p) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
87 char* const cp = (char*)p;
a61af66fc99e Initial load
duke
parents:
diff changeset
88 return cp >= committed_low_addr() && cp < committed_high_addr();
a61af66fc99e Initial load
duke
parents:
diff changeset
89 }
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 void PSVirtualSpace::release() {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
237
1fdb98a17101 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 0
diff changeset
93 // This may not release memory it didn't reserve.
1fdb98a17101 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 0
diff changeset
94 // Use rs.release() to release the underlying memory instead.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
95 _reserved_low_addr = _reserved_high_addr = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
96 _committed_low_addr = _committed_high_addr = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 _special = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
98 }
a61af66fc99e Initial load
duke
parents:
diff changeset
99
535
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 337
diff changeset
100 bool PSVirtualSpace::expand_by(size_t bytes) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
101 assert(is_aligned(bytes), "arg not aligned");
a61af66fc99e Initial load
duke
parents:
diff changeset
102 DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
a61af66fc99e Initial load
duke
parents:
diff changeset
103
a61af66fc99e Initial load
duke
parents:
diff changeset
104 if (uncommitted_size() < bytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
105 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
106 }
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108 char* const base_addr = committed_high_addr();
10969
a837fa3d3f86 8013057: assert(_needs_gc || SafepointSynchronize::is_at_safepoint()) failed: only read at safepoint
dcubed
parents: 3960
diff changeset
109 bool result = special() ||
a837fa3d3f86 8013057: assert(_needs_gc || SafepointSynchronize::is_at_safepoint()) failed: only read at safepoint
dcubed
parents: 3960
diff changeset
110 os::commit_memory(base_addr, bytes, alignment(), !ExecMem);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
111 if (result) {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 _committed_high_addr += bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 }
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 }
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 bool PSVirtualSpace::shrink_by(size_t bytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
119 assert(is_aligned(bytes), "arg not aligned");
a61af66fc99e Initial load
duke
parents:
diff changeset
120 DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 if (committed_size() < bytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
123 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 char* const base_addr = committed_high_addr() - bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
127 bool result = special() || os::uncommit_memory(base_addr, bytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
128 if (result) {
a61af66fc99e Initial load
duke
parents:
diff changeset
129 _committed_high_addr -= bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
131
a61af66fc99e Initial load
duke
parents:
diff changeset
132 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
133 }
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135 size_t
a61af66fc99e Initial load
duke
parents:
diff changeset
136 PSVirtualSpace::expand_into(PSVirtualSpace* other_space, size_t bytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
137 assert(is_aligned(bytes), "arg not aligned");
a61af66fc99e Initial load
duke
parents:
diff changeset
138 assert(grows_up(), "this space must grow up");
a61af66fc99e Initial load
duke
parents:
diff changeset
139 assert(other_space->grows_down(), "other space must grow down");
a61af66fc99e Initial load
duke
parents:
diff changeset
140 assert(reserved_high_addr() == other_space->reserved_low_addr(),
a61af66fc99e Initial load
duke
parents:
diff changeset
141 "spaces not contiguous");
a61af66fc99e Initial load
duke
parents:
diff changeset
142 assert(special() == other_space->special(), "one space is special, the other is not");
a61af66fc99e Initial load
duke
parents:
diff changeset
143 DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
a61af66fc99e Initial load
duke
parents:
diff changeset
144 DEBUG_ONLY(PSVirtualSpaceVerifier other_verifier(other_space));
a61af66fc99e Initial load
duke
parents:
diff changeset
145
a61af66fc99e Initial load
duke
parents:
diff changeset
146 size_t bytes_needed = bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
147
a61af66fc99e Initial load
duke
parents:
diff changeset
148 // First use the uncommitted region in this space.
a61af66fc99e Initial load
duke
parents:
diff changeset
149 size_t tmp_bytes = MIN2(uncommitted_size(), bytes_needed);
a61af66fc99e Initial load
duke
parents:
diff changeset
150 if (tmp_bytes > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
151 if (expand_by(tmp_bytes)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 bytes_needed -= tmp_bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
153 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
154 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
155 }
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158 // Next take from the uncommitted region in the other space, and commit it.
a61af66fc99e Initial load
duke
parents:
diff changeset
159 tmp_bytes = MIN2(other_space->uncommitted_size(), bytes_needed);
a61af66fc99e Initial load
duke
parents:
diff changeset
160 if (tmp_bytes > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
161 char* const commit_base = committed_high_addr();
a61af66fc99e Initial load
duke
parents:
diff changeset
162 if (other_space->special() ||
10969
a837fa3d3f86 8013057: assert(_needs_gc || SafepointSynchronize::is_at_safepoint()) failed: only read at safepoint
dcubed
parents: 3960
diff changeset
163 os::commit_memory(commit_base, tmp_bytes, alignment(), !ExecMem)) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
164 // Reduce the reserved region in the other space.
a61af66fc99e Initial load
duke
parents:
diff changeset
165 other_space->set_reserved(other_space->reserved_low_addr() + tmp_bytes,
a61af66fc99e Initial load
duke
parents:
diff changeset
166 other_space->reserved_high_addr(),
a61af66fc99e Initial load
duke
parents:
diff changeset
167 other_space->special());
a61af66fc99e Initial load
duke
parents:
diff changeset
168
a61af66fc99e Initial load
duke
parents:
diff changeset
169 // Grow both reserved and committed in this space.
a61af66fc99e Initial load
duke
parents:
diff changeset
170 _reserved_high_addr += tmp_bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
171 _committed_high_addr += tmp_bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
172 bytes_needed -= tmp_bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
173 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
174 return bytes - bytes_needed;
a61af66fc99e Initial load
duke
parents:
diff changeset
175 }
a61af66fc99e Initial load
duke
parents:
diff changeset
176 }
a61af66fc99e Initial load
duke
parents:
diff changeset
177
a61af66fc99e Initial load
duke
parents:
diff changeset
178 // Finally take from the already committed region in the other space.
a61af66fc99e Initial load
duke
parents:
diff changeset
179 tmp_bytes = bytes_needed;
a61af66fc99e Initial load
duke
parents:
diff changeset
180 if (tmp_bytes > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
181 // Reduce both committed and reserved in the other space.
a61af66fc99e Initial load
duke
parents:
diff changeset
182 other_space->set_committed(other_space->committed_low_addr() + tmp_bytes,
a61af66fc99e Initial load
duke
parents:
diff changeset
183 other_space->committed_high_addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
184 other_space->set_reserved(other_space->reserved_low_addr() + tmp_bytes,
a61af66fc99e Initial load
duke
parents:
diff changeset
185 other_space->reserved_high_addr(),
a61af66fc99e Initial load
duke
parents:
diff changeset
186 other_space->special());
a61af66fc99e Initial load
duke
parents:
diff changeset
187
a61af66fc99e Initial load
duke
parents:
diff changeset
188 // Grow both reserved and committed in this space.
a61af66fc99e Initial load
duke
parents:
diff changeset
189 _reserved_high_addr += tmp_bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
190 _committed_high_addr += tmp_bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
191 }
a61af66fc99e Initial load
duke
parents:
diff changeset
192
a61af66fc99e Initial load
duke
parents:
diff changeset
193 return bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
194 }
a61af66fc99e Initial load
duke
parents:
diff changeset
195
a61af66fc99e Initial load
duke
parents:
diff changeset
196 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
197 bool PSVirtualSpace::is_aligned(size_t value, size_t align) {
a61af66fc99e Initial load
duke
parents:
diff changeset
198 const size_t tmp_value = value + align - 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
199 const size_t mask = ~(align - 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
200 return (tmp_value & mask) == value;
a61af66fc99e Initial load
duke
parents:
diff changeset
201 }
a61af66fc99e Initial load
duke
parents:
diff changeset
202
a61af66fc99e Initial load
duke
parents:
diff changeset
203 bool PSVirtualSpace::is_aligned(size_t value) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
204 return is_aligned(value, alignment());
a61af66fc99e Initial load
duke
parents:
diff changeset
205 }
a61af66fc99e Initial load
duke
parents:
diff changeset
206
a61af66fc99e Initial load
duke
parents:
diff changeset
207 bool PSVirtualSpace::is_aligned(char* value) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
208 return is_aligned((size_t)value);
a61af66fc99e Initial load
duke
parents:
diff changeset
209 }
a61af66fc99e Initial load
duke
parents:
diff changeset
210
a61af66fc99e Initial load
duke
parents:
diff changeset
211 void PSVirtualSpace::verify() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
212 assert(is_aligned(alignment(), os::vm_page_size()), "bad alignment");
a61af66fc99e Initial load
duke
parents:
diff changeset
213 assert(is_aligned(reserved_low_addr()), "bad reserved_low_addr");
a61af66fc99e Initial load
duke
parents:
diff changeset
214 assert(is_aligned(reserved_high_addr()), "bad reserved_high_addr");
a61af66fc99e Initial load
duke
parents:
diff changeset
215 assert(is_aligned(committed_low_addr()), "bad committed_low_addr");
a61af66fc99e Initial load
duke
parents:
diff changeset
216 assert(is_aligned(committed_high_addr()), "bad committed_high_addr");
a61af66fc99e Initial load
duke
parents:
diff changeset
217
a61af66fc99e Initial load
duke
parents:
diff changeset
218 // Reserved region must be non-empty or both addrs must be 0.
a61af66fc99e Initial load
duke
parents:
diff changeset
219 assert(reserved_low_addr() < reserved_high_addr() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
220 reserved_low_addr() == NULL && reserved_high_addr() == NULL,
a61af66fc99e Initial load
duke
parents:
diff changeset
221 "bad reserved addrs");
a61af66fc99e Initial load
duke
parents:
diff changeset
222 assert(committed_low_addr() <= committed_high_addr(), "bad committed addrs");
a61af66fc99e Initial load
duke
parents:
diff changeset
223
a61af66fc99e Initial load
duke
parents:
diff changeset
224 if (grows_up()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
225 assert(reserved_low_addr() == committed_low_addr(), "bad low addrs");
a61af66fc99e Initial load
duke
parents:
diff changeset
226 assert(reserved_high_addr() >= committed_high_addr(), "bad high addrs");
a61af66fc99e Initial load
duke
parents:
diff changeset
227 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
228 assert(reserved_high_addr() == committed_high_addr(), "bad high addrs");
a61af66fc99e Initial load
duke
parents:
diff changeset
229 assert(reserved_low_addr() <= committed_low_addr(), "bad low addrs");
a61af66fc99e Initial load
duke
parents:
diff changeset
230 }
a61af66fc99e Initial load
duke
parents:
diff changeset
231 }
a61af66fc99e Initial load
duke
parents:
diff changeset
232
a61af66fc99e Initial load
duke
parents:
diff changeset
233 void PSVirtualSpace::print() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
234 gclog_or_tty->print_cr("virtual space [" PTR_FORMAT "]: alignment="
a61af66fc99e Initial load
duke
parents:
diff changeset
235 SIZE_FORMAT "K grows %s%s",
a61af66fc99e Initial load
duke
parents:
diff changeset
236 this, alignment() / K, grows_up() ? "up" : "down",
a61af66fc99e Initial load
duke
parents:
diff changeset
237 special() ? " (pinned in memory)" : "");
a61af66fc99e Initial load
duke
parents:
diff changeset
238 gclog_or_tty->print_cr(" reserved=" SIZE_FORMAT "K"
a61af66fc99e Initial load
duke
parents:
diff changeset
239 " [" PTR_FORMAT "," PTR_FORMAT "]"
a61af66fc99e Initial load
duke
parents:
diff changeset
240 " committed=" SIZE_FORMAT "K"
a61af66fc99e Initial load
duke
parents:
diff changeset
241 " [" PTR_FORMAT "," PTR_FORMAT "]",
a61af66fc99e Initial load
duke
parents:
diff changeset
242 reserved_size() / K,
a61af66fc99e Initial load
duke
parents:
diff changeset
243 reserved_low_addr(), reserved_high_addr(),
a61af66fc99e Initial load
duke
parents:
diff changeset
244 committed_size() / K,
a61af66fc99e Initial load
duke
parents:
diff changeset
245 committed_low_addr(), committed_high_addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
246 }
a61af66fc99e Initial load
duke
parents:
diff changeset
247 #endif // #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
248
a61af66fc99e Initial load
duke
parents:
diff changeset
249 void PSVirtualSpace::print_space_boundaries_on(outputStream* st) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
250 st->print_cr(" [" PTR_FORMAT ", " PTR_FORMAT ", " PTR_FORMAT ")",
a61af66fc99e Initial load
duke
parents:
diff changeset
251 low_boundary(), high(), high_boundary());
a61af66fc99e Initial load
duke
parents:
diff changeset
252 }
a61af66fc99e Initial load
duke
parents:
diff changeset
253
a61af66fc99e Initial load
duke
parents:
diff changeset
254 PSVirtualSpaceHighToLow::PSVirtualSpaceHighToLow(ReservedSpace rs,
a61af66fc99e Initial load
duke
parents:
diff changeset
255 size_t alignment) :
a61af66fc99e Initial load
duke
parents:
diff changeset
256 PSVirtualSpace(alignment)
a61af66fc99e Initial load
duke
parents:
diff changeset
257 {
a61af66fc99e Initial load
duke
parents:
diff changeset
258 set_reserved(rs);
a61af66fc99e Initial load
duke
parents:
diff changeset
259 set_committed(reserved_high_addr(), reserved_high_addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
260 DEBUG_ONLY(verify());
a61af66fc99e Initial load
duke
parents:
diff changeset
261 }
a61af66fc99e Initial load
duke
parents:
diff changeset
262
a61af66fc99e Initial load
duke
parents:
diff changeset
263 PSVirtualSpaceHighToLow::PSVirtualSpaceHighToLow(ReservedSpace rs) {
a61af66fc99e Initial load
duke
parents:
diff changeset
264 set_reserved(rs);
a61af66fc99e Initial load
duke
parents:
diff changeset
265 set_committed(reserved_high_addr(), reserved_high_addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
266 DEBUG_ONLY(verify());
a61af66fc99e Initial load
duke
parents:
diff changeset
267 }
a61af66fc99e Initial load
duke
parents:
diff changeset
268
535
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 337
diff changeset
269 bool PSVirtualSpaceHighToLow::expand_by(size_t bytes) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
270 assert(is_aligned(bytes), "arg not aligned");
a61af66fc99e Initial load
duke
parents:
diff changeset
271 DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
a61af66fc99e Initial load
duke
parents:
diff changeset
272
a61af66fc99e Initial load
duke
parents:
diff changeset
273 if (uncommitted_size() < bytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
274 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
275 }
a61af66fc99e Initial load
duke
parents:
diff changeset
276
a61af66fc99e Initial load
duke
parents:
diff changeset
277 char* const base_addr = committed_low_addr() - bytes;
10969
a837fa3d3f86 8013057: assert(_needs_gc || SafepointSynchronize::is_at_safepoint()) failed: only read at safepoint
dcubed
parents: 3960
diff changeset
278 bool result = special() ||
a837fa3d3f86 8013057: assert(_needs_gc || SafepointSynchronize::is_at_safepoint()) failed: only read at safepoint
dcubed
parents: 3960
diff changeset
279 os::commit_memory(base_addr, bytes, alignment(), !ExecMem);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
280 if (result) {
a61af66fc99e Initial load
duke
parents:
diff changeset
281 _committed_low_addr -= bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
282 }
a61af66fc99e Initial load
duke
parents:
diff changeset
283
a61af66fc99e Initial load
duke
parents:
diff changeset
284 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
285 }
a61af66fc99e Initial load
duke
parents:
diff changeset
286
a61af66fc99e Initial load
duke
parents:
diff changeset
287 bool PSVirtualSpaceHighToLow::shrink_by(size_t bytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
288 assert(is_aligned(bytes), "arg not aligned");
a61af66fc99e Initial load
duke
parents:
diff changeset
289 DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
a61af66fc99e Initial load
duke
parents:
diff changeset
290
a61af66fc99e Initial load
duke
parents:
diff changeset
291 if (committed_size() < bytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
292 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
293 }
a61af66fc99e Initial load
duke
parents:
diff changeset
294
a61af66fc99e Initial load
duke
parents:
diff changeset
295 char* const base_addr = committed_low_addr();
a61af66fc99e Initial load
duke
parents:
diff changeset
296 bool result = special() || os::uncommit_memory(base_addr, bytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
297 if (result) {
a61af66fc99e Initial load
duke
parents:
diff changeset
298 _committed_low_addr += bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
299 }
a61af66fc99e Initial load
duke
parents:
diff changeset
300
a61af66fc99e Initial load
duke
parents:
diff changeset
301 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
302 }
a61af66fc99e Initial load
duke
parents:
diff changeset
303
a61af66fc99e Initial load
duke
parents:
diff changeset
304 size_t PSVirtualSpaceHighToLow::expand_into(PSVirtualSpace* other_space,
a61af66fc99e Initial load
duke
parents:
diff changeset
305 size_t bytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
306 assert(is_aligned(bytes), "arg not aligned");
a61af66fc99e Initial load
duke
parents:
diff changeset
307 assert(grows_down(), "this space must grow down");
a61af66fc99e Initial load
duke
parents:
diff changeset
308 assert(other_space->grows_up(), "other space must grow up");
a61af66fc99e Initial load
duke
parents:
diff changeset
309 assert(reserved_low_addr() == other_space->reserved_high_addr(),
a61af66fc99e Initial load
duke
parents:
diff changeset
310 "spaces not contiguous");
a61af66fc99e Initial load
duke
parents:
diff changeset
311 assert(special() == other_space->special(), "one space is special in memory, the other is not");
a61af66fc99e Initial load
duke
parents:
diff changeset
312 DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
a61af66fc99e Initial load
duke
parents:
diff changeset
313 DEBUG_ONLY(PSVirtualSpaceVerifier other_verifier(other_space));
a61af66fc99e Initial load
duke
parents:
diff changeset
314
a61af66fc99e Initial load
duke
parents:
diff changeset
315 size_t bytes_needed = bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
316
a61af66fc99e Initial load
duke
parents:
diff changeset
317 // First use the uncommitted region in this space.
a61af66fc99e Initial load
duke
parents:
diff changeset
318 size_t tmp_bytes = MIN2(uncommitted_size(), bytes_needed);
a61af66fc99e Initial load
duke
parents:
diff changeset
319 if (tmp_bytes > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
320 if (expand_by(tmp_bytes)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
321 bytes_needed -= tmp_bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
322 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
323 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
324 }
a61af66fc99e Initial load
duke
parents:
diff changeset
325 }
a61af66fc99e Initial load
duke
parents:
diff changeset
326
a61af66fc99e Initial load
duke
parents:
diff changeset
327 // Next take from the uncommitted region in the other space, and commit it.
a61af66fc99e Initial load
duke
parents:
diff changeset
328 tmp_bytes = MIN2(other_space->uncommitted_size(), bytes_needed);
a61af66fc99e Initial load
duke
parents:
diff changeset
329 if (tmp_bytes > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
330 char* const commit_base = committed_low_addr() - tmp_bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
331 if (other_space->special() ||
10969
a837fa3d3f86 8013057: assert(_needs_gc || SafepointSynchronize::is_at_safepoint()) failed: only read at safepoint
dcubed
parents: 3960
diff changeset
332 os::commit_memory(commit_base, tmp_bytes, alignment(), !ExecMem)) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
333 // Reduce the reserved region in the other space.
a61af66fc99e Initial load
duke
parents:
diff changeset
334 other_space->set_reserved(other_space->reserved_low_addr(),
a61af66fc99e Initial load
duke
parents:
diff changeset
335 other_space->reserved_high_addr() - tmp_bytes,
a61af66fc99e Initial load
duke
parents:
diff changeset
336 other_space->special());
a61af66fc99e Initial load
duke
parents:
diff changeset
337
a61af66fc99e Initial load
duke
parents:
diff changeset
338 // Grow both reserved and committed in this space.
a61af66fc99e Initial load
duke
parents:
diff changeset
339 _reserved_low_addr -= tmp_bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
340 _committed_low_addr -= tmp_bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
341 bytes_needed -= tmp_bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
342 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
343 return bytes - bytes_needed;
a61af66fc99e Initial load
duke
parents:
diff changeset
344 }
a61af66fc99e Initial load
duke
parents:
diff changeset
345 }
a61af66fc99e Initial load
duke
parents:
diff changeset
346
a61af66fc99e Initial load
duke
parents:
diff changeset
347 // Finally take from the already committed region in the other space.
a61af66fc99e Initial load
duke
parents:
diff changeset
348 tmp_bytes = bytes_needed;
a61af66fc99e Initial load
duke
parents:
diff changeset
349 if (tmp_bytes > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
350 // Reduce both committed and reserved in the other space.
a61af66fc99e Initial load
duke
parents:
diff changeset
351 other_space->set_committed(other_space->committed_low_addr(),
a61af66fc99e Initial load
duke
parents:
diff changeset
352 other_space->committed_high_addr() - tmp_bytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
353 other_space->set_reserved(other_space->reserved_low_addr(),
a61af66fc99e Initial load
duke
parents:
diff changeset
354 other_space->reserved_high_addr() - tmp_bytes,
a61af66fc99e Initial load
duke
parents:
diff changeset
355 other_space->special());
a61af66fc99e Initial load
duke
parents:
diff changeset
356
a61af66fc99e Initial load
duke
parents:
diff changeset
357 // Grow both reserved and committed in this space.
a61af66fc99e Initial load
duke
parents:
diff changeset
358 _reserved_low_addr -= tmp_bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
359 _committed_low_addr -= tmp_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 return bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
363 }
a61af66fc99e Initial load
duke
parents:
diff changeset
364
a61af66fc99e Initial load
duke
parents:
diff changeset
365 void
a61af66fc99e Initial load
duke
parents:
diff changeset
366 PSVirtualSpaceHighToLow::print_space_boundaries_on(outputStream* st) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
367 st->print_cr(" (" PTR_FORMAT ", " PTR_FORMAT ", " PTR_FORMAT "]",
a61af66fc99e Initial load
duke
parents:
diff changeset
368 high_boundary(), low(), low_boundary());
a61af66fc99e Initial load
duke
parents:
diff changeset
369 }