duke@435: /* xdono@631: * Copyright 2001-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: class Generation; duke@435: class HeapWord; duke@435: class CardTableRS; duke@435: class CardTableModRefBS; duke@435: class DefNewGeneration; duke@435: coleenp@548: template class GenericTaskQueue; coleenp@548: typedef GenericTaskQueue OopTaskQueue; coleenp@548: template class GenericTaskQueueSet; coleenp@548: typedef GenericTaskQueueSet OopTaskQueueSet; coleenp@548: duke@435: // Closure for iterating roots from a particular generation duke@435: // Note: all classes deriving from this MUST call this do_barrier duke@435: // method at the end of their own do_oop method! duke@435: // Note: no do_oop defined, this is an abstract class. duke@435: duke@435: class OopsInGenClosure : public OopClosure { duke@435: private: coleenp@548: Generation* _orig_gen; // generation originally set in ctor coleenp@548: Generation* _gen; // generation being scanned duke@435: duke@435: protected: duke@435: // Some subtypes need access. coleenp@548: HeapWord* _gen_boundary; // start of generation coleenp@548: CardTableRS* _rs; // remembered set duke@435: duke@435: // For assertions duke@435: Generation* generation() { return _gen; } duke@435: CardTableRS* rs() { return _rs; } duke@435: duke@435: // Derived classes that modify oops so that they might be old-to-young duke@435: // pointers must call the method below. coleenp@548: template void do_barrier(T* p); duke@435: ysr@777: // Version for use by closures that may be called in parallel code. ysr@1280: template void par_do_barrier(T* p); ysr@777: duke@435: public: duke@435: OopsInGenClosure() : OopClosure(NULL), duke@435: _orig_gen(NULL), _gen(NULL), _gen_boundary(NULL), _rs(NULL) {}; duke@435: duke@435: OopsInGenClosure(Generation* gen); duke@435: void set_generation(Generation* gen); duke@435: duke@435: void reset_generation() { _gen = _orig_gen; } duke@435: duke@435: // Problem with static closures: must have _gen_boundary set at some point, duke@435: // but cannot do this until after the heap is initialized. duke@435: void set_orig_generation(Generation* gen) { duke@435: _orig_gen = gen; duke@435: set_generation(gen); duke@435: } duke@435: duke@435: HeapWord* gen_boundary() { return _gen_boundary; } duke@435: }; duke@435: duke@435: // Closure for scanning DefNewGeneration. duke@435: // duke@435: // This closure will perform barrier store calls for ALL duke@435: // pointers in scanned oops. duke@435: class ScanClosure: public OopsInGenClosure { coleenp@548: protected: duke@435: DefNewGeneration* _g; coleenp@548: HeapWord* _boundary; coleenp@548: bool _gc_barrier; coleenp@548: template inline void do_oop_work(T* p); coleenp@548: public: duke@435: ScanClosure(DefNewGeneration* g, bool gc_barrier); coleenp@548: virtual void do_oop(oop* p); coleenp@548: virtual void do_oop(narrowOop* p); coleenp@548: inline void do_oop_nv(oop* p); coleenp@548: inline void do_oop_nv(narrowOop* p); duke@435: bool do_header() { return false; } duke@435: Prefetch::style prefetch_style() { duke@435: return Prefetch::do_write; duke@435: } duke@435: }; duke@435: duke@435: // Closure for scanning DefNewGeneration. duke@435: // duke@435: // This closure only performs barrier store calls on duke@435: // pointers into the DefNewGeneration. This is less duke@435: // precise, but faster, than a ScanClosure duke@435: class FastScanClosure: public OopsInGenClosure { coleenp@548: protected: duke@435: DefNewGeneration* _g; coleenp@548: HeapWord* _boundary; coleenp@548: bool _gc_barrier; coleenp@548: template inline void do_oop_work(T* p); coleenp@548: public: duke@435: FastScanClosure(DefNewGeneration* g, bool gc_barrier); coleenp@548: virtual void do_oop(oop* p); coleenp@548: virtual void do_oop(narrowOop* p); coleenp@548: inline void do_oop_nv(oop* p); coleenp@548: inline void do_oop_nv(narrowOop* p); duke@435: bool do_header() { return false; } duke@435: Prefetch::style prefetch_style() { duke@435: return Prefetch::do_write; duke@435: } duke@435: }; duke@435: duke@435: class FilteringClosure: public OopClosure { coleenp@548: private: coleenp@548: HeapWord* _boundary; duke@435: OopClosure* _cl; coleenp@548: protected: coleenp@548: template inline void do_oop_work(T* p) { 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 ((HeapWord*)obj < _boundary) { coleenp@548: _cl->do_oop(p); coleenp@548: } coleenp@548: } coleenp@548: } coleenp@548: public: duke@435: FilteringClosure(HeapWord* boundary, OopClosure* cl) : duke@435: OopClosure(cl->_ref_processor), _boundary(boundary), duke@435: _cl(cl) {} coleenp@548: virtual void do_oop(oop* p); coleenp@548: virtual void do_oop(narrowOop* p); coleenp@548: inline void do_oop_nv(oop* p) { FilteringClosure::do_oop_work(p); } coleenp@548: inline void do_oop_nv(narrowOop* p) { FilteringClosure::do_oop_work(p); } duke@435: bool do_header() { return false; } duke@435: }; duke@435: duke@435: // Closure for scanning DefNewGeneration's weak references. duke@435: // NOTE: very much like ScanClosure but not derived from duke@435: // OopsInGenClosure -- weak references are processed all duke@435: // at once, with no notion of which generation they were in. duke@435: class ScanWeakRefClosure: public OopClosure { coleenp@548: protected: coleenp@548: DefNewGeneration* _g; coleenp@548: HeapWord* _boundary; coleenp@548: template inline void do_oop_work(T* p); coleenp@548: public: duke@435: ScanWeakRefClosure(DefNewGeneration* g); coleenp@548: virtual void do_oop(oop* p); coleenp@548: virtual void do_oop(narrowOop* p); coleenp@548: inline void do_oop_nv(oop* p); coleenp@548: inline void do_oop_nv(narrowOop* p); duke@435: }; duke@435: duke@435: class VerifyOopClosure: public OopClosure { coleenp@548: protected: coleenp@548: template inline void do_oop_work(T* p) { coleenp@548: oop obj = oopDesc::load_decode_heap_oop(p); coleenp@548: guarantee(obj->is_oop_or_null(), "invalid oop"); duke@435: } coleenp@548: public: coleenp@548: virtual void do_oop(oop* p); coleenp@548: virtual void do_oop(narrowOop* p); duke@435: static VerifyOopClosure verify_oop; duke@435: };