< prev index next >

src/hotspot/share/gc/shared/genCollectedHeap.hpp

Print this page




  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  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_GC_SHARED_GENCOLLECTEDHEAP_HPP
  26 #define SHARE_GC_SHARED_GENCOLLECTEDHEAP_HPP
  27 
  28 #include "gc/shared/collectedHeap.hpp"
  29 #include "gc/shared/generation.hpp"
  30 #include "gc/shared/oopStorageParState.hpp"
  31 #include "gc/shared/preGCValues.hpp"
  32 #include "gc/shared/softRefGenPolicy.hpp"
  33 
  34 class AdaptiveSizePolicy;
  35 class CardTableRS;
  36 class GCPolicyCounters;
  37 class GenerationSpec;
  38 class StrongRootsScope;
  39 class SubTasksDone;
  40 class WorkGang;
  41 
  42 // A "GenCollectedHeap" is a CollectedHeap that uses generational
  43 // collection.  It has two generations, young and old.
  44 class GenCollectedHeap : public CollectedHeap {
  45   friend class Generation;
  46   friend class DefNewGeneration;
  47   friend class TenuredGeneration;
  48   friend class ConcurrentMarkSweepGeneration;
  49   friend class CMSCollector;
  50   friend class GenMarkSweep;
  51   friend class VM_GenCollectForAllocation;


  79 
  80   // The sizing of the heap is controlled by a sizing policy.
  81   AdaptiveSizePolicy* _size_policy;
  82 
  83   GCPolicyCounters* _gc_policy_counters;
  84 
  85   // Indicates that the most recent previous incremental collection failed.
  86   // The flag is cleared when an action is taken that might clear the
  87   // condition that caused that incremental collection to fail.
  88   bool _incremental_collection_failed;
  89 
  90   // In support of ExplicitGCInvokesConcurrent functionality
  91   unsigned int _full_collections_completed;
  92 
  93   // Collects the given generation.
  94   void collect_generation(Generation* gen, bool full, size_t size, bool is_tlab,
  95                           bool run_verification, bool clear_soft_refs,
  96                           bool restore_marks_for_biased_locking);
  97 
  98   // Reserve aligned space for the heap as needed by the contained generations.
  99   ReservedHeapSpace allocate(size_t alignment);
 100 
 101   // Initialize ("weak") refs processing support
 102   void ref_processing_init();
 103 
 104   PreGenGCValues get_pre_gc_values() const;
 105 
 106 protected:
 107 
 108   // The set of potentially parallel tasks in root scanning.
 109   enum GCH_strong_roots_tasks {
 110     GCH_PS_Universe_oops_do,
 111     GCH_PS_JNIHandles_oops_do,
 112     GCH_PS_ObjectSynchronizer_oops_do,
 113     GCH_PS_FlatProfiler_oops_do,
 114     GCH_PS_Management_oops_do,
 115     GCH_PS_SystemDictionary_oops_do,
 116     GCH_PS_ClassLoaderDataGraph_oops_do,
 117     GCH_PS_jvmti_oops_do,
 118     GCH_PS_CodeCache_oops_do,
 119     AOT_ONLY(GCH_PS_aot_oops_do COMMA)

 120     GCH_PS_younger_gens,
 121     // Leave this one last.
 122     GCH_PS_NumElements
 123   };
 124 
 125   // Data structure for claiming the (potentially) parallel tasks in
 126   // (gen-specific) roots processing.
 127   SubTasksDone* _process_strong_tasks;
 128 
 129   GCMemoryManager* _young_manager;
 130   GCMemoryManager* _old_manager;
 131 
 132   // Helper functions for allocation
 133   HeapWord* attempt_allocation(size_t size,
 134                                bool   is_tlab,
 135                                bool   first_only);
 136 
 137   // Helper function for two callbacks below.
 138   // Considers collection of the first max_level+1 generations.
 139   void do_collection(bool           full,


 163 
 164 public:
 165 
 166   // Returns JNI_OK on success
 167   virtual jint initialize();
 168   virtual CardTableRS* create_rem_set(const MemRegion& reserved_region);
 169 
 170   void initialize_size_policy(size_t init_eden_size,
 171                               size_t init_promo_size,
 172                               size_t init_survivor_size);
 173 
 174   // Does operations required after initialization has been done.
 175   void post_initialize();
 176 
 177   Generation* young_gen() const { return _young_gen; }
 178   Generation* old_gen()   const { return _old_gen; }
 179 
 180   bool is_young_gen(const Generation* gen) const { return gen == _young_gen; }
 181   bool is_old_gen(const Generation* gen) const { return gen == _old_gen; }
 182 
 183   MemRegion reserved_region() const { return _reserved; }
 184   bool is_in_reserved(const void* addr) const { return _reserved.contains(addr); }
 185 
 186   GenerationSpec* young_gen_spec() const;
 187   GenerationSpec* old_gen_spec() const;
 188 
 189   virtual SoftRefPolicy* soft_ref_policy() { return &_soft_ref_gen_policy; }
 190 
 191   // Adaptive size policy
 192   virtual AdaptiveSizePolicy* size_policy() {
 193     return _size_policy;
 194   }
 195 
 196   // Performance Counter support
 197   GCPolicyCounters* counters()     { return _gc_policy_counters; }
 198 
 199   size_t capacity() const;
 200   size_t used() const;
 201 
 202   // Save the "used_region" for both generations.
 203   void save_used_regions();
 204 
 205   size_t max_capacity() const;


 249 
 250   // Iteration functions.
 251   void oop_iterate(OopIterateClosure* cl);
 252   void object_iterate(ObjectClosure* cl);
 253   void safe_object_iterate(ObjectClosure* cl);
 254   Space* space_containing(const void* addr) const;
 255 
 256   // A CollectedHeap is divided into a dense sequence of "blocks"; that is,
 257   // each address in the (reserved) heap is a member of exactly
 258   // one block.  The defining characteristic of a block is that it is
 259   // possible to find its size, and thus to progress forward to the next
 260   // block.  (Blocks may be of different sizes.)  Thus, blocks may
 261   // represent Java objects, or they might be free blocks in a
 262   // free-list-based heap (or subheap), as long as the two kinds are
 263   // distinguishable and the size of each is determinable.
 264 
 265   // Returns the address of the start of the "block" that contains the
 266   // address "addr".  We say "blocks" instead of "object" since some heaps
 267   // may not pack objects densely; a chunk may either be an object or a
 268   // non-object.
 269   HeapWord* block_start(const void* addr) const;
 270 
 271   // Requires "addr" to be the start of a block, and returns "TRUE" iff
 272   // the block is an object. Assumes (and verifies in non-product
 273   // builds) that addr is in the allocated part of the heap and is
 274   // the start of a chunk.
 275   bool block_is_obj(const HeapWord* addr) const;
 276 
 277   // Section on TLAB's.
 278   virtual bool supports_tlab_allocation() const;
 279   virtual size_t tlab_capacity(Thread* thr) const;
 280   virtual size_t tlab_used(Thread* thr) const;
 281   virtual size_t unsafe_max_tlab_alloc(Thread* thr) const;
 282   virtual HeapWord* allocate_new_tlab(size_t min_size,
 283                                       size_t requested_size,
 284                                       size_t* actual_size);
 285 
 286   // The "requestor" generation is performing some garbage collection
 287   // action for which it would be useful to have scratch space.  The
 288   // requestor promises to allocate no more than "max_alloc_words" in any
 289   // older generation (via promotion say.)   Any blocks of space that can
 290   // be provided are returned as a list of ScratchBlocks, sorted by
 291   // decreasing size.
 292   ScratchBlock* gather_scratch(Generation* requestor, size_t max_alloc_words);
 293   // Allow each generation to reset any scratch space that it has
 294   // contributed as it needs.
 295   void release_scratch();


 321 
 322   // Update the gc statistics for each generation.
 323   void update_gc_stats(Generation* current_generation, bool full) {
 324     _old_gen->update_gc_stats(current_generation, full);
 325   }
 326 
 327   bool no_gc_in_progress() { return !is_gc_active(); }
 328 
 329   // Override.
 330   void prepare_for_verify();
 331 
 332   // Override.
 333   void verify(VerifyOption option);
 334 
 335   // Override.
 336   virtual void print_on(outputStream* st) const;
 337   virtual void print_gc_threads_on(outputStream* st) const;
 338   virtual void gc_threads_do(ThreadClosure* tc) const;
 339   virtual void print_tracing_info() const;
 340 
 341   // Used to print information about locations in the hs_err file.
 342   virtual bool print_location(outputStream* st, void* addr) const;
 343 
 344   void print_heap_change(const PreGenGCValues& pre_gc_values) const;
 345 
 346   // The functions below are helper functions that a subclass of
 347   // "CollectedHeap" can use in the implementation of its virtual
 348   // functions.
 349 
 350   class GenClosure : public StackObj {
 351    public:
 352     virtual void do_generation(Generation* gen) = 0;
 353   };
 354 
 355   // Apply "cl.do_generation" to all generations in the heap
 356   // If "old_to_young" determines the order.
 357   void generation_iterate(GenClosure* cl, bool old_to_young);
 358 
 359   // Return "true" if all generations have reached the
 360   // maximal committed limit that they can reach, without a garbage
 361   // collection.
 362   virtual bool is_maximal_no_gc() const;
 363 
 364   // This function returns the CardTableRS object that allows us to scan




  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  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_GC_SHARED_GENCOLLECTEDHEAP_HPP
  26 #define SHARE_GC_SHARED_GENCOLLECTEDHEAP_HPP
  27 
  28 #include "gc/shared/collectedHeap.hpp"
  29 #include "gc/shared/generation.hpp"
  30 #include "gc/shared/oopStorageParState.hpp"

  31 #include "gc/shared/softRefGenPolicy.hpp"
  32 
  33 class AdaptiveSizePolicy;
  34 class CardTableRS;
  35 class GCPolicyCounters;
  36 class GenerationSpec;
  37 class StrongRootsScope;
  38 class SubTasksDone;
  39 class WorkGang;
  40 
  41 // A "GenCollectedHeap" is a CollectedHeap that uses generational
  42 // collection.  It has two generations, young and old.
  43 class GenCollectedHeap : public CollectedHeap {
  44   friend class Generation;
  45   friend class DefNewGeneration;
  46   friend class TenuredGeneration;
  47   friend class ConcurrentMarkSweepGeneration;
  48   friend class CMSCollector;
  49   friend class GenMarkSweep;
  50   friend class VM_GenCollectForAllocation;


  78 
  79   // The sizing of the heap is controlled by a sizing policy.
  80   AdaptiveSizePolicy* _size_policy;
  81 
  82   GCPolicyCounters* _gc_policy_counters;
  83 
  84   // Indicates that the most recent previous incremental collection failed.
  85   // The flag is cleared when an action is taken that might clear the
  86   // condition that caused that incremental collection to fail.
  87   bool _incremental_collection_failed;
  88 
  89   // In support of ExplicitGCInvokesConcurrent functionality
  90   unsigned int _full_collections_completed;
  91 
  92   // Collects the given generation.
  93   void collect_generation(Generation* gen, bool full, size_t size, bool is_tlab,
  94                           bool run_verification, bool clear_soft_refs,
  95                           bool restore_marks_for_biased_locking);
  96 
  97   // Reserve aligned space for the heap as needed by the contained generations.
  98   char* allocate(size_t alignment, ReservedSpace* heap_rs);
  99 
 100   // Initialize ("weak") refs processing support
 101   void ref_processing_init();
 102 


 103 protected:
 104 
 105   // The set of potentially parallel tasks in root scanning.
 106   enum GCH_strong_roots_tasks {
 107     GCH_PS_Universe_oops_do,
 108     GCH_PS_JNIHandles_oops_do,
 109     GCH_PS_ObjectSynchronizer_oops_do,
 110     GCH_PS_FlatProfiler_oops_do,
 111     GCH_PS_Management_oops_do,
 112     GCH_PS_SystemDictionary_oops_do,
 113     GCH_PS_ClassLoaderDataGraph_oops_do,
 114     GCH_PS_jvmti_oops_do,
 115     GCH_PS_CodeCache_oops_do,
 116     AOT_ONLY(GCH_PS_aot_oops_do COMMA)
 117     JVMCI_ONLY(GCH_PS_jvmci_oops_do COMMA)
 118     GCH_PS_younger_gens,
 119     // Leave this one last.
 120     GCH_PS_NumElements
 121   };
 122 
 123   // Data structure for claiming the (potentially) parallel tasks in
 124   // (gen-specific) roots processing.
 125   SubTasksDone* _process_strong_tasks;
 126 
 127   GCMemoryManager* _young_manager;
 128   GCMemoryManager* _old_manager;
 129 
 130   // Helper functions for allocation
 131   HeapWord* attempt_allocation(size_t size,
 132                                bool   is_tlab,
 133                                bool   first_only);
 134 
 135   // Helper function for two callbacks below.
 136   // Considers collection of the first max_level+1 generations.
 137   void do_collection(bool           full,


 161 
 162 public:
 163 
 164   // Returns JNI_OK on success
 165   virtual jint initialize();
 166   virtual CardTableRS* create_rem_set(const MemRegion& reserved_region);
 167 
 168   void initialize_size_policy(size_t init_eden_size,
 169                               size_t init_promo_size,
 170                               size_t init_survivor_size);
 171 
 172   // Does operations required after initialization has been done.
 173   void post_initialize();
 174 
 175   Generation* young_gen() const { return _young_gen; }
 176   Generation* old_gen()   const { return _old_gen; }
 177 
 178   bool is_young_gen(const Generation* gen) const { return gen == _young_gen; }
 179   bool is_old_gen(const Generation* gen) const { return gen == _old_gen; }
 180 



 181   GenerationSpec* young_gen_spec() const;
 182   GenerationSpec* old_gen_spec() const;
 183 
 184   virtual SoftRefPolicy* soft_ref_policy() { return &_soft_ref_gen_policy; }
 185 
 186   // Adaptive size policy
 187   virtual AdaptiveSizePolicy* size_policy() {
 188     return _size_policy;
 189   }
 190 
 191   // Performance Counter support
 192   GCPolicyCounters* counters()     { return _gc_policy_counters; }
 193 
 194   size_t capacity() const;
 195   size_t used() const;
 196 
 197   // Save the "used_region" for both generations.
 198   void save_used_regions();
 199 
 200   size_t max_capacity() const;


 244 
 245   // Iteration functions.
 246   void oop_iterate(OopIterateClosure* cl);
 247   void object_iterate(ObjectClosure* cl);
 248   void safe_object_iterate(ObjectClosure* cl);
 249   Space* space_containing(const void* addr) const;
 250 
 251   // A CollectedHeap is divided into a dense sequence of "blocks"; that is,
 252   // each address in the (reserved) heap is a member of exactly
 253   // one block.  The defining characteristic of a block is that it is
 254   // possible to find its size, and thus to progress forward to the next
 255   // block.  (Blocks may be of different sizes.)  Thus, blocks may
 256   // represent Java objects, or they might be free blocks in a
 257   // free-list-based heap (or subheap), as long as the two kinds are
 258   // distinguishable and the size of each is determinable.
 259 
 260   // Returns the address of the start of the "block" that contains the
 261   // address "addr".  We say "blocks" instead of "object" since some heaps
 262   // may not pack objects densely; a chunk may either be an object or a
 263   // non-object.
 264   virtual HeapWord* block_start(const void* addr) const;
 265 
 266   // Requires "addr" to be the start of a block, and returns "TRUE" iff
 267   // the block is an object. Assumes (and verifies in non-product
 268   // builds) that addr is in the allocated part of the heap and is
 269   // the start of a chunk.
 270   virtual bool block_is_obj(const HeapWord* addr) const;
 271 
 272   // Section on TLAB's.
 273   virtual bool supports_tlab_allocation() const;
 274   virtual size_t tlab_capacity(Thread* thr) const;
 275   virtual size_t tlab_used(Thread* thr) const;
 276   virtual size_t unsafe_max_tlab_alloc(Thread* thr) const;
 277   virtual HeapWord* allocate_new_tlab(size_t min_size,
 278                                       size_t requested_size,
 279                                       size_t* actual_size);
 280 
 281   // The "requestor" generation is performing some garbage collection
 282   // action for which it would be useful to have scratch space.  The
 283   // requestor promises to allocate no more than "max_alloc_words" in any
 284   // older generation (via promotion say.)   Any blocks of space that can
 285   // be provided are returned as a list of ScratchBlocks, sorted by
 286   // decreasing size.
 287   ScratchBlock* gather_scratch(Generation* requestor, size_t max_alloc_words);
 288   // Allow each generation to reset any scratch space that it has
 289   // contributed as it needs.
 290   void release_scratch();


 316 
 317   // Update the gc statistics for each generation.
 318   void update_gc_stats(Generation* current_generation, bool full) {
 319     _old_gen->update_gc_stats(current_generation, full);
 320   }
 321 
 322   bool no_gc_in_progress() { return !is_gc_active(); }
 323 
 324   // Override.
 325   void prepare_for_verify();
 326 
 327   // Override.
 328   void verify(VerifyOption option);
 329 
 330   // Override.
 331   virtual void print_on(outputStream* st) const;
 332   virtual void print_gc_threads_on(outputStream* st) const;
 333   virtual void gc_threads_do(ThreadClosure* tc) const;
 334   virtual void print_tracing_info() const;
 335 
 336   void print_heap_change(size_t young_prev_used, size_t old_prev_used) const;



 337 
 338   // The functions below are helper functions that a subclass of
 339   // "CollectedHeap" can use in the implementation of its virtual
 340   // functions.
 341 
 342   class GenClosure : public StackObj {
 343    public:
 344     virtual void do_generation(Generation* gen) = 0;
 345   };
 346 
 347   // Apply "cl.do_generation" to all generations in the heap
 348   // If "old_to_young" determines the order.
 349   void generation_iterate(GenClosure* cl, bool old_to_young);
 350 
 351   // Return "true" if all generations have reached the
 352   // maximal committed limit that they can reach, without a garbage
 353   // collection.
 354   virtual bool is_maximal_no_gc() const;
 355 
 356   // This function returns the CardTableRS object that allows us to scan


< prev index next >