aoqi@0: /* aoqi@0: * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #ifndef SHARE_VM_MEMORY_GENOOPCLOSURES_INLINE_HPP aoqi@0: #define SHARE_VM_MEMORY_GENOOPCLOSURES_INLINE_HPP aoqi@0: aoqi@0: #include "memory/cardTableRS.hpp" aoqi@0: #include "memory/defNewGeneration.hpp" aoqi@0: #include "memory/genCollectedHeap.hpp" aoqi@0: #include "memory/genOopClosures.hpp" aoqi@0: #include "memory/genRemSet.hpp" aoqi@0: #include "memory/generation.hpp" aoqi@0: #include "memory/sharedHeap.hpp" aoqi@0: #include "memory/space.hpp" aoqi@0: aoqi@0: inline OopsInGenClosure::OopsInGenClosure(Generation* gen) : aoqi@0: ExtendedOopClosure(gen->ref_processor()), _orig_gen(gen), _rs(NULL) { aoqi@0: set_generation(gen); aoqi@0: } aoqi@0: aoqi@0: inline void OopsInGenClosure::set_generation(Generation* gen) { aoqi@0: _gen = gen; aoqi@0: _gen_boundary = _gen->reserved().start(); aoqi@0: // Barrier set for the heap, must be set after heap is initialized aoqi@0: if (_rs == NULL) { aoqi@0: GenRemSet* rs = SharedHeap::heap()->rem_set(); aoqi@0: assert(rs->rs_kind() == GenRemSet::CardTable, "Wrong rem set kind"); aoqi@0: _rs = (CardTableRS*)rs; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: template inline void OopsInGenClosure::do_barrier(T* p) { aoqi@0: assert(generation()->is_in_reserved(p), "expected ref in generation"); aoqi@0: T heap_oop = oopDesc::load_heap_oop(p); aoqi@0: assert(!oopDesc::is_null(heap_oop), "expected non-null oop"); aoqi@0: oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); aoqi@0: // If p points to a younger generation, mark the card. aoqi@0: if ((HeapWord*)obj < _gen_boundary) { aoqi@0: _rs->inline_write_ref_field_gc(p, obj); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: template inline void OopsInGenClosure::par_do_barrier(T* p) { aoqi@0: assert(generation()->is_in_reserved(p), "expected ref in generation"); aoqi@0: T heap_oop = oopDesc::load_heap_oop(p); aoqi@0: assert(!oopDesc::is_null(heap_oop), "expected non-null oop"); aoqi@0: oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); aoqi@0: // If p points to a younger generation, mark the card. aoqi@0: if ((HeapWord*)obj < gen_boundary()) { aoqi@0: rs()->write_ref_field_gc_par(p, obj); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: inline void OopsInKlassOrGenClosure::do_klass_barrier() { aoqi@0: assert(_scanned_klass != NULL, "Must be"); aoqi@0: _scanned_klass->record_modified_oops(); aoqi@0: } aoqi@0: aoqi@0: // NOTE! Any changes made here should also be made aoqi@0: // in FastScanClosure::do_oop_work() aoqi@0: template inline void ScanClosure::do_oop_work(T* p) { aoqi@0: T heap_oop = oopDesc::load_heap_oop(p); aoqi@0: // Should we copy the obj? aoqi@0: if (!oopDesc::is_null(heap_oop)) { aoqi@0: oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); aoqi@0: if ((HeapWord*)obj < _boundary) { aoqi@0: assert(!_g->to()->is_in_reserved(obj), "Scanning field twice?"); aoqi@0: oop new_obj = obj->is_forwarded() ? obj->forwardee() aoqi@0: : _g->copy_to_survivor_space(obj); aoqi@0: oopDesc::encode_store_heap_oop_not_null(p, new_obj); aoqi@0: } aoqi@0: aoqi@0: if (is_scanning_a_klass()) { aoqi@0: do_klass_barrier(); aoqi@0: } else if (_gc_barrier) { aoqi@0: // Now call parent closure aoqi@0: do_barrier(p); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: inline void ScanClosure::do_oop_nv(oop* p) { ScanClosure::do_oop_work(p); } aoqi@0: inline void ScanClosure::do_oop_nv(narrowOop* p) { ScanClosure::do_oop_work(p); } aoqi@0: aoqi@0: // NOTE! Any changes made here should also be made aoqi@0: // in ScanClosure::do_oop_work() aoqi@0: template inline void FastScanClosure::do_oop_work(T* p) { aoqi@0: T heap_oop = oopDesc::load_heap_oop(p); aoqi@0: // Should we copy the obj? aoqi@0: if (!oopDesc::is_null(heap_oop)) { aoqi@0: oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); aoqi@0: if ((HeapWord*)obj < _boundary) { aoqi@0: assert(!_g->to()->is_in_reserved(obj), "Scanning field twice?"); aoqi@0: oop new_obj = obj->is_forwarded() ? obj->forwardee() aoqi@0: : _g->copy_to_survivor_space(obj); aoqi@0: oopDesc::encode_store_heap_oop_not_null(p, new_obj); aoqi@0: if (is_scanning_a_klass()) { aoqi@0: do_klass_barrier(); aoqi@0: } else if (_gc_barrier) { aoqi@0: // Now call parent closure aoqi@0: do_barrier(p); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: inline void FastScanClosure::do_oop_nv(oop* p) { FastScanClosure::do_oop_work(p); } aoqi@0: inline void FastScanClosure::do_oop_nv(narrowOop* p) { FastScanClosure::do_oop_work(p); } aoqi@0: aoqi@0: // Note similarity to ScanClosure; the difference is that aoqi@0: // the barrier set is taken care of outside this closure. aoqi@0: template inline void ScanWeakRefClosure::do_oop_work(T* p) { aoqi@0: assert(!oopDesc::is_null(*p), "null weak reference?"); aoqi@0: oop obj = oopDesc::load_decode_heap_oop_not_null(p); aoqi@0: // weak references are sometimes scanned twice; must check aoqi@0: // that to-space doesn't already contain this object aoqi@0: if ((HeapWord*)obj < _boundary && !_g->to()->is_in_reserved(obj)) { aoqi@0: oop new_obj = obj->is_forwarded() ? obj->forwardee() aoqi@0: : _g->copy_to_survivor_space(obj); aoqi@0: oopDesc::encode_store_heap_oop_not_null(p, new_obj); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: inline void ScanWeakRefClosure::do_oop_nv(oop* p) { ScanWeakRefClosure::do_oop_work(p); } aoqi@0: inline void ScanWeakRefClosure::do_oop_nv(narrowOop* p) { ScanWeakRefClosure::do_oop_work(p); } aoqi@0: aoqi@0: #endif // SHARE_VM_MEMORY_GENOOPCLOSURES_INLINE_HPP