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

Fri, 16 Mar 2012 16:14:04 +0100

author
nloodin
date
Fri, 16 Mar 2012 16:14:04 +0100
changeset 3665
8a729074feae
parent 3541
23c0eb012d6f
child 3711
b632e80fc9dc
permissions
-rw-r--r--

7154517: Build error in hotspot-gc without precompiled headers
Reviewed-by: jcoomes, brutisso

duke@435 1 /*
jcoomes@3541 2 * Copyright (c) 2001, 2012, 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/adjoiningGenerations.hpp"
stefank@2314 27 #include "gc_implementation/parallelScavenge/adjoiningVirtualSpaces.hpp"
stefank@2314 28 #include "gc_implementation/parallelScavenge/cardTableExtension.hpp"
stefank@2314 29 #include "gc_implementation/parallelScavenge/gcTaskManager.hpp"
stefank@2314 30 #include "gc_implementation/parallelScavenge/generationSizer.hpp"
stefank@2314 31 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.inline.hpp"
stefank@2314 32 #include "gc_implementation/parallelScavenge/psAdaptiveSizePolicy.hpp"
stefank@2314 33 #include "gc_implementation/parallelScavenge/psMarkSweep.hpp"
stefank@2314 34 #include "gc_implementation/parallelScavenge/psParallelCompact.hpp"
stefank@2314 35 #include "gc_implementation/parallelScavenge/psPromotionManager.hpp"
stefank@2314 36 #include "gc_implementation/parallelScavenge/psScavenge.hpp"
stefank@2314 37 #include "gc_implementation/parallelScavenge/vmPSOperations.hpp"
stefank@2314 38 #include "memory/gcLocker.inline.hpp"
stefank@2314 39 #include "oops/oop.inline.hpp"
stefank@2314 40 #include "runtime/handles.inline.hpp"
stefank@2314 41 #include "runtime/java.hpp"
stefank@2314 42 #include "runtime/vmThread.hpp"
stefank@2314 43 #include "utilities/vmError.hpp"
duke@435 44
duke@435 45 PSYoungGen* ParallelScavengeHeap::_young_gen = NULL;
duke@435 46 PSOldGen* ParallelScavengeHeap::_old_gen = NULL;
duke@435 47 PSPermGen* ParallelScavengeHeap::_perm_gen = NULL;
duke@435 48 PSAdaptiveSizePolicy* ParallelScavengeHeap::_size_policy = NULL;
duke@435 49 PSGCAdaptivePolicyCounters* ParallelScavengeHeap::_gc_policy_counters = NULL;
duke@435 50 ParallelScavengeHeap* ParallelScavengeHeap::_psh = NULL;
duke@435 51 GCTaskManager* ParallelScavengeHeap::_gc_task_manager = NULL;
duke@435 52
duke@435 53 static void trace_gen_sizes(const char* const str,
duke@435 54 size_t pg_min, size_t pg_max,
duke@435 55 size_t og_min, size_t og_max,
duke@435 56 size_t yg_min, size_t yg_max)
duke@435 57 {
duke@435 58 if (TracePageSizes) {
duke@435 59 tty->print_cr("%s: " SIZE_FORMAT "," SIZE_FORMAT " "
duke@435 60 SIZE_FORMAT "," SIZE_FORMAT " "
duke@435 61 SIZE_FORMAT "," SIZE_FORMAT " "
duke@435 62 SIZE_FORMAT,
duke@435 63 str, pg_min / K, pg_max / K,
duke@435 64 og_min / K, og_max / K,
duke@435 65 yg_min / K, yg_max / K,
duke@435 66 (pg_max + og_max + yg_max) / K);
duke@435 67 }
duke@435 68 }
duke@435 69
duke@435 70 jint ParallelScavengeHeap::initialize() {
ysr@1601 71 CollectedHeap::pre_initialize();
ysr@1601 72
duke@435 73 // Cannot be initialized until after the flags are parsed
jmasa@1822 74 // GenerationSizer flag_parser;
jmasa@1822 75 _collector_policy = new GenerationSizer();
duke@435 76
jmasa@1822 77 size_t yg_min_size = _collector_policy->min_young_gen_size();
jmasa@1822 78 size_t yg_max_size = _collector_policy->max_young_gen_size();
jmasa@1822 79 size_t og_min_size = _collector_policy->min_old_gen_size();
jmasa@1822 80 size_t og_max_size = _collector_policy->max_old_gen_size();
duke@435 81 // Why isn't there a min_perm_gen_size()?
jmasa@1822 82 size_t pg_min_size = _collector_policy->perm_gen_size();
jmasa@1822 83 size_t pg_max_size = _collector_policy->max_perm_gen_size();
duke@435 84
duke@435 85 trace_gen_sizes("ps heap raw",
duke@435 86 pg_min_size, pg_max_size,
duke@435 87 og_min_size, og_max_size,
duke@435 88 yg_min_size, yg_max_size);
duke@435 89
duke@435 90 // The ReservedSpace ctor used below requires that the page size for the perm
duke@435 91 // gen is <= the page size for the rest of the heap (young + old gens).
duke@435 92 const size_t og_page_sz = os::page_size_for_region(yg_min_size + og_min_size,
duke@435 93 yg_max_size + og_max_size,
duke@435 94 8);
duke@435 95 const size_t pg_page_sz = MIN2(os::page_size_for_region(pg_min_size,
duke@435 96 pg_max_size, 16),
duke@435 97 og_page_sz);
duke@435 98
duke@435 99 const size_t pg_align = set_alignment(_perm_gen_alignment, pg_page_sz);
duke@435 100 const size_t og_align = set_alignment(_old_gen_alignment, og_page_sz);
duke@435 101 const size_t yg_align = set_alignment(_young_gen_alignment, og_page_sz);
duke@435 102
duke@435 103 // Update sizes to reflect the selected page size(s).
duke@435 104 //
duke@435 105 // NEEDS_CLEANUP. The default TwoGenerationCollectorPolicy uses NewRatio; it
duke@435 106 // should check UseAdaptiveSizePolicy. Changes from generationSizer could
duke@435 107 // move to the common code.
duke@435 108 yg_min_size = align_size_up(yg_min_size, yg_align);
duke@435 109 yg_max_size = align_size_up(yg_max_size, yg_align);
jmasa@1822 110 size_t yg_cur_size =
jmasa@1822 111 align_size_up(_collector_policy->young_gen_size(), yg_align);
duke@435 112 yg_cur_size = MAX2(yg_cur_size, yg_min_size);
duke@435 113
duke@435 114 og_min_size = align_size_up(og_min_size, og_align);
kvn@2558 115 // Align old gen size down to preserve specified heap size.
kvn@2558 116 assert(og_align == yg_align, "sanity");
kvn@2558 117 og_max_size = align_size_down(og_max_size, og_align);
kvn@2558 118 og_max_size = MAX2(og_max_size, og_min_size);
jmasa@1822 119 size_t og_cur_size =
kvn@2558 120 align_size_down(_collector_policy->old_gen_size(), og_align);
duke@435 121 og_cur_size = MAX2(og_cur_size, og_min_size);
duke@435 122
duke@435 123 pg_min_size = align_size_up(pg_min_size, pg_align);
duke@435 124 pg_max_size = align_size_up(pg_max_size, pg_align);
duke@435 125 size_t pg_cur_size = pg_min_size;
duke@435 126
duke@435 127 trace_gen_sizes("ps heap rnd",
duke@435 128 pg_min_size, pg_max_size,
duke@435 129 og_min_size, og_max_size,
duke@435 130 yg_min_size, yg_max_size);
duke@435 131
kvn@1077 132 const size_t total_reserved = pg_max_size + og_max_size + yg_max_size;
kvn@1077 133 char* addr = Universe::preferred_heap_base(total_reserved, Universe::UnscaledNarrowOop);
kvn@1077 134
duke@435 135 // The main part of the heap (old gen + young gen) can often use a larger page
duke@435 136 // size than is needed or wanted for the perm gen. Use the "compound
duke@435 137 // alignment" ReservedSpace ctor to avoid having to use the same page size for
duke@435 138 // all gens.
kvn@1077 139
coleenp@672 140 ReservedHeapSpace heap_rs(pg_max_size, pg_align, og_max_size + yg_max_size,
kvn@1077 141 og_align, addr);
kvn@1077 142
kvn@1077 143 if (UseCompressedOops) {
kvn@1077 144 if (addr != NULL && !heap_rs.is_reserved()) {
kvn@1077 145 // Failed to reserve at specified address - the requested memory
kvn@1077 146 // region is taken already, for example, by 'java' launcher.
kvn@1077 147 // Try again to reserver heap higher.
kvn@1077 148 addr = Universe::preferred_heap_base(total_reserved, Universe::ZeroBasedNarrowOop);
kvn@1077 149 ReservedHeapSpace heap_rs0(pg_max_size, pg_align, og_max_size + yg_max_size,
kvn@1077 150 og_align, addr);
kvn@1077 151 if (addr != NULL && !heap_rs0.is_reserved()) {
kvn@1077 152 // Failed to reserve at specified address again - give up.
kvn@1077 153 addr = Universe::preferred_heap_base(total_reserved, Universe::HeapBasedNarrowOop);
kvn@1077 154 assert(addr == NULL, "");
kvn@1077 155 ReservedHeapSpace heap_rs1(pg_max_size, pg_align, og_max_size + yg_max_size,
kvn@1077 156 og_align, addr);
kvn@1077 157 heap_rs = heap_rs1;
kvn@1077 158 } else {
kvn@1077 159 heap_rs = heap_rs0;
kvn@1077 160 }
kvn@1077 161 }
kvn@1077 162 }
kvn@1077 163
duke@435 164 os::trace_page_sizes("ps perm", pg_min_size, pg_max_size, pg_page_sz,
duke@435 165 heap_rs.base(), pg_max_size);
duke@435 166 os::trace_page_sizes("ps main", og_min_size + yg_min_size,
duke@435 167 og_max_size + yg_max_size, og_page_sz,
duke@435 168 heap_rs.base() + pg_max_size,
duke@435 169 heap_rs.size() - pg_max_size);
duke@435 170 if (!heap_rs.is_reserved()) {
duke@435 171 vm_shutdown_during_initialization(
duke@435 172 "Could not reserve enough space for object heap");
duke@435 173 return JNI_ENOMEM;
duke@435 174 }
duke@435 175
duke@435 176 _reserved = MemRegion((HeapWord*)heap_rs.base(),
duke@435 177 (HeapWord*)(heap_rs.base() + heap_rs.size()));
duke@435 178
duke@435 179 CardTableExtension* const barrier_set = new CardTableExtension(_reserved, 3);
duke@435 180 _barrier_set = barrier_set;
duke@435 181 oopDesc::set_bs(_barrier_set);
duke@435 182 if (_barrier_set == NULL) {
duke@435 183 vm_shutdown_during_initialization(
duke@435 184 "Could not reserve enough space for barrier set");
duke@435 185 return JNI_ENOMEM;
duke@435 186 }
duke@435 187
duke@435 188 // Initial young gen size is 4 Mb
duke@435 189 //
duke@435 190 // XXX - what about flag_parser.young_gen_size()?
duke@435 191 const size_t init_young_size = align_size_up(4 * M, yg_align);
duke@435 192 yg_cur_size = MAX2(MIN2(init_young_size, yg_max_size), yg_cur_size);
duke@435 193
duke@435 194 // Split the reserved space into perm gen and the main heap (everything else).
duke@435 195 // The main heap uses a different alignment.
duke@435 196 ReservedSpace perm_rs = heap_rs.first_part(pg_max_size);
duke@435 197 ReservedSpace main_rs = heap_rs.last_part(pg_max_size, og_align);
duke@435 198
duke@435 199 // Make up the generations
duke@435 200 // Calculate the maximum size that a generation can grow. This
duke@435 201 // includes growth into the other generation. Note that the
duke@435 202 // parameter _max_gen_size is kept as the maximum
duke@435 203 // size of the generation as the boundaries currently stand.
duke@435 204 // _max_gen_size is still used as that value.
duke@435 205 double max_gc_pause_sec = ((double) MaxGCPauseMillis)/1000.0;
duke@435 206 double max_gc_minor_pause_sec = ((double) MaxGCMinorPauseMillis)/1000.0;
duke@435 207
duke@435 208 _gens = new AdjoiningGenerations(main_rs,
duke@435 209 og_cur_size,
duke@435 210 og_min_size,
duke@435 211 og_max_size,
duke@435 212 yg_cur_size,
duke@435 213 yg_min_size,
duke@435 214 yg_max_size,
duke@435 215 yg_align);
duke@435 216
duke@435 217 _old_gen = _gens->old_gen();
duke@435 218 _young_gen = _gens->young_gen();
duke@435 219
duke@435 220 const size_t eden_capacity = _young_gen->eden_space()->capacity_in_bytes();
duke@435 221 const size_t old_capacity = _old_gen->capacity_in_bytes();
duke@435 222 const size_t initial_promo_size = MIN2(eden_capacity, old_capacity);
duke@435 223 _size_policy =
duke@435 224 new PSAdaptiveSizePolicy(eden_capacity,
duke@435 225 initial_promo_size,
duke@435 226 young_gen()->to_space()->capacity_in_bytes(),
jmasa@448 227 intra_heap_alignment(),
duke@435 228 max_gc_pause_sec,
duke@435 229 max_gc_minor_pause_sec,
duke@435 230 GCTimeRatio
duke@435 231 );
duke@435 232
duke@435 233 _perm_gen = new PSPermGen(perm_rs,
duke@435 234 pg_align,
duke@435 235 pg_cur_size,
duke@435 236 pg_cur_size,
duke@435 237 pg_max_size,
duke@435 238 "perm", 2);
duke@435 239
duke@435 240 assert(!UseAdaptiveGCBoundary ||
duke@435 241 (old_gen()->virtual_space()->high_boundary() ==
duke@435 242 young_gen()->virtual_space()->low_boundary()),
duke@435 243 "Boundaries must meet");
duke@435 244 // initialize the policy counters - 2 collectors, 3 generations
duke@435 245 _gc_policy_counters =
duke@435 246 new PSGCAdaptivePolicyCounters("ParScav:MSC", 2, 3, _size_policy);
duke@435 247 _psh = this;
duke@435 248
duke@435 249 // Set up the GCTaskManager
duke@435 250 _gc_task_manager = GCTaskManager::create(ParallelGCThreads);
duke@435 251
duke@435 252 if (UseParallelOldGC && !PSParallelCompact::initialize()) {
duke@435 253 return JNI_ENOMEM;
duke@435 254 }
duke@435 255
duke@435 256 return JNI_OK;
duke@435 257 }
duke@435 258
duke@435 259 void ParallelScavengeHeap::post_initialize() {
duke@435 260 // Need to init the tenuring threshold
duke@435 261 PSScavenge::initialize();
duke@435 262 if (UseParallelOldGC) {
duke@435 263 PSParallelCompact::post_initialize();
duke@435 264 } else {
duke@435 265 PSMarkSweep::initialize();
duke@435 266 }
duke@435 267 PSPromotionManager::initialize();
duke@435 268 }
duke@435 269
duke@435 270 void ParallelScavengeHeap::update_counters() {
duke@435 271 young_gen()->update_counters();
duke@435 272 old_gen()->update_counters();
duke@435 273 perm_gen()->update_counters();
duke@435 274 }
duke@435 275
duke@435 276 size_t ParallelScavengeHeap::capacity() const {
duke@435 277 size_t value = young_gen()->capacity_in_bytes() + old_gen()->capacity_in_bytes();
duke@435 278 return value;
duke@435 279 }
duke@435 280
duke@435 281 size_t ParallelScavengeHeap::used() const {
duke@435 282 size_t value = young_gen()->used_in_bytes() + old_gen()->used_in_bytes();
duke@435 283 return value;
duke@435 284 }
duke@435 285
duke@435 286 bool ParallelScavengeHeap::is_maximal_no_gc() const {
duke@435 287 return old_gen()->is_maximal_no_gc() && young_gen()->is_maximal_no_gc();
duke@435 288 }
duke@435 289
duke@435 290
duke@435 291 size_t ParallelScavengeHeap::permanent_capacity() const {
duke@435 292 return perm_gen()->capacity_in_bytes();
duke@435 293 }
duke@435 294
duke@435 295 size_t ParallelScavengeHeap::permanent_used() const {
duke@435 296 return perm_gen()->used_in_bytes();
duke@435 297 }
duke@435 298
duke@435 299 size_t ParallelScavengeHeap::max_capacity() const {
duke@435 300 size_t estimated = reserved_region().byte_size();
duke@435 301 estimated -= perm_gen()->reserved().byte_size();
duke@435 302 if (UseAdaptiveSizePolicy) {
duke@435 303 estimated -= _size_policy->max_survivor_size(young_gen()->max_size());
duke@435 304 } else {
duke@435 305 estimated -= young_gen()->to_space()->capacity_in_bytes();
duke@435 306 }
duke@435 307 return MAX2(estimated, capacity());
duke@435 308 }
duke@435 309
duke@435 310 bool ParallelScavengeHeap::is_in(const void* p) const {
duke@435 311 if (young_gen()->is_in(p)) {
duke@435 312 return true;
duke@435 313 }
duke@435 314
duke@435 315 if (old_gen()->is_in(p)) {
duke@435 316 return true;
duke@435 317 }
duke@435 318
duke@435 319 if (perm_gen()->is_in(p)) {
duke@435 320 return true;
duke@435 321 }
duke@435 322
duke@435 323 return false;
duke@435 324 }
duke@435 325
duke@435 326 bool ParallelScavengeHeap::is_in_reserved(const void* p) const {
duke@435 327 if (young_gen()->is_in_reserved(p)) {
duke@435 328 return true;
duke@435 329 }
duke@435 330
duke@435 331 if (old_gen()->is_in_reserved(p)) {
duke@435 332 return true;
duke@435 333 }
duke@435 334
duke@435 335 if (perm_gen()->is_in_reserved(p)) {
duke@435 336 return true;
duke@435 337 }
duke@435 338
duke@435 339 return false;
duke@435 340 }
duke@435 341
jmasa@2909 342 bool ParallelScavengeHeap::is_scavengable(const void* addr) {
jmasa@2909 343 return is_in_young((oop)addr);
jmasa@2909 344 }
jmasa@2909 345
jmasa@2909 346 #ifdef ASSERT
jmasa@2909 347 // Don't implement this by using is_in_young(). This method is used
jmasa@2909 348 // in some cases to check that is_in_young() is correct.
jmasa@2909 349 bool ParallelScavengeHeap::is_in_partial_collection(const void *p) {
jmasa@2909 350 assert(is_in_reserved(p) || p == NULL,
jmasa@2909 351 "Does not work if address is non-null and outside of the heap");
jmasa@2909 352 // The order of the generations is perm (low addr), old, young (high addr)
jmasa@2909 353 return p >= old_gen()->reserved().end();
jmasa@2909 354 }
jmasa@2909 355 #endif
jmasa@2909 356
duke@435 357 // There are two levels of allocation policy here.
duke@435 358 //
duke@435 359 // When an allocation request fails, the requesting thread must invoke a VM
duke@435 360 // operation, transfer control to the VM thread, and await the results of a
duke@435 361 // garbage collection. That is quite expensive, and we should avoid doing it
duke@435 362 // multiple times if possible.
duke@435 363 //
duke@435 364 // To accomplish this, we have a basic allocation policy, and also a
duke@435 365 // failed allocation policy.
duke@435 366 //
duke@435 367 // The basic allocation policy controls how you allocate memory without
duke@435 368 // attempting garbage collection. It is okay to grab locks and
duke@435 369 // expand the heap, if that can be done without coming to a safepoint.
duke@435 370 // It is likely that the basic allocation policy will not be very
duke@435 371 // aggressive.
duke@435 372 //
duke@435 373 // The failed allocation policy is invoked from the VM thread after
duke@435 374 // the basic allocation policy is unable to satisfy a mem_allocate
duke@435 375 // request. This policy needs to cover the entire range of collection,
duke@435 376 // heap expansion, and out-of-memory conditions. It should make every
duke@435 377 // attempt to allocate the requested memory.
duke@435 378
duke@435 379 // Basic allocation policy. Should never be called at a safepoint, or
duke@435 380 // from the VM thread.
duke@435 381 //
duke@435 382 // This method must handle cases where many mem_allocate requests fail
duke@435 383 // simultaneously. When that happens, only one VM operation will succeed,
duke@435 384 // and the rest will not be executed. For that reason, this method loops
duke@435 385 // during failed allocation attempts. If the java heap becomes exhausted,
duke@435 386 // we rely on the size_policy object to force a bail out.
duke@435 387 HeapWord* ParallelScavengeHeap::mem_allocate(
duke@435 388 size_t size,
duke@435 389 bool* gc_overhead_limit_was_exceeded) {
duke@435 390 assert(!SafepointSynchronize::is_at_safepoint(), "should not be at safepoint");
duke@435 391 assert(Thread::current() != (Thread*)VMThread::vm_thread(), "should not be in vm thread");
duke@435 392 assert(!Heap_lock->owned_by_self(), "this thread should not own the Heap_lock");
duke@435 393
jmasa@1822 394 // In general gc_overhead_limit_was_exceeded should be false so
jmasa@1822 395 // set it so here and reset it to true only if the gc time
jmasa@1822 396 // limit is being exceeded as checked below.
jmasa@1822 397 *gc_overhead_limit_was_exceeded = false;
jmasa@1822 398
tonyp@2971 399 HeapWord* result = young_gen()->allocate(size);
duke@435 400
duke@435 401 uint loop_count = 0;
duke@435 402 uint gc_count = 0;
duke@435 403
duke@435 404 while (result == NULL) {
duke@435 405 // We don't want to have multiple collections for a single filled generation.
duke@435 406 // To prevent this, each thread tracks the total_collections() value, and if
duke@435 407 // the count has changed, does not do a new collection.
duke@435 408 //
duke@435 409 // The collection count must be read only while holding the heap lock. VM
duke@435 410 // operations also hold the heap lock during collections. There is a lock
duke@435 411 // contention case where thread A blocks waiting on the Heap_lock, while
duke@435 412 // thread B is holding it doing a collection. When thread A gets the lock,
duke@435 413 // the collection count has already changed. To prevent duplicate collections,
duke@435 414 // The policy MUST attempt allocations during the same period it reads the
duke@435 415 // total_collections() value!
duke@435 416 {
duke@435 417 MutexLocker ml(Heap_lock);
duke@435 418 gc_count = Universe::heap()->total_collections();
duke@435 419
tonyp@2971 420 result = young_gen()->allocate(size);
duke@435 421 if (result != NULL) {
duke@435 422 return result;
duke@435 423 }
jcoomes@3541 424
jcoomes@3541 425 // If certain conditions hold, try allocating from the old gen.
jcoomes@3541 426 result = mem_allocate_old_gen(size);
jcoomes@3541 427 if (result != NULL) {
jcoomes@3541 428 return result;
duke@435 429 }
jcoomes@3541 430
jcoomes@3541 431 // Failed to allocate without a gc.
duke@435 432 if (GC_locker::is_active_and_needs_gc()) {
duke@435 433 // If this thread is not in a jni critical section, we stall
duke@435 434 // the requestor until the critical section has cleared and
duke@435 435 // GC allowed. When the critical section clears, a GC is
duke@435 436 // initiated by the last thread exiting the critical section; so
duke@435 437 // we retry the allocation sequence from the beginning of the loop,
duke@435 438 // rather than causing more, now probably unnecessary, GC attempts.
duke@435 439 JavaThread* jthr = JavaThread::current();
duke@435 440 if (!jthr->in_critical()) {
duke@435 441 MutexUnlocker mul(Heap_lock);
duke@435 442 GC_locker::stall_until_clear();
duke@435 443 continue;
duke@435 444 } else {
duke@435 445 if (CheckJNICalls) {
duke@435 446 fatal("Possible deadlock due to allocating while"
duke@435 447 " in jni critical section");
duke@435 448 }
duke@435 449 return NULL;
duke@435 450 }
duke@435 451 }
duke@435 452 }
duke@435 453
duke@435 454 if (result == NULL) {
duke@435 455 // Generate a VM operation
tonyp@2971 456 VM_ParallelGCFailedAllocation op(size, gc_count);
duke@435 457 VMThread::execute(&op);
duke@435 458
duke@435 459 // Did the VM operation execute? If so, return the result directly.
duke@435 460 // This prevents us from looping until time out on requests that can
duke@435 461 // not be satisfied.
duke@435 462 if (op.prologue_succeeded()) {
duke@435 463 assert(Universe::heap()->is_in_or_null(op.result()),
duke@435 464 "result not in heap");
duke@435 465
duke@435 466 // If GC was locked out during VM operation then retry allocation
duke@435 467 // and/or stall as necessary.
duke@435 468 if (op.gc_locked()) {
duke@435 469 assert(op.result() == NULL, "must be NULL if gc_locked() is true");
duke@435 470 continue; // retry and/or stall as necessary
duke@435 471 }
jmasa@1822 472
jmasa@1822 473 // Exit the loop if the gc time limit has been exceeded.
jmasa@1822 474 // The allocation must have failed above ("result" guarding
jmasa@1822 475 // this path is NULL) and the most recent collection has exceeded the
jmasa@1822 476 // gc overhead limit (although enough may have been collected to
jmasa@1822 477 // satisfy the allocation). Exit the loop so that an out-of-memory
jmasa@1822 478 // will be thrown (return a NULL ignoring the contents of
jmasa@1822 479 // op.result()),
jmasa@1822 480 // but clear gc_overhead_limit_exceeded so that the next collection
jmasa@1822 481 // starts with a clean slate (i.e., forgets about previous overhead
jmasa@1822 482 // excesses). Fill op.result() with a filler object so that the
jmasa@1822 483 // heap remains parsable.
jmasa@1822 484 const bool limit_exceeded = size_policy()->gc_overhead_limit_exceeded();
jmasa@1822 485 const bool softrefs_clear = collector_policy()->all_soft_refs_clear();
jmasa@1822 486 assert(!limit_exceeded || softrefs_clear, "Should have been cleared");
jmasa@1822 487 if (limit_exceeded && softrefs_clear) {
jmasa@1822 488 *gc_overhead_limit_was_exceeded = true;
jmasa@1822 489 size_policy()->set_gc_overhead_limit_exceeded(false);
jmasa@1822 490 if (PrintGCDetails && Verbose) {
jmasa@1822 491 gclog_or_tty->print_cr("ParallelScavengeHeap::mem_allocate: "
jmasa@1822 492 "return NULL because gc_overhead_limit_exceeded is set");
jmasa@1822 493 }
jmasa@1822 494 if (op.result() != NULL) {
jmasa@1822 495 CollectedHeap::fill_with_object(op.result(), size);
jmasa@1822 496 }
jmasa@1822 497 return NULL;
duke@435 498 }
jmasa@1822 499
duke@435 500 return op.result();
duke@435 501 }
duke@435 502 }
duke@435 503
duke@435 504 // The policy object will prevent us from looping forever. If the
duke@435 505 // time spent in gc crosses a threshold, we will bail out.
duke@435 506 loop_count++;
duke@435 507 if ((result == NULL) && (QueuedAllocationWarningCount > 0) &&
duke@435 508 (loop_count % QueuedAllocationWarningCount == 0)) {
duke@435 509 warning("ParallelScavengeHeap::mem_allocate retries %d times \n\t"
tonyp@2971 510 " size=%d", loop_count, size);
duke@435 511 }
duke@435 512 }
duke@435 513
duke@435 514 return result;
duke@435 515 }
duke@435 516
jcoomes@3541 517 // A "death march" is a series of ultra-slow allocations in which a full gc is
jcoomes@3541 518 // done before each allocation, and after the full gc the allocation still
jcoomes@3541 519 // cannot be satisfied from the young gen. This routine detects that condition;
jcoomes@3541 520 // it should be called after a full gc has been done and the allocation
jcoomes@3541 521 // attempted from the young gen. The parameter 'addr' should be the result of
jcoomes@3541 522 // that young gen allocation attempt.
jcoomes@3541 523 void
jcoomes@3541 524 ParallelScavengeHeap::death_march_check(HeapWord* const addr, size_t size) {
jcoomes@3541 525 if (addr != NULL) {
jcoomes@3541 526 _death_march_count = 0; // death march has ended
jcoomes@3541 527 } else if (_death_march_count == 0) {
jcoomes@3541 528 if (should_alloc_in_eden(size)) {
jcoomes@3541 529 _death_march_count = 1; // death march has started
jcoomes@3541 530 }
jcoomes@3541 531 }
jcoomes@3541 532 }
jcoomes@3541 533
jcoomes@3541 534 HeapWord* ParallelScavengeHeap::mem_allocate_old_gen(size_t size) {
jcoomes@3541 535 if (!should_alloc_in_eden(size) || GC_locker::is_active_and_needs_gc()) {
jcoomes@3541 536 // Size is too big for eden, or gc is locked out.
jcoomes@3541 537 return old_gen()->allocate(size);
jcoomes@3541 538 }
jcoomes@3541 539
jcoomes@3541 540 // If a "death march" is in progress, allocate from the old gen a limited
jcoomes@3541 541 // number of times before doing a GC.
jcoomes@3541 542 if (_death_march_count > 0) {
jcoomes@3541 543 if (_death_march_count < 64) {
jcoomes@3541 544 ++_death_march_count;
jcoomes@3541 545 return old_gen()->allocate(size);
jcoomes@3541 546 } else {
jcoomes@3541 547 _death_march_count = 0;
jcoomes@3541 548 }
jcoomes@3541 549 }
jcoomes@3541 550 return NULL;
jcoomes@3541 551 }
jcoomes@3541 552
duke@435 553 // Failed allocation policy. Must be called from the VM thread, and
duke@435 554 // only at a safepoint! Note that this method has policy for allocation
duke@435 555 // flow, and NOT collection policy. So we do not check for gc collection
duke@435 556 // time over limit here, that is the responsibility of the heap specific
duke@435 557 // collection methods. This method decides where to attempt allocations,
duke@435 558 // and when to attempt collections, but no collection specific policy.
tonyp@2971 559 HeapWord* ParallelScavengeHeap::failed_mem_allocate(size_t size) {
duke@435 560 assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint");
duke@435 561 assert(Thread::current() == (Thread*)VMThread::vm_thread(), "should be in vm thread");
duke@435 562 assert(!Universe::heap()->is_gc_active(), "not reentrant");
duke@435 563 assert(!Heap_lock->owned_by_self(), "this thread should not own the Heap_lock");
duke@435 564
jcoomes@3541 565 // We assume that allocation in eden will fail unless we collect.
duke@435 566
duke@435 567 // First level allocation failure, scavenge and allocate in young gen.
duke@435 568 GCCauseSetter gccs(this, GCCause::_allocation_failure);
jcoomes@3541 569 const bool invoked_full_gc = PSScavenge::invoke();
tonyp@2971 570 HeapWord* result = young_gen()->allocate(size);
duke@435 571
duke@435 572 // Second level allocation failure.
duke@435 573 // Mark sweep and allocate in young generation.
jcoomes@3541 574 if (result == NULL && !invoked_full_gc) {
jcoomes@3541 575 invoke_full_gc(false);
jcoomes@3541 576 result = young_gen()->allocate(size);
duke@435 577 }
duke@435 578
jcoomes@3541 579 death_march_check(result, size);
jcoomes@3541 580
duke@435 581 // Third level allocation failure.
duke@435 582 // After mark sweep and young generation allocation failure,
duke@435 583 // allocate in old generation.
tonyp@2971 584 if (result == NULL) {
tonyp@2971 585 result = old_gen()->allocate(size);
duke@435 586 }
duke@435 587
duke@435 588 // Fourth level allocation failure. We're running out of memory.
duke@435 589 // More complete mark sweep and allocate in young generation.
duke@435 590 if (result == NULL) {
duke@435 591 invoke_full_gc(true);
tonyp@2971 592 result = young_gen()->allocate(size);
duke@435 593 }
duke@435 594
duke@435 595 // Fifth level allocation failure.
duke@435 596 // After more complete mark sweep, allocate in old generation.
tonyp@2971 597 if (result == NULL) {
tonyp@2971 598 result = old_gen()->allocate(size);
duke@435 599 }
duke@435 600
duke@435 601 return result;
duke@435 602 }
duke@435 603
duke@435 604 //
duke@435 605 // This is the policy loop for allocating in the permanent generation.
duke@435 606 // If the initial allocation fails, we create a vm operation which will
duke@435 607 // cause a collection.
duke@435 608 HeapWord* ParallelScavengeHeap::permanent_mem_allocate(size_t size) {
duke@435 609 assert(!SafepointSynchronize::is_at_safepoint(), "should not be at safepoint");
duke@435 610 assert(Thread::current() != (Thread*)VMThread::vm_thread(), "should not be in vm thread");
duke@435 611 assert(!Heap_lock->owned_by_self(), "this thread should not own the Heap_lock");
duke@435 612
duke@435 613 HeapWord* result;
duke@435 614
duke@435 615 uint loop_count = 0;
duke@435 616 uint gc_count = 0;
duke@435 617 uint full_gc_count = 0;
duke@435 618
duke@435 619 do {
duke@435 620 // We don't want to have multiple collections for a single filled generation.
duke@435 621 // To prevent this, each thread tracks the total_collections() value, and if
duke@435 622 // the count has changed, does not do a new collection.
duke@435 623 //
duke@435 624 // The collection count must be read only while holding the heap lock. VM
duke@435 625 // operations also hold the heap lock during collections. There is a lock
duke@435 626 // contention case where thread A blocks waiting on the Heap_lock, while
duke@435 627 // thread B is holding it doing a collection. When thread A gets the lock,
duke@435 628 // the collection count has already changed. To prevent duplicate collections,
duke@435 629 // The policy MUST attempt allocations during the same period it reads the
duke@435 630 // total_collections() value!
duke@435 631 {
duke@435 632 MutexLocker ml(Heap_lock);
duke@435 633 gc_count = Universe::heap()->total_collections();
duke@435 634 full_gc_count = Universe::heap()->total_full_collections();
duke@435 635
duke@435 636 result = perm_gen()->allocate_permanent(size);
apetrusenko@574 637
apetrusenko@574 638 if (result != NULL) {
apetrusenko@574 639 return result;
apetrusenko@574 640 }
apetrusenko@574 641
apetrusenko@574 642 if (GC_locker::is_active_and_needs_gc()) {
apetrusenko@574 643 // If this thread is not in a jni critical section, we stall
apetrusenko@574 644 // the requestor until the critical section has cleared and
apetrusenko@574 645 // GC allowed. When the critical section clears, a GC is
apetrusenko@574 646 // initiated by the last thread exiting the critical section; so
apetrusenko@574 647 // we retry the allocation sequence from the beginning of the loop,
apetrusenko@574 648 // rather than causing more, now probably unnecessary, GC attempts.
apetrusenko@574 649 JavaThread* jthr = JavaThread::current();
apetrusenko@574 650 if (!jthr->in_critical()) {
apetrusenko@574 651 MutexUnlocker mul(Heap_lock);
apetrusenko@574 652 GC_locker::stall_until_clear();
apetrusenko@574 653 continue;
apetrusenko@574 654 } else {
apetrusenko@574 655 if (CheckJNICalls) {
apetrusenko@574 656 fatal("Possible deadlock due to allocating while"
apetrusenko@574 657 " in jni critical section");
apetrusenko@574 658 }
apetrusenko@574 659 return NULL;
apetrusenko@574 660 }
apetrusenko@574 661 }
duke@435 662 }
duke@435 663
duke@435 664 if (result == NULL) {
duke@435 665
duke@435 666 // Exit the loop if the gc time limit has been exceeded.
duke@435 667 // The allocation must have failed above (result must be NULL),
duke@435 668 // and the most recent collection must have exceeded the
duke@435 669 // gc time limit. Exit the loop so that an out-of-memory
duke@435 670 // will be thrown (returning a NULL will do that), but
jmasa@1822 671 // clear gc_overhead_limit_exceeded so that the next collection
duke@435 672 // will succeeded if the applications decides to handle the
duke@435 673 // out-of-memory and tries to go on.
jmasa@1822 674 const bool limit_exceeded = size_policy()->gc_overhead_limit_exceeded();
jmasa@1822 675 if (limit_exceeded) {
jmasa@1822 676 size_policy()->set_gc_overhead_limit_exceeded(false);
duke@435 677 if (PrintGCDetails && Verbose) {
jmasa@1822 678 gclog_or_tty->print_cr("ParallelScavengeHeap::permanent_mem_allocate:"
jmasa@1822 679 " return NULL because gc_overhead_limit_exceeded is set");
duke@435 680 }
duke@435 681 assert(result == NULL, "Allocation did not fail");
duke@435 682 return NULL;
duke@435 683 }
duke@435 684
duke@435 685 // Generate a VM operation
duke@435 686 VM_ParallelGCFailedPermanentAllocation op(size, gc_count, full_gc_count);
duke@435 687 VMThread::execute(&op);
duke@435 688
duke@435 689 // Did the VM operation execute? If so, return the result directly.
duke@435 690 // This prevents us from looping until time out on requests that can
duke@435 691 // not be satisfied.
duke@435 692 if (op.prologue_succeeded()) {
duke@435 693 assert(Universe::heap()->is_in_permanent_or_null(op.result()),
duke@435 694 "result not in heap");
apetrusenko@574 695 // If GC was locked out during VM operation then retry allocation
apetrusenko@574 696 // and/or stall as necessary.
apetrusenko@574 697 if (op.gc_locked()) {
apetrusenko@574 698 assert(op.result() == NULL, "must be NULL if gc_locked() is true");
apetrusenko@574 699 continue; // retry and/or stall as necessary
apetrusenko@574 700 }
duke@435 701 // If a NULL results is being returned, an out-of-memory
jmasa@1822 702 // will be thrown now. Clear the gc_overhead_limit_exceeded
duke@435 703 // flag to avoid the following situation.
jmasa@1822 704 // gc_overhead_limit_exceeded is set during a collection
duke@435 705 // the collection fails to return enough space and an OOM is thrown
jmasa@1822 706 // a subsequent GC prematurely throws an out-of-memory because
jmasa@1822 707 // the gc_overhead_limit_exceeded counts did not start
jmasa@1822 708 // again from 0.
duke@435 709 if (op.result() == NULL) {
jmasa@1822 710 size_policy()->reset_gc_overhead_limit_count();
duke@435 711 }
duke@435 712 return op.result();
duke@435 713 }
duke@435 714 }
duke@435 715
duke@435 716 // The policy object will prevent us from looping forever. If the
duke@435 717 // time spent in gc crosses a threshold, we will bail out.
duke@435 718 loop_count++;
duke@435 719 if ((QueuedAllocationWarningCount > 0) &&
duke@435 720 (loop_count % QueuedAllocationWarningCount == 0)) {
duke@435 721 warning("ParallelScavengeHeap::permanent_mem_allocate retries %d times \n\t"
duke@435 722 " size=%d", loop_count, size);
duke@435 723 }
duke@435 724 } while (result == NULL);
duke@435 725
duke@435 726 return result;
duke@435 727 }
duke@435 728
duke@435 729 //
duke@435 730 // This is the policy code for permanent allocations which have failed
duke@435 731 // and require a collection. Note that just as in failed_mem_allocate,
duke@435 732 // we do not set collection policy, only where & when to allocate and
duke@435 733 // collect.
duke@435 734 HeapWord* ParallelScavengeHeap::failed_permanent_mem_allocate(size_t size) {
duke@435 735 assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint");
duke@435 736 assert(Thread::current() == (Thread*)VMThread::vm_thread(), "should be in vm thread");
duke@435 737 assert(!Universe::heap()->is_gc_active(), "not reentrant");
duke@435 738 assert(!Heap_lock->owned_by_self(), "this thread should not own the Heap_lock");
duke@435 739 assert(size > perm_gen()->free_in_words(), "Allocation should fail");
duke@435 740
duke@435 741 // We assume (and assert!) that an allocation at this point will fail
duke@435 742 // unless we collect.
duke@435 743
duke@435 744 // First level allocation failure. Mark-sweep and allocate in perm gen.
duke@435 745 GCCauseSetter gccs(this, GCCause::_allocation_failure);
duke@435 746 invoke_full_gc(false);
duke@435 747 HeapWord* result = perm_gen()->allocate_permanent(size);
duke@435 748
duke@435 749 // Second level allocation failure. We're running out of memory.
duke@435 750 if (result == NULL) {
duke@435 751 invoke_full_gc(true);
duke@435 752 result = perm_gen()->allocate_permanent(size);
duke@435 753 }
duke@435 754
duke@435 755 return result;
duke@435 756 }
duke@435 757
duke@435 758 void ParallelScavengeHeap::ensure_parsability(bool retire_tlabs) {
duke@435 759 CollectedHeap::ensure_parsability(retire_tlabs);
duke@435 760 young_gen()->eden_space()->ensure_parsability();
duke@435 761 }
duke@435 762
duke@435 763 size_t ParallelScavengeHeap::unsafe_max_alloc() {
duke@435 764 return young_gen()->eden_space()->free_in_bytes();
duke@435 765 }
duke@435 766
duke@435 767 size_t ParallelScavengeHeap::tlab_capacity(Thread* thr) const {
duke@435 768 return young_gen()->eden_space()->tlab_capacity(thr);
duke@435 769 }
duke@435 770
duke@435 771 size_t ParallelScavengeHeap::unsafe_max_tlab_alloc(Thread* thr) const {
duke@435 772 return young_gen()->eden_space()->unsafe_max_tlab_alloc(thr);
duke@435 773 }
duke@435 774
duke@435 775 HeapWord* ParallelScavengeHeap::allocate_new_tlab(size_t size) {
tonyp@2971 776 return young_gen()->allocate(size);
duke@435 777 }
duke@435 778
duke@435 779 void ParallelScavengeHeap::accumulate_statistics_all_tlabs() {
duke@435 780 CollectedHeap::accumulate_statistics_all_tlabs();
duke@435 781 }
duke@435 782
duke@435 783 void ParallelScavengeHeap::resize_all_tlabs() {
duke@435 784 CollectedHeap::resize_all_tlabs();
duke@435 785 }
duke@435 786
ysr@1462 787 bool ParallelScavengeHeap::can_elide_initializing_store_barrier(oop new_obj) {
ysr@1462 788 // We don't need barriers for stores to objects in the
ysr@1462 789 // young gen and, a fortiori, for initializing stores to
ysr@1462 790 // objects therein.
ysr@1462 791 return is_in_young(new_obj);
ysr@1462 792 }
ysr@1462 793
duke@435 794 // This method is used by System.gc() and JVMTI.
duke@435 795 void ParallelScavengeHeap::collect(GCCause::Cause cause) {
duke@435 796 assert(!Heap_lock->owned_by_self(),
duke@435 797 "this thread should not own the Heap_lock");
duke@435 798
duke@435 799 unsigned int gc_count = 0;
duke@435 800 unsigned int full_gc_count = 0;
duke@435 801 {
duke@435 802 MutexLocker ml(Heap_lock);
duke@435 803 // This value is guarded by the Heap_lock
duke@435 804 gc_count = Universe::heap()->total_collections();
duke@435 805 full_gc_count = Universe::heap()->total_full_collections();
duke@435 806 }
duke@435 807
duke@435 808 VM_ParallelGCSystemGC op(gc_count, full_gc_count, cause);
duke@435 809 VMThread::execute(&op);
duke@435 810 }
duke@435 811
duke@435 812 // This interface assumes that it's being called by the
duke@435 813 // vm thread. It collects the heap assuming that the
duke@435 814 // heap lock is already held and that we are executing in
duke@435 815 // the context of the vm thread.
duke@435 816 void ParallelScavengeHeap::collect_as_vm_thread(GCCause::Cause cause) {
duke@435 817 assert(Thread::current()->is_VM_thread(), "Precondition#1");
duke@435 818 assert(Heap_lock->is_locked(), "Precondition#2");
duke@435 819 GCCauseSetter gcs(this, cause);
duke@435 820 switch (cause) {
duke@435 821 case GCCause::_heap_inspection:
duke@435 822 case GCCause::_heap_dump: {
duke@435 823 HandleMark hm;
duke@435 824 invoke_full_gc(false);
duke@435 825 break;
duke@435 826 }
duke@435 827 default: // XXX FIX ME
duke@435 828 ShouldNotReachHere();
duke@435 829 }
duke@435 830 }
duke@435 831
duke@435 832
duke@435 833 void ParallelScavengeHeap::oop_iterate(OopClosure* cl) {
duke@435 834 Unimplemented();
duke@435 835 }
duke@435 836
duke@435 837 void ParallelScavengeHeap::object_iterate(ObjectClosure* cl) {
duke@435 838 young_gen()->object_iterate(cl);
duke@435 839 old_gen()->object_iterate(cl);
duke@435 840 perm_gen()->object_iterate(cl);
duke@435 841 }
duke@435 842
duke@435 843 void ParallelScavengeHeap::permanent_oop_iterate(OopClosure* cl) {
duke@435 844 Unimplemented();
duke@435 845 }
duke@435 846
duke@435 847 void ParallelScavengeHeap::permanent_object_iterate(ObjectClosure* cl) {
duke@435 848 perm_gen()->object_iterate(cl);
duke@435 849 }
duke@435 850
duke@435 851 HeapWord* ParallelScavengeHeap::block_start(const void* addr) const {
duke@435 852 if (young_gen()->is_in_reserved(addr)) {
duke@435 853 assert(young_gen()->is_in(addr),
duke@435 854 "addr should be in allocated part of young gen");
never@2262 855 // called from os::print_location by find or VMError
never@2262 856 if (Debugging || VMError::fatal_error_in_progress()) return NULL;
duke@435 857 Unimplemented();
duke@435 858 } else if (old_gen()->is_in_reserved(addr)) {
duke@435 859 assert(old_gen()->is_in(addr),
duke@435 860 "addr should be in allocated part of old gen");
duke@435 861 return old_gen()->start_array()->object_start((HeapWord*)addr);
duke@435 862 } else if (perm_gen()->is_in_reserved(addr)) {
duke@435 863 assert(perm_gen()->is_in(addr),
duke@435 864 "addr should be in allocated part of perm gen");
duke@435 865 return perm_gen()->start_array()->object_start((HeapWord*)addr);
duke@435 866 }
duke@435 867 return 0;
duke@435 868 }
duke@435 869
duke@435 870 size_t ParallelScavengeHeap::block_size(const HeapWord* addr) const {
duke@435 871 return oop(addr)->size();
duke@435 872 }
duke@435 873
duke@435 874 bool ParallelScavengeHeap::block_is_obj(const HeapWord* addr) const {
duke@435 875 return block_start(addr) == addr;
duke@435 876 }
duke@435 877
duke@435 878 jlong ParallelScavengeHeap::millis_since_last_gc() {
duke@435 879 return UseParallelOldGC ?
duke@435 880 PSParallelCompact::millis_since_last_gc() :
duke@435 881 PSMarkSweep::millis_since_last_gc();
duke@435 882 }
duke@435 883
duke@435 884 void ParallelScavengeHeap::prepare_for_verify() {
duke@435 885 ensure_parsability(false); // no need to retire TLABs for verification
duke@435 886 }
duke@435 887
duke@435 888 void ParallelScavengeHeap::print_on(outputStream* st) const {
duke@435 889 young_gen()->print_on(st);
duke@435 890 old_gen()->print_on(st);
duke@435 891 perm_gen()->print_on(st);
duke@435 892 }
duke@435 893
duke@435 894 void ParallelScavengeHeap::gc_threads_do(ThreadClosure* tc) const {
duke@435 895 PSScavenge::gc_task_manager()->threads_do(tc);
duke@435 896 }
duke@435 897
duke@435 898 void ParallelScavengeHeap::print_gc_threads_on(outputStream* st) const {
duke@435 899 PSScavenge::gc_task_manager()->print_threads_on(st);
duke@435 900 }
duke@435 901
duke@435 902 void ParallelScavengeHeap::print_tracing_info() const {
duke@435 903 if (TraceGen0Time) {
duke@435 904 double time = PSScavenge::accumulated_time()->seconds();
duke@435 905 tty->print_cr("[Accumulated GC generation 0 time %3.7f secs]", time);
duke@435 906 }
duke@435 907 if (TraceGen1Time) {
duke@435 908 double time = PSMarkSweep::accumulated_time()->seconds();
duke@435 909 tty->print_cr("[Accumulated GC generation 1 time %3.7f secs]", time);
duke@435 910 }
duke@435 911 }
duke@435 912
duke@435 913
johnc@2969 914 void ParallelScavengeHeap::verify(bool allow_dirty, bool silent, VerifyOption option /* ignored */) {
duke@435 915 // Why do we need the total_collections()-filter below?
duke@435 916 if (total_collections() > 0) {
duke@435 917 if (!silent) {
duke@435 918 gclog_or_tty->print("permanent ");
duke@435 919 }
duke@435 920 perm_gen()->verify(allow_dirty);
duke@435 921
duke@435 922 if (!silent) {
duke@435 923 gclog_or_tty->print("tenured ");
duke@435 924 }
duke@435 925 old_gen()->verify(allow_dirty);
duke@435 926
duke@435 927 if (!silent) {
duke@435 928 gclog_or_tty->print("eden ");
duke@435 929 }
duke@435 930 young_gen()->verify(allow_dirty);
duke@435 931 }
duke@435 932 }
duke@435 933
duke@435 934 void ParallelScavengeHeap::print_heap_change(size_t prev_used) {
duke@435 935 if (PrintGCDetails && Verbose) {
duke@435 936 gclog_or_tty->print(" " SIZE_FORMAT
duke@435 937 "->" SIZE_FORMAT
duke@435 938 "(" SIZE_FORMAT ")",
duke@435 939 prev_used, used(), capacity());
duke@435 940 } else {
duke@435 941 gclog_or_tty->print(" " SIZE_FORMAT "K"
duke@435 942 "->" SIZE_FORMAT "K"
duke@435 943 "(" SIZE_FORMAT "K)",
duke@435 944 prev_used / K, used() / K, capacity() / K);
duke@435 945 }
duke@435 946 }
duke@435 947
duke@435 948 ParallelScavengeHeap* ParallelScavengeHeap::heap() {
duke@435 949 assert(_psh != NULL, "Uninitialized access to ParallelScavengeHeap::heap()");
duke@435 950 assert(_psh->kind() == CollectedHeap::ParallelScavengeHeap, "not a parallel scavenge heap");
duke@435 951 return _psh;
duke@435 952 }
duke@435 953
duke@435 954 // Before delegating the resize to the young generation,
duke@435 955 // the reserved space for the young and old generations
duke@435 956 // may be changed to accomodate the desired resize.
duke@435 957 void ParallelScavengeHeap::resize_young_gen(size_t eden_size,
duke@435 958 size_t survivor_size) {
duke@435 959 if (UseAdaptiveGCBoundary) {
duke@435 960 if (size_policy()->bytes_absorbed_from_eden() != 0) {
duke@435 961 size_policy()->reset_bytes_absorbed_from_eden();
duke@435 962 return; // The generation changed size already.
duke@435 963 }
duke@435 964 gens()->adjust_boundary_for_young_gen_needs(eden_size, survivor_size);
duke@435 965 }
duke@435 966
duke@435 967 // Delegate the resize to the generation.
duke@435 968 _young_gen->resize(eden_size, survivor_size);
duke@435 969 }
duke@435 970
duke@435 971 // Before delegating the resize to the old generation,
duke@435 972 // the reserved space for the young and old generations
duke@435 973 // may be changed to accomodate the desired resize.
duke@435 974 void ParallelScavengeHeap::resize_old_gen(size_t desired_free_space) {
duke@435 975 if (UseAdaptiveGCBoundary) {
duke@435 976 if (size_policy()->bytes_absorbed_from_eden() != 0) {
duke@435 977 size_policy()->reset_bytes_absorbed_from_eden();
duke@435 978 return; // The generation changed size already.
duke@435 979 }
duke@435 980 gens()->adjust_boundary_for_old_gen_needs(desired_free_space);
duke@435 981 }
duke@435 982
duke@435 983 // Delegate the resize to the generation.
duke@435 984 _old_gen->resize(desired_free_space);
duke@435 985 }
jmasa@698 986
jrose@1424 987 ParallelScavengeHeap::ParStrongRootsScope::ParStrongRootsScope() {
jrose@1424 988 // nothing particular
jrose@1424 989 }
jrose@1424 990
jrose@1424 991 ParallelScavengeHeap::ParStrongRootsScope::~ParStrongRootsScope() {
jrose@1424 992 // nothing particular
jrose@1424 993 }
jrose@1424 994
jmasa@698 995 #ifndef PRODUCT
jmasa@698 996 void ParallelScavengeHeap::record_gen_tops_before_GC() {
jmasa@698 997 if (ZapUnusedHeapArea) {
jmasa@698 998 young_gen()->record_spaces_top();
jmasa@698 999 old_gen()->record_spaces_top();
jmasa@698 1000 perm_gen()->record_spaces_top();
jmasa@698 1001 }
jmasa@698 1002 }
jmasa@698 1003
jmasa@698 1004 void ParallelScavengeHeap::gen_mangle_unused_area() {
jmasa@698 1005 if (ZapUnusedHeapArea) {
jmasa@698 1006 young_gen()->eden_space()->mangle_unused_area();
jmasa@698 1007 young_gen()->to_space()->mangle_unused_area();
jmasa@698 1008 young_gen()->from_space()->mangle_unused_area();
jmasa@698 1009 old_gen()->object_space()->mangle_unused_area();
jmasa@698 1010 perm_gen()->object_space()->mangle_unused_area();
jmasa@698 1011 }
jmasa@698 1012 }
jmasa@698 1013 #endif

mercurial