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

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial