duke@435: /* duke@435: * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: inline void ParScanWeakRefClosure::do_oop(oop* p) duke@435: { duke@435: oop obj = *p; duke@435: assert (obj != NULL, "null weak reference?"); duke@435: // weak references are sometimes scanned twice; must check duke@435: // that to-space doesn't already contain this object duke@435: if ((HeapWord*)obj < _boundary && !_g->to()->is_in_reserved(obj)) { duke@435: // we need to ensure that it is copied (see comment in duke@435: // ParScanClosure::do_oop_work). duke@435: klassOop objK = obj->klass(); duke@435: markOop m = obj->mark(); duke@435: if (m->is_marked()) { // Contains forwarding pointer. duke@435: *p = ParNewGeneration::real_forwardee(obj); duke@435: } else { duke@435: size_t obj_sz = obj->size_given_klass(objK->klass_part()); duke@435: *p = ((ParNewGeneration*)_g)->copy_to_survivor_space(_par_scan_state, duke@435: obj, obj_sz, m); duke@435: } duke@435: } duke@435: } duke@435: duke@435: inline void ParScanWeakRefClosure::do_oop_nv(oop* p) duke@435: { duke@435: ParScanWeakRefClosure::do_oop(p); duke@435: } duke@435: duke@435: inline void ParScanClosure::par_do_barrier(oop* p) { duke@435: assert(generation()->is_in_reserved(p), "expected ref in generation"); duke@435: oop obj = *p; duke@435: assert(obj != NULL, "expected non-null object"); duke@435: // If p points to a younger generation, mark the card. duke@435: if ((HeapWord*)obj < gen_boundary()) { duke@435: rs()->write_ref_field_gc_par(p, obj); duke@435: } duke@435: } duke@435: duke@435: inline void ParScanClosure::do_oop_work(oop* p, duke@435: bool gc_barrier, duke@435: bool root_scan) { duke@435: oop obj = *p; duke@435: assert((!Universe::heap()->is_in_reserved(p) || duke@435: generation()->is_in_reserved(p)) duke@435: && (generation()->level() == 0 || gc_barrier), duke@435: "The gen must be right, and we must be doing the barrier " duke@435: "in older generations."); duke@435: if (obj != NULL) { duke@435: if ((HeapWord*)obj < _boundary) { duke@435: assert(!_g->to()->is_in_reserved(obj), "Scanning field twice?"); duke@435: // OK, we need to ensure that it is copied. duke@435: // We read the klass and mark in this order, so that we can reliably duke@435: // get the size of the object: if the mark we read is not a duke@435: // forwarding pointer, then the klass is valid: the klass is only duke@435: // overwritten with an overflow next pointer after the object is duke@435: // forwarded. duke@435: klassOop objK = obj->klass(); duke@435: markOop m = obj->mark(); duke@435: if (m->is_marked()) { // Contains forwarding pointer. duke@435: *p = ParNewGeneration::real_forwardee(obj); duke@435: } else { duke@435: size_t obj_sz = obj->size_given_klass(objK->klass_part()); duke@435: *p = _g->copy_to_survivor_space(_par_scan_state, obj, obj_sz, m); duke@435: if (root_scan) { duke@435: // This may have pushed an object. If we have a root duke@435: // category with a lot of roots, can't let the queue get too duke@435: // full: duke@435: (void)_par_scan_state->trim_queues(10 * ParallelGCThreads); duke@435: } duke@435: } duke@435: if (gc_barrier) { duke@435: // Now call parent closure duke@435: par_do_barrier(p); duke@435: } duke@435: } duke@435: } duke@435: }