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

Fri, 31 May 2013 14:32:44 +0200

author
stefank
date
Fri, 31 May 2013 14:32:44 +0200
changeset 5515
9766f73e770d
parent 5255
a837fa3d3f86
child 6461
bdd155477289
permissions
-rw-r--r--

8022880: False sharing between PSPromotionManager instances
Summary: Pad the PSPromotionManager instances in the manager array.
Reviewed-by: brutisso, jmasa

duke@435 1 /*
dcubed@5255 2 * Copyright (c) 2003, 2013, 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
never@3156 38 #ifdef TARGET_OS_FAMILY_bsd
never@3156 39 # include "os_bsd.inline.hpp"
never@3156 40 #endif
duke@435 41
duke@435 42 // PSVirtualSpace
duke@435 43
duke@435 44 PSVirtualSpace::PSVirtualSpace(ReservedSpace rs, size_t alignment) :
duke@435 45 _alignment(alignment)
duke@435 46 {
duke@435 47 set_reserved(rs);
duke@435 48 set_committed(reserved_low_addr(), reserved_low_addr());
duke@435 49 DEBUG_ONLY(verify());
duke@435 50 }
duke@435 51
duke@435 52 PSVirtualSpace::PSVirtualSpace(ReservedSpace rs) :
duke@435 53 _alignment(os::vm_page_size())
duke@435 54 {
duke@435 55 set_reserved(rs);
duke@435 56 set_committed(reserved_low_addr(), reserved_low_addr());
duke@435 57 DEBUG_ONLY(verify());
duke@435 58 }
duke@435 59
duke@435 60 // Deprecated.
duke@435 61 PSVirtualSpace::PSVirtualSpace(): _alignment(os::vm_page_size()) {
duke@435 62 }
duke@435 63
duke@435 64 // Deprecated.
duke@435 65 bool PSVirtualSpace::initialize(ReservedSpace rs,
duke@435 66 size_t commit_size) {
duke@435 67 set_reserved(rs);
duke@435 68 set_committed(reserved_low_addr(), reserved_low_addr());
duke@435 69
duke@435 70 // Commit to initial size.
duke@435 71 assert(commit_size <= rs.size(), "commit_size too big");
duke@435 72 bool result = commit_size > 0 ? expand_by(commit_size) : true;
duke@435 73 DEBUG_ONLY(verify());
duke@435 74 return result;
duke@435 75 }
duke@435 76
duke@435 77 PSVirtualSpace::~PSVirtualSpace() {
duke@435 78 release();
duke@435 79 }
duke@435 80
duke@435 81 bool PSVirtualSpace::contains(void* p) const {
duke@435 82 char* const cp = (char*)p;
duke@435 83 return cp >= committed_low_addr() && cp < committed_high_addr();
duke@435 84 }
duke@435 85
duke@435 86 void PSVirtualSpace::release() {
duke@435 87 DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
coleenp@672 88 // This may not release memory it didn't reserve.
coleenp@672 89 // Use rs.release() to release the underlying memory instead.
duke@435 90 _reserved_low_addr = _reserved_high_addr = NULL;
duke@435 91 _committed_low_addr = _committed_high_addr = NULL;
duke@435 92 _special = false;
duke@435 93 }
duke@435 94
iveresov@970 95 bool PSVirtualSpace::expand_by(size_t bytes) {
duke@435 96 assert(is_aligned(bytes), "arg not aligned");
duke@435 97 DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
duke@435 98
duke@435 99 if (uncommitted_size() < bytes) {
duke@435 100 return false;
duke@435 101 }
duke@435 102
duke@435 103 char* const base_addr = committed_high_addr();
dcubed@5255 104 bool result = special() ||
dcubed@5255 105 os::commit_memory(base_addr, bytes, alignment(), !ExecMem);
duke@435 106 if (result) {
duke@435 107 _committed_high_addr += bytes;
duke@435 108 }
duke@435 109
duke@435 110 return result;
duke@435 111 }
duke@435 112
duke@435 113 bool PSVirtualSpace::shrink_by(size_t bytes) {
duke@435 114 assert(is_aligned(bytes), "arg not aligned");
duke@435 115 DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
duke@435 116
duke@435 117 if (committed_size() < bytes) {
duke@435 118 return false;
duke@435 119 }
duke@435 120
duke@435 121 char* const base_addr = committed_high_addr() - bytes;
duke@435 122 bool result = special() || os::uncommit_memory(base_addr, bytes);
duke@435 123 if (result) {
duke@435 124 _committed_high_addr -= bytes;
duke@435 125 }
duke@435 126
duke@435 127 return result;
duke@435 128 }
duke@435 129
duke@435 130 size_t
duke@435 131 PSVirtualSpace::expand_into(PSVirtualSpace* other_space, size_t bytes) {
duke@435 132 assert(is_aligned(bytes), "arg not aligned");
duke@435 133 assert(grows_up(), "this space must grow up");
duke@435 134 assert(other_space->grows_down(), "other space must grow down");
duke@435 135 assert(reserved_high_addr() == other_space->reserved_low_addr(),
duke@435 136 "spaces not contiguous");
duke@435 137 assert(special() == other_space->special(), "one space is special, the other is not");
duke@435 138 DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
duke@435 139 DEBUG_ONLY(PSVirtualSpaceVerifier other_verifier(other_space));
duke@435 140
duke@435 141 size_t bytes_needed = bytes;
duke@435 142
duke@435 143 // First use the uncommitted region in this space.
duke@435 144 size_t tmp_bytes = MIN2(uncommitted_size(), bytes_needed);
duke@435 145 if (tmp_bytes > 0) {
duke@435 146 if (expand_by(tmp_bytes)) {
duke@435 147 bytes_needed -= tmp_bytes;
duke@435 148 } else {
duke@435 149 return 0;
duke@435 150 }
duke@435 151 }
duke@435 152
duke@435 153 // Next take from the uncommitted region in the other space, and commit it.
duke@435 154 tmp_bytes = MIN2(other_space->uncommitted_size(), bytes_needed);
duke@435 155 if (tmp_bytes > 0) {
duke@435 156 char* const commit_base = committed_high_addr();
duke@435 157 if (other_space->special() ||
dcubed@5255 158 os::commit_memory(commit_base, tmp_bytes, alignment(), !ExecMem)) {
duke@435 159 // Reduce the reserved region in the other space.
duke@435 160 other_space->set_reserved(other_space->reserved_low_addr() + tmp_bytes,
duke@435 161 other_space->reserved_high_addr(),
duke@435 162 other_space->special());
duke@435 163
duke@435 164 // Grow both reserved and committed in this space.
duke@435 165 _reserved_high_addr += tmp_bytes;
duke@435 166 _committed_high_addr += tmp_bytes;
duke@435 167 bytes_needed -= tmp_bytes;
duke@435 168 } else {
duke@435 169 return bytes - bytes_needed;
duke@435 170 }
duke@435 171 }
duke@435 172
duke@435 173 // Finally take from the already committed region in the other space.
duke@435 174 tmp_bytes = bytes_needed;
duke@435 175 if (tmp_bytes > 0) {
duke@435 176 // Reduce both committed and reserved in the other space.
duke@435 177 other_space->set_committed(other_space->committed_low_addr() + tmp_bytes,
duke@435 178 other_space->committed_high_addr());
duke@435 179 other_space->set_reserved(other_space->reserved_low_addr() + tmp_bytes,
duke@435 180 other_space->reserved_high_addr(),
duke@435 181 other_space->special());
duke@435 182
duke@435 183 // Grow both reserved and committed in this space.
duke@435 184 _reserved_high_addr += tmp_bytes;
duke@435 185 _committed_high_addr += tmp_bytes;
duke@435 186 }
duke@435 187
duke@435 188 return bytes;
duke@435 189 }
duke@435 190
duke@435 191 #ifndef PRODUCT
duke@435 192 bool PSVirtualSpace::is_aligned(size_t value, size_t align) {
duke@435 193 const size_t tmp_value = value + align - 1;
duke@435 194 const size_t mask = ~(align - 1);
duke@435 195 return (tmp_value & mask) == value;
duke@435 196 }
duke@435 197
duke@435 198 bool PSVirtualSpace::is_aligned(size_t value) const {
duke@435 199 return is_aligned(value, alignment());
duke@435 200 }
duke@435 201
duke@435 202 bool PSVirtualSpace::is_aligned(char* value) const {
duke@435 203 return is_aligned((size_t)value);
duke@435 204 }
duke@435 205
duke@435 206 void PSVirtualSpace::verify() const {
duke@435 207 assert(is_aligned(alignment(), os::vm_page_size()), "bad alignment");
duke@435 208 assert(is_aligned(reserved_low_addr()), "bad reserved_low_addr");
duke@435 209 assert(is_aligned(reserved_high_addr()), "bad reserved_high_addr");
duke@435 210 assert(is_aligned(committed_low_addr()), "bad committed_low_addr");
duke@435 211 assert(is_aligned(committed_high_addr()), "bad committed_high_addr");
duke@435 212
duke@435 213 // Reserved region must be non-empty or both addrs must be 0.
duke@435 214 assert(reserved_low_addr() < reserved_high_addr() ||
duke@435 215 reserved_low_addr() == NULL && reserved_high_addr() == NULL,
duke@435 216 "bad reserved addrs");
duke@435 217 assert(committed_low_addr() <= committed_high_addr(), "bad committed addrs");
duke@435 218
duke@435 219 if (grows_up()) {
duke@435 220 assert(reserved_low_addr() == committed_low_addr(), "bad low addrs");
duke@435 221 assert(reserved_high_addr() >= committed_high_addr(), "bad high addrs");
duke@435 222 } else {
duke@435 223 assert(reserved_high_addr() == committed_high_addr(), "bad high addrs");
duke@435 224 assert(reserved_low_addr() <= committed_low_addr(), "bad low addrs");
duke@435 225 }
duke@435 226 }
duke@435 227
duke@435 228 void PSVirtualSpace::print() const {
duke@435 229 gclog_or_tty->print_cr("virtual space [" PTR_FORMAT "]: alignment="
duke@435 230 SIZE_FORMAT "K grows %s%s",
duke@435 231 this, alignment() / K, grows_up() ? "up" : "down",
duke@435 232 special() ? " (pinned in memory)" : "");
duke@435 233 gclog_or_tty->print_cr(" reserved=" SIZE_FORMAT "K"
duke@435 234 " [" PTR_FORMAT "," PTR_FORMAT "]"
duke@435 235 " committed=" SIZE_FORMAT "K"
duke@435 236 " [" PTR_FORMAT "," PTR_FORMAT "]",
duke@435 237 reserved_size() / K,
duke@435 238 reserved_low_addr(), reserved_high_addr(),
duke@435 239 committed_size() / K,
duke@435 240 committed_low_addr(), committed_high_addr());
duke@435 241 }
duke@435 242 #endif // #ifndef PRODUCT
duke@435 243
duke@435 244 void PSVirtualSpace::print_space_boundaries_on(outputStream* st) const {
duke@435 245 st->print_cr(" [" PTR_FORMAT ", " PTR_FORMAT ", " PTR_FORMAT ")",
duke@435 246 low_boundary(), high(), high_boundary());
duke@435 247 }
duke@435 248
duke@435 249 PSVirtualSpaceHighToLow::PSVirtualSpaceHighToLow(ReservedSpace rs,
duke@435 250 size_t alignment) :
duke@435 251 PSVirtualSpace(alignment)
duke@435 252 {
duke@435 253 set_reserved(rs);
duke@435 254 set_committed(reserved_high_addr(), reserved_high_addr());
duke@435 255 DEBUG_ONLY(verify());
duke@435 256 }
duke@435 257
duke@435 258 PSVirtualSpaceHighToLow::PSVirtualSpaceHighToLow(ReservedSpace rs) {
duke@435 259 set_reserved(rs);
duke@435 260 set_committed(reserved_high_addr(), reserved_high_addr());
duke@435 261 DEBUG_ONLY(verify());
duke@435 262 }
duke@435 263
iveresov@970 264 bool PSVirtualSpaceHighToLow::expand_by(size_t bytes) {
duke@435 265 assert(is_aligned(bytes), "arg not aligned");
duke@435 266 DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
duke@435 267
duke@435 268 if (uncommitted_size() < bytes) {
duke@435 269 return false;
duke@435 270 }
duke@435 271
duke@435 272 char* const base_addr = committed_low_addr() - bytes;
dcubed@5255 273 bool result = special() ||
dcubed@5255 274 os::commit_memory(base_addr, bytes, alignment(), !ExecMem);
duke@435 275 if (result) {
duke@435 276 _committed_low_addr -= bytes;
duke@435 277 }
duke@435 278
duke@435 279 return result;
duke@435 280 }
duke@435 281
duke@435 282 bool PSVirtualSpaceHighToLow::shrink_by(size_t bytes) {
duke@435 283 assert(is_aligned(bytes), "arg not aligned");
duke@435 284 DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
duke@435 285
duke@435 286 if (committed_size() < bytes) {
duke@435 287 return false;
duke@435 288 }
duke@435 289
duke@435 290 char* const base_addr = committed_low_addr();
duke@435 291 bool result = special() || os::uncommit_memory(base_addr, bytes);
duke@435 292 if (result) {
duke@435 293 _committed_low_addr += bytes;
duke@435 294 }
duke@435 295
duke@435 296 return result;
duke@435 297 }
duke@435 298
duke@435 299 size_t PSVirtualSpaceHighToLow::expand_into(PSVirtualSpace* other_space,
duke@435 300 size_t bytes) {
duke@435 301 assert(is_aligned(bytes), "arg not aligned");
duke@435 302 assert(grows_down(), "this space must grow down");
duke@435 303 assert(other_space->grows_up(), "other space must grow up");
duke@435 304 assert(reserved_low_addr() == other_space->reserved_high_addr(),
duke@435 305 "spaces not contiguous");
duke@435 306 assert(special() == other_space->special(), "one space is special in memory, the other is not");
duke@435 307 DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
duke@435 308 DEBUG_ONLY(PSVirtualSpaceVerifier other_verifier(other_space));
duke@435 309
duke@435 310 size_t bytes_needed = bytes;
duke@435 311
duke@435 312 // First use the uncommitted region in this space.
duke@435 313 size_t tmp_bytes = MIN2(uncommitted_size(), bytes_needed);
duke@435 314 if (tmp_bytes > 0) {
duke@435 315 if (expand_by(tmp_bytes)) {
duke@435 316 bytes_needed -= tmp_bytes;
duke@435 317 } else {
duke@435 318 return 0;
duke@435 319 }
duke@435 320 }
duke@435 321
duke@435 322 // Next take from the uncommitted region in the other space, and commit it.
duke@435 323 tmp_bytes = MIN2(other_space->uncommitted_size(), bytes_needed);
duke@435 324 if (tmp_bytes > 0) {
duke@435 325 char* const commit_base = committed_low_addr() - tmp_bytes;
duke@435 326 if (other_space->special() ||
dcubed@5255 327 os::commit_memory(commit_base, tmp_bytes, alignment(), !ExecMem)) {
duke@435 328 // Reduce the reserved region in the other space.
duke@435 329 other_space->set_reserved(other_space->reserved_low_addr(),
duke@435 330 other_space->reserved_high_addr() - tmp_bytes,
duke@435 331 other_space->special());
duke@435 332
duke@435 333 // Grow both reserved and committed in this space.
duke@435 334 _reserved_low_addr -= tmp_bytes;
duke@435 335 _committed_low_addr -= tmp_bytes;
duke@435 336 bytes_needed -= tmp_bytes;
duke@435 337 } else {
duke@435 338 return bytes - bytes_needed;
duke@435 339 }
duke@435 340 }
duke@435 341
duke@435 342 // Finally take from the already committed region in the other space.
duke@435 343 tmp_bytes = bytes_needed;
duke@435 344 if (tmp_bytes > 0) {
duke@435 345 // Reduce both committed and reserved in the other space.
duke@435 346 other_space->set_committed(other_space->committed_low_addr(),
duke@435 347 other_space->committed_high_addr() - tmp_bytes);
duke@435 348 other_space->set_reserved(other_space->reserved_low_addr(),
duke@435 349 other_space->reserved_high_addr() - tmp_bytes,
duke@435 350 other_space->special());
duke@435 351
duke@435 352 // Grow both reserved and committed in this space.
duke@435 353 _reserved_low_addr -= tmp_bytes;
duke@435 354 _committed_low_addr -= tmp_bytes;
duke@435 355 }
duke@435 356
duke@435 357 return bytes;
duke@435 358 }
duke@435 359
duke@435 360 void
duke@435 361 PSVirtualSpaceHighToLow::print_space_boundaries_on(outputStream* st) const {
duke@435 362 st->print_cr(" (" PTR_FORMAT ", " PTR_FORMAT ", " PTR_FORMAT "]",
duke@435 363 high_boundary(), low(), low_boundary());
duke@435 364 }

mercurial