src/share/vm/memory/referenceProcessor.hpp

Mon, 20 Sep 2010 14:38:38 -0700

author
jmasa
date
Mon, 20 Sep 2010 14:38:38 -0700
changeset 2188
8b10f48633dc
parent 1907
c18cbe5936b8
child 2198
0715f0cf171d
permissions
-rw-r--r--

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

duke@435 1 /*
jmasa@2188 2 * Copyright (c) 2001, 2010, 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
duke@435 25 // ReferenceProcessor class encapsulates the per-"collector" processing
ysr@888 26 // of java.lang.Reference objects for GC. The interface is useful for supporting
duke@435 27 // a generational abstraction, in particular when there are multiple
duke@435 28 // generations that are being independently collected -- possibly
duke@435 29 // concurrently and/or incrementally. Note, however, that the
duke@435 30 // ReferenceProcessor class abstracts away from a generational setting
duke@435 31 // by using only a heap interval (called "span" below), thus allowing
duke@435 32 // its use in a straightforward manner in a general, non-generational
duke@435 33 // setting.
duke@435 34 //
duke@435 35 // The basic idea is that each ReferenceProcessor object concerns
duke@435 36 // itself with ("weak") reference processing in a specific "span"
duke@435 37 // of the heap of interest to a specific collector. Currently,
duke@435 38 // the span is a convex interval of the heap, but, efficiency
duke@435 39 // apart, there seems to be no reason it couldn't be extended
duke@435 40 // (with appropriate modifications) to any "non-convex interval".
duke@435 41
duke@435 42 // forward references
duke@435 43 class ReferencePolicy;
duke@435 44 class AbstractRefProcTaskExecutor;
duke@435 45 class DiscoveredList;
duke@435 46
duke@435 47 class ReferenceProcessor : public CHeapObj {
duke@435 48 protected:
duke@435 49 // End of list marker
duke@435 50 static oop _sentinelRef;
duke@435 51 MemRegion _span; // (right-open) interval of heap
duke@435 52 // subject to wkref discovery
duke@435 53 bool _discovering_refs; // true when discovery enabled
duke@435 54 bool _discovery_is_atomic; // if discovery is atomic wrt
duke@435 55 // other collectors in configuration
duke@435 56 bool _discovery_is_mt; // true if reference discovery is MT.
ysr@777 57 // If true, setting "next" field of a discovered refs list requires
ysr@777 58 // write barrier(s). (Must be true if used in a collector in which
ysr@777 59 // elements of a discovered list may be moved during discovery: for
ysr@777 60 // example, a collector like Garbage-First that moves objects during a
ysr@777 61 // long-term concurrent marking phase that does weak reference
ysr@777 62 // discovery.)
ysr@777 63 bool _discovered_list_needs_barrier;
ysr@777 64 BarrierSet* _bs; // Cached copy of BarrierSet.
duke@435 65 bool _enqueuing_is_done; // true if all weak references enqueued
duke@435 66 bool _processing_is_mt; // true during phases when
duke@435 67 // reference processing is MT.
duke@435 68 int _next_id; // round-robin counter in
duke@435 69 // support of work distribution
duke@435 70
duke@435 71 // For collectors that do not keep GC marking information
duke@435 72 // in the object header, this field holds a closure that
duke@435 73 // helps the reference processor determine the reachability
duke@435 74 // of an oop (the field is currently initialized to NULL for
duke@435 75 // all collectors but the CMS collector).
duke@435 76 BoolObjectClosure* _is_alive_non_header;
duke@435 77
ysr@888 78 // Soft ref clearing policies
ysr@888 79 // . the default policy
ysr@888 80 static ReferencePolicy* _default_soft_ref_policy;
ysr@888 81 // . the "clear all" policy
ysr@888 82 static ReferencePolicy* _always_clear_soft_ref_policy;
ysr@888 83 // . the current policy below is either one of the above
ysr@888 84 ReferencePolicy* _current_soft_ref_policy;
ysr@888 85
duke@435 86 // The discovered ref lists themselves
coleenp@548 87
jmasa@2188 88 // The active MT'ness degree of the queues below
coleenp@548 89 int _num_q;
jmasa@2188 90 // The maximum MT'ness degree of the queues below
jmasa@2188 91 int _max_num_q;
coleenp@548 92 // Arrays of lists of oops, one per thread
coleenp@548 93 DiscoveredList* _discoveredSoftRefs;
duke@435 94 DiscoveredList* _discoveredWeakRefs;
duke@435 95 DiscoveredList* _discoveredFinalRefs;
duke@435 96 DiscoveredList* _discoveredPhantomRefs;
duke@435 97
duke@435 98 public:
coleenp@548 99 int num_q() { return _num_q; }
jmasa@2188 100 void set_mt_degree(int v) { _num_q = v; }
duke@435 101 DiscoveredList* discovered_soft_refs() { return _discoveredSoftRefs; }
coleenp@548 102 static oop sentinel_ref() { return _sentinelRef; }
coleenp@548 103 static oop* adr_sentinel_ref() { return &_sentinelRef; }
ysr@892 104 ReferencePolicy* setup_policy(bool always_clear) {
ysr@888 105 _current_soft_ref_policy = always_clear ?
ysr@888 106 _always_clear_soft_ref_policy : _default_soft_ref_policy;
ysr@892 107 _current_soft_ref_policy->setup(); // snapshot the policy threshold
ysr@888 108 return _current_soft_ref_policy;
ysr@888 109 }
duke@435 110
duke@435 111 public:
duke@435 112 // Process references with a certain reachability level.
duke@435 113 void process_discovered_reflist(DiscoveredList refs_lists[],
duke@435 114 ReferencePolicy* policy,
duke@435 115 bool clear_referent,
duke@435 116 BoolObjectClosure* is_alive,
duke@435 117 OopClosure* keep_alive,
duke@435 118 VoidClosure* complete_gc,
duke@435 119 AbstractRefProcTaskExecutor* task_executor);
duke@435 120
duke@435 121 void process_phaseJNI(BoolObjectClosure* is_alive,
duke@435 122 OopClosure* keep_alive,
duke@435 123 VoidClosure* complete_gc);
duke@435 124
duke@435 125 // Work methods used by the method process_discovered_reflist
duke@435 126 // Phase1: keep alive all those referents that are otherwise
duke@435 127 // dead but which must be kept alive by policy (and their closure).
coleenp@548 128 void process_phase1(DiscoveredList& refs_list,
duke@435 129 ReferencePolicy* policy,
duke@435 130 BoolObjectClosure* is_alive,
duke@435 131 OopClosure* keep_alive,
duke@435 132 VoidClosure* complete_gc);
duke@435 133 // Phase2: remove all those references whose referents are
duke@435 134 // reachable.
coleenp@548 135 inline void process_phase2(DiscoveredList& refs_list,
duke@435 136 BoolObjectClosure* is_alive,
duke@435 137 OopClosure* keep_alive,
duke@435 138 VoidClosure* complete_gc) {
duke@435 139 if (discovery_is_atomic()) {
duke@435 140 // complete_gc is ignored in this case for this phase
coleenp@548 141 pp2_work(refs_list, is_alive, keep_alive);
duke@435 142 } else {
duke@435 143 assert(complete_gc != NULL, "Error");
coleenp@548 144 pp2_work_concurrent_discovery(refs_list, is_alive,
duke@435 145 keep_alive, complete_gc);
duke@435 146 }
duke@435 147 }
duke@435 148 // Work methods in support of process_phase2
coleenp@548 149 void pp2_work(DiscoveredList& refs_list,
duke@435 150 BoolObjectClosure* is_alive,
duke@435 151 OopClosure* keep_alive);
duke@435 152 void pp2_work_concurrent_discovery(
coleenp@548 153 DiscoveredList& refs_list,
duke@435 154 BoolObjectClosure* is_alive,
duke@435 155 OopClosure* keep_alive,
duke@435 156 VoidClosure* complete_gc);
duke@435 157 // Phase3: process the referents by either clearing them
duke@435 158 // or keeping them alive (and their closure)
coleenp@548 159 void process_phase3(DiscoveredList& refs_list,
duke@435 160 bool clear_referent,
duke@435 161 BoolObjectClosure* is_alive,
duke@435 162 OopClosure* keep_alive,
duke@435 163 VoidClosure* complete_gc);
duke@435 164
duke@435 165 // Enqueue references with a certain reachability level
coleenp@548 166 void enqueue_discovered_reflist(DiscoveredList& refs_list, HeapWord* pending_list_addr);
duke@435 167
duke@435 168 // "Preclean" all the discovered reference lists
duke@435 169 // by removing references with strongly reachable referents.
duke@435 170 // The first argument is a predicate on an oop that indicates
duke@435 171 // its (strong) reachability and the second is a closure that
duke@435 172 // may be used to incrementalize or abort the precleaning process.
duke@435 173 // The caller is responsible for taking care of potential
duke@435 174 // interference with concurrent operations on these lists
duke@435 175 // (or predicates involved) by other threads. Currently
jmasa@1625 176 // only used by the CMS collector. should_unload_classes is
jmasa@1625 177 // used to aid assertion checking when classes are collected.
duke@435 178 void preclean_discovered_references(BoolObjectClosure* is_alive,
duke@435 179 OopClosure* keep_alive,
duke@435 180 VoidClosure* complete_gc,
jmasa@1625 181 YieldClosure* yield,
jmasa@1625 182 bool should_unload_classes);
duke@435 183
duke@435 184 // Delete entries in the discovered lists that have
duke@435 185 // either a null referent or are not active. Such
duke@435 186 // Reference objects can result from the clearing
duke@435 187 // or enqueueing of Reference objects concurrent
duke@435 188 // with their discovery by a (concurrent) collector.
duke@435 189 // For a definition of "active" see java.lang.ref.Reference;
duke@435 190 // Refs are born active, become inactive when enqueued,
duke@435 191 // and never become active again. The state of being
duke@435 192 // active is encoded as follows: A Ref is active
duke@435 193 // if and only if its "next" field is NULL.
duke@435 194 void clean_up_discovered_references();
duke@435 195 void clean_up_discovered_reflist(DiscoveredList& refs_list);
duke@435 196
duke@435 197 // Returns the name of the discovered reference list
duke@435 198 // occupying the i / _num_q slot.
duke@435 199 const char* list_name(int i);
duke@435 200
coleenp@548 201 void enqueue_discovered_reflists(HeapWord* pending_list_addr, AbstractRefProcTaskExecutor* task_executor);
coleenp@548 202
duke@435 203 protected:
duke@435 204 // "Preclean" the given discovered reference list
duke@435 205 // by removing references with strongly reachable referents.
duke@435 206 // Currently used in support of CMS only.
duke@435 207 void preclean_discovered_reflist(DiscoveredList& refs_list,
duke@435 208 BoolObjectClosure* is_alive,
duke@435 209 OopClosure* keep_alive,
duke@435 210 VoidClosure* complete_gc,
duke@435 211 YieldClosure* yield);
duke@435 212
duke@435 213 int next_id() {
duke@435 214 int id = _next_id;
duke@435 215 if (++_next_id == _num_q) {
duke@435 216 _next_id = 0;
duke@435 217 }
duke@435 218 return id;
duke@435 219 }
duke@435 220 DiscoveredList* get_discovered_list(ReferenceType rt);
duke@435 221 inline void add_to_discovered_list_mt(DiscoveredList& refs_list, oop obj,
coleenp@548 222 HeapWord* discovered_addr);
duke@435 223 void verify_ok_to_handle_reflists() PRODUCT_RETURN;
duke@435 224
duke@435 225 void abandon_partial_discovered_list(DiscoveredList& refs_list);
duke@435 226
duke@435 227 // Calculate the number of jni handles.
duke@435 228 unsigned int count_jni_refs();
duke@435 229
duke@435 230 // Balances reference queues.
duke@435 231 void balance_queues(DiscoveredList ref_lists[]);
duke@435 232
duke@435 233 // Update (advance) the soft ref master clock field.
duke@435 234 void update_soft_ref_master_clock();
duke@435 235
duke@435 236 public:
duke@435 237 // constructor
duke@435 238 ReferenceProcessor():
duke@435 239 _span((HeapWord*)NULL, (HeapWord*)NULL),
duke@435 240 _discoveredSoftRefs(NULL), _discoveredWeakRefs(NULL),
duke@435 241 _discoveredFinalRefs(NULL), _discoveredPhantomRefs(NULL),
duke@435 242 _discovering_refs(false),
duke@435 243 _discovery_is_atomic(true),
duke@435 244 _enqueuing_is_done(false),
duke@435 245 _discovery_is_mt(false),
ysr@777 246 _discovered_list_needs_barrier(false),
ysr@777 247 _bs(NULL),
duke@435 248 _is_alive_non_header(NULL),
duke@435 249 _num_q(0),
jmasa@2188 250 _max_num_q(0),
duke@435 251 _processing_is_mt(false),
duke@435 252 _next_id(0)
duke@435 253 {}
duke@435 254
duke@435 255 ReferenceProcessor(MemRegion span, bool atomic_discovery,
ysr@777 256 bool mt_discovery,
ysr@777 257 int mt_degree = 1,
ysr@777 258 bool mt_processing = false,
ysr@777 259 bool discovered_list_needs_barrier = false);
duke@435 260
duke@435 261 // Allocates and initializes a reference processor.
duke@435 262 static ReferenceProcessor* create_ref_processor(
duke@435 263 MemRegion span,
duke@435 264 bool atomic_discovery,
duke@435 265 bool mt_discovery,
duke@435 266 BoolObjectClosure* is_alive_non_header = NULL,
duke@435 267 int parallel_gc_threads = 1,
ysr@777 268 bool mt_processing = false,
ysr@777 269 bool discovered_list_needs_barrier = false);
johnc@1679 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;
duke@435 342 static void verify();
duke@435 343
duke@435 344 // clear the discovered lists (unlinking each entry).
duke@435 345 void clear_discovered_references() PRODUCT_RETURN;
duke@435 346 };
duke@435 347
duke@435 348 // A utility class to disable reference discovery in
duke@435 349 // the scope which contains it, for given ReferenceProcessor.
duke@435 350 class NoRefDiscovery: StackObj {
duke@435 351 private:
duke@435 352 ReferenceProcessor* _rp;
duke@435 353 bool _was_discovering_refs;
duke@435 354 public:
duke@435 355 NoRefDiscovery(ReferenceProcessor* rp) : _rp(rp) {
duke@435 356 if (_was_discovering_refs = _rp->discovery_enabled()) {
duke@435 357 _rp->disable_discovery();
duke@435 358 }
duke@435 359 }
duke@435 360
duke@435 361 ~NoRefDiscovery() {
duke@435 362 if (_was_discovering_refs) {
duke@435 363 _rp->enable_discovery();
duke@435 364 }
duke@435 365 }
duke@435 366 };
duke@435 367
duke@435 368
duke@435 369 // A utility class to temporarily mutate the span of the
duke@435 370 // given ReferenceProcessor in the scope that contains it.
duke@435 371 class ReferenceProcessorSpanMutator: StackObj {
duke@435 372 private:
duke@435 373 ReferenceProcessor* _rp;
duke@435 374 MemRegion _saved_span;
duke@435 375
duke@435 376 public:
duke@435 377 ReferenceProcessorSpanMutator(ReferenceProcessor* rp,
duke@435 378 MemRegion span):
duke@435 379 _rp(rp) {
duke@435 380 _saved_span = _rp->span();
duke@435 381 _rp->set_span(span);
duke@435 382 }
duke@435 383
duke@435 384 ~ReferenceProcessorSpanMutator() {
duke@435 385 _rp->set_span(_saved_span);
duke@435 386 }
duke@435 387 };
duke@435 388
duke@435 389 // A utility class to temporarily change the MT'ness of
duke@435 390 // reference discovery for the given ReferenceProcessor
duke@435 391 // in the scope that contains it.
duke@435 392 class ReferenceProcessorMTMutator: StackObj {
duke@435 393 private:
duke@435 394 ReferenceProcessor* _rp;
duke@435 395 bool _saved_mt;
duke@435 396
duke@435 397 public:
duke@435 398 ReferenceProcessorMTMutator(ReferenceProcessor* rp,
duke@435 399 bool mt):
duke@435 400 _rp(rp) {
duke@435 401 _saved_mt = _rp->discovery_is_mt();
duke@435 402 _rp->set_mt_discovery(mt);
duke@435 403 }
duke@435 404
duke@435 405 ~ReferenceProcessorMTMutator() {
duke@435 406 _rp->set_mt_discovery(_saved_mt);
duke@435 407 }
duke@435 408 };
duke@435 409
duke@435 410
duke@435 411 // A utility class to temporarily change the disposition
duke@435 412 // of the "is_alive_non_header" closure field of the
duke@435 413 // given ReferenceProcessor in the scope that contains it.
duke@435 414 class ReferenceProcessorIsAliveMutator: StackObj {
duke@435 415 private:
duke@435 416 ReferenceProcessor* _rp;
duke@435 417 BoolObjectClosure* _saved_cl;
duke@435 418
duke@435 419 public:
duke@435 420 ReferenceProcessorIsAliveMutator(ReferenceProcessor* rp,
duke@435 421 BoolObjectClosure* cl):
duke@435 422 _rp(rp) {
duke@435 423 _saved_cl = _rp->is_alive_non_header();
duke@435 424 _rp->set_is_alive_non_header(cl);
duke@435 425 }
duke@435 426
duke@435 427 ~ReferenceProcessorIsAliveMutator() {
duke@435 428 _rp->set_is_alive_non_header(_saved_cl);
duke@435 429 }
duke@435 430 };
duke@435 431
duke@435 432 // A utility class to temporarily change the disposition
duke@435 433 // of the "discovery_is_atomic" field of the
duke@435 434 // given ReferenceProcessor in the scope that contains it.
duke@435 435 class ReferenceProcessorAtomicMutator: StackObj {
duke@435 436 private:
duke@435 437 ReferenceProcessor* _rp;
duke@435 438 bool _saved_atomic_discovery;
duke@435 439
duke@435 440 public:
duke@435 441 ReferenceProcessorAtomicMutator(ReferenceProcessor* rp,
duke@435 442 bool atomic):
duke@435 443 _rp(rp) {
duke@435 444 _saved_atomic_discovery = _rp->discovery_is_atomic();
duke@435 445 _rp->set_atomic_discovery(atomic);
duke@435 446 }
duke@435 447
duke@435 448 ~ReferenceProcessorAtomicMutator() {
duke@435 449 _rp->set_atomic_discovery(_saved_atomic_discovery);
duke@435 450 }
duke@435 451 };
duke@435 452
duke@435 453
duke@435 454 // A utility class to temporarily change the MT processing
duke@435 455 // disposition of the given ReferenceProcessor instance
duke@435 456 // in the scope that contains it.
duke@435 457 class ReferenceProcessorMTProcMutator: StackObj {
duke@435 458 private:
duke@435 459 ReferenceProcessor* _rp;
duke@435 460 bool _saved_mt;
duke@435 461
duke@435 462 public:
duke@435 463 ReferenceProcessorMTProcMutator(ReferenceProcessor* rp,
duke@435 464 bool mt):
duke@435 465 _rp(rp) {
duke@435 466 _saved_mt = _rp->processing_is_mt();
duke@435 467 _rp->set_mt_processing(mt);
duke@435 468 }
duke@435 469
duke@435 470 ~ReferenceProcessorMTProcMutator() {
duke@435 471 _rp->set_mt_processing(_saved_mt);
duke@435 472 }
duke@435 473 };
duke@435 474
duke@435 475
duke@435 476 // This class is an interface used to implement task execution for the
duke@435 477 // reference processing.
duke@435 478 class AbstractRefProcTaskExecutor {
duke@435 479 public:
duke@435 480
duke@435 481 // Abstract tasks to execute.
duke@435 482 class ProcessTask;
duke@435 483 class EnqueueTask;
duke@435 484
duke@435 485 // Executes a task using worker threads.
duke@435 486 virtual void execute(ProcessTask& task) = 0;
duke@435 487 virtual void execute(EnqueueTask& task) = 0;
duke@435 488
duke@435 489 // Switch to single threaded mode.
duke@435 490 virtual void set_single_threaded_mode() { };
duke@435 491 };
duke@435 492
duke@435 493 // Abstract reference processing task to execute.
duke@435 494 class AbstractRefProcTaskExecutor::ProcessTask {
duke@435 495 protected:
duke@435 496 ProcessTask(ReferenceProcessor& ref_processor,
duke@435 497 DiscoveredList refs_lists[],
duke@435 498 bool marks_oops_alive)
duke@435 499 : _ref_processor(ref_processor),
duke@435 500 _refs_lists(refs_lists),
duke@435 501 _marks_oops_alive(marks_oops_alive)
duke@435 502 { }
duke@435 503
duke@435 504 public:
duke@435 505 virtual void work(unsigned int work_id, BoolObjectClosure& is_alive,
duke@435 506 OopClosure& keep_alive,
duke@435 507 VoidClosure& complete_gc) = 0;
duke@435 508
duke@435 509 // Returns true if a task marks some oops as alive.
duke@435 510 bool marks_oops_alive() const
duke@435 511 { return _marks_oops_alive; }
duke@435 512
duke@435 513 protected:
duke@435 514 ReferenceProcessor& _ref_processor;
duke@435 515 DiscoveredList* _refs_lists;
duke@435 516 const bool _marks_oops_alive;
duke@435 517 };
duke@435 518
duke@435 519 // Abstract reference processing task to execute.
duke@435 520 class AbstractRefProcTaskExecutor::EnqueueTask {
duke@435 521 protected:
duke@435 522 EnqueueTask(ReferenceProcessor& ref_processor,
duke@435 523 DiscoveredList refs_lists[],
coleenp@548 524 HeapWord* pending_list_addr,
duke@435 525 oop sentinel_ref,
duke@435 526 int n_queues)
duke@435 527 : _ref_processor(ref_processor),
duke@435 528 _refs_lists(refs_lists),
duke@435 529 _pending_list_addr(pending_list_addr),
duke@435 530 _sentinel_ref(sentinel_ref),
duke@435 531 _n_queues(n_queues)
duke@435 532 { }
duke@435 533
duke@435 534 public:
duke@435 535 virtual void work(unsigned int work_id) = 0;
duke@435 536
duke@435 537 protected:
duke@435 538 ReferenceProcessor& _ref_processor;
duke@435 539 DiscoveredList* _refs_lists;
coleenp@548 540 HeapWord* _pending_list_addr;
duke@435 541 oop _sentinel_ref;
duke@435 542 int _n_queues;
duke@435 543 };

mercurial