< prev index next >

src/hotspot/share/gc/parallel/parallelScavengeHeap.hpp

Print this page




  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_GC_PARALLEL_PARALLELSCAVENGEHEAP_HPP
  26 #define SHARE_GC_PARALLEL_PARALLELSCAVENGEHEAP_HPP
  27 
  28 #include "gc/parallel/objectStartArray.hpp"
  29 #include "gc/parallel/psGCAdaptivePolicyCounters.hpp"
  30 #include "gc/parallel/psOldGen.hpp"
  31 #include "gc/parallel/psYoungGen.hpp"
  32 #include "gc/shared/cardTableBarrierSet.hpp"
  33 #include "gc/shared/collectedHeap.hpp"
  34 #include "gc/shared/gcPolicyCounters.hpp"
  35 #include "gc/shared/gcWhen.hpp"
  36 #include "gc/shared/preGCValues.hpp"
  37 #include "gc/shared/referenceProcessor.hpp"
  38 #include "gc/shared/softRefPolicy.hpp"
  39 #include "gc/shared/strongRootsScope.hpp"
  40 #include "gc/shared/workgroup.hpp"
  41 #include "logging/log.hpp"
  42 #include "memory/metaspace.hpp"
  43 #include "utilities/growableArray.hpp"
  44 #include "utilities/ostream.hpp"
  45 
  46 class AdjoiningGenerations;
  47 class GCHeapSummary;

  48 class MemoryManager;
  49 class MemoryPool;
  50 class PSAdaptiveSizePolicy;
  51 class PSCardTable;
  52 class PSHeapSummary;
  53 
  54 class ParallelScavengeHeap : public CollectedHeap {
  55   friend class VMStructs;
  56  private:
  57   static PSYoungGen* _young_gen;
  58   static PSOldGen*   _old_gen;
  59 
  60   // Sizing policy for entire heap
  61   static PSAdaptiveSizePolicy*       _size_policy;
  62   static PSGCAdaptivePolicyCounters* _gc_policy_counters;
  63 
  64   SoftRefPolicy _soft_ref_policy;
  65 
  66   // Collection of generations that are adjacent in the
  67   // space reserved for the heap.
  68   AdjoiningGenerations* _gens;
  69   unsigned int _death_march_count;
  70 



  71   GCMemoryManager* _young_manager;
  72   GCMemoryManager* _old_manager;
  73 
  74   MemoryPool* _eden_pool;
  75   MemoryPool* _survivor_pool;
  76   MemoryPool* _old_pool;
  77 
  78   WorkGang _workers;
  79 
  80   virtual void initialize_serviceability();
  81 
  82   void trace_heap(GCWhen::Type when, const GCTracer* tracer);
  83 
  84  protected:
  85   static inline size_t total_invocations();
  86   HeapWord* allocate_new_tlab(size_t min_size, size_t requested_size, size_t* actual_size);
  87 
  88   inline bool should_alloc_in_eden(size_t size) const;
  89   inline void death_march_check(HeapWord* const result, size_t size);
  90   HeapWord* mem_allocate_old_gen(size_t size);
  91 
  92  public:
  93   ParallelScavengeHeap() :
  94     CollectedHeap(),
  95     _gens(NULL),
  96     _death_march_count(0),
  97     _young_manager(NULL),
  98     _old_manager(NULL),
  99     _eden_pool(NULL),
 100     _survivor_pool(NULL),
 101     _old_pool(NULL),
 102     _workers("GC Thread",
 103              ParallelGCThreads,
 104              true /* are_GC_task_threads */,
 105              false /* are_ConcurrentGC_threads */) { }
 106 
 107   // For use by VM operations
 108   enum CollectionType {
 109     Scavenge,
 110     MarkSweep
 111   };
 112 
 113   virtual Name kind() const {
 114     return CollectedHeap::Parallel;
 115   }
 116 
 117   virtual const char* name() const {
 118     return "Parallel";
 119   }
 120 
 121   virtual SoftRefPolicy* soft_ref_policy() { return &_soft_ref_policy; }
 122 
 123   virtual GrowableArray<GCMemoryManager*> memory_managers();
 124   virtual GrowableArray<MemoryPool*> memory_pools();
 125 
 126   static PSYoungGen* young_gen() { return _young_gen; }
 127   static PSOldGen* old_gen()     { return _old_gen; }
 128 
 129   virtual PSAdaptiveSizePolicy* size_policy() { return _size_policy; }
 130 
 131   static PSGCAdaptivePolicyCounters* gc_policy_counters() { return _gc_policy_counters; }
 132 
 133   static ParallelScavengeHeap* heap();
 134 


 135   CardTableBarrierSet* barrier_set();
 136   PSCardTable* card_table();
 137 
 138   AdjoiningGenerations* gens() { return _gens; }
 139 
 140   // Returns JNI_OK on success
 141   virtual jint initialize();
 142 
 143   void post_initialize();
 144   void update_counters();
 145 
 146   size_t capacity() const;
 147   size_t used() const;
 148 
 149   // Return "true" if all generations have reached the
 150   // maximal committed limit that they can reach, without a garbage
 151   // collection.
 152   virtual bool is_maximal_no_gc() const;
 153 
 154   virtual void register_nmethod(nmethod* nm);
 155   virtual void unregister_nmethod(nmethod* nm);
 156   virtual void verify_nmethod(nmethod* nm);
 157   virtual void flush_nmethod(nmethod* nm);
 158 
 159   void prune_scavengable_nmethods();
 160 
 161   size_t max_capacity() const;
 162 
 163   // Whether p is in the allocated part of the heap
 164   bool is_in(const void* p) const;
 165 
 166   bool is_in_reserved(const void* p) const;
 167 
 168   bool is_in_young(oop p);  // reserved part
 169   bool is_in_old(oop p);    // reserved part
 170 
 171   MemRegion reserved_region() const { return _reserved; }
 172   HeapWord* base() const { return _reserved.start(); }
 173 
 174   // Memory allocation.   "gc_time_limit_was_exceeded" will
 175   // be set to true if the adaptive size policy determine that
 176   // an excessive amount of time is being spent doing collections
 177   // and caused a NULL to be returned.  If a NULL is not returned,
 178   // "gc_time_limit_was_exceeded" has an undefined meaning.
 179   HeapWord* mem_allocate(size_t size, bool* gc_overhead_limit_was_exceeded);
 180 
 181   // Allocation attempt(s) during a safepoint. It should never be called
 182   // to allocate a new TLAB as this allocation might be satisfied out
 183   // of the old generation.
 184   HeapWord* failed_mem_allocate(size_t size);
 185 
 186   // Support for System.gc()
 187   void collect(GCCause::Cause cause);
 188 
 189   // These also should be called by the vm thread at a safepoint (e.g., from a
 190   // VM operation).
 191   //
 192   // The first collects the young generation only, unless the scavenge fails; it
 193   // will then attempt a full gc.  The second collects the entire heap; if


 211   size_t tlab_capacity(Thread* thr) const;
 212   size_t tlab_used(Thread* thr) const;
 213   size_t unsafe_max_tlab_alloc(Thread* thr) const;
 214 
 215   void object_iterate(ObjectClosure* cl);
 216   void safe_object_iterate(ObjectClosure* cl) { object_iterate(cl); }
 217 
 218   HeapWord* block_start(const void* addr) const;
 219   bool block_is_obj(const HeapWord* addr) const;
 220 
 221   jlong millis_since_last_gc();
 222 
 223   void prepare_for_verify();
 224   PSHeapSummary create_ps_heap_summary();
 225   virtual void print_on(outputStream* st) const;
 226   virtual void print_on_error(outputStream* st) const;
 227   virtual void print_gc_threads_on(outputStream* st) const;
 228   virtual void gc_threads_do(ThreadClosure* tc) const;
 229   virtual void print_tracing_info() const;
 230 
 231   PreGenGCValues get_pre_gc_values() const;
 232   void print_heap_change(const PreGenGCValues& pre_gc_values) const;
 233 
 234   // Used to print information about locations in the hs_err file.
 235   virtual bool print_location(outputStream* st, void* addr) const;
 236 
 237   void verify(VerifyOption option /* ignored */);
 238 
 239   // Resize the young generation.  The reserved space for the
 240   // generation may be expanded in preparation for the resize.
 241   void resize_young_gen(size_t eden_size, size_t survivor_size);
 242 
 243   // Resize the old generation.  The reserved space for the
 244   // generation may be expanded in preparation for the resize.
 245   void resize_old_gen(size_t desired_free_space);
 246 
 247   // Save the tops of the spaces in all generations
 248   void record_gen_tops_before_GC() PRODUCT_RETURN;
 249 
 250   // Mangle the unused parts of all spaces in the heap
 251   void gen_mangle_unused_area() PRODUCT_RETURN;
 252 
 253   // Call these in sequential code around the processing of strong roots.
 254   class ParStrongRootsScope : public MarkScope {
 255    public:
 256     ParStrongRootsScope();
 257     ~ParStrongRootsScope();
 258   };
 259 
 260   GCMemoryManager* old_gc_manager() const { return _old_manager; }
 261   GCMemoryManager* young_gc_manager() const { return _young_manager; }

 262 
 263   WorkGang& workers() {
 264     return _workers;
 265   }

















 266 };
 267 
 268 // Class that can be used to print information about the
 269 // adaptive size policy at intervals specified by
 270 // AdaptiveSizePolicyOutputInterval.  Only print information
 271 // if an adaptive size policy is in use.
 272 class AdaptiveSizePolicyOutput : AllStatic {
 273   static bool enabled() {
 274     return UseParallelGC &&
 275            UseAdaptiveSizePolicy &&
 276            log_is_enabled(Debug, gc, ergo);
 277   }
 278  public:
 279   static void print() {
 280     if (enabled()) {
 281       ParallelScavengeHeap::heap()->size_policy()->print();
 282     }
 283   }
 284 
 285   static void print(AdaptiveSizePolicy* size_policy, uint count) {


  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_GC_PARALLEL_PARALLELSCAVENGEHEAP_HPP
  26 #define SHARE_GC_PARALLEL_PARALLELSCAVENGEHEAP_HPP
  27 
  28 #include "gc/parallel/objectStartArray.hpp"
  29 #include "gc/parallel/psGCAdaptivePolicyCounters.hpp"
  30 #include "gc/parallel/psOldGen.hpp"
  31 #include "gc/parallel/psYoungGen.hpp"
  32 #include "gc/shared/cardTableBarrierSet.hpp"
  33 #include "gc/shared/collectedHeap.hpp"
  34 #include "gc/shared/gcPolicyCounters.hpp"
  35 #include "gc/shared/gcWhen.hpp"

  36 #include "gc/shared/referenceProcessor.hpp"
  37 #include "gc/shared/softRefPolicy.hpp"
  38 #include "gc/shared/strongRootsScope.hpp"

  39 #include "logging/log.hpp"
  40 #include "memory/metaspace.hpp"
  41 #include "utilities/growableArray.hpp"
  42 #include "utilities/ostream.hpp"
  43 
  44 class AdjoiningGenerations;
  45 class GCHeapSummary;
  46 class GCTaskManager;
  47 class MemoryManager;
  48 class MemoryPool;
  49 class PSAdaptiveSizePolicy;
  50 class PSCardTable;
  51 class PSHeapSummary;
  52 
  53 class ParallelScavengeHeap : public CollectedHeap {
  54   friend class VMStructs;
  55  private:
  56   static PSYoungGen* _young_gen;
  57   static PSOldGen*   _old_gen;
  58 
  59   // Sizing policy for entire heap
  60   static PSAdaptiveSizePolicy*       _size_policy;
  61   static PSGCAdaptivePolicyCounters* _gc_policy_counters;
  62 
  63   SoftRefPolicy _soft_ref_policy;
  64 
  65   // Collection of generations that are adjacent in the
  66   // space reserved for the heap.
  67   AdjoiningGenerations* _gens;
  68   unsigned int _death_march_count;
  69 
  70   // The task manager
  71   static GCTaskManager* _gc_task_manager;
  72 
  73   GCMemoryManager* _young_manager;
  74   GCMemoryManager* _old_manager;
  75 
  76   MemoryPool* _eden_pool;
  77   MemoryPool* _survivor_pool;
  78   MemoryPool* _old_pool;
  79 


  80   virtual void initialize_serviceability();
  81 
  82   void trace_heap(GCWhen::Type when, const GCTracer* tracer);
  83 
  84  protected:
  85   static inline size_t total_invocations();
  86   HeapWord* allocate_new_tlab(size_t min_size, size_t requested_size, size_t* actual_size);
  87 
  88   inline bool should_alloc_in_eden(size_t size) const;
  89   inline void death_march_check(HeapWord* const result, size_t size);
  90   HeapWord* mem_allocate_old_gen(size_t size);
  91 
  92  public:
  93   ParallelScavengeHeap() :
  94     CollectedHeap(),
  95     _gens(NULL),
  96     _death_march_count(0),
  97     _young_manager(NULL),
  98     _old_manager(NULL),
  99     _eden_pool(NULL),
 100     _survivor_pool(NULL),
 101     _old_pool(NULL) { }




 102 
 103   // For use by VM operations
 104   enum CollectionType {
 105     Scavenge,
 106     MarkSweep
 107   };
 108 
 109   virtual Name kind() const {
 110     return CollectedHeap::Parallel;
 111   }
 112 
 113   virtual const char* name() const {
 114     return "Parallel";
 115   }
 116 
 117   virtual SoftRefPolicy* soft_ref_policy() { return &_soft_ref_policy; }
 118 
 119   virtual GrowableArray<GCMemoryManager*> memory_managers();
 120   virtual GrowableArray<MemoryPool*> memory_pools();
 121 
 122   static PSYoungGen* young_gen() { return _young_gen; }
 123   static PSOldGen* old_gen()     { return _old_gen; }
 124 
 125   virtual PSAdaptiveSizePolicy* size_policy() { return _size_policy; }
 126 
 127   static PSGCAdaptivePolicyCounters* gc_policy_counters() { return _gc_policy_counters; }
 128 
 129   static ParallelScavengeHeap* heap();
 130 
 131   static GCTaskManager* const gc_task_manager() { return _gc_task_manager; }
 132 
 133   CardTableBarrierSet* barrier_set();
 134   PSCardTable* card_table();
 135 
 136   AdjoiningGenerations* gens() { return _gens; }
 137 
 138   // Returns JNI_OK on success
 139   virtual jint initialize();
 140 
 141   void post_initialize();
 142   void update_counters();
 143 
 144   size_t capacity() const;
 145   size_t used() const;
 146 
 147   // Return "true" if all generations have reached the
 148   // maximal committed limit that they can reach, without a garbage
 149   // collection.
 150   virtual bool is_maximal_no_gc() const;
 151 
 152   virtual void register_nmethod(nmethod* nm);
 153   virtual void unregister_nmethod(nmethod* nm);
 154   virtual void verify_nmethod(nmethod* nm);
 155   virtual void flush_nmethod(nmethod* nm);
 156 
 157   void prune_scavengable_nmethods();
 158 
 159   size_t max_capacity() const;
 160 
 161   // Whether p is in the allocated part of the heap
 162   bool is_in(const void* p) const;
 163 
 164   bool is_in_reserved(const void* p) const;
 165 
 166   bool is_in_young(oop p);  // reserved part
 167   bool is_in_old(oop p);    // reserved part
 168 



 169   // Memory allocation.   "gc_time_limit_was_exceeded" will
 170   // be set to true if the adaptive size policy determine that
 171   // an excessive amount of time is being spent doing collections
 172   // and caused a NULL to be returned.  If a NULL is not returned,
 173   // "gc_time_limit_was_exceeded" has an undefined meaning.
 174   HeapWord* mem_allocate(size_t size, bool* gc_overhead_limit_was_exceeded);
 175 
 176   // Allocation attempt(s) during a safepoint. It should never be called
 177   // to allocate a new TLAB as this allocation might be satisfied out
 178   // of the old generation.
 179   HeapWord* failed_mem_allocate(size_t size);
 180 
 181   // Support for System.gc()
 182   void collect(GCCause::Cause cause);
 183 
 184   // These also should be called by the vm thread at a safepoint (e.g., from a
 185   // VM operation).
 186   //
 187   // The first collects the young generation only, unless the scavenge fails; it
 188   // will then attempt a full gc.  The second collects the entire heap; if


 206   size_t tlab_capacity(Thread* thr) const;
 207   size_t tlab_used(Thread* thr) const;
 208   size_t unsafe_max_tlab_alloc(Thread* thr) const;
 209 
 210   void object_iterate(ObjectClosure* cl);
 211   void safe_object_iterate(ObjectClosure* cl) { object_iterate(cl); }
 212 
 213   HeapWord* block_start(const void* addr) const;
 214   bool block_is_obj(const HeapWord* addr) const;
 215 
 216   jlong millis_since_last_gc();
 217 
 218   void prepare_for_verify();
 219   PSHeapSummary create_ps_heap_summary();
 220   virtual void print_on(outputStream* st) const;
 221   virtual void print_on_error(outputStream* st) const;
 222   virtual void print_gc_threads_on(outputStream* st) const;
 223   virtual void gc_threads_do(ThreadClosure* tc) const;
 224   virtual void print_tracing_info() const;
 225 






 226   void verify(VerifyOption option /* ignored */);
 227 
 228   // Resize the young generation.  The reserved space for the
 229   // generation may be expanded in preparation for the resize.
 230   void resize_young_gen(size_t eden_size, size_t survivor_size);
 231 
 232   // Resize the old generation.  The reserved space for the
 233   // generation may be expanded in preparation for the resize.
 234   void resize_old_gen(size_t desired_free_space);
 235 
 236   // Save the tops of the spaces in all generations
 237   void record_gen_tops_before_GC() PRODUCT_RETURN;
 238 
 239   // Mangle the unused parts of all spaces in the heap
 240   void gen_mangle_unused_area() PRODUCT_RETURN;
 241 
 242   // Call these in sequential code around the processing of strong roots.
 243   class ParStrongRootsScope : public MarkScope {
 244    public:
 245     ParStrongRootsScope();
 246     ~ParStrongRootsScope();
 247   };
 248 
 249   GCMemoryManager* old_gc_manager() const { return _old_manager; }
 250   GCMemoryManager* young_gc_manager() const { return _young_manager; }
 251 };
 252 
 253 // Simple class for storing info about the heap at the start of GC, to be used
 254 // after GC for comparison/printing.
 255 class PreGCValues {
 256 public:
 257   PreGCValues(ParallelScavengeHeap* heap) :
 258       _heap_used(heap->used()),
 259       _young_gen_used(heap->young_gen()->used_in_bytes()),
 260       _old_gen_used(heap->old_gen()->used_in_bytes()),
 261       _metadata_used(MetaspaceUtils::used_bytes()) { };
 262 
 263   size_t heap_used() const      { return _heap_used; }
 264   size_t young_gen_used() const { return _young_gen_used; }
 265   size_t old_gen_used() const   { return _old_gen_used; }
 266   size_t metadata_used() const  { return _metadata_used; }
 267 
 268 private:
 269   size_t _heap_used;
 270   size_t _young_gen_used;
 271   size_t _old_gen_used;
 272   size_t _metadata_used;
 273 };
 274 
 275 // Class that can be used to print information about the
 276 // adaptive size policy at intervals specified by
 277 // AdaptiveSizePolicyOutputInterval.  Only print information
 278 // if an adaptive size policy is in use.
 279 class AdaptiveSizePolicyOutput : AllStatic {
 280   static bool enabled() {
 281     return UseParallelGC &&
 282            UseAdaptiveSizePolicy &&
 283            log_is_enabled(Debug, gc, ergo);
 284   }
 285  public:
 286   static void print() {
 287     if (enabled()) {
 288       ParallelScavengeHeap::heap()->size_policy()->print();
 289     }
 290   }
 291 
 292   static void print(AdaptiveSizePolicy* size_policy, uint count) {
< prev index next >