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

Fri, 10 May 2013 08:27:30 -0700

author
minqi
date
Fri, 10 May 2013 08:27:30 -0700
changeset 5097
92ef81e2f571
parent 3156
f08d439fab8c
child 5255
a837fa3d3f86
permissions
-rw-r--r--

8003557: NPG: Klass* const k should be const Klass* k.
Summary: With NPG, const KlassOop klass which is in fact a definition converted to Klass* const, which is not the original intention. The right usage is converting them to const Klass*.
Reviewed-by: coleenp, kvn
Contributed-by: yumin.qi@oracle.com

duke@435 1 /*
stefank@2314 2 * Copyright (c) 2003, 2010, 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();
duke@435 104 bool result = special() || os::commit_memory(base_addr, bytes, alignment());
duke@435 105 if (result) {
duke@435 106 _committed_high_addr += bytes;
duke@435 107 }
duke@435 108
duke@435 109 return result;
duke@435 110 }
duke@435 111
duke@435 112 bool PSVirtualSpace::shrink_by(size_t bytes) {
duke@435 113 assert(is_aligned(bytes), "arg not aligned");
duke@435 114 DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
duke@435 115
duke@435 116 if (committed_size() < bytes) {
duke@435 117 return false;
duke@435 118 }
duke@435 119
duke@435 120 char* const base_addr = committed_high_addr() - bytes;
duke@435 121 bool result = special() || os::uncommit_memory(base_addr, bytes);
duke@435 122 if (result) {
duke@435 123 _committed_high_addr -= bytes;
duke@435 124 }
duke@435 125
duke@435 126 return result;
duke@435 127 }
duke@435 128
duke@435 129 size_t
duke@435 130 PSVirtualSpace::expand_into(PSVirtualSpace* other_space, size_t bytes) {
duke@435 131 assert(is_aligned(bytes), "arg not aligned");
duke@435 132 assert(grows_up(), "this space must grow up");
duke@435 133 assert(other_space->grows_down(), "other space must grow down");
duke@435 134 assert(reserved_high_addr() == other_space->reserved_low_addr(),
duke@435 135 "spaces not contiguous");
duke@435 136 assert(special() == other_space->special(), "one space is special, the other is not");
duke@435 137 DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
duke@435 138 DEBUG_ONLY(PSVirtualSpaceVerifier other_verifier(other_space));
duke@435 139
duke@435 140 size_t bytes_needed = bytes;
duke@435 141
duke@435 142 // First use the uncommitted region in this space.
duke@435 143 size_t tmp_bytes = MIN2(uncommitted_size(), bytes_needed);
duke@435 144 if (tmp_bytes > 0) {
duke@435 145 if (expand_by(tmp_bytes)) {
duke@435 146 bytes_needed -= tmp_bytes;
duke@435 147 } else {
duke@435 148 return 0;
duke@435 149 }
duke@435 150 }
duke@435 151
duke@435 152 // Next take from the uncommitted region in the other space, and commit it.
duke@435 153 tmp_bytes = MIN2(other_space->uncommitted_size(), bytes_needed);
duke@435 154 if (tmp_bytes > 0) {
duke@435 155 char* const commit_base = committed_high_addr();
duke@435 156 if (other_space->special() ||
duke@435 157 os::commit_memory(commit_base, tmp_bytes, alignment())) {
duke@435 158 // Reduce the reserved region in the other space.
duke@435 159 other_space->set_reserved(other_space->reserved_low_addr() + tmp_bytes,
duke@435 160 other_space->reserved_high_addr(),
duke@435 161 other_space->special());
duke@435 162
duke@435 163 // Grow both reserved and committed in this space.
duke@435 164 _reserved_high_addr += tmp_bytes;
duke@435 165 _committed_high_addr += tmp_bytes;
duke@435 166 bytes_needed -= tmp_bytes;
duke@435 167 } else {
duke@435 168 return bytes - bytes_needed;
duke@435 169 }
duke@435 170 }
duke@435 171
duke@435 172 // Finally take from the already committed region in the other space.
duke@435 173 tmp_bytes = bytes_needed;
duke@435 174 if (tmp_bytes > 0) {
duke@435 175 // Reduce both committed and reserved in the other space.
duke@435 176 other_space->set_committed(other_space->committed_low_addr() + tmp_bytes,
duke@435 177 other_space->committed_high_addr());
duke@435 178 other_space->set_reserved(other_space->reserved_low_addr() + tmp_bytes,
duke@435 179 other_space->reserved_high_addr(),
duke@435 180 other_space->special());
duke@435 181
duke@435 182 // Grow both reserved and committed in this space.
duke@435 183 _reserved_high_addr += tmp_bytes;
duke@435 184 _committed_high_addr += tmp_bytes;
duke@435 185 }
duke@435 186
duke@435 187 return bytes;
duke@435 188 }
duke@435 189
duke@435 190 #ifndef PRODUCT
duke@435 191 bool PSVirtualSpace::is_aligned(size_t value, size_t align) {
duke@435 192 const size_t tmp_value = value + align - 1;
duke@435 193 const size_t mask = ~(align - 1);
duke@435 194 return (tmp_value & mask) == value;
duke@435 195 }
duke@435 196
duke@435 197 bool PSVirtualSpace::is_aligned(size_t value) const {
duke@435 198 return is_aligned(value, alignment());
duke@435 199 }
duke@435 200
duke@435 201 bool PSVirtualSpace::is_aligned(char* value) const {
duke@435 202 return is_aligned((size_t)value);
duke@435 203 }
duke@435 204
duke@435 205 void PSVirtualSpace::verify() const {
duke@435 206 assert(is_aligned(alignment(), os::vm_page_size()), "bad alignment");
duke@435 207 assert(is_aligned(reserved_low_addr()), "bad reserved_low_addr");
duke@435 208 assert(is_aligned(reserved_high_addr()), "bad reserved_high_addr");
duke@435 209 assert(is_aligned(committed_low_addr()), "bad committed_low_addr");
duke@435 210 assert(is_aligned(committed_high_addr()), "bad committed_high_addr");
duke@435 211
duke@435 212 // Reserved region must be non-empty or both addrs must be 0.
duke@435 213 assert(reserved_low_addr() < reserved_high_addr() ||
duke@435 214 reserved_low_addr() == NULL && reserved_high_addr() == NULL,
duke@435 215 "bad reserved addrs");
duke@435 216 assert(committed_low_addr() <= committed_high_addr(), "bad committed addrs");
duke@435 217
duke@435 218 if (grows_up()) {
duke@435 219 assert(reserved_low_addr() == committed_low_addr(), "bad low addrs");
duke@435 220 assert(reserved_high_addr() >= committed_high_addr(), "bad high addrs");
duke@435 221 } else {
duke@435 222 assert(reserved_high_addr() == committed_high_addr(), "bad high addrs");
duke@435 223 assert(reserved_low_addr() <= committed_low_addr(), "bad low addrs");
duke@435 224 }
duke@435 225 }
duke@435 226
duke@435 227 void PSVirtualSpace::print() const {
duke@435 228 gclog_or_tty->print_cr("virtual space [" PTR_FORMAT "]: alignment="
duke@435 229 SIZE_FORMAT "K grows %s%s",
duke@435 230 this, alignment() / K, grows_up() ? "up" : "down",
duke@435 231 special() ? " (pinned in memory)" : "");
duke@435 232 gclog_or_tty->print_cr(" reserved=" SIZE_FORMAT "K"
duke@435 233 " [" PTR_FORMAT "," PTR_FORMAT "]"
duke@435 234 " committed=" SIZE_FORMAT "K"
duke@435 235 " [" PTR_FORMAT "," PTR_FORMAT "]",
duke@435 236 reserved_size() / K,
duke@435 237 reserved_low_addr(), reserved_high_addr(),
duke@435 238 committed_size() / K,
duke@435 239 committed_low_addr(), committed_high_addr());
duke@435 240 }
duke@435 241 #endif // #ifndef PRODUCT
duke@435 242
duke@435 243 void PSVirtualSpace::print_space_boundaries_on(outputStream* st) const {
duke@435 244 st->print_cr(" [" PTR_FORMAT ", " PTR_FORMAT ", " PTR_FORMAT ")",
duke@435 245 low_boundary(), high(), high_boundary());
duke@435 246 }
duke@435 247
duke@435 248 PSVirtualSpaceHighToLow::PSVirtualSpaceHighToLow(ReservedSpace rs,
duke@435 249 size_t alignment) :
duke@435 250 PSVirtualSpace(alignment)
duke@435 251 {
duke@435 252 set_reserved(rs);
duke@435 253 set_committed(reserved_high_addr(), reserved_high_addr());
duke@435 254 DEBUG_ONLY(verify());
duke@435 255 }
duke@435 256
duke@435 257 PSVirtualSpaceHighToLow::PSVirtualSpaceHighToLow(ReservedSpace rs) {
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
iveresov@970 263 bool PSVirtualSpaceHighToLow::expand_by(size_t bytes) {
duke@435 264 assert(is_aligned(bytes), "arg not aligned");
duke@435 265 DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
duke@435 266
duke@435 267 if (uncommitted_size() < bytes) {
duke@435 268 return false;
duke@435 269 }
duke@435 270
duke@435 271 char* const base_addr = committed_low_addr() - bytes;
duke@435 272 bool result = special() || os::commit_memory(base_addr, bytes, alignment());
duke@435 273 if (result) {
duke@435 274 _committed_low_addr -= bytes;
duke@435 275 }
duke@435 276
duke@435 277 return result;
duke@435 278 }
duke@435 279
duke@435 280 bool PSVirtualSpaceHighToLow::shrink_by(size_t bytes) {
duke@435 281 assert(is_aligned(bytes), "arg not aligned");
duke@435 282 DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
duke@435 283
duke@435 284 if (committed_size() < bytes) {
duke@435 285 return false;
duke@435 286 }
duke@435 287
duke@435 288 char* const base_addr = committed_low_addr();
duke@435 289 bool result = special() || os::uncommit_memory(base_addr, bytes);
duke@435 290 if (result) {
duke@435 291 _committed_low_addr += bytes;
duke@435 292 }
duke@435 293
duke@435 294 return result;
duke@435 295 }
duke@435 296
duke@435 297 size_t PSVirtualSpaceHighToLow::expand_into(PSVirtualSpace* other_space,
duke@435 298 size_t bytes) {
duke@435 299 assert(is_aligned(bytes), "arg not aligned");
duke@435 300 assert(grows_down(), "this space must grow down");
duke@435 301 assert(other_space->grows_up(), "other space must grow up");
duke@435 302 assert(reserved_low_addr() == other_space->reserved_high_addr(),
duke@435 303 "spaces not contiguous");
duke@435 304 assert(special() == other_space->special(), "one space is special in memory, the other is not");
duke@435 305 DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
duke@435 306 DEBUG_ONLY(PSVirtualSpaceVerifier other_verifier(other_space));
duke@435 307
duke@435 308 size_t bytes_needed = bytes;
duke@435 309
duke@435 310 // First use the uncommitted region in this space.
duke@435 311 size_t tmp_bytes = MIN2(uncommitted_size(), bytes_needed);
duke@435 312 if (tmp_bytes > 0) {
duke@435 313 if (expand_by(tmp_bytes)) {
duke@435 314 bytes_needed -= tmp_bytes;
duke@435 315 } else {
duke@435 316 return 0;
duke@435 317 }
duke@435 318 }
duke@435 319
duke@435 320 // Next take from the uncommitted region in the other space, and commit it.
duke@435 321 tmp_bytes = MIN2(other_space->uncommitted_size(), bytes_needed);
duke@435 322 if (tmp_bytes > 0) {
duke@435 323 char* const commit_base = committed_low_addr() - tmp_bytes;
duke@435 324 if (other_space->special() ||
duke@435 325 os::commit_memory(commit_base, tmp_bytes, alignment())) {
duke@435 326 // Reduce the reserved region in the other space.
duke@435 327 other_space->set_reserved(other_space->reserved_low_addr(),
duke@435 328 other_space->reserved_high_addr() - tmp_bytes,
duke@435 329 other_space->special());
duke@435 330
duke@435 331 // Grow both reserved and committed in this space.
duke@435 332 _reserved_low_addr -= tmp_bytes;
duke@435 333 _committed_low_addr -= tmp_bytes;
duke@435 334 bytes_needed -= tmp_bytes;
duke@435 335 } else {
duke@435 336 return bytes - bytes_needed;
duke@435 337 }
duke@435 338 }
duke@435 339
duke@435 340 // Finally take from the already committed region in the other space.
duke@435 341 tmp_bytes = bytes_needed;
duke@435 342 if (tmp_bytes > 0) {
duke@435 343 // Reduce both committed and reserved in the other space.
duke@435 344 other_space->set_committed(other_space->committed_low_addr(),
duke@435 345 other_space->committed_high_addr() - tmp_bytes);
duke@435 346 other_space->set_reserved(other_space->reserved_low_addr(),
duke@435 347 other_space->reserved_high_addr() - tmp_bytes,
duke@435 348 other_space->special());
duke@435 349
duke@435 350 // Grow both reserved and committed in this space.
duke@435 351 _reserved_low_addr -= tmp_bytes;
duke@435 352 _committed_low_addr -= tmp_bytes;
duke@435 353 }
duke@435 354
duke@435 355 return bytes;
duke@435 356 }
duke@435 357
duke@435 358 void
duke@435 359 PSVirtualSpaceHighToLow::print_space_boundaries_on(outputStream* st) const {
duke@435 360 st->print_cr(" (" PTR_FORMAT ", " PTR_FORMAT ", " PTR_FORMAT "]",
duke@435 361 high_boundary(), low(), low_boundary());
duke@435 362 }

mercurial