ysr@777: /* xdono@1014: * Copyright 2001-2009 Sun Microsystems, Inc. All Rights Reserved. ysr@777: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ysr@777: * ysr@777: * This code is free software; you can redistribute it and/or modify it ysr@777: * under the terms of the GNU General Public License version 2 only, as ysr@777: * published by the Free Software Foundation. ysr@777: * ysr@777: * This code is distributed in the hope that it will be useful, but WITHOUT ysr@777: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ysr@777: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ysr@777: * version 2 for more details (a copy is included in the LICENSE file that ysr@777: * accompanied this code). ysr@777: * ysr@777: * You should have received a copy of the GNU General Public License version ysr@777: * 2 along with this work; if not, write to the Free Software Foundation, ysr@777: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. ysr@777: * ysr@777: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, ysr@777: * CA 95054 USA or visit www.sun.com if you need additional information or ysr@777: * have any questions. ysr@777: * ysr@777: */ ysr@777: ysr@777: class HeapRegion; ysr@777: class G1CollectedHeap; ysr@777: class G1RemSet; ysr@777: class HRInto_G1RemSet; ysr@777: class G1RemSet; ysr@777: class ConcurrentMark; ysr@777: class DirtyCardToOopClosure; ysr@777: class CMBitMap; ysr@777: class CMMarkStack; ysr@777: class G1ParScanThreadState; ysr@777: ysr@777: // A class that scans oops in a given heap region (much as OopsInGenClosure ysr@777: // scans oops in a generation.) ysr@777: class OopsInHeapRegionClosure: public OopsInGenClosure { ysr@777: protected: ysr@777: HeapRegion* _from; ysr@777: public: ysr@777: virtual void set_region(HeapRegion* from) { _from = from; } ysr@777: }; ysr@777: ysr@777: class G1ParClosureSuper : public OopsInHeapRegionClosure { ysr@777: protected: ysr@777: G1CollectedHeap* _g1; ysr@777: G1RemSet* _g1_rem; ysr@777: ConcurrentMark* _cm; ysr@777: G1ParScanThreadState* _par_scan_state; ysr@777: public: ysr@777: G1ParClosureSuper(G1CollectedHeap* g1, G1ParScanThreadState* par_scan_state); ysr@777: bool apply_to_weak_ref_discovered_field() { return true; } ysr@777: }; ysr@777: iveresov@1696: class G1ParPushHeapRSClosure : public G1ParClosureSuper { iveresov@1696: public: iveresov@1696: G1ParPushHeapRSClosure(G1CollectedHeap* g1, G1ParScanThreadState* par_scan_state) : iveresov@1696: G1ParClosureSuper(g1, par_scan_state) { } iveresov@1696: template void do_oop_nv(T* p); iveresov@1696: virtual void do_oop(oop* p) { do_oop_nv(p); } iveresov@1696: virtual void do_oop(narrowOop* p) { do_oop_nv(p); } iveresov@1696: }; iveresov@1696: ysr@777: class G1ParScanClosure : public G1ParClosureSuper { ysr@777: public: ysr@777: G1ParScanClosure(G1CollectedHeap* g1, G1ParScanThreadState* par_scan_state) : ysr@777: G1ParClosureSuper(g1, par_scan_state) { } ysr@1280: template void do_oop_nv(T* p); ysr@777: virtual void do_oop(oop* p) { do_oop_nv(p); } ysr@777: virtual void do_oop(narrowOop* p) { do_oop_nv(p); } ysr@777: }; ysr@777: ysr@1280: #define G1_PARTIAL_ARRAY_MASK 0x2 ysr@777: ysr@1280: template inline bool has_partial_array_mask(T* ref) { ysr@1280: return ((uintptr_t)ref & G1_PARTIAL_ARRAY_MASK) == G1_PARTIAL_ARRAY_MASK; tonyp@961: } tonyp@961: ysr@1280: template inline T* set_partial_array_mask(T obj) { ysr@1280: assert(((uintptr_t)obj & G1_PARTIAL_ARRAY_MASK) == 0, "Information loss!"); ysr@1280: return (T*) ((uintptr_t)obj | G1_PARTIAL_ARRAY_MASK); tonyp@961: } tonyp@961: ysr@1280: template inline oop clear_partial_array_mask(T* ref) { ysr@1280: return oop((intptr_t)ref & ~G1_PARTIAL_ARRAY_MASK); tonyp@961: } tonyp@961: ysr@777: class G1ParScanPartialArrayClosure : public G1ParClosureSuper { ysr@777: G1ParScanClosure _scanner; ysr@777: public: ysr@777: G1ParScanPartialArrayClosure(G1CollectedHeap* g1, G1ParScanThreadState* par_scan_state) : ysr@777: G1ParClosureSuper(g1, par_scan_state), _scanner(g1, par_scan_state) { } ysr@1280: template void do_oop_nv(T* p); ysr@777: virtual void do_oop(oop* p) { do_oop_nv(p); } ysr@777: virtual void do_oop(narrowOop* p) { do_oop_nv(p); } ysr@777: }; ysr@777: ysr@777: ysr@777: class G1ParCopyHelper : public G1ParClosureSuper { ysr@777: G1ParScanClosure *_scanner; ysr@777: protected: ysr@1280: template void mark_forwardee(T* p); ysr@777: oop copy_to_survivor_space(oop obj); ysr@777: public: ysr@777: G1ParCopyHelper(G1CollectedHeap* g1, G1ParScanThreadState* par_scan_state, ysr@777: G1ParScanClosure *scanner) : ysr@777: G1ParClosureSuper(g1, par_scan_state), _scanner(scanner) { } ysr@777: }; ysr@777: tonyp@961: template ysr@777: class G1ParCopyClosure : public G1ParCopyHelper { ysr@777: G1ParScanClosure _scanner; ysr@1280: template void do_oop_work(T* p); ysr@777: public: ysr@777: G1ParCopyClosure(G1CollectedHeap* g1, G1ParScanThreadState* par_scan_state) : ysr@777: _scanner(g1, par_scan_state), G1ParCopyHelper(g1, par_scan_state, &_scanner) { } ysr@1280: template void do_oop_nv(T* p) { ysr@777: do_oop_work(p); ysr@777: if (do_mark_forwardee) ysr@777: mark_forwardee(p); ysr@777: } ysr@777: virtual void do_oop(oop* p) { do_oop_nv(p); } ysr@777: virtual void do_oop(narrowOop* p) { do_oop_nv(p); } ysr@777: }; ysr@777: iveresov@1696: typedef G1ParCopyClosure G1ParScanExtRootClosure; iveresov@1696: typedef G1ParCopyClosure G1ParScanPermClosure; iveresov@1696: typedef G1ParCopyClosure G1ParScanHeapRSClosure; iveresov@1696: typedef G1ParCopyClosure G1ParScanAndMarkExtRootClosure; iveresov@1696: typedef G1ParCopyClosure G1ParScanAndMarkPermClosure; iveresov@1696: typedef G1ParCopyClosure G1ParScanAndMarkHeapRSClosure; iveresov@1696: tonyp@961: // This is the only case when we set skip_cset_test. Basically, this tonyp@961: // closure is (should?) only be called directly while we're draining tonyp@961: // the overflow and task queues. In that case we know that the tonyp@961: // reference in question points into the collection set, otherwise we ysr@1280: // would not have pushed it on the queue. The following is defined in ysr@1280: // g1_specialized_oop_closures.hpp. ysr@1280: // typedef G1ParCopyClosure G1ParScanHeapEvacClosure; tonyp@961: // We need a separate closure to handle references during evacuation ysr@1280: // failure processing, as we cannot asume that the reference already ysr@1280: // points into the collection set (like G1ParScanHeapEvacClosure does). iveresov@1696: typedef G1ParCopyClosure G1ParScanHeapEvacFailureClosure; ysr@777: ysr@777: class FilterIntoCSClosure: public OopClosure { ysr@777: G1CollectedHeap* _g1; ysr@777: OopClosure* _oc; ysr@777: DirtyCardToOopClosure* _dcto_cl; ysr@777: public: ysr@777: FilterIntoCSClosure( DirtyCardToOopClosure* dcto_cl, ysr@777: G1CollectedHeap* g1, OopClosure* oc) : ysr@777: _dcto_cl(dcto_cl), _g1(g1), _oc(oc) ysr@777: {} ysr@1280: template void do_oop_nv(T* p); ysr@1280: virtual void do_oop(oop* p) { do_oop_nv(p); } ysr@1280: virtual void do_oop(narrowOop* p) { do_oop_nv(p); } ysr@777: bool apply_to_weak_ref_discovered_field() { return true; } ysr@777: bool do_header() { return false; } ysr@777: }; ysr@777: ysr@777: class FilterInHeapRegionAndIntoCSClosure : public OopsInHeapRegionClosure { ysr@777: G1CollectedHeap* _g1; ysr@777: OopsInHeapRegionClosure* _oc; ysr@777: public: ysr@777: FilterInHeapRegionAndIntoCSClosure(G1CollectedHeap* g1, ysr@777: OopsInHeapRegionClosure* oc) : ysr@777: _g1(g1), _oc(oc) ysr@777: {} ysr@1280: template void do_oop_nv(T* p); ysr@1280: virtual void do_oop(oop* p) { do_oop_nv(p); } ysr@1280: virtual void do_oop(narrowOop* p) { do_oop_nv(p); } ysr@777: bool apply_to_weak_ref_discovered_field() { return true; } ysr@777: bool do_header() { return false; } ysr@777: void set_region(HeapRegion* from) { ysr@777: _oc->set_region(from); ysr@777: } ysr@777: }; ysr@777: ysr@777: class FilterAndMarkInHeapRegionAndIntoCSClosure : public OopsInHeapRegionClosure { ysr@777: G1CollectedHeap* _g1; ysr@777: ConcurrentMark* _cm; ysr@777: OopsInHeapRegionClosure* _oc; ysr@777: public: ysr@777: FilterAndMarkInHeapRegionAndIntoCSClosure(G1CollectedHeap* g1, ysr@777: OopsInHeapRegionClosure* oc, ysr@777: ConcurrentMark* cm) ysr@777: : _g1(g1), _oc(oc), _cm(cm) { } ysr@777: ysr@1280: template void do_oop_nv(T* p); ysr@1280: virtual void do_oop(oop* p) { do_oop_nv(p); } ysr@1280: virtual void do_oop(narrowOop* p) { do_oop_nv(p); } ysr@777: bool apply_to_weak_ref_discovered_field() { return true; } ysr@777: bool do_header() { return false; } ysr@777: void set_region(HeapRegion* from) { ysr@777: _oc->set_region(from); ysr@777: } ysr@777: }; ysr@777: ysr@777: class FilterOutOfRegionClosure: public OopClosure { ysr@777: HeapWord* _r_bottom; ysr@777: HeapWord* _r_end; ysr@777: OopClosure* _oc; ysr@777: int _out_of_region; ysr@777: public: ysr@777: FilterOutOfRegionClosure(HeapRegion* r, OopClosure* oc); ysr@1280: template void do_oop_nv(T* p); ysr@1280: virtual void do_oop(oop* p) { do_oop_nv(p); } ysr@1280: virtual void do_oop(narrowOop* p) { do_oop_nv(p); } ysr@777: bool apply_to_weak_ref_discovered_field() { return true; } ysr@777: bool do_header() { return false; } ysr@777: int out_of_region() { return _out_of_region; } ysr@777: };