Mon, 29 Aug 2011 10:13:06 -0700
7080389: G1: refactor marking code in evacuation pause copy closures
Summary: Refactor code marking code in the evacuation pause copy closures so that an evacuated object is only marked by the thread that successfully copies it.
Reviewed-by: stefank, brutisso, tonyp
ysr@777 | 1 | /* |
tonyp@2962 | 2 | * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved. |
ysr@777 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ysr@777 | 4 | * |
ysr@777 | 5 | * This code is free software; you can redistribute it and/or modify it |
ysr@777 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ysr@777 | 7 | * published by the Free Software Foundation. |
ysr@777 | 8 | * |
ysr@777 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
ysr@777 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ysr@777 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ysr@777 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
ysr@777 | 13 | * accompanied this code). |
ysr@777 | 14 | * |
ysr@777 | 15 | * You should have received a copy of the GNU General Public License version |
ysr@777 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
ysr@777 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ysr@777 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
ysr@777 | 22 | * |
ysr@777 | 23 | */ |
ysr@777 | 24 | |
stefank@2314 | 25 | #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1OOPCLOSURES_HPP |
stefank@2314 | 26 | #define SHARE_VM_GC_IMPLEMENTATION_G1_G1OOPCLOSURES_HPP |
stefank@2314 | 27 | |
ysr@777 | 28 | class HeapRegion; |
ysr@777 | 29 | class G1CollectedHeap; |
ysr@777 | 30 | class G1RemSet; |
ysr@777 | 31 | class ConcurrentMark; |
ysr@777 | 32 | class DirtyCardToOopClosure; |
ysr@777 | 33 | class CMBitMap; |
ysr@777 | 34 | class CMMarkStack; |
ysr@777 | 35 | class G1ParScanThreadState; |
tonyp@2968 | 36 | class CMTask; |
ysr@777 | 37 | |
ysr@777 | 38 | // A class that scans oops in a given heap region (much as OopsInGenClosure |
ysr@777 | 39 | // scans oops in a generation.) |
ysr@777 | 40 | class OopsInHeapRegionClosure: public OopsInGenClosure { |
ysr@777 | 41 | protected: |
ysr@777 | 42 | HeapRegion* _from; |
ysr@777 | 43 | public: |
tonyp@2962 | 44 | void set_region(HeapRegion* from) { _from = from; } |
ysr@777 | 45 | }; |
ysr@777 | 46 | |
ysr@777 | 47 | class G1ParClosureSuper : public OopsInHeapRegionClosure { |
ysr@777 | 48 | protected: |
ysr@777 | 49 | G1CollectedHeap* _g1; |
ysr@777 | 50 | G1RemSet* _g1_rem; |
ysr@777 | 51 | ConcurrentMark* _cm; |
ysr@777 | 52 | G1ParScanThreadState* _par_scan_state; |
johnc@3086 | 53 | bool _during_initial_mark; |
johnc@3086 | 54 | bool _mark_in_progress; |
ysr@777 | 55 | public: |
ysr@777 | 56 | G1ParClosureSuper(G1CollectedHeap* g1, G1ParScanThreadState* par_scan_state); |
ysr@777 | 57 | bool apply_to_weak_ref_discovered_field() { return true; } |
ysr@777 | 58 | }; |
ysr@777 | 59 | |
iveresov@1696 | 60 | class G1ParPushHeapRSClosure : public G1ParClosureSuper { |
iveresov@1696 | 61 | public: |
iveresov@1696 | 62 | G1ParPushHeapRSClosure(G1CollectedHeap* g1, G1ParScanThreadState* par_scan_state) : |
iveresov@1696 | 63 | G1ParClosureSuper(g1, par_scan_state) { } |
iveresov@1696 | 64 | template <class T> void do_oop_nv(T* p); |
iveresov@1696 | 65 | virtual void do_oop(oop* p) { do_oop_nv(p); } |
iveresov@1696 | 66 | virtual void do_oop(narrowOop* p) { do_oop_nv(p); } |
iveresov@1696 | 67 | }; |
iveresov@1696 | 68 | |
ysr@777 | 69 | class G1ParScanClosure : public G1ParClosureSuper { |
ysr@777 | 70 | public: |
ysr@777 | 71 | G1ParScanClosure(G1CollectedHeap* g1, G1ParScanThreadState* par_scan_state) : |
ysr@777 | 72 | G1ParClosureSuper(g1, par_scan_state) { } |
ysr@1280 | 73 | template <class T> void do_oop_nv(T* p); |
ysr@777 | 74 | virtual void do_oop(oop* p) { do_oop_nv(p); } |
ysr@777 | 75 | virtual void do_oop(narrowOop* p) { do_oop_nv(p); } |
ysr@777 | 76 | }; |
ysr@777 | 77 | |
ysr@1280 | 78 | #define G1_PARTIAL_ARRAY_MASK 0x2 |
ysr@777 | 79 | |
ysr@1280 | 80 | template <class T> inline bool has_partial_array_mask(T* ref) { |
ysr@1280 | 81 | return ((uintptr_t)ref & G1_PARTIAL_ARRAY_MASK) == G1_PARTIAL_ARRAY_MASK; |
tonyp@961 | 82 | } |
tonyp@961 | 83 | |
ysr@1280 | 84 | template <class T> inline T* set_partial_array_mask(T obj) { |
ysr@1280 | 85 | assert(((uintptr_t)obj & G1_PARTIAL_ARRAY_MASK) == 0, "Information loss!"); |
ysr@1280 | 86 | return (T*) ((uintptr_t)obj | G1_PARTIAL_ARRAY_MASK); |
tonyp@961 | 87 | } |
tonyp@961 | 88 | |
ysr@1280 | 89 | template <class T> inline oop clear_partial_array_mask(T* ref) { |
ysr@1280 | 90 | return oop((intptr_t)ref & ~G1_PARTIAL_ARRAY_MASK); |
tonyp@961 | 91 | } |
tonyp@961 | 92 | |
ysr@777 | 93 | class G1ParScanPartialArrayClosure : public G1ParClosureSuper { |
ysr@777 | 94 | G1ParScanClosure _scanner; |
ysr@777 | 95 | public: |
ysr@777 | 96 | G1ParScanPartialArrayClosure(G1CollectedHeap* g1, G1ParScanThreadState* par_scan_state) : |
ysr@777 | 97 | G1ParClosureSuper(g1, par_scan_state), _scanner(g1, par_scan_state) { } |
ysr@1280 | 98 | template <class T> void do_oop_nv(T* p); |
ysr@777 | 99 | virtual void do_oop(oop* p) { do_oop_nv(p); } |
ysr@777 | 100 | virtual void do_oop(narrowOop* p) { do_oop_nv(p); } |
ysr@777 | 101 | }; |
ysr@777 | 102 | |
ysr@777 | 103 | |
ysr@777 | 104 | class G1ParCopyHelper : public G1ParClosureSuper { |
ysr@777 | 105 | G1ParScanClosure *_scanner; |
ysr@777 | 106 | protected: |
johnc@3086 | 107 | template <class T> void mark_object(T* p); |
johnc@3086 | 108 | oop copy_to_survivor_space(oop obj, bool should_mark_copy); |
ysr@777 | 109 | public: |
ysr@777 | 110 | G1ParCopyHelper(G1CollectedHeap* g1, G1ParScanThreadState* par_scan_state, |
ysr@777 | 111 | G1ParScanClosure *scanner) : |
ysr@777 | 112 | G1ParClosureSuper(g1, par_scan_state), _scanner(scanner) { } |
ysr@777 | 113 | }; |
ysr@777 | 114 | |
tonyp@961 | 115 | template<bool do_gen_barrier, G1Barrier barrier, |
johnc@3086 | 116 | bool do_mark_object> |
ysr@777 | 117 | class G1ParCopyClosure : public G1ParCopyHelper { |
ysr@777 | 118 | G1ParScanClosure _scanner; |
ysr@1280 | 119 | template <class T> void do_oop_work(T* p); |
ysr@777 | 120 | public: |
ysr@777 | 121 | G1ParCopyClosure(G1CollectedHeap* g1, G1ParScanThreadState* par_scan_state) : |
ysr@777 | 122 | _scanner(g1, par_scan_state), G1ParCopyHelper(g1, par_scan_state, &_scanner) { } |
ysr@1280 | 123 | template <class T> void do_oop_nv(T* p) { |
ysr@777 | 124 | do_oop_work(p); |
ysr@777 | 125 | } |
ysr@777 | 126 | virtual void do_oop(oop* p) { do_oop_nv(p); } |
ysr@777 | 127 | virtual void do_oop(narrowOop* p) { do_oop_nv(p); } |
ysr@777 | 128 | }; |
ysr@777 | 129 | |
iveresov@1696 | 130 | typedef G1ParCopyClosure<false, G1BarrierNone, false> G1ParScanExtRootClosure; |
iveresov@1696 | 131 | typedef G1ParCopyClosure<true, G1BarrierNone, false> G1ParScanPermClosure; |
iveresov@1696 | 132 | typedef G1ParCopyClosure<false, G1BarrierRS, false> G1ParScanHeapRSClosure; |
iveresov@1696 | 133 | typedef G1ParCopyClosure<false, G1BarrierNone, true> G1ParScanAndMarkExtRootClosure; |
iveresov@1696 | 134 | typedef G1ParCopyClosure<true, G1BarrierNone, true> G1ParScanAndMarkPermClosure; |
iveresov@1696 | 135 | typedef G1ParCopyClosure<false, G1BarrierRS, true> G1ParScanAndMarkHeapRSClosure; |
iveresov@1696 | 136 | |
tonyp@961 | 137 | // This is the only case when we set skip_cset_test. Basically, this |
tonyp@961 | 138 | // closure is (should?) only be called directly while we're draining |
tonyp@961 | 139 | // the overflow and task queues. In that case we know that the |
tonyp@961 | 140 | // reference in question points into the collection set, otherwise we |
ysr@1280 | 141 | // would not have pushed it on the queue. The following is defined in |
ysr@1280 | 142 | // g1_specialized_oop_closures.hpp. |
ysr@1280 | 143 | // typedef G1ParCopyClosure<false, G1BarrierEvac, false, true> G1ParScanHeapEvacClosure; |
tonyp@961 | 144 | // We need a separate closure to handle references during evacuation |
ysr@1280 | 145 | // failure processing, as we cannot asume that the reference already |
ysr@1280 | 146 | // points into the collection set (like G1ParScanHeapEvacClosure does). |
iveresov@1696 | 147 | typedef G1ParCopyClosure<false, G1BarrierEvac, false> G1ParScanHeapEvacFailureClosure; |
ysr@777 | 148 | |
ysr@777 | 149 | class FilterIntoCSClosure: public OopClosure { |
ysr@777 | 150 | G1CollectedHeap* _g1; |
ysr@777 | 151 | OopClosure* _oc; |
ysr@777 | 152 | DirtyCardToOopClosure* _dcto_cl; |
ysr@777 | 153 | public: |
ysr@777 | 154 | FilterIntoCSClosure( DirtyCardToOopClosure* dcto_cl, |
ysr@777 | 155 | G1CollectedHeap* g1, OopClosure* oc) : |
ysr@777 | 156 | _dcto_cl(dcto_cl), _g1(g1), _oc(oc) |
ysr@777 | 157 | {} |
ysr@1280 | 158 | template <class T> void do_oop_nv(T* p); |
ysr@1280 | 159 | virtual void do_oop(oop* p) { do_oop_nv(p); } |
ysr@1280 | 160 | virtual void do_oop(narrowOop* p) { do_oop_nv(p); } |
ysr@777 | 161 | bool apply_to_weak_ref_discovered_field() { return true; } |
ysr@777 | 162 | bool do_header() { return false; } |
ysr@777 | 163 | }; |
ysr@777 | 164 | |
ysr@777 | 165 | class FilterOutOfRegionClosure: public OopClosure { |
ysr@777 | 166 | HeapWord* _r_bottom; |
ysr@777 | 167 | HeapWord* _r_end; |
ysr@777 | 168 | OopClosure* _oc; |
ysr@777 | 169 | int _out_of_region; |
ysr@777 | 170 | public: |
ysr@777 | 171 | FilterOutOfRegionClosure(HeapRegion* r, OopClosure* oc); |
ysr@1280 | 172 | template <class T> void do_oop_nv(T* p); |
ysr@1280 | 173 | virtual void do_oop(oop* p) { do_oop_nv(p); } |
ysr@1280 | 174 | virtual void do_oop(narrowOop* p) { do_oop_nv(p); } |
ysr@777 | 175 | bool apply_to_weak_ref_discovered_field() { return true; } |
ysr@777 | 176 | bool do_header() { return false; } |
ysr@777 | 177 | int out_of_region() { return _out_of_region; } |
ysr@777 | 178 | }; |
stefank@2314 | 179 | |
tonyp@2968 | 180 | // Closure for iterating over object fields during concurrent marking |
tonyp@2968 | 181 | class G1CMOopClosure : public OopClosure { |
tonyp@2968 | 182 | G1CollectedHeap* _g1h; |
tonyp@2968 | 183 | ConcurrentMark* _cm; |
tonyp@2968 | 184 | CMTask* _task; |
tonyp@2968 | 185 | public: |
tonyp@2968 | 186 | G1CMOopClosure(G1CollectedHeap* g1h, ConcurrentMark* cm, CMTask* task); |
tonyp@2968 | 187 | template <class T> void do_oop_nv(T* p); |
tonyp@2968 | 188 | virtual void do_oop( oop* p) { do_oop_nv(p); } |
tonyp@2968 | 189 | virtual void do_oop(narrowOop* p) { do_oop_nv(p); } |
tonyp@2968 | 190 | }; |
tonyp@2968 | 191 | |
stefank@2314 | 192 | #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1OOPCLOSURES_HPP |