src/share/vm/memory/referenceProcessor.hpp

Thu, 24 Mar 2011 15:47:01 -0700

author
ysr
date
Thu, 24 Mar 2011 15:47:01 -0700
changeset 2710
5134fa1cfe63
parent 2651
92da084fefc9
child 3115
c2bf0120ee5d
permissions
-rw-r--r--

7029036: Card-table verification hangs with all framework collectors, except G1, even before the first GC
Summary: When verifying clean card ranges, use memory-range-bounded iteration over oops of objects overlapping that range, thus avoiding the otherwise quadratic worst-case cost of scanning large object arrays.
Reviewed-by: jmasa, jwilhelm, tonyp

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

mercurial