< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  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"


 149   void clear_referent();
 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


 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; }
 398   void set_enqueuing_is_done(bool v) { _enqueuing_is_done = v; }
 399 
 400   // iterate over oops
 401   void weak_oops_do(OopClosure* f);       // weak roots
 402 
 403   // Balance each of the discovered lists.
 404   void balance_all_queues();
 405   void verify_list(DiscoveredList& ref_list);
 406 
 407   // Discover a Reference object, using appropriate discovery criteria
 408   bool discover_reference(oop obj, ReferenceType rt);
 409 
 410   // Has discovered references that need handling
 411   bool has_discovered_references();
 412 
 413   // Process references found during GC (called by the garbage collector)
 414   ReferenceProcessorStats
 415   process_discovered_references(BoolObjectClosure*            is_alive,
 416                                 OopClosure*                   keep_alive,
 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();


   1 /*
   2  * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  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/referenceDiscoverer.hpp"
  29 #include "gc/shared/referencePolicy.hpp"
  30 #include "gc/shared/referenceProcessorPhaseTimes.hpp"
  31 #include "gc/shared/referenceProcessorStats.hpp"
  32 #include "memory/referenceType.hpp"
  33 #include "oops/instanceRefKlass.hpp"
  34 
  35 class GCTimer;
  36 
  37 // ReferenceProcessor class encapsulates the per-"collector" processing
  38 // of java.lang.Reference objects for GC. The interface is useful for supporting
  39 // a generational abstraction, in particular when there are multiple
  40 // generations that are being independently collected -- possibly
  41 // concurrently and/or incrementally.  Note, however, that the
  42 // ReferenceProcessor class abstracts away from a generational setting
  43 // by using only a heap interval (called "span" below), thus allowing
  44 // its use in a straightforward manner in a general, non-generational
  45 // setting.
  46 //
  47 // The basic idea is that each ReferenceProcessor object concerns
  48 // itself with ("weak") reference processing in a specific "span"


 150   void clear_referent();
 151 
 152   // Statistics
 153   NOT_PRODUCT(
 154   inline size_t processed() const { return _processed; }
 155   inline size_t removed() const   { return _removed; }
 156   )
 157 
 158   inline void move_to_next() {
 159     if (_ref == _next) {
 160       // End of the list.
 161       _ref = NULL;
 162     } else {
 163       _ref = _next;
 164     }
 165     assert(_ref != _first_seen, "cyclic ref_list found");
 166     NOT_PRODUCT(_processed++);
 167   }
 168 };
 169 
 170 class ReferenceProcessor : public ReferenceDiscoverer {
 171 
 172  private:
 173   size_t total_count(DiscoveredList lists[]) const;
 174 
 175  protected:
 176   // The SoftReference master timestamp clock
 177   static jlong _soft_ref_timestamp_clock;
 178 
 179   MemRegion   _span;                    // (right-open) interval of heap
 180                                         // subject to wkref discovery
 181 
 182   bool        _discovering_refs;        // true when discovery enabled
 183   bool        _discovery_is_atomic;     // if discovery is atomic wrt
 184                                         // other collectors in configuration
 185   bool        _discovery_is_mt;         // true if reference discovery is MT.
 186 
 187   bool        _enqueuing_is_done;       // true if all weak references enqueued
 188   bool        _processing_is_mt;        // true during phases when
 189                                         // reference processing is MT.
 190   uint        _next_id;                 // round-robin mod _num_q counter in


 389   // whether discovery is done by multiple threads same-old-timeously
 390   bool discovery_is_mt() const { return _discovery_is_mt; }
 391   void set_mt_discovery(bool mt) { _discovery_is_mt = mt; }
 392 
 393   // Whether we are in a phase when _processing_ is MT.
 394   bool processing_is_mt() const { return _processing_is_mt; }
 395   void set_mt_processing(bool mt) { _processing_is_mt = mt; }
 396 
 397   // whether all enqueueing of weak references is complete
 398   bool enqueuing_is_done()  { return _enqueuing_is_done; }
 399   void set_enqueuing_is_done(bool v) { _enqueuing_is_done = v; }
 400 
 401   // iterate over oops
 402   void weak_oops_do(OopClosure* f);       // weak roots
 403 
 404   // Balance each of the discovered lists.
 405   void balance_all_queues();
 406   void verify_list(DiscoveredList& ref_list);
 407 
 408   // Discover a Reference object, using appropriate discovery criteria
 409   virtual bool discover_reference(oop obj, ReferenceType rt);
 410 
 411   // Has discovered references that need handling
 412   bool has_discovered_references();
 413 
 414   // Process references found during GC (called by the garbage collector)
 415   ReferenceProcessorStats
 416   process_discovered_references(BoolObjectClosure*            is_alive,
 417                                 OopClosure*                   keep_alive,
 418                                 VoidClosure*                  complete_gc,
 419                                 AbstractRefProcTaskExecutor*  task_executor,
 420                                 ReferenceProcessorPhaseTimes* phase_times);
 421 
 422   // Enqueue references at end of GC (called by the garbage collector)
 423   void enqueue_discovered_references(AbstractRefProcTaskExecutor* task_executor,
 424                                      ReferenceProcessorPhaseTimes* phase_times);
 425 
 426   // If a discovery is in process that is being superceded, abandon it: all
 427   // the discovered lists will be empty, and all the objects on them will
 428   // have NULL discovered fields.  Must be called only at a safepoint.
 429   void abandon_partial_discovery();


< prev index next >