Mercurial > hg > truffle
comparison src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.cpp @ 1387:0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
Summary: Ensure a full GC that clears SoftReferences before throwing an out-of-memory
Reviewed-by: ysr, jcoomes
author | jmasa |
---|---|
date | Tue, 13 Apr 2010 13:52:10 -0700 |
parents | 2a1472c30599 |
children | cff162798819 |
comparison
equal
deleted
inserted
replaced
1361:6b73e879f1c2 | 1387:0bfd3fb24150 |
---|---|
1 /* | 1 /* |
2 * Copyright 2005-2009 Sun Microsystems, Inc. All Rights Reserved. | 2 * Copyright 2005-2010 Sun Microsystems, Inc. All Rights Reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
1921 // will do nothing further. If we need to bail out for policy reasons, scavenge | 1921 // will do nothing further. If we need to bail out for policy reasons, scavenge |
1922 // before full gc, or any other specialized behavior, it needs to be added here. | 1922 // before full gc, or any other specialized behavior, it needs to be added here. |
1923 // | 1923 // |
1924 // Note that this method should only be called from the vm_thread while at a | 1924 // Note that this method should only be called from the vm_thread while at a |
1925 // safepoint. | 1925 // safepoint. |
1926 // | |
1927 // Note that the all_soft_refs_clear flag in the collector policy | |
1928 // may be true because this method can be called without intervening | |
1929 // activity. For example when the heap space is tight and full measure | |
1930 // are being taken to free space. | |
1926 void PSParallelCompact::invoke(bool maximum_heap_compaction) { | 1931 void PSParallelCompact::invoke(bool maximum_heap_compaction) { |
1927 assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint"); | 1932 assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint"); |
1928 assert(Thread::current() == (Thread*)VMThread::vm_thread(), | 1933 assert(Thread::current() == (Thread*)VMThread::vm_thread(), |
1929 "should be in vm thread"); | 1934 "should be in vm thread"); |
1935 | |
1930 ParallelScavengeHeap* heap = gc_heap(); | 1936 ParallelScavengeHeap* heap = gc_heap(); |
1931 GCCause::Cause gc_cause = heap->gc_cause(); | 1937 GCCause::Cause gc_cause = heap->gc_cause(); |
1932 assert(!heap->is_gc_active(), "not reentrant"); | 1938 assert(!heap->is_gc_active(), "not reentrant"); |
1933 | 1939 |
1934 PSAdaptiveSizePolicy* policy = heap->size_policy(); | 1940 PSAdaptiveSizePolicy* policy = heap->size_policy(); |
1935 | 1941 IsGCActiveMark mark; |
1936 // Before each allocation/collection attempt, find out from the | 1942 |
1937 // policy object if GCs are, on the whole, taking too long. If so, | 1943 if (ScavengeBeforeFullGC) { |
1938 // bail out without attempting a collection. The exceptions are | 1944 PSScavenge::invoke_no_policy(); |
1939 // for explicitly requested GC's. | 1945 } |
1940 if (!policy->gc_time_limit_exceeded() || | 1946 |
1941 GCCause::is_user_requested_gc(gc_cause) || | 1947 const bool clear_all_soft_refs = |
1942 GCCause::is_serviceability_requested_gc(gc_cause)) { | 1948 heap->collector_policy()->should_clear_all_soft_refs(); |
1943 IsGCActiveMark mark; | 1949 |
1944 | 1950 PSParallelCompact::invoke_no_policy(clear_all_soft_refs || |
1945 if (ScavengeBeforeFullGC) { | 1951 maximum_heap_compaction); |
1946 PSScavenge::invoke_no_policy(); | |
1947 } | |
1948 | |
1949 PSParallelCompact::invoke_no_policy(maximum_heap_compaction); | |
1950 } | |
1951 } | 1952 } |
1952 | 1953 |
1953 bool ParallelCompactData::region_contains(size_t region_index, HeapWord* addr) { | 1954 bool ParallelCompactData::region_contains(size_t region_index, HeapWord* addr) { |
1954 size_t addr_region_index = addr_to_region_idx(addr); | 1955 size_t addr_region_index = addr_to_region_idx(addr); |
1955 return region_index == addr_region_index; | 1956 return region_index == addr_region_index; |
1973 GCCause::Cause gc_cause = heap->gc_cause(); | 1974 GCCause::Cause gc_cause = heap->gc_cause(); |
1974 PSYoungGen* young_gen = heap->young_gen(); | 1975 PSYoungGen* young_gen = heap->young_gen(); |
1975 PSOldGen* old_gen = heap->old_gen(); | 1976 PSOldGen* old_gen = heap->old_gen(); |
1976 PSPermGen* perm_gen = heap->perm_gen(); | 1977 PSPermGen* perm_gen = heap->perm_gen(); |
1977 PSAdaptiveSizePolicy* size_policy = heap->size_policy(); | 1978 PSAdaptiveSizePolicy* size_policy = heap->size_policy(); |
1979 | |
1980 // The scope of casr should end after code that can change | |
1981 // CollectorPolicy::_should_clear_all_soft_refs. | |
1982 ClearedAllSoftRefs casr(maximum_heap_compaction, | |
1983 heap->collector_policy()); | |
1978 | 1984 |
1979 if (ZapUnusedHeapArea) { | 1985 if (ZapUnusedHeapArea) { |
1980 // Save information needed to minimize mangling | 1986 // Save information needed to minimize mangling |
1981 heap->record_gen_tops_before_GC(); | 1987 heap->record_gen_tops_before_GC(); |
1982 } | 1988 } |
2107 perm_gen->used_in_bytes(), | 2113 perm_gen->used_in_bytes(), |
2108 young_gen->eden_space()->capacity_in_bytes(), | 2114 young_gen->eden_space()->capacity_in_bytes(), |
2109 old_gen->max_gen_size(), | 2115 old_gen->max_gen_size(), |
2110 max_eden_size, | 2116 max_eden_size, |
2111 true /* full gc*/, | 2117 true /* full gc*/, |
2112 gc_cause); | 2118 gc_cause, |
2119 heap->collector_policy()); | |
2113 | 2120 |
2114 heap->resize_old_gen( | 2121 heap->resize_old_gen( |
2115 size_policy->calculated_old_free_size_in_bytes()); | 2122 size_policy->calculated_old_free_size_in_bytes()); |
2116 | 2123 |
2117 // Don't resize the young generation at an major collection. A | 2124 // Don't resize the young generation at an major collection. A |
2155 } | 2162 } |
2156 | 2163 |
2157 // Track memory usage and detect low memory | 2164 // Track memory usage and detect low memory |
2158 MemoryService::track_memory_usage(); | 2165 MemoryService::track_memory_usage(); |
2159 heap->update_counters(); | 2166 heap->update_counters(); |
2160 | |
2161 if (PrintGCDetails) { | |
2162 if (size_policy->print_gc_time_limit_would_be_exceeded()) { | |
2163 if (size_policy->gc_time_limit_exceeded()) { | |
2164 gclog_or_tty->print_cr(" GC time is exceeding GCTimeLimit " | |
2165 "of %d%%", GCTimeLimit); | |
2166 } else { | |
2167 gclog_or_tty->print_cr(" GC time would exceed GCTimeLimit " | |
2168 "of %d%%", GCTimeLimit); | |
2169 } | |
2170 } | |
2171 size_policy->set_print_gc_time_limit_would_be_exceeded(false); | |
2172 } | |
2173 } | 2167 } |
2174 | 2168 |
2175 if (VerifyAfterGC && heap->total_collections() >= VerifyGCStartAt) { | 2169 if (VerifyAfterGC && heap->total_collections() >= VerifyGCStartAt) { |
2176 HandleMark hm; // Discard invalid handles created during verification | 2170 HandleMark hm; // Discard invalid handles created during verification |
2177 gclog_or_tty->print(" VerifyAfterGC:"); | 2171 gclog_or_tty->print(" VerifyAfterGC:"); |