< prev index next >

src/share/vm/memory/genCollectedHeap.hpp

Print this page




  14  *
  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_GENCOLLECTEDHEAP_HPP
  26 #define SHARE_VM_MEMORY_GENCOLLECTEDHEAP_HPP
  27 
  28 #include "gc_implementation/shared/adaptiveSizePolicy.hpp"
  29 #include "memory/collectorPolicy.hpp"
  30 #include "memory/generation.hpp"
  31 #include "memory/sharedHeap.hpp"
  32 
  33 class SubTasksDone;

  34 
  35 // A "GenCollectedHeap" is a SharedHeap that uses generational
  36 // collection.  It has two generations, young and old.
  37 class GenCollectedHeap : public SharedHeap {
  38   friend class GenCollectorPolicy;
  39   friend class Generation;
  40   friend class DefNewGeneration;
  41   friend class TenuredGeneration;
  42   friend class ConcurrentMarkSweepGeneration;
  43   friend class CMSCollector;
  44   friend class GenMarkSweep;
  45   friend class VM_GenCollectForAllocation;
  46   friend class VM_GenCollectFull;
  47   friend class VM_GenCollectFullConcurrent;
  48   friend class VM_GC_HeapInspection;
  49   friend class VM_HeapDumper;
  50   friend class HeapInspection;
  51   friend class GCCauseSetter;
  52   friend class VMStructs;
  53 public:


  76   // Indicates that the most recent previous incremental collection failed.
  77   // The flag is cleared when an action is taken that might clear the
  78   // condition that caused that incremental collection to fail.
  79   bool _incremental_collection_failed;
  80 
  81   // In support of ExplicitGCInvokesConcurrent functionality
  82   unsigned int _full_collections_completed;
  83 
  84   // Data structure for claiming the (potentially) parallel tasks in
  85   // (gen-specific) roots processing.
  86   SubTasksDone* _process_strong_tasks;
  87 
  88   // Collects the given generation.
  89   void collect_generation(Generation* gen, bool full, size_t size, bool is_tlab,
  90                           bool run_verification, bool clear_soft_refs,
  91                           bool restore_marks_for_biased_locking);
  92 
  93   // In block contents verification, the number of header words to skip
  94   NOT_PRODUCT(static size_t _skip_header_HeapWords;)
  95 


  96 protected:
  97   // Helper functions for allocation
  98   HeapWord* attempt_allocation(size_t size,
  99                                bool   is_tlab,
 100                                bool   first_only);
 101 
 102   // Helper function for two callbacks below.
 103   // Considers collection of the first max_level+1 generations.
 104   void do_collection(bool   full,
 105                      bool   clear_all_soft_refs,
 106                      size_t size,
 107                      bool   is_tlab,
 108                      int    max_level);
 109 
 110   // Callback from VM_GenCollectForAllocation operation.
 111   // This function does everything necessary/possible to satisfy an
 112   // allocation request that failed in the youngest generation that should
 113   // have handled it (including collection, expansion, etc.)
 114   HeapWord* satisfy_failed_allocation(size_t size, bool is_tlab);
 115 
 116   // Callback from VM_GenCollectFull operation.
 117   // Perform a full collection of the first max_level+1 generations.
 118   virtual void do_full_collection(bool clear_all_soft_refs);
 119   void do_full_collection(bool clear_all_soft_refs, int max_level);
 120 
 121   // Does the "cause" of GC indicate that
 122   // we absolutely __must__ clear soft refs?
 123   bool must_clear_all_soft_refs();
 124 
 125 public:
 126   GenCollectedHeap(GenCollectorPolicy *policy);
 127 


 128   GCStats* gc_stats(int level) const;
 129 
 130   // Returns JNI_OK on success
 131   virtual jint initialize();
 132 
 133   // Reserve aligned space for the heap as needed by the contained generations.
 134   char* allocate(size_t alignment, ReservedSpace* heap_rs);
 135 
 136   // Does operations required after initialization has been done.
 137   void post_initialize();
 138 
 139   // Initialize ("weak") refs processing support
 140   virtual void ref_processing_init();
 141 
 142   virtual CollectedHeap::Name kind() const {
 143     return CollectedHeap::GenCollectedHeap;
 144   }
 145 
 146   Generation* young_gen() const { return _young_gen; }
 147   Generation* old_gen()   const { return _old_gen; }


 314   }
 315 
 316   // Update above counter, as appropriate, at the end of a stop-world GC cycle
 317   unsigned int update_full_collections_completed();
 318   // Update above counter, as appropriate, at the end of a concurrent GC cycle
 319   unsigned int update_full_collections_completed(unsigned int count);
 320 
 321   // Update "time of last gc" for all generations to "now".
 322   void update_time_of_last_gc(jlong now) {
 323     _young_gen->update_time_of_last_gc(now);
 324     _old_gen->update_time_of_last_gc(now);
 325   }
 326 
 327   // Update the gc statistics for each generation.
 328   // "level" is the level of the latest collection.
 329   void update_gc_stats(int current_level, bool full) {
 330     _young_gen->update_gc_stats(current_level, full);
 331     _old_gen->update_gc_stats(current_level, full);
 332   }
 333 
 334   // Override.
 335   bool no_gc_in_progress() { return !is_gc_active(); }
 336 
 337   // Override.
 338   void prepare_for_verify();
 339 
 340   // Override.
 341   void verify(bool silent, VerifyOption option);
 342 
 343   // Override.
 344   virtual void print_on(outputStream* st) const;
 345   virtual void print_gc_threads_on(outputStream* st) const;
 346   virtual void gc_threads_do(ThreadClosure* tc) const;
 347   virtual void print_tracing_info() const;
 348   virtual void print_on_error(outputStream* st) const;
 349 
 350   // PrintGC, PrintGCDetails support
 351   void print_heap_change(size_t prev_used) const;
 352 
 353   // The functions below are helper functions that a subclass of
 354   // "CollectedHeap" can use in the implementation of its virtual
 355   // functions.
 356 
 357   class GenClosure : public StackObj {
 358    public:
 359     virtual void do_generation(Generation* gen) = 0;
 360   };
 361 
 362   // Apply "cl.do_generation" to all generations in the heap
 363   // If "old_to_young" determines the order.
 364   void generation_iterate(GenClosure* cl, bool old_to_young);
 365 
 366   void space_iterate(SpaceClosure* cl);
 367 
 368   // Return "true" if all generations have reached the
 369   // maximal committed limit that they can reach, without a garbage
 370   // collection.
 371   virtual bool is_maximal_no_gc() const;
 372 
 373   int n_gens() const {
 374     assert(_n_gens == gen_policy()->number_of_generations(), "Sanity");
 375     return _n_gens;
 376   }
 377 
 378   // This function returns the "GenRemSet" object that allows us to scan
 379   // generations in a fully generational heap.
 380   GenRemSet* rem_set() { return _rem_set; }
 381 
 382   // Convenience function to be used in situations where the heap type can be
 383   // asserted to be this type.
 384   static GenCollectedHeap* heap();
 385 
 386   void set_par_threads(uint t);
 387   void set_n_termination(uint t);


 514   // in an essential way: compaction is performed across generations, by
 515   // iterating over spaces.
 516   void prepare_for_compaction();
 517 
 518   // Perform a full collection of the first max_level+1 generations.
 519   // This is the low level interface used by the public versions of
 520   // collect() and collect_locked(). Caller holds the Heap_lock on entry.
 521   void collect_locked(GCCause::Cause cause, int max_level);
 522 
 523   // Returns success or failure.
 524   bool create_cms_collector();
 525 
 526   // In support of ExplicitGCInvokesConcurrent functionality
 527   bool should_do_concurrent_full_gc(GCCause::Cause cause);
 528   void collect_mostly_concurrent(GCCause::Cause cause);
 529 
 530   // Save the tops of the spaces in all generations
 531   void record_gen_tops_before_GC() PRODUCT_RETURN;
 532 
 533 protected:
 534   virtual void gc_prologue(bool full);
 535   virtual void gc_epilogue(bool full);
 536 };
 537 
 538 #endif // SHARE_VM_MEMORY_GENCOLLECTEDHEAP_HPP


  14  *
  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_GENCOLLECTEDHEAP_HPP
  26 #define SHARE_VM_MEMORY_GENCOLLECTEDHEAP_HPP
  27 
  28 #include "gc_implementation/shared/adaptiveSizePolicy.hpp"
  29 #include "memory/collectorPolicy.hpp"
  30 #include "memory/generation.hpp"
  31 #include "memory/sharedHeap.hpp"
  32 
  33 class SubTasksDone;
  34 class FlexibleWorkGang;
  35 
  36 // A "GenCollectedHeap" is a SharedHeap that uses generational
  37 // collection.  It has two generations, young and old.
  38 class GenCollectedHeap : public SharedHeap {
  39   friend class GenCollectorPolicy;
  40   friend class Generation;
  41   friend class DefNewGeneration;
  42   friend class TenuredGeneration;
  43   friend class ConcurrentMarkSweepGeneration;
  44   friend class CMSCollector;
  45   friend class GenMarkSweep;
  46   friend class VM_GenCollectForAllocation;
  47   friend class VM_GenCollectFull;
  48   friend class VM_GenCollectFullConcurrent;
  49   friend class VM_GC_HeapInspection;
  50   friend class VM_HeapDumper;
  51   friend class HeapInspection;
  52   friend class GCCauseSetter;
  53   friend class VMStructs;
  54 public:


  77   // Indicates that the most recent previous incremental collection failed.
  78   // The flag is cleared when an action is taken that might clear the
  79   // condition that caused that incremental collection to fail.
  80   bool _incremental_collection_failed;
  81 
  82   // In support of ExplicitGCInvokesConcurrent functionality
  83   unsigned int _full_collections_completed;
  84 
  85   // Data structure for claiming the (potentially) parallel tasks in
  86   // (gen-specific) roots processing.
  87   SubTasksDone* _process_strong_tasks;
  88 
  89   // Collects the given generation.
  90   void collect_generation(Generation* gen, bool full, size_t size, bool is_tlab,
  91                           bool run_verification, bool clear_soft_refs,
  92                           bool restore_marks_for_biased_locking);
  93 
  94   // In block contents verification, the number of header words to skip
  95   NOT_PRODUCT(static size_t _skip_header_HeapWords;)
  96 
  97   FlexibleWorkGang* _workers;
  98 
  99 protected:
 100   // Helper functions for allocation
 101   HeapWord* attempt_allocation(size_t size,
 102                                bool   is_tlab,
 103                                bool   first_only);
 104 
 105   // Helper function for two callbacks below.
 106   // Considers collection of the first max_level+1 generations.
 107   void do_collection(bool   full,
 108                      bool   clear_all_soft_refs,
 109                      size_t size,
 110                      bool   is_tlab,
 111                      int    max_level);
 112 
 113   // Callback from VM_GenCollectForAllocation operation.
 114   // This function does everything necessary/possible to satisfy an
 115   // allocation request that failed in the youngest generation that should
 116   // have handled it (including collection, expansion, etc.)
 117   HeapWord* satisfy_failed_allocation(size_t size, bool is_tlab);
 118 
 119   // Callback from VM_GenCollectFull operation.
 120   // Perform a full collection of the first max_level+1 generations.
 121   virtual void do_full_collection(bool clear_all_soft_refs);
 122   void do_full_collection(bool clear_all_soft_refs, int max_level);
 123 
 124   // Does the "cause" of GC indicate that
 125   // we absolutely __must__ clear soft refs?
 126   bool must_clear_all_soft_refs();
 127 
 128 public:
 129   GenCollectedHeap(GenCollectorPolicy *policy);
 130 
 131   FlexibleWorkGang* workers() const { return _workers; }
 132 
 133   GCStats* gc_stats(int level) const;
 134 
 135   // Returns JNI_OK on success
 136   virtual jint initialize();
 137 
 138   // Reserve aligned space for the heap as needed by the contained generations.
 139   char* allocate(size_t alignment, ReservedSpace* heap_rs);
 140 
 141   // Does operations required after initialization has been done.
 142   void post_initialize();
 143 
 144   // Initialize ("weak") refs processing support
 145   virtual void ref_processing_init();
 146 
 147   virtual CollectedHeap::Name kind() const {
 148     return CollectedHeap::GenCollectedHeap;
 149   }
 150 
 151   Generation* young_gen() const { return _young_gen; }
 152   Generation* old_gen()   const { return _old_gen; }


 319   }
 320 
 321   // Update above counter, as appropriate, at the end of a stop-world GC cycle
 322   unsigned int update_full_collections_completed();
 323   // Update above counter, as appropriate, at the end of a concurrent GC cycle
 324   unsigned int update_full_collections_completed(unsigned int count);
 325 
 326   // Update "time of last gc" for all generations to "now".
 327   void update_time_of_last_gc(jlong now) {
 328     _young_gen->update_time_of_last_gc(now);
 329     _old_gen->update_time_of_last_gc(now);
 330   }
 331 
 332   // Update the gc statistics for each generation.
 333   // "level" is the level of the latest collection.
 334   void update_gc_stats(int current_level, bool full) {
 335     _young_gen->update_gc_stats(current_level, full);
 336     _old_gen->update_gc_stats(current_level, full);
 337   }
 338 

 339   bool no_gc_in_progress() { return !is_gc_active(); }
 340 
 341   // Override.
 342   void prepare_for_verify();
 343 
 344   // Override.
 345   void verify(bool silent, VerifyOption option);
 346 
 347   // Override.
 348   virtual void print_on(outputStream* st) const;
 349   virtual void print_gc_threads_on(outputStream* st) const;
 350   virtual void gc_threads_do(ThreadClosure* tc) const;
 351   virtual void print_tracing_info() const;
 352   virtual void print_on_error(outputStream* st) const;
 353 
 354   // PrintGC, PrintGCDetails support
 355   void print_heap_change(size_t prev_used) const;
 356 
 357   // The functions below are helper functions that a subclass of
 358   // "CollectedHeap" can use in the implementation of its virtual
 359   // functions.
 360 
 361   class GenClosure : public StackObj {
 362    public:
 363     virtual void do_generation(Generation* gen) = 0;
 364   };
 365 
 366   // Apply "cl.do_generation" to all generations in the heap
 367   // If "old_to_young" determines the order.
 368   void generation_iterate(GenClosure* cl, bool old_to_young);
 369 


 370   // Return "true" if all generations have reached the
 371   // maximal committed limit that they can reach, without a garbage
 372   // collection.
 373   virtual bool is_maximal_no_gc() const;
 374 
 375   int n_gens() const {
 376     assert(_n_gens == gen_policy()->number_of_generations(), "Sanity");
 377     return _n_gens;
 378   }
 379 
 380   // This function returns the "GenRemSet" object that allows us to scan
 381   // generations in a fully generational heap.
 382   GenRemSet* rem_set() { return _rem_set; }
 383 
 384   // Convenience function to be used in situations where the heap type can be
 385   // asserted to be this type.
 386   static GenCollectedHeap* heap();
 387 
 388   void set_par_threads(uint t);
 389   void set_n_termination(uint t);


 516   // in an essential way: compaction is performed across generations, by
 517   // iterating over spaces.
 518   void prepare_for_compaction();
 519 
 520   // Perform a full collection of the first max_level+1 generations.
 521   // This is the low level interface used by the public versions of
 522   // collect() and collect_locked(). Caller holds the Heap_lock on entry.
 523   void collect_locked(GCCause::Cause cause, int max_level);
 524 
 525   // Returns success or failure.
 526   bool create_cms_collector();
 527 
 528   // In support of ExplicitGCInvokesConcurrent functionality
 529   bool should_do_concurrent_full_gc(GCCause::Cause cause);
 530   void collect_mostly_concurrent(GCCause::Cause cause);
 531 
 532   // Save the tops of the spaces in all generations
 533   void record_gen_tops_before_GC() PRODUCT_RETURN;
 534 
 535 protected:
 536   void gc_prologue(bool full);
 537   void gc_epilogue(bool full);
 538 };
 539 
 540 #endif // SHARE_VM_MEMORY_GENCOLLECTEDHEAP_HPP
< prev index next >