< prev index next >

src/share/vm/memory/sharedHeap.hpp

Print this page




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


  72 //  The pattern that appears  in the code is to set _n_threads
  73 //  to a value > 1 before a task that you would like executed in parallel
  74 //  and then to set it to 0 after that task has completed.  A value of
  75 //  0 is a "special" value in set_n_threads() which translates to
  76 //  setting _n_threads to 1.
  77 //
  78 //  Some code uses _n_termination to decide if work should be done in
  79 //  parallel.  The notorious possibly_parallel_oops_do() in threads.cpp
  80 //  is an example of such code.  Look for variable "is_par" for other
  81 //  examples.
  82 //
  83 //  The active_workers is not reset to 0 after a parallel phase.  It's
  84 //  value may be used in later phases and in one instance at least
  85 //  (the parallel remark) it has to be used (the parallel remark depends
  86 //  on the partitioning done in the previous parallel scavenge).
  87 
  88 class SharedHeap : public CollectedHeap {
  89   friend class VMStructs;
  90 
  91 protected:
  92   // If we're doing parallel GC, use this gang of threads.
  93   FlexibleWorkGang* _workers;
  94 
  95   // Full initialization is done in a concrete subtype's "initialize"
  96   // function.
  97   SharedHeap();
  98 
  99 public:
 100   // Note, the below comment needs to be updated to reflect the changes
 101   // introduced by JDK-8076225. This should be done as part of JDK-8076289.
 102   //
 103   //Some collectors will perform "process_strong_roots" in parallel.
 104   // Such a call will involve claiming some fine-grained tasks, such as
 105   // scanning of threads.  To make this process simpler, we provide the
 106   // "strong_roots_parity()" method.  Collectors that start parallel tasks
 107   // whose threads invoke "process_strong_roots" must
 108   // call "change_strong_roots_parity" in sequential code starting such a
 109   // task.  (This also means that a parallel thread may only call
 110   // process_strong_roots once.)
 111   //
 112   // For calls to process_roots by sequential code, the parity is
 113   // updated automatically.
 114   //


 120   //
 121   // If the client meats this spec, then strong_roots_parity() will have
 122   // the following properties:
 123   //   a) to return a different value than was returned before the last
 124   //      call to change_strong_roots_parity, and
 125   //   c) to never return a distinguished value (zero) with which such
 126   //      task-claiming variables may be initialized, to indicate "never
 127   //      claimed".
 128  public:
 129 
 130   // Call these in sequential code around process_roots.
 131   // strong_roots_prologue calls change_strong_roots_parity, if
 132   // parallel tasks are enabled.
 133   class StrongRootsScope : public MarkingCodeBlobClosure::MarkScope {
 134     SharedHeap*   _sh;
 135 
 136    public:
 137     StrongRootsScope(SharedHeap* heap, bool activate = true);
 138     ~StrongRootsScope();
 139   };
 140 
 141  private:
 142 
 143  public:
 144   FlexibleWorkGang* workers() const { return _workers; }
 145 
 146   // The functions below are helper functions that a subclass of
 147   // "SharedHeap" can use in the implementation of its virtual
 148   // functions.
 149  };
 150 
 151 #endif // SHARE_VM_MEMORY_SHAREDHEAP_HPP


  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.


  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   //


 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 >