< prev index next >

src/share/vm/memory/sharedHeap.hpp

Print this page
rev 7854 : imported patch 8027962-per-phase-timing-measurements-for-strong-roots-processing


  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. G1CollectedHeap,
  65 //    HRInto_G1RemSet, GenCollectedHeap and SharedHeap have SubTasksDone.
  66 //    This seems too many.
  67 //    3) SequentialSubTasksDone has an _n_threads that is used in
  68 //    a way similar to SubTasksDone and has the same dependency on the


  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 private:
 108   // For claiming strong_roots tasks.
 109   SubTasksDone* _process_strong_tasks;
 110 
 111 protected:
 112   // There should be only a single instance of "SharedHeap" in a program.
 113   // This is enforced with the protected constructor below, which will also
 114   // set the static pointer "_sh" to that instance.
 115   static SharedHeap* _sh;
 116 
 117   // A gc policy, controls global gc resource issues
 118   CollectorPolicy *_collector_policy;
 119 
 120   // See the discussion below, in the specification of the reader function
 121   // for this variable.
 122   int _strong_roots_parity;
 123 
 124   // If we're doing parallel GC, use this gang of threads.
 125   FlexibleWorkGang* _workers;
 126 


 223  public:
 224   enum ScanningOption {
 225     SO_None                =  0x0,
 226     SO_AllCodeCache        =  0x8,
 227     SO_ScavengeCodeCache   = 0x10
 228   };
 229 
 230   FlexibleWorkGang* workers() const { return _workers; }
 231 
 232   // Invoke the "do_oop" method the closure "roots" on all root locations.
 233   // The "so" argument determines which roots the closure is applied to:
 234   // "SO_None" does none;
 235   // "SO_AllCodeCache" applies the closure to all elements of the CodeCache.
 236   // "SO_ScavengeCodeCache" applies the closure to elements on the scavenge root list in the CodeCache.
 237   void process_roots(bool activate_scope,
 238                      ScanningOption so,
 239                      OopClosure* strong_roots,
 240                      OopClosure* weak_roots,
 241                      CLDClosure* strong_cld_closure,
 242                      CLDClosure* weak_cld_closure,
 243                      CodeBlobClosure* code_roots);

 244   void process_all_roots(bool activate_scope,
 245                          ScanningOption so,
 246                          OopClosure* roots,
 247                          CLDClosure* cld_closure,
 248                          CodeBlobClosure* code_roots);

 249   void process_strong_roots(bool activate_scope,
 250                             ScanningOption so,
 251                             OopClosure* roots,
 252                             CLDClosure* cld_closure,
 253                             CodeBlobClosure* code_roots);

 254 
 255 
 256   // Apply "root_closure" to the JNI weak roots..
 257   void process_weak_roots(OopClosure* root_closure);
 258 
 259   // The functions below are helper functions that a subclass of
 260   // "SharedHeap" can use in the implementation of its virtual
 261   // functions.
 262 
 263 public:
 264 
 265   // Do anything common to GC's.
 266   virtual void gc_prologue(bool full) = 0;
 267   virtual void gc_epilogue(bool full) = 0;
 268 
 269   // Sets the number of parallel threads that will be doing tasks
 270   // (such as process roots) subsequently.
 271   virtual void set_par_threads(uint t);
 272 
 273   int n_termination();


  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 class GCPhaseTimeTracker;
  50 
  51 // Note on use of FlexibleWorkGang's for GC.
  52 // There are three places where task completion is determined.
  53 // In
  54 //    1) ParallelTaskTerminator::offer_termination() where _n_threads
  55 //    must be set to the correct value so that count of workers that
  56 //    have offered termination will exactly match the number
  57 //    working on the task.  Tasks such as those derived from GCTask
  58 //    use ParallelTaskTerminator's.  Tasks that want load balancing
  59 //    by work stealing use this method to gauge completion.
  60 //    2) SubTasksDone has a variable _n_threads that is used in
  61 //    all_tasks_completed() to determine completion.  all_tasks_complete()
  62 //    counts the number of tasks that have been done and then reset
  63 //    the SubTasksDone so that it can be used again.  When the number of
  64 //    tasks is set to the number of GC workers, then _n_threads must
  65 //    be set to the number of active GC workers. G1CollectedHeap,
  66 //    HRInto_G1RemSet, GenCollectedHeap and SharedHeap have SubTasksDone.
  67 //    This seems too many.
  68 //    3) SequentialSubTasksDone has an _n_threads that is used in
  69 //    a way similar to SubTasksDone and has the same dependency on the


  87 //  to a value > 1 before a task that you would like executed in parallel
  88 //  and then to set it to 0 after that task has completed.  A value of
  89 //  0 is a "special" value in set_n_threads() which translates to
  90 //  setting _n_threads to 1.
  91 //
  92 //  Some code uses _n_termination to decide if work should be done in
  93 //  parallel.  The notorious possibly_parallel_oops_do() in threads.cpp
  94 //  is an example of such code.  Look for variable "is_par" for other
  95 //  examples.
  96 //
  97 //  The active_workers is not reset to 0 after a parallel phase.  It's
  98 //  value may be used in later phases and in one instance at least
  99 //  (the parallel remark) it has to be used (the parallel remark depends
 100 //  on the partitioning done in the previous parallel scavenge).
 101 
 102 class SharedHeap : public CollectedHeap {
 103   friend class VMStructs;
 104 
 105   friend class VM_GC_Operation;
 106   friend class VM_CGC_Operation;
 107 public:
 108   // The set of potentially parallel tasks in root scanning.
 109   enum SH_process_roots_tasks {
 110     SH_PS_Threads_oops_do,
 111     SH_PS_StringTable_oops_do,
 112     SH_PS_Universe_oops_do,
 113     SH_PS_JNIHandles_oops_do,
 114     SH_PS_ObjectSynchronizer_oops_do,
 115     SH_PS_FlatProfiler_oops_do,
 116     SH_PS_Management_oops_do,
 117     SH_PS_SystemDictionary_oops_do,
 118     SH_PS_ClassLoaderDataGraph_oops_do,
 119     SH_PS_jvmti_oops_do,
 120     SH_PS_CodeCache_oops_do,
 121     // Leave this one last.
 122     SH_PS_NumElements
 123   };
 124 
 125   static const char* ext_roots_task_str(uint task);
 126 private:
 127   // For claiming strong_roots tasks.
 128   SubTasksDone* _process_strong_tasks;
 129 
 130 protected:
 131   // There should be only a single instance of "SharedHeap" in a program.
 132   // This is enforced with the protected constructor below, which will also
 133   // set the static pointer "_sh" to that instance.
 134   static SharedHeap* _sh;
 135 
 136   // A gc policy, controls global gc resource issues
 137   CollectorPolicy *_collector_policy;
 138 
 139   // See the discussion below, in the specification of the reader function
 140   // for this variable.
 141   int _strong_roots_parity;
 142 
 143   // If we're doing parallel GC, use this gang of threads.
 144   FlexibleWorkGang* _workers;
 145 


 242  public:
 243   enum ScanningOption {
 244     SO_None                =  0x0,
 245     SO_AllCodeCache        =  0x8,
 246     SO_ScavengeCodeCache   = 0x10
 247   };
 248 
 249   FlexibleWorkGang* workers() const { return _workers; }
 250 
 251   // Invoke the "do_oop" method the closure "roots" on all root locations.
 252   // The "so" argument determines which roots the closure is applied to:
 253   // "SO_None" does none;
 254   // "SO_AllCodeCache" applies the closure to all elements of the CodeCache.
 255   // "SO_ScavengeCodeCache" applies the closure to elements on the scavenge root list in the CodeCache.
 256   void process_roots(bool activate_scope,
 257                      ScanningOption so,
 258                      OopClosure* strong_roots,
 259                      OopClosure* weak_roots,
 260                      CLDClosure* strong_cld_closure,
 261                      CLDClosure* weak_cld_closure,
 262                      CodeBlobClosure* code_roots,
 263                      GCPhaseTimeTracker* phase_durations = NULL);
 264   void process_all_roots(bool activate_scope,
 265                          ScanningOption so,
 266                          OopClosure* roots,
 267                          CLDClosure* cld_closure,
 268                          CodeBlobClosure* code_roots,
 269                          GCPhaseTimeTracker* phase_durations = NULL);
 270   void process_strong_roots(bool activate_scope,
 271                             ScanningOption so,
 272                             OopClosure* roots,
 273                             CLDClosure* cld_closure,
 274                             CodeBlobClosure* code_roots,
 275                             GCPhaseTimeTracker* phase_durations = NULL);
 276 
 277 
 278   // Apply "root_closure" to the JNI weak roots..
 279   void process_weak_roots(OopClosure* root_closure);
 280 
 281   // The functions below are helper functions that a subclass of
 282   // "SharedHeap" can use in the implementation of its virtual
 283   // functions.
 284 
 285 public:
 286 
 287   // Do anything common to GC's.
 288   virtual void gc_prologue(bool full) = 0;
 289   virtual void gc_epilogue(bool full) = 0;
 290 
 291   // Sets the number of parallel threads that will be doing tasks
 292   // (such as process roots) subsequently.
 293   virtual void set_par_threads(uint t);
 294 
 295   int n_termination();
< prev index next >