6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit

Ensure a full GC that clears SoftReferences before throwing an out-of-memory

Reviewed-by: ysr, jcoomes
This commit is contained in:
Jon Masamitsu 2010-04-13 13:52:10 -07:00
parent ba815bf09e
commit f5197d0d36
26 changed files with 543 additions and 364 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2002-2010 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -187,8 +187,7 @@ void PSRefProcTaskExecutor::execute(EnqueueTask& task)
//
// Note that this method should only be called from the vm_thread while
// at a safepoint!
void PSScavenge::invoke()
{
void PSScavenge::invoke() {
assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint");
assert(Thread::current() == (Thread*)VMThread::vm_thread(), "should be in vm thread");
assert(!Universe::heap()->is_gc_active(), "not reentrant");
@ -197,29 +196,25 @@ void PSScavenge::invoke()
assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
PSAdaptiveSizePolicy* policy = heap->size_policy();
IsGCActiveMark mark;
// Before each allocation/collection attempt, find out from the
// policy object if GCs are, on the whole, taking too long. If so,
// bail out without attempting a collection.
if (!policy->gc_time_limit_exceeded()) {
IsGCActiveMark mark;
bool scavenge_was_done = PSScavenge::invoke_no_policy();
bool scavenge_was_done = PSScavenge::invoke_no_policy();
PSGCAdaptivePolicyCounters* counters = heap->gc_policy_counters();
PSGCAdaptivePolicyCounters* counters = heap->gc_policy_counters();
if (UsePerfData)
counters->update_full_follows_scavenge(0);
if (!scavenge_was_done ||
policy->should_full_GC(heap->old_gen()->free_in_bytes())) {
if (UsePerfData)
counters->update_full_follows_scavenge(0);
if (!scavenge_was_done ||
policy->should_full_GC(heap->old_gen()->free_in_bytes())) {
if (UsePerfData)
counters->update_full_follows_scavenge(full_follows_scavenge);
counters->update_full_follows_scavenge(full_follows_scavenge);
GCCauseSetter gccs(heap, GCCause::_adaptive_size_policy);
CollectorPolicy* cp = heap->collector_policy();
const bool clear_all_softrefs = cp->should_clear_all_soft_refs();
GCCauseSetter gccs(heap, GCCause::_adaptive_size_policy);
if (UseParallelOldGC) {
PSParallelCompact::invoke_no_policy(false);
} else {
PSMarkSweep::invoke_no_policy(false);
}
if (UseParallelOldGC) {
PSParallelCompact::invoke_no_policy(clear_all_softrefs);
} else {
PSMarkSweep::invoke_no_policy(clear_all_softrefs);
}
}
}
@ -447,6 +442,9 @@ bool PSScavenge::invoke_no_policy() {
size_t promoted = old_gen->used_in_bytes() - old_gen_used_before;
size_policy->update_averages(_survivor_overflow, survived, promoted);
// A successful scavenge should restart the GC time limit count which is
// for full GC's.
size_policy->reset_gc_overhead_limit_count();
if (UseAdaptiveSizePolicy) {
// Calculate the new survivor size and tenuring threshold
@ -523,7 +521,8 @@ bool PSScavenge::invoke_no_policy() {
old_gen->max_gen_size(),
max_eden_size,
false /* full gc*/,
gc_cause);
gc_cause,
heap->collector_policy());
}
// Resize the young generation at every collection