< prev index next >

src/hotspot/share/gc/shared/referenceProcessor.hpp

Print this page
rev 49758 : imported patch 8201492-properly-implement-non-contiguous-reference-processing


  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_GC_SHARED_REFERENCEPROCESSOR_HPP
  26 #define SHARE_VM_GC_SHARED_REFERENCEPROCESSOR_HPP
  27 
  28 #include "gc/shared/referencePolicy.hpp"
  29 #include "gc/shared/referenceProcessorPhaseTimes.hpp"
  30 #include "gc/shared/referenceProcessorStats.hpp"
  31 #include "memory/referenceType.hpp"
  32 #include "oops/instanceRefKlass.hpp"
  33 
  34 class GCTimer;
  35 
  36 // ReferenceProcessor class encapsulates the per-"collector" processing
  37 // of java.lang.Reference objects for GC. The interface is useful for supporting
  38 // a generational abstraction, in particular when there are multiple
  39 // generations that are being independently collected -- possibly
  40 // concurrently and/or incrementally.  Note, however, that the
  41 // ReferenceProcessor class abstracts away from a generational setting
  42 // by using only a heap interval (called "span" below), thus allowing
  43 // its use in a straightforward manner in a general, non-generational
  44 // setting.

  45 //
  46 // The basic idea is that each ReferenceProcessor object concerns
  47 // itself with ("weak") reference processing in a specific "span"
  48 // of the heap of interest to a specific collector. Currently,
  49 // the span is a convex interval of the heap, but, efficiency
  50 // apart, there seems to be no reason it couldn't be extended
  51 // (with appropriate modifications) to any "non-convex interval".
  52 
  53 // forward references
  54 class ReferencePolicy;
  55 class AbstractRefProcTaskExecutor;
  56 
  57 // List of discovered references.
  58 class DiscoveredList {
  59 public:
  60   DiscoveredList() : _len(0), _compressed_head(0), _oop_head(NULL) { }
  61   inline oop head() const;
  62   HeapWord* adr_head() {
  63     return UseCompressedOops ? (HeapWord*)&_compressed_head :
  64                                (HeapWord*)&_oop_head;
  65   }
  66   inline void set_head(oop o);
  67   inline bool is_empty() const;
  68   size_t length()               { return _len; }
  69   void   set_length(size_t len) { _len = len;  }
  70   void   inc_length(size_t inc) { _len += inc; assert(_len > 0, "Error"); }
  71   void   dec_length(size_t dec) { _len -= dec; }


 150 
 151   // Statistics
 152   NOT_PRODUCT(
 153   inline size_t processed() const { return _processed; }
 154   inline size_t removed() const   { return _removed; }
 155   )
 156 
 157   inline void move_to_next() {
 158     if (_ref == _next) {
 159       // End of the list.
 160       _ref = NULL;
 161     } else {
 162       _ref = _next;
 163     }
 164     assert(_ref != _first_seen, "cyclic ref_list found");
 165     NOT_PRODUCT(_processed++);
 166   }
 167 };
 168 
 169 class ReferenceProcessor : public CHeapObj<mtGC> {
 170 
 171  private:
 172   size_t total_count(DiscoveredList lists[]) const;
 173 
 174  protected:
 175   // The SoftReference master timestamp clock
 176   static jlong _soft_ref_timestamp_clock;
 177 
 178   MemRegion   _span;                    // (right-open) interval of heap
 179                                         // subject to wkref discovery

 180 
 181   bool        _discovering_refs;        // true when discovery enabled
 182   bool        _discovery_is_atomic;     // if discovery is atomic wrt
 183                                         // other collectors in configuration
 184   bool        _discovery_is_mt;         // true if reference discovery is MT.
 185 
 186   bool        _enqueuing_is_done;       // true if all weak references enqueued
 187   bool        _processing_is_mt;        // true during phases when
 188                                         // reference processing is MT.
 189   uint        _next_id;                 // round-robin mod _num_q counter in
 190                                         // support of work distribution
 191 
 192   // For collectors that do not keep GC liveness information
 193   // in the object header, this field holds a closure that
 194   // helps the reference processor determine the reachability
 195   // of an oop. It is currently initialized to NULL for all
 196   // collectors except for CMS and G1.
 197   BoolObjectClosure* _is_alive_non_header;
 198 
 199   // Soft ref clearing policies


 239   // Process references with a certain reachability level.
 240   void process_discovered_reflist(DiscoveredList                refs_lists[],
 241                                   ReferencePolicy*              policy,
 242                                   bool                          clear_referent,
 243                                   BoolObjectClosure*            is_alive,
 244                                   OopClosure*                   keep_alive,
 245                                   VoidClosure*                  complete_gc,
 246                                   AbstractRefProcTaskExecutor*  task_executor,
 247                                   ReferenceProcessorPhaseTimes* phase_times);
 248 
 249   // Work methods used by the method process_discovered_reflist
 250   // Phase1: keep alive all those referents that are otherwise
 251   // dead but which must be kept alive by policy (and their closure).
 252   void process_phase1(DiscoveredList&     refs_list,
 253                       ReferencePolicy*    policy,
 254                       BoolObjectClosure*  is_alive,
 255                       OopClosure*         keep_alive,
 256                       VoidClosure*        complete_gc);
 257   // Phase2: remove all those references whose referents are
 258   // reachable.
 259   inline void process_phase2(DiscoveredList&    refs_list,
 260                              BoolObjectClosure* is_alive,
 261                              OopClosure*        keep_alive,
 262                              VoidClosure*       complete_gc) {
 263     if (discovery_is_atomic()) {
 264       // complete_gc is ignored in this case for this phase
 265       pp2_work(refs_list, is_alive, keep_alive);
 266     } else {
 267       assert(complete_gc != NULL, "Error");
 268       pp2_work_concurrent_discovery(refs_list, is_alive,
 269                                     keep_alive, complete_gc);
 270     }
 271   }
 272   // Work methods in support of process_phase2
 273   void pp2_work(DiscoveredList&    refs_list,
 274                 BoolObjectClosure* is_alive,
 275                 OopClosure*        keep_alive);
 276   void pp2_work_concurrent_discovery(
 277                 DiscoveredList&    refs_list,
 278                 BoolObjectClosure* is_alive,
 279                 OopClosure*        keep_alive,
 280                 VoidClosure*       complete_gc);
 281   // Phase3: process the referents by either clearing them
 282   // or keeping them alive (and their closure)
 283   void process_phase3(DiscoveredList&    refs_list,
 284                       bool               clear_referent,
 285                       BoolObjectClosure* is_alive,
 286                       OopClosure*        keep_alive,
 287                       VoidClosure*       complete_gc);
 288 
 289   // Enqueue references with a certain reachability level
 290   void enqueue_discovered_reflist(DiscoveredList& refs_list);
 291 


 294   // The first argument is a predicate on an oop that indicates
 295   // its (strong) reachability and the second is a closure that
 296   // may be used to incrementalize or abort the precleaning process.
 297   // The caller is responsible for taking care of potential
 298   // interference with concurrent operations on these lists
 299   // (or predicates involved) by other threads. Currently
 300   // only used by the CMS collector.
 301   void preclean_discovered_references(BoolObjectClosure* is_alive,
 302                                       OopClosure*        keep_alive,
 303                                       VoidClosure*       complete_gc,
 304                                       YieldClosure*      yield,
 305                                       GCTimer*           gc_timer);
 306 
 307   // Returns the name of the discovered reference list
 308   // occupying the i / _num_q slot.
 309   const char* list_name(uint i);
 310 
 311   void enqueue_discovered_reflists(AbstractRefProcTaskExecutor* task_executor,
 312                                    ReferenceProcessorPhaseTimes* phase_times);
 313 
 314  protected:
 315   // "Preclean" the given discovered reference list
 316   // by removing references with strongly reachable referents.
 317   // Currently used in support of CMS only.
 318   void preclean_discovered_reflist(DiscoveredList&    refs_list,
 319                                    BoolObjectClosure* is_alive,
 320                                    OopClosure*        keep_alive,
 321                                    VoidClosure*       complete_gc,
 322                                    YieldClosure*      yield);
 323 
 324   // round-robin mod _num_q (not: _not_ mode _max_num_q)
 325   uint next_id() {
 326     uint id = _next_id;
 327     assert(!_discovery_is_mt, "Round robin should only be used in serial discovery");
 328     if (++_next_id == _num_q) {
 329       _next_id = 0;
 330     }
 331     assert(_next_id < _num_q, "_next_id %u _num_q %u _max_num_q %u", _next_id, _num_q, _max_num_q);
 332     return id;
 333   }
 334   DiscoveredList* get_discovered_list(ReferenceType rt);
 335   inline void add_to_discovered_list_mt(DiscoveredList& refs_list, oop obj,
 336                                         HeapWord* discovered_addr);
 337 
 338   void clear_discovered_references(DiscoveredList& refs_list);
 339 
 340   void log_reflist_counts(DiscoveredList ref_lists[], uint active_length, size_t total_count) PRODUCT_RETURN;
 341 
 342   // Balances reference queues.
 343   void balance_queues(DiscoveredList ref_lists[]);
 344 
 345   // Update (advance) the soft ref master clock field.
 346   void update_soft_ref_master_clock();
 347 
 348  public:


 349   // Default parameters give you a vanilla reference processor.
 350   ReferenceProcessor(MemRegion span,
 351                      bool mt_processing = false, uint mt_processing_degree = 1,
 352                      bool mt_discovery  = false, uint mt_discovery_degree  = 1,
 353                      bool atomic_discovery = true,
 354                      BoolObjectClosure* is_alive_non_header = NULL);
 355 
 356   // RefDiscoveryPolicy values
 357   enum DiscoveryPolicy {
 358     ReferenceBasedDiscovery = 0,
 359     ReferentBasedDiscovery  = 1,
 360     DiscoveryPolicyMin      = ReferenceBasedDiscovery,
 361     DiscoveryPolicyMax      = ReferentBasedDiscovery
 362   };
 363 
 364   static void init_statics();
 365 
 366  public:
 367   // get and set "is_alive_non_header" field
 368   BoolObjectClosure* is_alive_non_header() {
 369     return _is_alive_non_header;
 370   }
 371   void set_is_alive_non_header(BoolObjectClosure* is_alive_non_header) {
 372     _is_alive_non_header = is_alive_non_header;
 373   }
 374 
 375   // get and set span
 376   MemRegion span()                   { return _span; }
 377   void      set_span(MemRegion span) { _span = span; }
 378 
 379   // start and stop weak ref discovery
 380   void enable_discovery(bool check_no_refs = true);
 381   void disable_discovery()  { _discovering_refs = false; }
 382   bool discovery_enabled()  { return _discovering_refs;  }
 383 
 384   // whether discovery is atomic wrt other collectors
 385   bool discovery_is_atomic() const { return _discovery_is_atomic; }
 386   void set_atomic_discovery(bool atomic) { _discovery_is_atomic = atomic; }
 387 
 388   // whether discovery is done by multiple threads same-old-timeously
 389   bool discovery_is_mt() const { return _discovery_is_mt; }
 390   void set_mt_discovery(bool mt) { _discovery_is_mt = mt; }
 391 
 392   // Whether we are in a phase when _processing_ is MT.
 393   bool processing_is_mt() const { return _processing_is_mt; }
 394   void set_mt_processing(bool mt) { _processing_is_mt = mt; }
 395 
 396   // whether all enqueueing of weak references is complete
 397   bool enqueuing_is_done()  { return _enqueuing_is_done; }


 417                                 VoidClosure*                  complete_gc,
 418                                 AbstractRefProcTaskExecutor*  task_executor,
 419                                 ReferenceProcessorPhaseTimes* phase_times);
 420 
 421   // Enqueue references at end of GC (called by the garbage collector)
 422   void enqueue_discovered_references(AbstractRefProcTaskExecutor* task_executor,
 423                                      ReferenceProcessorPhaseTimes* phase_times);
 424 
 425   // If a discovery is in process that is being superceded, abandon it: all
 426   // the discovered lists will be empty, and all the objects on them will
 427   // have NULL discovered fields.  Must be called only at a safepoint.
 428   void abandon_partial_discovery();
 429 
 430   size_t total_reference_count(ReferenceType rt) const;
 431 
 432   // debugging
 433   void verify_no_references_recorded() PRODUCT_RETURN;
 434   void verify_referent(oop obj)        PRODUCT_RETURN;
 435 };
 436 



























 437 // A utility class to disable reference discovery in
 438 // the scope which contains it, for given ReferenceProcessor.
 439 class NoRefDiscovery: StackObj {
 440  private:
 441   ReferenceProcessor* _rp;
 442   bool _was_discovering_refs;
 443  public:
 444   NoRefDiscovery(ReferenceProcessor* rp) : _rp(rp) {
 445     _was_discovering_refs = _rp->discovery_enabled();
 446     if (_was_discovering_refs) {
 447       _rp->disable_discovery();
 448     }
 449   }
 450 
 451   ~NoRefDiscovery() {
 452     if (_was_discovering_refs) {
 453       _rp->enable_discovery(false /*check_no_refs*/);
 454     }
 455   }
 456 };
 457 


















 458 
 459 // A utility class to temporarily mutate the span of the
 460 // given ReferenceProcessor in the scope that contains it.
 461 class ReferenceProcessorSpanMutator: StackObj {
 462  private:
 463   ReferenceProcessor* _rp;
 464   MemRegion           _saved_span;
 465 
 466  public:
 467   ReferenceProcessorSpanMutator(ReferenceProcessor* rp,
 468                                 MemRegion span):
 469     _rp(rp) {
 470     _saved_span = _rp->span();
 471     _rp->set_span(span);
 472   }
 473 
 474   ~ReferenceProcessorSpanMutator() {
 475     _rp->set_span(_saved_span);
 476   }
 477 };
 478 
 479 // A utility class to temporarily change the MT'ness of
 480 // reference discovery for the given ReferenceProcessor
 481 // in the scope that contains it.
 482 class ReferenceProcessorMTDiscoveryMutator: StackObj {
 483  private:
 484   ReferenceProcessor* _rp;
 485   bool                _saved_mt;
 486 
 487  public:
 488   ReferenceProcessorMTDiscoveryMutator(ReferenceProcessor* rp,
 489                                        bool mt):
 490     _rp(rp) {
 491     _saved_mt = _rp->discovery_is_mt();
 492     _rp->set_mt_discovery(mt);
 493   }
 494 
 495   ~ReferenceProcessorMTDiscoveryMutator() {
 496     _rp->set_mt_discovery(_saved_mt);
 497   }
 498 };
 499 
 500 
 501 // A utility class to temporarily change the disposition
 502 // of the "is_alive_non_header" closure field of the
 503 // given ReferenceProcessor in the scope that contains it.
 504 class ReferenceProcessorIsAliveMutator: StackObj {
 505  private:
 506   ReferenceProcessor* _rp;
 507   BoolObjectClosure*  _saved_cl;
 508 
 509  public:
 510   ReferenceProcessorIsAliveMutator(ReferenceProcessor* rp,
 511                                    BoolObjectClosure*  cl):
 512     _rp(rp) {
 513     _saved_cl = _rp->is_alive_non_header();
 514     _rp->set_is_alive_non_header(cl);
 515   }
 516 
 517   ~ReferenceProcessorIsAliveMutator() {
 518     _rp->set_is_alive_non_header(_saved_cl);
 519   }




  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_GC_SHARED_REFERENCEPROCESSOR_HPP
  26 #define SHARE_VM_GC_SHARED_REFERENCEPROCESSOR_HPP
  27 
  28 #include "gc/shared/referencePolicy.hpp"
  29 #include "gc/shared/referenceProcessorPhaseTimes.hpp"
  30 #include "gc/shared/referenceProcessorStats.hpp"
  31 #include "memory/referenceType.hpp"
  32 #include "oops/instanceRefKlass.hpp"
  33 
  34 class GCTimer;
  35 
  36 // ReferenceProcessor class encapsulates the per-"collector" processing
  37 // of java.lang.Reference objects for GC. The interface is useful for supporting
  38 // a generational abstraction, in particular when there are multiple
  39 // generations that are being independently collected -- possibly
  40 // concurrently and/or incrementally.
  41 // ReferenceProcessor class abstracts away from a generational setting
  42 // by using a closure that determines whether a given reference or referent are
  43 // subject to this ReferenceProcessor's discovery, thus allowing its use in a
  44 // straightforward manner in a general, non-generational, non-contiguous generation
  45 // (or heap) setting.
  46 //






  47 
  48 // forward references
  49 class ReferencePolicy;
  50 class AbstractRefProcTaskExecutor;
  51 
  52 // List of discovered references.
  53 class DiscoveredList {
  54 public:
  55   DiscoveredList() : _len(0), _compressed_head(0), _oop_head(NULL) { }
  56   inline oop head() const;
  57   HeapWord* adr_head() {
  58     return UseCompressedOops ? (HeapWord*)&_compressed_head :
  59                                (HeapWord*)&_oop_head;
  60   }
  61   inline void set_head(oop o);
  62   inline bool is_empty() const;
  63   size_t length()               { return _len; }
  64   void   set_length(size_t len) { _len = len;  }
  65   void   inc_length(size_t inc) { _len += inc; assert(_len > 0, "Error"); }
  66   void   dec_length(size_t dec) { _len -= dec; }


 145 
 146   // Statistics
 147   NOT_PRODUCT(
 148   inline size_t processed() const { return _processed; }
 149   inline size_t removed() const   { return _removed; }
 150   )
 151 
 152   inline void move_to_next() {
 153     if (_ref == _next) {
 154       // End of the list.
 155       _ref = NULL;
 156     } else {
 157       _ref = _next;
 158     }
 159     assert(_ref != _first_seen, "cyclic ref_list found");
 160     NOT_PRODUCT(_processed++);
 161   }
 162 };
 163 
 164 class ReferenceProcessor : public CHeapObj<mtGC> {


 165   size_t total_count(DiscoveredList lists[]) const;
 166 

 167   // The SoftReference master timestamp clock
 168   static jlong _soft_ref_timestamp_clock;
 169 
 170   BoolObjectClosure* _is_subject_to_discovery; // determines whether a given oop is subject
 171                                                // to this ReferenceProcessor's discovery
 172                                                // (and further processing).
 173 
 174   bool        _discovering_refs;        // true when discovery enabled
 175   bool        _discovery_is_atomic;     // if discovery is atomic wrt
 176                                         // other collectors in configuration
 177   bool        _discovery_is_mt;         // true if reference discovery is MT.
 178 
 179   bool        _enqueuing_is_done;       // true if all weak references enqueued
 180   bool        _processing_is_mt;        // true during phases when
 181                                         // reference processing is MT.
 182   uint        _next_id;                 // round-robin mod _num_q counter in
 183                                         // support of work distribution
 184 
 185   // For collectors that do not keep GC liveness information
 186   // in the object header, this field holds a closure that
 187   // helps the reference processor determine the reachability
 188   // of an oop. It is currently initialized to NULL for all
 189   // collectors except for CMS and G1.
 190   BoolObjectClosure* _is_alive_non_header;
 191 
 192   // Soft ref clearing policies


 232   // Process references with a certain reachability level.
 233   void process_discovered_reflist(DiscoveredList                refs_lists[],
 234                                   ReferencePolicy*              policy,
 235                                   bool                          clear_referent,
 236                                   BoolObjectClosure*            is_alive,
 237                                   OopClosure*                   keep_alive,
 238                                   VoidClosure*                  complete_gc,
 239                                   AbstractRefProcTaskExecutor*  task_executor,
 240                                   ReferenceProcessorPhaseTimes* phase_times);
 241 
 242   // Work methods used by the method process_discovered_reflist
 243   // Phase1: keep alive all those referents that are otherwise
 244   // dead but which must be kept alive by policy (and their closure).
 245   void process_phase1(DiscoveredList&     refs_list,
 246                       ReferencePolicy*    policy,
 247                       BoolObjectClosure*  is_alive,
 248                       OopClosure*         keep_alive,
 249                       VoidClosure*        complete_gc);
 250   // Phase2: remove all those references whose referents are
 251   // reachable.
 252   void process_phase2(DiscoveredList&    refs_list,
 253                       BoolObjectClosure* is_alive,
 254                       OopClosure*        keep_alive,
 255                       VoidClosure*       complete_gc);









 256   // Work methods in support of process_phase2
 257   void pp2_work(DiscoveredList&    refs_list,
 258                 BoolObjectClosure* is_alive,
 259                 OopClosure*        keep_alive);
 260   void pp2_work_concurrent_discovery(
 261                 DiscoveredList&    refs_list,
 262                 BoolObjectClosure* is_alive,
 263                 OopClosure*        keep_alive,
 264                 VoidClosure*       complete_gc);
 265   // Phase3: process the referents by either clearing them
 266   // or keeping them alive (and their closure)
 267   void process_phase3(DiscoveredList&    refs_list,
 268                       bool               clear_referent,
 269                       BoolObjectClosure* is_alive,
 270                       OopClosure*        keep_alive,
 271                       VoidClosure*       complete_gc);
 272 
 273   // Enqueue references with a certain reachability level
 274   void enqueue_discovered_reflist(DiscoveredList& refs_list);
 275 


 278   // The first argument is a predicate on an oop that indicates
 279   // its (strong) reachability and the second is a closure that
 280   // may be used to incrementalize or abort the precleaning process.
 281   // The caller is responsible for taking care of potential
 282   // interference with concurrent operations on these lists
 283   // (or predicates involved) by other threads. Currently
 284   // only used by the CMS collector.
 285   void preclean_discovered_references(BoolObjectClosure* is_alive,
 286                                       OopClosure*        keep_alive,
 287                                       VoidClosure*       complete_gc,
 288                                       YieldClosure*      yield,
 289                                       GCTimer*           gc_timer);
 290 
 291   // Returns the name of the discovered reference list
 292   // occupying the i / _num_q slot.
 293   const char* list_name(uint i);
 294 
 295   void enqueue_discovered_reflists(AbstractRefProcTaskExecutor* task_executor,
 296                                    ReferenceProcessorPhaseTimes* phase_times);
 297 

 298   // "Preclean" the given discovered reference list
 299   // by removing references with strongly reachable referents.
 300   // Currently used in support of CMS only.
 301   void preclean_discovered_reflist(DiscoveredList&    refs_list,
 302                                    BoolObjectClosure* is_alive,
 303                                    OopClosure*        keep_alive,
 304                                    VoidClosure*       complete_gc,
 305                                    YieldClosure*      yield);
 306 private:
 307   // round-robin mod _num_q (not: _not_ mode _max_num_q)
 308   uint next_id() {
 309     uint id = _next_id;
 310     assert(!_discovery_is_mt, "Round robin should only be used in serial discovery");
 311     if (++_next_id == _num_q) {
 312       _next_id = 0;
 313     }
 314     assert(_next_id < _num_q, "_next_id %u _num_q %u _max_num_q %u", _next_id, _num_q, _max_num_q);
 315     return id;
 316   }
 317   DiscoveredList* get_discovered_list(ReferenceType rt);
 318   inline void add_to_discovered_list_mt(DiscoveredList& refs_list, oop obj,
 319                                         HeapWord* discovered_addr);
 320 
 321   void clear_discovered_references(DiscoveredList& refs_list);
 322 
 323   void log_reflist_counts(DiscoveredList ref_lists[], uint active_length, size_t total_count) PRODUCT_RETURN;
 324 
 325   // Balances reference queues.
 326   void balance_queues(DiscoveredList ref_lists[]);
 327 
 328   // Update (advance) the soft ref master clock field.
 329   void update_soft_ref_master_clock();
 330 
 331   template <class T>
 332   bool is_subject_to_discovery(T const obj) const;
 333 public:
 334   // Default parameters give you a vanilla reference processor.
 335   ReferenceProcessor(BoolObjectClosure* is_subject_to_discovery,
 336                      bool mt_processing = false, uint mt_processing_degree = 1,
 337                      bool mt_discovery  = false, uint mt_discovery_degree  = 1,
 338                      bool atomic_discovery = true,
 339                      BoolObjectClosure* is_alive_non_header = NULL);
 340 
 341   // RefDiscoveryPolicy values
 342   enum DiscoveryPolicy {
 343     ReferenceBasedDiscovery = 0,
 344     ReferentBasedDiscovery  = 1,
 345     DiscoveryPolicyMin      = ReferenceBasedDiscovery,
 346     DiscoveryPolicyMax      = ReferentBasedDiscovery
 347   };
 348 
 349   static void init_statics();
 350 
 351  public:
 352   // get and set "is_alive_non_header" field
 353   BoolObjectClosure* is_alive_non_header() {
 354     return _is_alive_non_header;
 355   }
 356   void set_is_alive_non_header(BoolObjectClosure* is_alive_non_header) {
 357     _is_alive_non_header = is_alive_non_header;
 358   }
 359 
 360   BoolObjectClosure* is_subject_to_discovery_closure() const { return _is_subject_to_discovery; }
 361   void set_is_subject_to_discovery_closure(BoolObjectClosure* cl) { _is_subject_to_discovery = cl; }

 362 
 363   // start and stop weak ref discovery
 364   void enable_discovery(bool check_no_refs = true);
 365   void disable_discovery()  { _discovering_refs = false; }
 366   bool discovery_enabled()  { return _discovering_refs;  }
 367 
 368   // whether discovery is atomic wrt other collectors
 369   bool discovery_is_atomic() const { return _discovery_is_atomic; }
 370   void set_atomic_discovery(bool atomic) { _discovery_is_atomic = atomic; }
 371 
 372   // whether discovery is done by multiple threads same-old-timeously
 373   bool discovery_is_mt() const { return _discovery_is_mt; }
 374   void set_mt_discovery(bool mt) { _discovery_is_mt = mt; }
 375 
 376   // Whether we are in a phase when _processing_ is MT.
 377   bool processing_is_mt() const { return _processing_is_mt; }
 378   void set_mt_processing(bool mt) { _processing_is_mt = mt; }
 379 
 380   // whether all enqueueing of weak references is complete
 381   bool enqueuing_is_done()  { return _enqueuing_is_done; }


 401                                 VoidClosure*                  complete_gc,
 402                                 AbstractRefProcTaskExecutor*  task_executor,
 403                                 ReferenceProcessorPhaseTimes* phase_times);
 404 
 405   // Enqueue references at end of GC (called by the garbage collector)
 406   void enqueue_discovered_references(AbstractRefProcTaskExecutor* task_executor,
 407                                      ReferenceProcessorPhaseTimes* phase_times);
 408 
 409   // If a discovery is in process that is being superceded, abandon it: all
 410   // the discovered lists will be empty, and all the objects on them will
 411   // have NULL discovered fields.  Must be called only at a safepoint.
 412   void abandon_partial_discovery();
 413 
 414   size_t total_reference_count(ReferenceType rt) const;
 415 
 416   // debugging
 417   void verify_no_references_recorded() PRODUCT_RETURN;
 418   void verify_referent(oop obj)        PRODUCT_RETURN;
 419 };
 420 
 421 // A reference processor that uses a single memory span to determine the area that
 422 // is subject to discovery. Useful for collectors which have contiguous generations.
 423 class SpanReferenceProcessor : public ReferenceProcessor {
 424   class SpanBasedDiscoverer : public BoolObjectClosure {
 425   public:
 426     MemRegion _span;
 427 
 428     SpanBasedDiscoverer(MemRegion span) : BoolObjectClosure(), _span(span) { }
 429 
 430     virtual bool do_object_b(oop obj) {
 431       return _span.contains(obj);
 432     }
 433   };
 434 
 435   SpanBasedDiscoverer _span_based_discoverer;
 436 public:
 437   SpanReferenceProcessor(MemRegion span,
 438                               bool mt_processing = false, uint mt_processing_degree = 1,
 439                               bool mt_discovery  = false, uint mt_discovery_degree  = 1,
 440                               bool atomic_discovery = true,
 441                               BoolObjectClosure* is_alive_non_header = NULL);
 442 
 443   // get and set span
 444   MemRegion span()                   { return _span_based_discoverer._span; }
 445   void      set_span(MemRegion span) { _span_based_discoverer._span = span; }
 446 };
 447 
 448 // A utility class to disable reference discovery in
 449 // the scope which contains it, for given ReferenceProcessor.
 450 class NoRefDiscovery: StackObj {
 451  private:
 452   ReferenceProcessor* _rp;
 453   bool _was_discovering_refs;
 454  public:
 455   NoRefDiscovery(ReferenceProcessor* rp) : _rp(rp) {
 456     _was_discovering_refs = _rp->discovery_enabled();
 457     if (_was_discovering_refs) {
 458       _rp->disable_discovery();
 459     }
 460   }
 461 
 462   ~NoRefDiscovery() {
 463     if (_was_discovering_refs) {
 464       _rp->enable_discovery(false /*check_no_refs*/);
 465     }
 466   }
 467 };
 468 
 469 // A utility class to temporarily mutate the subject discovery closure of the
 470 // given ReferenceProcessor in the scope that contains it.
 471 class ReferenceProcessorSubjectToDiscoveryMutator : StackObj {
 472  private:
 473   ReferenceProcessor* _rp;
 474   BoolObjectClosure* _saved_cl;
 475 
 476  public:
 477   ReferenceProcessorSubjectToDiscoveryMutator(ReferenceProcessor* rp, BoolObjectClosure* cl):
 478     _rp(rp) {
 479     _saved_cl = _rp->is_subject_to_discovery_closure();
 480     _rp->set_is_subject_to_discovery_closure(cl);
 481   }
 482 
 483   ~ReferenceProcessorSubjectToDiscoveryMutator() {
 484     _rp->set_is_subject_to_discovery_closure(_saved_cl);
 485   }
 486 };
 487 
 488 // A utility class to temporarily mutate the span of the
 489 // given ReferenceProcessor in the scope that contains it.
 490 class ReferenceProcessorSpanMutator: StackObj {
 491  private:
 492   SpanReferenceProcessor* _rp;
 493   MemRegion _saved_span;
 494 
 495  public:
 496   ReferenceProcessorSpanMutator(SpanReferenceProcessor* rp,
 497                                 MemRegion span):
 498     _rp(rp) {
 499     _saved_span = _rp->span();
 500     _rp->set_span(span);
 501   }
 502 
 503   ~ReferenceProcessorSpanMutator() {
 504     _rp->set_span(_saved_span);
 505   }
 506 };
 507 
 508 // A utility class to temporarily change the MT'ness of
 509 // reference discovery for the given ReferenceProcessor
 510 // in the scope that contains it.
 511 class ReferenceProcessorMTDiscoveryMutator: StackObj {
 512  private:
 513   ReferenceProcessor* _rp;
 514   bool                _saved_mt;
 515 
 516  public:
 517   ReferenceProcessorMTDiscoveryMutator(ReferenceProcessor* rp,
 518                                        bool mt):
 519     _rp(rp) {
 520     _saved_mt = _rp->discovery_is_mt();
 521     _rp->set_mt_discovery(mt);
 522   }
 523 
 524   ~ReferenceProcessorMTDiscoveryMutator() {
 525     _rp->set_mt_discovery(_saved_mt);
 526   }
 527 };

 528 
 529 // A utility class to temporarily change the disposition
 530 // of the "is_alive_non_header" closure field of the
 531 // given ReferenceProcessor in the scope that contains it.
 532 class ReferenceProcessorIsAliveMutator: StackObj {
 533  private:
 534   ReferenceProcessor* _rp;
 535   BoolObjectClosure*  _saved_cl;
 536 
 537  public:
 538   ReferenceProcessorIsAliveMutator(ReferenceProcessor* rp,
 539                                    BoolObjectClosure*  cl):
 540     _rp(rp) {
 541     _saved_cl = _rp->is_alive_non_header();
 542     _rp->set_is_alive_non_header(cl);
 543   }
 544 
 545   ~ReferenceProcessorIsAliveMutator() {
 546     _rp->set_is_alive_non_header(_saved_cl);
 547   }


< prev index next >