< prev index next >

src/share/vm/memory/sharedHeap.hpp

Print this page




   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_MEMORY_SHAREDHEAP_HPP
  26 #define SHARE_VM_MEMORY_SHAREDHEAP_HPP
  27 
  28 #include "gc_interface/collectedHeap.hpp"
  29 #include "memory/generation.hpp"
  30 
  31 // A "SharedHeap" is an implementation of a java heap for HotSpot.  This
  32 // is an abstract class: there may be many different kinds of heaps.  This
  33 // class defines the functions that a heap must implement, and contains
  34 // infrastructure common to all heaps.
  35 
  36 class Generation;
  37 class BarrierSet;
  38 class GenRemSet;
  39 class Space;
  40 class SpaceClosure;
  41 class OopClosure;
  42 class OopsInGenClosure;
  43 class ObjectClosure;
  44 class SubTasksDone;
  45 class WorkGang;
  46 class FlexibleWorkGang;
  47 class CollectorPolicy;
  48 class KlassClosure;
  49 
  50 // Note on use of FlexibleWorkGang's for GC.
  51 // There are three places where task completion is determined.
  52 // In
  53 //    1) ParallelTaskTerminator::offer_termination() where _n_threads
  54 //    must be set to the correct value so that count of workers that
  55 //    have offered termination will exactly match the number
  56 //    working on the task.  Tasks such as those derived from GCTask
  57 //    use ParallelTaskTerminator's.  Tasks that want load balancing
  58 //    by work stealing use this method to gauge completion.
  59 //    2) SubTasksDone has a variable _n_threads that is used in
  60 //    all_tasks_completed() to determine completion.  all_tasks_complete()
  61 //    counts the number of tasks that have been done and then reset
  62 //    the SubTasksDone so that it can be used again.  When the number of
  63 //    tasks is set to the number of GC workers, then _n_threads must
  64 //    be set to the number of active GC workers. G1RootProcessor and
  65 //    GenCollectedHeap have SubTasksDone.
  66 //    3) SequentialSubTasksDone has an _n_threads that is used in
  67 //    a way similar to SubTasksDone and has the same dependency on the
  68 //    number of active GC workers.  CompactibleFreeListSpace and Space
  69 //    have SequentialSubTasksDone's.


  84 //
  85 //  The pattern that appears  in the code is to set _n_threads
  86 //  to a value > 1 before a task that you would like executed in parallel
  87 //  and then to set it to 0 after that task has completed.  A value of
  88 //  0 is a "special" value in set_n_threads() which translates to
  89 //  setting _n_threads to 1.
  90 //
  91 //  Some code uses _n_termination to decide if work should be done in
  92 //  parallel.  The notorious possibly_parallel_oops_do() in threads.cpp
  93 //  is an example of such code.  Look for variable "is_par" for other
  94 //  examples.
  95 //
  96 //  The active_workers is not reset to 0 after a parallel phase.  It's
  97 //  value may be used in later phases and in one instance at least
  98 //  (the parallel remark) it has to be used (the parallel remark depends
  99 //  on the partitioning done in the previous parallel scavenge).
 100 
 101 class SharedHeap : public CollectedHeap {
 102   friend class VMStructs;
 103 
 104   friend class VM_GC_Operation;
 105   friend class VM_CGC_Operation;
 106 
 107 protected:
 108   // If we're doing parallel GC, use this gang of threads.
 109   FlexibleWorkGang* _workers;
 110 
 111   // Full initialization is done in a concrete subtype's "initialize"
 112   // function.
 113   SharedHeap();
 114 
 115 public:
 116   void set_barrier_set(BarrierSet* bs);
 117 
 118   // Does operations required after initialization has been done.
 119   virtual void post_initialize();
 120 
 121   // Initialization of ("weak") reference processing support
 122   virtual void ref_processing_init();
 123 
 124   // Iteration functions.
 125   void oop_iterate(ExtendedOopClosure* cl) = 0;
 126 
 127   // Iterate over all spaces in use in the heap, in an undefined order.
 128   virtual void space_iterate(SpaceClosure* cl) = 0;
 129 
 130   // A SharedHeap will contain some number of spaces.  This finds the
 131   // space whose reserved area contains the given address, or else returns
 132   // NULL.
 133   virtual Space* space_containing(const void* addr) const = 0;
 134 
 135   bool no_gc_in_progress() { return !is_gc_active(); }
 136 
 137   // Note, the below comment needs to be updated to reflect the changes
 138   // introduced by JDK-8076225. This should be done as part of JDK-8076289.
 139   //
 140   //Some collectors will perform "process_strong_roots" in parallel.
 141   // Such a call will involve claiming some fine-grained tasks, such as
 142   // scanning of threads.  To make this process simpler, we provide the
 143   // "strong_roots_parity()" method.  Collectors that start parallel tasks
 144   // whose threads invoke "process_strong_roots" must
 145   // call "change_strong_roots_parity" in sequential code starting such a
 146   // task.  (This also means that a parallel thread may only call
 147   // process_strong_roots once.)
 148   //
 149   // For calls to process_roots by sequential code, the parity is
 150   // updated automatically.
 151   //
 152   // The idea is that objects representing fine-grained tasks, such as
 153   // threads, will contain a "parity" field.  A task will is claimed in the
 154   // current "process_roots" call only if its parity field is the
 155   // same as the "strong_roots_parity"; task claiming is accomplished by
 156   // updating the parity field to the strong_roots_parity with a CAS.
 157   //
 158   // If the client meats this spec, then strong_roots_parity() will have
 159   // the following properties:
 160   //   a) to return a different value than was returned before the last
 161   //      call to change_strong_roots_parity, and
 162   //   c) to never return a distinguished value (zero) with which such
 163   //      task-claiming variables may be initialized, to indicate "never
 164   //      claimed".
 165  public:
 166 
 167   // Call these in sequential code around process_roots.
 168   // strong_roots_prologue calls change_strong_roots_parity, if
 169   // parallel tasks are enabled.
 170   class StrongRootsScope : public MarkingCodeBlobClosure::MarkScope {
 171     SharedHeap*   _sh;
 172 
 173    public:
 174     StrongRootsScope(SharedHeap* heap, bool activate = true);
 175     ~StrongRootsScope();
 176   };
 177 
 178  private:
 179 
 180  public:
 181   FlexibleWorkGang* workers() const { return _workers; }
 182 
 183   // The functions below are helper functions that a subclass of
 184   // "SharedHeap" can use in the implementation of its virtual
 185   // functions.
 186 
 187 public:
 188 
 189   // Do anything common to GC's.
 190   virtual void gc_prologue(bool full) = 0;
 191   virtual void gc_epilogue(bool full) = 0;
 192 
 193   // Sets the number of parallel threads that will be doing tasks
 194   // (such as process roots) subsequently.
 195   virtual void set_par_threads(uint t);
 196 };
 197 
 198 #endif // SHARE_VM_MEMORY_SHAREDHEAP_HPP


   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_MEMORY_SHAREDHEAP_HPP
  26 #define SHARE_VM_MEMORY_SHAREDHEAP_HPP
  27 
  28 #include "gc_interface/collectedHeap.hpp"

  29 
  30 // A "SharedHeap" is an implementation of a java heap for HotSpot.  This
  31 // is an abstract class: there may be many different kinds of heaps.  This
  32 // class defines the functions that a heap must implement, and contains
  33 // infrastructure common to all heaps.
  34 














  35 // Note on use of FlexibleWorkGang's for GC.
  36 // There are three places where task completion is determined.
  37 // In
  38 //    1) ParallelTaskTerminator::offer_termination() where _n_threads
  39 //    must be set to the correct value so that count of workers that
  40 //    have offered termination will exactly match the number
  41 //    working on the task.  Tasks such as those derived from GCTask
  42 //    use ParallelTaskTerminator's.  Tasks that want load balancing
  43 //    by work stealing use this method to gauge completion.
  44 //    2) SubTasksDone has a variable _n_threads that is used in
  45 //    all_tasks_completed() to determine completion.  all_tasks_complete()
  46 //    counts the number of tasks that have been done and then reset
  47 //    the SubTasksDone so that it can be used again.  When the number of
  48 //    tasks is set to the number of GC workers, then _n_threads must
  49 //    be set to the number of active GC workers. G1RootProcessor and
  50 //    GenCollectedHeap have SubTasksDone.
  51 //    3) SequentialSubTasksDone has an _n_threads that is used in
  52 //    a way similar to SubTasksDone and has the same dependency on the
  53 //    number of active GC workers.  CompactibleFreeListSpace and Space
  54 //    have SequentialSubTasksDone's.


  69 //
  70 //  The pattern that appears  in the code is to set _n_threads
  71 //  to a value > 1 before a task that you would like executed in parallel
  72 //  and then to set it to 0 after that task has completed.  A value of
  73 //  0 is a "special" value in set_n_threads() which translates to
  74 //  setting _n_threads to 1.
  75 //
  76 //  Some code uses _n_termination to decide if work should be done in
  77 //  parallel.  The notorious possibly_parallel_oops_do() in threads.cpp
  78 //  is an example of such code.  Look for variable "is_par" for other
  79 //  examples.
  80 //
  81 //  The active_workers is not reset to 0 after a parallel phase.  It's
  82 //  value may be used in later phases and in one instance at least
  83 //  (the parallel remark) it has to be used (the parallel remark depends
  84 //  on the partitioning done in the previous parallel scavenge).
  85 
  86 class SharedHeap : public CollectedHeap {
  87   friend class VMStructs;
  88 



  89 protected:



  90   // Full initialization is done in a concrete subtype's "initialize"
  91   // function.
  92   SharedHeap();
  93 
  94 public:





















  95   // Note, the below comment needs to be updated to reflect the changes
  96   // introduced by JDK-8076225. This should be done as part of JDK-8076289.
  97   //
  98   //Some collectors will perform "process_strong_roots" in parallel.
  99   // Such a call will involve claiming some fine-grained tasks, such as
 100   // scanning of threads.  To make this process simpler, we provide the
 101   // "strong_roots_parity()" method.  Collectors that start parallel tasks
 102   // whose threads invoke "process_strong_roots" must
 103   // call "change_strong_roots_parity" in sequential code starting such a
 104   // task.  (This also means that a parallel thread may only call
 105   // process_strong_roots once.)
 106   //
 107   // For calls to process_roots by sequential code, the parity is
 108   // updated automatically.
 109   //
 110   // The idea is that objects representing fine-grained tasks, such as
 111   // threads, will contain a "parity" field.  A task will is claimed in the
 112   // current "process_roots" call only if its parity field is the
 113   // same as the "strong_roots_parity"; task claiming is accomplished by
 114   // updating the parity field to the strong_roots_parity with a CAS.
 115   //
 116   // If the client meats this spec, then strong_roots_parity() will have
 117   // the following properties:
 118   //   a) to return a different value than was returned before the last
 119   //      call to change_strong_roots_parity, and
 120   //   c) to never return a distinguished value (zero) with which such
 121   //      task-claiming variables may be initialized, to indicate "never
 122   //      claimed".
 123  public:
 124 
 125   // Call these in sequential code around process_roots.
 126   // strong_roots_prologue calls change_strong_roots_parity, if
 127   // parallel tasks are enabled.
 128   class StrongRootsScope : public MarkingCodeBlobClosure::MarkScope {
 129     SharedHeap*   _sh;
 130 
 131    public:
 132     StrongRootsScope(SharedHeap* heap, bool activate = true);
 133     ~StrongRootsScope();
 134   };
 135  };



















 136 
 137 #endif // SHARE_VM_MEMORY_SHAREDHEAP_HPP
< prev index next >