ysr@777: /* ysr@777: * Copyright 2001-2007 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: ysr@777: class G1ScanAndBalanceClosure : public OopClosure { ysr@777: G1CollectedHeap* _g1; ysr@777: static int _nq; ysr@777: public: ysr@777: G1ScanAndBalanceClosure(G1CollectedHeap* g1) : _g1(g1) { } ysr@777: inline void do_oop_nv(oop* p); ysr@777: inline void do_oop_nv(narrowOop* p) { guarantee(false, "NYI"); } ysr@777: virtual void do_oop(oop* p); ysr@777: virtual void do_oop(narrowOop* p) { guarantee(false, "NYI"); } 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: 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@777: void do_oop_nv(oop* p); // should be made inline ysr@777: inline void do_oop_nv(narrowOop* p) { guarantee(false, "NYI"); } 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: #define G1_PARTIAL_ARRAY_MASK 1 ysr@777: tonyp@961: inline bool has_partial_array_mask(oop* ref) { tonyp@961: return (intptr_t) ref & G1_PARTIAL_ARRAY_MASK; tonyp@961: } tonyp@961: tonyp@961: inline oop* set_partial_array_mask(oop obj) { tonyp@961: return (oop*) ((intptr_t) obj | G1_PARTIAL_ARRAY_MASK); tonyp@961: } tonyp@961: tonyp@961: inline oop clear_partial_array_mask(oop* ref) { tonyp@961: 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: template void process_array_chunk(oop obj, int start, int end); 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@777: void do_oop_nv(oop* p); ysr@777: void do_oop_nv(narrowOop* p) { guarantee(false, "NYI"); } 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@777: void mark_forwardee(oop* 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@777: void do_oop_work(oop* p); ysr@777: void do_oop_work(narrowOop* p) { guarantee(false, "NYI"); } 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@777: inline void do_oop_nv(oop* p) { ysr@777: do_oop_work(p); ysr@777: if (do_mark_forwardee) ysr@777: mark_forwardee(p); ysr@777: } ysr@777: inline void do_oop_nv(narrowOop* p) { guarantee(false, "NYI"); } 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: tonyp@961: typedef G1ParCopyClosure G1ParScanExtRootClosure; tonyp@961: typedef G1ParCopyClosure G1ParScanPermClosure; tonyp@961: typedef G1ParCopyClosure G1ParScanAndMarkExtRootClosure; tonyp@961: typedef G1ParCopyClosure G1ParScanAndMarkPermClosure; tonyp@961: typedef G1ParCopyClosure G1ParScanHeapRSClosure; tonyp@961: typedef G1ParCopyClosure G1ParScanAndMarkHeapRSClosure; 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 tonyp@961: // would not have pushed it on the queue. tonyp@961: typedef G1ParCopyClosure G1ParScanHeapEvacClosure; tonyp@961: // We need a separate closure to handle references during evacuation tonyp@961: // failure processing, as it cannot asume that the reference already tonyp@961: // points to the collection set (like G1ParScanHeapEvacClosure does). tonyp@961: 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@777: inline void do_oop_nv(oop* p); ysr@777: inline void do_oop_nv(narrowOop* p) { guarantee(false, "NYI"); } ysr@777: virtual void do_oop(oop* p); ysr@777: virtual void do_oop(narrowOop* p) { guarantee(false, "NYI"); } 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@777: inline void do_oop_nv(oop* p); ysr@777: inline void do_oop_nv(narrowOop* p) { guarantee(false, "NYI"); } ysr@777: virtual void do_oop(oop* p); ysr@777: virtual void do_oop(narrowOop* p) { guarantee(false, "NYI"); } 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@777: inline void do_oop_nv(oop* p); ysr@777: inline void do_oop_nv(narrowOop* p) { guarantee(false, "NYI"); } ysr@777: virtual void do_oop(oop* p); ysr@777: virtual void do_oop(narrowOop* p) { guarantee(false, "NYI"); } 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@777: inline void do_oop_nv(oop* p); ysr@777: inline void do_oop_nv(narrowOop* p) { guarantee(false, "NYI"); } ysr@777: virtual void do_oop(oop* p); ysr@777: virtual void do_oop(narrowOop* p) { guarantee(false, "NYI"); } 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: };