duke@435: /* xdono@631: * Copyright 2000-2008 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 MarkSweep::mark_object(oop obj) { duke@435: // some marks may contain information we need to preserve so we store them away duke@435: // and overwrite the mark. We'll restore it at the end of markSweep. duke@435: markOop mark = obj->mark(); duke@435: obj->set_mark(markOopDesc::prototype()->set_marked()); duke@435: duke@435: if (mark->must_be_preserved(obj)) { duke@435: preserve_mark(obj, mark); duke@435: } duke@435: } coleenp@548: coleenp@548: template inline void MarkSweep::follow_root(T* p) { coleenp@548: assert(!Universe::heap()->is_in_reserved(p), coleenp@548: "roots shouldn't be things within the heap"); coleenp@548: #ifdef VALIDATE_MARK_SWEEP coleenp@548: if (ValidateMarkSweep) { coleenp@548: guarantee(!_root_refs_stack->contains(p), "should only be in here once"); coleenp@548: _root_refs_stack->push(p); coleenp@548: } coleenp@548: #endif coleenp@548: T heap_oop = oopDesc::load_heap_oop(p); coleenp@548: if (!oopDesc::is_null(heap_oop)) { coleenp@548: oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); coleenp@548: if (!obj->mark()->is_marked()) { coleenp@548: mark_object(obj); coleenp@548: obj->follow_contents(); coleenp@548: } coleenp@548: } coleenp@548: follow_stack(); coleenp@548: } coleenp@548: coleenp@548: template inline void MarkSweep::mark_and_follow(T* p) { coleenp@548: // assert(Universe::heap()->is_in_reserved(p), "should be in object space"); coleenp@548: T heap_oop = oopDesc::load_heap_oop(p); coleenp@548: if (!oopDesc::is_null(heap_oop)) { coleenp@548: oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); coleenp@548: if (!obj->mark()->is_marked()) { coleenp@548: mark_object(obj); coleenp@548: obj->follow_contents(); coleenp@548: } coleenp@548: } coleenp@548: } coleenp@548: coleenp@548: template inline void MarkSweep::mark_and_push(T* p) { coleenp@548: // assert(Universe::heap()->is_in_reserved(p), "should be in object space"); coleenp@548: T heap_oop = oopDesc::load_heap_oop(p); coleenp@548: if (!oopDesc::is_null(heap_oop)) { coleenp@548: oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); coleenp@548: if (!obj->mark()->is_marked()) { coleenp@548: mark_object(obj); coleenp@548: _marking_stack->push(obj); coleenp@548: } coleenp@548: } coleenp@548: } coleenp@548: coleenp@548: template inline void MarkSweep::adjust_pointer(T* p, bool isroot) { coleenp@548: T heap_oop = oopDesc::load_heap_oop(p); coleenp@548: if (!oopDesc::is_null(heap_oop)) { coleenp@548: oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); coleenp@548: oop new_obj = oop(obj->mark()->decode_pointer()); coleenp@548: assert(new_obj != NULL || // is forwarding ptr? coleenp@548: obj->mark() == markOopDesc::prototype() || // not gc marked? coleenp@548: (UseBiasedLocking && obj->mark()->has_bias_pattern()) || coleenp@548: // not gc marked? coleenp@548: obj->is_shared(), // never forwarded? coleenp@548: "should be forwarded"); coleenp@548: if (new_obj != NULL) { coleenp@548: assert(Universe::heap()->is_in_reserved(new_obj), coleenp@548: "should be in object space"); coleenp@548: oopDesc::encode_store_heap_oop_not_null(p, new_obj); coleenp@548: } coleenp@548: } coleenp@548: VALIDATE_MARK_SWEEP_ONLY(track_adjusted_pointer(p, isroot)); coleenp@548: } coleenp@548: coleenp@548: template inline void MarkSweep::KeepAliveClosure::do_oop_work(T* p) { coleenp@548: #ifdef VALIDATE_MARK_SWEEP coleenp@548: if (ValidateMarkSweep) { coleenp@548: if (!Universe::heap()->is_in_reserved(p)) { coleenp@548: _root_refs_stack->push(p); coleenp@548: } else { coleenp@548: _other_refs_stack->push(p); coleenp@548: } coleenp@548: } coleenp@548: #endif coleenp@548: mark_and_push(p); coleenp@548: }