hotspot/src/share/vm/memory/sharedHeap.hpp

Print this page
rev 611 : Merge


  30 // class defines the functions that a heap must implement, and contains
  31 // infrastructure common to all heaps.
  32 
  33 class PermGen;
  34 class Generation;
  35 class BarrierSet;
  36 class GenRemSet;
  37 class Space;
  38 class SpaceClosure;
  39 class OopClosure;
  40 class OopsInGenClosure;
  41 class ObjectClosure;
  42 class SubTasksDone;
  43 class WorkGang;
  44 class CollectorPolicy;
  45 class KlassHandle;
  46 
  47 class SharedHeap : public CollectedHeap {
  48   friend class VMStructs;
  49 



  50 private:
  51   // For claiming strong_roots tasks.
  52   SubTasksDone* _process_strong_tasks;
  53 
  54 protected:
  55   // There should be only a single instance of "SharedHeap" in a program.
  56   // This is enforced with the protected constructor below, which will also
  57   // set the static pointer "_sh" to that instance.
  58   static SharedHeap* _sh;
  59 
  60   // All heaps contain a "permanent generation."  This is some ways
  61   // similar to a generation in a generational system, in other ways not.
  62   // See the "PermGen" class.
  63   PermGen* _perm_gen;
  64 
  65   // and the Gen Remembered Set, at least one good enough to scan the perm
  66   // gen.
  67   GenRemSet* _rem_set;
  68 
  69   // A gc policy, controls global gc resource issues
  70   CollectorPolicy *_collector_policy;
  71 
  72   // See the discussion below, in the specification of the reader function
  73   // for this variable.
  74   int _strong_roots_parity;
  75 
  76   // If we're doing parallel GC, use this gang of threads.
  77   WorkGang* _workers;
  78 
  79   // Number of parallel threads currently working on GC tasks.
  80   // O indicates use sequential code; 1 means use parallel code even with
  81   // only one thread, for performance testing purposes.
  82   int _n_par_threads;
  83 
  84   // Full initialization is done in a concrete subtype's "initialize"
  85   // function.
  86   SharedHeap(CollectorPolicy* policy_);
  87 








  88 public:
  89   static SharedHeap* heap() { return _sh; }
  90 
  91   CollectorPolicy *collector_policy() const { return _collector_policy; }
  92 
  93   void set_barrier_set(BarrierSet* bs);
  94 
  95   // Does operations required after initialization has been done.
  96   virtual void post_initialize();
  97 
  98   // Initialization of ("weak") reference processing support
  99   virtual void ref_processing_init();
 100 
 101   void set_perm(PermGen* perm_gen) { _perm_gen = perm_gen; }
 102 
 103   // A helper function that fills an allocated-but-not-yet-initialized
 104   // region with a garbage object.
 105   static void fill_region_with_object(MemRegion mr);
 106 
 107   // Minimum garbage fill object size
 108   static size_t min_fill_size()          { return (size_t)align_object_size(oopDesc::header_size()); }
 109   static size_t min_fill_size_in_bytes() { return min_fill_size() * HeapWordSize; }
 110 
 111   // This function returns the "GenRemSet" object that allows us to scan
 112   // generations; at least the perm gen, possibly more in a fully
 113   // generational heap.
 114   GenRemSet* rem_set() { return _rem_set; }
 115 
 116   // These function return the "permanent" generation, in which
 117   // reflective objects are allocated and stored.  Two versions, the second
 118   // of which returns the view of the perm gen as a generation.
 119   PermGen* perm() const { return _perm_gen; }
 120   Generation* perm_gen() const { return _perm_gen->as_gen(); }
 121 
 122   // Iteration functions.
 123   void oop_iterate(OopClosure* cl) = 0;
 124 
 125   // Same as above, restricted to a memory region.
 126   virtual void oop_iterate(MemRegion mr, OopClosure* cl) = 0;
 127 
 128   // Iterate over all objects allocated since the last collection, calling
 129   // "cl->do_object" on each.  The heap must have been initialized properly
 130   // to support this function, or else this call will fail.


 200   // "SO_CodeCache" applies the closure to all elements of the CodeCache.
 201   void process_strong_roots(bool collecting_perm_gen,
 202                             ScanningOption so,
 203                             OopClosure* roots,
 204                             OopsInGenClosure* perm_blk);
 205 
 206   // Apply "blk" to all the weak roots of the system.  These include
 207   // JNI weak roots, the code cache, system dictionary, symbol table,
 208   // string table.
 209   void process_weak_roots(OopClosure* root_closure,
 210                           OopClosure* non_root_closure);
 211                           
 212 
 213   // Like CollectedHeap::collect, but assume that the caller holds the Heap_lock.
 214   virtual void collect_locked(GCCause::Cause cause) = 0;
 215 
 216   // The functions below are helper functions that a subclass of
 217   // "SharedHeap" can use in the implementation of its virtual
 218   // functions.
 219 
 220 protected:
 221 
 222   // Do anything common to GC's.
 223   virtual void gc_prologue(bool full) = 0;
 224   virtual void gc_epilogue(bool full) = 0;
 225 
 226 public:
 227   //
 228   // New methods from CollectedHeap
 229   //
 230 
 231   size_t permanent_capacity() const {
 232     assert(perm_gen(), "NULL perm gen");
 233     return perm_gen()->capacity();
 234   }
 235 
 236   size_t permanent_used() const {
 237     assert(perm_gen(), "NULL perm gen");
 238     return perm_gen()->used();
 239   }
 240 
 241   bool is_in_permanent(const void *p) const {
 242     assert(perm_gen(), "NULL perm gen");
 243     return perm_gen()->is_in_reserved(p);
 244   }
 245 
 246   // Different from is_in_permanent in that is_in_permanent


 252     assert(perm_gen(), "NULL perm gen");
 253     return perm_gen()->is_in(p);
 254   }
 255 
 256   HeapWord* permanent_mem_allocate(size_t size) {
 257     assert(perm_gen(), "NULL perm gen");
 258     return _perm_gen->mem_allocate(size);
 259   }
 260 
 261   void permanent_oop_iterate(OopClosure* cl) {
 262     assert(perm_gen(), "NULL perm gen");
 263     _perm_gen->oop_iterate(cl);
 264   }
 265 
 266   void permanent_object_iterate(ObjectClosure* cl) {
 267     assert(perm_gen(), "NULL perm gen");
 268     _perm_gen->object_iterate(cl);
 269   }
 270 
 271   // Some utilities.
 272   void print_size_transition(size_t bytes_before,

 273                              size_t bytes_after,
 274                              size_t capacity);
 275 };
 276 
 277 


  30 // class defines the functions that a heap must implement, and contains
  31 // infrastructure common to all heaps.
  32 
  33 class PermGen;
  34 class Generation;
  35 class BarrierSet;
  36 class GenRemSet;
  37 class Space;
  38 class SpaceClosure;
  39 class OopClosure;
  40 class OopsInGenClosure;
  41 class ObjectClosure;
  42 class SubTasksDone;
  43 class WorkGang;
  44 class CollectorPolicy;
  45 class KlassHandle;
  46 
  47 class SharedHeap : public CollectedHeap {
  48   friend class VMStructs;
  49 
  50   friend class VM_GC_Operation;
  51   friend class VM_CGC_Operation;
  52 
  53 private:
  54   // For claiming strong_roots tasks.
  55   SubTasksDone* _process_strong_tasks;
  56 
  57 protected:
  58   // There should be only a single instance of "SharedHeap" in a program.
  59   // This is enforced with the protected constructor below, which will also
  60   // set the static pointer "_sh" to that instance.
  61   static SharedHeap* _sh;
  62 
  63   // All heaps contain a "permanent generation."  This is some ways
  64   // similar to a generation in a generational system, in other ways not.
  65   // See the "PermGen" class.
  66   PermGen* _perm_gen;
  67 
  68   // and the Gen Remembered Set, at least one good enough to scan the perm
  69   // gen.
  70   GenRemSet* _rem_set;
  71 
  72   // A gc policy, controls global gc resource issues
  73   CollectorPolicy *_collector_policy;
  74 
  75   // See the discussion below, in the specification of the reader function
  76   // for this variable.
  77   int _strong_roots_parity;
  78 
  79   // If we're doing parallel GC, use this gang of threads.
  80   WorkGang* _workers;
  81 
  82   // Number of parallel threads currently working on GC tasks.
  83   // O indicates use sequential code; 1 means use parallel code even with
  84   // only one thread, for performance testing purposes.
  85   int _n_par_threads;
  86 
  87   // Full initialization is done in a concrete subtype's "initialize"
  88   // function.
  89   SharedHeap(CollectorPolicy* policy_);
  90 
  91   // Returns true if the calling thread holds the heap lock,
  92   // or the calling thread is a par gc thread and the heap_lock is held
  93   // by the vm thread doing a gc operation.
  94   bool heap_lock_held_for_gc();
  95   // True if the heap_lock is held by the a non-gc thread invoking a gc
  96   // operation.
  97   bool _thread_holds_heap_lock_for_gc;
  98 
  99 public:
 100   static SharedHeap* heap() { return _sh; }
 101 
 102   CollectorPolicy *collector_policy() const { return _collector_policy; }
 103 
 104   void set_barrier_set(BarrierSet* bs);
 105 
 106   // Does operations required after initialization has been done.
 107   virtual void post_initialize();
 108 
 109   // Initialization of ("weak") reference processing support
 110   virtual void ref_processing_init();
 111 
 112   void set_perm(PermGen* perm_gen) { _perm_gen = perm_gen; }
 113 








 114   // This function returns the "GenRemSet" object that allows us to scan
 115   // generations; at least the perm gen, possibly more in a fully
 116   // generational heap.
 117   GenRemSet* rem_set() { return _rem_set; }
 118 
 119   // These function return the "permanent" generation, in which
 120   // reflective objects are allocated and stored.  Two versions, the second
 121   // of which returns the view of the perm gen as a generation.
 122   PermGen* perm() const { return _perm_gen; }
 123   Generation* perm_gen() const { return _perm_gen->as_gen(); }
 124 
 125   // Iteration functions.
 126   void oop_iterate(OopClosure* cl) = 0;
 127 
 128   // Same as above, restricted to a memory region.
 129   virtual void oop_iterate(MemRegion mr, OopClosure* cl) = 0;
 130 
 131   // Iterate over all objects allocated since the last collection, calling
 132   // "cl->do_object" on each.  The heap must have been initialized properly
 133   // to support this function, or else this call will fail.


 203   // "SO_CodeCache" applies the closure to all elements of the CodeCache.
 204   void process_strong_roots(bool collecting_perm_gen,
 205                             ScanningOption so,
 206                             OopClosure* roots,
 207                             OopsInGenClosure* perm_blk);
 208 
 209   // Apply "blk" to all the weak roots of the system.  These include
 210   // JNI weak roots, the code cache, system dictionary, symbol table,
 211   // string table.
 212   void process_weak_roots(OopClosure* root_closure,
 213                           OopClosure* non_root_closure);
 214                           
 215 
 216   // Like CollectedHeap::collect, but assume that the caller holds the Heap_lock.
 217   virtual void collect_locked(GCCause::Cause cause) = 0;
 218 
 219   // The functions below are helper functions that a subclass of
 220   // "SharedHeap" can use in the implementation of its virtual
 221   // functions.
 222 
 223 public:
 224 
 225   // Do anything common to GC's.
 226   virtual void gc_prologue(bool full) = 0;
 227   virtual void gc_epilogue(bool full) = 0;
 228 

 229   //
 230   // New methods from CollectedHeap
 231   //
 232 
 233   size_t permanent_capacity() const {
 234     assert(perm_gen(), "NULL perm gen");
 235     return perm_gen()->capacity();
 236   }
 237 
 238   size_t permanent_used() const {
 239     assert(perm_gen(), "NULL perm gen");
 240     return perm_gen()->used();
 241   }
 242 
 243   bool is_in_permanent(const void *p) const {
 244     assert(perm_gen(), "NULL perm gen");
 245     return perm_gen()->is_in_reserved(p);
 246   }
 247 
 248   // Different from is_in_permanent in that is_in_permanent


 254     assert(perm_gen(), "NULL perm gen");
 255     return perm_gen()->is_in(p);
 256   }
 257 
 258   HeapWord* permanent_mem_allocate(size_t size) {
 259     assert(perm_gen(), "NULL perm gen");
 260     return _perm_gen->mem_allocate(size);
 261   }
 262 
 263   void permanent_oop_iterate(OopClosure* cl) {
 264     assert(perm_gen(), "NULL perm gen");
 265     _perm_gen->oop_iterate(cl);
 266   }
 267 
 268   void permanent_object_iterate(ObjectClosure* cl) {
 269     assert(perm_gen(), "NULL perm gen");
 270     _perm_gen->object_iterate(cl);
 271   }
 272 
 273   // Some utilities.
 274   void print_size_transition(outputStream* out,
 275                              size_t bytes_before,
 276                              size_t bytes_after,
 277                              size_t capacity);
 278 };
 279 
 280