< prev index next >

src/share/vm/memory/sharedHeap.hpp

Print this page




  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   // There should be only a single instance of "SharedHeap" in a program.
 109   // This is enforced with the protected constructor below, which will also
 110   // set the static pointer "_sh" to that instance.
 111   static SharedHeap* _sh;
 112 
 113   // A gc policy, controls global gc resource issues
 114   CollectorPolicy *_collector_policy;
 115 
 116   // See the discussion below, in the specification of the reader function
 117   // for this variable.
 118   int _strong_roots_parity;
 119 
 120   // If we're doing parallel GC, use this gang of threads.
 121   FlexibleWorkGang* _workers;
 122 
 123   // Full initialization is done in a concrete subtype's "initialize"
 124   // function.
 125   SharedHeap(CollectorPolicy* policy_);
 126 
 127   // Returns true if the calling thread holds the heap lock,
 128   // or the calling thread is a par gc thread and the heap_lock is held
 129   // by the vm thread doing a gc operation.
 130   bool heap_lock_held_for_gc();
 131   // True if the heap_lock is held by the a non-gc thread invoking a gc
 132   // operation.
 133   bool _thread_holds_heap_lock_for_gc;
 134 
 135 public:
 136   static SharedHeap* heap() { return _sh; }
 137 
 138   void set_barrier_set(BarrierSet* bs);
 139 


 165   // task.  (This also means that a parallel thread may only call
 166   // process_strong_roots once.)
 167   //
 168   // For calls to process_roots by sequential code, the parity is
 169   // updated automatically.
 170   //
 171   // The idea is that objects representing fine-grained tasks, such as
 172   // threads, will contain a "parity" field.  A task will is claimed in the
 173   // current "process_roots" call only if its parity field is the
 174   // same as the "strong_roots_parity"; task claiming is accomplished by
 175   // updating the parity field to the strong_roots_parity with a CAS.
 176   //
 177   // If the client meats this spec, then strong_roots_parity() will have
 178   // the following properties:
 179   //   a) to return a different value than was returned before the last
 180   //      call to change_strong_roots_parity, and
 181   //   c) to never return a distinguished value (zero) with which such
 182   //      task-claiming variables may be initialized, to indicate "never
 183   //      claimed".
 184  public:
 185   int strong_roots_parity() { return _strong_roots_parity; }
 186 
 187   // Call these in sequential code around process_roots.
 188   // strong_roots_prologue calls change_strong_roots_parity, if
 189   // parallel tasks are enabled.
 190   class StrongRootsScope : public MarkingCodeBlobClosure::MarkScope {
 191     SharedHeap*   _sh;
 192 
 193    public:
 194     StrongRootsScope(SharedHeap* heap, bool activate = true);

 195   };
 196   friend class StrongRootsScope;
 197 
 198  private:
 199   void change_strong_roots_parity();
 200 
 201  public:
 202   FlexibleWorkGang* workers() const { return _workers; }
 203 
 204   // The functions below are helper functions that a subclass of
 205   // "SharedHeap" can use in the implementation of its virtual
 206   // functions.
 207 
 208 public:
 209 
 210   // Do anything common to GC's.
 211   virtual void gc_prologue(bool full) = 0;
 212   virtual void gc_epilogue(bool full) = 0;
 213 
 214   // Sets the number of parallel threads that will be doing tasks
 215   // (such as process roots) subsequently.
 216   virtual void set_par_threads(uint t);
 217 };
 218 
 219 #endif // SHARE_VM_MEMORY_SHAREDHEAP_HPP


  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   // There should be only a single instance of "SharedHeap" in a program.
 109   // This is enforced with the protected constructor below, which will also
 110   // set the static pointer "_sh" to that instance.
 111   static SharedHeap* _sh;
 112 
 113   // A gc policy, controls global gc resource issues
 114   CollectorPolicy *_collector_policy;
 115 




 116   // If we're doing parallel GC, use this gang of threads.
 117   FlexibleWorkGang* _workers;
 118 
 119   // Full initialization is done in a concrete subtype's "initialize"
 120   // function.
 121   SharedHeap(CollectorPolicy* policy_);
 122 
 123   // Returns true if the calling thread holds the heap lock,
 124   // or the calling thread is a par gc thread and the heap_lock is held
 125   // by the vm thread doing a gc operation.
 126   bool heap_lock_held_for_gc();
 127   // True if the heap_lock is held by the a non-gc thread invoking a gc
 128   // operation.
 129   bool _thread_holds_heap_lock_for_gc;
 130 
 131 public:
 132   static SharedHeap* heap() { return _sh; }
 133 
 134   void set_barrier_set(BarrierSet* bs);
 135 


 161   // task.  (This also means that a parallel thread may only call
 162   // process_strong_roots once.)
 163   //
 164   // For calls to process_roots by sequential code, the parity is
 165   // updated automatically.
 166   //
 167   // The idea is that objects representing fine-grained tasks, such as
 168   // threads, will contain a "parity" field.  A task will is claimed in the
 169   // current "process_roots" call only if its parity field is the
 170   // same as the "strong_roots_parity"; task claiming is accomplished by
 171   // updating the parity field to the strong_roots_parity with a CAS.
 172   //
 173   // If the client meats this spec, then strong_roots_parity() will have
 174   // the following properties:
 175   //   a) to return a different value than was returned before the last
 176   //      call to change_strong_roots_parity, and
 177   //   c) to never return a distinguished value (zero) with which such
 178   //      task-claiming variables may be initialized, to indicate "never
 179   //      claimed".
 180  public:

 181 
 182   // Call these in sequential code around process_roots.
 183   // strong_roots_prologue calls change_strong_roots_parity, if
 184   // parallel tasks are enabled.
 185   class StrongRootsScope : public MarkingCodeBlobClosure::MarkScope {
 186     SharedHeap*   _sh;
 187 
 188    public:
 189     StrongRootsScope(SharedHeap* heap, bool activate = true);
 190     ~StrongRootsScope();
 191   };

 192 
 193  private:

 194 
 195  public:
 196   FlexibleWorkGang* workers() const { return _workers; }
 197 
 198   // The functions below are helper functions that a subclass of
 199   // "SharedHeap" can use in the implementation of its virtual
 200   // functions.
 201 
 202 public:
 203 
 204   // Do anything common to GC's.
 205   virtual void gc_prologue(bool full) = 0;
 206   virtual void gc_epilogue(bool full) = 0;
 207 
 208   // Sets the number of parallel threads that will be doing tasks
 209   // (such as process roots) subsequently.
 210   virtual void set_par_threads(uint t);
 211 };
 212 
 213 #endif // SHARE_VM_MEMORY_SHAREDHEAP_HPP
< prev index next >