Mercurial > hg > graal-compiler
comparison src/share/vm/gc_implementation/g1/g1CollectedHeap.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 | bda703475ded |
children | 7666957bc44d |
comparison
equal
deleted
inserted
replaced
1361:6b73e879f1c2 | 1387:0bfd3fb24150 |
---|---|
1 /* | 1 /* |
2 * Copyright 2001-2009 Sun Microsystems, Inc. All Rights Reserved. | 2 * Copyright 2001-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. |
918 } | 918 } |
919 | 919 |
920 assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint"); | 920 assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint"); |
921 assert(Thread::current() == VMThread::vm_thread(), "should be in vm thread"); | 921 assert(Thread::current() == VMThread::vm_thread(), "should be in vm thread"); |
922 | 922 |
923 const bool do_clear_all_soft_refs = clear_all_soft_refs || | |
924 collector_policy()->should_clear_all_soft_refs(); | |
925 | |
926 ClearedAllSoftRefs casr(do_clear_all_soft_refs, collector_policy()); | |
927 | |
923 { | 928 { |
924 IsGCActiveMark x; | 929 IsGCActiveMark x; |
925 | 930 |
926 // Timing | 931 // Timing |
927 gclog_or_tty->date_stamp(PrintGC && PrintGCDateStamps); | 932 gclog_or_tty->date_stamp(PrintGC && PrintGCDateStamps); |
928 TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); | 933 TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); |
929 TraceTime t(full ? "Full GC (System.gc())" : "Full GC", PrintGC, true, gclog_or_tty); | 934 TraceTime t(full ? "Full GC (System.gc())" : "Full GC", |
935 PrintGC, true, gclog_or_tty); | |
930 | 936 |
931 TraceMemoryManagerStats tms(true /* fullGC */); | 937 TraceMemoryManagerStats tms(true /* fullGC */); |
932 | 938 |
933 double start = os::elapsedTime(); | 939 double start = os::elapsedTime(); |
934 g1_policy()->record_full_collection_start(); | 940 g1_policy()->record_full_collection_start(); |
983 | 989 |
984 // Temporarily clear _is_alive_non_header | 990 // Temporarily clear _is_alive_non_header |
985 ReferenceProcessorIsAliveMutator rp_is_alive_null(ref_processor(), NULL); | 991 ReferenceProcessorIsAliveMutator rp_is_alive_null(ref_processor(), NULL); |
986 | 992 |
987 ref_processor()->enable_discovery(); | 993 ref_processor()->enable_discovery(); |
988 ref_processor()->setup_policy(clear_all_soft_refs); | 994 ref_processor()->setup_policy(do_clear_all_soft_refs); |
989 | 995 |
990 // Do collection work | 996 // Do collection work |
991 { | 997 { |
992 HandleMark hm; // Discard invalid handles created during gc | 998 HandleMark hm; // Discard invalid handles created during gc |
993 G1MarkSweep::invoke_at_safepoint(ref_processor(), clear_all_soft_refs); | 999 G1MarkSweep::invoke_at_safepoint(ref_processor(), do_clear_all_soft_refs); |
994 } | 1000 } |
995 // Because freeing humongous regions may have added some unclean | 1001 // Because freeing humongous regions may have added some unclean |
996 // regions, it is necessary to tear down again before rebuilding. | 1002 // regions, it is necessary to tear down again before rebuilding. |
997 tear_down_region_lists(); | 1003 tear_down_region_lists(); |
998 rebuild_region_lists(); | 1004 rebuild_region_lists(); |
1205 result = attempt_allocation(word_size, /*permit_collection_pause*/false); | 1211 result = attempt_allocation(word_size, /*permit_collection_pause*/false); |
1206 if (result != NULL) { | 1212 if (result != NULL) { |
1207 assert(is_in(result), "result not in heap"); | 1213 assert(is_in(result), "result not in heap"); |
1208 return result; | 1214 return result; |
1209 } | 1215 } |
1216 | |
1217 assert(!collector_policy()->should_clear_all_soft_refs(), | |
1218 "Flag should have been handled and cleared prior to this point"); | |
1210 | 1219 |
1211 // What else? We might try synchronous finalization later. If the total | 1220 // What else? We might try synchronous finalization later. If the total |
1212 // space available is large enough for the allocation, then a more | 1221 // space available is large enough for the allocation, then a more |
1213 // complete compaction phase than we've tried so far might be | 1222 // complete compaction phase than we've tried so far might be |
1214 // appropriate. | 1223 // appropriate. |