src/share/vm/gc_implementation/parNew/parOopClosures.inline.hpp

Tue, 13 Apr 2010 13:52:10 -0700

author
jmasa
date
Tue, 13 Apr 2010 13:52:10 -0700
changeset 1822
0bfd3fb24150
parent 548
ba764ed4b6f2
child 1907
c18cbe5936b8
permissions
-rw-r--r--

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

duke@435 1 /*
duke@435 2 * Copyright (c) 2007 Sun Microsystems, Inc. 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 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
coleenp@548 25 template <class T> inline void ParScanWeakRefClosure::do_oop_work(T* p) {
coleenp@548 26 assert (!oopDesc::is_null(*p), "null weak reference?");
coleenp@548 27 oop obj = oopDesc::load_decode_heap_oop_not_null(p);
duke@435 28 // weak references are sometimes scanned twice; must check
duke@435 29 // that to-space doesn't already contain this object
duke@435 30 if ((HeapWord*)obj < _boundary && !_g->to()->is_in_reserved(obj)) {
duke@435 31 // we need to ensure that it is copied (see comment in
duke@435 32 // ParScanClosure::do_oop_work).
duke@435 33 klassOop objK = obj->klass();
duke@435 34 markOop m = obj->mark();
coleenp@548 35 oop new_obj;
duke@435 36 if (m->is_marked()) { // Contains forwarding pointer.
coleenp@548 37 new_obj = ParNewGeneration::real_forwardee(obj);
duke@435 38 } else {
duke@435 39 size_t obj_sz = obj->size_given_klass(objK->klass_part());
coleenp@548 40 new_obj = ((ParNewGeneration*)_g)->copy_to_survivor_space(_par_scan_state,
coleenp@548 41 obj, obj_sz, m);
duke@435 42 }
coleenp@548 43 oopDesc::encode_store_heap_oop_not_null(p, new_obj);
duke@435 44 }
duke@435 45 }
duke@435 46
coleenp@548 47 inline void ParScanWeakRefClosure::do_oop_nv(oop* p) { ParScanWeakRefClosure::do_oop_work(p); }
coleenp@548 48 inline void ParScanWeakRefClosure::do_oop_nv(narrowOop* p) { ParScanWeakRefClosure::do_oop_work(p); }
duke@435 49
coleenp@548 50 template <class T> inline void ParScanClosure::par_do_barrier(T* p) {
duke@435 51 assert(generation()->is_in_reserved(p), "expected ref in generation");
coleenp@548 52 assert(!oopDesc::is_null(*p), "expected non-null object");
coleenp@548 53 oop obj = oopDesc::load_decode_heap_oop_not_null(p);
duke@435 54 // If p points to a younger generation, mark the card.
duke@435 55 if ((HeapWord*)obj < gen_boundary()) {
duke@435 56 rs()->write_ref_field_gc_par(p, obj);
duke@435 57 }
duke@435 58 }
duke@435 59
coleenp@548 60 template <class T>
coleenp@548 61 inline void ParScanClosure::do_oop_work(T* p,
duke@435 62 bool gc_barrier,
duke@435 63 bool root_scan) {
duke@435 64 assert((!Universe::heap()->is_in_reserved(p) ||
duke@435 65 generation()->is_in_reserved(p))
duke@435 66 && (generation()->level() == 0 || gc_barrier),
duke@435 67 "The gen must be right, and we must be doing the barrier "
duke@435 68 "in older generations.");
coleenp@548 69 T heap_oop = oopDesc::load_heap_oop(p);
coleenp@548 70 if (!oopDesc::is_null(heap_oop)) {
coleenp@548 71 oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
duke@435 72 if ((HeapWord*)obj < _boundary) {
duke@435 73 assert(!_g->to()->is_in_reserved(obj), "Scanning field twice?");
duke@435 74 // OK, we need to ensure that it is copied.
duke@435 75 // We read the klass and mark in this order, so that we can reliably
duke@435 76 // get the size of the object: if the mark we read is not a
duke@435 77 // forwarding pointer, then the klass is valid: the klass is only
duke@435 78 // overwritten with an overflow next pointer after the object is
duke@435 79 // forwarded.
duke@435 80 klassOop objK = obj->klass();
duke@435 81 markOop m = obj->mark();
coleenp@548 82 oop new_obj;
duke@435 83 if (m->is_marked()) { // Contains forwarding pointer.
coleenp@548 84 new_obj = ParNewGeneration::real_forwardee(obj);
coleenp@548 85 oopDesc::encode_store_heap_oop_not_null(p, new_obj);
duke@435 86 } else {
duke@435 87 size_t obj_sz = obj->size_given_klass(objK->klass_part());
coleenp@548 88 new_obj = _g->copy_to_survivor_space(_par_scan_state, obj, obj_sz, m);
coleenp@548 89 oopDesc::encode_store_heap_oop_not_null(p, new_obj);
duke@435 90 if (root_scan) {
duke@435 91 // This may have pushed an object. If we have a root
duke@435 92 // category with a lot of roots, can't let the queue get too
duke@435 93 // full:
duke@435 94 (void)_par_scan_state->trim_queues(10 * ParallelGCThreads);
duke@435 95 }
duke@435 96 }
duke@435 97 if (gc_barrier) {
duke@435 98 // Now call parent closure
duke@435 99 par_do_barrier(p);
duke@435 100 }
duke@435 101 }
duke@435 102 }
duke@435 103 }
coleenp@548 104
coleenp@548 105 inline void ParScanWithBarrierClosure::do_oop_nv(oop* p) { ParScanClosure::do_oop_work(p, true, false); }
coleenp@548 106 inline void ParScanWithBarrierClosure::do_oop_nv(narrowOop* p) { ParScanClosure::do_oop_work(p, true, false); }
coleenp@548 107
coleenp@548 108 inline void ParScanWithoutBarrierClosure::do_oop_nv(oop* p) { ParScanClosure::do_oop_work(p, false, false); }
coleenp@548 109 inline void ParScanWithoutBarrierClosure::do_oop_nv(narrowOop* p) { ParScanClosure::do_oop_work(p, false, false); }

mercurial