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

Fri, 01 Nov 2013 17:09:38 +0100

author
jwilhelm
date
Fri, 01 Nov 2013 17:09:38 +0100
changeset 6085
8f07aa079343
parent 5531
1a8fb39bdbc4
child 6376
cfd4aac53239
permissions
-rw-r--r--

8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
7057939: jmap shows MaxNewSize=4GB when Java is using parallel collector
Summary: Major cleanup of the collectorpolicy classes
Reviewed-by: tschatzl, jcoomes

duke@435 1 /*
sla@5237 2 * Copyright (c) 2001, 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/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"
sla@5237 38 #include "gc_implementation/shared/gcHeapSummary.hpp"
sla@5237 39 #include "gc_implementation/shared/gcWhen.hpp"
stefank@2314 40 #include "memory/gcLocker.inline.hpp"
stefank@2314 41 #include "oops/oop.inline.hpp"
stefank@2314 42 #include "runtime/handles.inline.hpp"
stefank@2314 43 #include "runtime/java.hpp"
stefank@2314 44 #include "runtime/vmThread.hpp"
zgu@3900 45 #include "services/memTracker.hpp"
stefank@2314 46 #include "utilities/vmError.hpp"
duke@435 47
duke@435 48 PSYoungGen* ParallelScavengeHeap::_young_gen = NULL;
duke@435 49 PSOldGen* ParallelScavengeHeap::_old_gen = NULL;
duke@435 50 PSAdaptiveSizePolicy* ParallelScavengeHeap::_size_policy = NULL;
duke@435 51 PSGCAdaptivePolicyCounters* ParallelScavengeHeap::_gc_policy_counters = NULL;
duke@435 52 ParallelScavengeHeap* ParallelScavengeHeap::_psh = NULL;
duke@435 53 GCTaskManager* ParallelScavengeHeap::_gc_task_manager = NULL;
duke@435 54
duke@435 55 jint ParallelScavengeHeap::initialize() {
ysr@1601 56 CollectedHeap::pre_initialize();
ysr@1601 57
jwilhelm@6085 58 // Initialize collector policy
jmasa@1822 59 _collector_policy = new GenerationSizer();
jwilhelm@6085 60 _collector_policy->initialize_all();
duke@435 61
jwilhelm@6085 62 const size_t heap_size = _collector_policy->max_heap_byte_size();
duke@435 63
jwilhelm@6085 64 ReservedSpace heap_rs = Universe::reserve_heap(heap_size, _collector_policy->heap_alignment());
zgu@3900 65 MemTracker::record_virtual_memory_type((address)heap_rs.base(), mtJavaHeap);
zgu@3900 66
jwilhelm@6085 67 os::trace_page_sizes("ps main", _collector_policy->min_heap_byte_size(),
jwilhelm@6085 68 heap_size, generation_alignment(),
coleenp@4037 69 heap_rs.base(),
coleenp@4037 70 heap_rs.size());
duke@435 71 if (!heap_rs.is_reserved()) {
duke@435 72 vm_shutdown_during_initialization(
duke@435 73 "Could not reserve enough space for object heap");
duke@435 74 return JNI_ENOMEM;
duke@435 75 }
duke@435 76
duke@435 77 _reserved = MemRegion((HeapWord*)heap_rs.base(),
duke@435 78 (HeapWord*)(heap_rs.base() + heap_rs.size()));
duke@435 79
duke@435 80 CardTableExtension* const barrier_set = new CardTableExtension(_reserved, 3);
duke@435 81 _barrier_set = barrier_set;
duke@435 82 oopDesc::set_bs(_barrier_set);
duke@435 83 if (_barrier_set == NULL) {
duke@435 84 vm_shutdown_during_initialization(
duke@435 85 "Could not reserve enough space for barrier set");
duke@435 86 return JNI_ENOMEM;
duke@435 87 }
duke@435 88
duke@435 89 // Make up the generations
duke@435 90 // Calculate the maximum size that a generation can grow. This
duke@435 91 // includes growth into the other generation. Note that the
duke@435 92 // parameter _max_gen_size is kept as the maximum
duke@435 93 // size of the generation as the boundaries currently stand.
duke@435 94 // _max_gen_size is still used as that value.
duke@435 95 double max_gc_pause_sec = ((double) MaxGCPauseMillis)/1000.0;
duke@435 96 double max_gc_minor_pause_sec = ((double) MaxGCMinorPauseMillis)/1000.0;
duke@435 97
jwilhelm@6085 98 _gens = new AdjoiningGenerations(heap_rs, _collector_policy, generation_alignment());
duke@435 99
duke@435 100 _old_gen = _gens->old_gen();
duke@435 101 _young_gen = _gens->young_gen();
duke@435 102
duke@435 103 const size_t eden_capacity = _young_gen->eden_space()->capacity_in_bytes();
duke@435 104 const size_t old_capacity = _old_gen->capacity_in_bytes();
duke@435 105 const size_t initial_promo_size = MIN2(eden_capacity, old_capacity);
duke@435 106 _size_policy =
duke@435 107 new PSAdaptiveSizePolicy(eden_capacity,
duke@435 108 initial_promo_size,
duke@435 109 young_gen()->to_space()->capacity_in_bytes(),
jwilhelm@6085 110 _collector_policy->gen_alignment(),
duke@435 111 max_gc_pause_sec,
duke@435 112 max_gc_minor_pause_sec,
duke@435 113 GCTimeRatio
duke@435 114 );
duke@435 115
duke@435 116 assert(!UseAdaptiveGCBoundary ||
duke@435 117 (old_gen()->virtual_space()->high_boundary() ==
duke@435 118 young_gen()->virtual_space()->low_boundary()),
duke@435 119 "Boundaries must meet");
duke@435 120 // initialize the policy counters - 2 collectors, 3 generations
duke@435 121 _gc_policy_counters =
duke@435 122 new PSGCAdaptivePolicyCounters("ParScav:MSC", 2, 3, _size_policy);
duke@435 123 _psh = this;
duke@435 124
duke@435 125 // Set up the GCTaskManager
duke@435 126 _gc_task_manager = GCTaskManager::create(ParallelGCThreads);
duke@435 127
duke@435 128 if (UseParallelOldGC && !PSParallelCompact::initialize()) {
duke@435 129 return JNI_ENOMEM;
duke@435 130 }
duke@435 131
duke@435 132 return JNI_OK;
duke@435 133 }
duke@435 134
duke@435 135 void ParallelScavengeHeap::post_initialize() {
duke@435 136 // Need to init the tenuring threshold
duke@435 137 PSScavenge::initialize();
duke@435 138 if (UseParallelOldGC) {
duke@435 139 PSParallelCompact::post_initialize();
duke@435 140 } else {
duke@435 141 PSMarkSweep::initialize();
duke@435 142 }
duke@435 143 PSPromotionManager::initialize();
duke@435 144 }
duke@435 145
duke@435 146 void ParallelScavengeHeap::update_counters() {
duke@435 147 young_gen()->update_counters();
duke@435 148 old_gen()->update_counters();
coleenp@4037 149 MetaspaceCounters::update_performance_counters();
ehelin@5531 150 CompressedClassSpaceCounters::update_performance_counters();
duke@435 151 }
duke@435 152
duke@435 153 size_t ParallelScavengeHeap::capacity() const {
duke@435 154 size_t value = young_gen()->capacity_in_bytes() + old_gen()->capacity_in_bytes();
duke@435 155 return value;
duke@435 156 }
duke@435 157
duke@435 158 size_t ParallelScavengeHeap::used() const {
duke@435 159 size_t value = young_gen()->used_in_bytes() + old_gen()->used_in_bytes();
duke@435 160 return value;
duke@435 161 }
duke@435 162
duke@435 163 bool ParallelScavengeHeap::is_maximal_no_gc() const {
duke@435 164 return old_gen()->is_maximal_no_gc() && young_gen()->is_maximal_no_gc();
duke@435 165 }
duke@435 166
duke@435 167
duke@435 168 size_t ParallelScavengeHeap::max_capacity() const {
duke@435 169 size_t estimated = reserved_region().byte_size();
duke@435 170 if (UseAdaptiveSizePolicy) {
duke@435 171 estimated -= _size_policy->max_survivor_size(young_gen()->max_size());
duke@435 172 } else {
duke@435 173 estimated -= young_gen()->to_space()->capacity_in_bytes();
duke@435 174 }
duke@435 175 return MAX2(estimated, capacity());
duke@435 176 }
duke@435 177
duke@435 178 bool ParallelScavengeHeap::is_in(const void* p) const {
duke@435 179 if (young_gen()->is_in(p)) {
duke@435 180 return true;
duke@435 181 }
duke@435 182
duke@435 183 if (old_gen()->is_in(p)) {
duke@435 184 return true;
duke@435 185 }
duke@435 186
duke@435 187 return false;
duke@435 188 }
duke@435 189
duke@435 190 bool ParallelScavengeHeap::is_in_reserved(const void* p) const {
duke@435 191 if (young_gen()->is_in_reserved(p)) {
duke@435 192 return true;
duke@435 193 }
duke@435 194
duke@435 195 if (old_gen()->is_in_reserved(p)) {
duke@435 196 return true;
duke@435 197 }
duke@435 198
duke@435 199 return false;
duke@435 200 }
duke@435 201
jmasa@2909 202 bool ParallelScavengeHeap::is_scavengable(const void* addr) {
jmasa@2909 203 return is_in_young((oop)addr);
jmasa@2909 204 }
jmasa@2909 205
jmasa@2909 206 #ifdef ASSERT
jmasa@2909 207 // Don't implement this by using is_in_young(). This method is used
jmasa@2909 208 // in some cases to check that is_in_young() is correct.
jmasa@2909 209 bool ParallelScavengeHeap::is_in_partial_collection(const void *p) {
jmasa@2909 210 assert(is_in_reserved(p) || p == NULL,
jmasa@2909 211 "Does not work if address is non-null and outside of the heap");
coleenp@4037 212 // The order of the generations is old (low addr), young (high addr)
jmasa@2909 213 return p >= old_gen()->reserved().end();
jmasa@2909 214 }
jmasa@2909 215 #endif
jmasa@2909 216
duke@435 217 // There are two levels of allocation policy here.
duke@435 218 //
duke@435 219 // When an allocation request fails, the requesting thread must invoke a VM
duke@435 220 // operation, transfer control to the VM thread, and await the results of a
duke@435 221 // garbage collection. That is quite expensive, and we should avoid doing it
duke@435 222 // multiple times if possible.
duke@435 223 //
duke@435 224 // To accomplish this, we have a basic allocation policy, and also a
duke@435 225 // failed allocation policy.
duke@435 226 //
duke@435 227 // The basic allocation policy controls how you allocate memory without
duke@435 228 // attempting garbage collection. It is okay to grab locks and
duke@435 229 // expand the heap, if that can be done without coming to a safepoint.
duke@435 230 // It is likely that the basic allocation policy will not be very
duke@435 231 // aggressive.
duke@435 232 //
duke@435 233 // The failed allocation policy is invoked from the VM thread after
duke@435 234 // the basic allocation policy is unable to satisfy a mem_allocate
duke@435 235 // request. This policy needs to cover the entire range of collection,
duke@435 236 // heap expansion, and out-of-memory conditions. It should make every
duke@435 237 // attempt to allocate the requested memory.
duke@435 238
duke@435 239 // Basic allocation policy. Should never be called at a safepoint, or
duke@435 240 // from the VM thread.
duke@435 241 //
duke@435 242 // This method must handle cases where many mem_allocate requests fail
duke@435 243 // simultaneously. When that happens, only one VM operation will succeed,
duke@435 244 // and the rest will not be executed. For that reason, this method loops
duke@435 245 // during failed allocation attempts. If the java heap becomes exhausted,
duke@435 246 // we rely on the size_policy object to force a bail out.
duke@435 247 HeapWord* ParallelScavengeHeap::mem_allocate(
duke@435 248 size_t size,
duke@435 249 bool* gc_overhead_limit_was_exceeded) {
duke@435 250 assert(!SafepointSynchronize::is_at_safepoint(), "should not be at safepoint");
duke@435 251 assert(Thread::current() != (Thread*)VMThread::vm_thread(), "should not be in vm thread");
duke@435 252 assert(!Heap_lock->owned_by_self(), "this thread should not own the Heap_lock");
duke@435 253
jmasa@1822 254 // In general gc_overhead_limit_was_exceeded should be false so
jmasa@1822 255 // set it so here and reset it to true only if the gc time
jmasa@1822 256 // limit is being exceeded as checked below.
jmasa@1822 257 *gc_overhead_limit_was_exceeded = false;
jmasa@1822 258
tonyp@2971 259 HeapWord* result = young_gen()->allocate(size);
duke@435 260
duke@435 261 uint loop_count = 0;
duke@435 262 uint gc_count = 0;
mgerdin@4853 263 int gclocker_stalled_count = 0;
duke@435 264
duke@435 265 while (result == NULL) {
duke@435 266 // We don't want to have multiple collections for a single filled generation.
duke@435 267 // To prevent this, each thread tracks the total_collections() value, and if
duke@435 268 // the count has changed, does not do a new collection.
duke@435 269 //
duke@435 270 // The collection count must be read only while holding the heap lock. VM
duke@435 271 // operations also hold the heap lock during collections. There is a lock
duke@435 272 // contention case where thread A blocks waiting on the Heap_lock, while
duke@435 273 // thread B is holding it doing a collection. When thread A gets the lock,
duke@435 274 // the collection count has already changed. To prevent duplicate collections,
duke@435 275 // The policy MUST attempt allocations during the same period it reads the
duke@435 276 // total_collections() value!
duke@435 277 {
duke@435 278 MutexLocker ml(Heap_lock);
duke@435 279 gc_count = Universe::heap()->total_collections();
duke@435 280
tonyp@2971 281 result = young_gen()->allocate(size);
duke@435 282 if (result != NULL) {
duke@435 283 return result;
duke@435 284 }
jcoomes@3541 285
jcoomes@3541 286 // If certain conditions hold, try allocating from the old gen.
jcoomes@3541 287 result = mem_allocate_old_gen(size);
jcoomes@3541 288 if (result != NULL) {
jcoomes@3541 289 return result;
duke@435 290 }
jcoomes@3541 291
mgerdin@4853 292 if (gclocker_stalled_count > GCLockerRetryAllocationCount) {
mgerdin@4853 293 return NULL;
mgerdin@4853 294 }
mgerdin@4853 295
jcoomes@3541 296 // Failed to allocate without a gc.
duke@435 297 if (GC_locker::is_active_and_needs_gc()) {
duke@435 298 // If this thread is not in a jni critical section, we stall
duke@435 299 // the requestor until the critical section has cleared and
duke@435 300 // GC allowed. When the critical section clears, a GC is
duke@435 301 // initiated by the last thread exiting the critical section; so
duke@435 302 // we retry the allocation sequence from the beginning of the loop,
duke@435 303 // rather than causing more, now probably unnecessary, GC attempts.
duke@435 304 JavaThread* jthr = JavaThread::current();
duke@435 305 if (!jthr->in_critical()) {
duke@435 306 MutexUnlocker mul(Heap_lock);
duke@435 307 GC_locker::stall_until_clear();
mgerdin@4853 308 gclocker_stalled_count += 1;
duke@435 309 continue;
duke@435 310 } else {
duke@435 311 if (CheckJNICalls) {
duke@435 312 fatal("Possible deadlock due to allocating while"
duke@435 313 " in jni critical section");
duke@435 314 }
duke@435 315 return NULL;
duke@435 316 }
duke@435 317 }
duke@435 318 }
duke@435 319
duke@435 320 if (result == NULL) {
duke@435 321 // Generate a VM operation
tonyp@2971 322 VM_ParallelGCFailedAllocation op(size, gc_count);
duke@435 323 VMThread::execute(&op);
duke@435 324
duke@435 325 // Did the VM operation execute? If so, return the result directly.
duke@435 326 // This prevents us from looping until time out on requests that can
duke@435 327 // not be satisfied.
duke@435 328 if (op.prologue_succeeded()) {
duke@435 329 assert(Universe::heap()->is_in_or_null(op.result()),
duke@435 330 "result not in heap");
duke@435 331
duke@435 332 // If GC was locked out during VM operation then retry allocation
duke@435 333 // and/or stall as necessary.
duke@435 334 if (op.gc_locked()) {
duke@435 335 assert(op.result() == NULL, "must be NULL if gc_locked() is true");
duke@435 336 continue; // retry and/or stall as necessary
duke@435 337 }
jmasa@1822 338
jmasa@1822 339 // Exit the loop if the gc time limit has been exceeded.
jmasa@1822 340 // The allocation must have failed above ("result" guarding
jmasa@1822 341 // this path is NULL) and the most recent collection has exceeded the
jmasa@1822 342 // gc overhead limit (although enough may have been collected to
jmasa@1822 343 // satisfy the allocation). Exit the loop so that an out-of-memory
jmasa@1822 344 // will be thrown (return a NULL ignoring the contents of
jmasa@1822 345 // op.result()),
jmasa@1822 346 // but clear gc_overhead_limit_exceeded so that the next collection
jmasa@1822 347 // starts with a clean slate (i.e., forgets about previous overhead
jmasa@1822 348 // excesses). Fill op.result() with a filler object so that the
jmasa@1822 349 // heap remains parsable.
jmasa@1822 350 const bool limit_exceeded = size_policy()->gc_overhead_limit_exceeded();
jmasa@1822 351 const bool softrefs_clear = collector_policy()->all_soft_refs_clear();
jmasa@4743 352
jmasa@1822 353 if (limit_exceeded && softrefs_clear) {
jmasa@1822 354 *gc_overhead_limit_was_exceeded = true;
jmasa@1822 355 size_policy()->set_gc_overhead_limit_exceeded(false);
jmasa@1822 356 if (PrintGCDetails && Verbose) {
jmasa@1822 357 gclog_or_tty->print_cr("ParallelScavengeHeap::mem_allocate: "
jmasa@1822 358 "return NULL because gc_overhead_limit_exceeded is set");
jmasa@1822 359 }
jmasa@1822 360 if (op.result() != NULL) {
jmasa@1822 361 CollectedHeap::fill_with_object(op.result(), size);
jmasa@1822 362 }
jmasa@1822 363 return NULL;
duke@435 364 }
jmasa@1822 365
duke@435 366 return op.result();
duke@435 367 }
duke@435 368 }
duke@435 369
duke@435 370 // The policy object will prevent us from looping forever. If the
duke@435 371 // time spent in gc crosses a threshold, we will bail out.
duke@435 372 loop_count++;
duke@435 373 if ((result == NULL) && (QueuedAllocationWarningCount > 0) &&
duke@435 374 (loop_count % QueuedAllocationWarningCount == 0)) {
duke@435 375 warning("ParallelScavengeHeap::mem_allocate retries %d times \n\t"
tonyp@2971 376 " size=%d", loop_count, size);
duke@435 377 }
duke@435 378 }
duke@435 379
duke@435 380 return result;
duke@435 381 }
duke@435 382
jcoomes@3541 383 // A "death march" is a series of ultra-slow allocations in which a full gc is
jcoomes@3541 384 // done before each allocation, and after the full gc the allocation still
jcoomes@3541 385 // cannot be satisfied from the young gen. This routine detects that condition;
jcoomes@3541 386 // it should be called after a full gc has been done and the allocation
jcoomes@3541 387 // attempted from the young gen. The parameter 'addr' should be the result of
jcoomes@3541 388 // that young gen allocation attempt.
jcoomes@3541 389 void
jcoomes@3541 390 ParallelScavengeHeap::death_march_check(HeapWord* const addr, size_t size) {
jcoomes@3541 391 if (addr != NULL) {
jcoomes@3541 392 _death_march_count = 0; // death march has ended
jcoomes@3541 393 } else if (_death_march_count == 0) {
jcoomes@3541 394 if (should_alloc_in_eden(size)) {
jcoomes@3541 395 _death_march_count = 1; // death march has started
jcoomes@3541 396 }
jcoomes@3541 397 }
jcoomes@3541 398 }
jcoomes@3541 399
jcoomes@3541 400 HeapWord* ParallelScavengeHeap::mem_allocate_old_gen(size_t size) {
jcoomes@3541 401 if (!should_alloc_in_eden(size) || GC_locker::is_active_and_needs_gc()) {
jcoomes@3541 402 // Size is too big for eden, or gc is locked out.
jcoomes@3541 403 return old_gen()->allocate(size);
jcoomes@3541 404 }
jcoomes@3541 405
jcoomes@3541 406 // If a "death march" is in progress, allocate from the old gen a limited
jcoomes@3541 407 // number of times before doing a GC.
jcoomes@3541 408 if (_death_march_count > 0) {
jcoomes@3541 409 if (_death_march_count < 64) {
jcoomes@3541 410 ++_death_march_count;
jcoomes@3541 411 return old_gen()->allocate(size);
jcoomes@3541 412 } else {
jcoomes@3541 413 _death_march_count = 0;
jcoomes@3541 414 }
jcoomes@3541 415 }
jcoomes@3541 416 return NULL;
jcoomes@3541 417 }
jcoomes@3541 418
coleenp@4037 419 void ParallelScavengeHeap::do_full_collection(bool clear_all_soft_refs) {
coleenp@4037 420 if (UseParallelOldGC) {
coleenp@4037 421 // The do_full_collection() parameter clear_all_soft_refs
coleenp@4037 422 // is interpreted here as maximum_compaction which will
coleenp@4037 423 // cause SoftRefs to be cleared.
coleenp@4037 424 bool maximum_compaction = clear_all_soft_refs;
coleenp@4037 425 PSParallelCompact::invoke(maximum_compaction);
coleenp@4037 426 } else {
coleenp@4037 427 PSMarkSweep::invoke(clear_all_soft_refs);
coleenp@4037 428 }
coleenp@4037 429 }
coleenp@4037 430
duke@435 431 // Failed allocation policy. Must be called from the VM thread, and
duke@435 432 // only at a safepoint! Note that this method has policy for allocation
duke@435 433 // flow, and NOT collection policy. So we do not check for gc collection
duke@435 434 // time over limit here, that is the responsibility of the heap specific
duke@435 435 // collection methods. This method decides where to attempt allocations,
duke@435 436 // and when to attempt collections, but no collection specific policy.
tonyp@2971 437 HeapWord* ParallelScavengeHeap::failed_mem_allocate(size_t size) {
duke@435 438 assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint");
duke@435 439 assert(Thread::current() == (Thread*)VMThread::vm_thread(), "should be in vm thread");
duke@435 440 assert(!Universe::heap()->is_gc_active(), "not reentrant");
duke@435 441 assert(!Heap_lock->owned_by_self(), "this thread should not own the Heap_lock");
duke@435 442
jcoomes@3541 443 // We assume that allocation in eden will fail unless we collect.
duke@435 444
duke@435 445 // First level allocation failure, scavenge and allocate in young gen.
duke@435 446 GCCauseSetter gccs(this, GCCause::_allocation_failure);
jcoomes@3541 447 const bool invoked_full_gc = PSScavenge::invoke();
tonyp@2971 448 HeapWord* result = young_gen()->allocate(size);
duke@435 449
duke@435 450 // Second level allocation failure.
duke@435 451 // Mark sweep and allocate in young generation.
jcoomes@3541 452 if (result == NULL && !invoked_full_gc) {
coleenp@4037 453 do_full_collection(false);
jcoomes@3541 454 result = young_gen()->allocate(size);
duke@435 455 }
duke@435 456
jcoomes@3541 457 death_march_check(result, size);
jcoomes@3541 458
duke@435 459 // Third level allocation failure.
duke@435 460 // After mark sweep and young generation allocation failure,
duke@435 461 // allocate in old generation.
tonyp@2971 462 if (result == NULL) {
tonyp@2971 463 result = old_gen()->allocate(size);
duke@435 464 }
duke@435 465
duke@435 466 // Fourth level allocation failure. We're running out of memory.
duke@435 467 // More complete mark sweep and allocate in young generation.
duke@435 468 if (result == NULL) {
coleenp@4037 469 do_full_collection(true);
tonyp@2971 470 result = young_gen()->allocate(size);
duke@435 471 }
duke@435 472
duke@435 473 // Fifth level allocation failure.
duke@435 474 // After more complete mark sweep, allocate in old generation.
tonyp@2971 475 if (result == NULL) {
tonyp@2971 476 result = old_gen()->allocate(size);
duke@435 477 }
duke@435 478
duke@435 479 return result;
duke@435 480 }
duke@435 481
duke@435 482 void ParallelScavengeHeap::ensure_parsability(bool retire_tlabs) {
duke@435 483 CollectedHeap::ensure_parsability(retire_tlabs);
duke@435 484 young_gen()->eden_space()->ensure_parsability();
duke@435 485 }
duke@435 486
duke@435 487 size_t ParallelScavengeHeap::unsafe_max_alloc() {
duke@435 488 return young_gen()->eden_space()->free_in_bytes();
duke@435 489 }
duke@435 490
duke@435 491 size_t ParallelScavengeHeap::tlab_capacity(Thread* thr) const {
duke@435 492 return young_gen()->eden_space()->tlab_capacity(thr);
duke@435 493 }
duke@435 494
duke@435 495 size_t ParallelScavengeHeap::unsafe_max_tlab_alloc(Thread* thr) const {
duke@435 496 return young_gen()->eden_space()->unsafe_max_tlab_alloc(thr);
duke@435 497 }
duke@435 498
duke@435 499 HeapWord* ParallelScavengeHeap::allocate_new_tlab(size_t size) {
tonyp@2971 500 return young_gen()->allocate(size);
duke@435 501 }
duke@435 502
duke@435 503 void ParallelScavengeHeap::accumulate_statistics_all_tlabs() {
duke@435 504 CollectedHeap::accumulate_statistics_all_tlabs();
duke@435 505 }
duke@435 506
duke@435 507 void ParallelScavengeHeap::resize_all_tlabs() {
duke@435 508 CollectedHeap::resize_all_tlabs();
duke@435 509 }
duke@435 510
ysr@1462 511 bool ParallelScavengeHeap::can_elide_initializing_store_barrier(oop new_obj) {
ysr@1462 512 // We don't need barriers for stores to objects in the
ysr@1462 513 // young gen and, a fortiori, for initializing stores to
ysr@1462 514 // objects therein.
ysr@1462 515 return is_in_young(new_obj);
ysr@1462 516 }
ysr@1462 517
duke@435 518 // This method is used by System.gc() and JVMTI.
duke@435 519 void ParallelScavengeHeap::collect(GCCause::Cause cause) {
duke@435 520 assert(!Heap_lock->owned_by_self(),
duke@435 521 "this thread should not own the Heap_lock");
duke@435 522
duke@435 523 unsigned int gc_count = 0;
duke@435 524 unsigned int full_gc_count = 0;
duke@435 525 {
duke@435 526 MutexLocker ml(Heap_lock);
duke@435 527 // This value is guarded by the Heap_lock
duke@435 528 gc_count = Universe::heap()->total_collections();
duke@435 529 full_gc_count = Universe::heap()->total_full_collections();
duke@435 530 }
duke@435 531
duke@435 532 VM_ParallelGCSystemGC op(gc_count, full_gc_count, cause);
duke@435 533 VMThread::execute(&op);
duke@435 534 }
duke@435 535
coleenp@4037 536 void ParallelScavengeHeap::oop_iterate(ExtendedOopClosure* cl) {
duke@435 537 Unimplemented();
duke@435 538 }
duke@435 539
duke@435 540 void ParallelScavengeHeap::object_iterate(ObjectClosure* cl) {
duke@435 541 young_gen()->object_iterate(cl);
duke@435 542 old_gen()->object_iterate(cl);
duke@435 543 }
duke@435 544
duke@435 545
duke@435 546 HeapWord* ParallelScavengeHeap::block_start(const void* addr) const {
duke@435 547 if (young_gen()->is_in_reserved(addr)) {
duke@435 548 assert(young_gen()->is_in(addr),
duke@435 549 "addr should be in allocated part of young gen");
never@2262 550 // called from os::print_location by find or VMError
never@2262 551 if (Debugging || VMError::fatal_error_in_progress()) return NULL;
duke@435 552 Unimplemented();
duke@435 553 } else if (old_gen()->is_in_reserved(addr)) {
duke@435 554 assert(old_gen()->is_in(addr),
duke@435 555 "addr should be in allocated part of old gen");
duke@435 556 return old_gen()->start_array()->object_start((HeapWord*)addr);
duke@435 557 }
duke@435 558 return 0;
duke@435 559 }
duke@435 560
duke@435 561 size_t ParallelScavengeHeap::block_size(const HeapWord* addr) const {
duke@435 562 return oop(addr)->size();
duke@435 563 }
duke@435 564
duke@435 565 bool ParallelScavengeHeap::block_is_obj(const HeapWord* addr) const {
duke@435 566 return block_start(addr) == addr;
duke@435 567 }
duke@435 568
duke@435 569 jlong ParallelScavengeHeap::millis_since_last_gc() {
duke@435 570 return UseParallelOldGC ?
duke@435 571 PSParallelCompact::millis_since_last_gc() :
duke@435 572 PSMarkSweep::millis_since_last_gc();
duke@435 573 }
duke@435 574
duke@435 575 void ParallelScavengeHeap::prepare_for_verify() {
duke@435 576 ensure_parsability(false); // no need to retire TLABs for verification
duke@435 577 }
duke@435 578
sla@5237 579 PSHeapSummary ParallelScavengeHeap::create_ps_heap_summary() {
sla@5237 580 PSOldGen* old = old_gen();
sla@5237 581 HeapWord* old_committed_end = (HeapWord*)old->virtual_space()->committed_high_addr();
sla@5237 582 VirtualSpaceSummary old_summary(old->reserved().start(), old_committed_end, old->reserved().end());
sla@5237 583 SpaceSummary old_space(old->reserved().start(), old_committed_end, old->used_in_bytes());
sla@5237 584
sla@5237 585 PSYoungGen* young = young_gen();
sla@5237 586 VirtualSpaceSummary young_summary(young->reserved().start(),
sla@5237 587 (HeapWord*)young->virtual_space()->committed_high_addr(), young->reserved().end());
sla@5237 588
sla@5237 589 MutableSpace* eden = young_gen()->eden_space();
sla@5237 590 SpaceSummary eden_space(eden->bottom(), eden->end(), eden->used_in_bytes());
sla@5237 591
sla@5237 592 MutableSpace* from = young_gen()->from_space();
sla@5237 593 SpaceSummary from_space(from->bottom(), from->end(), from->used_in_bytes());
sla@5237 594
sla@5237 595 MutableSpace* to = young_gen()->to_space();
sla@5237 596 SpaceSummary to_space(to->bottom(), to->end(), to->used_in_bytes());
sla@5237 597
sla@5237 598 VirtualSpaceSummary heap_summary = create_heap_space_summary();
sla@5237 599 return PSHeapSummary(heap_summary, used(), old_summary, old_space, young_summary, eden_space, from_space, to_space);
sla@5237 600 }
sla@5237 601
duke@435 602 void ParallelScavengeHeap::print_on(outputStream* st) const {
duke@435 603 young_gen()->print_on(st);
duke@435 604 old_gen()->print_on(st);
coleenp@4037 605 MetaspaceAux::print_on(st);
duke@435 606 }
duke@435 607
stefank@4904 608 void ParallelScavengeHeap::print_on_error(outputStream* st) const {
stefank@4904 609 this->CollectedHeap::print_on_error(st);
stefank@4904 610
stefank@4904 611 if (UseParallelOldGC) {
stefank@4904 612 st->cr();
stefank@4904 613 PSParallelCompact::print_on_error(st);
stefank@4904 614 }
stefank@4904 615 }
stefank@4904 616
duke@435 617 void ParallelScavengeHeap::gc_threads_do(ThreadClosure* tc) const {
duke@435 618 PSScavenge::gc_task_manager()->threads_do(tc);
duke@435 619 }
duke@435 620
duke@435 621 void ParallelScavengeHeap::print_gc_threads_on(outputStream* st) const {
duke@435 622 PSScavenge::gc_task_manager()->print_threads_on(st);
duke@435 623 }
duke@435 624
duke@435 625 void ParallelScavengeHeap::print_tracing_info() const {
duke@435 626 if (TraceGen0Time) {
duke@435 627 double time = PSScavenge::accumulated_time()->seconds();
duke@435 628 tty->print_cr("[Accumulated GC generation 0 time %3.7f secs]", time);
duke@435 629 }
duke@435 630 if (TraceGen1Time) {
tschatzl@4785 631 double time = UseParallelOldGC ? PSParallelCompact::accumulated_time()->seconds() : PSMarkSweep::accumulated_time()->seconds();
duke@435 632 tty->print_cr("[Accumulated GC generation 1 time %3.7f secs]", time);
duke@435 633 }
duke@435 634 }
duke@435 635
duke@435 636
brutisso@3711 637 void ParallelScavengeHeap::verify(bool silent, VerifyOption option /* ignored */) {
duke@435 638 // Why do we need the total_collections()-filter below?
duke@435 639 if (total_collections() > 0) {
duke@435 640 if (!silent) {
duke@435 641 gclog_or_tty->print("tenured ");
duke@435 642 }
brutisso@3711 643 old_gen()->verify();
duke@435 644
duke@435 645 if (!silent) {
duke@435 646 gclog_or_tty->print("eden ");
duke@435 647 }
brutisso@3711 648 young_gen()->verify();
duke@435 649 }
duke@435 650 }
duke@435 651
duke@435 652 void ParallelScavengeHeap::print_heap_change(size_t prev_used) {
duke@435 653 if (PrintGCDetails && Verbose) {
duke@435 654 gclog_or_tty->print(" " SIZE_FORMAT
duke@435 655 "->" SIZE_FORMAT
duke@435 656 "(" SIZE_FORMAT ")",
duke@435 657 prev_used, used(), capacity());
duke@435 658 } else {
duke@435 659 gclog_or_tty->print(" " SIZE_FORMAT "K"
duke@435 660 "->" SIZE_FORMAT "K"
duke@435 661 "(" SIZE_FORMAT "K)",
duke@435 662 prev_used / K, used() / K, capacity() / K);
duke@435 663 }
duke@435 664 }
duke@435 665
sla@5237 666 void ParallelScavengeHeap::trace_heap(GCWhen::Type when, GCTracer* gc_tracer) {
sla@5237 667 const PSHeapSummary& heap_summary = create_ps_heap_summary();
sla@5237 668 const MetaspaceSummary& metaspace_summary = create_metaspace_summary();
sla@5237 669 gc_tracer->report_gc_heap_summary(when, heap_summary, metaspace_summary);
sla@5237 670 }
sla@5237 671
duke@435 672 ParallelScavengeHeap* ParallelScavengeHeap::heap() {
duke@435 673 assert(_psh != NULL, "Uninitialized access to ParallelScavengeHeap::heap()");
duke@435 674 assert(_psh->kind() == CollectedHeap::ParallelScavengeHeap, "not a parallel scavenge heap");
duke@435 675 return _psh;
duke@435 676 }
duke@435 677
duke@435 678 // Before delegating the resize to the young generation,
duke@435 679 // the reserved space for the young and old generations
duke@435 680 // may be changed to accomodate the desired resize.
duke@435 681 void ParallelScavengeHeap::resize_young_gen(size_t eden_size,
duke@435 682 size_t survivor_size) {
duke@435 683 if (UseAdaptiveGCBoundary) {
duke@435 684 if (size_policy()->bytes_absorbed_from_eden() != 0) {
duke@435 685 size_policy()->reset_bytes_absorbed_from_eden();
duke@435 686 return; // The generation changed size already.
duke@435 687 }
duke@435 688 gens()->adjust_boundary_for_young_gen_needs(eden_size, survivor_size);
duke@435 689 }
duke@435 690
duke@435 691 // Delegate the resize to the generation.
duke@435 692 _young_gen->resize(eden_size, survivor_size);
duke@435 693 }
duke@435 694
duke@435 695 // Before delegating the resize to the old generation,
duke@435 696 // the reserved space for the young and old generations
duke@435 697 // may be changed to accomodate the desired resize.
duke@435 698 void ParallelScavengeHeap::resize_old_gen(size_t desired_free_space) {
duke@435 699 if (UseAdaptiveGCBoundary) {
duke@435 700 if (size_policy()->bytes_absorbed_from_eden() != 0) {
duke@435 701 size_policy()->reset_bytes_absorbed_from_eden();
duke@435 702 return; // The generation changed size already.
duke@435 703 }
duke@435 704 gens()->adjust_boundary_for_old_gen_needs(desired_free_space);
duke@435 705 }
duke@435 706
duke@435 707 // Delegate the resize to the generation.
duke@435 708 _old_gen->resize(desired_free_space);
duke@435 709 }
jmasa@698 710
jrose@1424 711 ParallelScavengeHeap::ParStrongRootsScope::ParStrongRootsScope() {
jrose@1424 712 // nothing particular
jrose@1424 713 }
jrose@1424 714
jrose@1424 715 ParallelScavengeHeap::ParStrongRootsScope::~ParStrongRootsScope() {
jrose@1424 716 // nothing particular
jrose@1424 717 }
jrose@1424 718
jmasa@698 719 #ifndef PRODUCT
jmasa@698 720 void ParallelScavengeHeap::record_gen_tops_before_GC() {
jmasa@698 721 if (ZapUnusedHeapArea) {
jmasa@698 722 young_gen()->record_spaces_top();
jmasa@698 723 old_gen()->record_spaces_top();
jmasa@698 724 }
jmasa@698 725 }
jmasa@698 726
jmasa@698 727 void ParallelScavengeHeap::gen_mangle_unused_area() {
jmasa@698 728 if (ZapUnusedHeapArea) {
jmasa@698 729 young_gen()->eden_space()->mangle_unused_area();
jmasa@698 730 young_gen()->to_space()->mangle_unused_area();
jmasa@698 731 young_gen()->from_space()->mangle_unused_area();
jmasa@698 732 old_gen()->object_space()->mangle_unused_area();
jmasa@698 733 }
jmasa@698 734 }
jmasa@698 735 #endif

mercurial