comparison src/share/vm/memory/genCollectedHeap.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 c4d722788ed6
children bb843ebc7c55
comparison
equal deleted inserted replaced
1361:6b73e879f1c2 1387:0bfd3fb24150
1 /* 1 /*
2 * Copyright 2000-2009 Sun Microsystems, Inc. All Rights Reserved. 2 * Copyright 2000-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.
426 426
427 assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint"); 427 assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint");
428 assert(my_thread->is_VM_thread() || 428 assert(my_thread->is_VM_thread() ||
429 my_thread->is_ConcurrentGC_thread(), 429 my_thread->is_ConcurrentGC_thread(),
430 "incorrect thread type capability"); 430 "incorrect thread type capability");
431 assert(Heap_lock->is_locked(), "the requesting thread should have the Heap_lock"); 431 assert(Heap_lock->is_locked(),
432 "the requesting thread should have the Heap_lock");
432 guarantee(!is_gc_active(), "collection is not reentrant"); 433 guarantee(!is_gc_active(), "collection is not reentrant");
433 assert(max_level < n_gens(), "sanity check"); 434 assert(max_level < n_gens(), "sanity check");
434 435
435 if (GC_locker::check_active_before_gc()) { 436 if (GC_locker::check_active_before_gc()) {
436 return; // GC is disabled (e.g. JNI GetXXXCritical operation) 437 return; // GC is disabled (e.g. JNI GetXXXCritical operation)
437 } 438 }
439
440 const bool do_clear_all_soft_refs = clear_all_soft_refs ||
441 collector_policy()->should_clear_all_soft_refs();
442
443 ClearedAllSoftRefs casr(do_clear_all_soft_refs, collector_policy());
438 444
439 const size_t perm_prev_used = perm_gen()->used(); 445 const size_t perm_prev_used = perm_gen()->used();
440 446
441 if (PrintHeapAtGC) { 447 if (PrintHeapAtGC) {
442 Universe::print_heap_before_gc(); 448 Universe::print_heap_before_gc();
558 // atomic wrt other collectors in this configuration, we 564 // atomic wrt other collectors in this configuration, we
559 // are guaranteed to have empty discovered ref lists. 565 // are guaranteed to have empty discovered ref lists.
560 if (rp->discovery_is_atomic()) { 566 if (rp->discovery_is_atomic()) {
561 rp->verify_no_references_recorded(); 567 rp->verify_no_references_recorded();
562 rp->enable_discovery(); 568 rp->enable_discovery();
563 rp->setup_policy(clear_all_soft_refs); 569 rp->setup_policy(do_clear_all_soft_refs);
564 } else { 570 } else {
565 // collect() below will enable discovery as appropriate 571 // collect() below will enable discovery as appropriate
566 } 572 }
567 _gens[i]->collect(full, clear_all_soft_refs, size, is_tlab); 573 _gens[i]->collect(full, do_clear_all_soft_refs, size, is_tlab);
568 if (!rp->enqueuing_is_done()) { 574 if (!rp->enqueuing_is_done()) {
569 rp->enqueue_discovered_references(); 575 rp->enqueue_discovered_references();
570 } else { 576 } else {
571 rp->set_enqueuing_is_done(false); 577 rp->set_enqueuing_is_done(false);
572 } 578 }