Thu, 11 Feb 2010 15:52:19 -0800
6923991: G1: improve scalability of RSet scanning
Summary: Implemented block-based work stealing. Moved copying during the rset scanning phase to the main copying phase. Made the size of rset table depend on the region size.
Reviewed-by: apetrusenko, tonyp
1 /*
2 * Copyright 2001-2009 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
25 class HeapRegion;
26 class G1CollectedHeap;
27 class G1RemSet;
28 class HRInto_G1RemSet;
29 class G1RemSet;
30 class ConcurrentMark;
31 class DirtyCardToOopClosure;
32 class CMBitMap;
33 class CMMarkStack;
34 class G1ParScanThreadState;
36 // A class that scans oops in a given heap region (much as OopsInGenClosure
37 // scans oops in a generation.)
38 class OopsInHeapRegionClosure: public OopsInGenClosure {
39 protected:
40 HeapRegion* _from;
41 public:
42 virtual void set_region(HeapRegion* from) { _from = from; }
43 };
45 class G1ParClosureSuper : public OopsInHeapRegionClosure {
46 protected:
47 G1CollectedHeap* _g1;
48 G1RemSet* _g1_rem;
49 ConcurrentMark* _cm;
50 G1ParScanThreadState* _par_scan_state;
51 public:
52 G1ParClosureSuper(G1CollectedHeap* g1, G1ParScanThreadState* par_scan_state);
53 bool apply_to_weak_ref_discovered_field() { return true; }
54 };
56 class G1ParPushHeapRSClosure : public G1ParClosureSuper {
57 public:
58 G1ParPushHeapRSClosure(G1CollectedHeap* g1, G1ParScanThreadState* par_scan_state) :
59 G1ParClosureSuper(g1, par_scan_state) { }
60 template <class T> void do_oop_nv(T* p);
61 virtual void do_oop(oop* p) { do_oop_nv(p); }
62 virtual void do_oop(narrowOop* p) { do_oop_nv(p); }
63 };
65 class G1ParScanClosure : public G1ParClosureSuper {
66 public:
67 G1ParScanClosure(G1CollectedHeap* g1, G1ParScanThreadState* par_scan_state) :
68 G1ParClosureSuper(g1, par_scan_state) { }
69 template <class T> void do_oop_nv(T* p);
70 virtual void do_oop(oop* p) { do_oop_nv(p); }
71 virtual void do_oop(narrowOop* p) { do_oop_nv(p); }
72 };
74 #define G1_PARTIAL_ARRAY_MASK 0x2
76 template <class T> inline bool has_partial_array_mask(T* ref) {
77 return ((uintptr_t)ref & G1_PARTIAL_ARRAY_MASK) == G1_PARTIAL_ARRAY_MASK;
78 }
80 template <class T> inline T* set_partial_array_mask(T obj) {
81 assert(((uintptr_t)obj & G1_PARTIAL_ARRAY_MASK) == 0, "Information loss!");
82 return (T*) ((uintptr_t)obj | G1_PARTIAL_ARRAY_MASK);
83 }
85 template <class T> inline oop clear_partial_array_mask(T* ref) {
86 return oop((intptr_t)ref & ~G1_PARTIAL_ARRAY_MASK);
87 }
89 class G1ParScanPartialArrayClosure : public G1ParClosureSuper {
90 G1ParScanClosure _scanner;
91 public:
92 G1ParScanPartialArrayClosure(G1CollectedHeap* g1, G1ParScanThreadState* par_scan_state) :
93 G1ParClosureSuper(g1, par_scan_state), _scanner(g1, par_scan_state) { }
94 template <class T> void do_oop_nv(T* p);
95 virtual void do_oop(oop* p) { do_oop_nv(p); }
96 virtual void do_oop(narrowOop* p) { do_oop_nv(p); }
97 };
100 class G1ParCopyHelper : public G1ParClosureSuper {
101 G1ParScanClosure *_scanner;
102 protected:
103 template <class T> void mark_forwardee(T* p);
104 oop copy_to_survivor_space(oop obj);
105 public:
106 G1ParCopyHelper(G1CollectedHeap* g1, G1ParScanThreadState* par_scan_state,
107 G1ParScanClosure *scanner) :
108 G1ParClosureSuper(g1, par_scan_state), _scanner(scanner) { }
109 };
111 template<bool do_gen_barrier, G1Barrier barrier,
112 bool do_mark_forwardee>
113 class G1ParCopyClosure : public G1ParCopyHelper {
114 G1ParScanClosure _scanner;
115 template <class T> void do_oop_work(T* p);
116 public:
117 G1ParCopyClosure(G1CollectedHeap* g1, G1ParScanThreadState* par_scan_state) :
118 _scanner(g1, par_scan_state), G1ParCopyHelper(g1, par_scan_state, &_scanner) { }
119 template <class T> void do_oop_nv(T* p) {
120 do_oop_work(p);
121 if (do_mark_forwardee)
122 mark_forwardee(p);
123 }
124 virtual void do_oop(oop* p) { do_oop_nv(p); }
125 virtual void do_oop(narrowOop* p) { do_oop_nv(p); }
126 };
128 typedef G1ParCopyClosure<false, G1BarrierNone, false> G1ParScanExtRootClosure;
129 typedef G1ParCopyClosure<true, G1BarrierNone, false> G1ParScanPermClosure;
130 typedef G1ParCopyClosure<false, G1BarrierRS, false> G1ParScanHeapRSClosure;
131 typedef G1ParCopyClosure<false, G1BarrierNone, true> G1ParScanAndMarkExtRootClosure;
132 typedef G1ParCopyClosure<true, G1BarrierNone, true> G1ParScanAndMarkPermClosure;
133 typedef G1ParCopyClosure<false, G1BarrierRS, true> G1ParScanAndMarkHeapRSClosure;
135 // This is the only case when we set skip_cset_test. Basically, this
136 // closure is (should?) only be called directly while we're draining
137 // the overflow and task queues. In that case we know that the
138 // reference in question points into the collection set, otherwise we
139 // would not have pushed it on the queue. The following is defined in
140 // g1_specialized_oop_closures.hpp.
141 // typedef G1ParCopyClosure<false, G1BarrierEvac, false, true> G1ParScanHeapEvacClosure;
142 // We need a separate closure to handle references during evacuation
143 // failure processing, as we cannot asume that the reference already
144 // points into the collection set (like G1ParScanHeapEvacClosure does).
145 typedef G1ParCopyClosure<false, G1BarrierEvac, false> G1ParScanHeapEvacFailureClosure;
147 class FilterIntoCSClosure: public OopClosure {
148 G1CollectedHeap* _g1;
149 OopClosure* _oc;
150 DirtyCardToOopClosure* _dcto_cl;
151 public:
152 FilterIntoCSClosure( DirtyCardToOopClosure* dcto_cl,
153 G1CollectedHeap* g1, OopClosure* oc) :
154 _dcto_cl(dcto_cl), _g1(g1), _oc(oc)
155 {}
156 template <class T> void do_oop_nv(T* p);
157 virtual void do_oop(oop* p) { do_oop_nv(p); }
158 virtual void do_oop(narrowOop* p) { do_oop_nv(p); }
159 bool apply_to_weak_ref_discovered_field() { return true; }
160 bool do_header() { return false; }
161 };
163 class FilterInHeapRegionAndIntoCSClosure : public OopsInHeapRegionClosure {
164 G1CollectedHeap* _g1;
165 OopsInHeapRegionClosure* _oc;
166 public:
167 FilterInHeapRegionAndIntoCSClosure(G1CollectedHeap* g1,
168 OopsInHeapRegionClosure* oc) :
169 _g1(g1), _oc(oc)
170 {}
171 template <class T> void do_oop_nv(T* p);
172 virtual void do_oop(oop* p) { do_oop_nv(p); }
173 virtual void do_oop(narrowOop* p) { do_oop_nv(p); }
174 bool apply_to_weak_ref_discovered_field() { return true; }
175 bool do_header() { return false; }
176 void set_region(HeapRegion* from) {
177 _oc->set_region(from);
178 }
179 };
181 class FilterAndMarkInHeapRegionAndIntoCSClosure : public OopsInHeapRegionClosure {
182 G1CollectedHeap* _g1;
183 ConcurrentMark* _cm;
184 OopsInHeapRegionClosure* _oc;
185 public:
186 FilterAndMarkInHeapRegionAndIntoCSClosure(G1CollectedHeap* g1,
187 OopsInHeapRegionClosure* oc,
188 ConcurrentMark* cm)
189 : _g1(g1), _oc(oc), _cm(cm) { }
191 template <class T> void do_oop_nv(T* p);
192 virtual void do_oop(oop* p) { do_oop_nv(p); }
193 virtual void do_oop(narrowOop* p) { do_oop_nv(p); }
194 bool apply_to_weak_ref_discovered_field() { return true; }
195 bool do_header() { return false; }
196 void set_region(HeapRegion* from) {
197 _oc->set_region(from);
198 }
199 };
201 class FilterOutOfRegionClosure: public OopClosure {
202 HeapWord* _r_bottom;
203 HeapWord* _r_end;
204 OopClosure* _oc;
205 int _out_of_region;
206 public:
207 FilterOutOfRegionClosure(HeapRegion* r, OopClosure* oc);
208 template <class T> void do_oop_nv(T* p);
209 virtual void do_oop(oop* p) { do_oop_nv(p); }
210 virtual void do_oop(narrowOop* p) { do_oop_nv(p); }
211 bool apply_to_weak_ref_discovered_field() { return true; }
212 bool do_header() { return false; }
213 int out_of_region() { return _out_of_region; }
214 };