src/share/vm/gc_implementation/parallelScavenge/psVirtualspace.cpp

Thu, 09 Apr 2015 15:58:49 +0200

author
mlarsson
date
Thu, 09 Apr 2015 15:58:49 +0200
changeset 7686
fb69749583e8
parent 6680
78bbf4d43a14
child 6876
710a3c8b516e
permissions
-rw-r--r--

8072621: Clean up around VM_GC_Operations
Reviewed-by: brutisso, jmasa

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

mercurial