Mercurial > hg > graal-compiler
annotate src/share/vm/memory/referenceProcessor.hpp @ 1833:8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
Summary: Associate number of GC workers with the workgang as opposed to the task.
Reviewed-by: johnc, ysr
author | jmasa |
---|---|
date | Mon, 20 Sep 2010 14:38:38 -0700 |
parents | c18cbe5936b8 |
children | 0715f0cf171d |
rev | line source |
---|---|
0 | 1 /* |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
2 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1244
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1244
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1244
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
25 // ReferenceProcessor class encapsulates the per-"collector" processing | |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
356
diff
changeset
|
26 // of java.lang.Reference objects for GC. The interface is useful for supporting |
0 | 27 // a generational abstraction, in particular when there are multiple |
28 // generations that are being independently collected -- possibly | |
29 // concurrently and/or incrementally. Note, however, that the | |
30 // ReferenceProcessor class abstracts away from a generational setting | |
31 // by using only a heap interval (called "span" below), thus allowing | |
32 // its use in a straightforward manner in a general, non-generational | |
33 // setting. | |
34 // | |
35 // The basic idea is that each ReferenceProcessor object concerns | |
36 // itself with ("weak") reference processing in a specific "span" | |
37 // of the heap of interest to a specific collector. Currently, | |
38 // the span is a convex interval of the heap, but, efficiency | |
39 // apart, there seems to be no reason it couldn't be extended | |
40 // (with appropriate modifications) to any "non-convex interval". | |
41 | |
42 // forward references | |
43 class ReferencePolicy; | |
44 class AbstractRefProcTaskExecutor; | |
45 class DiscoveredList; | |
46 | |
47 class ReferenceProcessor : public CHeapObj { | |
48 protected: | |
49 // End of list marker | |
50 static oop _sentinelRef; | |
51 MemRegion _span; // (right-open) interval of heap | |
52 // subject to wkref discovery | |
53 bool _discovering_refs; // true when discovery enabled | |
54 bool _discovery_is_atomic; // if discovery is atomic wrt | |
55 // other collectors in configuration | |
56 bool _discovery_is_mt; // true if reference discovery is MT. | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
57 // If true, setting "next" field of a discovered refs list requires |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
58 // write barrier(s). (Must be true if used in a collector in which |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
59 // elements of a discovered list may be moved during discovery: for |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
60 // example, a collector like Garbage-First that moves objects during a |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
61 // long-term concurrent marking phase that does weak reference |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
62 // discovery.) |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
63 bool _discovered_list_needs_barrier; |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
64 BarrierSet* _bs; // Cached copy of BarrierSet. |
0 | 65 bool _enqueuing_is_done; // true if all weak references enqueued |
66 bool _processing_is_mt; // true during phases when | |
67 // reference processing is MT. | |
68 int _next_id; // round-robin counter in | |
69 // support of work distribution | |
70 | |
71 // For collectors that do not keep GC marking information | |
72 // in the object header, this field holds a closure that | |
73 // helps the reference processor determine the reachability | |
74 // of an oop (the field is currently initialized to NULL for | |
75 // all collectors but the CMS collector). | |
76 BoolObjectClosure* _is_alive_non_header; | |
77 | |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
356
diff
changeset
|
78 // Soft ref clearing policies |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
356
diff
changeset
|
79 // . the default policy |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
356
diff
changeset
|
80 static ReferencePolicy* _default_soft_ref_policy; |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
356
diff
changeset
|
81 // . the "clear all" policy |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
356
diff
changeset
|
82 static ReferencePolicy* _always_clear_soft_ref_policy; |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
356
diff
changeset
|
83 // . the current policy below is either one of the above |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
356
diff
changeset
|
84 ReferencePolicy* _current_soft_ref_policy; |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
356
diff
changeset
|
85 |
0 | 86 // The discovered ref lists themselves |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
87 |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
88 // The active MT'ness degree of the queues below |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
89 int _num_q; |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
90 // The maximum MT'ness degree of the queues below |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
91 int _max_num_q; |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
92 // Arrays of lists of oops, one per thread |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
93 DiscoveredList* _discoveredSoftRefs; |
0 | 94 DiscoveredList* _discoveredWeakRefs; |
95 DiscoveredList* _discoveredFinalRefs; | |
96 DiscoveredList* _discoveredPhantomRefs; | |
97 | |
98 public: | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
99 int num_q() { return _num_q; } |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
100 void set_mt_degree(int v) { _num_q = v; } |
0 | 101 DiscoveredList* discovered_soft_refs() { return _discoveredSoftRefs; } |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
102 static oop sentinel_ref() { return _sentinelRef; } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
103 static oop* adr_sentinel_ref() { return &_sentinelRef; } |
457
27a80744a83b
6778647: snap(), snap_policy() should be renamed setup(), setup_policy()
ysr
parents:
453
diff
changeset
|
104 ReferencePolicy* setup_policy(bool always_clear) { |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
356
diff
changeset
|
105 _current_soft_ref_policy = always_clear ? |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
356
diff
changeset
|
106 _always_clear_soft_ref_policy : _default_soft_ref_policy; |
457
27a80744a83b
6778647: snap(), snap_policy() should be renamed setup(), setup_policy()
ysr
parents:
453
diff
changeset
|
107 _current_soft_ref_policy->setup(); // snapshot the policy threshold |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
356
diff
changeset
|
108 return _current_soft_ref_policy; |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
356
diff
changeset
|
109 } |
0 | 110 |
111 public: | |
112 // Process references with a certain reachability level. | |
113 void process_discovered_reflist(DiscoveredList refs_lists[], | |
114 ReferencePolicy* policy, | |
115 bool clear_referent, | |
116 BoolObjectClosure* is_alive, | |
117 OopClosure* keep_alive, | |
118 VoidClosure* complete_gc, | |
119 AbstractRefProcTaskExecutor* task_executor); | |
120 | |
121 void process_phaseJNI(BoolObjectClosure* is_alive, | |
122 OopClosure* keep_alive, | |
123 VoidClosure* complete_gc); | |
124 | |
125 // Work methods used by the method process_discovered_reflist | |
126 // Phase1: keep alive all those referents that are otherwise | |
127 // dead but which must be kept alive by policy (and their closure). | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
128 void process_phase1(DiscoveredList& refs_list, |
0 | 129 ReferencePolicy* policy, |
130 BoolObjectClosure* is_alive, | |
131 OopClosure* keep_alive, | |
132 VoidClosure* complete_gc); | |
133 // Phase2: remove all those references whose referents are | |
134 // reachable. | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
135 inline void process_phase2(DiscoveredList& refs_list, |
0 | 136 BoolObjectClosure* is_alive, |
137 OopClosure* keep_alive, | |
138 VoidClosure* complete_gc) { | |
139 if (discovery_is_atomic()) { | |
140 // complete_gc is ignored in this case for this phase | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
141 pp2_work(refs_list, is_alive, keep_alive); |
0 | 142 } else { |
143 assert(complete_gc != NULL, "Error"); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
144 pp2_work_concurrent_discovery(refs_list, is_alive, |
0 | 145 keep_alive, complete_gc); |
146 } | |
147 } | |
148 // Work methods in support of process_phase2 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
149 void pp2_work(DiscoveredList& refs_list, |
0 | 150 BoolObjectClosure* is_alive, |
151 OopClosure* keep_alive); | |
152 void pp2_work_concurrent_discovery( | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
153 DiscoveredList& refs_list, |
0 | 154 BoolObjectClosure* is_alive, |
155 OopClosure* keep_alive, | |
156 VoidClosure* complete_gc); | |
157 // Phase3: process the referents by either clearing them | |
158 // or keeping them alive (and their closure) | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
159 void process_phase3(DiscoveredList& refs_list, |
0 | 160 bool clear_referent, |
161 BoolObjectClosure* is_alive, | |
162 OopClosure* keep_alive, | |
163 VoidClosure* complete_gc); | |
164 | |
165 // Enqueue references with a certain reachability level | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
166 void enqueue_discovered_reflist(DiscoveredList& refs_list, HeapWord* pending_list_addr); |
0 | 167 |
168 // "Preclean" all the discovered reference lists | |
169 // by removing references with strongly reachable referents. | |
170 // The first argument is a predicate on an oop that indicates | |
171 // its (strong) reachability and the second is a closure that | |
172 // may be used to incrementalize or abort the precleaning process. | |
173 // The caller is responsible for taking care of potential | |
174 // interference with concurrent operations on these lists | |
175 // (or predicates involved) by other threads. Currently | |
1190
4788266644c1
6895236: CMS: cmsOopClosures.inline.hpp:43 assert(..., "Should remember klasses in this context")
jmasa
parents:
457
diff
changeset
|
176 // only used by the CMS collector. should_unload_classes is |
4788266644c1
6895236: CMS: cmsOopClosures.inline.hpp:43 assert(..., "Should remember klasses in this context")
jmasa
parents:
457
diff
changeset
|
177 // used to aid assertion checking when classes are collected. |
0 | 178 void preclean_discovered_references(BoolObjectClosure* is_alive, |
179 OopClosure* keep_alive, | |
180 VoidClosure* complete_gc, | |
1190
4788266644c1
6895236: CMS: cmsOopClosures.inline.hpp:43 assert(..., "Should remember klasses in this context")
jmasa
parents:
457
diff
changeset
|
181 YieldClosure* yield, |
4788266644c1
6895236: CMS: cmsOopClosures.inline.hpp:43 assert(..., "Should remember klasses in this context")
jmasa
parents:
457
diff
changeset
|
182 bool should_unload_classes); |
0 | 183 |
184 // Delete entries in the discovered lists that have | |
185 // either a null referent or are not active. Such | |
186 // Reference objects can result from the clearing | |
187 // or enqueueing of Reference objects concurrent | |
188 // with their discovery by a (concurrent) collector. | |
189 // For a definition of "active" see java.lang.ref.Reference; | |
190 // Refs are born active, become inactive when enqueued, | |
191 // and never become active again. The state of being | |
192 // active is encoded as follows: A Ref is active | |
193 // if and only if its "next" field is NULL. | |
194 void clean_up_discovered_references(); | |
195 void clean_up_discovered_reflist(DiscoveredList& refs_list); | |
196 | |
197 // Returns the name of the discovered reference list | |
198 // occupying the i / _num_q slot. | |
199 const char* list_name(int i); | |
200 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
201 void enqueue_discovered_reflists(HeapWord* pending_list_addr, AbstractRefProcTaskExecutor* task_executor); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
202 |
0 | 203 protected: |
204 // "Preclean" the given discovered reference list | |
205 // by removing references with strongly reachable referents. | |
206 // Currently used in support of CMS only. | |
207 void preclean_discovered_reflist(DiscoveredList& refs_list, | |
208 BoolObjectClosure* is_alive, | |
209 OopClosure* keep_alive, | |
210 VoidClosure* complete_gc, | |
211 YieldClosure* yield); | |
212 | |
213 int next_id() { | |
214 int id = _next_id; | |
215 if (++_next_id == _num_q) { | |
216 _next_id = 0; | |
217 } | |
218 return id; | |
219 } | |
220 DiscoveredList* get_discovered_list(ReferenceType rt); | |
221 inline void add_to_discovered_list_mt(DiscoveredList& refs_list, oop obj, | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
222 HeapWord* discovered_addr); |
0 | 223 void verify_ok_to_handle_reflists() PRODUCT_RETURN; |
224 | |
225 void abandon_partial_discovered_list(DiscoveredList& refs_list); | |
226 | |
227 // Calculate the number of jni handles. | |
228 unsigned int count_jni_refs(); | |
229 | |
230 // Balances reference queues. | |
231 void balance_queues(DiscoveredList ref_lists[]); | |
232 | |
233 // Update (advance) the soft ref master clock field. | |
234 void update_soft_ref_master_clock(); | |
235 | |
236 public: | |
237 // constructor | |
238 ReferenceProcessor(): | |
239 _span((HeapWord*)NULL, (HeapWord*)NULL), | |
240 _discoveredSoftRefs(NULL), _discoveredWeakRefs(NULL), | |
241 _discoveredFinalRefs(NULL), _discoveredPhantomRefs(NULL), | |
242 _discovering_refs(false), | |
243 _discovery_is_atomic(true), | |
244 _enqueuing_is_done(false), | |
245 _discovery_is_mt(false), | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
246 _discovered_list_needs_barrier(false), |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
247 _bs(NULL), |
0 | 248 _is_alive_non_header(NULL), |
249 _num_q(0), | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
250 _max_num_q(0), |
0 | 251 _processing_is_mt(false), |
252 _next_id(0) | |
253 {} | |
254 | |
255 ReferenceProcessor(MemRegion span, bool atomic_discovery, | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
256 bool mt_discovery, |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
257 int mt_degree = 1, |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
258 bool mt_processing = false, |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
259 bool discovered_list_needs_barrier = false); |
0 | 260 |
261 // Allocates and initializes a reference processor. | |
262 static ReferenceProcessor* create_ref_processor( | |
263 MemRegion span, | |
264 bool atomic_discovery, | |
265 bool mt_discovery, | |
266 BoolObjectClosure* is_alive_non_header = NULL, | |
267 int parallel_gc_threads = 1, | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
268 bool mt_processing = false, |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
269 bool discovered_list_needs_barrier = false); |
1244
745c853ee57f
6885297: java -XX:RefDiscoveryPolicy=2 or -XX:TLABWasteTargetPercent=0 cause VM crash
johnc
parents:
1190
diff
changeset
|
270 |
0 | 271 // RefDiscoveryPolicy values |
1244
745c853ee57f
6885297: java -XX:RefDiscoveryPolicy=2 or -XX:TLABWasteTargetPercent=0 cause VM crash
johnc
parents:
1190
diff
changeset
|
272 enum DiscoveryPolicy { |
0 | 273 ReferenceBasedDiscovery = 0, |
1244
745c853ee57f
6885297: java -XX:RefDiscoveryPolicy=2 or -XX:TLABWasteTargetPercent=0 cause VM crash
johnc
parents:
1190
diff
changeset
|
274 ReferentBasedDiscovery = 1, |
745c853ee57f
6885297: java -XX:RefDiscoveryPolicy=2 or -XX:TLABWasteTargetPercent=0 cause VM crash
johnc
parents:
1190
diff
changeset
|
275 DiscoveryPolicyMin = ReferenceBasedDiscovery, |
745c853ee57f
6885297: java -XX:RefDiscoveryPolicy=2 or -XX:TLABWasteTargetPercent=0 cause VM crash
johnc
parents:
1190
diff
changeset
|
276 DiscoveryPolicyMax = ReferentBasedDiscovery |
0 | 277 }; |
278 | |
279 static void init_statics(); | |
280 | |
281 public: | |
282 // get and set "is_alive_non_header" field | |
283 BoolObjectClosure* is_alive_non_header() { | |
284 return _is_alive_non_header; | |
285 } | |
286 void set_is_alive_non_header(BoolObjectClosure* is_alive_non_header) { | |
287 _is_alive_non_header = is_alive_non_header; | |
288 } | |
289 | |
290 // get and set span | |
291 MemRegion span() { return _span; } | |
292 void set_span(MemRegion span) { _span = span; } | |
293 | |
294 // start and stop weak ref discovery | |
295 void enable_discovery() { _discovering_refs = true; } | |
296 void disable_discovery() { _discovering_refs = false; } | |
297 bool discovery_enabled() { return _discovering_refs; } | |
298 | |
299 // whether discovery is atomic wrt other collectors | |
300 bool discovery_is_atomic() const { return _discovery_is_atomic; } | |
301 void set_atomic_discovery(bool atomic) { _discovery_is_atomic = atomic; } | |
302 | |
303 // whether discovery is done by multiple threads same-old-timeously | |
304 bool discovery_is_mt() const { return _discovery_is_mt; } | |
305 void set_mt_discovery(bool mt) { _discovery_is_mt = mt; } | |
306 | |
307 // Whether we are in a phase when _processing_ is MT. | |
308 bool processing_is_mt() const { return _processing_is_mt; } | |
309 void set_mt_processing(bool mt) { _processing_is_mt = mt; } | |
310 | |
311 // whether all enqueuing of weak references is complete | |
312 bool enqueuing_is_done() { return _enqueuing_is_done; } | |
313 void set_enqueuing_is_done(bool v) { _enqueuing_is_done = v; } | |
314 | |
315 // iterate over oops | |
316 void weak_oops_do(OopClosure* f); // weak roots | |
317 static void oops_do(OopClosure* f); // strong root(s) | |
318 | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
319 // Balance each of the discovered lists. |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
320 void balance_all_queues(); |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
321 |
0 | 322 // Discover a Reference object, using appropriate discovery criteria |
323 bool discover_reference(oop obj, ReferenceType rt); | |
324 | |
325 // Process references found during GC (called by the garbage collector) | |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
356
diff
changeset
|
326 void process_discovered_references(BoolObjectClosure* is_alive, |
0 | 327 OopClosure* keep_alive, |
328 VoidClosure* complete_gc, | |
329 AbstractRefProcTaskExecutor* task_executor); | |
330 | |
331 public: | |
332 // Enqueue references at end of GC (called by the garbage collector) | |
333 bool enqueue_discovered_references(AbstractRefProcTaskExecutor* task_executor = NULL); | |
334 | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
335 // If a discovery is in process that is being superceded, abandon it: all |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
336 // the discovered lists will be empty, and all the objects on them will |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
337 // have NULL discovered fields. Must be called only at a safepoint. |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
338 void abandon_partial_discovery(); |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
339 |
0 | 340 // debugging |
341 void verify_no_references_recorded() PRODUCT_RETURN; | |
342 static void verify(); | |
343 | |
344 // clear the discovered lists (unlinking each entry). | |
345 void clear_discovered_references() PRODUCT_RETURN; | |
346 }; | |
347 | |
348 // A utility class to disable reference discovery in | |
349 // the scope which contains it, for given ReferenceProcessor. | |
350 class NoRefDiscovery: StackObj { | |
351 private: | |
352 ReferenceProcessor* _rp; | |
353 bool _was_discovering_refs; | |
354 public: | |
355 NoRefDiscovery(ReferenceProcessor* rp) : _rp(rp) { | |
356 if (_was_discovering_refs = _rp->discovery_enabled()) { | |
357 _rp->disable_discovery(); | |
358 } | |
359 } | |
360 | |
361 ~NoRefDiscovery() { | |
362 if (_was_discovering_refs) { | |
363 _rp->enable_discovery(); | |
364 } | |
365 } | |
366 }; | |
367 | |
368 | |
369 // A utility class to temporarily mutate the span of the | |
370 // given ReferenceProcessor in the scope that contains it. | |
371 class ReferenceProcessorSpanMutator: StackObj { | |
372 private: | |
373 ReferenceProcessor* _rp; | |
374 MemRegion _saved_span; | |
375 | |
376 public: | |
377 ReferenceProcessorSpanMutator(ReferenceProcessor* rp, | |
378 MemRegion span): | |
379 _rp(rp) { | |
380 _saved_span = _rp->span(); | |
381 _rp->set_span(span); | |
382 } | |
383 | |
384 ~ReferenceProcessorSpanMutator() { | |
385 _rp->set_span(_saved_span); | |
386 } | |
387 }; | |
388 | |
389 // A utility class to temporarily change the MT'ness of | |
390 // reference discovery for the given ReferenceProcessor | |
391 // in the scope that contains it. | |
392 class ReferenceProcessorMTMutator: StackObj { | |
393 private: | |
394 ReferenceProcessor* _rp; | |
395 bool _saved_mt; | |
396 | |
397 public: | |
398 ReferenceProcessorMTMutator(ReferenceProcessor* rp, | |
399 bool mt): | |
400 _rp(rp) { | |
401 _saved_mt = _rp->discovery_is_mt(); | |
402 _rp->set_mt_discovery(mt); | |
403 } | |
404 | |
405 ~ReferenceProcessorMTMutator() { | |
406 _rp->set_mt_discovery(_saved_mt); | |
407 } | |
408 }; | |
409 | |
410 | |
411 // A utility class to temporarily change the disposition | |
412 // of the "is_alive_non_header" closure field of the | |
413 // given ReferenceProcessor in the scope that contains it. | |
414 class ReferenceProcessorIsAliveMutator: StackObj { | |
415 private: | |
416 ReferenceProcessor* _rp; | |
417 BoolObjectClosure* _saved_cl; | |
418 | |
419 public: | |
420 ReferenceProcessorIsAliveMutator(ReferenceProcessor* rp, | |
421 BoolObjectClosure* cl): | |
422 _rp(rp) { | |
423 _saved_cl = _rp->is_alive_non_header(); | |
424 _rp->set_is_alive_non_header(cl); | |
425 } | |
426 | |
427 ~ReferenceProcessorIsAliveMutator() { | |
428 _rp->set_is_alive_non_header(_saved_cl); | |
429 } | |
430 }; | |
431 | |
432 // A utility class to temporarily change the disposition | |
433 // of the "discovery_is_atomic" field of the | |
434 // given ReferenceProcessor in the scope that contains it. | |
435 class ReferenceProcessorAtomicMutator: StackObj { | |
436 private: | |
437 ReferenceProcessor* _rp; | |
438 bool _saved_atomic_discovery; | |
439 | |
440 public: | |
441 ReferenceProcessorAtomicMutator(ReferenceProcessor* rp, | |
442 bool atomic): | |
443 _rp(rp) { | |
444 _saved_atomic_discovery = _rp->discovery_is_atomic(); | |
445 _rp->set_atomic_discovery(atomic); | |
446 } | |
447 | |
448 ~ReferenceProcessorAtomicMutator() { | |
449 _rp->set_atomic_discovery(_saved_atomic_discovery); | |
450 } | |
451 }; | |
452 | |
453 | |
454 // A utility class to temporarily change the MT processing | |
455 // disposition of the given ReferenceProcessor instance | |
456 // in the scope that contains it. | |
457 class ReferenceProcessorMTProcMutator: StackObj { | |
458 private: | |
459 ReferenceProcessor* _rp; | |
460 bool _saved_mt; | |
461 | |
462 public: | |
463 ReferenceProcessorMTProcMutator(ReferenceProcessor* rp, | |
464 bool mt): | |
465 _rp(rp) { | |
466 _saved_mt = _rp->processing_is_mt(); | |
467 _rp->set_mt_processing(mt); | |
468 } | |
469 | |
470 ~ReferenceProcessorMTProcMutator() { | |
471 _rp->set_mt_processing(_saved_mt); | |
472 } | |
473 }; | |
474 | |
475 | |
476 // This class is an interface used to implement task execution for the | |
477 // reference processing. | |
478 class AbstractRefProcTaskExecutor { | |
479 public: | |
480 | |
481 // Abstract tasks to execute. | |
482 class ProcessTask; | |
483 class EnqueueTask; | |
484 | |
485 // Executes a task using worker threads. | |
486 virtual void execute(ProcessTask& task) = 0; | |
487 virtual void execute(EnqueueTask& task) = 0; | |
488 | |
489 // Switch to single threaded mode. | |
490 virtual void set_single_threaded_mode() { }; | |
491 }; | |
492 | |
493 // Abstract reference processing task to execute. | |
494 class AbstractRefProcTaskExecutor::ProcessTask { | |
495 protected: | |
496 ProcessTask(ReferenceProcessor& ref_processor, | |
497 DiscoveredList refs_lists[], | |
498 bool marks_oops_alive) | |
499 : _ref_processor(ref_processor), | |
500 _refs_lists(refs_lists), | |
501 _marks_oops_alive(marks_oops_alive) | |
502 { } | |
503 | |
504 public: | |
505 virtual void work(unsigned int work_id, BoolObjectClosure& is_alive, | |
506 OopClosure& keep_alive, | |
507 VoidClosure& complete_gc) = 0; | |
508 | |
509 // Returns true if a task marks some oops as alive. | |
510 bool marks_oops_alive() const | |
511 { return _marks_oops_alive; } | |
512 | |
513 protected: | |
514 ReferenceProcessor& _ref_processor; | |
515 DiscoveredList* _refs_lists; | |
516 const bool _marks_oops_alive; | |
517 }; | |
518 | |
519 // Abstract reference processing task to execute. | |
520 class AbstractRefProcTaskExecutor::EnqueueTask { | |
521 protected: | |
522 EnqueueTask(ReferenceProcessor& ref_processor, | |
523 DiscoveredList refs_lists[], | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
524 HeapWord* pending_list_addr, |
0 | 525 oop sentinel_ref, |
526 int n_queues) | |
527 : _ref_processor(ref_processor), | |
528 _refs_lists(refs_lists), | |
529 _pending_list_addr(pending_list_addr), | |
530 _sentinel_ref(sentinel_ref), | |
531 _n_queues(n_queues) | |
532 { } | |
533 | |
534 public: | |
535 virtual void work(unsigned int work_id) = 0; | |
536 | |
537 protected: | |
538 ReferenceProcessor& _ref_processor; | |
539 DiscoveredList* _refs_lists; | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
540 HeapWord* _pending_list_addr; |
0 | 541 oop _sentinel_ref; |
542 int _n_queues; | |
543 }; |