duke@435: /* coleenp@4037: * Copyright (c) 2001, 2012, Oracle and/or its affiliates. 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: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_MEMORY_GENOOPCLOSURES_HPP stefank@2314: #define SHARE_VM_MEMORY_GENOOPCLOSURES_HPP stefank@2314: stefank@2314: #include "memory/iterator.hpp" stefank@2314: #include "oops/oop.hpp" stefank@2314: duke@435: class Generation; duke@435: class HeapWord; duke@435: class CardTableRS; duke@435: class CardTableModRefBS; duke@435: class DefNewGeneration; coleenp@4037: class KlassRemSet; duke@435: zgu@3900: template class GenericTaskQueue; zgu@3900: typedef GenericTaskQueue OopTaskQueue; zgu@3900: template class GenericTaskQueueSet; zgu@3900: 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: coleenp@4037: class OopsInGenClosure : public ExtendedOopClosure { 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: coleenp@4037: OopsInGenClosure() : ExtendedOopClosure(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; } coleenp@4037: coleenp@4037: }; coleenp@4037: coleenp@4037: // Super class for scan closures. It contains code to dirty scanned Klasses. coleenp@4037: class OopsInKlassOrGenClosure: public OopsInGenClosure { coleenp@4037: Klass* _scanned_klass; coleenp@4037: public: coleenp@4037: OopsInKlassOrGenClosure(Generation* g) : OopsInGenClosure(g), _scanned_klass(NULL) {} coleenp@4037: void set_scanned_klass(Klass* k) { coleenp@4037: assert(k == NULL || _scanned_klass == NULL, "Must be"); coleenp@4037: _scanned_klass = k; coleenp@4037: } coleenp@4037: bool is_scanning_a_klass() { return _scanned_klass != NULL; } coleenp@4037: void do_klass_barrier(); 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. coleenp@4037: class ScanClosure: public OopsInKlassOrGenClosure { 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: 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 coleenp@4037: class FastScanClosure: public OopsInKlassOrGenClosure { 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: Prefetch::style prefetch_style() { duke@435: return Prefetch::do_write; duke@435: } duke@435: }; duke@435: coleenp@4037: class KlassScanClosure: public KlassClosure { coleenp@4037: OopsInKlassOrGenClosure* _scavenge_closure; coleenp@4037: // true if the the modified oops state should be saved. coleenp@4037: bool _accumulate_modified_oops; coleenp@4037: public: coleenp@4037: KlassScanClosure(OopsInKlassOrGenClosure* scavenge_closure, coleenp@4037: KlassRemSet* klass_rem_set_policy); coleenp@4037: void do_klass(Klass* k); coleenp@4037: }; coleenp@4037: coleenp@4037: class FilteringClosure: public ExtendedOopClosure { coleenp@548: private: coleenp@548: HeapWord* _boundary; coleenp@4037: ExtendedOopClosure* _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: coleenp@4037: FilteringClosure(HeapWord* boundary, ExtendedOopClosure* cl) : coleenp@4037: ExtendedOopClosure(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); } coleenp@4037: virtual bool do_metadata() { return do_metadata_nv(); } coleenp@4037: inline bool do_metadata_nv() { assert(!_cl->do_metadata(), "assumption broken, must change to 'return _cl->do_metadata()'"); 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); twisti@2874: guarantee(obj->is_oop_or_null(), err_msg("invalid oop: " INTPTR_FORMAT, (oopDesc*) obj)); 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: }; stefank@2314: stefank@2314: #endif // SHARE_VM_MEMORY_GENOOPCLOSURES_HPP